669{
670inline
672 return std::ranges::subrange (p->particles_in_const_begin(),
673 p->particles_in_const_end());
674}
675}
676#endif
677
679{
680 template <class VTX>
681 auto particles_in (
const VTX* p) {
return p->particles_in(); }
682 template <class VTX>
683 auto particles_in (
const std::shared_ptr<VTX>& p) {
return p->particles_in(); }
684
686 {
688 template <
class T>
inline bool isConditionA(
const T& p) {
return p->status() == 62 ||
p->status() == 52 ||
p->status() == 21 ||
p->status() == 22;}
689
690 template <
class T>
inline bool isConditionB(
const T& p) {
return p->status() == 23;}
691
692 template <
class T>
inline bool isConditionC(
const T& p) {
return p->status() > 30 &&
p->status() < 40;}
693 }
694
696
699
702
705
708
711
714
717
720
723
726
731 const auto vertex =
p->end_vertex();
733 }
734
737
740 const int apid = std::abs(
p->pdg_id());
742 if (apid == 1000022 || apid == 1000024 || apid == 5100022) return true;
743 if (apid ==
GRAVITON || apid == 1000039 || apid == 5000039)
return true;
744 if (apid == 9000001 || apid == 9000002 || apid == 9000003 || apid == 9000004 || apid == 9000005 || apid == 9000006) return true;
745 return false;
746 }
747
749
751 auto partOriVert = thePart->production_vertex();
752 if (!partOriVert) return nullptr;
753
754 long partPDG = thePart->pdg_id();
755 long MotherPDG(0);
756
757 auto MothOriVert = partOriVert;
758 MothOriVert = nullptr;
760
761 size_t itr = 0;
762 do {
763 if (itr != 0) partOriVert = MothOriVert;
766 if (!theMoth) continue;
767 MotherPDG = theMoth->pdg_id();
768 MothOriVert = theMoth->production_vertex();
769 if (MotherPDG == partPDG) break;
770 }
771 itr++;
772 if (itr > 100) {
773 break;
774 }
776 MothOriVert != partOriVert);
777 return theMoth;
778 }
779
781
782 template <
class C,
class T>
T findMatching(
C TruthContainer, T p) {
784 if (!p) return ptrPart;
786 for (T truthParticle : *TruthContainer) {
788 ptrPart = truthParticle;
789 break;
790 }
791 }
792 }
793 else {
794 for (T truthParticle : TruthContainer) {
796 ptrPart = truthParticle;
797 break;
798 }
799 }
800 }
801 return ptrPart;
802 }
804
806 auto prodVtx = thePart->production_vertex();
807 if (!prodVtx) return;
808 for (const auto& theMother: prodVtx->particles_in()) {
809 if (!theMother) continue;
810 allancestors.insert(theMother);
812 }
813 }
814
816
818 auto endVtx = thePart->end_vertex();
819 if (!endVtx) return;
820 for (const auto& theDaughter: endVtx->particles_out()) {
821 if (!theDaughter) continue;
823 allstabledescendants.insert(theDaughter);
824 }
826 }
827 }
828
832
834 if (pVert == nullptr) return false;
836 int numOfPartIn(0);
837 int pdg(0);
838
839 do {
840 pVert = pV;
841 auto incoming = pVert->particles_in();
842 numOfPartIn = incoming.size();
843 pdg = numOfPartIn && incoming.front() != nullptr ? incoming.front()->pdg_id() : 0;
844 pV = numOfPartIn && incoming.front() != nullptr ? incoming.front()->production_vertex() : nullptr;
845
846 } while (numOfPartIn == 1 && (std::abs(pdg) < 81 || std::abs(pdg) > 100) && pV != nullptr);
847
848 if (numOfPartIn == 2) {
849 auto incoming = pVert->particles_in();
850 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;
851 }
852 return false;
853}
854
858
859 template <class T, class U>
860 bool isFromHadron(T p, U hadron,
bool &fromTau,
bool &fromBSM) {
862 auto vtx =
p->production_vertex();
863 if (!vtx) return false;
864 bool fromHad = false;
866 if (!parent) continue;
867
868
869 fromBSM |=
isBSM(parent);
871 fromTau |=
isTau(parent);
874 return true;
875 }
876 fromHad |=
isFromHadron(parent, hadron, fromTau, fromBSM);
877 }
878 return fromHad;
879 }
880
883
885 decltype(thePart->end_vertex()) EndVert = thePart->end_vertex();
886 decltype(thePart->end_vertex()) pVert(nullptr);
887 if (EndVert != nullptr) {
888 do {
889 bool samePart = false;
890 pVert = nullptr;
891 auto outgoing = EndVert->particles_out();
892 auto incoming = EndVert->particles_in();
893 for (const auto& itrDaug: outgoing) {
894 if (!itrDaug) continue;
896
897 (outgoing.size() == 1 && incoming.size() == 1 &&
899 itrDaug->pdg_id() == thePart->pdg_id()) {
900 samePart = true;
901 pVert = itrDaug->end_vertex();
902 }
903 }
904 if (samePart) EndVert = pVert;
905 } while (pVert != nullptr && pVert != EndVert);
906 }
907 return EndVert;
908 }
909
911
913 if (!theVert) return {};
914 decltype(theVert->particles_out()) finalStatePart;
915 auto outgoing = theVert->particles_out();
916 for (const auto& thePart: outgoing) {
917 if (!thePart) continue;
918 finalStatePart.push_back(thePart);
921 if (pVert == theVert) break;
922 if (pVert != nullptr) {
924 finalStatePart.insert(finalStatePart.end(),vecPart.begin(),vecPart.end());
925 }
926 }
927 return finalStatePart;
928 }
929#if !defined(XAOD_ANALYSIS)
931#ifdef HEPMC3
932inline void GeVToMeV(HepMC::GenEvent* evt) {
for (
auto& p:
evt->particles()) {
p->set_momentum(
p->momentum()*1000);
p->set_generated_mass(1000*
p->generated_mass());}}
933inline 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());} }
934#else
935inline void GeVToMeV(HepMC::GenEvent* evt) {
936 for (HepMC::GenEvent::particle_iterator p =
evt->particles_begin(); p !=
evt->particles_end(); ++p) {
937 const HepMC::FourVector fv((*p)->momentum().px() * 1000,
938 (*p)->momentum().py() * 1000,
939 (*p)->momentum().pz() * 1000,
940 (*p)->momentum().e() * 1000);
941 (*p)->set_momentum(fv);
942 (*p)->set_generated_mass(1000 * (*p)->generated_mass());
943 }
944}
945inline void MeVToGeV(HepMC::GenEvent* evt) {
946 for (HepMC::GenEvent::particle_iterator p =
evt->particles_begin(); p !=
evt->particles_end(); ++p) {
947 const HepMC::FourVector fv((*p)->momentum().px() / 1000,
948 (*p)->momentum().py() / 1000,
949 (*p)->momentum().pz() / 1000,
950 (*p)->momentum().e() / 1000);
951 (*p)->set_momentum(fv);
952 (*p)->set_generated_mass((*p)->generated_mass() / 1000);
953 }
954}
955#endif
956#endif
957}
958#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.