EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_fsPHENIX.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_fsPHENIX.C
1 #ifndef MACRO_FUN4ALLG4FSPHENIX_C
2 #define MACRO_FUN4ALLG4FSPHENIX_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <DisplayOn.C>
7 #include <G4Setup_fsPHENIX.C>
8 #include <G4_Bbc.C>
9 #include <G4_CaloTrigger.C>
10 #include <G4_DSTReader_fsPHENIX.C>
11 #include <G4_FwdJets.C>
12 #include <G4_Global.C>
13 #include <G4_Input.C>
14 #include <G4_Tracking.C>
15 #include <G4_Jets.C>
16 #include <G4_Production.C>
17 #include <G4_User.C>
18 
21 #include <fun4all/Fun4AllServer.h>
22 
23 #include <phool/recoConsts.h>
24 
25 R__LOAD_LIBRARY(libfun4all.so)
26 
27 // If using the default embedding file results in a error, try
28 // TFile *f1 = TFile::Open("http://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/fsPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root")
29 // if it returns a certificate error, something like
30 // Error in <DavixOpen>: can not open file with davix: Failure (Neon): Server certificate verification failed: bad certificate chain after 3 attempts (6)
31 // add the line
32 // Davix.GSI.CACheck: n
33 // to your .rootrc
34 
36  const int nEvents = 2,
37  const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/fsPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
38  const string &outputFile = "G4fsPHENIX.root",
39  const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/fsPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
40  const int skip = 0,
41  const string &outdir = ".")
42 {
43  //---------------
44  // Fun4All server
45  //---------------
46 
48  se->Verbosity(0);
49  // Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
50  // PHRandomSeed::Verbosity(1);
51  // just if we set some flags somewhere in this macro
53  // By default every random number generator uses
54  // PHRandomSeed() which reads /dev/urandom to get its seed
55  // if the RANDOMSEED flag is set its value is taken as initial seed
56  // which will produce identical results so you can debug your code
57  // rc->set_IntFlag("RANDOMSEED", 12345);
58 
59  //===============
60  // Input options
61  //===============
62  // verbosity setting (applies to all input managers)
63  Input::VERBOSITY = 0;
64  // Either:
65  // read previously generated g4-hits files, in this case it opens a DST and skips
66  // the simulations step completely. The G4Setup macro is only loaded to get information
67  // about the number of layers used for the cell reco code
68  Input::READHITS = false;
69  INPUTREADHITS::filename[0] = inputFile;
70  // if you use a filelist
71  // INPUTREADHITS::listfile[0] = inputFile;
72  // Or:
73  // Use particle generator
74  // And
75  // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
76  // 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
77  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
78 
79  // Input::EMBED = true;
80  INPUTEMBED::filename[0] = embed_input_file;
81  // if you use a filelist
82  //INPUTEMBED::listfile[0] = embed_input_file;
83 
84  Input::SIMPLE = true;
85  // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
86  // Input::SIMPLE_VERBOSITY = 1;
87 
88  // Input::PYTHIA6 = true;
89 
90  // Input::PYTHIA8 = true;
91 
92  // Input::GUN = true;
93  // Input::GUN_NUMBER = 3; // if you need 3 of them
94  // Input::GUN_VERBOSITY = 1;
95 
96  // Upsilon generator
97  // Input::UPSILON = true;
98  // Input::UPSILON_NUMBER = 3; // if you need 3 of them
99  // Input::UPSILON_VERBOSITY = 0;
100 
101  // Input::HEPMC = true;
102  INPUTHEPMC::filename = inputFile;
103 
104  // Event pile up simulation with collision rate in Hz MB collisions.
105  Input::PILEUPRATE = 100e3;
106 
107  //-----------------
108  // Initialize the selected Input/Event generation
109  //-----------------
110  InputInit();
111 
112  //--------------
113  // Set generator specific options
114  //--------------
115  // can only be set after InputInit() is called
116 
117  // Simple Input generator:
118  // if you run more than one of these Input::SIMPLE_NUMBER > 1
119  // add the settings for other with [1], next with [2]...
120  if (Input::SIMPLE)
121  {
122  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi-", 5);
123  if (Input::HEPMC || Input::EMBED)
124  {
125  INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
126  INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
127  }
128  else
129  {
130  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
133  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
134  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0., 0., 5.);
135  }
136  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1, 3);
137  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
138  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(0.5, 50.);
139  }
140  // Upsilons
141  // if you run more than one of these Input::UPSILON_NUMBER > 1
142  // add the settings for other with [1], next with [2]...
143  if (Input::UPSILON)
144  {
145  INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("mu", 0);
146  INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
147  INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
148  // Y species - select only one, last one wins
149  INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
150  if (Input::HEPMC || Input::EMBED)
151  {
152  INPUTGENERATOR::VectorMesonGenerator[0]->set_reuse_existing_vertex(true);
153  INPUTGENERATOR::VectorMesonGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
154  }
155  }
156  // particle gun
157  // if you run more than one of these Input::GUN_NUMBER > 1
158  // add the settings for other with [1], next with [2]...
159  if (Input::GUN)
160  {
161  INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
162  INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
163  }
164 
165  // pythia6
166  if (Input::PYTHIA6)
167  {
170  }
171  // pythia8
172  if (Input::PYTHIA8)
173  {
176  }
177 
178  //--------------
179  // Set Input Manager specific options
180  //--------------
181  // can only be set after InputInit() is called
182 
183  if (Input::HEPMC)
184  {
187 
188  // optional overriding beam parameters
189  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 8, 0); //optional collision smear in space, time
190  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
191  // //optional choice of vertex distribution function in space, time
192  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_function(PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus);
193  if (Input::PILEUPRATE > 0)
194  {
195  // Copy vertex settings from foreground hepmc input
197  // and then modify the ones you want to be different
198  // INPUTMANAGER::HepMCPileupInputManager->set_vertex_distribution_width(100e-4,100e-4,8,0);
199  }
200  }
201  if (Input::PILEUPRATE > 0)
202  {
205  }
206 
207  // register all input generators with Fun4All
208  InputRegister();
209 
210  // set up production relatedstuff
211  // Enable::PRODUCTION = true;
212 
213  //======================
214  // Write the DST
215  //======================
216 
217  //Enable::DSTOUT = true;
218  Enable::DSTOUT_COMPRESS = false;
219  DstOut::OutputDir = outdir;
220  DstOut::OutputFile = outputFile;
221 
222  //Option to convert DST to human command readable TTree for quick poke around the outputs
223  // Enable::DSTREADER = true;
224 
225  // turn the display on (default off)
226  Enable::DISPLAY = false;
227 
228  //======================
229  // What to run
230  //======================
231  // Global options (enabled for all enables subsystems - if implemented)
232  // Enable::ABSORBER = true;
233  // Enable::OVERLAPCHECK = true;
234  // Enable::VERBOSITY = 1;
235 
236  // Enable::BBC = true;
237  Enable::BBCFAKE = true; // Smeared vtx and t0, use if you don't want real BBC in simulation
238 
239  Enable::PIPE = true;
240  Enable::PIPE_ABSORBER = true;
241  // Enable::PIPE_OVERLAPCHECK = true;
242 
243  // central tracking
244  Enable::MVTX = true;
247 
248  Enable::INTT = true;
251 
252  Enable::TPC = true;
253  // Enable::TPC_ABSORBER = true;
254  Enable::TPC_CELL = Enable::TPC && true;
256 
259 
260  // central calorimeters, which is a detailed simulation and slow to run
261  Enable::CEMC = true;
262  // Enable::CEMC_ABSORBER = true;
267 
268  Enable::HCALIN = true;
269  // Enable::HCALIN_ABSORBER = true;
274 
275  Enable::MAGNET = true;
276  // Enable::MAGNET_ABSORBER = true;
277 
278  Enable::HCALOUT = true;
279  // Enable::HCALOUT_ABSORBER = true;
284 
285  Enable::GLOBAL_RECO = true;
286  // Enable::GLOBAL_FASTSIM = true;
287 
289 
290  Enable::JETS = true;
292 
293  Enable::FWDJETS = true;
295 
296  // fsPHENIX geometry
297 
298  Enable::FGEM = true;
301 
302  Enable::FEMC = true;
303  Enable::FEMC_ABSORBER = true;
306 
307  Enable::FHCAL = true;
308  // Enable::FHCAL_ABSORBER = true; // make absorber active volume
309  // Enable::FHCAL_SUPPORT = true; // make support active volume
313 
314  // Enable::PISTON = true;
317 
318  Enable::PLUGDOOR = true;
319  // Enable::PLUGDOOR_ABSORBER = true;
321 
322  // new settings using Enable namespace in GlobalVariables.C
323  Enable::BLACKHOLE = true;
324  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
325  // BlackHoleGeometry::visible = true;
326 
327  // run user provided code (from local G4_User.C)
328  //Enable::USER = true;
329 
330  //---------------
331  // World Settings
332  //---------------
333  // G4WORLD::PhysicsList = "FTFP_BERT"; // FTFP_BERT_HP best for calo
334  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
335 
336  //---------------
337  // Magnet Settings
338  //---------------
339 
340  // const string magfield = "1.4"; // alternatively to specify a constant magnetic field, give a float number, which will be translated to solenoidal field in T, if string use as fieldmap name (including path)
341 // This is the 3d fieldmap setting (default)
342 // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sphenix3dbigmapxyz.root"); // default map from the calibration database
343 // G4MAGNET::magfield_rescale = 1.; // in case you want to play with field
344 
345 // for 2d map use these settings
346  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root"); // default map from the calibration database
347 // G4MAGNET::magfield_rescale = -1.4 / 1.5; // make consistent with expected Babar field strength of 1.4T
348 
349  //---------------
350  // Pythia Decayer
351  //---------------
352  // list of decay types in
353  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
354  // default is All:
355  // G4P6DECAYER::decayType = EDecayType::kAll;
356 
357  // Initialize the selected subsystems
358  G4Init();
359 
360  if (!Input::READHITS)
361  {
362  //---------------------
363  // Set up G4 only if we do not read hits
364  //---------------------
365  G4Setup();
366  }
367 
368  //------------------
369  // Detector Division
370  //------------------
371 
373 
374  if (Enable::MVTX_CELL) Mvtx_Cells();
377 
379 
381 
383 
384  //-----------------------------
385  // CEMC towering and clustering
386  //-----------------------------
387 
390 
391  //-----------------------------
392  // HCAL towering and clustering
393  //-----------------------------
394 
397 
398  if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
400 
403 
406 
408 
409  //--------------
410  // SVTX tracking
411  //--------------
413  {
414  TrackingInit();
415  }
416 
420 
422  {
423  Tracking_Reco();
424  }
425 
426  //--------------
427  // FGEM tracking
428  //--------------
429 
431 
432  //-----------------
433  // Global Vertexing
434  //-----------------
436  {
437  cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
438  gSystem->Exit(1);
439  }
441  {
442  Global_Reco();
443  }
444  else if (Enable::GLOBAL_FASTSIM)
445  {
446  Global_FastSim();
447  }
448 
449  //-----------------
450  // Calo Trigger Simulation
451  //-----------------
452 
454  {
455  CaloTrigger_Sim();
456  }
457 
458  //---------
459  // Jet reco
460  //---------
461 
462  if (Enable::JETS) Jet_Reco();
463 
465 
466  //----------------------
467  // Simulation evaluation
468  //----------------------
469 
470  string outputroot = outputFile;
471  string remove_this = ".root";
472  size_t pos = outputroot.find(remove_this);
473  if (pos != string::npos)
474  {
475  outputroot.erase(pos, remove_this.length());
476  }
477 
478  if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "g4tracking_eval.root");
479 
480  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "g4cemc_eval.root");
481 
482  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "g4hcalin_eval.root");
483 
484  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "g4hcalout_eval.root");
485 
486  if (Enable::FEMC_EVAL) FEMC_Eval(outputroot + "g4femc_eval.root");
487 
488  if (Enable::FHCAL_EVAL) FHCAL_Eval(outputroot + "_g4fhcal_eval.root");
489 
490  if (Enable::JETS_EVAL) Jet_Eval(outputroot + "g4jet_eval.root");
491 
492  if (Enable::FWDJETS_EVAL) Jet_FwdEval(outputroot + "g4fwdjet_eval.root");
493 
494  if (Enable::FGEM_EVAL) FGEM_FastSim_Eval(outputroot + "g4tracking_fgem_eval.root");
495 
496  if (Enable::DSTREADER) G4DSTreader_fsPHENIX(outputroot + "_DSTReader.root");
497 
499 
500  //--------------
501  // Set up Input Managers
502  //--------------
503 
504  InputManagers();
505 
506  //--------------
507  // Set up Output Managers
508  //--------------
509  if (Enable::PRODUCTION)
510  {
512  }
513 
514  if (Enable::DSTOUT)
515  {
516  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
517  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
519  se->registerOutputManager(out);
520  }
521 
522  //-----------------
523  // Event processing
524  //-----------------
525  if (Enable::DISPLAY)
526  {
527  DisplayOn();
528 
529  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
530  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
531 
532  cout << "-------------------------------------------------" << endl;
533  cout << "You are in event display mode. Run one event with" << endl;
534  cout << "se->run(1)" << endl;
535  cout << "Run Geant4 command with following examples" << endl;
536  gROOT->ProcessLine("displaycmd()");
537 
538  return 0;
539  }
540 
541  // if we use a negative number of events we go back to the command line here
542  if (nEvents < 0)
543  {
544  return 0;
545  }
546  // if we run the particle generator and use 0 it'll run forever
547  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS)
548  {
549  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
550  cout << "it will run forever, so I just return without running anything" << endl;
551  return 0;
552  }
553 
554  se->skip(skip);
555  se->run(nEvents);
556 
557  //-----
558  // Exit
559  //-----
560 
561  se->End();
562  std::cout << "All done" << std::endl;
563  delete se;
564  if (Enable::PRODUCTION)
565  {
567  }
568  gSystem->Exit(0);
569  return 0;
570 }
571 
572 void G4Cmd(const char *cmd)
573 {
575  PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO");
576  g4->ApplyCommand(cmd);
577 }
578 #endif