Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4All_G4_E1039_R2.C
Go to the documentation of this file.
1 
2 #include <iostream>
3 
4 using namespace std;
5 
6 int Fun4All_G4_E1039_R2(const int nEvents = 1)
7 {
8  const int use_g4steps = 1;
9  const double target_l = 7.9; //cm
10  const double target_z = (7.9-target_l)/2.; //cm
11 
12  gSystem->Load("libfun4all");
13  gSystem->Load("libg4detectors");
14  gSystem->Load("libg4testbench");
15  gSystem->Load("libg4eval");
16  gSystem->Load("libtruth_eval.so");
17 
19  // Make the Server
22  se->Verbosity(1);
23 
24  // particle gun
25  PHG4ParticleGun *gun = new PHG4ParticleGun("PGUN");
26  gun->set_name("proton");//proton
27  gun->set_vtx(0, 0, -400); //-363.32 cm
28  gun->set_mom(0, 0, 120);
29  TF2 *beam_profile = new TF2("beam_profile",
30  //"(((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)))",
31  "(((x**2+y**2)<=0.81)*exp(-(x**2+y**2)/0.18))+(((x**2+y**2)>0.81&&(x**2+y**2)<=25)*0.9*exp(-4.5)/(sqrt(x**2+y**2)))",
32  -5,5,-5,5);
33  gun->set_beam_profile(beam_profile);
34  se->registerSubsystem(gun);
35 
36  // Fun4All G4 module
37  PHG4Reco *g4Reco = new PHG4Reco();
38  //g4Reco->G4Seed(123);
39  //g4Reco->set_field(5.);
40  g4Reco->set_field_map("target.field.root",4);
41  // size of the world - every detector has to fit in here
42  g4Reco->SetWorldSizeX(100);
43  g4Reco->SetWorldSizeY(100);
44  g4Reco->SetWorldSizeZ(800);
45  // shape of our world - it is a tube
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  PHG4CollimatorSubsystem* collimator = new PHG4CollimatorSubsystem("Collimator",0);
53  collimator->SuperDetector("Collimator");
54  collimator->set_double_param("place_z",-302.36);//-302.36 cm
55  collimator->set_double_param("size_z",121.92);
56  collimator->SetActive(1);
57  g4Reco->registerSubsystem(collimator);
58 
59  PHG4TargetCoilSubsystem* coil_0 = new PHG4TargetCoilSubsystem("Coil", 0);
60  coil_0->SuperDetector("Coil");
61  coil_0->set_double_param("rot_x", 90.);
62  coil_0->set_double_param("rot_y", 0.);
63  coil_0->set_double_param("rot_z", 0.);
64  coil_0->set_double_param("place_x", 0.);
65  coil_0->set_double_param("place_y", (22.7+4.)/2);
66  coil_0->set_double_param("place_z", 0.);
67  coil_0->set_int_param("use_g4steps", use_g4steps);
68  coil_0->SetActive(1); // it is an active volume - save G4Hits
69  g4Reco->registerSubsystem(coil_0);
70 
71  PHG4TargetCoilSubsystem* coil_1 = new PHG4TargetCoilSubsystem("Coil", 1);
72  coil_1->SuperDetector("Coil");
73  coil_1->set_double_param("rot_x", -90.);
74  coil_1->set_double_param("rot_y", 0.);
75  coil_1->set_double_param("rot_z", 0.);
76  coil_1->set_double_param("place_x", 0.);
77  coil_1->set_double_param("place_y", -(22.7+4.)/2);
78  coil_1->set_double_param("place_z", 0.);
79  coil_1->set_int_param("use_g4steps", use_g4steps);
80  coil_1->SetActive(1); // it is an active volume - save G4Hits
81  g4Reco->registerSubsystem(coil_1);
82 
83  PHG4CylinderSubsystem* target = new PHG4CylinderSubsystem("Target", 0);
84  target->SuperDetector("Target");
85  target->set_double_param("length", target_l);
86  target->set_double_param("rot_x", 0.);
87  target->set_double_param("rot_y", 0.);
88  target->set_double_param("rot_z", 0.);
89  target->set_double_param("place_x", 0.);
90  target->set_double_param("place_y", 0.);
91  target->set_double_param("place_z", target_z);
92  target->set_double_param("radius", 0.);
93  target->set_double_param("thickness", (2.)/2);
94  target->set_string_param("material", "Target"); // material of target
95  target->set_int_param("lengthviarapidity", 0);
96  target->set_int_param("use_g4steps", use_g4steps);
97  target->SetActive(1); // it is an active volume - save G4Hits
98  g4Reco->registerSubsystem(target);
99 
100 
101  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
102  g4Reco->registerSubsystem(truth);
103 
104  se->registerSubsystem(g4Reco);
105 
106  TruthEval* eval = new TruthEval("TruthEval","eval.root");
107  eval->target_l = target_l;
108  eval->target_z = target_z;
109  se->registerSubsystem(eval);
110 
112  // Output
114 
115  // save a comprehensive evaluation file
117  string("DSTReader.root"));
118  ana->set_save_particle(true);
119  ana->set_load_all_particle(false);
120  ana->set_load_active_particle(true);
121  ana->set_save_vertex(true);
122  ana->AddNode("Coil");
123  ana->AddNode("Target");
124  ana->AddNode("Collimator");
125  se->registerSubsystem(ana);
126 
127  // input - we need a dummy to drive the event loop
129  se->registerInputManager(in);
130 
131  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "DST.root");
132  se->registerOutputManager(out);
133 
134  // a quick evaluator to inspect on hit/particle/tower level
135 
136  if (nEvents > 0)
137  {
138  se->run(nEvents);
139 
140  PHGeomUtility::ExportGeomtry(se->topNode(),"geom.root");
141 
142  // finish job - close and save output files
143  se->End();
144  std::cout << "All done" << std::endl;
145 
146  // cleanup - delete the server and exit
147  delete se;
148  gSystem->Exit(0);
149  }
150  return;
151 }
152 
153 PHG4ParticleGun *get_gun(const char *name = "PGUN")
154 {
156  PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name);
157  return pgun;
158 }
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
int Fun4All_G4_E1039_R2(const int nEvents=1)
void SetWorldShape(const std::string &s)
Definition: PHG4Reco.h:117
float target_l
Definition: TruthEval.h:49
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")
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_field_map(const std::string &fmap, const PHFieldConfig::FieldConfigTypes dim)
Definition: PHG4Reco.h:87
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)
float target_z
Definition: TruthEval.h:50
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