Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4All_G4_E1039_R1.C
Go to the documentation of this file.
1 
2 #include <iostream>
3 
4 using namespace std;
5 
6 int Fun4All_G4_E1039_R1(const int nEvents = 1)
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("proton");
25  gun->set_vtx(0, 0, -30);
26  gun->set_mom(0, 0, 120);
27  TF2 *beam_profile = new TF2("beam_profile",
28  "(((x**2+y**2)<=0.81)*exp(-(x**2+y**2)/0.18))+(((x**2+y**2)>0.81&&(x**2+y**2)<=25&&abs(y)<1.)*0.9*exp(-4.5)/(sqrt(x**2+y**2)))",-5,5,-5,5);
29  gun->set_beam_profile(beam_profile);
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  PHG4TargetCoilSubsystem* coil_0 = new PHG4TargetCoilSubsystem("Coil", 0);
54  coil_0->SuperDetector("Coil");
55  coil_0->set_double_param("rot_x", 90.);
56  coil_0->set_double_param("rot_y", 0.);
57  coil_0->set_double_param("rot_z", 0.);
58  coil_0->set_double_param("place_x", 0.);
59  coil_0->set_double_param("place_y", (22.7+4.)/2);
60  coil_0->set_double_param("place_z", 0.);
61  coil_0->set_int_param("use_g4steps", use_g4steps);
62  coil_0->SetActive(1); // it is an active volume - save G4Hits
63  g4Reco->registerSubsystem(coil_0);
64 
65  PHG4TargetCoilSubsystem* coil_1 = new PHG4TargetCoilSubsystem("Coil", 1);
66  coil_1->SuperDetector("Coil");
67  coil_1->set_double_param("rot_x", -90.);
68  coil_1->set_double_param("rot_y", 0.);
69  coil_1->set_double_param("rot_z", 0.);
70  coil_1->set_double_param("place_x", 0.);
71  coil_1->set_double_param("place_y", -(22.7+4.)/2);
72  coil_1->set_double_param("place_z", 0.);
73  coil_1->set_int_param("use_g4steps", use_g4steps);
74  coil_1->SetActive(1); // it is an active volume - save G4Hits
75  g4Reco->registerSubsystem(coil_1);
76 
77  PHG4CylinderSubsystem* target = new PHG4CylinderSubsystem("Target", 0);
78  target->SuperDetector("Target");
79  target->set_double_param("length", 7.9);
80  target->set_double_param("rot_x", 0.);
81  target->set_double_param("rot_y", 0.);
82  target->set_double_param("rot_z", 0.);
83  target->set_double_param("place_x", 0.);
84  target->set_double_param("place_y", 0.);
85  target->set_double_param("place_z", 0.);
86  target->set_double_param("radius", 0.);
87  target->set_double_param("thickness", (2.)/2);
88  target->set_string_param("material", "Target"); // material of target
89  target->set_int_param("lengthviarapidity", 0);
90  target->set_int_param("use_g4steps", use_g4steps);
91  target->SetActive(1); // it is an active volume - save G4Hits
92  g4Reco->registerSubsystem(target);
93 
94 
96  g4Reco->registerSubsystem(truth);
97 
98  se->registerSubsystem(g4Reco);
99 
100  TruthEval* eval = new TruthEval("TruthEval","eval.root");
101  se->registerSubsystem(eval);
102 
104  // Output
106 
107  // save a comprehensive evaluation file
109  string("DSTReader.root"));
110  ana->set_save_particle(true);
111  ana->set_load_all_particle(false);
112  ana->set_load_active_particle(true);
113  ana->set_save_vertex(true);
114  ana->AddNode("Coil");
115  se->registerSubsystem(ana);
116 
117  // input - we need a dummy to drive the event loop
119  se->registerInputManager(in);
120 
121  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "DST.root");
122  se->registerOutputManager(out);
123 
124  // a quick evaluator to inspect on hit/particle/tower level
125 
126  if (nEvents > 0)
127  {
128  se->run(nEvents);
129 
130  PHGeomUtility::ExportGeomtry(se->topNode(),"geom.root");
131 
132  // finish job - close and save output files
133  se->End();
134  std::cout << "All done" << std::endl;
135 
136  // cleanup - delete the server and exit
137  delete se;
138  gSystem->Exit(0);
139  }
140  return;
141 }
142 
143 PHG4ParticleGun *get_gun(const char *name = "PGUN")
144 {
146  PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name);
147  return pgun;
148 }
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)
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 Fun4All_G4_E1039_R1(const int nEvents=1)
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 set_beam_profile(TF2 *beamProfile)
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