ATLAS Offline Software
Common.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
6 namespace Common {
7 bool prompt( const xAOD::TruthParticle* part,ToolHandle<IMCTruthClassifier>& classif ) {
8  MCTruthPartClassifier::ParticleOrigin orig = classif->particleTruthClassifier( part ).second;
9 
10  switch(orig) {
29  return false;
30  default:
31  break;
32  }
33  return true;
34  }
35 
36 
37 static bool fromWZ(const HepMC::ConstGenParticlePtr& part )
38 {
39  // Loop through parents
40  // Hit a hadron -> return false
41  // Hit a parton -> return true
42  // This catch is important - we *cannot* look explicitly for the W or Z, because some
43  // generators do not include the W or Z in the truth record (like Sherpa)
44  // This code, like the code before it, really assumes one incoming particle per vertex...
45  if (!part->production_vertex()) return false;
46 #ifdef HEPMC3
47  for (const auto& iter: part->production_vertex()->particles_in()){
48  int parent_pdgid = iter->pdg_id();
49  if (MC::isW(parent_pdgid) || MC::isZ(parent_pdgid)) return true;
50  if (MC::isHadron( parent_pdgid ) ) return false;
51  if ( std::abs( parent_pdgid ) < 9 ) return true;
52  if ( parent_pdgid == part->pdg_id() ) return fromWZ( iter );
53  }
54 #else
55  for (HepMC::GenVertex::particles_in_const_iterator iter=part->production_vertex()->particles_in_const_begin();
56  iter!=part->production_vertex()->particles_in_const_end();++iter){
57  int parent_pdgid = (*iter)->pdg_id();
58  if (MC::isW(parent_pdgid) || MC::isZ(parent_pdgid)) return true;
59  if (MC::isHadron( parent_pdgid ) ) return false;
60  if ( std::abs( parent_pdgid ) < 9 ) return true;
61  if ( parent_pdgid == part->pdg_id() ) return fromWZ( *iter );
62  }
63 #endif
64  return false;
65 }
66 
67 static bool fromTau(const HepMC::ConstGenParticlePtr& part )
68 {
69  // Loop through parents
70  // Find a tau -> return true
71  // Find a hadron or parton -> return false
72  // This code, like the code before it, really assumes one incoming particle per vertex...
73  if (!part->production_vertex()) return false;
74 #ifdef HEPMC3
75  for (const auto& iter: part->production_vertex()->particles_in()){
76  int parent_pdgid = iter->pdg_id();
77  if ( std::abs( parent_pdgid ) == 15 ) return true;
78  if (MC::isHadron( parent_pdgid ) || MC::isQuark( parent_pdgid ) ) return false;
79  if ( parent_pdgid == part->pdg_id() ) return fromTau( iter );
80  }
81 #else
82  for (HepMC::GenVertex::particles_in_const_iterator iter=part->production_vertex()->particles_in_const_begin();
83  iter!=part->production_vertex()->particles_in_const_end();++iter){
84  int parent_pdgid = (*iter)->pdg_id();
85  if ( std::abs( parent_pdgid ) == 15 ) return true;
86  if (MC::isHadron( parent_pdgid ) || MC::isQuark( parent_pdgid ) ) return false;
87  if ( parent_pdgid == part->pdg_id() ) return fromTau( *iter );
88  }
89 #endif
90  return false;
91 }
92 
93 bool fromWZorTau(const HepMC::ConstGenParticlePtr& part ) { return fromWZ(part)||fromTau(part); }
94 
95 
96 void classify(ToolHandle<IMCTruthClassifier>& classif,
97  const xAOD::TruthParticle * theParticle,
98  unsigned int& particleOutCome,
99  unsigned int& result,
100  int& hadron_pdg,
101  unsigned int& particleType,
102  unsigned int& particleOrigin )
103  {
105  std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin> classification = classif->particleTruthClassifier(theParticle, &info);
106  particleOutCome = info.particleOutCome;
107  auto tpl = MCTruthPartClassifier::defOrigOfParticle(theParticle);
108  result = (unsigned int)std::get<0>(tpl);
109  hadron_pdg = std::get<1>(tpl)?std::get<1>(tpl)->pdg_id():0;
110  particleType = classification.first;
111  particleOrigin = classification.second;
112  }
113 }
grepfile.info
info
Definition: grepfile.py:38
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
StrangeMeson
@ StrangeMeson
Definition: TruthClasses.h:80
get_generator_info.result
result
Definition: get_generator_info.py:21
TruthClassifiers.h
Mu
@ Mu
Definition: TruthClasses.h:62
BBbarMeson
@ BBbarMeson
Definition: TruthClasses.h:85
BottomMeson
@ BottomMeson
Definition: TruthClasses.h:82
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
PionDecay
@ PionDecay
Definition: TruthClasses.h:90
Common::classify
void classify(ToolHandle< IMCTruthClassifier > &m_classif, const xAOD::TruthParticle *theParticle, unsigned int &particleOutCome, unsigned int &result, int &hadron_pdg, unsigned int &particleType, unsigned int &particleOrigin)
Definition: Common.cxx:96
ElMagProc
@ ElMagProc
Definition: TruthClasses.h:61
PhotonConv
@ PhotonConv
Definition: TruthClasses.h:59
MCTruthPartClassifier::defOrigOfParticle
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
Definition: TruthClassifiers.h:151
Common::prompt
bool prompt(const xAOD::TruthParticle *part, ToolHandle< IMCTruthClassifier > &m_classif)
Definition: Common.cxx:7
particleType
Definition: particleType.h:29
CCbarMeson
@ CCbarMeson
Definition: TruthClasses.h:83
NonDefined
@ NonDefined
Definition: TruthClasses.h:52
isQuark
bool isQuark(const T &p)
PDG rule 2: Quarks and leptons are numbered consecutively starting from 1 and 11 respectively; to dot...
Definition: AtlasPID.h:113
Common
Definition: Common.h:9
CharmedBaryon
@ CharmedBaryon
Definition: TruthClasses.h:88
ParticleOrigin
ParticleOrigin
Definition: TruthClasses.h:51
isZ
bool isZ(const T &p)
Definition: AtlasPID.h:164
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
StrangeBaryon
@ StrangeBaryon
Definition: TruthClasses.h:87
LightMeson
@ LightMeson
Definition: TruthClasses.h:79
JPsi
@ JPsi
Definition: TruthClasses.h:84
CharmedMeson
@ CharmedMeson
Definition: TruthClasses.h:81
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
Common.h
isHadron
bool isHadron(const T &p)
Definition: AtlasPID.h:207
Common::fromWZorTau
bool fromWZorTau(const HepMC::ConstGenParticlePtr &part)
Definition: Common.cxx:93
BottomBaryon
@ BottomBaryon
Definition: TruthClasses.h:89
LightBaryon
@ LightBaryon
Definition: TruthClasses.h:86
isW
bool isW(const T &p)
Definition: AtlasPID.h:167
DalitzDec
@ DalitzDec
Definition: TruthClasses.h:60
KaonDecay
@ KaonDecay
Definition: TruthClasses.h:91
MCTruthPartClassifier::Info
Definition: IMCTruthClassifier.h:49