RivetHepMC.hh
Go to the documentation of this file.
00001 // -*- C++ -*- 00002 #ifndef RIVET_RivetHepMC_HH 00003 #define RIVET_RivetHepMC_HH 00004 00005 #include "HepMC/GenEvent.h" 00006 #include "HepMC/GenParticle.h" 00007 #include "HepMC/GenVertex.h" 00008 #include "HepMC/GenRanges.h" 00009 #include "HepMC/IO_GenEvent.h" 00010 #include "Rivet/Tools/RivetSTL.hh" 00011 #include "Rivet/Exceptions.hh" 00012 00013 namespace Rivet { 00014 00015 00016 using HepMC::GenEvent; 00017 using HepMC::GenParticle; 00018 using HepMC::GenVertex; 00019 00020 00021 /// @todo Use mcutils 00022 00023 00024 inline std::vector<GenParticle const *> particles(const GenEvent* ge) { 00025 assert(ge); 00026 std::vector<const GenParticle*> rtn; 00027 for (GenEvent::particle_const_iterator pi = ge->particles_begin(); pi != ge->particles_end(); ++pi) 00028 rtn.push_back(*pi); 00029 return rtn; 00030 } 00031 00032 inline std::vector<GenParticle*> particles(GenEvent* ge) { 00033 assert(ge); 00034 std::vector<GenParticle*> rtn; 00035 for (GenEvent::particle_iterator pi = ge->particles_begin(); pi != ge->particles_end(); ++pi) 00036 rtn.push_back(*pi); 00037 return rtn; 00038 } 00039 00040 00041 inline std::vector<const GenVertex*> vertices(const GenEvent* ge) { 00042 std::vector<GenVertex const *> rtn; 00043 for (GenEvent::vertex_const_iterator vi = ge->vertices_begin(); vi != ge->vertices_end(); ++vi) 00044 rtn.push_back(*vi); 00045 return rtn; 00046 } 00047 00048 inline std::vector<GenVertex*> vertices(GenEvent* ge) { 00049 std::vector<GenVertex*> rtn; 00050 for (GenEvent::vertex_iterator vi = ge->vertices_begin(); vi != ge->vertices_end(); ++vi) 00051 rtn.push_back(*vi); 00052 return rtn; 00053 } 00054 00055 00056 ////////////////////////// 00057 00058 00059 inline std::vector<const GenParticle*> particles(const GenVertex* gv, HepMC::IteratorRange range=HepMC::relatives) { 00060 std::vector<GenParticle const *> rtn; 00061 /// @todo A particle_const_iterator on GenVertex would be nice... 00062 // Before HepMC 2.7.0 there were no GV::particles_const_iterators and constness consistency was all screwed up :-/ 00063 #if HEPMC_VERSION_CODE >= 2007000 00064 // for (GenVertex::particle_iterator pi = gv->particles_const_begin(range); pi != gv->particles_const_end(range); ++pi) 00065 for (GenVertex::particle_iterator pi = gv->particles_begin(range); pi != gv->particles_end(range); ++pi) 00066 rtn.push_back(*pi); 00067 #else 00068 GenVertex* gv2 = const_cast<GenVertex*>(gv); 00069 for (GenVertex::particle_iterator pi = gv2->particles_begin(range); pi != gv2->particles_end(range); ++pi) 00070 rtn.push_back(const_cast<const GenParticle*>(*pi)); 00071 #endif 00072 return rtn; 00073 } 00074 00075 inline std::vector<GenParticle*> particles(GenVertex* gv, HepMC::IteratorRange range=HepMC::relatives) { 00076 std::vector<GenParticle*> rtn; 00077 for (GenVertex::particle_iterator pi = gv->particles_begin(range); pi != gv->particles_end(range); ++pi) 00078 rtn.push_back(*pi); 00079 return rtn; 00080 } 00081 00082 00083 inline std::pair<GenVertex::particles_in_const_iterator, GenVertex::particles_in_const_iterator> 00084 particles_in(const GenVertex* gv) { 00085 return make_pair(gv->particles_in_const_begin(), gv->particles_in_const_end()); 00086 } 00087 00088 #if HEPMC_VERSION_CODE >= 2007000 00089 inline std::pair<GenVertex::particles_in_iterator, GenVertex::particles_in_iterator> 00090 particles_in(GenVertex* gv) { 00091 return make_pair(gv->particles_in_begin(), gv->particles_in_end()); 00092 } 00093 #endif 00094 00095 inline std::pair<GenVertex::particles_out_const_iterator, GenVertex::particles_out_const_iterator> 00096 particles_out(const GenVertex* gv) { 00097 return make_pair(gv->particles_out_const_begin(), gv->particles_out_const_end()); 00098 } 00099 00100 #if HEPMC_VERSION_CODE >= 2007000 00101 inline std::pair<GenVertex::particles_out_iterator, GenVertex::particles_out_iterator> 00102 particles_out(GenVertex* gv) { 00103 return make_pair(gv->particles_out_begin(), gv->particles_out_end()); 00104 } 00105 #endif 00106 00107 ////////////////////////// 00108 00109 00110 /// Get the direct parents or all-ancestors of GenParticle @a gp 00111 inline std::vector<const GenParticle*> particles_in(const GenParticle* gp, HepMC::IteratorRange range=HepMC::ancestors) { 00112 if (range != HepMC::parents && range != HepMC::ancestors) 00113 throw UserError("Requested particles_in(GenParticle*) with a non-'in' iterator range"); 00114 if (!gp->production_vertex()) return std::vector<const GenParticle*>(); 00115 #if HEPMC_VERSION_CODE >= 2007000 00116 return particles(gp->production_vertex(), range); 00117 #else 00118 // Before HepMC 2.7.0 the constness consistency of methods and their return types was all screwed up :-/ 00119 std::vector<const GenParticle*> rtn; 00120 foreach (GenParticle* gp2, particles(gp->production_vertex(), range)) 00121 rtn.push_back( const_cast<const GenParticle*>(gp2) ); 00122 return rtn; 00123 #endif 00124 } 00125 00126 /// Get the direct parents or all-ancestors of GenParticle @a gp 00127 inline std::vector<GenParticle*> particles_in(GenParticle* gp, HepMC::IteratorRange range=HepMC::ancestors) { 00128 if (range != HepMC::parents && range != HepMC::ancestors) 00129 throw UserError("Requested particles_in(GenParticle*) with a non-'in' iterator range"); 00130 return (gp->production_vertex()) ? particles(gp->production_vertex(), range) : std::vector<GenParticle*>(); 00131 } 00132 00133 00134 /// Get the direct children or all-descendents of GenParticle @a gp 00135 inline std::vector<const GenParticle*> particles_out(const GenParticle* gp, HepMC::IteratorRange range=HepMC::descendants) { 00136 if (range != HepMC::children && range != HepMC::descendants) 00137 throw UserError("Requested particles_out(GenParticle*) with a non-'out' iterator range"); 00138 if (!gp->end_vertex()) return std::vector<const GenParticle*>(); 00139 #if HEPMC_VERSION_CODE >= 2007000 00140 return particles(gp->end_vertex(), range); 00141 #else 00142 // Before HepMC 2.7.0 the constness consistency of methods and their return types was all screwed up :-/ 00143 std::vector<const GenParticle*> rtn; 00144 foreach (GenParticle* gp2, particles(gp->end_vertex(), range)) 00145 rtn.push_back( const_cast<const GenParticle*>(gp2) ); 00146 return rtn; 00147 #endif 00148 } 00149 00150 /// Get the direct children or all-descendents of GenParticle @a gp 00151 inline std::vector<GenParticle*> particles_out(GenParticle* gp, HepMC::IteratorRange range=HepMC::descendants) { 00152 if (range != HepMC::children && range != HepMC::descendants) 00153 throw UserError("Requested particles_out(GenParticle*) with a non-'out' iterator range"); 00154 return (gp->end_vertex()) ? particles(gp->end_vertex(), range) : std::vector<GenParticle*>(); 00155 } 00156 00157 00158 } 00159 00160 #endif Generated on Wed Oct 7 2015 12:09:14 for The Rivet MC analysis system by ![]() |