Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HepMCFlowAfterBurner.C
Go to the documentation of this file.
1 //
2 // Inspired by code from ATLAS. Thanks!
3 //
4 #include "HepMCFlowAfterBurner.h"
5 
6 #include <PHHepMCGenEvent.h>
7 
8 #include <Fun4AllReturnCodes.h>
9 #include <getClass.h>
10 #include <phool.h>
11 
12 #include <iostream>
13 #include <cstdlib>
14 #include <string>
15 #include <memory>
16 
17 #include <HepMC/GenEvent.h>
18 
19 #include <CLHEP/Random/RandomEngine.h>
20 #include <CLHEP/Random/MTwistEngine.h>
21 #include <CLHEP/Random/RandFlat.h>
22 #include <CLHEP/Vector/LorentzVector.h>
23 #include <CLHEP/Geometry/Point3D.h>
24 
25 #include <boost/property_tree/ptree.hpp>
26 #include <boost/property_tree/xml_parser.hpp>
27 #include <boost/foreach.hpp>
28 #include <boost/lexical_cast.hpp>
29 
30 #include <flowAfterburner.h>
31 
32 using namespace std;
33 
34 CLHEP::HepRandomEngine * engine = NULL;
35 
36 HepMCFlowAfterBurner::HepMCFlowAfterBurner(const std::string &name):
37  SubsysReco(name),
38  config_filename("flowAfterburner.xml"),
39  algorithmName("JJNEW"),
40  mineta(-1),
41  maxeta(-1),
42  mineta_macro(NAN),
43  maxeta_macro(NAN),
44  minpt(0.),
45  maxpt(100.),
46  minpt_macro(NAN),
47  maxpt_macro(NAN),
48  seedset(0),
49  seed(0),
50  randomSeed(11793)
51 {}
52 
53 
54 int
56 {
57 
58  using boost::property_tree::ptree;
59  ptree pt;
60 
61  std::ifstream config_file(config_filename.c_str());
62 
63  if (config_file)
64  {
65  // Read XML configuration file.
66  read_xml (config_file, pt);
67  }
68  if (seedset)
69  {
70  randomSeed = seed;
71  }
72  else
73  {
74  randomSeed = pt.get ("FLOWAFTERBURNER.RANDOM.SEED", randomSeed);
75  }
76 
77  engine = new CLHEP::MTwistEngine (randomSeed);
78 
79  if (isfinite(mineta_macro))
80  {
81  mineta = mineta_macro;
82  }
83  else
84  {
85  mineta = pt.get("FLOWAFTERBURNER.CUTS.MINETA", mineta);
86  }
87  if (isfinite(maxeta_macro))
88  {
89  maxeta = maxeta_macro;
90  }
91  else
92  {
93  maxeta = pt.get("FLOWAFTERBURNER.CUTS.MAXETA", maxeta);
94  }
95  if (isfinite(minpt_macro))
96  {
97  minpt = minpt_macro;
98  }
99  else
100  {
101  minpt = pt.get("FLOWAFTERBURNER.CUTS.MINPT", minpt);
102  }
103 
104  if (isfinite(maxpt_macro))
105  {
106  maxpt = maxpt_macro;
107  }
108  else
109  {
110  maxpt = pt.get("FLOWAFTERBURNER.CUTS.MAXPT", maxpt);
111  }
112 
113  if (algorithmName_macro.size() > 0)
114  {
115  algorithmName = algorithmName_macro;
116  }
117  else
118  {
119  algorithmName = pt.get("FLOWAFTERBURNER.ALGORITHM", algorithmName);
120  }
121 
122  return 0;
123 }
124 
125 int
127 {
128  PHHepMCGenEvent *genevt = findNode::getClass<PHHepMCGenEvent>(topNode,"PHHepMCGenEvent");
129  HepMC::GenEvent *evt = genevt->getEvent();
130  if (!evt)
131  {
132  cout << PHWHERE << " no evt pointer under HEPMC Node found" << endl;
133  return ABORTEVENT;
134  }
135  if (verbosity > 0)
136  {
137  cout << "calling flowAfterburner with algorithm "
138  << algorithmName << ", mineta " << mineta
139  << ", maxeta: " << maxeta << ", minpt: " << minpt
140  << ", maxpt: " << maxpt << endl;
141  }
142  flowAfterburner(evt, engine, algorithmName, mineta, maxeta, minpt, maxpt);
143  return EVENT_OK;
144 }
145 
146 void
147 HepMCFlowAfterBurner::setSeed(const long il)
148 {
149  seedset = 1;
150  seed = il;
151  randomSeed = seed;
152  // just in case we are already running, kill the engine and make
153  // a new one using the selected seed
154  if (engine)
155  {
156  delete engine;
157  engine = new CLHEP::MTwistEngine (randomSeed);
158  }
159  return;
160 }
161 
162 void
163 HepMCFlowAfterBurner::SaveRandomState(const string &savefile)
164 {
165  if (engine)
166  {
167  engine->saveStatus(savefile.c_str());
168  return;
169  }
170  cout << PHWHERE << " Radom engine not started yet" << endl;
171 }
172 
173 void
174 HepMCFlowAfterBurner::RestoreRandomState(const string &savefile)
175 {
176  if (engine)
177  {
178  engine->restoreStatus(savefile.c_str());
179  return;
180  }
181  cout << PHWHERE << " Radom engine not started yet" << endl;
182 }
virtual int process_event(PHCompositeNode *)
Definition: SubsysReco.h:52
virtual int Init(PHCompositeNode *)
Definition: SubsysReco.h:41
int verbosity
The verbosity level. 0 means not verbose at all.
Definition: Fun4AllBase.h:75
#define PHWHERE
Definition: phool.h:23
CLHEP::HepRandomEngine * engine
virtual HepMC::GenEvent * getEvent()
#define NULL
Definition: Pdb.h:9
HepMCFlowAfterBurner(const std::string &name="HEPMCFLOW")