EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_IonGun.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_IonGun.C
1 #pragma once
2 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
3 #include <fun4all/SubsysReco.h>
10 #include <g4histos/G4EdepNtuple.h>
11 #include <g4histos/G4HitNtuple.h>
12 #include <g4main/PHG4IonGun.h>
13 #include <g4main/PHG4ParticleGun.h>
15 #include <g4main/PHG4Reco.h>
17 #include "GlobalVariables.h"
18 #include "DisplayOn.C"
19 
20 R__LOAD_LIBRARY(libfun4all.so)
21 R__LOAD_LIBRARY(libg4testbench.so)
22 R__LOAD_LIBRARY(libg4detectors.so)
23 R__LOAD_LIBRARY(libg4histos)
24 #endif
25 
26 void Fun4All_G4_IonGun(int nEvents = 10)
27 {
28 
29  bool WriteDst = true; // set to true if yoy want to save everything in a Dst
30 
32  // Make the Server
35  // se->Verbosity(1);
36 // size of the box in cm
37  double xsize = 20.;
38  double ysize = 20.;
39  double zsize = 10.;
40 // needs to be registered before PHG4Reco, otherwise you generate
41 // the ion after the G4 simulation is run leaving you with an empty detector
42  igun = new PHG4IonGun();
43  igun->SetA(197);
44  igun->SetZ(79);
45  igun->SetMom(0,0,1*197);
46  igun->SetCharge(79);
48 
49  PHG4Reco* g4Reco = new PHG4Reco();
50 // the default is a solenoidal field - we certainly do not want this
51  g4Reco->set_field(0);
52 // set the world size and shape, make it large enough for your volume to fit
53 // but not much larger since G4 will track particles until they leave the
54 // world volume (or they interact/decay)
55  g4Reco->SetWorldSizeX(500);
56  g4Reco->SetWorldSizeY(500);
57  g4Reco->SetWorldSizeZ(500);
58  g4Reco->SetWorldShape("G4BOX");
59 // if you want vacuum use G4_Galactic (the thinnest material in G4)
60  g4Reco->SetWorldMaterial("G4_AIR");
61 // Choose an existing physics list. They are explicitely implemented in
62 // our code, if you need another existing one, let us know.
63 // BIC is binary intranuclear cascade, suitable for ions
64  g4Reco->SetPhysicsList("QGSP_BIC");
65 
66  PHG4BlockSubsystem *box = new PHG4BlockSubsystem("box1",1);
67  box->set_double_param("size_x",xsize);
68  box->set_double_param("size_y",ysize);
69  box->set_double_param("size_z",zsize);
70 // shift by zsize/2. puts ion gun just at the front of the target box
71 // shifting by 10cm more gives some space to see the ion trail (but
72 // you will incur energy loss in 10cm of air)
73  box->set_double_param("place_z",zsize/2.+10);
74  box->set_string_param("material","G4_WATER"); // material of target box
75  // normally G4 determines the stepsize automatically according to what
76 // physics process is chosen, leading to very coarse eloss resolution
77 // this sets the step size to 1mm, caveat: if the step sizes are too small
78 // the eloss calculation can be out of whack leading to very strange dEdx
79  box->set_double_param("steplimits",0.1);
80 // do not integrate energy loss in active vlomue, store each G4 step
81 // as separate hit
82  box->set_int_param("use_g4steps",1);
83  box->SetActive();
84  // this will check for overlaps during construction, if you have multiple
85  // volumes in very close proximity you might want to run this once with
86  // this flag enabled
87  // box->OverlapCheck(1);
88  // the name used to construct the hit node, used in the ntuple code
89  // to identify the target volume (case sensitive)
90  box->SuperDetector("box");
91  g4Reco->registerSubsystem(box);
92 
94  g4Reco->registerSubsystem(truth);
95  se->registerSubsystem( g4Reco );
96 
97 
98 
99 // first argument is the name, second the filename for the ntuple
100  G4EdepNtuple *edn = new G4EdepNtuple("EdepNtuple","G4EdepNtuple.root");
101  edn->AddNode("box",1); // connects hit node name with detid in ntuple (G4HIT_box is detid=1)
102  se->registerSubsystem(edn);
103  G4HitNtuple *hit = new G4HitNtuple("HitNtuple","G4HitNtuple.root");
104  hit->AddNode("box",1); // connects hit node name with detid in ntuple (G4HIT_box is detid=1)
105  se->registerSubsystem(hit);
107  // IOManagers...
109 
110  if (WriteDst)
111  {
112  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT","G4.root");
113  se->registerOutputManager(out);
114  }
116  se->registerInputManager( in );
117 // only run if number of events is positive, otherwise quit here
118 // so one can start the display and then run events by hand
119  if (nEvents > 0)
120  {
121  se->run(nEvents);
122  se->End();
123  std::cout << "All done" << std::endl;
124  delete se;
125  gSystem->Exit(0);
126  }
127 }
128 
130 {
131  return igun;
132 }