Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4All_G4_BNL.C
Go to the documentation of this file.
1 
2 #include <iostream>
3 
4 using namespace std;
5 
6 int Fun4All_G4_BNL(const int nEvents = 1000)
7 {
8  double gap = 6.0;
9  double beam_energy = 24;
10  double beam_angle = TMath::Pi()/6.;
11 
12  const int use_g4steps = 1;
13 
14  gSystem->Load("libfun4all");
15  gSystem->Load("libg4detectors");
16  gSystem->Load("libg4testbench");
17  gSystem->Load("libg4eval");
18  gSystem->Load("libtruth_eval.so");
19 
21  // Make the Server
24  se->Verbosity(100);
25 
26  // particle gun
27  PHG4ParticleGun *gun = new PHG4ParticleGun("PGUN");
28  // gun->set_name("anti_proton");
29  gun->set_name("proton");
30  // gun->set_name("mu-");
31  // gun->set_name("proton");
32  gun->set_vtx(30*TMath::Tan(beam_angle), 0, -30);
33  gun->set_mom(-beam_energy*TMath::Sin(beam_angle), 0, beam_energy*TMath::Cos(beam_angle));
34  se->registerSubsystem(gun);
35 
36  // Fun4All G4 module
37  PHG4Reco *g4Reco = new PHG4Reco();
38  //g4Reco->G4Seed(123);
39  // no magnetic field
40  g4Reco->set_field(5.);
41  // size of the world - every detector has to fit in here
42  g4Reco->SetWorldSizeX(200);
43  g4Reco->SetWorldSizeY(200);
44  g4Reco->SetWorldSizeZ(200);
45  // shape of our world - it is a box
46  g4Reco->SetWorldShape("G4BOX");
47  // this is what our world is filled with
48  g4Reco->SetWorldMaterial("G4_Galactic");
49  // Geant4 Physics list to use
50  g4Reco->SetPhysicsList("FTFP_BERT");
51 
52  // our block "detector", size is in cm
53  double xsize = 200.;
54  double ysize = 200.;
55  double zsize = 400.;
56 
57  PHG4CylinderSubsystem * tube = 0;
58 
59  tube = new PHG4CylinderSubsystem("Coil", 0);
60  tube->SuperDetector("Coil");
61  tube->set_double_param("length", 12.0);
62  tube->set_double_param("rot_x", 90.);
63  tube->set_double_param("rot_y", 0.);
64  tube->set_double_param("rot_z", 0.);
65  tube->set_double_param("place_x", 0.);
66  tube->set_double_param("place_y", (12.0+gap)/2);
67  tube->set_double_param("place_z", 0.);
68  tube->set_double_param("radius", 7.9/2);
69  tube->set_double_param("thickness", (32.5-7.8)/2);
70  tube->set_string_param("material", "Coil"); // material of box
71  tube->set_int_param("lengthviarapidity", 0);
72  tube->set_int_param("use_g4steps", use_g4steps);
73  tube->SetActive(1); // it is an active volume - save G4Hits
74  g4Reco->registerSubsystem(tube);
75 
76 
77  tube = new PHG4CylinderSubsystem("Coil", 1);
78  tube->SuperDetector("Coil");
79  tube->set_double_param("length", 14.8);
80  tube->set_double_param("rot_x", 90.);
81  tube->set_double_param("rot_y", 0.);
82  tube->set_double_param("rot_z", 0.);
83  tube->set_double_param("place_x", 0.);
84  tube->set_double_param("place_y", -(14.8+gap)/2);
85  tube->set_double_param("place_z", 0.);
86  tube->set_double_param("radius", 7.9/2);
87  tube->set_double_param("thickness", (32.5-7.8)/2);
88  tube->set_string_param("material", "Coil"); // material of box
89  tube->set_int_param("lengthviarapidity", 0);
90  tube->set_int_param("use_g4steps", use_g4steps);
91  tube->SetActive(1); // it is an active volume - save G4Hits
92  g4Reco->registerSubsystem(tube);
93 
94  tube = new PHG4CylinderSubsystem("Target", 0);
95  tube->SuperDetector("Target");
96  tube->set_double_param("length", 4);
97  tube->set_double_param("rot_x", 0.);
98  tube->set_double_param("rot_y", 0.);
99  tube->set_double_param("rot_z", 0.);
100  tube->set_double_param("place_x", 0.);
101  tube->set_double_param("place_y", 0.);
102  tube->set_double_param("place_z", 0.);
103  tube->set_double_param("radius", 0.);
104  tube->set_double_param("thickness", (2.5)/2);
105  tube->set_string_param("material", "Target"); // material of box
106  tube->set_int_param("lengthviarapidity", 0);
107  tube->set_int_param("use_g4steps", use_g4steps);
108  tube->SetActive(1); // it is an active volume - save G4Hits
109  g4Reco->registerSubsystem(tube);
110 
111  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
112  g4Reco->registerSubsystem(truth);
113 
114  se->registerSubsystem(g4Reco);
115 
116  TruthEval* eval = new TruthEval("TruthEval","eval.root");
117  eval->beam_angle = beam_angle;
118  eval->target_r = 1.25;
119  eval->target_z = 4;
120  eval->coil_in_r = 7.9/2;
121  eval->coil_ot_r = 32.5/2;
122  eval->coil_min_y_0 = gap/2.;
123  eval->coil_max_y_0 = gap/2. + 12.;
124  eval->coil_min_y_1 = -gap/2.-14.8;
125  eval->coil_max_y_1 = -gap/2.;
126  se->registerSubsystem(eval);
127 
129  // Output
131 
132  // save a comprehensive evaluation file
134  string("DSTReader.root"));
135  ana->set_save_particle(true);
136  ana->set_load_all_particle(false);
137  ana->set_load_active_particle(true);
138  ana->set_save_vertex(true);
139  ana->AddNode("Coil");
140  se->registerSubsystem(ana);
141 
142  // input - we need a dummy to drive the event loop
144  se->registerInputManager(in);
145 
146  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "DST.root");
147  se->registerOutputManager(out);
148 
149  // a quick evaluator to inspect on hit/particle/tower level
150 
151  if (nEvents > 0)
152  {
153  se->run(nEvents);
154 
155  PHGeomUtility::ExportGeomtry(se->topNode(),"geom.root");
156 
157  // finish job - close and save output files
158  se->End();
159  std::cout << "All done" << std::endl;
160 
161  // cleanup - delete the server and exit
162  delete se;
163  gSystem->Exit(0);
164  }
165  return;
166 }
167 
168 PHG4ParticleGun *get_gun(const char *name = "PGUN")
169 {
171  PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name);
172  return pgun;
173 }
int registerInputManager(Fun4AllInputManager *InManager)
virtual int End()
Runs G4 as a subsystem.
Definition: PHG4Reco.h:38
void set_int_param(const std::string &name, const int ival)
void set_load_all_particle(bool b)
Definition: PHG4DSTReader.h:73
PHG4DSTReader save information from DST to an evaluator, which could include hit. particle...
Definition: PHG4DSTReader.h:39
void SetWorldMaterial(const std::string &s)
Definition: PHG4Reco.h:118
float coil_min_y_1
Definition: TruthEval.h:56
float coil_max_y_0
Definition: TruthEval.h:55
void SetWorldShape(const std::string &s)
Definition: PHG4Reco.h:117
static Fun4AllServer * instance()
Fun4AllServer * se
static void ExportGeomtry(PHCompositeNode *topNode, const std::string &geometry_file)
DST node -&gt; TGeoManager -&gt; export files, like gdml, .root or .C formats.
void SuperDetector(const std::string &name)
float coil_in_r
Definition: TruthEval.h:52
void set_double_param(const std::string &name, const double dval)
int registerSubsystem(SubsysReco *subsystem, const std::string &topnodename="TOP")
void set_field(const float tesla)
set default magnetic field strength with a constant magnetic field. Only valid if set_field_map() is ...
Definition: PHG4Reco.h:79
float coil_min_y_0
Definition: TruthEval.h:54
int run(const int nevnts=0, const bool require_nevents=false)
run n events (0 means up to end of file)
int Fun4All_G4_BNL(const int nEvents=1000)
Definition: Fun4All_G4_BNL.C:6
int registerOutputManager(Fun4AllOutputManager *manager)
void set_save_vertex(bool b)
Switch for vertex.
Definition: PHG4DSTReader.h:94
void AddNode(const std::string &name)
Definition: PHG4DSTReader.h:59
PHCompositeNode * topNode() const
Definition: Fun4AllServer.h:59
void set_save_particle(bool b)
Switch for saving any particles at all.
Definition: PHG4DSTReader.h:87
void ana()
Definition: ana.C:291
void set_string_param(const std::string &name, const std::string &sval)
void SetWorldSizeX(const double sx)
Definition: PHG4Reco.h:111
void SetPhysicsList(const std::string &s)
Definition: PHG4Reco.h:119
virtual void set_vtx(const double x, const double y, const double z)
SubsysReco * getSubsysReco(const std::string &name)
virtual void Verbosity(const int ival)
Sets the verbosity of this module (0 by default=quiet).
Definition: Fun4AllBase.h:58
void set_load_active_particle(bool b)
load all particle that produced a saved hit
Definition: PHG4DSTReader.h:80
void SetActive(const int i=1)
float coil_max_y_1
Definition: TruthEval.h:57
float coil_ot_r
Definition: TruthEval.h:53
virtual void set_name(const std::string &particle="proton")
virtual void set_mom(const double x, const double y, const double z)
float target_z
Definition: TruthEval.h:50
float target_r
Definition: TruthEval.h:48
PHG4ParticleGun * get_gun(const char *name="PGUN")
void registerSubsystem(PHG4Subsystem *subsystem)
register subsystem
Definition: PHG4Reco.h:65
void SetWorldSizeZ(const double sz)
Definition: PHG4Reco.h:113
void SetWorldSizeY(const double sy)
Definition: PHG4Reco.h:112