Analysis Software
Documentation for sPHENIX simulation 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 #ifndef MACRO_FUN4ALLGENERATORDISPLAY_C
2 #define MACRO_FUN4ALLGENERATORDISPLAY_C
3 
4 #include <fun4all/SubsysReco.h>
12 #include <g4main/PHG4ParticleGun.h>
13 #include <g4main/CosmicSpray.h>
14 #include <g4main/PHG4Reco.h>
15 #include <g4main/HepMCNodeReader.h>
16 #include <g4main/ReadEICFiles.h>
18 #include <phool/recoConsts.h>
19 #include <phpythia6/PHPythia6.h>
20 #include <phpythia8/PHPythia8.h>
21 #include <phsartre/PHSartre.h>
22 
23 R__LOAD_LIBRARY(libfun4all.so)
24 R__LOAD_LIBRARY(libg4testbench.so)
25 R__LOAD_LIBRARY(libPHPythia6.so)
26 R__LOAD_LIBRARY(libPHPythia8.so)
27 R__LOAD_LIBRARY(libPHSartre.so)
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 = true;
56  // Or:
57  // Use Pythia 6
58  const bool runpythia6 = false;
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 bool cosmic = false;
75 
76  const double magfield = 1.4; // in T
77 
78  //---------------
79  // Fun4All server
80  //---------------
81 
83 // se->Verbosity(1); // do some blabbering
84  // just if we set some flags somewhere in this macro
86  // By default every random number generator uses
87  // PHRandomSeed() which reads /dev/urandom to get its seed
88  // if the RANDOMSEED flag is set its value is taken as seed
89  // rc->set_IntFlag("RANDOMSEED", 12345);
90 
91  //-----------------
92  // Event generation
93  //-----------------
94 
95  if (readeictree)
96  {
97  // this module is needed to read the EICTree style records into our G4 sims
98  ReadEICFiles *eicr = new ReadEICFiles();
99  eicr->OpenInputFile(inputFile);
100 
101  se->registerSubsystem(eicr);
102  }
103  else if (runpythia8)
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  PHPythia6 *pythia6 = new PHPythia6();
113  // see coresoftware/generators/PHPythia6 for example config
114  pythia6->set_config_file("phpythia6.cfg");
115  se->registerSubsystem(pythia6);
116  }
117  else if (runsartre)
118  {
119  // see coresoftware/generators/PHSartre/README for setup instructions
120  PHSartre* mysartre = new PHSartre();
121  // see coresoftware/generators/PHSartre for example config
122  mysartre->set_config_file("sartre.cfg");
123  se->registerSubsystem(mysartre);
124  }
125 
126  if(particles)
127  {
128  // toss low multiplicity dummy events
130  gen->add_particles("pi-",1); // mu+,e+,proton,pi+,Upsilon
131  //gen->add_particles("pi+",100); // 100 pion option
132  if (readhepmc)
133  {
134  gen->set_reuse_existing_vertex(true);
135  gen->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
136  }
137  else
138  {
142  gen->set_vertex_distribution_mean(0.0, 0.0, 0.0);
143  gen->set_vertex_distribution_width(0.0, 0.0, 0.0);
144  }
146  gen->set_vertex_size_parameters(0.0, 0.0);
147  gen->set_eta_range(-3, 3);
148  gen->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
149  gen->set_pt_range(0.1, 20.0);
150  gen->Embed(1);
151  gen->Verbosity(0);
152 
153  se->registerSubsystem(gen);
154  }
155  if (usegun)
156  {
157  // PHG4ParticleGun *gun = new PHG4ParticleGun();
158  // gun->set_name("anti_proton");
159  // gun->set_name("geantino");
160  // gun->set_vtx(0, 0, 0);
161  // gun->set_mom(10, 0, 0.01);
162  // gun->AddParticle("geantino",1.7776,-0.4335,0.);
163  // gun->AddParticle("geantino",1.7709,-0.4598,0.);
164  // gun->AddParticle("geantino",2.5621,0.60964,0.);
165  // gun->AddParticle("geantino",1.8121,0.253,0.);
166  // se->registerSubsystem(gun);
168  pgen->set_name("mu-");
169  pgen->set_z_range(0,0);
170  pgen->set_eta_range(-4.0,0.0);
171  pgen->set_mom_range(30,30);
172  pgen->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
173  se->registerSubsystem(pgen);
174  }
175  if (cosmic)
176  {
177  CosmicSpray *cosmo = new CosmicSpray("CosmicGun",500.);
178  se->registerSubsystem(cosmo);
179  }
180 
181  // 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
182  if(upsilons)
183  {
184  // run upsilons for momentum, dca performance, alone or embedded in Hijing
185 
187  vgen->add_decay_particles("e+","e-",0); // i = decay id
188  // event vertex
189  if (readhepmc || particles)
190  {
191  vgen->set_reuse_existing_vertex(true);
192  }
193 
194  // Note: this rapidity range completely fills the acceptance of eta = +/- 1 unit
195  vgen->set_rapidity_range(-1.0, +1.0);
196  vgen->set_pt_range(0.0, 10.0);
197 
198  int istate = 1;
199 
200  if(istate == 1)
201  {
202  // Upsilon(1S)
203  vgen->set_mass(9.46);
204  vgen->set_width(54.02e-6);
205  }
206  else if (istate == 2)
207  {
208  // Upsilon(2S)
209  vgen->set_mass(10.0233);
210  vgen->set_width(31.98e-6);
211  }
212  else
213  {
214  // Upsilon(3S)
215  vgen->set_mass(10.3552);
216  vgen->set_width(20.32e-6);
217  }
218 
219  vgen->Verbosity(0);
220  vgen->Embed(2);
221  se->registerSubsystem(vgen);
222 
223  cout << "Upsilon generator for istate = " << istate << " created and registered " << endl;
224  }
225 
226  //--------------
227  // Input Manager (HepMC or Dummy depending on input)
228  //--------------
229 
230  if (readhepmc)
231  {
233  se->registerInputManager( in );
234  se->fileopen( in->Name(), inputFile );
235  }
236  else
237  {
238  // for single particle generators we just need something which drives
239  // the event loop, the Dummy Input Mgr does just that
241  se->registerInputManager( in );
242  }
243  // read-in HepMC events to Geant4 if there is any
244  HepMCNodeReader *hr = new HepMCNodeReader();
245  se->registerSubsystem(hr);
246 
247  g4 = new PHG4Reco();
248  g4->set_rapidity_coverage(1.1); // according to drawings
249  g4->set_field(magfield);
250  g4->save_DST_geometry(false); // saving the geometry crashes here
251  se->registerSubsystem(g4);
252 
253 // Start the display
254 
255  g4->InitRun(se->topNode());
257  g4->ApplyCommand("/control/execute vis.mac");
258 // draw 1m long axis
259  g4->ApplyCommand("/vis/scene/add/axes 0 0 0 100 cm");
260 
261  se->run(1);
262 // print some empty lines so the instructions stick out
263  for (int i=0; i<5; i++)
264  {
265  cout << endl;
266  }
267  cout << "Type displaycmd() to see some commands to change the display" << endl;
268  cout << "If you want to run more events, do:" << endl;
269  cout << "Fun4AllServer *se = Fun4AllServer::instance();" << endl;
270  cout << "se->run(1);" << endl;
271  return 0;
272 }
273 
275 {
276  cout << "draw 1m axis: " << endl;
277  cout << " g4->ApplyCommand(\"/vis/scene/add/axes 0 0 0 100 cm\")" << endl;
278  cout << "zoom" << endl;
279  cout << " g4->ApplyCommand(\"/vis/viewer/zoom 1\")" << endl;
280  cout << "viewpoint:" << endl;
281  cout << " g4->ApplyCommand(\"/vis/viewer/set/viewpointThetaPhi 0 0\")" << endl;
282  cout << "panTo:" << endl;
283  cout << " g4->ApplyCommand(\"/vis/viewer/panTo 0 0 cm\")" << endl;
284  cout << "print to eps:" << endl;
285  cout << " g4->ApplyCommand(\"/vis/ogl/printEPS\")" << endl;
286  cout << "set background color:" << endl;
287  cout << " g4->ApplyCommand(\"/vis/viewer/set/background white\")" << endl;
288 }
289 
290 #endif