4#ifndef TRUTHUTILS_HEPMCHELPERS_H
5#define TRUTHUTILS_HEPMCHELPERS_H
24 auto particles_in (
const std::shared_ptr<VTX>& p) {
return p->particles_in(); }
29 template <
class T>
inline bool isConditionA(
const T& p) {
return p->status() == 62 || p->status() == 52 || p->status() == 21 || p->status() == 22;}
31 template <
class T>
inline bool isConditionB(
const T& p) {
return p->status() == 23;}
33 template <
class T>
inline bool isConditionC(
const T& p) {
return p->status() > 30 && p->status() < 40;}
72 const auto vertex = p->end_vertex();
81 const int apid = std::abs(p->pdg_id());
83 if (apid == 1000022 || apid == 1000024 || apid == 5100022)
return true;
84 if (apid ==
GRAVITON || apid == 1000039 || apid == 5000039)
return true;
85 if (apid == 9000001 || apid == 9000002 || apid == 9000003 || apid == 9000004 || apid == 9000005 || apid == 9000006)
return true;
92 auto partOriVert = thePart->production_vertex();
93 if (!partOriVert)
return nullptr;
95 long partPDG = thePart->pdg_id();
98 auto MothOriVert = partOriVert;
99 MothOriVert =
nullptr;
104 if (itr != 0) partOriVert = MothOriVert;
107 if (!theMoth)
continue;
108 MotherPDG = theMoth->pdg_id();
109 MothOriVert = theMoth->production_vertex();
110 if (MotherPDG == partPDG)
break;
117 MothOriVert != partOriVert);
125 if (!p)
return ptrPart;
127 for (T truthParticle : *TruthContainer) {
129 ptrPart = truthParticle;
135 for (
T truthParticle : TruthContainer) {
137 ptrPart = truthParticle;
147 auto prodVtx = thePart->production_vertex();
148 if (!prodVtx)
return;
149 for (
const auto& theMother: prodVtx->particles_in()) {
150 if (!theMother)
continue;
151 allancestors.insert(theMother);
159 auto endVtx = thePart->end_vertex();
161 for (
const auto& theDaughter: endVtx->particles_out()) {
162 if (!theDaughter)
continue;
164 allstabledescendants.insert(theDaughter);
175 if (pVert ==
nullptr)
return false;
182 auto incoming = pVert->particles_in();
183 numOfPartIn = incoming.size();
184 pdg = numOfPartIn && incoming.front() !=
nullptr ? incoming.front()->pdg_id() : 0;
185 pV = numOfPartIn && incoming.front() !=
nullptr ? incoming.front()->production_vertex() :
nullptr;
187 }
while (numOfPartIn == 1 && (std::abs(pdg) < 81 || std::abs(pdg) > 100) && pV !=
nullptr);
189 if (numOfPartIn == 2) {
190 auto incoming = pVert->particles_in();
191 if (incoming.at(0) && incoming.at(1) && (std::abs(incoming.at(0)->pdg_id()) < 7 || incoming.at(0)->pdg_id() == 21) && (std::abs(incoming.at(1)->pdg_id()) < 7 || incoming.at(1)->pdg_id() == 21))
return true;
200 template <
class T,
class U>
203 auto vtx = p->production_vertex();
204 if (!vtx)
return false;
205 bool fromHad =
false;
207 if (!parent)
continue;
214 if (!hadron) hadron = parent;
226 decltype(thePart->end_vertex()) EndVert = thePart->end_vertex();
227 decltype(thePart->end_vertex()) pVert(
nullptr);
228 if (EndVert !=
nullptr) {
230 bool samePart =
false;
232 auto outgoing = EndVert->particles_out();
233 auto incoming = EndVert->particles_in();
234 for (
const auto& itrDaug: outgoing) {
235 if (!itrDaug)
continue;
238 (outgoing.size() == 1 && incoming.size() == 1 &&
240 itrDaug->pdg_id() == thePart->pdg_id()) {
242 pVert = itrDaug->end_vertex();
245 if (samePart) EndVert = pVert;
246 }
while (pVert !=
nullptr && pVert != EndVert);
254 if (!theVert)
return {};
255 decltype(theVert->particles_out()) finalStatePart;
256 auto outgoing = theVert->particles_out();
257 for (
const auto& thePart: outgoing) {
258 if (!thePart)
continue;
259 finalStatePart.push_back(thePart);
262 if (pVert == theVert)
break;
263 if (pVert !=
nullptr) {
265 finalStatePart.insert(finalStatePart.end(),vecPart.begin(),vecPart.end());
268 return finalStatePart;
270#if !defined(XAOD_ANALYSIS)
272inline void GeVToMeV(
HepMC::GenEvent* evt) {
for (
auto& p: evt->particles()) { p->set_momentum(p->momentum()*1000); p->set_generated_mass(1000* p->generated_mass());}}
273inline void MeVToGeV(
HepMC::GenEvent* evt) {
for (
auto& p: evt->particles()) { p->set_momentum(p->momentum()*1.0/1000); p->set_generated_mass(1.0/1000* p->generated_mass());} }
bool is_same_generator_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same generated particle.
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (TODO migrate to be based on status).
constexpr int SIM_STATUS_THRESHOLD
Constant definiting the status threshold for simulated particles, eg. can be used to separate generat...
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
constexpr bool is_smart_ptr_v
bool is_sim_descendant(const T1 &p1, const T2 &p2)
Method to check if the first particle is a descendant of the second in the simulation,...
HepMC3::GenEvent GenEvent
bool isConditionB(const T &p)
bool isConditionA(const T &p)
To be understood.
bool isConditionC(const T &p)
T findMatching(C TruthContainer, T p)
Function to find a particle in container.
static const int GRAVITON
auto particles_in(const VTX *p)
bool isZeroEnergyPhoton(const T &p)
Identify a photon with zero energy. Probably a workaround for a generator bug.
bool isHardScatteringVertex(T pVert)
Function to classify the vertex as hard scattering vertex.
void MeVToGeV(HepMC::GenEvent *evt)
bool isStableOrSimDecayed(const T &p)
Identify if particle is satble or decayed in simulation.
bool isPhoton(const T &p)
bool isSpecialNonInteracting(const T &p)
Identify a special non-interacting particles.
bool isFromHadron(T p, U hadron, bool &fromTau, bool &fromBSM)
Function to classify the particle.
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isGeantino(const T &p)
bool isSimInteracting(const T &p)
Identify if the particle could interact with the detector during the simulation, e....
void GeVToMeV(HepMC::GenEvent *evt)
bool isEMInteracting(const T &p)
void findParticleAncestors(T thePart, std::set< T > &allancestors)
Function to find all ancestors of the particle.
bool isStrongInteracting(const T &p)
bool isInteracting(const T &p)
Identify if the particle with given PDG ID would not interact with the detector, i....
auto findFinalStateParticles(V theVert) -> decltype(theVert->particles_out())
Function to find the stable particle descendants of the given vertex..
bool isChargedNonShowering(const T &p)
Identify if the particle with given PDG ID would produce ID tracks but not shower in the detector if ...
bool isDecayed(const T &p)
Identify if the particle decayed.
T findMother(T thePart)
Function to get a mother of particle. MCTruthClassifier legacy.
void findParticleStableDescendants(T thePart, std::set< T > &allstabledescendants)
Function to get the particle stable MC daughters.
bool isBeam(const T &p)
Identify if the particle is beam particle.
bool isFinalState(const T &p)
Identify if the particle is final state particle.
bool isGenStable(const T &p)
Determine if the particle is stable at the generator (not det-sim) level,.
bool isHadron(const T &p)
bool isSimStable(const T &p)
Identify if the particle is considered stable at the post-detector-sim stage.
auto findSimulatedEndVertex(T thePart) -> decltype(thePart->end_vertex())
Function to find the end vertex of a particle.
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
bool isBSM(const T &p)
APID: graviton and all Higgs extensions are BSM.
Author: James Monk (jmonk@cern.ch).