Skip to content

Commit 6ce8551

Browse files
authored
Merge pull request #47604 from mkirsano/hepmc3togenparticles
Add reco::GenParticle collection production from HepMC3 event record
2 parents b043e2f + 7860371 commit 6ce8551

File tree

5 files changed

+248
-31
lines changed

5 files changed

+248
-31
lines changed

PhysicsTools/HepMCCandAlgos/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<use name="DataFormats/HepMCCandidate"/>
44
<use name="CommonTools/UtilAlgos"/>
55
<use name="hepmc"/>
6+
<use name="hepmc3"/>
67
<use name="eigen"/>
78
<use name="CLHEP"/>
89
<export>

PhysicsTools/HepMCCandAlgos/interface/MCTruthHelper.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
77
#include "DataFormats/HepMCCandidate/interface/GenStatusFlags.h"
88

9+
#include "HepMC3/GenEvent.h"
10+
#include "HepMC3/GenParticle.h"
11+
#include "HepMC3/GenVertex.h"
12+
913
#include <iostream>
1014
#include <unordered_set>
1115

@@ -143,36 +147,54 @@ class MCTruthHelper {
143147
//pdgid
144148
int pdgId(const HepMC::GenParticle &p) const;
145149

150+
//pdgid
151+
int pdgId(const HepMC3::GenParticle &p) const;
152+
146153
//abs(pdgid)
147154
int absPdgId(const reco::GenParticle &p) const;
148155

149156
//abs(pdgid)
150157
int absPdgId(const HepMC::GenParticle &p) const;
151158

159+
//abs(pdgid)
160+
int absPdgId(const HepMC3::GenParticle &p) const;
161+
152162
//number of mothers
153163
unsigned int numberOfMothers(const reco::GenParticle &p) const;
154164

155165
//number of mothers
156166
unsigned int numberOfMothers(const HepMC::GenParticle &p) const;
157167

168+
//number of mothers
169+
unsigned int numberOfMothers(const HepMC3::GenParticle &p) const;
170+
158171
//mother
159172
const reco::GenParticle *mother(const reco::GenParticle &p, unsigned int imoth = 0) const;
160173

161174
//mother
162175
const HepMC::GenParticle *mother(const HepMC::GenParticle &p, unsigned int imoth = 0) const;
163176

177+
//mother
178+
const HepMC3::GenParticle *mother(const HepMC3::GenParticle &p, unsigned int imoth = 0) const;
179+
164180
//number of daughters
165181
unsigned int numberOfDaughters(const reco::GenParticle &p) const;
166182

167183
//number of daughters
168184
unsigned int numberOfDaughters(const HepMC::GenParticle &p) const;
169185

186+
//number of daughters
187+
unsigned int numberOfDaughters(const HepMC3::GenParticle &p) const;
188+
170189
//ith daughter
171190
const reco::GenParticle *daughter(const reco::GenParticle &p, unsigned int idau) const;
172191

173192
//ith daughter
174193
const HepMC::GenParticle *daughter(const HepMC::GenParticle &p, unsigned int idau) const;
175194

195+
//ith daughter
196+
const HepMC3::GenParticle *daughter(const HepMC3::GenParticle &p, unsigned int idau) const;
197+
176198
/////////////////////////////////////////////////////////////////////////////
177199
//Helper function to fill status flags
178200
void fillGenStatusFlags(const P &p, reco::GenStatusFlags &statusFlags) const;
@@ -576,6 +598,12 @@ int MCTruthHelper<P>::pdgId(const HepMC::GenParticle &p) const {
576598
return p.pdg_id();
577599
}
578600

601+
//////////////////////////////////////////////////////////////
602+
template <typename P>
603+
int MCTruthHelper<P>::pdgId(const HepMC3::GenParticle &p) const {
604+
return p.pid();
605+
}
606+
579607
//////////////////////////////////////////////////////////////
580608
template <typename P>
581609
int MCTruthHelper<P>::absPdgId(const reco::GenParticle &p) const {
@@ -588,6 +616,12 @@ int MCTruthHelper<P>::absPdgId(const HepMC::GenParticle &p) const {
588616
return std::abs(p.pdg_id());
589617
}
590618

619+
//////////////////////////////////////////////////////////////
620+
template <typename P>
621+
int MCTruthHelper<P>::absPdgId(const HepMC3::GenParticle &p) const {
622+
return std::abs(p.pid());
623+
}
624+
591625
/////////////////////////////////////////////////////////////////////////////
592626
template <typename P>
593627
unsigned int MCTruthHelper<P>::numberOfMothers(const reco::GenParticle &p) const {
@@ -600,6 +634,12 @@ unsigned int MCTruthHelper<P>::numberOfMothers(const HepMC::GenParticle &p) cons
600634
return p.production_vertex() ? p.production_vertex()->particles_in_size() : 0;
601635
}
602636

637+
/////////////////////////////////////////////////////////////////////////////
638+
template <typename P>
639+
unsigned int MCTruthHelper<P>::numberOfMothers(const HepMC3::GenParticle &p) const {
640+
return p.production_vertex() ? p.production_vertex()->particles_in_size() : 0;
641+
}
642+
603643
/////////////////////////////////////////////////////////////////////////////
604644
template <typename P>
605645
const reco::GenParticle *MCTruthHelper<P>::mother(const reco::GenParticle &p, unsigned int imoth) const {
@@ -614,6 +654,20 @@ const HepMC::GenParticle *MCTruthHelper<P>::mother(const HepMC::GenParticle &p,
614654
: nullptr;
615655
}
616656

657+
/////////////////////////////////////////////////////////////////////////////
658+
template <typename P>
659+
const HepMC3::GenParticle *MCTruthHelper<P>::mother(const HepMC3::GenParticle &p, unsigned int imoth) const {
660+
if (numberOfMothers(p) > 0) {
661+
unsigned int imothi = 0;
662+
for (const HepMC3::ConstGenParticlePtr &mother : (p.production_vertex())->particles_in()) {
663+
if (imothi == imoth)
664+
return mother.get();
665+
imothi++;
666+
}
667+
}
668+
return nullptr;
669+
}
670+
617671
/////////////////////////////////////////////////////////////////////////////
618672
template <typename P>
619673
unsigned int MCTruthHelper<P>::numberOfDaughters(const reco::GenParticle &p) const {
@@ -626,6 +680,12 @@ unsigned int MCTruthHelper<P>::numberOfDaughters(const HepMC::GenParticle &p) co
626680
return p.end_vertex() ? p.end_vertex()->particles_out_size() : 0;
627681
}
628682

683+
/////////////////////////////////////////////////////////////////////////////
684+
template <typename P>
685+
unsigned int MCTruthHelper<P>::numberOfDaughters(const HepMC3::GenParticle &p) const {
686+
return p.end_vertex() ? p.end_vertex()->particles_out_size() : 0;
687+
}
688+
629689
/////////////////////////////////////////////////////////////////////////////
630690
template <typename P>
631691
const reco::GenParticle *MCTruthHelper<P>::daughter(const reco::GenParticle &p, unsigned int idau) const {
@@ -638,6 +698,20 @@ const HepMC::GenParticle *MCTruthHelper<P>::daughter(const HepMC::GenParticle &p
638698
return *(p.end_vertex()->particles_out_const_begin() + idau);
639699
}
640700

701+
/////////////////////////////////////////////////////////////////////////////
702+
template <typename P>
703+
const HepMC3::GenParticle *MCTruthHelper<P>::daughter(const HepMC3::GenParticle &p, unsigned int idau) const {
704+
if (numberOfDaughters(p) > 0) {
705+
unsigned int idaui = 0;
706+
for (const HepMC3::ConstGenParticlePtr &daughter : (p.end_vertex())->particles_out()) {
707+
if (idaui == idau)
708+
return daughter.get();
709+
idaui++;
710+
}
711+
}
712+
return nullptr;
713+
}
714+
641715
/////////////////////////////////////////////////////////////////////////////
642716
template <typename P>
643717
void MCTruthHelper<P>::fillGenStatusFlags(const P &p, reco::GenStatusFlags &statusFlags) const {

0 commit comments

Comments
 (0)