EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_Beast.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_Beast.C
1 #ifndef MACRO_FUN4ALLG4BEAST_C
2 #define MACRO_FUN4ALLG4BEAST_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <DisplayOn.C>
7 #include <G4Setup_Beast.C>
8 #include <G4_DSTReader_Beast.C>
9 #include <G4_Input.C>
10 
13 #include <fun4all/Fun4AllServer.h>
14 
15 #include <phool/PHRandomSeed.h>
16 #include <phool/recoConsts.h>
17 
18 R__LOAD_LIBRARY(libfun4all.so)
19 R__LOAD_LIBRARY(libg4testbench.so)
20 
22  const int nEvents = 1,
23  const string &inputFile = "/sphenix/data/data02/review_2017-08-02/single_particle/spacal2d/fieldmap/G4Hits_sPHENIX_e-_eta0_8GeV-0002.root",
24  const string &outputFile = "G4Beast.root",
25  const string &embed_input_file = "/sphenix/data/data02/review_2017-08-02/sHijing/fm_0-4.list",
26  const int skip = 0,
27  const string &outdir = ".")
28 {
30  se->Verbosity(0);
31 
32  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
34 
35  // just if we set some flags somewhere in this macro
37  // By default every random number generator uses
38  // PHRandomSeed() which reads /dev/urandom to get its seed
39  // if the RANDOMSEED flag is set its value is taken as seed
40  // You can either set this to a random value using PHRandomSeed()
41  // which will make all seeds identical (not sure what the point of
42  // this would be:
43  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
44  // or set it to a fixed value so you can debug your code
45  // rc->set_IntFlag("RANDOMSEED", 12345);
46 
47  //===============
48  // Input options
49  //===============
50  // First enable the input generators
51  // Either:
52  // read previously generated g4-hits files, in this case it opens a DST and skips
53  // the simulations step completely. The G4Setup macro is only loaded to get information
54  // about the number of layers used for the cell reco code
55  // Input::READHITS = true;
56  INPUTREADHITS::filename[0] = inputFile;
57 
58  // Or:
59  // Use particle generator
60  // And
61  // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
62  // 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
63  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
64  // Input::EMBED = true;
65  INPUTEMBED::filename[0] = embed_input_file;
66 
67  Input::SIMPLE = true;
68  //Input::SIMPLE_VERBOSITY = 1;
69 
70  // Input::PYTHIA6 = true;
71 
72  // Input::PYTHIA8 = true;
73 
74  // Input::GUN = true;
75  //Input::GUN_VERBOSITY = 1;
76 
77  // Upsilon generator
78  // Input::UPSILON = true;
80 
81  // Input::HEPMC = true;
82  Input::VERBOSITY = 0;
83  INPUTHEPMC::filename = inputFile;
84 
85  // Event pile up simulation with collision rate in Hz MB collisions.
86  //Input::PILEUPRATE = 100e3;
87 
88  //-----------------
89  // Initialize the selected Input/Event generation
90  //-----------------
91  // This creates the input generator(s)
92  InputInit();
93 
94  //--------------
95  // Set generator specific options
96  //--------------
97  // can only be set after InputInit() is called
98 
99  // Simple Input generator:
100  // if you run more than one of these Input::SIMPLE_NUMBER > 1
101  // add the settings for other with [1], next with [2]...
102  if (Input::SIMPLE)
103  {
104  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi-", 5);
105  if (Input::HEPMC || Input::EMBED)
106  {
107  INPUTGENERATOR::SimpleEventGenerator[0]->set_reuse_existing_vertex(true);
108  INPUTGENERATOR::SimpleEventGenerator[0]->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
109  }
110  else
111  {
112  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Uniform,
115  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
116  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0., 0., 5.);
117  }
118  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1, 1);
119  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
120  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(0.1, 20.);
121  }
122  // Upsilons
123  // if you run more than one of these Input::UPSILON_NUMBER > 1
124  // add the settings for other with [1], next with [2]...
125  if (Input::UPSILON)
126  {
127  INPUTGENERATOR::VectorMesonGenerator[0]->add_decay_particles("e", 0);
128  INPUTGENERATOR::VectorMesonGenerator[0]->set_rapidity_range(-1, 1);
129  INPUTGENERATOR::VectorMesonGenerator[0]->set_pt_range(0., 10.);
130  // Y species - select only one, last one wins
131  INPUTGENERATOR::VectorMesonGenerator[0]->set_upsilon_1s();
132  }
133  // particle gun
134  // if you run more than one of these Input::GUN_NUMBER > 1
135  // add the settings for other with [1], next with [2]...
136  if (Input::GUN)
137  {
138  INPUTGENERATOR::Gun[0]->AddParticle("pi-", 0, 1, 0);
139  INPUTGENERATOR::Gun[0]->set_vtx(0, 0, 0);
140  }
141 
142  //--------------
143  // Set Input Manager specific options
144  //--------------
145  // can only be set after InputInit() is called
146 
147  if (Input::HEPMC)
148  {
149  INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 30, 0); //optional collision smear in space, time
150  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
151  // //optional choice of vertex distribution function in space, time
157  //INPUTMANAGER::HepMCInputManager->set_embedding_id(2);
158  }
159  // register all input generators with Fun4All
160  InputRegister();
161 
162  //======================
163  // Write the DST
164  //======================
165 
166  // Enable::DSTOUT = true;
167  Enable::DSTOUT_COMPRESS = false;
168  DstOut::OutputDir = outdir;
169  DstOut::OutputFile = outputFile;
170 
171  //Option to convert DST to human command readable TTree for quick poke around the outputs
172  Enable::DSTREADER = true;
173 
174  // turn the display on (default off)
175  Enable::DISPLAY = false;
176 
177  //======================
178  // What to run
179  //======================
180 
181  // whether to simulate the Be section of the beam pipe
182  Enable::PIPE = true;
183  Enable::PIPE_ABSORBER = true;
184  // EIC beam pipe extension beyond the Be-section:
186 
187  Enable::MAGNET = true;
189 
190  // new settings using Enable namespace in GlobalVariables.C
191  Enable::BLACKHOLE = true;
192  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
193  //BlackHoleGeometry::visible = true;
194 
195  //---------------
196  // Magnet Settings
197  //---------------
198 // use updated Beast field map (default is old mfield.4col.dat)
199  G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/EIC_Magnetic_Field_Map_2021_05_07_radial_coords_cm_T.120000.lines.Bmap");
200 
201 
202 
203  // establish the geometry and reconstruction setup
204  G4Init();
205 
206  if (!Input::READHITS)
207  {
208  //---------------------
209  // Detector description
210  //---------------------
211 
212  G4Setup();
213  }
214 
215  string outputroot = outputFile;
216  string remove_this = ".root";
217  size_t pos = outputroot.find(remove_this);
218  if (pos != string::npos)
219  {
220  outputroot.erase(pos, remove_this.length());
221  }
222 
223  if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
224 
225  //--------------
226  // Set up Input Managers
227  //--------------
228 
229  InputManagers();
230 
231  if (Enable::DSTOUT)
232  {
233  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
234  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
236  se->registerOutputManager(out);
237  }
238 
239  //-----------------
240  // Event processing
241  //-----------------
242  if (nEvents < 0)
243  {
244  return 0;
245  }
246  // if we run the particle generator and use 0 it'll run forever
247  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS)
248  {
249  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
250  cout << "it will run forever, so I just return without running anything" << endl;
251  return 0;
252  }
253 
254  if (Enable::DISPLAY)
255  {
256  DisplayOn();
257  // prevent macro from finishing so can see display
258  int i;
259  cout << "***** Enter any integer to proceed" << endl;
260  cin >> i;
261  }
262 
263  se->run(nEvents);
264 
265  //-----
266  // Exit
267  //-----
268 
269  se->End();
270  std::cout << "All done" << std::endl;
271  delete se;
272  gSystem->Exit(0);
273  return 0;
274 }
275 
276 #endif // MACRO_FUN4ALLG4BEAST_C