Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_fsPHENIX_pi0.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_fsPHENIX_pi0.C
1 
3  const int nEvents = 10,
4  const char * inputFile = "/sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/fieldmap/G4Hits_sPHENIX_e-_eta0_8GeV-0002.root",
5  const char * outputFile = "G4fsPHENIX.root",
6  const char * embed_input_file = "/sphenix/sim/sim01/production/2016-07-12/sHijing/spacal2d/G4Hits_sPHENIX_sHijing-0-4.4fm.list"
7  )
8 {
9  // Set the number of TPC layer
10  const int n_TPC_layers = 40; // use 60 for backward compatibility only
11 
12  //===============
13  // Input options
14  //===============
15 
16  // Either:
17  // read previously generated g4-hits files, in this case it opens a DST and skips
18  // the simulations step completely. The G4Setup macro is only loaded to get information
19  // about the number of layers used for the cell reco code
20  const bool readhits = false;
21  // Or:
22  // read files in HepMC format (typically output from event generators like hijing or pythia)
23  const bool readhepmc = false; // read HepMC files
24  // Or:
25  // Use particle generator
26  const bool runpythia8 = false;
27  const bool runpythia6 = false;
28  // And
29  // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
30  // 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
31  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
32  const bool do_embedding = false;
33 
34  //======================
35  // What to run
36  //======================
37 
38  bool do_bbc = true;
39 
40  bool do_pipe = true;
41 
42  bool do_svtx = true;
43  bool do_svtx_cell = do_svtx && true;
44  bool do_svtx_track = do_svtx_cell && true;
45  bool do_svtx_eval = do_svtx_track && false;
46 
47  bool do_cemc = true;
48  bool do_cemc_cell = do_cemc && true;
49  bool do_cemc_twr = do_cemc_cell && true;
50  bool do_cemc_cluster = do_cemc_twr && true;
51  bool do_cemc_eval = do_cemc_cluster && false;
52 
53  bool do_hcalin = true;
54  bool do_hcalin_cell = do_hcalin && true;
55  bool do_hcalin_twr = do_hcalin_cell && true;
56  bool do_hcalin_cluster = do_hcalin_twr && true;
57  bool do_hcalin_eval = do_hcalin_cluster && false;
58 
59  bool do_magnet = true;
60 
61  bool do_hcalout = true;
62  bool do_hcalout_cell = do_hcalout && true;
63  bool do_hcalout_twr = do_hcalout_cell && true;
64  bool do_hcalout_cluster = do_hcalout_twr && true;
65  bool do_hcalout_eval = do_hcalout_cluster && false;
66 
67  bool do_global = true;
68  bool do_global_fastsim = false;
69 
70  bool do_jet_reco = false;
71  bool do_jet_eval = do_jet_reco && true;
72 
73  bool do_fwd_jet_reco = false;
74  bool do_fwd_jet_eval = do_fwd_jet_reco && false;
75 
76  // fsPHENIX geometry
77 
78  bool do_FGEM = true;
79  bool do_FGEM_track = do_FGEM && false;
80 
81  bool do_FEMC = true;
82  bool do_FEMC_cell = do_FEMC && true;
83  bool do_FEMC_twr = do_FEMC_cell && true;
84  bool do_FEMC_cluster = do_FEMC_twr && true;
85 
86  bool do_FHCAL = true;
87  bool do_FHCAL_cell = do_FHCAL && true;
88  bool do_FHCAL_twr = do_FHCAL_cell && true;
89  bool do_FHCAL_cluster = do_FHCAL_twr && true;
90 
91  bool do_dst_compress = false;
92 
93  //Option to convert DST to human command readable TTree for quick poke around the outputs
94  bool do_DSTReader = true;
95  //---------------
96  // Load libraries
97  //---------------
98 
99  gSystem->Load("libfun4all.so");
100  gSystem->Load("libg4detectors.so");
101  gSystem->Load("libphhepmc.so");
102  gSystem->Load("libg4testbench.so");
103  gSystem->Load("libg4hough.so");
104  gSystem->Load("libg4eval.so");
105 
106  // establish the geometry and reconstruction setup
107  gROOT->LoadMacro("G4Setup_fsPHENIX.C");
108  G4Init(do_svtx,do_cemc,do_hcalin,do_magnet,do_hcalout,do_pipe,do_FGEM,do_FEMC,do_FHCAL,n_TPC_layers);
109 
110  int absorberactive = 0; // set to 1 to make all absorbers active volumes
111  // const string magfield = "1.5"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
112  const string magfield = "/phenix/upgrades/decadal/fieldmaps/fsPHENIX.2d.root"; // fsPHENIX field map by Cesar Luiz da Silva <slash@rcf.rhic.bnl.gov>, sPHENIX + piston
113  const float magfield_rescale = 1.0; // already adjusted to 1.4T central field
114 
115  //---------------
116  // Fun4All server
117  //---------------
118 
120 // se->Verbosity(0); // uncomment for batch production running with minimal output messages
121  se->Verbosity(Fun4AllServer::VERBOSITY_SOME); // uncomment for some info for interactive running
122  // just if we set some flags somewhere in this macro
124  // By default every random number generator uses
125  // PHRandomSeed() which reads /dev/urandom to get its seed
126  // if the RANDOMSEED flag is set its value is taken as seed
127  // You can either set this to a random value using PHRandomSeed()
128  // which will make all seeds identical (not sure what the point of
129  // this would be:
130  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
131  // or set it to a fixed value so you can debug your code
132  // rc->set_IntFlag("RANDOMSEED", 12345);
133 
134  //-----------------
135  // Event generation
136  //-----------------
137 
138  if (readhits)
139  {
140  // Get the hits from a file
141  // The input manager is declared later
142  if (do_embedding)
143  {
144  cout <<"Do not support read hits and embed background at the same time."<<endl;
145  exit(1);
146  }
147  }
148  else if (readhepmc)
149  {
150  // action is performed in later stage at the input manager level
151  }
152  else if (runpythia8)
153  {
154  gSystem->Load("libPHPythia8.so");
155 
156  PHPythia8* pythia8 = new PHPythia8();
157  // see coresoftware/generators/PHPythia8 for example config
158  pythia8->set_config_file("phpythia8.cfg");
159  se->registerSubsystem(pythia8);
160  }
161  else if (runpythia6)
162  {
163  gSystem->Load("libPHPythia6.so");
164 
165  PHPythia6 *pythia6 = new PHPythia6();
166  pythia6->set_config_file("phpythia6.cfg");
167  se->registerSubsystem(pythia6);
168  }
169  else
170  {
171  // toss low multiplicity dummy events
173  //gen->add_particles("e-",5); // mu+,e+,proton,pi+,Upsilon
174  //gen->add_particles("e+",5); // mu-,e-,anti_proton,pi-
175  //gen->add_particles("pi-",1); // mu-,e-,anti_proton,pi-
176  gen->add_particles(111,1);
177 
178  if (readhepmc || do_embedding) {
179  gen->set_reuse_existing_vertex(true);
180  gen->set_existing_vertex_offset_vector(0.0,0.0,0.0);
181  } else {
185  gen->set_vertex_distribution_mean(0.0,0.0,0.0);
186  gen->set_vertex_distribution_width(0.0,0.0,5.0);
187  }
189  gen->set_vertex_size_parameters(0.0,0.0);
190  gen->set_eta_range(2.2, 2.5);
191  //gen->set_eta_range(3.0, 3.0); //fsPHENIX FWD
192  gen->set_phi_range(-1.0*TMath::Pi(), 1.0*TMath::Pi());
193  //gen->set_phi_range(TMath::Pi()/2-0.1, TMath::Pi()/2-0.1);
194  gen->set_p_range(5.0, 8.0);
195  //gen->Embed(1);
196  gen->Verbosity(0);
197  se->registerSubsystem(gen);
198  }
199 
200  if (!readhits)
201  {
202  //---------------------
203  // Detector description
204  //---------------------
205 
206  G4Setup(absorberactive, magfield, TPythia6Decayer::kAll,
207  do_svtx, do_cemc, do_hcalin, do_magnet, do_hcalout, do_pipe,
208  do_FGEM, do_FEMC, do_FHCAL,
209  magfield_rescale);
210 
211  }
212 
213  //---------
214  // BBC Reco
215  //---------
216 
217  if (do_bbc)
218  {
219  gROOT->LoadMacro("G4_Bbc.C");
220  BbcInit();
221  Bbc_Reco();
222  }
223 
224  //------------------
225  // Detector Division
226  //------------------
227 
228  if (do_svtx_cell) Svtx_Cells();
229 
230  if (do_cemc_cell) CEMC_Cells();
231 
232  if (do_hcalin_cell) HCALInner_Cells();
233 
234  if (do_hcalout_cell) HCALOuter_Cells();
235 
236  if (do_FEMC_cell) FEMC_Cells();
237  if (do_FHCAL_cell) FHCAL_Cells();
238 
239  //-----------------------------
240  // CEMC towering and clustering
241  //-----------------------------
242 
243  if (do_cemc_twr) CEMC_Towers();
244  if (do_cemc_cluster) CEMC_Clusters();
245 
246  //-----------------------------
247  // HCAL towering and clustering
248  //-----------------------------
249 
250  if (do_hcalin_twr) HCALInner_Towers();
251  if (do_hcalin_cluster) HCALInner_Clusters();
252 
253  if (do_hcalout_twr) HCALOuter_Towers();
254  if (do_hcalout_cluster) HCALOuter_Clusters();
255 
256  if (do_FEMC_twr) FEMC_Towers();
257  if (do_FEMC_cluster) FEMC_Clusters();
258 
259  if (do_FHCAL_twr) FHCAL_Towers();
260  if (do_FHCAL_cluster) FHCAL_Clusters();
261 
262  if (do_dst_compress) ShowerCompress();
263 
264  //--------------
265  // SVTX tracking
266  //--------------
267 
268  if (do_svtx_track) Svtx_Reco();
269 
270  //--------------
271  // FGEM tracking
272  //--------------
273 
274  if(do_FGEM_track) FGEM_FastSim_Reco();
275 
276  //-----------------
277  // Global Vertexing
278  //-----------------
279 
280  if (do_global)
281  {
282  gROOT->LoadMacro("G4_Global.C");
283  Global_Reco();
284  }
285 
286  else if (do_global_fastsim)
287  {
288  gROOT->LoadMacro("G4_Global.C");
289  Global_FastSim();
290  }
291 
292  //---------
293  // Jet reco
294  //---------
295 
296  if (do_jet_reco)
297  {
298  gROOT->LoadMacro("G4_Jets.C");
299  Jet_Reco();
300  }
301 
302  if (do_fwd_jet_reco)
303  {
304  gROOT->LoadMacro("G4_FwdJets.C");
305  Jet_FwdReco();
306  }
307  //----------------------
308  // Simulation evaluation
309  //----------------------
310 
311  if (do_svtx_eval) Svtx_Eval("g4svtx_eval.root");
312 
313  if (do_cemc_eval) CEMC_Eval("g4cemc_eval.root");
314 
315  if (do_hcalin_eval) HCALInner_Eval("g4hcalin_eval.root");
316 
317  if (do_hcalout_eval) HCALOuter_Eval("g4hcalout_eval.root");
318 
319  if (do_jet_eval) Jet_Eval("g4jet_eval.root");
320 
321  if (do_fwd_jet_eval) Jet_FwdEval("g4fwdjet_eval.root");
322 
323 
324  gSystem->Load("libPhotons.so");
325  Forward_pi0s *photons = new Forward_pi0s(outputFile);
326  photons->Verbosity(0);
327 
328  photons->set_cluspt_mincut(0.5);
329  photons->set_eta_lowhigh(1.1,3.5);
330  se->registerSubsystem(photons);
331 
332 
333 
334 
335  //--------------
336  // IO management
337  //--------------
338 
339  if (readhits)
340  {
341  // Hits file
342  Fun4AllInputManager *hitsin = new Fun4AllDstInputManager("DSTin");
343  hitsin->fileopen(inputFile);
344  se->registerInputManager(hitsin);
345  }
346  if (do_embedding)
347  {
348  if (embed_input_file == NULL)
349  {
350  cout << "Missing embed_input_file! Exit";
351  exit(3);
352  }
353 
354  Fun4AllDstInputManager *in1 = new Fun4AllNoSyncDstInputManager("DSTinEmbed");
355  // in1->AddFile(embed_input_file); // if one use a single input file
356  in1->AddListFile(embed_input_file); // RecommendedL: if one use a text list of many input files
357  se->registerInputManager(in1);
358  }
359  if (readhepmc)
360  {
362  se->registerInputManager( in );
363  se->fileopen( in->Name().c_str(), inputFile );
364  }
365  else
366  {
367  // for single particle generators we just need something which drives
368  // the event loop, the Dummy Input Mgr does just that
370  se->registerInputManager( in );
371  }
372 
373  if (do_DSTReader)
374  {
375  //Convert DST to human command readable TTree for quick poke around the outputs
376  gROOT->LoadMacro("G4_DSTReader_fsPHENIX.C");
377 
378  G4DSTreader_fsPHENIX( outputFile, //
379  /*int*/ absorberactive ,
380  /*bool*/ do_svtx ,
381  /*bool*/ do_cemc ,
382  /*bool*/ do_hcalin ,
383  /*bool*/ do_magnet ,
384  /*bool*/ do_hcalout ,
385  /*bool*/ do_cemc_twr ,
386  /*bool*/ do_hcalin_twr ,
387  /*bool*/ do_magnet ,
388  /*bool*/ do_hcalout_twr,
389  /*bool*/ do_FGEM,
390  /*bool*/ do_FHCAL,
391  /*bool*/ do_FHCAL_twr,
392  /*bool*/ do_FEMC,
393  /*bool*/ do_FEMC_twr
394  );
395  }
396 
397  //Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outputFile);
398  //if (do_dst_compress) DstCompress(out);
399  //se->registerOutputManager(out);
400 
401  if (nEvents == 0 && !readhits && !readhepmc)
402  {
403  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
404  cout << "it will run forever, so I just return without running anything" << endl;
405  return;
406  }
407 
408  if (nEvents < 0)
409  {
410  PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO");
411  g4->ApplyCommand("/control/execute vis.mac");
412  //g4->StartGui();
413  se->run(1);
414 
415  se->End();
416  std::cout << "All done" << std::endl;
417 
418 
419  std::cout << "==== Useful display commands ==" << std::endl;
420  cout << "draw axis: " << endl;
421  cout << " G4Cmd(\"/vis/scene/add/axes 0 0 0 50 cm\")" << endl;
422  cout << "zoom" << endl;
423  cout << " G4Cmd(\"/vis/viewer/zoom 1\")" << endl;
424  cout << "viewpoint:" << endl;
425  cout << " G4Cmd(\"/vis/viewer/set/viewpointThetaPhi 0 0\")" << endl;
426  cout << "panTo:" << endl;
427  cout << " G4Cmd(\"/vis/viewer/panTo 0 0 cm\")" << endl;
428  cout << "print to eps:" << endl;
429  cout << " G4Cmd(\"/vis/ogl/printEPS\")" << endl;
430  cout << "set background color:" << endl;
431  cout << " G4Cmd(\"/vis/viewer/set/background white\")" << endl;
432  std::cout << "===============================" << std::endl;
433  }
434  else
435  {
436 
437  se->run(nEvents);
438 
439  se->End();
440  std::cout << "All done" << std::endl;
441  delete se;
442  gSystem->Exit(0);
443  }
444 
445 }
446 
447 
448 void
449 G4Cmd(const char * cmd)
450 {
452  PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO");
453  g4->ApplyCommand(cmd);
454 }