699{
700inline
702 return std::ranges::subrange (p->particles_in_const_begin(),
703 p->particles_in_const_end());
704}
705}
706#endif
707
709{
710 template <class VTX>
711 auto particles_in (
const VTX* p) {
return p->particles_in(); }
712 template <class VTX>
713 auto particles_in (
const std::shared_ptr<VTX>& p) {
return p->particles_in(); }
714
716 {
718 template <
class T>
inline bool isConditionA(
const T& p) {
return p->status() == 62 ||
p->status() == 52 ||
p->status() == 21 ||
p->status() == 22;}
719
720 template <
class T>
inline bool isConditionB(
const T& p) {
return p->status() == 23;}
721
722 template <
class T>
inline bool isConditionC(
const T& p) {
return p->status() > 30 &&
p->status() < 40;}
723 }
724
726
729
732
735
738
741
744
747
750
753
756
761 const auto vertex =
p->end_vertex();
763 }
764
767
770 const int apid = std::abs(
p->pdg_id());
772 if (apid == 1000022 || apid == 1000024 || apid == 5100022) return true;
773 if (apid ==
GRAVITON || apid == 1000039 || apid == 5000039)
return true;
774 if (apid == 9000001 || apid == 9000002 || apid == 9000003 || apid == 9000004 || apid == 9000005 || apid == 9000006) return true;
775 return false;
776 }
777
779
781 auto partOriVert = thePart->production_vertex();
782 if (!partOriVert) return nullptr;
783
784 long partPDG = thePart->pdg_id();
785 long MotherPDG(0);
786
787 auto MothOriVert = partOriVert;
788 MothOriVert = nullptr;
790
791 size_t itr = 0;
792 do {
793 if (itr != 0) partOriVert = MothOriVert;
796 if (!theMoth) continue;
797 MotherPDG = theMoth->pdg_id();
798 MothOriVert = theMoth->production_vertex();
799 if (MotherPDG == partPDG) break;
800 }
801 itr++;
802 if (itr > 100) {
803 break;
804 }
806 MothOriVert != partOriVert);
807 return theMoth;
808 }
809
811
812 template <
class C,
class T>
T findMatching(
C TruthContainer, T p) {
814 if (!p) return ptrPart;
816 for (T truthParticle : *TruthContainer) {
818 ptrPart = truthParticle;
819 break;
820 }
821 }
822 }
823 else {
824 for (T truthParticle : TruthContainer) {
826 ptrPart = truthParticle;
827 break;
828 }
829 }
830 }
831 return ptrPart;
832 }
834
836 auto prodVtx = thePart->production_vertex();
837 if (!prodVtx) return;
838 for (const auto& theMother: prodVtx->particles_in()) {
839 if (!theMother) continue;
840 allancestors.insert(theMother);
842 }
843 }
844
846
848 auto endVtx = thePart->end_vertex();
849 if (!endVtx) return;
850 for (const auto& theDaughter: endVtx->particles_out()) {
851 if (!theDaughter) continue;
853 allstabledescendants.insert(theDaughter);
854 }
856 }
857 }
858
862
864 if (pVert == nullptr) return false;
866 int numOfPartIn(0);
867 int pdg(0);
868
869 do {
870 pVert = pV;
871 auto incoming = pVert->particles_in();
872 numOfPartIn = incoming.size();
873 pdg = numOfPartIn && incoming.front() != nullptr ? incoming.front()->pdg_id() : 0;
874 pV = numOfPartIn && incoming.front() != nullptr ? incoming.front()->production_vertex() : nullptr;
875
876 } while (numOfPartIn == 1 && (std::abs(pdg) < 81 || std::abs(pdg) > 100) && pV != nullptr);
877
878 if (numOfPartIn == 2) {
879 auto incoming = pVert->particles_in();
880 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;
881 }
882 return false;
883}
884
888
889 template <class T, class U>
890 bool isFromHadron(T p, U hadron,
bool &fromTau,
bool &fromBSM) {
892 auto vtx =
p->production_vertex();
893 if (!vtx) return false;
894 bool fromHad = false;
896 if (!parent) continue;
897
898
899 fromBSM |=
isBSM(parent);
901 fromTau |=
isTau(parent);
904 return true;
905 }
906 fromHad |=
isFromHadron(parent, hadron, fromTau, fromBSM);
907 }
908 return fromHad;
909 }
910
913
915 decltype(thePart->end_vertex()) EndVert = thePart->end_vertex();
916 decltype(thePart->end_vertex()) pVert(nullptr);
917 if (EndVert != nullptr) {
918 do {
919 bool samePart = false;
920 pVert = nullptr;
921 auto outgoing = EndVert->particles_out();
922 auto incoming = EndVert->particles_in();
923 for (const auto& itrDaug: outgoing) {
924 if (!itrDaug) continue;
926
927 (outgoing.size() == 1 && incoming.size() == 1 &&
929 itrDaug->pdg_id() == thePart->pdg_id()) {
930 samePart = true;
931 pVert = itrDaug->end_vertex();
932 }
933 }
934 if (samePart) EndVert = pVert;
935 } while (pVert != nullptr && pVert != EndVert);
936 }
937 return EndVert;
938 }
939
941
943 if (!theVert) return {};
944 decltype(theVert->particles_out()) finalStatePart;
945 auto outgoing = theVert->particles_out();
946 for (const auto& thePart: outgoing) {
947 if (!thePart) continue;
948 finalStatePart.push_back(thePart);
951 if (pVert == theVert) break;
952 if (pVert != nullptr) {
954 finalStatePart.insert(finalStatePart.end(),vecPart.begin(),vecPart.end());
955 }
956 }
957 return finalStatePart;
958 }
959#if !defined(XAOD_ANALYSIS)
961#ifdef HEPMC3
962inline void GeVToMeV(HepMC::GenEvent* evt) {
for (
auto& p:
evt->particles()) {
p->set_momentum(
p->momentum()*1000);
p->set_generated_mass(1000*
p->generated_mass());}}
963inline 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());} }
964#else
965inline void GeVToMeV(HepMC::GenEvent* evt) {
966 for (HepMC::GenEvent::particle_iterator p =
evt->particles_begin(); p !=
evt->particles_end(); ++p) {
967 const HepMC::FourVector fv((*p)->momentum().px() * 1000,
968 (*p)->momentum().py() * 1000,
969 (*p)->momentum().pz() * 1000,
970 (*p)->momentum().e() * 1000);
971 (*p)->set_momentum(fv);
972 (*p)->set_generated_mass(1000 * (*p)->generated_mass());
973 }
974}
975inline void MeVToGeV(HepMC::GenEvent* evt) {
976 for (HepMC::GenEvent::particle_iterator p =
evt->particles_begin(); p !=
evt->particles_end(); ++p) {
977 const HepMC::FourVector fv((*p)->momentum().px() / 1000,
978 (*p)->momentum().py() / 1000,
979 (*p)->momentum().pz() / 1000,
980 (*p)->momentum().e() / 1000);
981 (*p)->set_momentum(fv);
982 (*p)->set_generated_mass((*p)->generated_mass() / 1000);
983 }
984}
985#endif
986#endif
987}
988#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.