Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4All_Test.C
Go to the documentation of this file.
1 
2 #include <iostream>
3 
4 using namespace std;
5 
6 int Fun4All_Test(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, -30); //-363.32 cm
28  gun->set_mom(0, 0, 0.1);
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");//G4_Galactic, G4_AIR
49  // Geant4 Physics list to use
50  g4Reco->SetPhysicsList("FTFP_BERT");
51 
52  //PHG4CylinderSubsystem *blackhole = new PHG4CylinderSubsystem("BH", 1);
53  //blackhole->set_double_param("radius", 25); // add 10 cm
54  //blackhole->set_int_param("lengthviarapidity",0);
55  //blackhole->set_double_param("length",1); // make it cover the world in length
56  //blackhole->set_double_param("rot_x", -90.);
57  //blackhole->BlackHole();
58  //blackhole->set_double_param("thickness",0.1); // it needs some thickness
59  //blackhole->SetActive(); // always see what leaks out
60  //g4Reco->registerSubsystem(blackhole);
61 
62  PHG4CylinderSubsystem *dummy = new PHG4CylinderSubsystem("DUMMY", 1);
63  dummy->set_string_param("material", "G4_AIR"); // material of target
64  dummy->set_double_param("radius", 22); // add 10 cm
65  dummy->set_int_param("lengthviarapidity",0);
66  dummy->set_double_param("length",1); // make it cover the world in length
67  dummy->set_double_param("rot_x", -90.);
68  dummy->set_double_param("thickness",0.1); // it needs some thickness
69  dummy->SetActive(); // always see what leaks out
70  g4Reco->registerSubsystem(dummy);
71 
72  //PHG4CollimatorSubsystem* collimator = new PHG4CollimatorSubsystem("Collimator",0);
73  //collimator->SuperDetector("Collimator");
74  //collimator->set_double_param("place_z",-302.36);//-302.36 cm
75  //collimator->set_double_param("size_z",121.92);
76  //collimator->SetActive(1);
77  //g4Reco->registerSubsystem(collimator);
78 
79  PHG4TargetCoilSubsystem* coil_0 = new PHG4TargetCoilSubsystem("Coil", 0);
80  coil_0->SuperDetector("Coil");
81  coil_0->set_double_param("rot_x", 90.);
82  coil_0->set_double_param("rot_y", 0.);
83  coil_0->set_double_param("rot_z", 0.);
84  coil_0->set_double_param("place_x", 0.);
85  coil_0->set_double_param("place_y", (22.7+4.)/2);
86  coil_0->set_double_param("place_z", 0.);
87  coil_0->set_int_param("use_g4steps", use_g4steps);
88  coil_0->SetActive(1); // it is an active volume - save G4Hits
89  g4Reco->registerSubsystem(coil_0);
90 
91  PHG4TargetCoilSubsystem* coil_1 = new PHG4TargetCoilSubsystem("Coil", 1);
92  coil_1->SuperDetector("Coil");
93  coil_1->set_double_param("rot_x", -90.);
94  coil_1->set_double_param("rot_y", 0.);
95  coil_1->set_double_param("rot_z", 0.);
96  coil_1->set_double_param("place_x", 0.);
97  coil_1->set_double_param("place_y", -(22.7+4.)/2);
98  coil_1->set_double_param("place_z", 0.);
99  coil_1->set_int_param("use_g4steps", use_g4steps);
100  coil_1->SetActive(1); // it is an active volume - save G4Hits
101  //g4Reco->registerSubsystem(coil_1);
102 
103  PHG4CylinderSubsystem* target = new PHG4CylinderSubsystem("Target", 0);
104  target->SuperDetector("Target");
105  target->set_double_param("length", target_l);
106  target->set_double_param("rot_x", 0.);
107  target->set_double_param("rot_y", 0.);
108  target->set_double_param("rot_z", 0.);
109  target->set_double_param("place_x", 0.);
110  target->set_double_param("place_y", 0.);
111  target->set_double_param("place_z", target_z);
112  target->set_double_param("radius", 0.);
113  target->set_double_param("thickness", (2.)/2);
114  target->set_string_param("material", "Target"); // material of target
115  target->set_int_param("lengthviarapidity", 0);
116  target->set_int_param("use_g4steps", use_g4steps);
117  target->SetActive(1); // it is an active volume - save G4Hits
118  g4Reco->registerSubsystem(target);
119 
120 
121  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
122  g4Reco->registerSubsystem(truth);
123 
124  se->registerSubsystem(g4Reco);
125 
126  TruthEval* eval = new TruthEval("TruthEval","eval.root");
127  eval->target_l = target_l;
128  eval->target_z = target_z;
129  se->registerSubsystem(eval);
130 
132  // Output
134 
135  // save a comprehensive evaluation file
136  //PHG4DSTReader *ana = new PHG4DSTReader(
137  // string("DSTReader.root"));
138  //ana->set_save_particle(true);
139  //ana->set_load_all_particle(false);
140  //ana->set_load_active_particle(true);
141  //ana->set_save_vertex(true);
143  //ana->AddNode("Target");
145  //se->registerSubsystem(ana);
146 
147  // input - we need a dummy to drive the event loop
149  se->registerInputManager(in);
150 
151  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "DST.root");
152  se->registerOutputManager(out);
153 
154  // a quick evaluator to inspect on hit/particle/tower level
155 
156  if (nEvents > 0)
157  {
158  se->run(nEvents);
159 
160  PHGeomUtility::ExportGeomtry(se->topNode(),"geom.root");
161 
162  // finish job - close and save output files
163  se->End();
164  std::cout << "All done" << std::endl;
165 
166  // cleanup - delete the server and exit
167  delete se;
168  gSystem->Exit(0);
169  }
170  return;
171 }
172 
173 PHG4ParticleGun *get_gun(const char *name = "PGUN")
174 {
176  PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name);
177  return pgun;
178 }
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 SetWorldMaterial(const std::string &s)
Definition: PHG4Reco.h:118
void SetWorldShape(const std::string &s)
Definition: PHG4Reco.h:117
float target_l
Definition: TruthEval.h:49
int Fun4All_Test(const int nEvents=1)
Definition: Fun4All_Test.C:6
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
PHCompositeNode * topNode() const
Definition: Fun4AllServer.h:59
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 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