Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4TrkDev.C
Go to the documentation of this file.
1 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
2 #include <phool/recoConsts.h>
3 #include <fun4all/SubsysReco.h>
11 #include <g4main/PHG4Reco.h>
15 #include <g4main/PHG4ParticleGun.h>
16 #include <g4main/HepMCNodeReader.h>
19 #include <g4detectors/DPDigitizer.h>
20 //#include <phpythia6/PHPythia6.h>
21 #include <phpythia8/PHPythia8.h>
22 //#include <phhepmc/Fun4AllHepMCInputManager.h>
23 #include <g4eval/PHG4DSTReader.h>
24 #include <jobopts_svc/JobOptsSvc.h>
25 #include <geom_svc/GeomSvc.h>
26 #include <module_example/TrkEval.h>
27 
28 #include <TSystem.h>
29 
30 #include "G4_SensitiveDetectors.C"
31 #include "G4_Target.C"
32 
33 R__LOAD_LIBRARY(libfun4all)
34 R__LOAD_LIBRARY(libg4detectors)
35 R__LOAD_LIBRARY(libg4testbench)
36 R__LOAD_LIBRARY(libg4eval)
37 R__LOAD_LIBRARY(libktracker)
38 R__LOAD_LIBRARY(libPHPythia8)
39 //R__LOAD_LIBRARY(libembedding)
40 #endif
41 
42 using namespace std;
43 
45  const int nEvents = 1,
46  const int nmu = 1,
47  const double x0_shift = 0.0 //cm
48  )
49 {
50  const double target_coil_pos_z = -300;
51  int embedding_opt = 0;
52 
53  const bool do_collimator = false;
54  const bool do_target = false;
55  const double target_l = 7.9; //cm
56  const double target_z = (7.9-target_l)/2.; //cm
57  const int use_g4steps = 1;
58 
59  const bool gen_gun = false;
60  const bool gen_pythia8 = false;
61  const bool gen_test = false;
62  const bool gen_particle = true;
63 
64  gSystem->Load("libfun4all");
65  gSystem->Load("libg4detectors");
66  gSystem->Load("libg4testbench");
67  gSystem->Load("libg4eval");
68  gSystem->Load("libktracker.so");
69 
70  JobOptsSvc *jobopt_svc = JobOptsSvc::instance();
71  jobopt_svc->init("default.opts");
72 
73  GeomSvc *geom_svc = GeomSvc::instance();
74  std::cout << "D2X::X0: " << geom_svc->getDetectorX0("D2X") << std::endl;
75  geom_svc->setDetectorX0("D2X", geom_svc->getDetectorX0("D2X")+x0_shift);
76  std::cout << "D2X::X0: " << geom_svc->getDetectorX0("D2X") << std::endl;
77 
79  // Make the Server
82  se->Verbosity(100);
83 
84  // particle gun
85  if(gen_gun) {
86  PHG4ParticleGun *gun = new PHG4ParticleGun("GUN");
87  gun->set_name("mu+");
88  gun->set_vtx(0, 0, target_coil_pos_z);
89  gun->set_mom(3, 0, 40);
90  se->registerSubsystem(gun);
91  }
92 
93  if(gen_pythia8) {
94  gSystem->Load("libPHPythia8.so");
95 
96  PHPythia8 *pythia8 = new PHPythia8();
97  pythia8->set_config_file("phpythia8_DY.cfg");
98  pythia8->set_vertex_distribution_mean(0, 0, target_coil_pos_z, 0);
99  se->registerSubsystem(pythia8);
100 
101  pythia8->set_trigger_AND();
102 
103  PHPy8ParticleTrigger* trigger_mup = new PHPy8ParticleTrigger();
104  trigger_mup->AddParticles("-13");
105  //trigger_mup->SetPxHighLow(7, 0.5);
106  //trigger_mup->SetPyHighLow(6, -6);
107  trigger_mup->SetPzHighLow(120, 10);
108  pythia8->register_trigger(trigger_mup);
109 
110  PHPy8ParticleTrigger* trigger_mum = new PHPy8ParticleTrigger();
111  trigger_mum->AddParticles("13");
112  //trigger_mum->SetPxHighLow(-0.5, -7);
113  //trigger_mum->SetPyHighLow(6, -6);
114  trigger_mum->SetPzHighLow(120, 10);
115  pythia8->register_trigger(trigger_mum);
116 
117  HepMCNodeReader *hr = new HepMCNodeReader();
118  hr->set_particle_filter_on(true);
121  se->registerSubsystem(hr);
122  }
123 
124  if(gen_test) {
125  PHG4ParticleGun *gun_mup = new PHG4ParticleGun("GUN_mup");
126  gun_mup->set_name("mu+");
127  //gun_mup->set_vtx(30, 0, 500);
128  //gun_mup->set_mom(0, 0, 30.);
129  gun_mup->set_vtx(0., 0., target_coil_pos_z);
130  gun_mup->set_mom(3., 0.2, 40.);
131  se->registerSubsystem(gun_mup);
132 
133  PHG4ParticleGun *gun_mum = new PHG4ParticleGun("GUN_mum");
134  gun_mum->set_name("mu-");
135  //gun_mum->set_vtx(-30, 0, 500);
136  //gun_mum->set_mom(0., 0., 30.);
137  gun_mum->set_vtx(0., 0., target_coil_pos_z);
138  gun_mum->set_mom(-3., -0.2, 40.);
139  se->registerSubsystem(gun_mum);
140  }
141 
142  if(gen_particle) {
144  //gen->set_seed(123);
145  gen->add_particles("mu+", nmu); // mu+,e+,proton,pi+,Upsilon
149  gen->set_vertex_distribution_mean(0.0, 0.0, target_coil_pos_z);
150  gen->set_vertex_distribution_width(0.0, 0.0, 0.0);
152  gen->set_vertex_size_parameters(0.0, 0.0);
153 
154  //gen->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
155  //gen->set_eta_range(2, 4);
156 
157  gen->set_pxpypz_range(-0.2,-0.2, 0.4,0.4, 51,51);
158  gen->set_vertex_distribution_mean(25, 8, 615);
159 
160  //gen->set_pxpypz_range(3,3, 0.5,0.5, 60,60);
161  //gen->set_pxpypz_range(1,4, -1,1, 30,60);
162  //gen->set_pxpypz_range(0,6, -6,6, 10,100);
163 
164  gen->Verbosity(0);
165  se->registerSubsystem(gen);
166  }
167 
168  if(gen_particle) {
170  gen2->add_particles("mu-", nmu); // mu+,e+,proton,pi+,Upsilon
174  gen2->set_vertex_distribution_mean(0.0, 0.0, target_coil_pos_z);
175  gen2->set_vertex_distribution_width(0.0, 0.0, 0.0);
177  gen2->set_vertex_size_parameters(0.0, 0.0);
178 
179  //gen2->set_phi_range(-1.0 * TMath::Pi(), 1.0 * TMath::Pi());
180  //gen2->set_eta_range(2, 4);
181  gen2->set_pxpypz_range(-4, -1, -1, 1, 30, 60);
182  gen2->Verbosity(0);
183  //se->registerSubsystem(gen2);
184  }
185 
186  // Fun4All G4 module
187  PHG4Reco *g4Reco = new PHG4Reco();
188  //PHG4Reco::G4Seed(123);
189  //g4Reco->set_field(5.);
190  g4Reco->set_field_map(
191  jobopt_svc->m_fMagFile+" "+
192  jobopt_svc->m_kMagFile+" "+
193  "1.0 1.0 0.0",
195  // size of the world - every detector has to fit in here
196  g4Reco->SetWorldSizeX(1000);
197  g4Reco->SetWorldSizeY(1000);
198  g4Reco->SetWorldSizeZ(5000);
199  // shape of our world - it is a tube
200  g4Reco->SetWorldShape("G4BOX");
201  // this is what our world is filled with
202  g4Reco->SetWorldMaterial("G4_AIR"); //G4_Galactic, G4_AIR
203  // Geant4 Physics list to use
204  g4Reco->SetPhysicsList("FTFP_BERT");
205 
206  PHG4E1039InsensSubsystem* insens = new PHG4E1039InsensSubsystem("Insens");
207  g4Reco->registerSubsystem(insens);
208 
209  gROOT->LoadMacro("G4_Target.C");
210  SetupTarget(g4Reco, do_collimator, do_target, target_coil_pos_z, target_l, target_z, use_g4steps);
211 
212  gROOT->LoadMacro("G4_SensitiveDetectors.C");
213  SetupSensitiveDetectors(g4Reco);
214 
215  se->registerSubsystem(g4Reco);
216 
217  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
218  g4Reco->registerSubsystem(truth);
219 
220  DPDigitizer *digitizer = new DPDigitizer("DPDigitizer", 0);
221  //digitizer->Verbosity(10);
222  se->registerSubsystem(digitizer);
223 
224  gSystem->Load("libembedding.so");
225 
226 #if ROOT_VERSION_CODE < ROOT_VERSION(6,00,0)
227  if(embedding_opt == 1) {
228  SRawEventEmbed *embed = new SRawEventEmbed("SRawEventEmbed");
229  embed->set_in_name("digit_016070_R007.root");
230  embed->set_in_tree_name("save");
231  embed->set_trigger_bit((1<<0));
232  //embed->set_in_name("random_run3a_1.root");
233  //embed->set_in_tree_name("mb");
234  //embed->set_trigger_bit((1<<7));
235  embed->Verbosity(100);
236  se->registerSubsystem(embed);
237  } else if(embedding_opt == 2) {
238  RndmEmbed *embed = new RndmEmbed("RndmEmbed");
239 
240  //high
241  //double noise_rate_1 = 0.25;
242  //double noise_rate_2 = 0.15;
243  //double noise_rate_3 = 0.12;
244 
245  //medium
246  double noise_rate_1 = 0.12;
247  double noise_rate_2 = 0.10;
248  double noise_rate_3 = 0.08;
249 
250  embed->set_noise_rate("D1X", noise_rate_1);
251  embed->set_noise_rate("D1U", noise_rate_1);
252  embed->set_noise_rate("D1V", noise_rate_1);
253  embed->set_noise_rate("D2Xp", noise_rate_2);
254  embed->set_noise_rate("D2U", noise_rate_2);
255  embed->set_noise_rate("D2V", noise_rate_2);
256  embed->set_noise_rate("D3pXp", noise_rate_3);
257  embed->set_noise_rate("D3pUp", noise_rate_3);
258  embed->set_noise_rate("D3pVp", noise_rate_3);
259  embed->set_noise_rate("D3mXp", noise_rate_3);
260  embed->set_noise_rate("D3mUp", noise_rate_3);
261  embed->set_noise_rate("D3mVp", noise_rate_3);
262 
263  embed->print_noise_rate();
264 
265  se->registerSubsystem(embed);
266  }
267 #endif
268 
269 
270  gSystem->Load("libktracker.so");
271  KalmanFastTrackingWrapper *ktracker = new KalmanFastTrackingWrapper();
272  ktracker->Verbosity(10);
273  ktracker->set_DS_level(0);
274  se->registerSubsystem(ktracker);
275 
277  // Output
279 
280  // save a comprehensive evaluation file
282  string("DSTReader.root"));
283  ana->set_save_particle(true);
284  ana->set_load_all_particle(false);
285  ana->set_load_active_particle(true);
286  ana->set_save_vertex(true);
287  //ana->AddNode("Coil");
288  //ana->AddNode("Target");
289  //ana->AddNode("Collimator");
290  ana->AddNode("C1X");
291  ana->AddNode("C2X");
292  se->registerSubsystem(ana);
293 
294  // input - we need a dummy to drive the event loop
296  se->registerInputManager(in);
297 
298  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "DST.root");
299  se->registerOutputManager(out);
300 
301  // a quick evaluator to inspect on hit/particle/tower level
302 
303  if (nEvents > 0)
304  {
305  se->run(nEvents);
306 
307  PHGeomUtility::ExportGeomtry(se->topNode(),"geom.root");
308 
309  // finish job - close and save output files
310  se->End();
311  se->PrintTimer();
312  std::cout << "All done" << std::endl;
313 
314  // cleanup - delete the server and exit
315  delete se;
316  gSystem->Exit(0);
317  }
318  return 0;
319 }
320 
321 PHG4ParticleGun *get_gun(const char *name = "PGUN")
322 {
324  PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name);
325  return pgun;
326 }
int registerInputManager(Fun4AllInputManager *InManager)
virtual int End()
Runs G4 as a subsystem.
Definition: PHG4Reco.h:38
void set_in_tree_name(const std::string &inTreeName)
void insert_particle_filter_pid(const int a)
void SetupSensitiveDetectors(PHG4Reco *g4Reco, bool toggle_dphodo=true, bool toggle_dc1=false, std::string chamberGas="SQ_ArCO2", std::string hodoMat="SQ_Scintillator", const int verbosity=0)
void set_load_all_particle(bool b)
Definition: PHG4DSTReader.h:73
void set_trigger_AND()
Definition: PHPythia8.h:60
void AddParticles(std::string particles)
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 print_noise_rate() const
Definition: RndmEmbed.h:75
SQDigitizer DPDigitizer
void add_particles(const std::string &name, const unsigned int count)
interface for adding particles by name
void set_noise_rate(const std::string &name, const double &rate)
Definition: RndmEmbed.h:81
void SetWorldShape(const std::string &s)
Definition: PHG4Reco.h:117
void set_particle_filter_on(const bool a)
static Fun4AllServer * instance()
Fun4AllServer * se
void PrintTimer(const std::string &name="")
static void ExportGeomtry(PHCompositeNode *topNode, const std::string &geometry_file)
DST node -&gt; TGeoManager -&gt; export files, like gdml, .root or .C formats.
double getDetectorX0(const std::string detectorName) const
Definition: GeomSvc.h:170
void set_vertex_distribution_function(FUNCTION x, FUNCTION y, FUNCTION z)
toss a new vertex according to a Uniform or Gaus distribution
int registerSubsystem(SubsysReco *subsystem, const std::string &topnodename="TOP")
void set_config_file(const char *cfg_file)
Definition: PHPythia8.h:46
void SetPzHighLow(double pzHigh, double pzLow)
int run(const int nevnts=0, const bool require_nevents=false)
run n events (0 means up to end of file)
void set_vertex_distribution_mean(const double x, const double y, const double z)
set the mean value of the vertex distribution
int registerOutputManager(Fun4AllOutputManager *manager)
void set_vertex_distribution_width(const double x, const double y, const double z)
set the width of the vertex distribution function about the mean
void set_field_map(const std::string &fmap, const PHFieldConfig::FieldConfigTypes dim)
Definition: PHG4Reco.h:87
void set_vertex_distribution_mean(const double x, const double y, const double z, const double t)
set the mean value of the vertex distribution, use PHENIX units of cm, ns
Definition: PHPythia8.h:86
void set_in_name(const std::string &inName)
void set_save_vertex(bool b)
Switch for vertex.
Definition: PHG4DSTReader.h:94
void SetupTarget(PHG4Reco *g4Reco, const double target_coil_pos_z=-300, const double target_l=7.9, const double target_z=0., const int use_g4steps=1, const int register_hits=0)
Definition: G4_Target.C:10
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 SetWorldSizeX(const double sx)
Definition: PHG4Reco.h:111
void setDetectorX0(const std::string detectorName, const double val)
TODO temp solution to overwrite the y0 of a plane.
Definition: GeomSvc.h:151
void SetPhysicsList(const std::string &s)
Definition: PHG4Reco.h:119
void set_vertex_size_parameters(const double mean, const double width)
set the dimensions of the distribution of particles about the vertex
virtual void set_vtx(const double x, const double y, const double z)
void set_vertex_size_function(FUNCTION r)
set the distribution function of particles about the vertex
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
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:211
void set_load_active_particle(bool b)
load all particle that produced a saved hit
Definition: PHG4DSTReader.h:80
void register_trigger(PHPy8GenTrigger *theTrigger)
set event selection criteria
Definition: PHPythia8.C:303
virtual void set_name(const std::string &particle="proton")
virtual void set_mom(const double x, const double y, const double z)
void set_trigger_bit(int triggerBit)
int Fun4TrkDev(const int nEvents=1, const int nmu=1, const double x0_shift=0.0)
Definition: Fun4TrkDev.C:44
PHG4ParticleGun * get_gun(const char *name="PGUN")
void registerSubsystem(PHG4Subsystem *subsystem)
register subsystem
Definition: PHG4Reco.h:65
void set_pxpypz_range(const double x_min, const double x_max, const double y_min, const double y_max, const double z_min, const double z_max)
void SetWorldSizeZ(const double sz)
Definition: PHG4Reco.h:113
void SetWorldSizeY(const double sy)
Definition: PHG4Reco.h:112