Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4AllHepMCPileupInputManager.cc
Go to the documentation of this file.
2 
6 #include <phool/getClass.h>
7 #include <phool/recoConsts.h>
8 
9 #include <ffaobjects/RunHeader.h>
10 #include "PHHepMCGenEvent.h"
11 #include "PHHepMCGenEventMap.h"
12 
13 #include <frog/FROG.h>
14 #include <phool/PHCompositeNode.h>
15 #include <phool/PHDataNode.h>
16 #include <phool/PHRandomSeed.h>
17 
18 #include <HepMC/GenEvent.h>
19 #include <HepMC/IO_GenEvent.h>
20 
21 #include <TPRegexp.h>
22 #include <TString.h>
23 
24 #include <fstream>
25 #include <iostream>
26 #include <istream>
27 #include <sstream>
28 
29 #include <boost/iostreams/filter/bzip2.hpp>
30 #include <boost/iostreams/filter/gzip.hpp>
31 #include <boost/iostreams/filtering_streambuf.hpp>
32 
33 #include <cstdlib>
34 #include <memory>
35 
36 #include <gsl/gsl_const.h>
37 #include <gsl/gsl_randist.h>
38 #include <gsl/gsl_rng.h>
39 
40 using namespace std;
41 
43  const string &name, const string &nodename, const string &topnodename)
44  : Fun4AllHepMCInputManager(name, nodename, topnodename)
45  , _min_integration_time(-17500.0)
46  , _max_integration_time(+17500.0)
47  , _collision_rate(100.0e3)
48  , _time_between_crossings(106.0)
49  , _ave_coll_per_crossing(1.0)
50  , // recalculated
51  _min_crossing(0)
52  , // recalculated
53  _max_crossing(0)
54  , // recalculated
55  _first_run(true)
56 {
57 
59  Repeat(1);
60 
63 
67  hepmc_helper.set_vertex_distribution_width(100e-4, 100e-4, 30, 5); //100um beam lumi width, 30-cm vertex, 5 ns time spread (~Run14 level)
68 
69  RandomGenerator = gsl_rng_alloc(gsl_rng_mt19937);
70  unsigned int seed = PHRandomSeed(); // fixed seed is handled in this funtcion
71  gsl_rng_set(RandomGenerator, seed);
72 
73  return;
74 }
75 
77 {
78  gsl_rng_free(RandomGenerator);
79 }
80 
82 {
83  if (_first_run)
84  {
85  _first_run = false;
86 
87  _ave_coll_per_crossing = _collision_rate * _time_between_crossings * 1e-9;
88  _min_crossing = _min_integration_time / _time_between_crossings;
89  _max_crossing = _max_integration_time / _time_between_crossings;
90 
91  if (Verbosity() >= VERBOSITY_SOME)
92  {
93  cout << "Fun4AllHepMCPileupInputManager::run:first event: - ";
94  cout << " _ave_coll_per_crossing = " << _ave_coll_per_crossing;
95  cout << " _min_crossing = " << _min_crossing;
96  cout << " _max_crossing = " << _max_crossing;
97  cout << ". Start first event."<<endl;
98  }
99  }
100 
101  // toss multiple crossings all the way back
102  for (int icrossing = _min_crossing; icrossing <= _max_crossing; ++icrossing)
103  {
104  double crossing_time = _time_between_crossings * icrossing;
105 
106  int ncollisions = gsl_ran_poisson(RandomGenerator, _ave_coll_per_crossing);
107  // if (icrossing == 0) --ncollisions; // Jin: this is not necessary.
108  // Triggering an interesting crossing does not change the distribution of the number of background collisions in that crossing
109 
110  for (int icollision = 0; icollision < ncollisions; ++icollision)
111  {
112  double t0 = crossing_time;
113 
114  // loop until retrieve a valid event
115  while (true)
116  {
117  if (!isopen)
118  {
119  if (!filelist.size())
120  {
121  if (verbosity > 0)
122  {
123  cout << Name() << ": No Input file open" << endl;
124  }
125  return -1;
126  }
127  else
128  {
129  if (OpenNextFile())
130  {
131  cout << Name() << ": No Input file from filelist opened" << endl;
132  return -1;
133  }
134  }
135  }
136 
137  if (save_evt)
138  { // if an event was pushed back, copy saved pointer and
139  // reset save_evt pointer
140  evt = save_evt;
141  save_evt = NULL;
142  }
143  else
144  {
145  if (readoscar)
146  {
147  evt = ConvertFromOscar();
148  }
149  else
150  {
151  evt = ascii_in->read_next_event();
152  }
153  }
154 
155  if (!evt)
156  {
157  if (verbosity > 1)
158  {
159  cout << "error type: " << ascii_in->error_type()
160  << ", rdstate: " << ascii_in->rdstate() << endl;
161  }
162  fileclose();
163  }
164  else
165  {
166  mySyncManager->CurrentEvent(evt->event_number());
167  if (verbosity > 0)
168  {
169  cout << "hepmc evt no: " << evt->event_number() << endl;
170  }
171  }
172  events_total++;
173  events_thisfile++;
174  // check if the local SubsysReco discards this event
176  {
177  ResetEvent();
178  // goto readagain;
179  }
180  else
181  {
182  break; // got the evt, move on
183  }
184  } // loop until retrieve a valid event
185 
187  PHHepMCGenEvent *genevent = nullptr;
188  if (hepmc_helper.get_embedding_id() > 0)
189  {
191 
192  genevent = geneventmap->insert_active_event();
193  }
194  else
195  {
197 
198  genevent = geneventmap->insert_background_event();
199  }
200  assert(genevent);
201  genevent->addEvent(evt);
202  hepmc_helper.move_vertex(genevent);
203  // place to the crossing center in time
204  genevent->moveVertex(0, 0, 0, t0);
205 
206  } // for (int icollision = 0; icollision < ncollisions; ++icollision)
207 
208  } // for (int icrossing = _min_crossing; icrossing <= _max_crossing; ++icrossing)
209 
210  return 0;
211 }
PHHepMCGenEventMap is collection of HEPMC events input into this simulation map of embedding ID -&gt; PH...
int verbosity
The verbosity level. 0 means not verbose at all.
Definition: Fun4AllBase.h:75
Fun4AllSyncManager * mySyncManager
std::list< std::string > filelist
bool addEvent(HepMC::GenEvent *evt)
host an HepMC event
void CurrentEvent(const int evt)
virtual void moveVertex(double x, double y, double z, double t=0)
move the collision vertex position in the Hall coordinate system, use PHENIX units of cm...
int get_embedding_id() const
#define NULL
Definition: Pdb.h:9
void set_vertex_distribution_mean(const double x, const double y, const double z, const double t)
set the mean value of the vertex distribution, use PHENIX units of cm, ns
void set_vertex_distribution_function(VTXFUNC x, VTXFUNC y, VTXFUNC z, VTXFUNC t)
toss a new vertex according to a Uniform or Gaus distribution
tuple nevents
Definition: submit_bnl.py:11
virtual const std::string Name() const
Returns the name of this module.
Definition: Fun4AllBase.h:23
void move_vertex(PHHepMCGenEvent *genevent)
move vertex according to vertex settings
Fun4AllHepMCPileupInputManager(const std::string &name="DUMMY", const std::string &nodename="DST", const std::string &topnodename="TOP")
virtual int Verbosity() const
Gets the verbosity of this module.
Definition: Fun4AllBase.h:64
void Repeat(const int i=-1)
PHHepMCGenEvent * insert_active_event(const PHHepMCGenEvent *event=nullptr)
insert a event of interest, e.g. jetty event from pythia
Output some useful messages during manual command line running.
Definition: Fun4AllBase.h:39
const PHHepMCGenEventMap * get_geneventmap() const
PHHepMCGenHelper hepmc_helper
helper for insert HepMC event to DST node and add vertex smearing
void set_vertex_distribution_width(const double x, const double y, const double z, const double t)
set the width of the vertex distribution function about the mean, use PHENIX units of cm...
normal distribution with sigma width set via set_vertex_distribution_width()
void set_embedding_id(int id)
PHHepMCGenEvent * insert_background_event(const PHHepMCGenEvent *event=nullptr)
insert a event of background, e.g. Au+Au collision background. First event has embedding ID = 0...