Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RecoE1039Sim.C
Go to the documentation of this file.
1 #include <TSystem.h>
2 
3 #include <top/G4_Beamline.C>
4 #include <top/G4_Target.C>
5 #include <top/G4_InsensitiveVolumes.C>
6 #include <top/G4_SensitiveDetectors.C>
7 
8 R__LOAD_LIBRARY(libfun4all)
9 R__LOAD_LIBRARY(libPHPythia8)
10 R__LOAD_LIBRARY(libg4detectors)
11 R__LOAD_LIBRARY(libg4testbench)
12 R__LOAD_LIBRARY(libg4eval)
13 R__LOAD_LIBRARY(libg4dst)
14 R__LOAD_LIBRARY(libdptrigger)
15 R__LOAD_LIBRARY(libktracker)
16 R__LOAD_LIBRARY(libevt_filter)
17 R__LOAD_LIBRARY(libanamodule)
18 
19 using namespace std;
20 
21 /*
22 This is an example script intended to demonstrate how to run SQReco in a minimalistic fashion, it is NOT
23 suitable for production use and users should develop their own reconstruction macro for their own analysis.
24 */
25 
26 int RecoE1039Sim(const int nevent = 10, TString prefix = "run", int seed = 12345)
27 {
28  const bool cosmic = false;
29  const bool dimuon = false && (!cosmic);
30  const bool single = (!dimuon) && (!cosmic);
31  const bool jpsi = false;
32 
33  const bool legacy_rec_container = false;
34 
35  const bool do_collimator = true;
36  const bool do_target = true;
37  const bool do_shielding = true;
38  const bool do_fmag = true;
39  const bool do_kmag = true;
40  const bool do_absorber = true;
41 
42  const double collimator_pos_z = -602.36;
43  const double target_coil_pos_z = -300.;
44  const double target_l = 7.9; //cm
45  const double target_z = (7.9-target_l)/2.; //cm
46 
47  const double FMAGSTR = -1.054;
48  const double KMAGSTR = -0.951;
49 
51  rc->set_DoubleFlag("FMAGSTR", FMAGSTR);
52  rc->set_DoubleFlag("KMAGSTR", KMAGSTR);
53  rc->set_IntFlag("RANDOMSEED", seed);
54  rc->set_DoubleFlag("SIGX_BEAM", 2.);
55  rc->set_DoubleFlag("SIGY_BEAM", 2.);
56  if(cosmic)
57  {
58  rc->init("cosmic");
59  rc->set_BoolFlag("COARSE_MODE", true);
60  rc->set_DoubleFlag("KMAGSTR", 0.);
61  rc->set_DoubleFlag("FMAGSTR", 0.);
62  }
63  rc->Print();
64 
65  GeomSvc::UseDbSvc(true);
66  GeomSvc* geom_svc = GeomSvc::instance();
67  geom_svc->printTable();
68 
70  se->Verbosity(0);
71 
72  if(dimuon) //change the pythia configuration file to change the dimuons generated
73  {
74  PHPythia8 *pythia8 = new PHPythia8();
75  //pythia8->Verbosity(99);
76  if(jpsi)
77  pythia8->set_config_file("support/phpythia8_Jpsi.cfg");
78  else
79  pythia8->set_config_file("support/phpythia8_DY.cfg");
80 
81  pythia8->set_vertex_distribution_mean(0, 0, target_coil_pos_z, 0);
82  se->registerSubsystem(pythia8);
83 
84  pythia8->set_trigger_AND();
85 
86  PHPy8ParticleTrigger* trigger_mup = new PHPy8ParticleTrigger();
87  trigger_mup->AddParticles("-13");
88  trigger_mup->SetPzHighLow(120, 15);
89  pythia8->register_trigger(trigger_mup);
90 
91  PHPy8ParticleTrigger* trigger_mum = new PHPy8ParticleTrigger();
92  trigger_mum->AddParticles("13");
93  trigger_mum->SetPzHighLow(120, 15);
94  pythia8->register_trigger(trigger_mum);
95 
96  HepMCNodeReader* hr = new HepMCNodeReader();
97  hr->set_particle_filter_on(true);
100  se->registerSubsystem(hr);
101  }
102 
103  if(single) //change the hard-coded numbers to change the initial vertex/momentum distribution
104  {
106  genp->add_particles("mu+", 1); // mu+,e+,proton,pi+,Upsilon
108  genp->set_vertex_distribution_mean(0.0, 0.0, target_coil_pos_z);
109  genp->set_vertex_distribution_width(0.0, 0.0, 0.0);
111  genp->set_vertex_size_parameters(0.0, 0.0);
112  genp->set_pxpypz_range(-6., 6., -3. ,3., 25., 100.);
113  se->registerSubsystem(genp);
114  }
115 
116  if(cosmic)
117  {
118  SQCosmicGen* cosmicGen = new SQCosmicGen();
119  se->registerSubsystem(cosmicGen);
120  }
121 
122  // Fun4All G4 module
123  PHG4Reco* g4Reco = new PHG4Reco();
124  //PHG4Reco::G4Seed(123);
125  g4Reco->set_field_map(
126  rc->get_CharFlag("fMagFile")+" "+
127  rc->get_CharFlag("kMagFile")+" "+
128  Form("%f",FMAGSTR) + " " +
129  Form("%f",KMAGSTR) + " " +
130  "5.0",
132 
133  // size of the world - every detector has to fit in here
134  g4Reco->SetWorldSizeX(1000);
135  g4Reco->SetWorldSizeY(1000);
136  g4Reco->SetWorldSizeZ(5000);
137  // shape of our world - it is a box
138  g4Reco->SetWorldShape("G4BOX");
139  // this is what our world is filled with
140  g4Reco->SetWorldMaterial("G4_AIR"); //G4_Galactic, G4_AIR
141  // Geant4 Physics list to use
142  g4Reco->SetPhysicsList("FTFP_BERT");
143 
144  SetupBeamline(g4Reco, do_collimator, collimator_pos_z);
145  SetupTarget(g4Reco, target_coil_pos_z, target_l, target_z, 1, 0);
146  SetupInsensitiveVolumes(g4Reco, do_shielding, do_fmag, do_kmag, do_absorber);
147  SetupSensitiveDetectors(g4Reco);
148  se->registerSubsystem(g4Reco);
149 
150  // save truth info to the Node Tree
151  PHG4TruthSubsystem* truth = new PHG4TruthSubsystem();
152  g4Reco->registerSubsystem(truth);
153 
154  // apply in-acceptance cut
156  if(dimuon)
157  {
158  inacc->SetNumParticlesPerEvent(2);
159  se->registerSubsystem(inacc);
160  }
161  else if(single)
162  {
163  inacc->SetNumParticlesPerEvent(1);
164  se->registerSubsystem(inacc);
165  }
166 
167  // digitizer
168  SQDigitizer* digitizer = new SQDigitizer("Digitizer", 0);
169  //digitizer->Verbosity(99);
170  se->registerSubsystem(digitizer);
171 
172  // trakcing module
173  SQReco* reco = new SQReco();
174  reco->Verbosity(0);
175  reco->set_legacy_rec_container(legacy_rec_container);
176  //reco->set_geom_file_name("support/geom.root"); //not needed as it's created on the fly
177  reco->set_enable_KF(true); //Kalman filter not needed for the track finding, disabling KF saves a lot of initialization time
178  reco->setInputTy(SQReco::E1039); //options are SQReco::E906 and SQReco::E1039
179  reco->setFitterTy(SQReco::KFREF); //not relavant for the track finding
180  reco->set_evt_reducer_opt("none"); //if not provided, event reducer will be using JobOptsSvc to intialize; to turn off, set it to "none", for normal tracking, set to something like "aoc"
181  reco->set_enable_eval(true); //set to true to generate evaluation file which includes final track candidates
182  reco->set_eval_file_name(Form("eval_%s_%d.root", prefix.Data(), seed));
183  reco->set_enable_eval_dst(false); //set to true to include final track cnadidates in the DST tree
184  if(cosmic) reco->add_eval_list(3); //output of cosmic reco is contained in the eval output for now
185  //reco->add_eval_list(3); //include back partial tracks in eval tree for debuging
186  //reco->add_eval_list(2); //include station-3+/- in eval tree for debuging
187  //reco->add_eval_list(1); //include station-2 in eval tree for debugging
188  se->registerSubsystem(reco);
189 
190  TruthNodeMaker* truthMaker = new TruthNodeMaker();
191  truthMaker->set_legacy_rec_container(legacy_rec_container);
192  se->registerSubsystem(truthMaker);
193 
194  SQTruthVertexing* truthVtx = new SQTruthVertexing();
195  truthVtx->set_legacy_rec_container(legacy_rec_container);
196  se->registerSubsystem(truthVtx);
197 
198  //A simple analysis module for single muon tracking QA
199  AnaModule* ana = new AnaModule();
200  ana->set_output_filename(Form("ana_%s_%d.root", prefix.Data(), seed));
201  ana->set_legacy_rec_container(legacy_rec_container);
202  se->registerSubsystem(ana);
203 
204  // Vertexing is not tested and probably does not work yet
205  // VertexFit* vertexing = new VertexFit();
206  // se->registerSubsystem(vertexing);
207 
208  // input - we need a dummy to drive the event loop
210  se->registerInputManager(in);
211 
213  // Output
215  // DST output manager, tunred off to save disk by default
216  Fun4AllDstOutputManager* out = new Fun4AllDstOutputManager("DSTOUT", Form("DST_%s_%d.root", prefix.Data(), seed));
217  se->registerOutputManager(out);
218 
219  se->run(nevent);
220  PHGeomUtility::ExportGeomtry(se->topNode(), "geom.root");
221 
222  // finish job - close and save output files
223  se->End();
224  se->PrintTimer();
225  std::cout << "All done" << std::endl;
226 
227  // cleanup - delete the server and exit
228  delete se;
229  gSystem->Exit(0);
230 
231  return 0;
232 }
int registerInputManager(Fun4AllInputManager *InManager)
virtual int End()
virtual void set_DoubleFlag(const std::string &name, const double flag)
Definition: PHFlag.cc:77
Runs G4 as a subsystem.
Definition: PHG4Reco.h:38
void set_legacy_rec_container(const bool b=true)
Definition: SQReco.h:77
virtual void set_BoolFlag(const std::string &name, const bool flag)
Definition: PHFlag.cc:179
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_trigger_AND()
Definition: PHPythia8.h:60
void AddParticles(std::string particles)
void SetWorldMaterial(const std::string &s)
Definition: PHG4Reco.h:118
void init(int runNo=0, bool verbose=false)
initialize the constants by the runNo - not implemented yet
Definition: recoConsts.cc:157
void add_particles(const std::string &name, const unsigned int count)
interface for adding particles by name
void Print() const
print all the parameters
Definition: recoConsts.cc:185
An SubsysReco module to create a set of SQ nodes for the simulation true info.
void SetWorldShape(const std::string &s)
Definition: PHG4Reco.h:117
void set_particle_filter_on(const bool a)
void set_legacy_rec_container(bool b=true)
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.
void set_legacy_rec_container(bool b)
Definition: AnaModule.h:28
virtual void set_IntFlag(const std::string &name, const int flag)
Definition: PHFlag.cc:145
int run(const int nEvents=1)
Definition: run.C:10
static recoConsts * instance()
Definition: recoConsts.cc:7
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")
static bool UseDbSvc()
Definition: GeomSvc.h:304
void set_config_file(const char *cfg_file)
Definition: PHPythia8.h:46
void SetPzHighLow(double pzHigh, double pzLow)
void set_enable_KF(bool enable)
Definition: SQReco.h:66
int run(const int nevnts=0, const bool require_nevents=false)
run n events (0 means up to end of file)
void set_eval_file_name(const TString &evalFileName)
Definition: SQReco.h:60
void SetNumParticlesPerEvent(const int val)
void set_vertex_distribution_mean(const double x, const double y, const double z)
set the mean value of the vertex distribution
void set_legacy_rec_container(const bool enable=true)
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 SetupInsensitiveVolumes(PHG4Reco *g4Reco, const bool toggle_shielding=true, const bool toggle_fmag=true, const bool toggle_kmag=true, const bool toggle_absorber=true, const int enable_fmag_filter=0, const double filter_max_slope=0.25, const double filter_min_energy=5.)
void set_output_filename(const TString &n)
Definition: AnaModule.h:32
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
An SubsysReco module to select in-acceptance events.
PHCompositeNode * topNode() const
Definition: Fun4AllServer.h:59
virtual const std::string get_CharFlag(const std::string &flag) const
Definition: PHFlag.cc:13
void ana()
Definition: ana.C:291
void SetWorldSizeX(const double sx)
Definition: PHG4Reco.h:111
Definition: SQReco.h:42
void setInputTy(SQReco::INPUT_TYPE input_ty)
Definition: SQReco.h:56
void printTable()
Definition: GeomSvc.cxx:1164
void set_evt_reducer_opt(const TString &opt)
Definition: SQReco.h:75
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
void set_enable_eval(bool enable)
Definition: SQReco.h:69
void set_vertex_size_function(FUNCTION r)
set the distribution function of particles about the vertex
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 register_trigger(PHPy8GenTrigger *theTrigger)
set event selection criteria
Definition: PHPythia8.C:303
void SetupBeamline(PHG4Reco *g4Reco, const bool toggle_collimator=true, const double collimator_pos_z=-300, const int register_hits=0)
Definition: G4_Beamline.C:8
int RecoE1039Sim(const int nevent=10, TString prefix="run", int seed=12345)
Definition: RecoE1039Sim.C:26
void registerSubsystem(PHG4Subsystem *subsystem)
register subsystem
Definition: PHG4Reco.h:65
An SubsysReco module to create create dimuons based on the truth vertex information.
void setFitterTy(SQReco::FITTER_TYPE fitter_ty)
Definition: SQReco.h:57
void set_enable_eval_dst(bool enable)
Definition: SQReco.h:71
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 add_eval_list(int listID)
Definition: SQReco.cxx:665
void SetWorldSizeZ(const double sz)
Definition: PHG4Reco.h:113
void SetWorldSizeY(const double sy)
Definition: PHG4Reco.h:112