EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_sPHENIX_particle_gen.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_sPHENIX_particle_gen.C
1 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
2 #include <phool/PHRandomSeed.h>
3 #include <fun4all/SubsysReco.h>
13 #include <g4main/HepMCNodeReader.h>
15 #include <phool/recoConsts.h>
16 #include "G4Setup_sPHENIX.C"
17 #include "G4_Global.C"
18 #include "G4_DSTReader.C"
19 #include "DisplayOn.C"
20 
21 R__LOAD_LIBRARY(libfun4all.so)
22 R__LOAD_LIBRARY(libg4testbench.so)
23 R__LOAD_LIBRARY(libphhepmc.so)
24 
25 #endif
26 
27 using namespace std;
28 
30  const int nEvents = 1,
31  const char *outputFile = "G4sPHENIX.root",
32  const char *genpar = "pi-")
33 {
34  const bool usegun = true;
35  bool do_pipe = true;
36  bool do_tracking = true;
37  bool do_global_fastsim = false;
38 
39  //---------------
40  // Load libraries
41  //---------------
42  gSystem->Load("libfun4all.so");
43  gSystem->Load("libg4detectors.so");
44  gSystem->Load("libg4testbench.so");
45  gSystem->Load("libg4eval.so");
46  gSystem->Load("libg4intt.so");
47 
48  // establish the geometry and reconstruction setup
49  gROOT->LoadMacro("G4Setup_sPHENIX.C");
50  G4Init(do_tracking,false,false,false,false,false,do_pipe,false,false);
51 
52  int absorberactive = 1; // set to 1 to make all absorbers active volumes
53 
54  // 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)
55  const string magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root"); // default map from the calibration database
56  const float magfield_rescale = -1.4 / 1.5; // scale the map to a 1.4 T field
57 
58  //---------------
59  // Fun4All server
60  //---------------
61  bool display_on = false;
62  if(display_on) gROOT->LoadMacro("DisplayOn.C");
63 
65  se->Verbosity(0);
66 
67  // just if we set some flags somewhere in this macro
69  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
70  // rc->set_IntFlag("RANDOMSEED", 12345);
71 
72  //-----------------
73  // Event generation
74  //-----------------
75  if (usegun)
76  {
78  gen->set_name(std::string(genpar)); // geantino, pi-, pi+, mu-, mu+, e-., e+, proton, ... (currently passed as an input)
79  gen->set_vtx(0,0,0); // Vertex generation range
80  gen->set_mom_range(.00001,8.); // Momentum generation range in GeV/c
81  gen->set_z_range(0.,0.);
82  gen->set_eta_range(-1.5,1.5); // Detector coverage corresponds to |η|< 4
83  gen->set_phi_range(0.,2.*TMath::Pi());
84  se->registerSubsystem(gen);
85  }
86 
87  //---------------------
88  // Detector description
89  //---------------------
90 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
91  G4Setup(absorberactive, magfield, EDecayType::kAll,
92  do_tracking, false , false , false , false , false , do_pipe, false , false , magfield_rescale);
93 #else
94  G4Setup(absorberactive, magfield, TPythia6Decayer::kAll,
95  do_tracking, false , false , false , false , false , do_pipe, false , false , magfield_rescale);
96 #endif
97  Tracking_Cells();
98  Tracking_Clus();
99  Tracking_Reco();
100 
101  //-----------------
102  // Global Vertexing
103  //-----------------
104  if (do_global_fastsim){
105  gROOT->LoadMacro("G4_Global.C");
106  Global_FastSim();
107  }
108 
109  Tracking_Eval(string(outputFile) + "_g4svtx_eval.root");
110 
111  //--------------
112  // IO management
113  //--------------
115  se->registerInputManager(in);
116 
117  //-----------------
118  // Event processing
119  //-----------------
120  if (nEvents <= 0) return 0;
121 
122  if(display_on)
123  {
124  DisplayOn();
125  // prevent macro from finishing so can see display
126  int i;
127  cout << "***** Enter any integer to proceed" << endl;
128  cin >> i;
129  }
130 
131  se->run(nEvents);
132 
133  //-----
134  // Exit
135  //-----
136  se->End();
137  std::cout << "All done" << std::endl;
138  delete se;
139  gSystem->Exit(0);
140  return 0;
141 }