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