Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_sPHENIX_AnaGenFit.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_sPHENIX_AnaGenFit.C
1 
3  const int nEvents = 10000,
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 = "AnaSvtxTracksForGenFit.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 = true;
30 
31  bool do_pipe = true;
32 
33  bool do_svtx = true;
34  bool do_svtx_cell = true;
35  bool do_svtx_track = true;
36  bool do_svtx_eval = true;
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_dst_compress = false;
67 
68  //Option to convert DST to human command readable TTree for quick poke around the outputs
69  bool do_DSTReader = false;
70  //---------------
71  // Load libraries
72  //---------------
73 
74  gSystem->Load("libfun4all.so");
75  gSystem->Load("libg4detectors.so");
76  gSystem->Load("libphhepmc.so");
77  gSystem->Load("libg4testbench.so");
78  gSystem->Load("libg4hough.so");
79  gSystem->Load("libg4calo.so");
80  gSystem->Load("libg4eval.so");
81  gSystem->Load("libAnaSvtxTracksForGenFit.so");
82 
83  // establish the geometry and reconstruction setup
84  gROOT->LoadMacro("G4Setup_sPHENIX.C");
85  G4Init(do_svtx, do_preshower, do_cemc, do_hcalin, do_magnet, do_hcalout, do_pipe);
86 
87  int absorberactive = 1; // set to 1 to make all absorbers active volumes
88  // const string magfield = "1.5"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
89  const string magfield = "/phenix/upgrades/decadal/fieldmaps/sPHENIX.2d.root"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
90  const float magfield_rescale = 1.4 / 1.5; // scale the map to a 1.4 T field
91 
92  //---------------
93  // Fun4All server
94  //---------------
95 
97  se->Verbosity(0);
98  // just if we set some flags somewhere in this macro
100  // By default every random number generator uses
101  // PHRandomSeed() which reads /dev/urandom to get its seed
102  // if the RANDOMSEED flag is set its value is taken as seed
103  // You ca neither set this to a random value using PHRandomSeed()
104  // which will make all seeds identical (not sure what the point of
105  // this would be:
106  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
107  // or set it to a fixed value so you can debug your code
108  // rc->set_IntFlag("RANDOMSEED", 12345);
109 
110  //-----------------
111  // Event generation
112  //-----------------
113 
114  if (readhits)
115  {
116  // Get the hits from a file
117  // The input manager is declared later
118  }
119  else if (readhepmc)
120  {
121  // this module is needed to read the HepMC records into our G4 sims
122  // but only if you read HepMC input files
123  HepMCNodeReader *hr = new HepMCNodeReader();
124  se->registerSubsystem(hr);
125  }
126  else if (runpythia8)
127  {
128  gSystem->Load("libPHPythia8.so");
129 
130  PHPythia8* pythia8 = new PHPythia8();
131  // see coresoftware/generators/PHPythia8 for example config
132  pythia8->set_config_file("phpythia8.cfg");
133  se->registerSubsystem(pythia8);
134 
135  HepMCNodeReader *hr = new HepMCNodeReader();
136  se->registerSubsystem(hr);
137  }
138  else if (runpythia6)
139  {
140  gSystem->Load("libPHPythia6.so");
141 
142  PHPythia6 *pythia6 = new PHPythia6();
143  pythia6->set_config_file("phpythia6.cfg");
144  se->registerSubsystem(pythia6);
145 
146  HepMCNodeReader *hr = new HepMCNodeReader();
147  se->registerSubsystem(hr);
148  }
149  else
150  {
151  // toss low multiplicity dummy events
153  gen->add_particles("mu+", 1); // mu+,e+,proton,pi+,Upsilon
154  // gen->add_particles("e+",5); // mu-,e-,anti_proton,pi-
155  if (readhepmc) {
156  gen->set_reuse_existing_vertex(true);
157  gen->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
158  } else {
162  gen->set_vertex_distribution_mean(0.0, 0.0, 0.0);
163  gen->set_vertex_distribution_width(0.0, 0.0, 5.0);
164  }
166  gen->set_vertex_size_parameters(0.0, 0.0);
167  gen->set_eta_range(-0.5, 0.5);
168  gen->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
169  gen->set_pt_range(0.1, 10.0);
170  gen->Embed(1);
171  gen->Verbosity(0);
172  se->registerSubsystem(gen);
173  }
174 
175  if (!readhits)
176  {
177  //---------------------
178  // Detector description
179  //---------------------
180 
181  G4Setup(absorberactive, magfield, TPythia6Decayer::kAll,
182  do_svtx, do_preshower, do_cemc, do_hcalin, do_magnet, do_hcalout, do_pipe, magfield_rescale);
183  }
184 
185  //---------
186  // BBC Reco
187  //---------
188 
189  if (do_bbc)
190  {
191  gROOT->LoadMacro("G4_Bbc.C");
192  BbcInit();
193  Bbc_Reco();
194  }
195  //------------------
196  // Detector Division
197  //------------------
198 
199  if (do_svtx_cell) Svtx_Cells();
200 
201  if (do_cemc_cell) CEMC_Cells();
202 
203  if (do_hcalin_cell) HCALInner_Cells();
204 
205  if (do_hcalout_cell) HCALOuter_Cells();
206 
207  //-----------------------------
208  // CEMC towering and clustering
209  //-----------------------------
210 
211  if (do_cemc_twr) CEMC_Towers();
212  if (do_cemc_cluster) CEMC_Clusters();
213 
214  //-----------------------------
215  // HCAL towering and clustering
216  //-----------------------------
217 
218  if (do_hcalin_twr) HCALInner_Towers();
219  if (do_hcalin_cluster) HCALInner_Clusters();
220 
221  if (do_hcalout_twr) HCALOuter_Towers();
222  if (do_hcalout_cluster) HCALOuter_Clusters();
223 
224  if (do_dst_compress) ShowerCompress();
225 
226  //--------------
227  // SVTX tracking
228  //--------------
229 
230  if (do_svtx_track) Svtx_Reco();
231 
232  //-----------------
233  // Global Vertexing
234  //-----------------
235 
236  if (do_global)
237  {
238  gROOT->LoadMacro("G4_Global.C");
239  Global_Reco();
240  }
241 
242  else if (do_global_fastsim)
243  {
244  gROOT->LoadMacro("G4_Global.C");
245  Global_FastSim();
246  }
247 
248  //---------
249  // Jet reco
250  //---------
251 
252  if (do_jet_reco)
253  {
254  gROOT->LoadMacro("G4_Jets.C");
255  Jet_Reco();
256  }
257  //----------------------
258  // Simulation evaluation
259  //----------------------
260 
261  if (do_svtx_eval) Svtx_Eval("g4svtx_eval.root");
262 
263  if (do_cemc_eval) CEMC_Eval("g4cemc_eval.root");
264 
265  if (do_hcalin_eval) HCALInner_Eval("g4hcalin_eval.root");
266 
267  if (do_hcalout_eval) HCALOuter_Eval("g4hcalout_eval.root");
268 
269  if (do_jet_eval) Jet_Eval("g4jet_eval.root");
270 
271  //--------------
272  // IO management
273  //--------------
274 
275  if (readhits)
276  {
277  // Hits file
278  Fun4AllInputManager *hitsin = new Fun4AllDstInputManager("DSTin");
279  hitsin->fileopen(inputFile);
280  se->registerInputManager(hitsin);
281  }
282  if (readhepmc)
283  {
285  se->registerInputManager( in );
286  se->fileopen( in->Name().c_str(), inputFile );
287  }
288  else
289  {
290  // for single particle generators we just need something which drives
291  // the event loop, the Dummy Input Mgr does just that
293  se->registerInputManager( in );
294  }
295 
296  if (do_DSTReader)
297  {
298  //Convert DST to human command readable TTree for quick poke around the outputs
299  gROOT->LoadMacro("G4_DSTReader.C");
300 
301  G4DSTreader( outputFile, //
302  /*int*/ absorberactive ,
303  /*bool*/ do_svtx ,
304  /*bool*/ do_preshower ,
305  /*bool*/ do_cemc ,
306  /*bool*/ do_hcalin ,
307  /*bool*/ do_magnet ,
308  /*bool*/ do_hcalout ,
309  /*bool*/ do_cemc_twr ,
310  /*bool*/ do_hcalin_twr ,
311  /*bool*/ do_magnet ,
312  /*bool*/ do_hcalout_twr
313  );
314  }
315 
316  // Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outputFile);
317  // if (do_dst_compress) DstCompress(out);
318  // se->registerOutputManager(out);
319 
320  //-----------------
321  // Analysis Module
322  //-----------------
323 
325  ana->set_filename( outputFile );
326  se->registerSubsystem( ana );
327 
328  //-----------------
329  // Event processing
330  //-----------------
331  if (nEvents < 0)
332  {
333  return;
334  }
335  // if we run the particle generator and use 0 it'll run forever
336  if (nEvents == 0 && !readhits && !readhepmc)
337  {
338  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
339  cout << "it will run forever, so I just return without running anything" << endl;
340  return;
341  }
342 
343  se->run(nEvents);
344 
345  //-----
346  // Exit
347  //-----
348 
349  se->End();
350  std::cout << "All done" << std::endl;
351  delete se;
352  gSystem->Exit(0);
353 }