Default constructor.
331{
332 template <class VTX>
333 auto particles_in (
const VTX* p) {
return p->particles_in(); }
334 template <class VTX>
335 auto particles_in (
const std::shared_ptr<VTX>& p) {
return p->particles_in(); }
336
337 namespace Pythia8
338 {
340 template <
class T>
inline bool isConditionA(
const T& p) {
return p->status() == 62 ||
p->status() == 52 ||
p->status() == 21 ||
p->status() == 22;}
341
342 template <
class T>
inline bool isConditionB(
const T& p) {
return p->status() == 23;}
343
344 template <
class T>
inline bool isConditionC(
const T& p) {
return p->status() > 30 &&
p->status() < 40;}
345 }
346
348
351
354
357
360
363
366
369
372
375
378
383 const auto vertex =
p->end_vertex();
385 }
386
389
392 const int apid = std::abs(
p->pdg_id());
394 if (apid == 1000022 || apid == 1000024 || apid == 5100022) return true;
395 if (apid ==
GRAVITON || apid == 1000039 || apid == 5000039)
return true;
396 if (apid == 9000001 || apid == 9000002 || apid == 9000003 || apid == 9000004 || apid == 9000005 || apid == 9000006) return true;
397 return false;
398 }
399
401
403 auto partOriVert = thePart->production_vertex();
404 if (!partOriVert) return nullptr;
405
406 long partPDG = thePart->pdg_id();
407 long MotherPDG(0);
408
409 auto MothOriVert = partOriVert;
410 MothOriVert = nullptr;
412
413 size_t itr = 0;
414 do {
415 if (itr != 0) partOriVert = MothOriVert;
418 if (!theMoth) continue;
419 MotherPDG = theMoth->pdg_id();
420 MothOriVert = theMoth->production_vertex();
421 if (MotherPDG == partPDG) break;
422 }
423 itr++;
424 if (itr > 100) {
425 break;
426 }
428 MothOriVert != partOriVert);
429 return theMoth;
430 }
431
433
434 template <
class C,
class T>
T findMatching(
C TruthContainer, T p) {
436 if (!p) return ptrPart;
438 for (T truthParticle : *TruthContainer) {
440 ptrPart = truthParticle;
441 break;
442 }
443 }
444 }
445 else {
446 for (T truthParticle : TruthContainer) {
448 ptrPart = truthParticle;
449 break;
450 }
451 }
452 }
453 return ptrPart;
454 }
456
458 auto prodVtx = thePart->production_vertex();
459 if (!prodVtx) return;
460 for (const auto& theMother: prodVtx->particles_in()) {
461 if (!theMother) continue;
462 allancestors.insert(theMother);
464 }
465 }
466
468
470 auto endVtx = thePart->end_vertex();
471 if (!endVtx) return;
472 for (const auto& theDaughter: endVtx->particles_out()) {
473 if (!theDaughter) continue;
475 allstabledescendants.insert(theDaughter);
476 }
478 }
479 }
480
484
486 if (pVert == nullptr) return false;
488 int numOfPartIn(0);
489 int pdg(0);
490
491 do {
492 pVert = pV;
493 auto incoming = pVert->particles_in();
494 numOfPartIn = incoming.size();
495 pdg = numOfPartIn && incoming.front() != nullptr ? incoming.front()->pdg_id() : 0;
496 pV = numOfPartIn && incoming.front() != nullptr ? incoming.front()->production_vertex() : nullptr;
497
498 } while (numOfPartIn == 1 && (std::abs(pdg) < 81 || std::abs(pdg) > 100) && pV != nullptr);
499
500 if (numOfPartIn == 2) {
501 auto incoming = pVert->particles_in();
502 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;
503 }
504 return false;
505}
506
510
511 template <class T, class U>
512 bool isFromHadron(T p, U hadron,
bool &fromTau,
bool &fromBSM) {
514 auto vtx =
p->production_vertex();
515 if (!vtx) return false;
516 bool fromHad = false;
518 if (!parent) continue;
519
520
521 fromBSM |=
isBSM(parent);
523 fromTau |=
isTau(parent);
526 return true;
527 }
528 fromHad |=
isFromHadron(parent, hadron, fromTau, fromBSM);
529 }
530 return fromHad;
531 }
532
535
537 decltype(thePart->end_vertex()) EndVert = thePart->end_vertex();
538 decltype(thePart->end_vertex()) pVert(nullptr);
539 if (EndVert != nullptr) {
540 do {
541 bool samePart = false;
542 pVert = nullptr;
543 auto outgoing = EndVert->particles_out();
544 auto incoming = EndVert->particles_in();
545 for (const auto& itrDaug: outgoing) {
546 if (!itrDaug) continue;
548
549 (outgoing.size() == 1 && incoming.size() == 1 &&
551 itrDaug->pdg_id() == thePart->pdg_id()) {
552 samePart = true;
553 pVert = itrDaug->end_vertex();
554 }
555 }
556 if (samePart) EndVert = pVert;
557 } while (pVert != nullptr && pVert != EndVert);
558 }
559 return EndVert;
560 }
561
563
565 if (!theVert) return {};
566 decltype(theVert->particles_out()) finalStatePart;
567 auto outgoing = theVert->particles_out();
568 for (const auto& thePart: outgoing) {
569 if (!thePart) continue;
570 finalStatePart.push_back(thePart);
573 if (pVert == theVert) break;
574 if (pVert != nullptr) {
576 finalStatePart.insert(finalStatePart.end(),vecPart.begin(),vecPart.end());
577 }
578 }
579 return finalStatePart;
580 }
581#if !defined(XAOD_ANALYSIS)
583inline void GeVToMeV(
HepMC::GenEvent* evt) {
for (
auto& p:
evt->particles()) {
p->set_momentum(
p->momentum()*1000);
p->set_generated_mass(1000*
p->generated_mass());}}
584inline 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());} }
585
586#endif
587}
588#endif
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.