ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_block.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_block.C
1 #pragma once
2 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
3 #include <fun4all/SubsysReco.h>
10 #include <g4eval/PHG4DSTReader.h>
11 #include <g4main/PHG4ParticleGun.h>
12 #include <g4main/PHG4Reco.h>
14 #include <phool/recoConsts.h>
15 R__LOAD_LIBRARY(libg4eval.so)
16 R__LOAD_LIBRARY(libfun4all.so)
17 R__LOAD_LIBRARY(libg4testbench.so)
18 R__LOAD_LIBRARY(libg4detectors.so)
19 #endif
20 
21 int Fun4All_G4_block(const int nEvents = 10, const char *outfile=NULL)
22 {
23 
24  gSystem->Load("libfun4all");
25  gSystem->Load("libg4detectors");
26  gSystem->Load("libg4testbench");
27  gSystem->Load("libg4eval");
28  gSystem->Load("libg4histos");
29 
31  // Make the Server
34  // se->Verbosity(1); // enable some blabbering
35 
37 // uncomment and change number (or not)if you want to use a fixed seed
38 // rc->set_IntFlag("RANDOMSEED", 12345);
39 
40  // particle gun
41  PHG4ParticleGun *gun = new PHG4ParticleGun("PGUN");
42  // gun->set_name("anti_proton");
43  gun->set_name("pi-");
44  // gun->set_name("proton");
45  gun->set_vtx(0,0,0);
46  gun->set_mom(0,0,1);
47  se->registerSubsystem(gun);
48 
49  // Fun4All G4 module
50  PHG4Reco* g4Reco = new PHG4Reco();
51  // no magnetic field
52  g4Reco->set_field(0);
53  // size of the world - every detector has to fit in here
54  g4Reco->SetWorldSizeX(500);
55  g4Reco->SetWorldSizeY(500);
56  g4Reco->SetWorldSizeZ(2000);
57  // shape of our world - it is a box
58  g4Reco->SetWorldShape("G4BOX");
59  // this is what our world is filled with
60  g4Reco->SetWorldMaterial("G4_AIR");
61  // Geant4 Physics list to use
62  g4Reco->SetPhysicsList("QGSP_BERT");
63 
64  // our block "detector", size is in cm
65  double xsize = 200.;
66  double ysize = 200.;
67  double zsize = 400.;
69  box->set_double_param("size_x",xsize);
70  box->set_double_param("size_y",ysize);
71  box->set_double_param("size_z",zsize);
72  box->set_double_param("place_z",zsize/2.+100);// shift box so we do not create particles in its center and shift by 10 so we can see the track of the incoming particle
73  box->set_string_param("material","G4_POLYSTYRENE"); // material of box
74  box->SetActive(); // it is an active volume - save G4Hits
75  g4Reco->registerSubsystem(box);
76 
78  g4Reco->registerSubsystem(truth);
79 
80  se->registerSubsystem( g4Reco );
81 
83  // Output
85 
86  if (outfile)
87  {
88  Fun4AllOutputManager *out = new Fun4AllDstOutputManager("DSTOUT",outfile);
89  se->registerOutputManager(out);
90 
91  }
92  if (outfile)
93  {
94  // save a comprehensive evaluation file
95  PHG4DSTReader* ana = new PHG4DSTReader(
96  string(outfile) + string("_DSTReader.root"));
97  ana->set_save_particle(true);
98  ana->set_load_all_particle(false);
99  ana->set_load_active_particle(true);
100  ana->set_save_vertex(true);
101  if (nEvents > 0 && nEvents < 2)
102  {
103  ana->Verbosity(2);
104  }
105  ana->AddNode("box_0");
106  se->registerSubsystem(ana);
107  }
108 
109  // input - we need a dummy to drive the event loop
111  se->registerInputManager( in );
112 
113  // a quick evaluator to inspect on hit/particle/tower level
114 
115 
116  if (nEvents > 0)
117  {
118  se->run(nEvents);
119  // finish job - close and save output files
120  se->End();
121  std::cout << "All done" << std::endl;
122 
123  // cleanup - delete the server and exit
124  delete se;
125  gSystem->Exit(0);
126  }
127  return 0;
128 
129 }
130 
131 PHG4ParticleGun *get_gun(const char *name="PGUN")
132 {
135  return pgun;
136 }
137