462{
463 template <class VTX>
464 auto particles_in (
const VTX* p) {
return p->particles_in(); }
465 template <class VTX>
466 auto particles_in (
const std::shared_ptr<VTX>& p) {
return p->particles_in(); }
467
469 {
471 template <class T> inline bool isConditionA(const T& p) { return p->status() == 62 || p->status() == 52 || p->status() == 21 || p->status() == 22;}
472
473 template <
class T>
inline bool isConditionB(
const T& p) {
return p->status() == 23;}
474
475 template <
class T>
inline bool isConditionC(
const T& p) {
return p->status() > 30 &&
p->status() < 40;}
476 }
477
479
482
485
488
491
494
497
500
503
506
509
514 const auto vertex =
p->end_vertex();
516 }
517
520
523 const int apid = std::abs(
p->pdg_id());
525 if (apid == 1000022 || apid == 1000024 || apid == 5100022) return true;
526 if (apid ==
GRAVITON || apid == 1000039 || apid == 5000039)
return true;
527 if (apid == 9000001 || apid == 9000002 || apid == 9000003 || apid == 9000004 || apid == 9000005 || apid == 9000006) return true;
528 return false;
529 }
530
532
534 auto partOriVert = thePart->production_vertex();
535 if (!partOriVert) return nullptr;
536
537 long partPDG = thePart->pdg_id();
538 long MotherPDG(0);
539
540 auto MothOriVert = partOriVert;
541 MothOriVert = nullptr;
543
544 size_t itr = 0;
545 do {
546 if (itr != 0) partOriVert = MothOriVert;
549 if (!theMoth) continue;
550 MotherPDG = theMoth->pdg_id();
551 MothOriVert = theMoth->production_vertex();
552 if (MotherPDG == partPDG) break;
553 }
554 itr++;
555 if (itr > 100) {
556 break;
557 }
559 MothOriVert != partOriVert);
560 return theMoth;
561 }
562
564
565 template <
class C,
class T>
T findMatching(
C TruthContainer, T p) {
567 if (!p) return ptrPart;
569 for (T truthParticle : *TruthContainer) {
571 ptrPart = truthParticle;
572 break;
573 }
574 }
575 }
576 else {
577 for (T truthParticle : TruthContainer) {
579 ptrPart = truthParticle;
580 break;
581 }
582 }
583 }
584 return ptrPart;
585 }
587
589 auto prodVtx = thePart->production_vertex();
590 if (!prodVtx) return;
591 for (const auto& theMother: prodVtx->particles_in()) {
592 if (!theMother) continue;
593 allancestors.insert(theMother);
595 }
596 }
597
599
601 auto endVtx = thePart->end_vertex();
602 if (!endVtx) return;
603 for (const auto& theDaughter: endVtx->particles_out()) {
604 if (!theDaughter) continue;
606 allstabledescendants.insert(theDaughter);
607 }
609 }
610 }
611
615
617 if (pVert == nullptr) return false;
619 int numOfPartIn(0);
620 int pdg(0);
621
622 do {
623 pVert = pV;
624 auto incoming = pVert->particles_in();
625 numOfPartIn = incoming.size();
626 pdg = numOfPartIn && incoming.front() != nullptr ? incoming.front()->pdg_id() : 0;
627 pV = numOfPartIn && incoming.front() != nullptr ? incoming.front()->production_vertex() : nullptr;
628
629 } while (numOfPartIn == 1 && (std::abs(pdg) < 81 || std::abs(pdg) > 100) && pV != nullptr);
630
631 if (numOfPartIn == 2) {
632 auto incoming = pVert->particles_in();
633 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;
634 }
635 return false;
636}
637
641
642 template <class T, class U>
643 bool isFromHadron(T p, U hadron,
bool &fromTau,
bool &fromBSM) {
645 auto vtx =
p->production_vertex();
646 if (!vtx) return false;
647 bool fromHad = false;
649 if (!parent) continue;
650
651
652 fromBSM |=
isBSM(parent);
654 fromTau |=
isTau(parent);
657 return true;
658 }
659 fromHad |=
isFromHadron(parent, hadron, fromTau, fromBSM);
660 }
661 return fromHad;
662 }
663
666
668 decltype(thePart->end_vertex()) EndVert = thePart->end_vertex();
669 decltype(thePart->end_vertex()) pVert(nullptr);
670 if (EndVert != nullptr) {
671 do {
672 bool samePart = false;
673 pVert = nullptr;
674 auto outgoing = EndVert->particles_out();
675 auto incoming = EndVert->particles_in();
676 for (const auto& itrDaug: outgoing) {
677 if (!itrDaug) continue;
679
680 (outgoing.size() == 1 && incoming.size() == 1 &&
682 itrDaug->pdg_id() == thePart->pdg_id()) {
683 samePart = true;
684 pVert = itrDaug->end_vertex();
685 }
686 }
687 if (samePart) EndVert = pVert;
688 } while (pVert != nullptr && pVert != EndVert);
689 }
690 return EndVert;
691 }
692
694
696 if (!theVert) return {};
697 decltype(theVert->particles_out()) finalStatePart;
698 auto outgoing = theVert->particles_out();
699 for (const auto& thePart: outgoing) {
700 if (!thePart) continue;
701 finalStatePart.push_back(thePart);
704 if (pVert == theVert) break;
705 if (pVert != nullptr) {
707 finalStatePart.insert(finalStatePart.end(),vecPart.begin(),vecPart.end());
708 }
709 }
710 return finalStatePart;
711 }
712#if !defined(XAOD_ANALYSIS)
714inline void GeVToMeV(
HepMC::GenEvent* evt) {
for (
auto& p:
evt->particles()) {
p->set_momentum(
p->momentum()*1000);
p->set_generated_mass(1000*
p->generated_mass());}}
715inline 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());} }
716
717#endif
718}
719#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).
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 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 isSimInteracting(const T &p)
Identify if the particle could interact with the detector during the simulation, e....
void GeVToMeV(HepMC::GenEvent *evt)
void findParticleAncestors(T thePart, std::set< T > &allancestors)
Function to find all ancestors of the particle.
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).