Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_EICAnalysis_DVCS.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_EICAnalysis_DVCS.C
2  const int nEvents = 10,
3  const char * inputFile = "example_tesst.dat",
4  const char * outputFile = "G4sPHENIXCells.root",
5  const char * embed_input_file = "/sphenix/sim/sim01/production/2016-07-12/sHijing/spacal2d/G4Hits_sPHENIX_sHijing-0-4.4fm.list"
6  )
7 {
8  //===============
9  // Input options
10  //===============
11 
12  // Either:
13  // read previously generated g4-hits files, in this case it opens a DST and skips
14  // the simulations step completely. The G4Setup macro is only loaded to get information
15  // about the number of layers used for the cell reco code
16  //
17  // In case reading production output, please double check your G4Setup_sPHENIX.C and G4_*.C consistent with those in the production macro folder
18  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
19  const bool readhits = false;
20  // Or:
21  // read files in HepMC format (typically output from event generators like hijing or pythia)
22  const bool readhepmc = false; // read HepMC files
23  // Or:
24  // Use pythia
25  const bool runpythia8 = false;
26  const bool runpythia6 = false;
27  const bool runhepgen = true;
28  // else
29  // Use particle generator (default simple generator)
30  // or gun/ very simple generator
31  const bool usegun = false;
32 
33  const bool readeictree = false;
34 
35  gSystem->Load("libfun4all.so");
36  // gSystem->Load("libg4detectors.so");
37  gSystem->Load("libphhepmc.so");
38  gSystem->Load("libg4testbench.so");
39  gSystem->Load("libg4hough.so");
40  // gSystem->Load("libg4eval.so");
41  gSystem->Load("libeicana.so");
42 
43  // establish the geometry and reconstruction setup
44  // gROOT->LoadMacro("G4Setup_sPHENIX.C");
45  // G4Init(do_svtx,do_preshower,do_cemc,do_hcalin,do_magnet,do_hcalout,do_pipe);
46 
47  // int absorberactive = 1; // set to 1 to make all absorbers active volumes
48  // const string magfield = "1.5"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
49  const string magfield = "/phenix/upgrades/decadal/fieldmaps/sPHENIX.2d.root"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
50  const float magfield_rescale = 1.4/1.5; // scale the map to a 1.4 T field
51 
52  //---------------
53  // Fun4All server
54  //---------------
55 
57  se->Verbosity(0);
58  // just if we set some flags somewhere in this macro
59  // recoConsts *rc = recoConsts::instance();
60  // By default every random number generator uses
61  // PHRandomSeed() which reads /dev/urandom to get its seed
62  // if the RANDOMSEED flag is set its value is taken as seed
63  // You ca neither set this to a random value using PHRandomSeed()
64  // which will make all seeds identical (not sure what the point of
65  // this would be:
66  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
67  // or set it to a fixed value so you can debug your code
68  // rc->set_IntFlag("RANDOMSEED", 12345);
69 
70  //-----------------
71  // Event generation
72  //-----------------
73 
74  if (readhits)
75  {
76  // Get the hits from a file
77  // The input manager is declared later
78  }
79  else if (readhepmc)
80  {
81  // this module is needed to read the HepMC records into our G4 sims
82  // but only if you read HepMC input files
83  HepMCNodeReader *hr = new HepMCNodeReader();
84  se->registerSubsystem(hr);
85  }
86  /* Read EICTree files */
87  else if (readeictree)
88  {
89  // this module is needed to read the EICTree style records into our G4 sims
90  ReadEICFiles *eicr = new ReadEICFiles();
91  eicr->OpenInputFile(inputFile);
92 
93  se->registerSubsystem(eicr);
94 
95  HepMCNodeReader *hr = new HepMCNodeReader();
96  se->registerSubsystem(hr);
97 
98  }
99  else if (runpythia8)
100  {
101  gSystem->Load("libPHPythia8.so");
102 
103  PHPythia8* pythia8 = new PHPythia8();
104  // see coresoftware/generators/PHPythia8 for example config
105  pythia8->set_config_file("phpythia8.cfg");
106  se->registerSubsystem(pythia8);
107 
108  HepMCNodeReader *hr = new HepMCNodeReader();
109  se->registerSubsystem(hr);
110  }
111  else if (runpythia6)
112  {
113  gSystem->Load("libPHPythia6.so");
114 
115  PHPythia6 *pythia6 = new PHPythia6();
116  pythia6->set_config_file("phpythia6.cfg");
117  se->registerSubsystem(pythia6);
118 
119  HepMCNodeReader *hr = new HepMCNodeReader();
120  se->registerSubsystem(hr);
121  }
122  else if (runhepgen)
123  {
124  gSystem->Load("libsHEPGen.so");
125 
126  sHEPGen *hepgen = new sHEPGen();
127  hepgen->set_datacard_file("hepgen_dvcs.data");
128  hepgen->set_momentum_electron(20);
129  hepgen->set_momentum_hadron(250);
130  se->registerSubsystem(hepgen);
131 
132  // HepMCNodeReader *hr = new HepMCNodeReader();
133  // se->registerSubsystem(hr);
134  }
135  else
136  {
137  // toss low multiplicity dummy events
139  gen->add_particles("e-",1); // mu+,e+,proton,pi+,Upsilon
140  // gen->add_particles("e+",5); // mu-,e-,anti_proton,pi-
141  if (readhepmc)
142  {
143  gen->set_reuse_existing_vertex(true);
144  gen->set_existing_vertex_offset_vector(0.0, 0.0, 0.0);
145  }
146  else
147  {
151  gen->set_vertex_distribution_mean(0.0, 0.0, 0.0);
152  gen->set_vertex_distribution_width(0.0, 0.0, 5.0);
153  }
155  gen->set_vertex_size_parameters(0.0, 0.0);
156  gen->set_eta_range(-0.5, 0.5);
157  gen->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
158  gen->set_pt_range(0.1, 10.0);
159  gen->Embed(1);
160  gen->Verbosity(0);
161  if (! usegun)
162  {
163  se->registerSubsystem(gen);
164  }
165  else
166  {
167  PHG4ParticleGun *gun = new PHG4ParticleGun();
168  // gun->set_name("anti_proton");
169  gun->set_name("geantino");
170  gun->set_vtx(0, 0, 0);
171  gun->set_mom(10, 0, 0.01);
172  // gun->AddParticle("geantino",1.7776,-0.4335,0.);
173  // gun->AddParticle("geantino",1.7709,-0.4598,0.);
174  // gun->AddParticle("geantino",2.5621,0.60964,0.);
175  // gun->AddParticle("geantino",1.8121,0.253,0.);
176  // se->registerSubsystem(gun);
178  pgen->set_name("geantino");
179  pgen->set_z_range(0,0);
180  pgen->set_eta_range(0.01,0.01);
181  pgen->set_mom_range(10,10);
182  pgen->set_phi_range(5.3./180.*TMath::Pi(),5.7./180.*TMath::Pi());
183  se->registerSubsystem(pgen);
184  pgen = new PHG4ParticleGenerator();
185  pgen->set_name("geantino");
186  pgen->set_z_range(0,0);
187  pgen->set_eta_range(0.01,0.01);
188  pgen->set_mom_range(10,10);
189  pgen->set_phi_range(-0.2./180.*TMath::Pi(),0.2./180.*TMath::Pi());
190  se->registerSubsystem(pgen);
191  }
192  }
193 
194 
195  if (readhits)
196  {
197  // Hits file
198  Fun4AllInputManager *hitsin = new Fun4AllDstInputManager("DSTin");
199  hitsin->fileopen(inputFile);
200  se->registerInputManager(hitsin);
201  }
202  if (readhepmc)
203  {
205  se->registerInputManager( in );
206  se->fileopen( in->Name().c_str(), inputFile );
207  }
208  else
209  {
210  // for single particle generators we just need something which drives
211  // the event loop, the Dummy Input Mgr does just that
212  // Fun4AllInputManager *in = new Fun4AllDummyInputManager( "JADE");
213  // se->registerInputManager( in );
214  }
215 
216 
217  //--------------
218  // Analysis modules
219  //--------------
220  DISKinematics *mcana = new DISKinematics(outputFile);
221  se->registerSubsystem( mcana );
222 
223 
224  //-----------------
225  // Event processing
226  //-----------------
227  if (nEvents < 0)
228  {
229  return;
230  }
231  // if we run the particle generator and use 0 it'll run forever
232  if (nEvents == 0 && !readhits && !readhepmc)
233  {
234  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
235  cout << "it will run forever, so I just return without running anything" << endl;
236  return;
237  }
238 
239  se->run(nEvents);
240 
241  //-----
242  // Exit
243  //-----
244 
245  se->End();
246  std::cout << "All done" << std::endl;
247  delete se;
248  gSystem->Exit(0);
249 }