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

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. 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.

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
49  if (!isoTruthParticles.isValid()) {
50  ATH_MSG_ERROR("Couldn't retrieve collection with name " << m_isoParticlesKey);
51  return StatusCode::FAILURE;
52  }
53 
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
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 }

◆ 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 }

◆ 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 }

◆ initialize()

StatusCode TruthIsolationTool::initialize ( )
finaloverridevirtual

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

19 {
20 
21  // Initialise input keys
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 }

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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 31 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 52 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 46 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:32
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:138
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:53
DerivationFramework::TruthIsolationTool::m_coneSizesSort
std::vector< float > m_coneSizesSort
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:61
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
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:47
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:44
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:367
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:97
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:35
DerivationFramework::TruthIsolationTool::m_variableR
Gaudi::Property< bool > m_variableR
Parameter: Use variable radius?
Definition: DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthIsolationTool.h:59
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:41
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:56
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:50
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:38
DerivationFramework::TruthIsolationTool::calculateDeltaR2
static float calculateDeltaR2(const xAOD::IParticle *p1, float eta2, float phi2)
Definition: DerivationFramework/DerivationFrameworkMCTruth/src/TruthIsolationTool.cxx:135
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