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) 2020 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 
31 class Pythia8Rivet {
32 
33 public:
34 
39  Pythia8Rivet(Pythia & pytin, string fname)
40  : pythia(&pytin), filename(fname), rivet(0), igBeam(false) {}
41 
47  done();
48  }
49 
54  void addAnalysis(string ana) {
55  analyses.insert(ana);
56  }
57 
61  void addPreload(string prel) {
62  preloads.push_back(prel);
63  }
64 
68  void ignoreBeams(bool flagIn) {
69  igBeam = flagIn;
70  }
71 
75  void addRunName(const string runname) {
76  rname = runname;
77  }
81  void init(const HepMC::GenEvent & gev) {
82  if ( rivet ) return;
83  rivet = new Rivet::AnalysisHandler(rname);
84  rivet->setIgnoreBeams(igBeam);
85  Rivet::addAnalysisLibPath(".");
86  for(int i = 0, N = preloads.size(); i < N; ++i)
87  rivet->readData(preloads[i]);
88  for (set<string>::iterator it = analyses.begin();
89  it != analyses.end(); ++it) {
90  rivet->addAnalysis(*it);
91  }
92  rivet->init(gev);
93  }
94 
99  void operator()() {
100  this->operator()(pythia->event, -1, &pythia->info, &pythia->settings);
101  }
102 
106  void operator()(Event & event, int ievnum = -1,
107  const Pythia8::Info* pyinfo = 0,
108  Pythia8::Settings* pyset = 0, bool append = false,
109  HepMC::GenParticle* rootParticle = 0, int iBarcode = -1) {
110  HepMC::GenEvent geneve;
111  converter.fill_next_event(event, &geneve, ievnum, pyinfo, pyset,
112  append, rootParticle, iBarcode);
113  if ( pyinfo && pyinfo->hiInfo ) {
114  HepMC::HeavyIon ion;
115  ion.set_Ncoll_hard(pyinfo->hiInfo->nCollNDTot());
116  ion.set_Ncoll(pyinfo->hiInfo->nAbsProj() +
117  pyinfo->hiInfo->nDiffProj() +
118  pyinfo->hiInfo->nAbsTarg() +
119  pyinfo->hiInfo->nDiffTarg() -
120  pyinfo->hiInfo->nCollND() -
121  pyinfo->hiInfo->nCollDD());
122  ion.set_Npart_proj(pyinfo->hiInfo->nAbsProj() +
123  pyinfo->hiInfo->nDiffProj());
124  ion.set_Npart_targ(pyinfo->hiInfo->nAbsTarg() +
125  pyinfo->hiInfo->nDiffTarg());
126  ion.set_impact_parameter(pyinfo->hiInfo->b());
127  geneve.set_heavy_ion(ion);
128  }
129  if ( !rivet ) init(geneve);
130  rivet->analyze(geneve);
131  }
132 
137  void done() {
138  if ( !rivet ) return;
139  rivet->finalize();
140  rivet->writeData(filename);
141  delete rivet;
142  rivet = 0;
143  }
144 
145 private:
146 
150  Pythia * pythia;
151 
155  string filename;
156 
160  set<string> analyses;
161 
165  vector<string> preloads;
166 
170  Rivet::AnalysisHandler * rivet;
171 
175  HepMC::Pythia8ToHepMC converter;
176 
180  string rname;
181 
185  bool igBeam;
186 
187 };
188 
189 }
190 
191 #endif
void addRunName(const string runname)
Definition: Pythia8Rivet.h:75
void ignoreBeams(bool flagIn)
Definition: Pythia8Rivet.h:68
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:81
void set_Npart_targ(const int &i)
set number of target participants
Definition: HeavyIon.h:123
Pythia8Rivet(Pythia &pytin, string fname)
Definition: Pythia8Rivet.h:39
void operator()(Event &event, int ievnum=-1, const Pythia8::Info *pyinfo=0, Pythia8::Settings *pyset=0, bool append=false, HepMC::GenParticle *rootParticle=0, int iBarcode=-1)
Definition: Pythia8Rivet.h:106
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:54
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
void addPreload(string prel)
Definition: Pythia8Rivet.h:61
The HeavyIon class stores information about heavy ions.
Definition: HeavyIon.h:45
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60