EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_Cleo.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_Cleo.C
1 #ifndef MACRO_FUN4ALLG4CLEO_C
2 #define MACRO_FUN4ALLG4CLEO_C
3 
4 #include "GlobalVariables.C"
5 
6 #include "DisplayOn.C"
7 #include "G4Setup_Cleo.C"
8 #include "G4_DSTReader_Cleo.C"
9 #include "G4_Input.C"
10 
13 #include <fun4all/Fun4AllServer.h>
14 
15 #include <phool/PHRandomSeed.h>
16 #include <phool/recoConsts.h>
17 
18 R__LOAD_LIBRARY(libfun4all.so)
19 R__LOAD_LIBRARY(libg4testbench.so)
20 
22  const int nEvents = 1,
23  const string &inputFile = "/sphenix/data/data02/review_2017-08-02/single_particle/spacal2d/fieldmap/G4Hits_sPHENIX_e-_eta0_8GeV-0002.root",
24  const string &outputFile = "G4Cleo.root",
25  const string &embed_input_file = "/sphenix/data/data02/review_2017-08-02/sHijing/fm_0-4.list",
26  const int skip = 0,
27  const string &outdir = ".")
28 {
30  se->Verbosity(0);
31 
32  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
34 
35  // just if we set some flags somewhere in this macro
37  // By default every random number generator uses
38  // PHRandomSeed() which reads /dev/urandom to get its seed
39  // if the RANDOMSEED flag is set its value is taken as seed
40  // You can either set this to a random value using PHRandomSeed()
41  // which will make all seeds identical (not sure what the point of
42  // this would be:
43  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
44  // or set it to a fixed value so you can debug your code
45  // rc->set_IntFlag("RANDOMSEED", 12345);
46 
47  //===============
48  // Input options
49  //===============
50  // First enable the input generators
51  // Either:
52  // read previously generated g4-hits files, in this case it opens a DST and skips
53  // the simulations step completely. The G4Setup macro is only loaded to get information
54  // about the number of layers used for the cell reco code
55  // Input::READHITS = true;
56  INPUTREADHITS::filename = inputFile;
57 
58  // Or:
59  // Use particle generator
60  // And
61  // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
62  // In case embedding into a production output, please double check your G4Setup_sPHENIX.C and G4_*.C consistent with those in the production macro folder
63  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
64  // Input::EMBED = true;
65  INPUTEMBED::filename = embed_input_file;
66 
67  Input::SIMPLE = true;
68  //Input::SIMPLE_VERBOSITY = 1;
69 
70  // Input::PYTHIA6 = true;
71 
72  // Input::PYTHIA8 = true;
73 
74  // Input::GUN = true;
75  //Input::GUN_VERBOSITY = 1;
76 
77  // Upsilon generator
78  // Input::UPSILON = true;
80 
81  // Input::HEPMC = true;
82  Input::VERBOSITY = 0;
83  INPUTHEPMC::filename = inputFile;
84 
85  // Event pile up simulation with collision rate in Hz MB collisions.
86  //Input::PILEUPRATE = 100e3;
87 
88  //-----------------
89  // Initialize the selected Input/Event generation
90  //-----------------
91  // This creates the input generator(s)
92  InputInit();
93 
94  //--------------
95  // Set generator specific options
96  //--------------
97  // can only be set after InputInit() is called
98 
99  // Simple Input generator:
100  if (Input::SIMPLE)
101  {
102  INPUTGENERATOR::SimpleEventGenerator->add_particles("pi-", 5);
103  if (Input::HEPMC || Input::EMBED)
104  {
105  INPUTGENERATOR::SimpleEventGenerator->set_reuse_existing_vertex(true);
106  INPUTGENERATOR::SimpleEventGenerator->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
107  }
108  else
109  {
113  INPUTGENERATOR::SimpleEventGenerator->set_vertex_distribution_mean(0., 0., 0.);
114  INPUTGENERATOR::SimpleEventGenerator->set_vertex_distribution_width(0., 0., 5.);
115  }
116  INPUTGENERATOR::SimpleEventGenerator->set_eta_range(-1, 1);
118  INPUTGENERATOR::SimpleEventGenerator->set_pt_range(0.1, 20.);
119  }
120  // Upsilons
121  if (Input::UPSILON)
122  {
123  INPUTGENERATOR::VectorMesonGenerator->add_decay_particles("e", 0);
124  INPUTGENERATOR::VectorMesonGenerator->set_rapidity_range(-1, 1);
125  INPUTGENERATOR::VectorMesonGenerator->set_pt_range(0., 10.);
126  // Y species - select only one, last one wins
127  INPUTGENERATOR::VectorMesonGenerator->set_upsilon_1s();
128  }
129  // particle gun
130  if (Input::GUN)
131  {
132  INPUTGENERATOR::Gun->AddParticle("pi-", 0, 1, 0);
133  INPUTGENERATOR::Gun->set_vtx(0, 0, 0);
134  }
135 
136  //--------------
137  // Set Input Manager specific options
138  //--------------
139  // can only be set after InputInit() is called
140 
141  if (Input::HEPMC)
142  {
143  INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 30, 0); //optional collision smear in space, time
144  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
145  // //optional choice of vertex distribution function in space, time
151  //INPUTMANAGER::HepMCInputManager->set_embedding_id(2);
152  }
153  // register all input generators with Fun4All
154  InputRegister();
155 
156  //======================
157  // Write the DST
158  //======================
159 
160  // Enable::DSTOUT = true;
161  Enable::DSTOUT_COMPRESS = false;
162  DstOut::OutputDir = outdir;
163  DstOut::OutputFile = outputFile;
164 
165  //Option to convert DST to human command readable TTree for quick poke around the outputs
166  Enable::DSTREADER = true;
167 
168  // turn the display on (default off)
169  Enable::DISPLAY = false;
170 
171  //======================
172  // What to run
173  //======================
174 
175  // whether to simulate the Be section of the beam pipe
176  Enable::PIPE = true;
177  Enable::PIPE_ABSORBER = true;
178  // EIC beam pipe extension beyond the Be-section:
180 
181  Enable::MAGNET = true;
183 
184  // new settings using Enable namespace in GlobalVariables.C
185  Enable::BLACKHOLE = true;
186  // leave 1m gap so we can see tracks outside detector, comment out when you
187  // want to use the black hole to measure leakage
188  BlackHoleGeometry::gap = 100.; // leave 1m gap so we can see tracks outside detector
189  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
190  //BlackHoleGeometry::visible = true;
191 
192  // establish the geometry and reconstruction setup
193  G4Init();
194 
195  if (!Input::READHITS)
196  {
197  //---------------------
198  // Detector description
199  //---------------------
200 
201  G4Setup();
202  }
203 
204  string outputroot = outputFile;
205  string remove_this = ".root";
206  size_t pos = outputroot.find(remove_this);
207  if (pos != string::npos)
208  {
209  outputroot.erase(pos, remove_this.length());
210  }
211 
212  if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
213 
214  //--------------
215  // Set up Input Managers
216  //--------------
217 
218  InputManagers();
219 
220  if (Enable::DSTOUT)
221  {
222  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
223  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
225  se->registerOutputManager(out);
226  }
227 
228  //-----------------
229  // Event processing
230  //-----------------
231  if (nEvents < 0)
232  {
233  return 0;
234  }
235  // if we run the particle generator and use 0 it'll run forever
236  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS)
237  {
238  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
239  cout << "it will run forever, so I just return without running anything" << endl;
240  return 0;
241  }
242 
243  if (Enable::DISPLAY)
244  {
245  DisplayOn();
246  // prevent macro from finishing so can see display
247  int i;
248  cout << "***** Enter any integer to proceed" << endl;
249  cin >> i;
250  }
251 
252  se->run(nEvents);
253 
254  //-----
255  // Exit
256  //-----
257 
258  se->End();
259  std::cout << "All done" << std::endl;
260  delete se;
261  gSystem->Exit(0);
262  return 0;
263 }
264 
265 #endif // MACRO_FUN4ALLG4CLEO_C