ATLAS Offline Software
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
DerivationFramework::TruthIsolationTool Class Reference

#include <TruthIsolationTool.h>

Inheritance diagram for DerivationFramework::TruthIsolationTool:
Collaboration diagram for DerivationFramework::TruthIsolationTool:

Public Member Functions

 TruthIsolationTool (const std::string &t, const std::string &n, const IInterface *p)
 
 ~TruthIsolationTool ()
 
virtual StatusCode initialize () override
 
virtual StatusCode addBranches () const override
 

Private Member Functions

void calcIsos (const xAOD::TruthParticle *particle, const std::vector< const xAOD::TruthParticle * > &, std::vector< float > &) const
 

Static Private Member Functions

static float calculateDeltaR2 (const xAOD::IParticle *p1, float eta2, float phi2)
 

Private Attributes

SG::ReadHandleKey< xAOD::TruthParticleContainerm_isoParticlesKey {this, "isoParticlesKey", "TruthParticles", "Name of TruthParticle key for input"}
 Parameter: input collection key. More...
 
SG::ReadHandleKey< xAOD::TruthParticleContainerm_allParticlesKey {this, "allParticlesKey", "TruthParticles", "Name of Truthparticle key to find in iso cone"}
 Parameter: input collection key for particles used in calculation. More...
 
SG::WriteDecorHandleKeyArray< xAOD::TruthParticleContainer, float > m_isoDecorKeys {this, "DoNotSet_isoDecorKeys", {}, "WriteDecorHandleKeyArray - set internally but must be property"}
 Decor handle key array. More...
 
Gaudi::Property< std::vector< float > > m_coneSizes {this, "IsolationConeSizes", {0.2}, "Vector of sizes of dR cone in which to include particles"}
 Parameter: Cone size for Isolation. More...
 
Gaudi::Property< bool > m_chargedOnly {this, "ChargedParticlesOnly", false, "Only keep charged particles in isolation cone"}
 Parameter: only use charged particles for iso? More...
 
Gaudi::Property< std::vector< int > > m_listOfPIDs {this, "particleIDsToCalculate", {11,13,22}, "List of the pdgIDs of particles for which to calculate isolation"}
 Parameter: List of pdgIDs of particles to dress. More...
 
Gaudi::Property< std::vector< int > > m_excludeFromCone {this, "excludeIDsFromCone", {}, "List of the pdgIDs of particles to exclude from the cone when calculating isolation"}
 Parameter: List of pdgIDs to exclude from cone calculation. More...
 
Gaudi::Property< std::string > m_isoVarNamePrefix {this, "IsolationVarNamePrefix", "", "Prefix of name of the variable to add to output xAOD"}
 Parameter: name of output variable. More...
 
Gaudi::Property< bool > m_includeNonInteracting {this, "IncludeNonInteracting", false, "Include non-interacting particles in the isolation definition"}
 Parameter: Include non-interacting particles? More...
 
Gaudi::Property< bool > m_variableR {this, "VariableR", false, "Use radius that shrinks with pT in isolation"}
 Parameter: Use variable radius? More...
 
std::vector< float > m_coneSizesSort
 

Detailed Description

Definition at line 21 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

Constructor & Destructor Documentation

◆ TruthIsolationTool()

TruthIsolationTool::TruthIsolationTool ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Definition at line 18 of file DerivationFramework/DerivationFrameworkMCTruth/src/TruthIsolationTool.cxx.

20  :
21  base_class(t,n,p)
22 {
23 }

◆ ~TruthIsolationTool()

TruthIsolationTool::~TruthIsolationTool ( )

Member Function Documentation

◆ addBranches()

StatusCode TruthIsolationTool::addBranches ( ) const
overridevirtual

Even if this is with some dummy value

Definition at line 54 of file DerivationFramework/DerivationFrameworkMCTruth/src/TruthIsolationTool.cxx.

55 {
56  // Event context
57  const EventContext& ctx = Gaudi::Hive::currentContext();
58 
59  // Retrieve the truth collections
61  if (!isoTruthParticles.isValid()) {
62  ATH_MSG_ERROR("Couldn't retrieve collection with name " << m_isoParticlesKey);
63  return StatusCode::FAILURE;
64  }
65 
67  if (!allTruthParticles.isValid()) {
68  ATH_MSG_ERROR("Couldn't retrieve collection with name " << m_allParticlesKey);
69  return StatusCode::FAILURE;
70  }
71 
72  //get struct of helper functions
74 
75  // Isolation is applied to selected particles only
76  std::vector<const xAOD::TruthParticle*> listOfParticlesForIso;
77  decayHelper.constructListOfFinalParticles(isoTruthParticles.ptr(), listOfParticlesForIso, m_listOfPIDs);
78 
79  // Vectors to store particles which will be dressed
80  std::vector<const xAOD::TruthParticle*> candidateParticlesList;
81 
82  std::vector<int> emptyList;
83  //make a list of all candidate particles that could fall inside the cone of the particle of interest from listOfParticlesForIso
84  decayHelper.constructListOfFinalParticles(allTruthParticles.ptr(), candidateParticlesList, emptyList, true, m_chargedOnly);
85 
86  std::vector<SG::WriteDecorHandle< xAOD::TruthParticleContainer, float > >
87  decorator_iso = m_isoDecorKeys.makeHandles (ctx);
88 
89  //All isolation must filled for all Particles.
91  for ( unsigned int icone = 0; icone < m_coneSizesSort.size(); ++icone ) {
92  for (const auto* part : *isoTruthParticles) {
93  decorator_iso.at(icone)(*part) = -1;
94  }
95  }
96 
97  // Standard particle loop over final state particles of interest
98  for (const auto* part : listOfParticlesForIso) {
99  std::vector<float> isolationsCalcs(m_coneSizesSort.size(), 0.0);
100  calcIsos(part, candidateParticlesList, isolationsCalcs);
101  for ( unsigned int icone = 0; icone < m_coneSizesSort.size(); ++icone ) {
102  decorator_iso.at(icone)(*part) = isolationsCalcs.at(icone);
103  }
104  }
105 
106  return StatusCode::SUCCESS;
107 }

◆ calcIsos()

void TruthIsolationTool::calcIsos ( const xAOD::TruthParticle particle,
const std::vector< const xAOD::TruthParticle * > &  candidateParticlesList,
std::vector< float > &  isoCalcs 
) const
private

Definition at line 109 of file DerivationFramework/DerivationFrameworkMCTruth/src/TruthIsolationTool.cxx.

112 {
113  //given a bare TruthParticle particle, calculate the isolation(s) using the
114  //particles in candidateParticlesList, filling isoCalcs in order corresponding
115  //to the sorted cone sizes
116 
117  float part_eta = particle->eta();
118  float part_phi = particle->phi();
119  for (const auto* cand_part : candidateParticlesList) {
120  if (find(m_excludeFromCone.begin(), m_excludeFromCone.end(), cand_part->pdgId()) != m_excludeFromCone.end()) {
121  //skip if we find a particle in the exclude list
122  continue;
123  }
124  if (!m_includeNonInteracting && !MC::isInteracting(cand_part->pdgId())){
125  // Do not include non-interacting particles, and this particle is non-interacting
126  continue;
127  }
128  if (!HepMC::is_same_particle(cand_part,particle)) {
129  //iteration over sorted cone sizes
130  for ( unsigned int icone = 0; icone < m_coneSizesSort.size(); ++icone ) {
131  const float dr2 = calculateDeltaR2(cand_part, part_eta, part_phi);
132  const float coneSize = m_coneSizesSort.at(icone);
133  if (dr2 < coneSize*coneSize &&
134  (!m_variableR || dr2*particle->pt()*particle->pt() < 100000000.)) {
135  //sum the transverse momenta
136  isoCalcs.at(icone) = isoCalcs.at(icone) + cand_part->pt();
137  } else {
138  //break out of the loop safely since the cone sizes are sorted descending
139  break;
140  }
141  }
142  }
143  }
144  return;
145 }

◆ calculateDeltaR2()

float TruthIsolationTool::calculateDeltaR2 ( const xAOD::IParticle p1,
float  eta2,
float  phi2 
)
staticprivate

Definition at line 147 of file DerivationFramework/DerivationFrameworkMCTruth/src/TruthIsolationTool.cxx.

148 {
149  //calculate dR^2 this way to hopefully do fewer sqrt and TVector3::Pseudorapidity calls
150  float phi1 = p1->phi();
151  float eta1 = p1->eta();
152  float deltaPhi = std::abs(phi1-phi2);
153  if (deltaPhi>M_PI) deltaPhi = 2.0*M_PI - deltaPhi;
154  float deltaPhiSq = deltaPhi * deltaPhi;
155  float deltaEtaSq = (eta1-eta2)*(eta1-eta2);
156  return deltaPhiSq+deltaEtaSq;
157 }

◆ initialize()

StatusCode TruthIsolationTool::initialize ( )
overridevirtual

Definition at line 30 of file DerivationFramework/DerivationFrameworkMCTruth/src/TruthIsolationTool.cxx.

31 {
32 
33  // Initialise input keys
36 
37  //sort (descsending) the cone sizes vector to optimize calculation
39  std::sort(m_coneSizesSort.begin(), m_coneSizesSort.end(), [](float a, float b){return a>b;});
40 
41  // Decorations depend on the list of cone sizes
42  for ( auto csize_itr : m_coneSizesSort ) {
43  std::ostringstream sizess;
44  if (m_variableR) sizess << "var";
45  sizess << m_isoVarNamePrefix.value() << (int)((csize_itr)*100.);
46  m_isoDecorKeys.emplace_back(m_isoParticlesKey.key()+"."+sizess.str());
47  }
48  ATH_CHECK(m_isoDecorKeys.initialize());
49 
50  return StatusCode::SUCCESS;
51 }

Member Data Documentation

◆ m_allParticlesKey

SG::ReadHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthIsolationTool::m_allParticlesKey {this, "allParticlesKey", "TruthParticles", "Name of Truthparticle key to find in iso cone"}
private

Parameter: input collection key for particles used in calculation.

Definition at line 33 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

◆ m_chargedOnly

Gaudi::Property<bool> DerivationFramework::TruthIsolationTool::m_chargedOnly {this, "ChargedParticlesOnly", false, "Only keep charged particles in isolation cone"}
private

Parameter: only use charged particles for iso?

Definition at line 42 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

◆ m_coneSizes

Gaudi::Property<std::vector<float> > DerivationFramework::TruthIsolationTool::m_coneSizes {this, "IsolationConeSizes", {0.2}, "Vector of sizes of dR cone in which to include particles"}
private

Parameter: Cone size for Isolation.

Definition at line 39 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

◆ m_coneSizesSort

std::vector<float> DerivationFramework::TruthIsolationTool::m_coneSizesSort
private

◆ m_excludeFromCone

Gaudi::Property<std::vector<int> > DerivationFramework::TruthIsolationTool::m_excludeFromCone {this, "excludeIDsFromCone", {}, "List of the pdgIDs of particles to exclude from the cone when calculating isolation"}
private

Parameter: List of pdgIDs to exclude from cone calculation.

Definition at line 48 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

◆ m_includeNonInteracting

Gaudi::Property<bool> DerivationFramework::TruthIsolationTool::m_includeNonInteracting {this, "IncludeNonInteracting", false, "Include non-interacting particles in the isolation definition"}
private

Parameter: Include non-interacting particles?

Definition at line 54 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

◆ m_isoDecorKeys

SG::WriteDecorHandleKeyArray<xAOD::TruthParticleContainer, float> DerivationFramework::TruthIsolationTool::m_isoDecorKeys {this, "DoNotSet_isoDecorKeys", {}, "WriteDecorHandleKeyArray - set internally but must be property"}
private

◆ m_isoParticlesKey

SG::ReadHandleKey<xAOD::TruthParticleContainer> DerivationFramework::TruthIsolationTool::m_isoParticlesKey {this, "isoParticlesKey", "TruthParticles", "Name of TruthParticle key for input"}
private

Parameter: input collection key.

Definition at line 30 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

◆ m_isoVarNamePrefix

Gaudi::Property<std::string> DerivationFramework::TruthIsolationTool::m_isoVarNamePrefix {this, "IsolationVarNamePrefix", "", "Prefix of name of the variable to add to output xAOD"}
private

Parameter: name of output variable.

Definition at line 51 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

◆ m_listOfPIDs

Gaudi::Property<std::vector<int> > DerivationFramework::TruthIsolationTool::m_listOfPIDs {this, "particleIDsToCalculate", {11,13,22}, "List of the pdgIDs of particles for which to calculate isolation"}
private

Parameter: List of pdgIDs of particles to dress.

Definition at line 45 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

◆ m_variableR

Gaudi::Property<bool> DerivationFramework::TruthIsolationTool::m_variableR {this, "VariableR", false, "Use radius that shrinks with pT in isolation"}
private

The documentation for this class was generated from the following files:
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
DerivationFramework::TruthIsolationTool::m_isoParticlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_isoParticlesKey
Parameter: input collection key.
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:31
P4Helpers::deltaEtaSq
double deltaEtaSq(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:98
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:79
ParticleGun_SamplingFraction.eta2
eta2
Definition: ParticleGun_SamplingFraction.py:96
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::ReadHandle< xAOD::TruthParticleContainer >
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:161
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
DerivationFramework::TruthIsolationTool::m_isoVarNamePrefix
Gaudi::Property< std::string > m_isoVarNamePrefix
Parameter: name of output variable.
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:52
DerivationFramework::TruthIsolationTool::m_coneSizesSort
std::vector< float > m_coneSizesSort
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:60
M_PI
#define M_PI
Definition: ActiveFraction.h:11
xAOD::eta1
setEt setPhi setE277 setWeta2 eta1
Definition: TrigEMCluster_v1.cxx:41
DerivationFramework::DecayGraphHelper::constructListOfFinalParticles
bool constructListOfFinalParticles(const xAOD::TruthParticleContainer *allParticles, std::vector< const xAOD::TruthParticle * > &selectedlist, const std::vector< int > &pdgId, bool allowFromHadron=false, bool chargedOnly=false) const
Definition: DecayGraphHelper.h:218
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::TruthIsolationTool::m_listOfPIDs
Gaudi::Property< std::vector< int > > m_listOfPIDs
Parameter: List of pdgIDs of particles to dress.
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:46
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DerivationFramework::TruthIsolationTool::m_chargedOnly
Gaudi::Property< bool > m_chargedOnly
Parameter: only use charged particles for iso?
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:43
HepMC::is_same_particle
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
Definition: MagicNumbers.h:366
DerivationFramework::TruthIsolationTool::calcIsos
void calcIsos(const xAOD::TruthParticle *particle, const std::vector< const xAOD::TruthParticle * > &, std::vector< float > &) const
Definition: DerivationFramework/DerivationFrameworkMCTruth/src/TruthIsolationTool.cxx:109
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::TruthIsolationTool::m_allParticlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_allParticlesKey
Parameter: input collection key for particles used in calculation.
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:34
beamspotman.n
n
Definition: beamspotman.py:727
DerivationFramework::TruthIsolationTool::m_variableR
Gaudi::Property< bool > m_variableR
Parameter: Use variable radius?
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:58
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DerivationFramework::TruthIsolationTool::m_coneSizes
Gaudi::Property< std::vector< float > > m_coneSizes
Parameter: Cone size for Isolation.
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:40
P4Helpers::deltaPhiSq
double deltaPhiSq(const I4Momentum &pA, const I4Momentum &pB)
delta Phi squared in range ([-pi,pi[)^2 from two I4momentum references
Definition: P4Helpers.h:185
DerivationFramework::TruthIsolationTool::m_includeNonInteracting
Gaudi::Property< bool > m_includeNonInteracting
Parameter: Include non-interacting particles?
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:55
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
DerivationFramework::DecayGraphHelper
Definition: DecayGraphHelper.h:26
DerivationFramework::TruthIsolationTool::m_excludeFromCone
Gaudi::Property< std::vector< int > > m_excludeFromCone
Parameter: List of pdgIDs to exclude from cone calculation.
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:49
a
TList * a
Definition: liststreamerinfos.cxx:10
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
DerivationFramework::TruthIsolationTool::m_isoDecorKeys
SG::WriteDecorHandleKeyArray< xAOD::TruthParticleContainer, float > m_isoDecorKeys
Decor handle key array.
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:37
DerivationFramework::TruthIsolationTool::calculateDeltaR2
static float calculateDeltaR2(const xAOD::IParticle *p1, float eta2, float phi2)
Definition: DerivationFramework/DerivationFrameworkMCTruth/src/TruthIsolationTool.cxx:147
MC::isInteracting
bool isInteracting(const T &p)
Identify if the particle with given PDG ID would not interact with the detector, i....
Definition: HepMCHelpers.h:33
xAOD::Iso::coneSize
float coneSize(IsolationConeSize type)
convert Isolation Size into cone size
Definition: IsolationHelpers.h:27