Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_LeadBrick.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_LeadBrick.C
1 
2 #include <iostream>
3 
4 using namespace std;
5 
6 int Fun4All_G4_LeadBrick(const int nEvents = 10, const char *outfile = NULL)
7 {
8  gSystem->Load("libfun4all");
9  gSystem->Load("libg4detectors");
10  gSystem->Load("libg4testbench");
11  gSystem->Load("libg4eval");
12 
14  // Make the Server
17  se->Verbosity(1);
18 
19  // particle gun
20  PHG4ParticleGun *gun = new PHG4ParticleGun("PGUN");
21  // gun->set_name("anti_proton");
22  gun->set_name("proton");
23  // gun->set_name("mu-");
24  // gun->set_name("proton");
25  gun->set_vtx(0, 0, -100);
26  gun->set_mom(0, 0, 120);
27  se->registerSubsystem(gun);
28 
29  // Fun4All G4 module
30  PHG4Reco *g4Reco = new PHG4Reco();
31  // no magnetic field
32  g4Reco->set_field(0);
33  // size of the world - every detector has to fit in here
34  g4Reco->SetWorldSizeX(200);
35  g4Reco->SetWorldSizeY(200);
36  g4Reco->SetWorldSizeZ(200);
37  // shape of our world - it is a box
38  g4Reco->SetWorldShape("G4BOX");
39  // this is what our world is filled with
40  g4Reco->SetWorldMaterial("G4_AIR");
41  // Geant4 Physics list to use
42  g4Reco->SetPhysicsList("FTFP_BERT");
43 
44  // our block "detector", size is in cm
45  double xsize = 200.;
46  double ysize = 200.;
47  double zsize = 400.;
48  PHG4BlockSubsystem *box = new PHG4BlockSubsystem("LeadBrick");
49  box->set_double_param("size_x", 20);
50  box->set_double_param("size_y", 20);
51  box->set_double_param("size_z", 10);
52  box->set_double_param("place_z", 0); // 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
53  box->set_string_param("material", "G4_Pb"); // material of box
54  box->SetActive(0); // if it is an active volume - save G4Hits
55  g4Reco->registerSubsystem(box);
56 
57  for (int stave = 0; stave < 4; ++stave)
58  {
59  box = new PHG4BlockSubsystem("MVTX", stave);
60  box->SuperDetector("MVTX");
61  box->set_double_param("size_x", 2);
62  box->set_double_param("size_y", 1);
63  box->set_double_param("size_z", 50e-4); // 50us
64  box->set_double_param("place_z", 10 * (stave + 1)); // 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
65  box->set_string_param("material", "G4_Si"); // material of box
66  box->SetActive(1); // it is an active volume - save G4Hits
67  g4Reco->registerSubsystem(box);
68  }
69 
71  g4Reco->registerSubsystem(truth);
72 
73  se->registerSubsystem(g4Reco);
74 
76  // Output
78 
79  // save a comprehensive evaluation file
80  PHG4DSTReader *ana = new PHG4DSTReader(
81  string("LeadBrick_DSTReader.root"));
82  ana->set_save_particle(true);
83  ana->set_load_all_particle(false);
84  ana->set_load_active_particle(true);
85  ana->set_save_vertex(true);
86  ana->AddNode("LeadBrick");
87  ana->AddNode("MVTX");
88  se->registerSubsystem(ana);
89 
90  // input - we need a dummy to drive the event loop
92  se->registerInputManager(in);
93 
94  // a quick evaluator to inspect on hit/particle/tower level
95 
96  if (nEvents > 0)
97  {
98  se->run(nEvents);
99  // finish job - close and save output files
100  se->End();
101  std::cout << "All done" << std::endl;
102 
103  // cleanup - delete the server and exit
104  delete se;
105  gSystem->Exit(0);
106  }
107  return;
108 }
109 
110 PHG4ParticleGun *get_gun(const char *name = "PGUN")
111 {
114  return pgun;
115 }