ATLAS Offline Software
Loading...
Searching...
No Matches
Common.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
6namespace Common {
35
36
37static 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
67static 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
93bool fromWZorTau(const HepMC::ConstGenParticlePtr& part ) { return fromWZ(part)||fromTau(part); }
94
95
96void 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}
Definition Common.h:9
static bool fromTau(const HepMC::ConstGenParticlePtr &part)
Definition Common.cxx:67
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
bool fromWZorTau(const HepMC::ConstGenParticlePtr &part)
Definition Common.cxx:93
bool prompt(const xAOD::TruthParticle *part, ToolHandle< IMCTruthClassifier > &m_classif)
Definition Common.cxx:7
static bool fromWZ(const HepMC::ConstGenParticlePtr &part)
Definition Common.cxx:37
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
bool isZ(const T &p)
bool isW(const T &p)
bool isQuark(const T &p)
PDG rule 2: Quarks and leptons are numbered consecutively starting from 1 and 11 respectively; to do ...
bool isHadron(const T &p)
TruthParticle_v1 TruthParticle
Typedef to implementation.