Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4All_G4_E1039.C
Go to the documentation of this file.
1 
2 #include <iostream>
3 
4 using namespace std;
5 
6 int Fun4All_G4_E1039(const int nEvents = 100)
7 {
8  const int use_g4steps = 1;
9 
10  gSystem->Load("libfun4all");
11  gSystem->Load("libg4detectors");
12  gSystem->Load("libg4testbench");
13  gSystem->Load("libg4eval");
14  gSystem->Load("libtruth_eval.so");
15 
17  // Make the Server
20  se->Verbosity(1);
21 
22  // particle gun
23  PHG4ParticleGun *gun = new PHG4ParticleGun("PGUN");
24  // gun->set_name("anti_proton");
25  gun->set_name("proton");
26  // gun->set_name("mu-");
27  // gun->set_name("proton");
28  gun->set_vtx(0, 0, -30);
29  gun->set_mom(0, 0, 120);
30  se->registerSubsystem(gun);
31 
32  // Fun4All G4 module
33  PHG4Reco *g4Reco = new PHG4Reco();
34  //g4Reco->G4Seed(123);
35  // no magnetic field
36  g4Reco->set_field(5.);
37  // size of the world - every detector has to fit in here
38  g4Reco->SetWorldSizeX(200);
39  g4Reco->SetWorldSizeY(200);
40  g4Reco->SetWorldSizeZ(200);
41  // shape of our world - it is a tube
42  g4Reco->SetWorldShape("G4BOX");
43  // this is what our world is filled with
44  g4Reco->SetWorldMaterial("G4_Galactic");
45  // Geant4 Physics list to use
46  g4Reco->SetPhysicsList("FTFP_BERT");
47 
48  // our block "detector", size is in cm
49  double xsize = 200.;
50  double ysize = 200.;
51  double zsize = 400.;
52 
53  PHG4CylinderSubsystem * tube = 0;
54 
55  tube = new PHG4CylinderSubsystem("Coil", 0);
56  tube->SuperDetector("Coil");
57  tube->set_double_param("length", 22.7);
58  tube->set_double_param("rot_x", 90.);
59  tube->set_double_param("rot_y", 0.);
60  tube->set_double_param("rot_z", 0.);
61  tube->set_double_param("place_x", 0.);
62  tube->set_double_param("place_y", (22.7+4.)/2);
63  tube->set_double_param("place_z", 0.);
64  tube->set_double_param("radius", 12./2);
65  tube->set_double_param("thickness", (44.45-12.)/2);
66  tube->set_string_param("material", "Coil"); // material of tube
67  tube->set_int_param("lengthviarapidity", 0);
68  tube->set_int_param("use_g4steps", use_g4steps);
69  tube->SetActive(1); // it is an active volume - save G4Hits
70  g4Reco->registerSubsystem(tube);
71 
72 
73  tube = new PHG4CylinderSubsystem("Coil", 1);
74  tube->SuperDetector("Coil");
75  tube->set_double_param("length", 22.7);
76  tube->set_double_param("rot_x", 90.);
77  tube->set_double_param("rot_y", 0.);
78  tube->set_double_param("rot_z", 0.);
79  tube->set_double_param("place_x", 0.);
80  tube->set_double_param("place_y", -(22.7+4.)/2);
81  tube->set_double_param("place_z", 0.);
82  tube->set_double_param("radius", 12./2);
83  tube->set_double_param("thickness", (44.45-12.)/2);
84  tube->set_string_param("material", "Coil"); // material of tube
85  tube->set_int_param("lengthviarapidity", 0);
86  tube->set_int_param("use_g4steps", use_g4steps);
87  tube->SetActive(1); // it is an active volume - save G4Hits
88  g4Reco->registerSubsystem(tube);
89 
90  tube = new PHG4CylinderSubsystem("Target", 0);
91  tube->SuperDetector("Target");
92  tube->set_double_param("length", 7.9);
93  tube->set_double_param("rot_x", 0.);
94  tube->set_double_param("rot_y", 0.);
95  tube->set_double_param("rot_z", 0.);
96  tube->set_double_param("place_x", 0.);
97  tube->set_double_param("place_y", 0.);
98  tube->set_double_param("place_z", 0.);
99  tube->set_double_param("radius", 0.);
100  tube->set_double_param("thickness", (2.)/2);
101  tube->set_string_param("material", "Target"); // material of tube
102  tube->set_int_param("lengthviarapidity", 0);
103  tube->set_int_param("use_g4steps", use_g4steps);
104  tube->SetActive(1); // it is an active volume - save G4Hits
105  g4Reco->registerSubsystem(tube);
106 
107  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
108  g4Reco->registerSubsystem(truth);
109 
110  se->registerSubsystem(g4Reco);
111 
112  TruthEval* eval = new TruthEval("TruthEval","eval.root");
113  se->registerSubsystem(eval);
114 
116  // Output
118 
119  // save a comprehensive evaluation file
121  string("DSTReader.root"));
122  ana->set_save_particle(true);
123  ana->set_load_all_particle(false);
124  ana->set_load_active_particle(true);
125  ana->set_save_vertex(true);
126  ana->AddNode("Coil");
127  se->registerSubsystem(ana);
128 
129  // input - we need a dummy to drive the event loop
131  se->registerInputManager(in);
132 
133  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "DST.root");
134  se->registerOutputManager(out);
135 
136  // a quick evaluator to inspect on hit/particle/tower level
137 
138  if (nEvents > 0)
139  {
140  se->run(nEvents);
141 
142  PHGeomUtility::ExportGeomtry(se->topNode(),"geom.root");
143 
144  // finish job - close and save output files
145  se->End();
146  std::cout << "All done" << std::endl;
147 
148  // cleanup - delete the server and exit
149  delete se;
150  gSystem->Exit(0);
151  }
152  return;
153 }
154 
155 PHG4ParticleGun *get_gun(const char *name = "PGUN")
156 {
158  PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name);
159  return pgun;
160 }
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
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)
int Fun4All_G4_E1039(const int nEvents=100)
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
int run(const int nevnts=0, const bool require_nevents=false)
run n events (0 means up to end of file)
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)
virtual void set_name(const std::string &particle="proton")
virtual void set_mom(const double x, const double y, const double z)
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