EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_Example03.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_Example03.C
1 #ifndef MACRO_FUN4ALLG4EXAMPLE03_C
2 #define MACRO_FUN4ALLG4EXAMPLE03_C
3 
4 #include <g4exampledetector03/G4Example03Subsystem.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(libg4example03detector.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 Example03 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  G4Example03Subsystem *example03 = new G4Example03Subsystem("HoleInBox");
74  example03->set_color(1, 1, 0, 1);
75  example03->SetActive();
76  g4Reco->registerSubsystem(example03);
77 
78  example03 = new G4Example03Subsystem("AnotherHoleInBox");
79  example03->set_double_param("place_x", 40.);
80  example03->set_double_param("place_y", 40.);
81  example03->set_double_param("rot_x", 45.);
82  example03->set_string_param("material", "G4_Fe");
83  example03->set_color(1, 0, 0, 1);
84  example03->SetActive();
85  g4Reco->registerSubsystem(example03);
86 
87  example03 = new G4Example03Subsystem("YetAnotherHoleInBox");
88  example03->set_double_param("place_x", -40.);
89  example03->set_double_param("place_z", 40.);
90  example03->set_double_param("rot_y", 45.);
91  example03->set_double_param("rot_z", 45.);
92  example03->set_string_param("material", "G4_Cu");
93  example03->set_color(0, 1, 0, 1);
94  example03->SetActive();
95  g4Reco->registerSubsystem(example03);
96 
97  // This is our Black Hole - absorbs every particle
98  example03 = new G4Example03Subsystem("BewareOfTheBlackHole");
99  example03->set_double_param("place_z", 40.);
100  example03->set_double_param("rot_y", 45.);
101  example03->set_double_param("rot_z", 45.);
102  example03->set_color(1, 0, 1, 1);
103  example03->BlackHole();
104  example03->SetActive();
105  g4Reco->registerSubsystem(example03);
106 
107  // this is an inactive volume (no hits will be created)
108  example03 = new G4Example03Subsystem("InActiveHoleInBox");
109  example03->set_double_param("place_z", -40.);
110  example03->set_double_param("rot_y", 45.);
111  example03->set_double_param("rot_z", 45.);
112  example03->set_string_param("material", "G4_W");
113  example03->set_color(0, 1, 1, 1);
114  g4Reco->registerSubsystem(example03);
115 
116  se->registerSubsystem(g4Reco);
117 
119  // Fun4All modules
121 
122  G4HitNtuple *hits = new G4HitNtuple("Hits");
123  hits->AddNode("HoleInBox", 0);
124  se->registerSubsystem(hits);
125 
127  // IOManagers...
129 
130  // Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT","G4Example03.root");
131  // out->Verbosity(10);
132  // se->registerOutputManager(out);
133 
134  // this (dummy) input manager just drives the event loop
136  se->registerInputManager(in);
137  // events = 0 => run forever
138  if (nEvents <= 0)
139  {
140  return 0;
141  }
142  se->run(nEvents);
143  example03->Print();
144  se->End();
145  std::cout << "All done" << std::endl;
146  delete se;
147  gSystem->Exit(0);
148 }
149 
150 #endif