2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
8 // @TODO: probably replace this by an enum some day
9 #define ISF_UNDEF_CHARGE -99999.
11 #include "AtlasHepMC/GenEvent.h"
12 #include "AtlasHepMC/IteratorRange.h"
13 #include "AtlasHepMC/Relatives.h"
15 ISF::HepMCHelper::HepMCHelper() {
18 /** emtpy destructor */
19 ISF::HepMCHelper::~HepMCHelper() {
23 HepMC::IteratorRange ISF::HepMCHelper::convertIteratorRange( int intItRange ) {
24 if (intItRange==0) return ( HepMC::parents );
25 else if (intItRange==1) return ( HepMC::family );
26 else if (intItRange==2) return ( HepMC::ancestors );
27 else if (intItRange==3) return ( HepMC::relatives );
28 else return ( HepMC::parents );
32 HepMC::ConstGenParticlePtr ISF::HepMCHelper::findRealtiveWithPDG( HepMC::ConstGenParticlePtr& genParticle,
33 const HepMC::IteratorRange &relation,
34 const std::set<int> &relativesPDG ) {
35 // get range of relative particles
36 std::vector<HepMC::ConstGenParticlePtr> relativesRng;
38 case HepMC::parents: {
39 if (genParticle->production_vertex()) relativesRng= genParticle->production_vertex()->particles_in();
43 if (genParticle->production_vertex()) relativesRng= genParticle->production_vertex()->particles_in();
44 std::vector<HepMC::ConstGenParticlePtr> temp;
45 if (genParticle->end_vertex()) temp=genParticle->end_vertex()->particles_out();
46 relativesRng.insert(relativesRng.end(),temp.begin(),temp.end());
49 case HepMC::ancestors: {
50 relativesRng= HepMC::ancestor_particles(genParticle);
53 case HepMC::relatives: {
54 relativesRng= HepMC::ancestor_particles(genParticle);
55 std::vector<HepMC::ConstGenParticlePtr> temp=HepMC::descendant_particles(genParticle);
56 relativesRng.insert(relativesRng.end(),temp.begin(),temp.end());
60 if (genParticle->production_vertex()) relativesRng= genParticle->production_vertex()->particles_in();
64 // loop over relatives
65 for (auto curRelative: relativesRng) {
66 if (relativesPDG.count( curRelative->pdg_id() ) != 0) return curRelative;
72 HepMC::ConstGenParticlePtr ISF::HepMCHelper::findRealtiveWithPDG( HepMC::ConstGenParticlePtr& genParticle,
73 const HepMC::IteratorRange &relation,
74 const std::set<int> &relativesPDG ) {
76 if (!genParticle) return 0;
77 // get range of relative particles
78 HepMC::ConstGenParticleProductionRange relativesRng = genParticle->particles_in( relation );
80 // loop over relatives
81 HepMC::GenVertex::particle_iterator partIt = relativesRng.begin();
82 const HepMC::GenVertex::particle_iterator partEnd = relativesRng.end();
83 HepMC::ConstGenParticlePtr curRelative{};
85 for ( ; (!found) && (partIt!=partEnd) ; ++partIt) {
86 curRelative = (*partIt) ;
87 // check if current relative particle PDG ID is found in the set
88 found = relativesPDG.count( curRelative->pdg_id() ) != 0;
91 return (found ? curRelative : 0);