StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Pythia8Rivet.h
1 // Pythia8Rivet.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2018 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 #ifndef PYTHIA8RIVET_H
7 #define PYTHIA8RIVET_H
8 
9 #include "Pythia8/HIUserHooks.h"
10 #include "Pythia8Plugins/HepMC2.h"
11 #include "HepMC/GenEvent.h"
12 #include "HepMC/IO_GenEvent.h"
13 #include <set>
14 #include <vector>
15 #include <string>
16 #include "Rivet/Rivet.hh"
17 
18 namespace Pythia8 {
19 
20 using namespace std;
21 
33 class Pythia8Rivet {
34 
35 public:
36 
41  Pythia8Rivet(Pythia & pytin, string fname)
42  : pythia(&pytin), filename(fname), rivet(0) {}
43 
49  done();
50  }
51 
56  void addAnalysis(string ana) {
57  analyses.insert(ana);
58  }
59 
63  void addRunName(const string runname) {
64  rname = runname;
65  }
69  void init(const HepMC::GenEvent & gev) {
70  if ( rivet ) return;
71  rivet = new Rivet::AnalysisHandler(rname);
72  Rivet::addAnalysisLibPath(".");
73  vector<string> anals(analyses.begin(), analyses.end());
74  rivet->addAnalyses(anals);
75  rivet->init(gev);
76  }
77 
82  void operator()() {
83  this->operator()(pythia->event, -1, &pythia->info, &pythia->settings);
84  }
85 
89  void operator()(Event & event, int ievnum = -1, Pythia8::Info* pyinfo = 0,
90  Pythia8::Settings* pyset = 0, bool append = false,
91  HepMC::GenParticle* rootParticle = 0, int iBarcode = -1) {
92  HepMC::GenEvent geneve;
93  converter.fill_next_event(event, &geneve, ievnum, pyinfo, pyset,
94  append, rootParticle, iBarcode);
95  if ( pyinfo && pyinfo->hiinfo ) {
96  HepMC::HeavyIon ion;
97  ion.set_Ncoll_hard(pyinfo->hiinfo->nCollNDTot());
98  ion.set_Ncoll(pyinfo->hiinfo->nAbsProj() +
99  pyinfo->hiinfo->nDiffProj() +
100  pyinfo->hiinfo->nAbsTarg() +
101  pyinfo->hiinfo->nDiffTarg() -
102  pyinfo->hiinfo->nCollND() -
103  pyinfo->hiinfo->nCollDD());
104  ion.set_Npart_proj(pyinfo->hiinfo->nAbsProj() +
105  pyinfo->hiinfo->nDiffProj());
106  ion.set_Npart_targ(pyinfo->hiinfo->nAbsTarg() +
107  pyinfo->hiinfo->nDiffTarg());
108  ion.set_impact_parameter(pyinfo->hiinfo->b());
109  geneve.set_heavy_ion(ion);
110  }
111  if ( !rivet ) init(geneve);
112  rivet->analyze(geneve);
113  }
114 
119  void done() {
120  if ( !rivet ) return;
121  rivet->finalize();
122  rivet->writeData(filename);
123  delete rivet;
124  rivet = 0;
125  }
126 
127 private:
128 
132  Pythia * pythia;
133 
137  string filename;
138 
142  set<string> analyses;
143 
147  Rivet::AnalysisHandler * rivet;
148 
152  HepMC::Pythia8ToHepMC converter;
153 
157  string rname;
158 
159 };
160 
161 }
162 
163 #endif
void addRunName(const string runname)
Definition: Pythia8Rivet.h:63
void operator()(Event &event, int ievnum=-1, Pythia8::Info *pyinfo=0, Pythia8::Settings *pyset=0, bool append=false, HepMC::GenParticle *rootParticle=0, int iBarcode=-1)
Definition: Pythia8Rivet.h:89
void set_impact_parameter(const float &f)
set Impact Parameter in fm
Definition: HeavyIon.h:138
void set_Npart_proj(const int &i)
set number of projectile participants
Definition: HeavyIon.h:121
void init(const HepMC::GenEvent &gev)
Definition: Pythia8Rivet.h:69
void set_Npart_targ(const int &i)
set number of target participants
Definition: HeavyIon.h:123
Pythia8Rivet(Pythia &pytin, string fname)
Definition: Pythia8Rivet.h:41
void set_Ncoll(const int &i)
set number of NN (nucleon-nucleon) collisions
Definition: HeavyIon.h:125
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
void addAnalysis(string ana)
Definition: Pythia8Rivet.h:56
void set_heavy_ion(const HeavyIon &ion)
provide a pointer to the HeavyIon container
Definition: GenEvent.h:758
void set_Ncoll_hard(const int &i)
set number of hard scatterings
Definition: HeavyIon.h:119
The HeavyIon class stores information about heavy ions.
Definition: HeavyIon.h:45
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60