Rivet  3.1.4
RivetHepMC.hh
1 // -*- C++ -*-
2 #ifndef RIVET_RivetHepMC_HH
3 #define RIVET_RivetHepMC_HH
4 
5 #include "Rivet/Config/RivetConfig.hh"
6 #include "Rivet/Tools/RivetSTL.hh"
7 #include "Rivet/Tools/Exceptions.hh"
8 #include <valarray>
9 
10 
11 #ifdef RIVET_ENABLE_HEPMC_3
12 
13 #include "HepMC3/HepMC3.h"
14 #include "HepMC3/Relatives.h"
15 #include "HepMC3/Reader.h"
16 #ifndef HEPMC_HAS_CROSS_SECTION
17 #define HEPMC_HAS_CROSS_SECTION
18 #endif
19 
20 namespace HepMC3 {
21  std::shared_ptr<HepMC3::Reader> deduce_reader(const std::string &filename);
22  std::shared_ptr<HepMC3::Reader> deduce_reader(std::istream &stream);
23 }
24 
25 namespace Rivet {
26  namespace RivetHepMC = HepMC3;
27 
28  using RivetHepMC::ConstGenParticlePtr;
29  using RivetHepMC::ConstGenVertexPtr;
30  using RivetHepMC::Relatives;
31  using RivetHepMC::ConstGenHeavyIonPtr;
32 
33  using HepMC_IO_type = RivetHepMC::Reader;
34  using PdfInfo = RivetHepMC::GenPdfInfo;
35 }
36 
37 #else // HEPMC_2
38 
39 #include "HepMC/GenEvent.h"
40 #include "HepMC/GenParticle.h"
41 #include "HepMC/HeavyIon.h"
42 #include "HepMC/GenVertex.h"
43 #include "HepMC/Version.h"
44 #include "HepMC/GenRanges.h"
45 #include "HepMC/IO_GenEvent.h"
46 namespace Rivet {
47  namespace RivetHepMC = HepMC;
48 
49  // HepMC 2.07 provides its own #defines
50  typedef const HepMC::GenParticle* ConstGenParticlePtr;
51  typedef const HepMC::GenVertex* ConstGenVertexPtr;
52  typedef const HepMC::HeavyIon* ConstGenHeavyIonPtr;
53 
56  class Relatives {
57  public:
58 
59  constexpr Relatives(HepMC::IteratorRange relo): _internal(relo){}
60 
61  constexpr HepMC::IteratorRange operator()() const {return _internal;}
62  operator HepMC::IteratorRange() const {return _internal;}
63 
64  const static Relatives PARENTS;
65  const static Relatives CHILDREN;
66  const static Relatives ANCESTORS;
67  const static Relatives DESCENDANTS;
68 
69  private:
70  const HepMC::IteratorRange _internal;
71 
72  };
73 
74  using HepMC_IO_type = HepMC::IO_GenEvent;
75  using PdfInfo = RivetHepMC::PdfInfo;
76 }
77 
78 #endif
79 
80 
81 namespace Rivet {
82 
83 
84  using RivetHepMC::GenEvent;
85  using ConstGenEventPtr = std::shared_ptr<const GenEvent>;
86 
88  namespace HepMCUtils {
89  ConstGenParticlePtr getParticlePtr(const RivetHepMC::GenParticle & gp);
90  std::vector<ConstGenParticlePtr> particles(ConstGenEventPtr ge);
91  std::vector<ConstGenParticlePtr> particles(const GenEvent *ge);
92  std::vector<ConstGenVertexPtr> vertices(ConstGenEventPtr ge);
93  std::vector<ConstGenVertexPtr> vertices(const GenEvent *ge);
94  std::vector<ConstGenParticlePtr> particles(ConstGenVertexPtr gv, const Relatives &relo);
95  std::vector<ConstGenParticlePtr> particles(ConstGenParticlePtr gp, const Relatives &relo);
96  int uniqueId(ConstGenParticlePtr gp);
97  int particles_size(ConstGenEventPtr ge);
98  int particles_size(const GenEvent* ge);
99  std::pair<ConstGenParticlePtr,ConstGenParticlePtr> beams(const GenEvent* ge);
100  std::shared_ptr<HepMC_IO_type> makeReader(std::string filename, std::shared_ptr<std::istream>& istrp, std::string* errm = 0);
101  bool readEvent(std::shared_ptr<HepMC_IO_type> io, std::shared_ptr<GenEvent> evt);
102  void strip(GenEvent & ge, const set<long>& stripid = {1, -1, 2, -2, 3,-3, 21});
103  vector<string> weightNames(const GenEvent& ge);
104  std::valarray<double> weights(const GenEvent& ge);
105  pair<double,double> crossSection(const GenEvent& ge);
106  }
107 
108 
109 }
110 
111 #endif
Definition: MC_Cent_pPb.hh:10
ParticlePair beams(const Event &e)
Get beam particles from an event.