EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_Babar.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_Babar.C
1 #ifndef MACRO_FUN4ALLG4BABAR_C
2 #define MACRO_FUN4ALLG4BABAR_C
3 
4 #include "GlobalVariables.C"
5 
6 #include "DisplayOn.C"
7 #include "G4Setup_Babar.C"
8 #include "G4_DSTReader_Babar.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 = "G4Babar.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 = 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 = 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 (Input::SIMPLE)
101  {
102  INPUTGENERATOR::SimpleEventGenerator->add_particles("pi-", 5);
103  if (Input::HEPMC || Input::EMBED)
104  {
105  INPUTGENERATOR::SimpleEventGenerator->set_reuse_existing_vertex(true);
106  INPUTGENERATOR::SimpleEventGenerator->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
107  }
108  else
109  {
113  INPUTGENERATOR::SimpleEventGenerator->set_vertex_distribution_mean(0., 0., 0.);
114  INPUTGENERATOR::SimpleEventGenerator->set_vertex_distribution_width(0., 0., 5.);
115  }
116  INPUTGENERATOR::SimpleEventGenerator->set_eta_range(-1, 1);
118  INPUTGENERATOR::SimpleEventGenerator->set_pt_range(0.1, 20.);
119  }
120  // Upsilons
121  if (Input::UPSILON)
122  {
123  INPUTGENERATOR::VectorMesonGenerator->add_decay_particles("e", 0);
124  INPUTGENERATOR::VectorMesonGenerator->set_rapidity_range(-1, 1);
125  INPUTGENERATOR::VectorMesonGenerator->set_pt_range(0., 10.);
126  // Y species - select only one, last one wins
127  INPUTGENERATOR::VectorMesonGenerator->set_upsilon_1s();
128  }
129  // particle gun
130  if (Input::GUN)
131  {
132  INPUTGENERATOR::Gun->AddParticle("pi-", 0, 1, 0);
133  INPUTGENERATOR::Gun->set_vtx(0, 0, 0);
134  }
135 
136  //--------------
137  // Set Input Manager specific options
138  //--------------
139  // can only be set after InputInit() is called
140 
141  if (Input::HEPMC)
142  {
143  INPUTMANAGER::HepMCInputManager->set_vertex_distribution_width(100e-4, 100e-4, 30, 0); //optional collision smear in space, time
144  // INPUTMANAGER::HepMCInputManager->set_vertex_distribution_mean(0,0,0,0);//optional collision central position shift in space, time
145  // //optional choice of vertex distribution function in space, time
151  //INPUTMANAGER::HepMCInputManager->set_embedding_id(2);
152  }
153  // register all input generators with Fun4All
154  InputRegister();
155 
156  //======================
157  // Write the DST
158  //======================
159 
160  // Enable::DSTOUT = true;
161  Enable::DSTOUT_COMPRESS = false;
162  DstOut::OutputDir = outdir;
163  DstOut::OutputFile = outputFile;
164 
165  //Option to convert DST to human command readable TTree for quick poke around the outputs
166  Enable::DSTREADER = true;
167 
168  // turn the display on (default off)
169  Enable::DISPLAY = false;
170 
171  //======================
172  // What to run
173  //======================
174 
175  // whether to simulate the Be section of the beam pipe
176  Enable::PIPE = true;
177  Enable::PIPE_ABSORBER = true;
178  // EIC beam pipe extension beyond the Be-section:
180 
181  Enable::MAGNET = true;
183 
184  // new settings using Enable namespace in GlobalVariables.C
185  Enable::BLACKHOLE = true;
186  // leave 1m gap so we can see tracks outside detector, comment out when you
187  // want to use the black hole to measure leakage
188  BlackHoleGeometry::gap = 100.; // leave 1m gap so we can see tracks outside detector
189  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
190  //BlackHoleGeometry::visible = true;
191 
192  //---------------
193  // World Settings
194  //---------------
195  // G4WORLD::PhysicsList = "QGSP_BERT"; //FTFP_BERT_HP best for calo
196  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
197 
198  //---------------
199  // Magnet Settings
200  //---------------
201 
202  // 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)
203  // G4MAGNET::magfield = string(getenv("CALIBRATIONROOT")) + string("/Field/Map/sPHENIX.2d.root"); // default map from the calibration database
204  G4MAGNET::magfield_rescale = -1.4 / 1.5; // make consistent with expected Babar field strength of 1.4T
205 
206  // establish the geometry and reconstruction setup
207  G4Init();
208 
209  if (!Input::READHITS)
210  {
211  //---------------------
212  // Detector description
213  //---------------------
214 
215  G4Setup();
216  }
217 
218  string outputroot = outputFile;
219  string remove_this = ".root";
220  size_t pos = outputroot.find(remove_this);
221  if (pos != string::npos)
222  {
223  outputroot.erase(pos, remove_this.length());
224  }
225 
226  if (Enable::DSTREADER) G4DSTreader(outputroot + "_DSTReader.root");
227 
228  //--------------
229  // Set up Input Managers
230  //--------------
231 
232  InputManagers();
233 
234  if (Enable::DSTOUT)
235  {
236  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
237  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
239  se->registerOutputManager(out);
240  }
241 
242  //-----------------
243  // Event processing
244  //-----------------
245  if (nEvents < 0)
246  {
247  return 0;
248  }
249  // if we run the particle generator and use 0 it'll run forever
250  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS)
251  {
252  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
253  cout << "it will run forever, so I just return without running anything" << endl;
254  return 0;
255  }
256 
257  if (Enable::DISPLAY)
258  {
259  DisplayOn();
260  // prevent macro from finishing so can see display
261  int i;
262  cout << "***** Enter any integer to proceed" << endl;
263  cin >> i;
264  }
265 
266  se->run(nEvents);
267 
268  //-----
269  // Exit
270  //-----
271 
272  se->End();
273  std::cout << "All done" << std::endl;
274  delete se;
275  gSystem->Exit(0);
276  return 0;
277 }
278 
279 #endif // MACRO_FUN4ALLG4BABAR_C