Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepMCFlowAfterBurner.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HepMCFlowAfterBurner.cc
1 //
2 // Inspired by code from ATLAS. Thanks!
3 //
4 #include "HepMCFlowAfterBurner.h"
5 
6 #include "PHHepMCGenEvent.h"
7 #include "PHHepMCGenEventMap.h"
8 
9 #include <flowafterburner/flowAfterburner.h>
10 
12 #include <fun4all/SubsysReco.h> // for SubsysReco
13 
14 #include <phool/PHRandomSeed.h>
15 #include <phool/getClass.h>
16 #include <phool/phool.h>
17 
18 #include <CLHEP/Random/MTwistEngine.h>
19 #include <CLHEP/Random/RandomEngine.h>
20 
21 #include <iostream>
22 #include <iterator> // for operator!=, reverse_ite...
23 #include <set> // for set, _Rb_tree_const_ite...
24 #include <string>
25 #include <utility> // for pair
26 
27 using namespace std;
28 
29 class PHCompositeNode;
30 namespace HepMC { class GenEvent; }
31 
32 CLHEP::HepRandomEngine *engine = nullptr;
33 
34 set<string> algoset = {"MINBIAS", "MINBIAS_V2_ONLY", "CUSTOM"};
35 
36 // we want to keep the default eta range identical between here and
37 // the flowAfterburner executable. If you change the default eta range here
38 // please apply the same change to generators/flowAfterburner/main.cc
40  : SubsysReco(name)
41 {
42 }
43 
45 {
46  if (seedset)
47  {
48  randomSeed = seed;
49  }
50  else
51  {
53  }
54 
55  engine = new CLHEP::MTwistEngine(randomSeed);
56 
57  return 0;
58 }
59 
61 {
62  PHHepMCGenEventMap *genevtmap = findNode::getClass<PHHepMCGenEventMap>(topNode, "PHHepMCGenEventMap");
63  for (PHHepMCGenEventMap::ReverseIter iter = genevtmap->rbegin(); iter != genevtmap->rend(); ++iter)
64  {
65  PHHepMCGenEvent *genevt = iter->second;
66 
67  HepMC::GenEvent *evt = genevt->getEvent();
68  if (!evt)
69  {
70  cout << PHWHERE << " no evt pointer under HEPMC Node found" << endl;
72  }
73  if (Verbosity() > 0)
74  {
75  cout << "calling flowAfterburner with algorithm "
76  << algorithmName << ", mineta " << mineta
77  << ", maxeta: " << maxeta << ", minpt: " << minpt
78  << ", maxpt: " << maxpt << endl;
79  }
81  }
83 }
84 
85 void HepMCFlowAfterBurner::setSeed(const long il)
86 {
87  seedset = 1;
88  seed = il;
89  randomSeed = seed;
90  // just in case we are already running, kill the engine and make
91  // a new one using the selected seed
92  if (engine)
93  {
94  delete engine;
95  engine = new CLHEP::MTwistEngine(randomSeed);
96  }
97  return;
98 }
99 
100 void HepMCFlowAfterBurner::SaveRandomState(const string &savefile)
101 {
102  if (engine)
103  {
104  engine->saveStatus(savefile.c_str());
105  return;
106  }
107  cout << PHWHERE << " Random engine not started yet" << endl;
108 }
109 
110 void HepMCFlowAfterBurner::RestoreRandomState(const string &savefile)
111 {
112  if (engine)
113  {
114  engine->restoreStatus(savefile.c_str());
115  return;
116  }
117  cout << PHWHERE << " Random engine not started yet" << endl;
118 }
119 
120 void HepMCFlowAfterBurner::Print(const string &/*what*/) const
121 {
122  cout << "FlowAfterBurner parameters:" << endl;
123  cout << "algorithm: " << algorithmName << endl;
124  cout << "mineta: " << mineta << ", maxeta: " << maxeta << endl;
125  cout << "minpt: " << minpt << ", maxpt: " << maxpt << endl;
126  cout << "Implemented algorithms: MINBIAS (default), MINBIAS_V2_ONLY, CUSTOM"
127  << endl;
128  return;
129 }
130 
132 {
133  auto it = algoset.find(name);
134  if (it != algoset.end())
135  {
136  algorithmName = *it;
137  }
138  else
139  {
140  cout << "algorithm " << name << " not in list of possible algorithms" << endl;
141  cout << "possible algorithms are" << endl;
142  for (auto &al : algoset)
143  {
144  cout << al << endl;
145  }
146  }
147  return;
148 }