EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_Generator_Display.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_Generator_Display.C
1 #pragma once
2 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
3 #include <fun4all/SubsysReco.h>
11 #include <g4main/PHG4ParticleGun.h>
12 #include <g4main/PHG4Reco.h>
13 #include <g4main/HepMCNodeReader.h>
14 #include <g4main/ReadEICFiles.h>
16 #include <phool/recoConsts.h>
17 #include <phpythia6/PHPythia6.h>
18 #include <phpythia8/PHPythia8.h>
19 #include <phsartre/PHSartre.h>
20 R__LOAD_LIBRARY(libfun4all.so)
21 R__LOAD_LIBRARY(libg4testbench.so)
22 R__LOAD_LIBRARY(libPHPythia6.so)
23 R__LOAD_LIBRARY(libPHPythia8.so)
24 //R__LOAD_LIBRARY(libPHSartre.so)
25 #endif
26 
27 using namespace std;
28 
29 PHG4Reco *g4 = nullptr;
30 
32  const int nEvents = 1,
33  const std::string &inputFile = "input.root"
34  )
35 {
36  //===============
37  // Input options
38  //===============
39 
40  // Either:
41  // read previously generated g4-hits files, in this case it opens a DST and skips
42  // the simulations step completely. The G4Setup macro is only loaded to get information
43  // about the number of layers used for the cell reco code
44  //
45  // In case reading production output, please double check your G4Setup_sPHENIX.C and G4_*.C consistent with those in the production macro folder
46  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
47  // Or:
48  // read files in HepMC format (typically output from event generators like hijing or pythia)
49  const bool readhepmc = false; // read HepMC files
50  // Or:
51  // read files in EICTree format generated by eicsmear package
52  const bool readeictree = false;
53  // Or:
54  // Use Pythia 8
55  const bool runpythia8 = false;
56  // Or:
57  // Use Pythia 6
58  const bool runpythia6 = true;
59  // Or:
60  // Use Sartre - DO NOT USE RIGHT NOW
61  const bool runsartre = false;
62 
63 
64 
65 
66  // Besides the above flags. One can further choose to further put in following particles in Geant4 simulation
67  // Use multi-particle generator (PHG4SimpleEventGenerator), see the code block below to choose particle species and kinematics
68  const bool particles = false;
69  // or gun/ very simple single particle gun generator
70  const bool usegun = false;
71  // Throw single Upsilons, may be embedded in Hijing by setting readhepmc flag also (note, careful to set Z vertex equal to Hijing events)
72  const bool upsilons = false;
73 
74  const double magfield = 1.5; // in T
75 
76  //---------------
77  // Fun4All server
78  //---------------
79 
81 // se->Verbosity(1); // do some blabbering
82  // just if we set some flags somewhere in this macro
84  // By default every random number generator uses
85  // PHRandomSeed() which reads /dev/urandom to get its seed
86  // if the RANDOMSEED flag is set its value is taken as seed
87  // rc->set_IntFlag("RANDOMSEED", 12345);
88 
89  //-----------------
90  // Event generation
91  //-----------------
92 
93  if (readeictree)
94  {
95  // this module is needed to read the EICTree style records into our G4 sims
96  ReadEICFiles *eicr = new ReadEICFiles();
97  eicr->OpenInputFile(inputFile);
98 
99  se->registerSubsystem(eicr);
100  }
101  else if (runpythia8)
102  {
103  gSystem->Load("libPHPythia8.so");
104 
105  PHPythia8* pythia8 = new PHPythia8();
106  // see coresoftware/generators/PHPythia8 for example config
107  pythia8->set_config_file("phpythia8.cfg");
108  se->registerSubsystem(pythia8);
109  }
110  else if (runpythia6)
111  {
112  gSystem->Load("libPHPythia6.so");
113 
114  PHPythia6 *pythia6 = new PHPythia6();
115  // see coresoftware/generators/PHPythia6 for example config
116  pythia6->set_config_file("phpythia6.cfg");
117  se->registerSubsystem(pythia6);
118  }
119  else if (runsartre)
120  {
121  // see coresoftware/generators/PHSartre/README for setup instructions
122  gSystem->Load("libPHSartre.so");
123  PHSartre* mysartre = new PHSartre();
124  // see coresoftware/generators/PHSartre for example config
125  mysartre->set_config_file("sartre.cfg");
126  se->registerSubsystem(mysartre);
127  }
128 
129  if(particles)
130  {
131  // toss low multiplicity dummy events
133  gen->add_particles("pi-",1); // mu+,e+,proton,pi+,Upsilon
134  //gen->add_particles("pi+",100); // 100 pion option
135  if (readhepmc)
136  {
137  gen->set_reuse_existing_vertex(true);
138  gen->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
139  }
140  else
141  {
145  gen->set_vertex_distribution_mean(0.0, 0.0, 0.0);
146  gen->set_vertex_distribution_width(0.0, 0.0, 0.0);
147  }
149  gen->set_vertex_size_parameters(0.0, 0.0);
150  gen->set_eta_range(-3, 3);
151  gen->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
152  gen->set_pt_range(0.1, 20.0);
153  gen->Embed(1);
154  gen->Verbosity(0);
155 
156  se->registerSubsystem(gen);
157  }
158  if (usegun)
159  {
160  // PHG4ParticleGun *gun = new PHG4ParticleGun();
161  // gun->set_name("anti_proton");
162  // gun->set_name("geantino");
163  // gun->set_vtx(0, 0, 0);
164  // gun->set_mom(10, 0, 0.01);
165  // gun->AddParticle("geantino",1.7776,-0.4335,0.);
166  // gun->AddParticle("geantino",1.7709,-0.4598,0.);
167  // gun->AddParticle("geantino",2.5621,0.60964,0.);
168  // gun->AddParticle("geantino",1.8121,0.253,0.);
169  // se->registerSubsystem(gun);
171  pgen->set_name("mu-");
172  pgen->set_z_range(0,0);
173  pgen->set_eta_range(-4.0,0.0);
174  pgen->set_mom_range(30,30);
175  pgen->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
176  se->registerSubsystem(pgen);
177  }
178 
179  // If "readhepMC" is also set, the Upsilons will be embedded in Hijing events, if 'particles" is set, the Upsilons will be embedded in whatever particles are thrown
180  if(upsilons)
181  {
182  // run upsilons for momentum, dca performance, alone or embedded in Hijing
183 
185  vgen->add_decay_particles("e+","e-",0); // i = decay id
186  // event vertex
187  if (readhepmc || particles)
188  {
189  vgen->set_reuse_existing_vertex(true);
190  }
191 
192  // Note: this rapidity range completely fills the acceptance of eta = +/- 1 unit
193  vgen->set_rapidity_range(-1.0, +1.0);
194  vgen->set_pt_range(0.0, 10.0);
195 
196  int istate = 1;
197 
198  if(istate == 1)
199  {
200  // Upsilon(1S)
201  vgen->set_mass(9.46);
202  vgen->set_width(54.02e-6);
203  }
204  else if (istate == 2)
205  {
206  // Upsilon(2S)
207  vgen->set_mass(10.0233);
208  vgen->set_width(31.98e-6);
209  }
210  else
211  {
212  // Upsilon(3S)
213  vgen->set_mass(10.3552);
214  vgen->set_width(20.32e-6);
215  }
216 
217  vgen->Verbosity(0);
218  vgen->Embed(2);
219  se->registerSubsystem(vgen);
220 
221  cout << "Upsilon generator for istate = " << istate << " created and registered " << endl;
222  }
223 
224  //--------------
225  // Input Manager (HepMC or Dummy depending on input)
226  //--------------
227 
228  if (readhepmc)
229  {
231  se->registerInputManager( in );
232  se->fileopen( in->Name().c_str(), inputFile.c_str() );
233  }
234  else
235  {
236  // for single particle generators we just need something which drives
237  // the event loop, the Dummy Input Mgr does just that
239  se->registerInputManager( in );
240  }
241  // read-in HepMC events to Geant4 if there is any
242  HepMCNodeReader *hr = new HepMCNodeReader();
243  se->registerSubsystem(hr);
244  g4 = new PHG4Reco();
245  g4->set_rapidity_coverage(1.1); // according to drawings
246  g4->set_field(magfield);
247  g4->save_DST_geometry(false); // saving the geometry crashes here
248  se->registerSubsystem(g4);
249 
250 // Start the display
251  g4->InitRun(se->topNode());
253  g4->ApplyCommand("/control/execute vis.mac");
254 // draw 1m long axis
255  g4->ApplyCommand("/vis/scene/add/axes 0 0 0 100 cm");
256  se->run(1);
257 // print some empty lines so the instructions stick out
258  for (int i=0; i<5; i++)
259  {
260  cout << endl;
261  }
262  cout << "Type displaycmd() to see some commands to change the display" << endl;
263  cout << "If you want to run more events, do:" << endl;
264  cout << "Fun4AllServer *se = Fun4AllServer::instance();" << endl;
265  cout << "se->run(1);" << endl;
266  return 0;
267 }
268 
270 {
271  cout << "draw 1m axis: " << endl;
272  cout << " g4->ApplyCommand(\"/vis/scene/add/axes 0 0 0 100 cm\")" << endl;
273  cout << "zoom" << endl;
274  cout << " g4->ApplyCommand(\"/vis/viewer/zoom 1\")" << endl;
275  cout << "viewpoint:" << endl;
276  cout << " g4->ApplyCommand(\"/vis/viewer/set/viewpointThetaPhi 0 0\")" << endl;
277  cout << "panTo:" << endl;
278  cout << " g4->ApplyCommand(\"/vis/viewer/panTo 0 0 cm\")" << endl;
279  cout << "print to eps:" << endl;
280  cout << " g4->ApplyCommand(\"/vis/ogl/printEPS\")" << endl;
281  cout << "set background color:" << endl;
282  cout << " g4->ApplyCommand(\"/vis/viewer/set/background white\")" << endl;
283 }