Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_Example02.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_Example02.C
1 #ifndef MACRO_FUN4ALLG4EXAMPLE02_C
2 #define MACRO_FUN4ALLG4EXAMPLE02_C
3 
4 #include <g4exampledetector02/G4Example02Subsystem.h>
5 
7 
8 #include <g4histos/G4HitNtuple.h>
9 
12 #include <g4main/PHG4ParticleGun.h>
13 #include <g4main/PHG4Reco.h>
15 
20 #include <fun4all/Fun4AllServer.h>
21 #include <fun4all/SubsysReco.h>
22 
23 #include <phool/recoConsts.h>
24 
25 R__LOAD_LIBRARY(libfun4all.so)
26 R__LOAD_LIBRARY(libg4detectors.so)
27 R__LOAD_LIBRARY(libg4example02detector.so)
28 R__LOAD_LIBRARY(libg4histos.so)
29 
31 {
33  // Make the Server
37  // if you want to fix the random seed to reproduce results
38  // set this flag
39  // nail this down so I know what the first event looks like...
40  rc->set_IntFlag("RANDOMSEED", 12345);
41 
42  //
43  // Particle Generator
44  //
45 
46  // the PHG4ParticleGenerator makes cones using phi and eta
47  // PHG4ParticleGenerator *gen = new PHG4ParticleGenerator();
48  // gen->set_name("e-");
49  // gen->set_vtx(0, 0, 0);
50  // gen->set_eta_range(-0.9, 0.9);
51  // gen->set_mom_range(1.0, 10.0);
52  // gen->set_z_range(0.,0.);
53  // gen->set_phi_range(-5/180.*TMath::Pi(), 5/180.*TMath::Pi());
54  // se->registerSubsystem(gen);
55 
56  PHG4ParticleGun *gun = new PHG4ParticleGun();
57  gun->set_name("pi-");
58  //gun->set_name("geantino");
59  //gun->set_name("proton");
60  gun->set_vtx(0, -5, -20); // shoots right into the original Example02 volume
61  gun->set_mom(0, 0, 1);
62  se->registerSubsystem(gun);
63 
64  //
65  // Geant4 setup
66  //
67  PHG4Reco *g4Reco = new PHG4Reco();
68  g4Reco->set_field(0); // no field
69  g4Reco->save_DST_geometry(false);
70  // try non default physics lists
71  //g4Reco->SetPhysicsList("FTFP_BERT_HP");
72 
73  G4Example02Subsystem *example02 = new G4Example02Subsystem("HoleInBox");
74  example02->SetActive();
75  g4Reco->registerSubsystem(example02);
76 
77  example02 = new G4Example02Subsystem("AnotherHoleInBox");
78  example02->set_double_param("place_x", 40.);
79  example02->set_double_param("place_y", 40.);
80  example02->set_double_param("rot_x", 45.);
81  example02->set_string_param("material", "G4_Fe");
82  example02->SetActive();
83  g4Reco->registerSubsystem(example02);
84 
85  example02 = new G4Example02Subsystem("YetAnotherHoleInBox");
86  example02->set_double_param("place_x", -40.);
87  example02->set_double_param("place_z", 40.);
88  example02->set_double_param("rot_y", 45.);
89  example02->set_double_param("rot_z", 45.);
90  example02->set_string_param("material", "G4_Cu");
91  example02->SetActive();
92  g4Reco->registerSubsystem(example02);
93 
94  // This is our Black Hole - absorbs every particle
95  example02 = new G4Example02Subsystem("BewareOfTheBlackHole");
96  example02->set_double_param("place_z", 40.);
97  example02->set_double_param("rot_y", 45.);
98  example02->set_double_param("rot_z", 45.);
99  example02->BlackHole();
100  example02->SetActive();
101  g4Reco->registerSubsystem(example02);
102 
103  // this is an inactive volume (no hits will be created)
104  example02 = new G4Example02Subsystem("InActiveHoleInBox");
105  example02->set_double_param("place_z", -40.);
106  example02->set_double_param("rot_y", 45.);
107  example02->set_double_param("rot_z", 45.);
108  example02->set_string_param("material", "G4_W");
109  g4Reco->registerSubsystem(example02);
110 
111  se->registerSubsystem(g4Reco);
112 
114  // Fun4All modules
116 
117  G4HitNtuple *hits = new G4HitNtuple("Hits");
118  hits->AddNode("HoleInBox", 0);
119  se->registerSubsystem(hits);
120 
122  // IOManagers...
124 
125  // Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT","G4Example02.root");
126  // out->Verbosity(10);
127  // se->registerOutputManager(out);
128 
129  // this (dummy) input manager just drives the event loop
131  se->registerInputManager(in);
132  // events = 0 => run forever
133  if (nEvents <= 0)
134  {
135  return 0;
136  }
137  se->run(nEvents);
138  example02->Print();
139  se->End();
140  std::cout << "All done" << std::endl;
141  delete se;
142  gSystem->Exit(0);
143 }
144 
145 #endif