2 #ifndef RIVET_RivetHepMC_HH 3 #define RIVET_RivetHepMC_HH 5 #include "HepMC/GenEvent.h" 6 #include "HepMC/GenParticle.h" 7 #include "HepMC/GenVertex.h" 8 #include "HepMC/GenRanges.h" 9 #include "HepMC/IO_GenEvent.h" 10 #include "Rivet/Tools/RivetSTL.hh" 11 #include "Rivet/Tools/Exceptions.hh" 16 using HepMC::GenEvent;
17 using HepMC::GenParticle;
18 using HepMC::GenVertex;
20 #if HEPMC_VERSION_CODE >= 3000000 21 using HepMC::GenEventPtr;
22 using HepMC::GenParticlePtr;
23 using HepMC::GenVertexPtr;
24 #elif HEPMC_VERSION_CODE >= 2007000 27 #define GenEventPtr GenEvent* 28 #define GenParticlePtr GenParticle* 29 #define GenVertexPtr GenVertex* 36 inline std::vector<GenParticle const *>
particles(
const GenEvent* ge) {
38 std::vector<const GenParticle*> rtn;
39 for (GenEvent::particle_const_iterator pi = ge->particles_begin(); pi != ge->particles_end(); ++pi)
44 inline std::vector<GenParticlePtr>
particles(GenEvent* ge) {
46 std::vector<GenParticle*> rtn;
47 for (GenEvent::particle_iterator pi = ge->particles_begin(); pi != ge->particles_end(); ++pi)
53 inline std::vector<const GenVertex*> vertices(
const GenEvent* ge) {
54 std::vector<GenVertex const *> rtn;
55 for (GenEvent::vertex_const_iterator vi = ge->vertices_begin(); vi != ge->vertices_end(); ++vi)
60 inline std::vector<GenVertex*> vertices(GenEvent* ge) {
61 std::vector<GenVertex*> rtn;
62 for (GenEvent::vertex_iterator vi = ge->vertices_begin(); vi != ge->vertices_end(); ++vi)
71 inline std::vector<const GenParticle*>
particles(
const GenVertex* gv, HepMC::IteratorRange range=HepMC::relatives) {
72 std::vector<GenParticle const *> rtn;
75 #if HEPMC_VERSION_CODE >= 2007000 77 for (GenVertex::particle_iterator pi = gv->particles_begin(range); pi != gv->particles_end(range); ++pi)
80 GenVertex* gv2 =
const_cast<GenVertex*
>(gv);
81 for (GenVertex::particle_iterator pi = gv2->particles_begin(range); pi != gv2->particles_end(range); ++pi)
82 rtn.push_back(const_cast<const GenParticle*>(*pi));
87 inline std::vector<GenParticle*>
particles(GenVertex* gv, HepMC::IteratorRange range=HepMC::relatives) {
88 std::vector<GenParticle*> rtn;
89 for (GenVertex::particle_iterator pi = gv->particles_begin(range); pi != gv->particles_end(range); ++pi)
99 typedef vector<GenParticle*>::const_iterator genvertex_particles_const_iterator;
100 GenVertexIterRangeC(
const genvertex_particles_const_iterator& begin,
const genvertex_particles_const_iterator& end)
101 : _begin(begin), _end(end) { }
102 const genvertex_particles_const_iterator& begin() {
return _begin; }
103 const genvertex_particles_const_iterator& end() {
return _end; }
105 const genvertex_particles_const_iterator _begin, _end;
113 return GenVertexIterRangeC(gv->particles_out_const_begin(), gv->particles_out_const_end());
118 #if HEPMC_VERSION_CODE >= 2007000 122 struct GenVertexIterRange {
123 typedef vector<GenParticle*>::iterator genvertex_particles_iterator;
124 GenVertexIterRange(
const genvertex_particles_iterator& begin,
const genvertex_particles_iterator& end)
125 : _begin(begin), _end(end) { }
126 const genvertex_particles_iterator& begin() {
return _begin; }
127 const genvertex_particles_iterator& end() {
return _end; }
129 const genvertex_particles_iterator _begin, _end;
132 inline GenVertexIterRange particles_in(GenVertex* gv) {
133 return GenVertexIterRange(gv->particles_in_begin(), gv->particles_in_end());
136 inline GenVertexIterRange particles_out(GenVertex* gv) {
137 return GenVertexIterRange(gv->particles_out_begin(), gv->particles_out_end());
147 inline std::vector<const GenParticle*> particles_in(
const GenParticle* gp, HepMC::IteratorRange range=HepMC::ancestors) {
148 if (range != HepMC::parents && range != HepMC::ancestors)
149 throw UserError(
"Requested particles_in(GenParticle*) with a non-'in' iterator range");
150 if (!gp->production_vertex())
return std::vector<const GenParticle*>();
151 #if HEPMC_VERSION_CODE >= 2007000 152 return particles(gp->production_vertex(), range);
155 std::vector<const GenParticle*> rtn;
156 foreach (GenParticle* gp2,
particles(gp->production_vertex(), range))
157 rtn.push_back( const_cast<const GenParticle*>(gp2) );
163 inline std::vector<GenParticle*> particles_in(GenParticle* gp, HepMC::IteratorRange range=HepMC::ancestors) {
164 if (range != HepMC::parents && range != HepMC::ancestors)
165 throw UserError(
"Requested particles_in(GenParticle*) with a non-'in' iterator range");
166 return (gp->production_vertex()) ?
particles(gp->production_vertex(), range) : std::vector<GenParticle*>();
171 inline std::vector<const GenParticle*> particles_out(
const GenParticle* gp, HepMC::IteratorRange range=HepMC::descendants) {
172 if (range != HepMC::children && range != HepMC::descendants)
173 throw UserError(
"Requested particles_out(GenParticle*) with a non-'out' iterator range");
174 if (!gp->end_vertex())
return std::vector<const GenParticle*>();
175 #if HEPMC_VERSION_CODE >= 2007000 176 return particles(gp->end_vertex(), range);
179 std::vector<const GenParticle*> rtn;
180 foreach (GenParticle* gp2,
particles(gp->end_vertex(), range))
181 rtn.push_back( const_cast<const GenParticle*>(gp2) );
187 inline std::vector<GenParticle*> particles_out(GenParticle* gp, HepMC::IteratorRange range=HepMC::descendants) {
188 if (range != HepMC::children && range != HepMC::descendants)
189 throw UserError(
"Requested particles_out(GenParticle*) with a non-'out' iterator range");
190 return (gp->end_vertex()) ?
particles(gp->end_vertex(), range) : std::vector<GenParticle*>();
195 inline std::vector<const GenParticle*>
particles(
const GenParticle* gp, HepMC::IteratorRange range=HepMC::ancestors) {
196 if (range == HepMC::parents || range == HepMC::ancestors)
197 return particles_in(gp, range);
198 if (range == HepMC::children || range == HepMC::descendants)
199 return particles_in(gp, range);
200 throw UserError(
"Requested particles(GenParticle*) with an unsupported iterator range");
Definition: ALICE_2010_I880049.cc:13
Error specialisation for where the problem is between the chair and the computer. ...
Definition: Exceptions.hh:55
std::vector< GenParticle const * > particles(const GenEvent *ge)
Definition: RivetHepMC.hh:36
Definition: RivetHepMC.hh:98