Analysis Software
Documentation for sPHENIX simulation 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 
2 //modified and simplified Fun4All macro (Simple inputgen + HCALOUT)
3 
4 #ifndef MACRO_FUN4ALLG4SPHENIX_C
5 #define MACRO_FUN4ALLG4SPHENIX_C
6 
7 #include "Calib.h"
8 #include <GlobalVariables.C>
9 
10 #include <DisplayOn.C>
11 #include <G4Setup_sPHENIX.C>
12 #include <G4_Bbc.C>
13 #include <G4_CaloTrigger.C>
14 #include <G4_Centrality.C>
15 #include <G4_DSTReader.C>
16 #include <G4_Global.C>
17 #include <G4_HIJetReco.C>
18 #include <G4_Input.C>
19 #include <G4_Jets.C>
20 #include <G4_KFParticle.C>
21 #include <G4_ParticleFlow.C>
22 #include <G4_Production.C>
23 #include <G4_TopoClusterReco.C>
24 #include <G4_Tracking.C>
25 #include <G4_User.C>
26 #include <QA.C>
27 
28 #include <ffamodules/FlagHandler.h>
29 #include <ffamodules/HeadReco.h>
30 #include <ffamodules/SyncReco.h>
31 #include <ffamodules/XploadInterface.h>
32 
35 #include <fun4all/Fun4AllServer.h>
36 
37 #include <phool/PHRandomSeed.h>
38 #include <phool/recoConsts.h>
39 
40 R__LOAD_LIBRARY(libfun4all.so)
41 R__LOAD_LIBRARY(libffamodules.so)
42 R__LOAD_LIBRARY(libCalib.so.0.0.0)
43 
44 
45 // For HepMC Hijing
46 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
47 
49  const int nEvents = 1,
50  const string &inputFile = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
51  const string &outputFile = "G4sPHENIX.root",
52  const string &embed_input_file = "https://www.phenix.bnl.gov/WWW/publish/phnxbld/sPHENIX/files/sPHENIX_G4Hits_sHijing_9-11fm_00000_00010.root",
53  const int skip = 0,
54  const string &outdir = ".")
55 {
57  se->Verbosity(0);
58 
59  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
61 
62  // just if we set some flags somewhere in this macro
64 
65  //===============
66  // Input options
67  //===============
68  // verbosity setting (applies to all input managers)
69  Input::VERBOSITY = 0;
70 
71  Input::SIMPLE = true;
72 
73  // Input::GUN = true;
74 
75  //-----------------
76  // Initialize the selected Input/Event generation
77  //-----------------
78  // This creates the input generator(s)
79  InputInit();
80 
81  //--------------
82  // Set generator specific options
83  //--------------
84  // can only be set after InputInit() is called
85 
86  // Simple Input generator:
87  // if you run more than one of these Input::SIMPLE_NUMBER > 1
88  // add the settings for other with [1], next with [2]...
89 
90  if (Input::SIMPLE)
91  {
92  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi-", 1);
93 
96  PHG4SimpleEventGenerator::Uniform); INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
97  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(140., 140., 10.);
98  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0., 0., 0.);
99  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(0, 0);
100  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(0, 0);
101  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(10., 10.);
102  }
103 
104  // particle gun
105  // if you run more than one of these Input::GUN_NUMBER > 1
106  // add the settings for other with [1], next with [2]...
107  if (Input::GUN)
108  {
109  INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
110  INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
111  }
112 
113  //--------------
114  // Set Input Manager specific options
115  //--------------
116  // can only be set after InputInit() is called
117 
118  // register all input generators with Fun4All
119  InputRegister();
120 
121  if (! Input::READHITS)
122  {
123  rc->set_IntFlag("RUNNUMBER",1);
124 
125  SyncReco *sync = new SyncReco();
126  se->registerSubsystem(sync);
127 
128  HeadReco *head = new HeadReco();
129  se->registerSubsystem(head);
130  }
131 
132 // Flag Handler is always needed to read flags from input (if used)
133 // and update our rc flags with them. At the end it saves all flags
134 // again on the DST in the Flags node under the RUN node
135  FlagHandler *flag = new FlagHandler();
136  se->registerSubsystem(flag);
137 
138  // set up production relatedstuff
139  // Enable::PRODUCTION = true;
140 
141  //======================
142  // Write the DST
143  //======================
144 
145  //Enable::DSTOUT = true;
146  Enable::DSTOUT_COMPRESS = false;
147  DstOut::OutputDir = outdir;
148  DstOut::OutputFile = outputFile;
149 
150  //Option to convert DST to human command readable TTree for quick poke around the outputs
151  // Enable::DSTREADER = true;
152 
153  // turn the display on (default off)
154  Enable::DISPLAY = false;
155 
156  //======================
157  // What to run
158  //======================
159 
160  // QA, main switch
161  Enable::QA = false;
162 
163  // Global options (enabled for all enables subsystems - if implemented)
164  // Enable::ABSORBER = true;
165  // Enable::OVERLAPCHECK = true;
166  // Enable::VERBOSITY = 1;
167 
168  // Enable::BBC = true;
169  // Enable::BBC_SUPPORT = true; // save hist in bbc support structure
170  Enable::BBCFAKE = true; // Smeared vtx and t0, use if you don't want real BBC in simulation
171 
172  Enable::PIPE = true;
173  Enable::PIPE_ABSORBER = true;
174 
175  // central tracking
176  Enable::MVTX = false;
180 
181  Enable::INTT = false;
182 // Enable::INTT_ABSORBER = true; // enables layerwise support structure readout
183 // Enable::INTT_SUPPORT = true; // enable global support structure readout
186  Enable::INTT_QA = Enable::INTT_CLUSTER && Enable::QA && true;
187 
188  Enable::TPC = false;
189  Enable::TPC_ABSORBER = true;
190  Enable::TPC_CELL = Enable::TPC && true;
192  Enable::TPC_QA = Enable::TPC_CLUSTER && Enable::QA && true;
193 
194  Enable::MICROMEGAS = false;
197  Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
198 
199  Enable::TRACKING_TRACK = false;
200  //Enable::TRACKING_EVAL = Enable::TRACKING_TRACK && true;
201  Enable::TRACKING_QA = Enable::TRACKING_TRACK && Enable::QA && true;
202 
203  // cemc electronics + thin layer of W-epoxy to get albedo from cemc
204  // into the tracking, cannot run together with CEMC
205  // Enable::CEMCALBEDO = true;
206 
207  Enable::CEMC = false;
208  Enable::CEMC_ABSORBER = true;
212  //Enable::CEMC_EVAL = Enable::CEMC_CLUSTER && true;
213  Enable::CEMC_QA = Enable::CEMC_CLUSTER && Enable::QA && true;
214 
215  Enable::HCALIN = false;
220  //Enable::HCALIN_EVAL = Enable::HCALIN_CLUSTER && true;
221  Enable::HCALIN_QA = Enable::HCALIN_CLUSTER && Enable::QA && true;
222 
223  Enable::MAGNET = false;
225 
226  Enable::HCALOUT = true;
231  //Enable::HCALOUT_EVAL = Enable::HCALOUT_CLUSTER && true;
232  Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER && Enable::QA && true;
233 
234  Enable::EPD = false;
235 
236  Enable::BEAMLINE = true;
237 // Enable::BEAMLINE_ABSORBER = true; // makes the beam line magnets sensitive volumes
238 // Enable::BEAMLINE_BLACKHOLE = true; // turns the beamline magnets into black holes
239  Enable::ZDC = false;
240 // Enable::ZDC_ABSORBER = true;
241 // Enable::ZDC_SUPPORT = true;
242  Enable::ZDC_TOWER = Enable::ZDC && true;
243  //Enable::ZDC_EVAL = Enable::ZDC_TOWER && true;
244 
246  //Enable::PLUGDOOR = true;
248 
249  //Enable::GLOBAL_RECO = (Enable::BBCFAKE || Enable::TRACKING_TRACK) && true;
250  Enable::GLOBAL_FASTSIM = true;
251 
252  //Enable::KFPARTICLE = true;
253  //Enable::KFPARTICLE_VERBOSITY = 1;
254  //Enable::KFPARTICLE_TRUTH_MATCH = true;
255  //Enable::KFPARTICLE_SAVE_NTUPLE = true;
256 
258 
259  //Enable::JETS = (Enable::GLOBAL_RECO || Enable::GLOBAL_FASTSIM) && true;
260  //Enable::JETS_EVAL = Enable::JETS && true;
261  Enable::JETS_QA = Enable::JETS && Enable::QA && true;
262 
263  // HI Jet Reco for p+Au / Au+Au collisions (default is false for
264  // single particle / p+p-only simulations, or for p+Au / Au+Au
265  // simulations which don't particularly care about jets)
266  //Enable::HIJETS = Enable::JETS && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
267 
268  // 3-D topoCluster reconstruction, potentially in all calorimeter layers
269  Enable::TOPOCLUSTER = Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
270  // particle flow jet reconstruction - needs topoClusters!
272  // centrality reconstruction
273  Enable::CENTRALITY = true;
274 
275  // new settings using Enable namespace in GlobalVariables.C
276  Enable::BLACKHOLE = true;
277  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
278  //Enable::BLACKHOLE_FORWARD_SAVEHITS = false; // disable forward/backward hits
279  //BlackHoleGeometry::visible = true;
280 
281  // run user provided code (from local G4_User.C)
282  //Enable::USER = true;
283 
284  //===============
285  // conditions DB flags
286  //===============
287  //Enable::XPLOAD = true;
288  // tag
289  rc->set_StringFlag("XPLOAD_TAG",XPLOAD::tag);
290  // database config
291  rc->set_StringFlag("XPLOAD_CONFIG",XPLOAD::config);
292  // 64 bit timestamp
293  rc->set_uint64Flag("TIMESTAMP",XPLOAD::timestamp);
294 
295  //---------------
296  // World Settings
297  //---------------
298  // G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
299  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
300 
301  //---------------
302  // Magnet Settings
303  //---------------
304 
305  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT"))+ string("/Field/Map/sphenix3dbigmapxyz.root"); // default map from the calibration database
306  // 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)
307 // G4MAGNET::magfield_rescale = 1.; // make consistent with expected Babar field strength of 1.4T
308 
309  //---------------
310  // Pythia Decayer
311  //---------------
312  // list of decay types in
313  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
314  // default is All:
315  // G4P6DECAYER::decayType = EDecayType::kAll;
316 
317  // Initialize the selected subsystems
318  G4Init();
319 
320  //---------------------
321  // GEANT4 Detector description
322  //---------------------
323  if (!Input::READHITS)
324  {
325  G4Setup();
326  }
327 
328  //------------------
329  // Detector Division
330  //------------------
331 
332  if (Enable::BBC || Enable::BBCFAKE) Bbc_Reco();
333 
338 
340 
342 
344 
345  //-----------------------------
346  // CEMC towering and clustering
347  //-----------------------------
348 
351 
352  //-----------------------------
353  // HCAL towering and clustering
354  //-----------------------------
355 
358 
359  if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
361 
362  // if enabled, do topoClustering early, upstream of any possible jet reconstruction
364 
365  //--------------
366  // SVTX tracking
367  //--------------
369  {
370  TrackingInit();
371  }
376 
378  {
379  Tracking_Reco();
380  }
381  //-----------------
382  // Global Vertexing
383  //-----------------
384 
386  {
387  cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
388  gSystem->Exit(1);
389  }
391  {
392  Global_Reco();
393  }
394  else if (Enable::GLOBAL_FASTSIM)
395  {
396  Global_FastSim();
397  }
398 
399  //-----------------
400  // Centrality Determination
401  //-----------------
402 
403  if (Enable::CENTRALITY)
404  {
405  Centrality();
406  }
407 
408  //-----------------
409  // Calo Trigger Simulation
410  //-----------------
411 
413  {
414  CaloTrigger_Sim();
415  }
416 
417  //---------
418  // Jet reco
419  //---------
420 
421  if (Enable::JETS) Jet_Reco();
422  if (Enable::HIJETS) HIJetReco();
423 
425 
426  //----------------------
427  // Simulation evaluation
428  //----------------------
429  string outputroot = outputFile;
430  string remove_this = ".root";
431  size_t pos = outputroot.find(remove_this);
432  if (pos != string::npos)
433  {
434  outputroot.erase(pos, remove_this.length());
435  }
436 
437  if (Enable::TRACKING_EVAL) Tracking_Eval(outputroot + "_g4svtx_eval.root");
438 
439  if (Enable::CEMC_EVAL) CEMC_Eval(outputroot + "_g4cemc_eval.root");
440 
441  if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root");
442 
443  if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root");
444 
445  if (Enable::JETS_EVAL) Jet_Eval(outputroot + "_g4jet_eval.root");
446 
447  if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
448 
450 
451 
452  gSystem->Load("libCalib.so.0.0.0");
453  Calib *hcal_eval = new Calib();
454  hcal_eval->set_filename("hcal_tower_energies.root");
455  se->registerSubsystem(hcal_eval);
456 
457 
458 
459 
460  //======================
461  // Run KFParticle on evt
462  //======================
465 
466  //----------------------
467  // Standard QAs
468  //----------------------
469 
470  if (Enable::CEMC_QA) CEMC_QA();
473 
474  if (Enable::JETS_QA) Jet_QA();
475 
476  if (Enable::MVTX_QA) Mvtx_QA();
477  if (Enable::INTT_QA) Intt_QA();
478  if (Enable::TPC_QA) TPC_QA();
481 
483 
484  //--------------
485  // Set up Input Managers
486  //--------------
487 
488  InputManagers();
489 
490  if (Enable::PRODUCTION)
491  {
493  }
494 
495  if (Enable::DSTOUT)
496  {
497  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
498  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
500  {
501  ShowerCompress();
502  DstCompress(out);
503  }
504  se->registerOutputManager(out);
505  }
506  //-----------------
507  // Event processing
508  //-----------------
509  if (Enable::DISPLAY)
510  {
511  DisplayOn();
512 
513  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
514  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
515 
516  cout << "-------------------------------------------------" << endl;
517  cout << "You are in event display mode. Run one event with" << endl;
518  cout << "se->run(1)" << endl;
519  cout << "Run Geant4 command with following examples" << endl;
520  gROOT->ProcessLine("displaycmd()");
521 
522  return 0;
523  }
524 
525  // if we use a negative number of events we go back to the command line here
526  if (nEvents < 0)
527  {
528  return 0;
529  }
530  // if we run the particle generator and use 0 it'll run forever
531  // for embedding it runs forever if the repeat flag is set
532  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
533  {
534  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
535  cout << "it will run forever, so I just return without running anything" << endl;
536  return 0;
537  }
538 
539  se->skip(skip);
540  se->run(nEvents);
541 
542  //-----
543  // QA output
544  //-----
545 
546  if (Enable::QA) QA_Output(outputroot + "_qa.root");
547 
548  //-----
549  // Exit
550  //-----
551 
552  se->End();
553  std::cout << "All done" << std::endl;
554  delete se;
555  if (Enable::PRODUCTION)
556  {
558  }
559 
560  gSystem->Exit(0);
561  return 0;
562 }
563 #endif