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