Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_EICIR.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_EICIR.C
1 
3  const int nEvents = 1,
4  const char * inputFile = "/gpfs02/phenix/prod/sPHENIX/preCDR/pro.1-beta.5/single_particle/spacal1d/fieldmap/G4Hits_sPHENIX_e-_eta0_16GeV.root",
5  const char * outputFile = "G4EICIR.root"
6  )
7 {
8  //===============
9  // Input options
10  //===============
11 
12  // Use particle gun
13  const bool pgun = true;
14 
15  //======================
16  // What to run
17  //======================
18 
19  bool do_pipe = false;
20 
21  bool do_magnet = true;
22 
23  // Extended IR
24  bool do_ExtendedIR = true;
25 
26  //---------------
27  // Load libraries
28  //---------------
29 
30  gSystem->Load("libfun4all.so");
31  gSystem->Load("libg4detectors.so");
32  gSystem->Load("libphhepmc.so");
33  gSystem->Load("libg4testbench.so");
34  gSystem->Load("libg4hough.so");
35  gSystem->Load("libg4eval.so");
36 
37  // establish the geometry and reconstruction setup
38  gROOT->LoadMacro("G4Setup_EICIR.C");
39  G4Init(do_magnet,do_pipe,do_ExtendedIR);
40 
41  int absorberactive = 0; // set to 1 to make all absorbers active volumes
42  // const string magfield = "1.5"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
43  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)
44  const float magfield_rescale = 1.4/1.5; // scale the map to a 1.4 T field
45 
46  //---------------
47  // Fun4All server
48  //---------------
49 
51  //se->Verbosity(100); // uncomment for batch production running with minimal output messages
52  se->Verbosity(Fun4AllServer::VERBOSITY_SOME); // uncomment for some info for interactive running
53  // just if we set some flags somewhere in this macro
55  // By default every random number generator uses
56  // PHRandomSeed() which reads /dev/urandom to get its seed
57  // if the RANDOMSEED flag is set its value is taken as seed
58  // You can either set this to a random value using PHRandomSeed()
59  // which will make all seeds identical (not sure what the point of
60  // this would be:
61  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
62  // or set it to a fixed value so you can debug your code
63  // rc->set_IntFlag("RANDOMSEED", 12345);
64 
65  //-----------------
66  // Event generation
67  //-----------------
68 
69  if (pgun)
70  {
71  /* angle of particle phi:
72  pz = p * cos(psi)
73  px = p * sin(psi) */
74  double psi_mrad = 0;
75 
76  double ptot = 250*1;
77 
78  double vx = 0;
79  double vy = 0;
80  double vz = 0;
81 
82  double px = ptot * sin(psi_mrad / 1000.);
83  double py = 0;
84  double pz = ptot * cos(psi_mrad / 1000.);
85 
86  PHG4ParticleGun*gun = new PHG4ParticleGun();
87  gun->set_name("proton");
88  gun->set_vtx(vx,vy,vz);
89  gun->set_mom(px,py,pz);
90  se->registerSubsystem(gun);
91  }
92  else
93  {
94  cout << "WARNING: No events being generated!" << endl;
95  }
96 
97  //---------------------
98  // Detector description
99  //---------------------
100 
101  G4Setup(absorberactive, magfield, TPythia6Decayer::kAll,do_magnet,do_pipe,do_ExtendedIR,magfield_rescale);
102 
103 
104 
105  //--------------
106  // IO management
107  //--------------
108 
109  // for single particle generators we just need something which drives
110  // the event loop, the Dummy Input Mgr does just that
112  se->registerInputManager( in );
113 
114  //Convert DST to human command readable TTree for quick poke around the outputs
115  gROOT->LoadMacro("G4_DSTReader_EICIR.C");
116 
117  G4DSTreader_EICIR( outputFile, //
118  /*int*/ absorberactive );
119 
120  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outputFile);
121  //if (do_dst_compress) DstCompress(out);
122  se->registerOutputManager(out);
123 
124  if (nEvents == 0 && !readhits && !readhepmc)
125  {
126  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
127  cout << "it will run forever, so I just return without running anything" << endl;
128  return;
129  }
130 
131  if (nEvents < 0)
132  {
133  PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO");
134  g4->ApplyCommand("/control/execute vis.mac");
135  //g4->StartGui();
136  se->run(1);
137 
138  se->End();
139  std::cout << "All done" << std::endl;
140 
141  std::cout << "==== Useful display commands ==" << std::endl;
142  cout << "draw axis: " << endl;
143  cout << " G4Cmd(\"/vis/scene/add/axes 0 0 0 50 cm\")" << endl;
144  cout << "zoom" << endl;
145  cout << " G4Cmd(\"/vis/viewer/zoom 1\")" << endl;
146  cout << "viewpoint:" << endl;
147  cout << " G4Cmd(\"/vis/viewer/set/viewpointThetaPhi 0 0\")" << endl;
148  cout << "panTo:" << endl;
149  cout << " G4Cmd(\"/vis/viewer/panTo 0 0 cm\")" << endl;
150  cout << "print to eps:" << endl;
151  cout << " G4Cmd(\"/vis/ogl/printEPS\")" << endl;
152  cout << "set background color:" << endl;
153  cout << " G4Cmd(\"/vis/viewer/set/background white\")" << endl;
154  std::cout << "===============================" << std::endl;
155  }
156  else
157  {
158  se->run(nEvents);
159 
160  se->End();
161  std::cout << "All done" << std::endl;
162  delete se;
163  gSystem->Exit(0);
164  }
165 
166 }
167 
168 
169 void
170 G4Cmd(const char * cmd)
171 {
173  PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco("PHG4RECO");
174  g4->ApplyCommand(cmd);
175 }