Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
run_calo_fromMDC2Hits_towslope_Fun4All_G4_Calo.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file run_calo_fromMDC2Hits_towslope_Fun4All_G4_Calo.C
1 #ifndef MACRO_FUN4ALLG4CALO_C
2 #define MACRO_FUN4ALLG4CALO_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <DisplayOn.C>
7 #include <G4Setup_sPHENIX.C>
8 #include <G4_Mbd.C>
9 #include <G4_CaloTrigger.C>
10 #include <G4_DSTReader.C>
11 #include <G4_Global.C>
12 #include <G4_HIJetReco.C>
13 #include <G4_Input.C>
14 #include <G4_Jets.C>
15 #include <G4_ParticleFlow.C>
16 #include <G4_Production.C>
17 #include <G4_TopoClusterReco.C>
18 #include <G4_Tracking.C>
19 #include <G4_User.C>
20 
23 #include <fun4all/Fun4AllServer.h>
24 
25 #include <litecaloeval/LiteCaloEval.h>
26 
27 
28 #include <phool/PHRandomSeed.h>
29 #include <phool/recoConsts.h>
30 
31 #include <litecaloeval/LiteCaloEval.h>
32 #include <calib_emc_pi0/CaloCalibEmc_Pi0.h>
33 
34 R__LOAD_LIBRARY(libfun4all.so)
35 R__LOAD_LIBRARY(libcaloCalibDBFile.so)
36 R__LOAD_LIBRARY(libcalibCaloEmc_pi0.so)
37 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
38 
39 
40 // For HepMC Hijing
41 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
42 
44  const int nEvents = 2,
45  // const string &inputFile0 = "DST_CALO_G4HIT_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000004-10000.root",
46  //const string &inputFile1 = "DST_VERTEX_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000004-10000.root",
47  const int mdc2_4_file_num = 1,
48  const string &outputFile = "newoutput1_calo1",
49  // const string &inputFile0 = "/gpfs/mnt/gpfs02/sphenix/sim/sim01/sphnxpro/MDC2/sHijing_HepMC/fm_0_20/pileup/DST_CALO_G4HIT_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000003-00001.root", //"DST_CALO_G4HIT_sHijing_0_12fm-0000000001-00000.root",
50  // const string &inputFile1 = "/gpfs/mnt/gpfs02/sphenix/sim/sim01/sphnxpro/MDC2/sHijing_HepMC/fm_0_20/pileup/DST_VERTEX_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000003-00001.root", //"DST_VERTEX_sHijing_0_12fm-0000000001-00000.root",
51  // const string &outputFile = "G4sPHENIX_calo1",
52  const string &outdir = ".")
53 {
55  se->Verbosity(0);
56 
57 
58  // string inputFile0 = "DST_CALO_G4HIT_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000004-10000.root";
59  // string inputFile1 = "DST_VERTEX_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000004-10000.root";
60 
61  //There are 40,000 mdc2 production 4 files.
62  // this piece of code allows you to simply specify which of the 40k files
63  // by the single integer input (from 0-40k) mdc2_4_file_num
64 
65  string inputFile0 = "DST_CALO_G4HIT_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000004-";
66  string inputFile1 = "DST_VERTEX_sHijing_0_20fm_50kHz_bkg_0_20fm-0000000004-";
67 
68 
69  int ynum_int = 100000+ mdc2_4_file_num;
70  TString yn_tstr = "";
71  yn_tstr += ynum_int;
72  yn_tstr.Remove(0,1);
73  inputFile0 += yn_tstr.Data();
74  inputFile1 += yn_tstr.Data();
75 
76  inputFile0 += ".root";
77  inputFile1 += ".root";
78 
79  cout << "running over these files" << endl;
80  cout << inputFile0 << endl;
81  cout << inputFile1 << endl;
82 
83  //const string &outputFile = "newoutput1_calo1",
84 
85 
86  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
88  /*
89  long mtime = gSystem->Now();
90  TString fileOut = outputFile.c_str();
91  fileOut += (mtime / 100000 - 8542922)/3;
92  string outputFile2 = fileOut.Data();
93  */
94  string outputFile2 = outputFile.c_str();
95  outputFile2 = outputFile2 + ".root";
96 
97  // just if we set some flags somewhere in this macro
99  // By default every random number generator uses
100  // PHRandomSeed() which reads /dev/urandom to get its seed
101  // if the RANDOMSEED flag is set its value is taken as seed
102  // You can either set this to a random value using PHRandomSeed()
103  // which will make all seeds identical (not sure what the point of
104  // this would be:
105  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
106  // or set it to a fixed value so you can debug your code
107  // rc->set_IntFlag("RANDOMSEED", 12345);
108 
109  //===============
110  // Input options
111  //===============
112  // verbosity setting (applies to all input managers)
113  Input::VERBOSITY = 1;
114  // First enable the input generators
115  // Either:
116  // read previously generated g4-hits files, in this case it opens a DST and skips
117  // the simulations step completely. The G4Setup macro is only loaded to get information
118  // about the number of layers used for the cell reco code
119  Input::READHITS = true;
120  INPUTREADHITS::filename[0] = inputFile0;
121  INPUTREADHITS::filename[1] = inputFile1;
122 
123  //-----------------
124  // Initialize the selected Input/Event generation
125  //-----------------
126  // This creates the input generator(s)
127  InputInit();
128 
129  // register all input generators with Fun4All
130  InputRegister();
131 
132  // set up production relatedstuff
133  Enable::PRODUCTION = true;
134 
135  //======================
136  // Write the DST
137  //======================
138 
139  Enable::DSTOUT = false;
140  Enable::DSTOUT_COMPRESS = false;
141  DstOut::OutputDir = outdir;
142 // DstOut::OutputFile = outputFile;
143  DstOut::OutputFile = outputFile2;
144 
145 
146  //Option to convert DST to human command readable TTree for quick poke around the outputs
147  // Enable::DSTREADER = true;
148 
149  // turn the display on (default off)
150  Enable::DISPLAY = false;
151 
152  //======================
153  // What to run
154  //======================
155  // Global options (enabled for all enables subsystems - if implemented)
156  // Enable::ABSORBER = true;
157  // Enable::OVERLAPCHECK = true;
158  // Enable::VERBOSITY = 1;
159 
160  Enable::CEMC = true;
164 // Enable::CEMC_EVAL = Enable::CEMC_CLUSTER && true;
165 
166  Enable::HCALIN = true;
169  // Enable::HCALIN_CLUSTER = Enable::HCALIN_TOWER && true;
170 // Enable::HCALIN_EVAL = Enable::HCALIN_CLUSTER && true;
171 
172  Enable::HCALOUT = true;
175  // Enable::HCALOUT_CLUSTER = Enable::HCALOUT_TOWER && true;
176 // Enable::HCALOUT_EVAL = Enable::HCALOUT_CLUSTER && true;
177 
178 
179 // Enable::EPD = false;
180 
181 // Enable::GLOBAL_RECO = true;
182  // Enable::GLOBAL_FASTSIM = true;
183 
184 // Enable::CALOTRIGGER = Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
185 
186 // Enable::JETS = true;
187 // Enable::JETS_EVAL = Enable::JETS && true;
188 
189  // HI Jet Reco for p+Au / Au+Au collisions (default is false for
190  // single particle / p+p-only simulations, or for p+Au / Au+Au
191  // simulations which don't particularly care about jets)
192 // Enable::HIJETS = false && Enable::JETS && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER;
193 
194  // 3-D topoCluster reconstruction, potentially in all calorimeter layers
195 // Enable::TOPOCLUSTER = true && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER;
196  // particle flow jet reconstruction - needs topoClusters!
197 // Enable::PARTICLEFLOW = true && Enable::TOPOCLUSTER;
198 
199  //---------------
200  // Magnet Settings
201  //---------------
202 
203  // const string 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)
204  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root"); // default map from the calibration database
205 // G4MAGNET::magfield_rescale = 1; // make consistent with expected Babar field strength of 1.4T
206 
207  //---------------
208  // Pythia Decayer
209  //---------------
210  // list of decay types in
211  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
212  // default is All:
213  // G4P6DECAYER::decayType = EDecayType::kAll;
214 
215  // Initialize the selected subsystems
216  G4Init();
217 
218  //---------------------
219  // GEANT4 Detector description
220  //---------------------
221  if (!Input::READHITS)
222  {
223  G4Setup();
224  }
225 
226  //------------------
227  // Detector Division
228  //------------------
229 
231 
236 
238 
240 
242 
243  //-----------------------------
244  // CEMC towering and clustering
245  //-----------------------------
246 
249 
250  //-----------------------------
251  // HCAL towering and clustering
252  //-----------------------------
253 
256 
259 
260  // if enabled, do topoClustering early, upstream of any possible jet reconstruction
262 
264 
265  //--------------
266  // SVTX tracking
267  //--------------
272 
274  {
275  TrackingInit();
276  Tracking_Reco();
277  }
278  //-----------------
279  // Global Vertexing
280  //-----------------
281 
283  {
284  cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
285  gSystem->Exit(1);
286  }
288  {
289  Global_Reco();
290  }
291  else if (Enable::GLOBAL_FASTSIM)
292  {
293  Global_FastSim();
294  }
295 
296  //-----------------
297  // Calo Trigger Simulation
298  //-----------------
299 
301  {
302  CaloTrigger_Sim();
303  }
304 
305  //---------
306  // Jet reco
307  //---------
308 
309  if (Enable::JETS) Jet_Reco();
310  if (Enable::HIJETS) HIJetReco();
311 
313 
314  //----------------------
315  // Simulation evaluation
316  //----------------------
317  string outputroot = outputFile;
318  string remove_this = ".root";
319  size_t pos = outputroot.find(remove_this);
320  if (pos != string::npos)
321  {
322  outputroot.erase(pos, remove_this.length());
323  }
324 
325  //--------------
326  // Set up Input Managers
327  //--------------
328 
329  InputManagers();
330 
331  if (Enable::PRODUCTION)
332  {
334  }
335 
336  if (Enable::DSTOUT)
337  {
338  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
339  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
340  out->AddNode("Sync");
341  out->AddNode("EventHeader");
342  out->AddNode("TOWER_SIM_HCALIN");
343  out->AddNode("TOWER_RAW_HCALIN");
344  out->AddNode("TOWER_CALIB_HCALIN");
345  out->AddNode("CLUSTER_HCALIN");
346  out->AddNode("TOWER_SIM_HCALOUT");
347  out->AddNode("TOWER_RAW_HCALOUT");
348  out->AddNode("TOWER_CALIB_HCALOUT");
349  out->AddNode("CLUSTER_HCALOUT");
350  out->AddNode("TOWER_SIM_CEMC");
351  out->AddNode("TOWER_RAW_CEMC");
352  out->AddNode("TOWER_CALIB_CEMC");
353  out->AddNode("CLUSTER_CEMC");
354  out->AddNode("CLUSTER_POS_COR_CEMC");
355 // leave the topo cluster here in case we run this during pass3
356  out->AddNode("TOPOCLUSTER_ALLCALO");
357  out->AddNode("TOPOCLUSTER_EMCAL");
358  out->AddNode("TOPOCLUSTER_HCAL");
359  out->AddNode("GlobalVertexMap");
361  se->registerOutputManager(out);
362  }
363  //-----------------
364  // Event processing
365  //-----------------
366  if (Enable::DISPLAY)
367  {
368  DisplayOn();
369 
370  gROOT->ProcessLine("Fun4AllServer *se = Fun4AllServer::instance();");
371  gROOT->ProcessLine("PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");");
372 
373  cout << "-------------------------------------------------" << endl;
374  cout << "You are in event display mode. Run one event with" << endl;
375  cout << "se->run(1)" << endl;
376  cout << "Run Geant4 command with following examples" << endl;
377  gROOT->ProcessLine("displaycmd()");
378 
379  return 0;
380  }
381 
382  string outputfile = outputFile2 + "_g4hcin_eval.root";
383  string outputfile2 = outputFile2 + "_hout.root";
384  string outputfile3 = outputFile2 + "_hin_eval_mod.root";
385  string outputfile4 = outputFile2 + "_hout_mod.root";
386  string outputfile5 = outputFile2 + "_cemc_eval.root";
387  string outputfile6 = outputFile2 + "_cemceval_mod.root";
388 
389 
390  LiteCaloEval *eval = new LiteCaloEval("HOUTEVALUATOR0", "HCALOUT", outputfile2.c_str());
391  //"CEMCEVALUATOR2", "CEMC", outputfile.c_str());
392  // eval->Verbosity(verbosity);
394  se->registerSubsystem(eval);
395 
396 
397  // LiteCaloEval *eval3a = new LiteCaloEval("HOUTEVALUATOR", "HCALOUT", outputfile4.c_str());
398  // // eval->Verbosity(verbosity);
399  // eval3a->CaloType(LiteCaloEval::HCALOUT); // eval->Verbosity(verbosity);
400  // eval3a->set_mode(1);
401  // se->registerSubsystem(eval3a);
402 
403 
404  LiteCaloEval *eval2 = new LiteCaloEval("HINEVALUATOR2", "HCALIN", outputfile.c_str());
405  // eval->Verbosity(verbosity);
407  se->registerSubsystem(eval2);
408 
409 
410  // LiteCaloEval *eval4a = new LiteCaloEval("HINEVALUATOR4", "HCALIN", outputfile3.c_str());
411  // // eval->Verbosity(verbosity);
412  // eval4a->CaloType(LiteCaloEval::HCALIN); // eval->Verbosity(verbosity);
413  // eval4a->set_mode(1);
414  // se->registerSubsystem(eval4a);
415 
416 
417 
418  LiteCaloEval *eval5 = new LiteCaloEval("CEMCEVALUATOR2", "CEMC", outputfile5.c_str());
419  // eval->Verbosity(verbosity);
421  se->registerSubsystem(eval5);
422 
423 
424  // LiteCaloEval *eval6 = new LiteCaloEval("CEMCEVALUATOR", "CEMC", outputfile6.c_str());
425  // // eval->Verbosity(verbosity);
426  // eval6->CaloType(LiteCaloEval::CEMC);
427  // eval6->set_mode(1);
428  // se->registerSubsystem(eval6);
429 
430 
431 
432  /*
433  LiteCaloEval *eval = new LiteCaloEval("CEMCEVALUATOR2", "CEMC", outputfile.c_str());
434  // eval->Verbosity(verbosity);
435  eval->CaloType(LiteCaloEval::CEMC);
436  se->registerSubsystem(eval);
437 
438  */
439  /*
440  CaloCalibEmc_Pi0 *eval_pi1 = new CaloCalibEmc_Pi0("CEMC_CALIB_PI0", outputfile2);
441  // eval_pi1->set_mode(1);
442  // eval->Verbosity(verbosity);
443  se->registerSubsystem(eval_pi1);
444  */
445 
446  /*
447  CaloCalibEmc_Pi0 *eval_pi2 = new CaloCalibEmc_Pi0("CEMC_CALIB_PI02", outputfile4);
448  eval_pi2->set_mode(1);
449  // eval->Verbosity(verbosity);
450  se->registerSubsystem(eval_pi2);
451  */
452 
453  /*
454  LiteCaloEval *eval3 = new LiteCaloEval("HOUTEVALUATOR", "HCALOUT", outputfile3.c_str());
455  // eval->Verbosity(verbosity);
456  eval3->CaloType(LiteCaloEval::HCALOUT);
457  // se->registerSubsystem(eval3);
458  */
459 
460  // if we use a negative number of events we go back to the command line here
461  if (nEvents < 0)
462  {
463  return 0;
464  }
465  // if we run the particle generator and use 0 it'll run forever
466  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS)
467  {
468  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
469  cout << "it will run forever, so I just return without running anything" << endl;
470  return 0;
471  }
472 
473  se->run(nEvents);
474 
475  //-----
476  // Exit
477  //-----
478 
479  se->End();
480  // se->PrintTimer();
481  //se->PrintMemoryTracker();
482  std::cout << "All done" << std::endl;
483  gSystem->Exit(0);
484  delete se;
485  /*
486  if (Enable::PRODUCTION)
487  {
488  Production_MoveOutput();
489  }
490  */
491 
492  return 0;
493 }
494 #endif