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