EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_sPHENIX.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_sPHENIX.C
1 #ifndef MACRO_FUN4ALLG4SPHENIX_C
2 #define MACRO_FUN4ALLG4SPHENIX_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <DisplayOn.C>
7 #include <G4Setup_sPHENIX.C>
8 #include <G4_Bbc.C>
9 #include <G4_CaloTrigger.C>
10 #include <G4_Centrality.C>
11 #include <G4_DSTReader.C>
12 #include <G4_Global.C>
13 #include <G4_HIJetReco.C>
14 #include <G4_Input.C>
15 #include <G4_Jets.C>
16 #include <G4_KFParticle.C>
17 #include <G4_ParticleFlow.C>
18 #include <G4_Production.C>
19 #include <G4_TopoClusterReco.C>
20 #include <G4_Tracking.C>
21 #include <G4_User.C>
22 #include <QA.C>
23 
26 #include <fun4all/Fun4AllServer.h>
27 
28 #include <phool/PHRandomSeed.h>
29 #include <phool/recoConsts.h>
30 
31 R__LOAD_LIBRARY(libfun4all.so)
32 
33 // For HepMC Hijing
34 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
35 
37  const int nEvents = 1,
38  const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
39  const string &outputFile = "G4sPHENIX.root",
40  const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
41  const int skip = 0,
42  const string &outdir = ".")
43 {
45  se->Verbosity(0);
46 
47  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
49 
50  // just if we set some flags somewhere in this macro
52  // By default every random number generator uses
53  // PHRandomSeed() which reads /dev/urandom to get its seed
54  // if the RANDOMSEED flag is set its value is taken as seed
55  // You can either set this to a random value using PHRandomSeed()
56  // which will make all seeds identical (not sure what the point of
57  // this would be:
58  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
59  // or set it to a fixed value so you can debug your code
60  // rc->set_IntFlag("RANDOMSEED", 12345);
61 
62  //===============
63  // conditions DB flags
64  //===============
65  // tag
66  rc->set_StringFlag("XPLOAD_TAG","example_tag_1");
67  // database
68  rc->set_StringFlag("XPLOAD_CONFIG","test");
69 
70 
71  //===============
72  // Input options
73  //===============
74  // verbosity setting (applies to all input managers)
75  Input::VERBOSITY = 0;
76  // First enable the input generators
77  // Either:
78  // read previously generated g4-hits files, in this case it opens a DST and skips
79  // the simulations step completely. The G4Setup macro is only loaded to get information
80  // about the number of layers used for the cell reco code
81  // Input::READHITS = true;
82  INPUTREADHITS::filename[0] = inputFile;
83  // if you use a filelist
84  // INPUTREADHITS::listfile[0] = inputFile;
85  // Or:
86  // Use particle generator
87  // And
88  // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
89  // 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
90  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
91  // Input::EMBED = true;
92  INPUTEMBED::filename[0] = embed_input_file;
93  // if you use a filelist
94  //INPUTEMBED::listfile[0] = embed_input_file;
95 
96  Input::SIMPLE = true;
97  // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
98  // Input::SIMPLE_VERBOSITY = 1;
99 
100  // Input::PYTHIA6 = true;
101 
102  // Input::PYTHIA8 = true;
103 
104  // Input::GUN = true;
105  // Input::GUN_NUMBER = 3; // if you need 3 of them
106  // Input::GUN_VERBOSITY = 1;
107 
108  //D0 generator
109  //Input::DZERO = false;
110  //Input::DZERO_VERBOSITY = 0;
111  //Lambda_c generator //Not ready yet
112  //Input::LAMBDAC = false;
113  //Input::LAMBDAC_VERBOSITY = 0;
114  // Upsilon generator
115  //Input::UPSILON = true;
116  //Input::UPSILON_NUMBER = 3; // if you need 3 of them
117  //Input::UPSILON_VERBOSITY = 0;
118 
119  // Input::HEPMC = true;
120  INPUTHEPMC::filename = inputFile;
121 
122  // Event pile up simulation with collision rate in Hz MB collisions.
123  //Input::PILEUPRATE = 100e3;
124 
125  //-----------------
126  // Initialize the selected Input/Event generation
127  //-----------------
128  // This creates the input generator(s)
129  InputInit();
130 
131  //--------------
132  // Set generator specific options
133  //--------------
134  // can only be set after InputInit() is called
135 
136  // Simple Input generator:
137  // if you run more than one of these Input::SIMPLE_NUMBER > 1
138  // add the settings for other with [1], next with [2]...
139  if (Input::SIMPLE)
140  {
141  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi-", 5);
142  if (Input::HEPMC || Input::EMBED)
143  {
144  INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
145  INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
146  }
147  else
148  {
149  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
152  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
153  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0., 0., 5.);
154  }
155  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1, 1);
156  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
157  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(0.1, 20.);
158  }
159  // Upsilons
160  // if you run more than one of these Input::UPSILON_NUMBER > 1
161  // add the settings for other with [1], next with [2]...
162  if (Input::UPSILON)
163  {
164  INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("e", 0);
165  INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
166  INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
167  // Y species - select only one, last one wins
168  INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
169  if (Input::HEPMC || Input::EMBED)
170  {
171  INPUTGENERATOR::VectorMesonGenerator[0]->set_reuse_existing_vertex(true);
172  INPUTGENERATOR::VectorMesonGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
173  }
174  }
175  // particle gun
176  // if you run more than one of these Input::GUN_NUMBER > 1
177  // add the settings for other with [1], next with [2]...
178  if (Input::GUN)
179  {
180  INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
181  INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
182  }
183 
184  // pythia6
185  if (Input::PYTHIA6)
186  {
189  }
190  // pythia8
191  if (Input::PYTHIA8)
192  {
195  }
196 
197  //--------------
198  // Set Input Manager specific options
199  //--------------
200  // can only be set after InputInit() is called
201 
202  if (Input::HEPMC)
203  {
206 
207  // optional overriding beam parameters
208  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 8, 0); //optional collision smear in space, time
209  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
210  // //optional choice of vertex distribution function in space, time
211  //INPUTMANAGER::HepMCInputManager->set_vertex_distribution_function(PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus, PHHepMCGenHelper::Gaus);
216  //INPUTMANAGER::HepMCInputManager->set_embedding_id(Input::EmbedID);
217  if (Input::PILEUPRATE > 0)
218  {
219  // Copy vertex settings from foreground hepmc input
221  // and then modify the ones you want to be different
222  // INPUTMANAGER::HepMCPileupInputManager->set_vertex_distribution_width(100e-4,100e-4,8,0);
223  }
224  }
225  if (Input::PILEUPRATE > 0)
226  {
229  }
230  // register all input generators with Fun4All
231  InputRegister();
232 
233  // set up production relatedstuff
234  // Enable::PRODUCTION = true;
235 
236  //======================
237  // Write the DST
238  //======================
239 
240  //Enable::DSTOUT = true;
241  Enable::DSTOUT_COMPRESS = false;
242  DstOut::OutputDir = outdir;
243  DstOut::OutputFile = outputFile;
244 
245  //Option to convert DST to human command readable TTree for quick poke around the outputs
246  // Enable::DSTREADER = true;
247 
248  // turn the display on (default off)
249  //Enable::DISPLAY = true;
250 
251  //======================
252  // What to run
253  //======================
254 
255  // QA, main switch
256  Enable::QA = true;
257 
258  // Global options (enabled for all enables subsystems - if implemented)
259  // Enable::ABSORBER = true;
260  // Enable::OVERLAPCHECK = true;
261  // Enable::VERBOSITY = 1;
262 
263  // Enable::BBC = true;
264  // Enable::BBC_SUPPORT = true; // save hist in bbc support structure
265  Enable::BBCFAKE = true; // Smeared vtx and t0, use if you don't want real BBC in simulation
266 
267  Enable::PIPE = true;
268  Enable::PIPE_ABSORBER = true;
269 
270  // central tracking
271  Enable::MVTX = true;
276 
277  Enable::INTT = true;
280  Enable::INTT_QA = Enable::INTT_CLUSTER and Enable::QA && true;
281 
282  Enable::TPC = true;
283  Enable::TPC_ABSORBER = true;
284  Enable::TPC_CELL = Enable::TPC && true;
286  Enable::TPC_QA = Enable::TPC_CLUSTER and Enable::QA && true;
287 
288  Enable::MICROMEGAS = true;
291  Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
292 
293  Enable::TRACKING_TRACK = true;
295  Enable::TRACKING_QA = Enable::TRACKING_TRACK and Enable::QA && true;
296 
297  // cemc electronics + thin layer of W-epoxy to get albedo from cemc
298  // into the tracking, cannot run together with CEMC
299  // Enable::CEMCALBEDO = true;
300 
301  Enable::CEMC = true;
302  Enable::CEMC_ABSORBER = true;
307  Enable::CEMC_QA = Enable::CEMC_CLUSTER and Enable::QA && true;
308 
309  Enable::HCALIN = true;
315  Enable::HCALIN_QA = Enable::HCALIN_CLUSTER and Enable::QA && true;
316 
317  Enable::MAGNET = true;
319 
320  Enable::HCALOUT = true;
326  Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER and Enable::QA && true;
327 
328  Enable::EPD = true;
329 
330  Enable::BEAMLINE = true;
331 // Enable::BEAMLINE_ABSORBER = true; // makes the beam line magnets sensitive volumes
332 // Enable::BEAMLINE_BLACKHOLE = true; // turns the beamline magnets into black holes
333  Enable::ZDC = true;
334 // Enable::ZDC_ABSORBER = true;
335 // Enable::ZDC_SUPPORT = true;
336  Enable::ZDC_TOWER = Enable::ZDC && true;
338 
340  //Enable::PLUGDOOR = true;
342 
343  Enable::GLOBAL_RECO = true;
344  //Enable::GLOBAL_FASTSIM = true;
345  //Enable::KFPARTICLE = true;
346  //Enable::KFPARTICLE_VERBOSITY = 1;
347  //Enable::KFPARTICLE_TRUTH_MATCH = true;
348  //Enable::KFPARTICLE_SAVE_NTUPLE = true;
349 
351 
352  Enable::JETS = true;
354  Enable::JETS_QA = Enable::JETS and Enable::QA && true;
355 
356  // HI Jet Reco for p+Au / Au+Au collisions (default is false for
357  // single particle / p+p-only simulations, or for p+Au / Au+Au
358  // simulations which don't particularly care about jets)
360 
361  // 3-D topoCluster reconstruction, potentially in all calorimeter layers
363  // particle flow jet reconstruction - needs topoClusters!
365  // centrality reconstruction
366  Enable::CENTRALITY = true;
367 
368  // new settings using Enable namespace in GlobalVariables.C
369  Enable::BLACKHOLE = true;
370  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
371  //BlackHoleGeometry::visible = true;
372 
373  // run user provided code (from local G4_User.C)
374  //Enable::USER = true;
375 
376  //---------------
377  // World Settings
378  //---------------
379  // G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
380  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
381 
382  //---------------
383  // Magnet Settings
384  //---------------
385 
386  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT"))+ string("/Field/Map/sphenix3dbigmapxyz.root"); // default map from the calibration database
387  // G4MAGNET::magfield = "1.5"; // 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)
388  G4MAGNET::magfield_rescale = 1.; // make consistent with expected Babar field strength of 1.4T
389 
390  //---------------
391  // Pythia Decayer
392  //---------------
393  // list of decay types in
394  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
395  // default is All:
396  // G4P6DECAYER::decayType = EDecayType::kAll;
397 
398  // Initialize the selected subsystems
399  G4Init();
400 
401  //---------------------
402  // GEANT4 Detector description
403  //---------------------
404  if (!Input::READHITS)
405  {
406  G4Setup();
407  }
408 
409  //------------------
410  // Detector Division
411  //------------------
412 
414 
419 
421 
423 
425 
426  //-----------------------------
427  // CEMC towering and clustering
428  //-----------------------------
429 
432 
433  //-----------------------------
434  // HCAL towering and clustering
435  //-----------------------------
436 
439 
440  if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
442 
443  // if enabled, do topoClustering early, upstream of any possible jet reconstruction
445 
446  //--------------
447  // SVTX tracking
448  //--------------
450  {
451  TrackingInit();
452  }
457 
459  {
460  Tracking_Reco();
461  }
462  //-----------------
463  // Global Vertexing
464  //-----------------
465 
467  {
468  cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
469  gSystem->Exit(1);
470  }
472  {
473  Global_Reco();
474  }
475  else if (Enable::GLOBAL_FASTSIM)
476  {
477  Global_FastSim();
478  }
479 
480  //-----------------
481  // Centrality Determination
482  //-----------------
483 
484  if (Enable::CENTRALITY)
485  {
486  Centrality();
487  }
488 
489  //-----------------
490  // Calo Trigger Simulation
491  //-----------------
492 
494  {
495  CaloTrigger_Sim();
496  }
497 
498  //---------
499  // Jet reco
500  //---------
501 
502  if (Enable::JETS) Jet_Reco();
503  if (Enable::HIJETS) HIJetReco();
504 
506 
507  //----------------------
508  // Simulation evaluation
509  //----------------------
510  string outputroot = outputFile;
511  string remove_this = ".root";
512  size_t pos = outputroot.find(remove_this);
513  if (pos != string::npos)
514  {
515  outputroot.erase(pos, remove_this.length());
516  }
517 
518  if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4svtx_eval.root");
519 
520  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
521 
522  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
523 
524  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
525 
526  if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
527 
528  if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
529 
531 
532  //======================
533  // Run KFParticle on evt
534  //======================
537 
538  //----------------------
539  // Standard QAs
540  //----------------------
541 
542  if (Enable::CEMC_QA) CEMC_QA();
545 
546  if (Enable::JETS_QA) Jet_QA();
547 
548  if (Enable::MVTX_QA) Mvtx_QA();
549  if (Enable::INTT_QA) Intt_QA();
550  if (Enable::TPC_QA) TPC_QA();
553 
555 
556  //--------------
557  // Set up Input Managers
558  //--------------
559 
560  InputManagers();
561 
562  if (Enable::PRODUCTION)
563  {
565  }
566 
567  if (Enable::DSTOUT)
568  {
569  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
570  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
572  {
573  ShowerCompress();
574  DstCompress(out);
575  }
576  se->registerOutputManager(out);
577  }
578  //-----------------
579  // Event processing
580  //-----------------
581  if (Enable::DISPLAY)
582  {
583  DisplayOn();
584 
585  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
586  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
587 
588  cout << "-------------------------------------------------" << endl;
589  cout << "You are in event display mode. Run one event with" << endl;
590  cout << "se->run(1)" << endl;
591  cout << "Run Geant4 command with following examples" << endl;
592  gROOT->ProcessLine("displaycmd()");
593 
594  return 0;
595  }
596 
597  // if we use a negative number of events we go back to the command line here
598  if (nEvents < 0)
599  {
600  return 0;
601  }
602  // if we run the particle generator and use 0 it'll run forever
603  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS)
604  {
605  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
606  cout << "it will run forever, so I just return without running anything" << endl;
607  return 0;
608  }
609 
610  se->skip(skip);
611  se->run(nEvents);
612 
613  //-----
614  // QA output
615  //-----
616 
617  if (Enable::QA) QA_Output(outputroot + "_qa.root");
618 
619  //-----
620  // Exit
621  //-----
622 
623  se->End();
624  std::cout << "All done" << std::endl;
625  delete se;
626  if (Enable::PRODUCTION)
627  {
629  }
630 
631  gSystem->Exit(0);
632  return 0;
633 }
634 #endif