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