ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::TruthIsolationTool Class Reference

#include <TruthIsolationTool.h>

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

Public Member Functions

virtual StatusCode initialize () override final
virtual StatusCode addBranches (const EventContext &ctx) const override final

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.
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.
SG::WriteDecorHandleKeyArray< xAOD::TruthParticleContainer, float > m_isoDecorKeys {this, "DoNotSet_isoDecorKeys", {}, "WriteDecorHandleKeyArray - set internally but must be property"}
 Decor handle key array.
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.
Gaudi::Property< bool > m_chargedOnly {this, "ChargedParticlesOnly", false, "Only keep charged particles in isolation cone"}
 Parameter: only use charged particles for iso?
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.
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.
Gaudi::Property< std::string > m_isoVarNamePrefix {this, "IsolationVarNamePrefix", "", "Prefix of name of the variable to add to output xAOD"}
 Parameter: name of output variable.
Gaudi::Property< bool > m_includeNonInteracting {this, "IncludeNonInteracting", false, "Include non-interacting particles in the isolation definition"}
 Parameter: Include non-interacting particles?
Gaudi::Property< bool > m_variableR {this, "VariableR", false, "Use radius that shrinks with pT in isolation"}
 Parameter: Use variable radius?
std::vector< float > m_coneSizesSort

Detailed Description

Member Function Documentation

◆ addBranches()

StatusCode TruthIsolationTool::addBranches ( const EventContext & ctx) const
finaloverridevirtual

Even if this is with some dummy value

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

44{
45 // Event context
46
47 // Retrieve the truth collections
48 SG::ReadHandle<xAOD::TruthParticleContainer> isoTruthParticles(m_isoParticlesKey, ctx);
49 if (!isoTruthParticles.isValid()) {
50 ATH_MSG_ERROR("Couldn't retrieve collection with name " << m_isoParticlesKey);
51 return StatusCode::FAILURE;
52 }
53
54 SG::ReadHandle<xAOD::TruthParticleContainer> allTruthParticles(m_allParticlesKey, ctx);
55 if (!allTruthParticles.isValid()) {
56 ATH_MSG_ERROR("Couldn't retrieve collection with name " << m_allParticlesKey);
57 return StatusCode::FAILURE;
58 }
59
60 //get struct of helper functions
61 DerivationFramework::DecayGraphHelper decayHelper;
62
63 // Isolation is applied to selected particles only
64 std::vector<const xAOD::TruthParticle*> listOfParticlesForIso;
65 decayHelper.constructListOfFinalParticles(isoTruthParticles.ptr(), listOfParticlesForIso, m_listOfPIDs);
66
67 // Vectors to store particles which will be dressed
68 std::vector<const xAOD::TruthParticle*> candidateParticlesList;
69
70 std::vector<int> emptyList;
71 //make a list of all candidate particles that could fall inside the cone of the particle of interest from listOfParticlesForIso
72 decayHelper.constructListOfFinalParticles(allTruthParticles.ptr(), candidateParticlesList, emptyList, true, m_chargedOnly);
73
74 std::vector<SG::WriteDecorHandle< xAOD::TruthParticleContainer, float > >
75 decorator_iso = m_isoDecorKeys.makeHandles (ctx);
76
77 //All isolation must filled for all Particles.
79 for ( unsigned int icone = 0; icone < m_coneSizesSort.size(); ++icone ) {
80 for (const auto* part : *isoTruthParticles) {
81 decorator_iso.at(icone)(*part) = -1;
82 }
83 }
84
85 // Standard particle loop over final state particles of interest
86 for (const auto* part : listOfParticlesForIso) {
87 std::vector<float> isolationsCalcs(m_coneSizesSort.size(), 0.0);
88 calcIsos(part, candidateParticlesList, isolationsCalcs);
89 for ( unsigned int icone = 0; icone < m_coneSizesSort.size(); ++icone ) {
90 decorator_iso.at(icone)(*part) = isolationsCalcs.at(icone);
91 }
92 }
93
94 return StatusCode::SUCCESS;
95}
#define ATH_MSG_ERROR(x)
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_isoParticlesKey
Parameter: input collection key.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_allParticlesKey
Parameter: input collection key for particles used in calculation.
SG::WriteDecorHandleKeyArray< xAOD::TruthParticleContainer, float > m_isoDecorKeys
Decor handle key array.
Gaudi::Property< std::vector< int > > m_listOfPIDs
Parameter: List of pdgIDs of particles to dress.
void calcIsos(const xAOD::TruthParticle *particle, const std::vector< const xAOD::TruthParticle * > &, std::vector< float > &) const
bool constructListOfFinalParticles(const xAOD::TruthParticleContainer *allParticles, std::vector< const xAOD::TruthParticle * > &selectedlist, const std::vector< int > &pdgId, bool allowFromHadron=false, bool chargedOnly=false) const

◆ calcIsos()

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

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

100{
101 //given a bare TruthParticle particle, calculate the isolation(s) using the
102 //particles in candidateParticlesList, filling isoCalcs in order corresponding
103 //to the sorted cone sizes
104
105 float part_eta = particle->eta();
106 float part_phi = particle->phi();
107 for (const auto* cand_part : candidateParticlesList) {
108 if (find(m_excludeFromCone.begin(), m_excludeFromCone.end(), cand_part->pdgId()) != m_excludeFromCone.end()) {
109 //skip if we find a particle in the exclude list
110 continue;
111 }
112 if (!m_includeNonInteracting && !MC::isInteracting(cand_part->pdgId())){
113 // Do not include non-interacting particles, and this particle is non-interacting
114 continue;
115 }
116 if (!HepMC::is_same_particle(cand_part,particle)) {
117 //iteration over sorted cone sizes
118 for ( unsigned int icone = 0; icone < m_coneSizesSort.size(); ++icone ) {
119 const float dr2 = calculateDeltaR2(cand_part, part_eta, part_phi);
120 const float coneSize = m_coneSizesSort.at(icone);
121 if (dr2 < coneSize*coneSize &&
122 (!m_variableR || dr2*particle->pt()*particle->pt() < 100000000.)) {
123 //sum the transverse momenta
124 isoCalcs.at(icone) = isoCalcs.at(icone) + cand_part->pt();
125 } else {
126 //break out of the loop safely since the cone sizes are sorted descending
127 break;
128 }
129 }
130 }
131 }
132 return;
133}
Gaudi::Property< std::vector< int > > m_excludeFromCone
Parameter: List of pdgIDs to exclude from cone calculation.
static float calculateDeltaR2(const xAOD::IParticle *p1, float eta2, float phi2)
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
bool isInteracting(const T &p)
Identify if the particle with given PDG ID would not interact with the detector, i....
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
float coneSize(IsolationConeSize type)
convert Isolation Size into cone size

◆ calculateDeltaR2()

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

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

136{
137 //calculate dR^2 this way to hopefully do fewer sqrt and TVector3::Pseudorapidity calls
138 float phi1 = p1->phi();
139 float eta1 = p1->eta();
140 float deltaPhi = std::abs(phi1-phi2);
141 if (deltaPhi>M_PI) deltaPhi = 2.0*M_PI - deltaPhi;
142 float deltaPhiSq = deltaPhi * deltaPhi;
143 float deltaEtaSq = (eta1-eta2)*(eta1-eta2);
144 return deltaPhiSq+deltaEtaSq;
145}
#define M_PI
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
double deltaEtaSq(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition P4Helpers.h:98
double deltaPhiSq(const I4Momentum &pA, const I4Momentum &pB)
delta Phi squared in range ([-pi,pi[)^2 from two I4momentum references
Definition P4Helpers.h:185
setEt setPhi setE277 setWeta2 eta1

◆ initialize()

StatusCode TruthIsolationTool::initialize ( )
finaloverridevirtual

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

19{
20
21 // Initialise input keys
22 ATH_CHECK(m_isoParticlesKey.initialize());
23 ATH_CHECK(m_allParticlesKey.initialize());
24
25 //sort (descsending) the cone sizes vector to optimize calculation
27 std::sort(m_coneSizesSort.begin(), m_coneSizesSort.end(), [](float a, float b){return a>b;});
28
29 // Decorations depend on the list of cone sizes
30 // FIXME set decorations properly in the configuration
31 for ( auto csize_itr : m_coneSizesSort ) {
32 std::ostringstream sizess;
33 if (m_variableR) sizess << "var";
34 sizess << m_isoVarNamePrefix.value() << (int)((csize_itr)*100.);
35 m_isoDecorKeys.emplace_back(m_isoParticlesKey.key()+"."+sizess.str());
36 }
37 ATH_CHECK(m_isoDecorKeys.initialize());
38
39 return StatusCode::SUCCESS;
40}
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t a
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

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 34 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

35{this, "allParticlesKey", "TruthParticles", "Name of Truthparticle key to find in iso cone"};

◆ 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 43 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

44{this, "ChargedParticlesOnly", false, "Only keep charged particles in isolation cone"};

◆ 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 40 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

41{this, "IsolationConeSizes", {0.2}, "Vector of sizes of dR cone in which to include particles"};

◆ 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 49 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

50{this, "excludeIDsFromCone", {}, "List of the pdgIDs of particles to exclude from the cone when calculating isolation"};

◆ 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 55 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

56{this, "IncludeNonInteracting", false, "Include non-interacting particles in the isolation definition"};

◆ m_isoDecorKeys

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

Decor handle key array.

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

38{this, "DoNotSet_isoDecorKeys", {}, "WriteDecorHandleKeyArray - set internally but must be property"};

◆ 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 31 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

32{this, "isoParticlesKey", "TruthParticles", "Name of TruthParticle key for input"};

◆ 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 52 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

53{this, "IsolationVarNamePrefix", "", "Prefix of name of the variable to add to output xAOD"};

◆ 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 46 of file DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h.

47{this, "particleIDsToCalculate", {11,13,22}, "List of the pdgIDs of particles for which to calculate isolation"};

◆ m_variableR

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

Parameter: Use variable radius?

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

59{this, "VariableR", false, "Use radius that shrinks with pT in isolation"};

The documentation for this class was generated from the following files: