Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_G4_MyDetector.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_G4_MyDetector.C
1 #ifndef MACRO_FUN4ALLG4MYDETECTOR_C
2 #define MACRO_FUN4ALLG4MYDETECTOR_C
3 
4 #include <mydetector/MyDetectorSubsystem.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(libMyDetector.so)
28 R__LOAD_LIBRARY(libg4histos.so)
29 
30 // needs 10000 geantinos to make a decent scan plot
31 void Fun4All_G4_MyDetector(int nEvents = 10000)
32 {
34  // Make the Server
38  // if you want to fix the random seed to reproduce results
39  // set this flag
40  // nail this down so I know what the first event looks like...
41  // rc->set_IntFlag("RANDOMSEED",12345);
42 
43  //
44  // Particle Generator
45  //
46 
47  // the PHG4ParticleGenerator makes cones using phi and eta
49  gen->set_name("geantino");
50  gen->set_mom_range(1.0, 1.0);
51  gen->set_z_range(0., 0.);
52  // experimentally found ranges, they cover the original block
53  gen->set_vtx(-50, 0, 0);
54  gen->set_phi_range(-14.5 / 180 * TMath::Pi(), 14.5 / 180 * TMath::Pi());
55  gen->set_eta_range(-0.26, 0.26);
56  se->registerSubsystem(gen);
57 
58  // ParticleGun shoots right into the original MyDetector volume
59  PHG4ParticleGun *gun = new PHG4ParticleGun();
60  // gun->set_name("pi-");
61  gun->set_name("geantino");
62  gun->set_vtx(0, 0, -20);
63  gun->set_mom(0, 0, 1);
64  // se->registerSubsystem(gun);
65 
66  //
67  // Geant4 setup
68  //
69  PHG4Reco *g4Reco = new PHG4Reco();
70  // setup of G4:
71  // no field
72  // no saving of geometry: it takes time and we do not do tracking
73  // so we do not need the geometry
74  g4Reco->set_field(0);
75  g4Reco->save_DST_geometry(false);
76 
77  MyDetectorSubsystem *mydet = new MyDetectorSubsystem("MyDetector1");
78  mydet->SetActive();
79  g4Reco->registerSubsystem(mydet);
80 
81  // mydet = new MyDetectorSubsystem("MyDetector2");
82  // mydet->set_double_param("place_x",40.);
83  // mydet->set_double_param("place_y",40.);
84  // mydet->set_double_param("rot_x",45.);
85  // mydet->set_string_param("material","G4_Fe");
86  // mydet->SetActive();
87  // g4Reco->registerSubsystem(mydet);
88 
89  se->registerSubsystem(g4Reco);
90 
92  // Fun4All modules
94 
95  G4HitNtuple *hits = new G4HitNtuple("Hits");
96  hits->AddNode("MyDetector1_0", 0);
97  se->registerSubsystem(hits);
98 
100  // IOManagers...
102 
103  // Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT","G4Example02.root");
104  // out->Verbosity(10);
105  // se->registerOutputManager(out);
106 
107  // this (dummy) input manager just drives the event loop
109  se->registerInputManager(in);
110  // events = 0 => run forever
111  if (nEvents <= 0)
112  {
113  return 0;
114  }
115  se->run(nEvents);
116  cout << "Print out Detector parameters" << endl;
117  mydet->Print();
118  se->End();
119  delete se;
120  cout << endl
121  << endl;
122  cout << "Now open the ntuple file with " << endl;
123  cout << " root.exe G4HitNtuple.root" << endl;
124  cout << "and draw the 3d hit distribution," << endl;
125  cout << "exit hits in black, entry hits in red:" << endl;
126  cout << " hitntup->Draw(\"x1:y1:z1\")" << endl;
127  cout << " hitntup->SetMarkerColor(2)" << endl;
128  cout << " hitntup->Draw(\"x0:y0:z0\",\"\",\"same\")" << endl;
129  cout << endl;
130  gSystem->Exit(0);
131 }
132 
133 #endif