649{
650inline
652 return std::ranges::subrange (p->particles_in_const_begin(),
653 p->particles_in_const_end());
654}
655}
656#endif
657
659{
660 template <class VTX>
661 auto particles_in (
const VTX* p) {
return p->particles_in(); }
662 template <class VTX>
663 auto particles_in (
const std::shared_ptr<VTX>& p) {
return p->particles_in(); }
664
666 {
668 template <
class T>
inline bool isConditionA(
const T& p) {
return p->status() == 62 ||
p->status() == 52 ||
p->status() == 21 ||
p->status() == 22;}
669
670 template <
class T>
inline bool isConditionB(
const T& p) {
return p->status() == 23;}
671
672 template <
class T>
inline bool isConditionC(
const T& p) {
return p->status() > 30 &&
p->status() < 40;}
673 }
674
676
679
682
685
688
691
694
697
700
703
706
711 const auto vertex =
p->end_vertex();
713 }
714
717
720 const int apid = std::abs(
p->pdg_id());
722 if (apid == 1000022 || apid == 1000024 || apid == 5100022) return true;
723 if (apid ==
GRAVITON || apid == 1000039 || apid == 5000039)
return true;
724 if (apid == 9000001 || apid == 9000002 || apid == 9000003 || apid == 9000004 || apid == 9000005 || apid == 9000006) return true;
725 return false;
726 }
727
729
731 auto partOriVert = thePart->production_vertex();
732 if (!partOriVert) return nullptr;
733
734 long partPDG = thePart->pdg_id();
735 long MotherPDG(0);
736
737 auto MothOriVert = partOriVert;
738 MothOriVert = nullptr;
740
741 size_t itr = 0;
742 do {
743 if (itr != 0) partOriVert = MothOriVert;
746 if (!theMoth) continue;
747 MotherPDG = theMoth->pdg_id();
748 MothOriVert = theMoth->production_vertex();
749 if (MotherPDG == partPDG) break;
750 }
751 itr++;
752 if (itr > 100) {
753 break;
754 }
756 MothOriVert != partOriVert);
757 return theMoth;
758 }
759
761
762 template <
class C,
class T>
T findMatching(
C TruthContainer, T p) {
764 if (!p) return ptrPart;
766 for (T truthParticle : *TruthContainer) {
768 ptrPart = truthParticle;
769 break;
770 }
771 }
772 }
773 else {
774 for (T truthParticle : TruthContainer) {
776 ptrPart = truthParticle;
777 break;
778 }
779 }
780 }
781 return ptrPart;
782 }
784
786 auto prodVtx = thePart->production_vertex();
787 if (!prodVtx) return;
788 for (const auto& theMother: prodVtx->particles_in()) {
789 if (!theMother) continue;
790 allancestors.insert(theMother);
792 }
793 }
794
796
798 auto endVtx = thePart->end_vertex();
799 if (!endVtx) return;
800 for (const auto& theDaughter: endVtx->particles_out()) {
801 if (!theDaughter) continue;
803 allstabledescendants.insert(theDaughter);
804 }
806 }
807 }
808
812
814 if (pVert == nullptr) return false;
816 int numOfPartIn(0);
817 int pdg(0);
818
819 do {
820 pVert = pV;
821 auto incoming = pVert->particles_in();
822 numOfPartIn = incoming.size();
823 pdg = numOfPartIn && incoming.front() != nullptr ? incoming.front()->pdg_id() : 0;
824 pV = numOfPartIn && incoming.front() != nullptr ? incoming.front()->production_vertex() : nullptr;
825
826 } while (numOfPartIn == 1 && (std::abs(pdg) < 81 || std::abs(pdg) > 100) && pV != nullptr);
827
828 if (numOfPartIn == 2) {
829 auto incoming = pVert->particles_in();
830 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;
831 }
832 return false;
833}
834
838
839 template <class T, class U>
840 bool isFromHadron(T p, U hadron,
bool &fromTau,
bool &fromBSM) {
842 auto vtx =
p->production_vertex();
843 if (!vtx) return false;
844 bool fromHad = false;
846 if (!parent) continue;
847
848
849 fromBSM |=
isBSM(parent);
851 fromTau |=
isTau(parent);
854 return true;
855 }
856 fromHad |=
isFromHadron(parent, hadron, fromTau, fromBSM);
857 }
858 return fromHad;
859 }
860
863
865 decltype(thePart->end_vertex()) EndVert = thePart->end_vertex();
866 decltype(thePart->end_vertex()) pVert(nullptr);
867 if (EndVert != nullptr) {
868 do {
869 bool samePart = false;
870 pVert = nullptr;
871 auto outgoing = EndVert->particles_out();
872 auto incoming = EndVert->particles_in();
873 for (const auto& itrDaug: outgoing) {
874 if (!itrDaug) continue;
876
877 (outgoing.size() == 1 && incoming.size() == 1 &&
879 itrDaug->pdg_id() == thePart->pdg_id()) {
880 samePart = true;
881 pVert = itrDaug->end_vertex();
882 }
883 }
884 if (samePart) EndVert = pVert;
885 } while (pVert != nullptr && pVert != EndVert);
886 }
887 return EndVert;
888 }
889
891
893 if (!theVert) return {};
894 decltype(theVert->particles_out()) finalStatePart;
895 auto outgoing = theVert->particles_out();
896 for (const auto& thePart: outgoing) {
897 if (!thePart) continue;
898 finalStatePart.push_back(thePart);
901 if (pVert == theVert) break;
902 if (pVert != nullptr) {
904 finalStatePart.insert(finalStatePart.end(),vecPart.begin(),vecPart.end());
905 }
906 }
907 return finalStatePart;
908 }
909#if !defined(XAOD_ANALYSIS)
911#ifdef HEPMC3
912inline void GeVToMeV(HepMC::GenEvent* evt) {
for (
auto& p:
evt->particles()) {
p->set_momentum(
p->momentum()*1000);
p->set_generated_mass(1000*
p->generated_mass());}}
913inline 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());} }
914#else
915inline void GeVToMeV(HepMC::GenEvent* evt) {
916 for (HepMC::GenEvent::particle_iterator p =
evt->particles_begin(); p !=
evt->particles_end(); ++p) {
917 const HepMC::FourVector fv((*p)->momentum().px() * 1000,
918 (*p)->momentum().py() * 1000,
919 (*p)->momentum().pz() * 1000,
920 (*p)->momentum().e() * 1000);
921 (*p)->set_momentum(fv);
922 (*p)->set_generated_mass(1000 * (*p)->generated_mass());
923 }
924}
925inline void MeVToGeV(HepMC::GenEvent* evt) {
926 for (HepMC::GenEvent::particle_iterator p =
evt->particles_begin(); p !=
evt->particles_end(); ++p) {
927 const HepMC::FourVector fv((*p)->momentum().px() / 1000,
928 (*p)->momentum().py() / 1000,
929 (*p)->momentum().pz() / 1000,
930 (*p)->momentum().e() / 1000);
931 (*p)->set_momentum(fv);
932 (*p)->set_generated_mass((*p)->generated_mass() / 1000);
933 }
934}
935#endif
936#endif
937}
938#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,...
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
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.
auto particles_in(const HepMC::GenVertex *p)
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.