Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4Sim.C
Go to the documentation of this file.
1 #include <top/G4_Beamline.C>
2 #include <top/G4_Target.C>
3 #include <top/G4_InsensitiveVolumes.C>
4 #include <top/G4_SensitiveDetectors.C>
5 
6 R__LOAD_LIBRARY(libfun4all)
7 R__LOAD_LIBRARY(libPHPythia8)
8 R__LOAD_LIBRARY(libg4detectors)
9 R__LOAD_LIBRARY(libg4testbench)
10 R__LOAD_LIBRARY(libg4eval)
11 R__LOAD_LIBRARY(libg4dst)
12 R__LOAD_LIBRARY(libdptrigger)
13 R__LOAD_LIBRARY(libembedding)
14 R__LOAD_LIBRARY(libevt_filter)
15 R__LOAD_LIBRARY(libktracker)
16 R__LOAD_LIBRARY(libSQPrimaryGen)
17 using namespace std;
18 
19 int Fun4Sim(const int nevent = 10)
20 {
21  const double target_coil_pos_z = -300;
22  const int nmu = 1;
23  int embedding_opt = 0;
24  const bool legacy_rec_container = true;
25 
26  const bool do_collimator = true;
27  const bool do_target = true;
28  const bool do_e1039_shielding = true;
29  const bool do_fmag = true;
30  const bool do_kmag = true;
31  const bool do_absorber = true;
32  const bool do_dphodo = true;
33  const bool do_station1DC = false; //station-1 drift chamber should be turned off by default
34 
35  const double target_l = 7.9; //cm
36  const double target_z = (7.9-target_l)/2.; //cm
37  const int use_g4steps = 1;
38 
39  const double FMAGSTR = -1.054;
40  const double KMAGSTR = -0.951;
41 
42  const bool gen_pythia8 = true; // false;
43  const bool gen_cosmic = false;
44  const bool gen_gun = false;
45  const bool gen_particle = false;
46  const bool read_hepmc = false;
47  const bool gen_e906legacy = false; //E906LegacyGen()
48  const bool save_in_acc = false; //< Set true to save only in-acceptance events into DST.
49 
51  rc->set_DoubleFlag("FMAGSTR", FMAGSTR);
52  rc->set_DoubleFlag("KMAGSTR", KMAGSTR);
53  if(gen_cosmic) {
54  rc->init("cosmic");
55  rc->set_BoolFlag("COARSE_MODE", true);
56  rc->set_DoubleFlag("KMAGSTR", 0.);
57  rc->set_DoubleFlag("FMAGSTR", 0.);
58  }
59  rc->Print();
60 
61  GeomSvc::UseDbSvc(true);
62  GeomSvc *geom_svc = GeomSvc::instance();
63  //const double x0_shift = 0.0; //cm
64  //std::cout << "D2X::X0: " << geom_svc->getDetectorX0("D2X") << std::endl;
65  //geom_svc->setDetectorX0("D2X", geom_svc->getDetectorX0("D2X")+x0_shift);
66  //std::cout << "D2X::X0: " << geom_svc->getDetectorX0("D2X") << std::endl;
67 
69  // Make the Server
72  se->Verbosity(0);
73 
74 
75  // pythia8
76  if(gen_pythia8) {
77  PHPythia8 *pythia8 = new PHPythia8();
78  //pythia8->Verbosity(99);
79 // pythia8->set_config_file("phpythia8_DY.cfg");
80  pythia8->set_config_file("phpythia8_Jpsi.cfg");
81  pythia8->set_vertex_distribution_mean(0, 0, target_coil_pos_z, 0);
82  pythia8->set_embedding_id(1);
83  se->registerSubsystem(pythia8);
84 
85  pythia8->set_trigger_AND();
86 
87  PHPy8ParticleTrigger* trigger_mup = new PHPy8ParticleTrigger();
88  trigger_mup->AddParticles("-13");
89  //trigger_mup->SetPxHighLow(7, 0.5);
90  //trigger_mup->SetPyHighLow(6, -6);
91  trigger_mup->SetPzHighLow(120, 10);
92  pythia8->register_trigger(trigger_mup);
93 
94  PHPy8ParticleTrigger* trigger_mum = new PHPy8ParticleTrigger();
95  trigger_mum->AddParticles("13");
96  //trigger_mum->SetPxHighLow(-0.5, 7);
97  //trigger_mum->SetPyHighLow(6, -6);
98  trigger_mum->SetPzHighLow(120, 10);
99  pythia8->register_trigger(trigger_mum);
100  }
101 
102  if(gen_pythia8 || read_hepmc) {
103  HepMCNodeReader *hr = new HepMCNodeReader();
104  hr->set_particle_filter_on(true);
107  se->registerSubsystem(hr);
108  }
109 
110  // single gun
111  if(gen_gun) {
112  PHG4ParticleGun *gun = new PHG4ParticleGun("GUN");
113  gun->set_name("mu-");
114  //gun->set_vtx(0, 0, target_coil_pos_z);
115  //gun->set_mom(3, 3, 50);
116  gun->set_vtx(30, 10, 590);
117  gun->set_mom(-0.3, 2, 50);
118  se->registerSubsystem(gun);
119  }
120 
121  // multi particle gun
122  if(gen_particle) {
124  //genp->set_seed(123);
125  genp->add_particles("mu+", nmu); // mu+,e+,proton,pi+,Upsilon
129  genp->set_vertex_distribution_mean(0.0, 0.0, target_coil_pos_z);
130  genp->set_vertex_distribution_width(0.0, 0.0, 0.0);
132  genp->set_vertex_size_parameters(0.0, 0.0);
133 
134  if(FMAGSTR>0)
135  //genp->set_pxpypz_range(0,6, -6,6, 10,100);
136  genp->set_pxpypz_range(-3,6, -3,3, 10,100);
137  else
138  //genp->set_pxpypz_range(-6,0, -6,6, 10,100);
139  genp->set_pxpypz_range(-6,3, -3,3, 10,100);
140 
141 
142  genp->Verbosity(0);
143  se->registerSubsystem(genp);
144  }
145 
146  if(gen_particle) {
148  //genm->set_seed(123);
149  genm->add_particles("mu-", nmu); // mu+,e+,proton,pi+,Upsilon
153  genm->set_vertex_distribution_mean(0.0, 0.0, target_coil_pos_z);
154  genm->set_vertex_distribution_width(0.0, 0.0, 0.0);
156  genm->set_vertex_size_parameters(0.0, 0.0);
157 
158  if(FMAGSTR>0)
159  //genm->set_pxpypz_range(-6,0, -6,6, 10,100);
160  genm->set_pxpypz_range(-6,3, -3,3, 10,100);
161  else
162  //genm->set_pxpypz_range(0,6, -6,6, 10,100);
163  genm->set_pxpypz_range(-3,6, -3,3, 10,100);
164 
165  genm->Verbosity(0);
166  se->registerSubsystem(genm);
167  }
168 
169  // E906LegacyGen
170  if(gen_e906legacy){
171  SQPrimaryParticleGen *e906legacy = new SQPrimaryParticleGen();
172 
173  const bool pythia_gen = false;
174  const bool drellyan_gen = true;
175  const bool JPsi_gen = false;
176  const bool Psip_gen = false;
177 
178  if(drellyan_gen){
179  e906legacy->set_xfRange(0.1, 0.5); //[-1.,1.]
180  e906legacy->set_massRange(0.23, 10.0);// 0.22 and above
181  e906legacy->enableDrellYanGen();
182  }
183 
184 
185  if(Psip_gen){
186  e906legacy->set_xfRange(0.1, 0.5); //[-1.,1.]
187  e906legacy->enablePsipGen();
188  }
189 
190 
191  if(JPsi_gen){
192  e906legacy->set_xfRange(0.1, 0.5); //[-1.,1.]
193  e906legacy->enableJPsiGen();
194  }
195 
196  if(pythia_gen) e906legacy->enablePythia();
197 
198  se->registerSubsystem(e906legacy);
199  }
200 
201  if(gen_cosmic) {
202  SQCosmicGen* cosmicGen = new SQCosmicGen();
203  se->registerSubsystem(cosmicGen);
204  }
205 
206  // Fun4All G4 module
207  PHG4Reco *g4Reco = new PHG4Reco();
208  //PHG4Reco::G4Seed(123);
209  //g4Reco->set_field(5.);
210  g4Reco->set_field_map(
211  rc->get_CharFlag("fMagFile")+" "+
212  rc->get_CharFlag("kMagFile")+" "+
213  Form("%f",FMAGSTR) + " " +
214  Form("%f",KMAGSTR) + " " +
215  "5.0",
217  // size of the world - every detector has to fit in here
218  g4Reco->SetWorldSizeX(1000);
219  g4Reco->SetWorldSizeY(1000);
220  g4Reco->SetWorldSizeZ(5000);
221  // shape of our world - it is a tube
222  g4Reco->SetWorldShape("G4BOX");
223  // this is what our world is filled with
224  g4Reco->SetWorldMaterial("G4_AIR"); //G4_Galactic, G4_AIR
225  // Geant4 Physics list to use
226  g4Reco->SetPhysicsList("FTFP_BERT");
227 
228  // insensitive elements of the spectrometer
229  SetupInsensitiveVolumes(g4Reco, do_e1039_shielding, do_fmag, do_kmag, do_absorber);
230 
231  // collimator, targer and shielding between target and FMag
232  SetupBeamline(g4Reco, do_collimator, target_coil_pos_z - 302.36); // Is the position correct??
233 
234  if (do_target) {
235  SetupTarget(g4Reco, target_coil_pos_z, target_l, target_z, use_g4steps);
236  }
237 
238  // sensitive elements of the spectrometer
239  SetupSensitiveDetectors(g4Reco, do_dphodo, do_station1DC);
240 
241  se->registerSubsystem(g4Reco);
242 
243  if (save_in_acc) se->registerSubsystem(new RequireParticlesInAcc());
244 
245  // save truth info to the Node Tree
246  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
247  g4Reco->registerSubsystem(truth);
248 
249  // digitizer
250  SQDigitizer *digitizer = new SQDigitizer("DPDigitizer", 0);
251  //digitizer->Verbosity(99);
252  digitizer->set_enable_st1dc(do_station1DC); // these two lines need to be in sync with the parameters used
253  digitizer->set_enable_dphodo(do_dphodo); // in the SetupSensitiveVolumes() function call above
254  se->registerSubsystem(digitizer);
255 
256  // Make SQ nodes for truth info
258 
259  // embedding
260  if(embedding_opt == 1) {
261  SRawEventEmbed *embed = new SRawEventEmbed("SRawEventEmbed");
262  embed->set_in_name("digit_016070_R007.root");
263  embed->set_in_tree_name("save");
264  embed->set_trigger_bit((1<<0));
265  //embed->set_in_name("random_run3a_1.root");
266  //embed->set_in_tree_name("mb");
267  //embed->set_trigger_bit((1<<7));
268  embed->Verbosity(0);
269  se->registerSubsystem(embed);
270  }
271 
272  // Trigger Emulator
273  DPTriggerAnalyzer* dptrigger = new DPTriggerAnalyzer();
274  dptrigger->set_road_set_file_name("$E1039_RESOURCE/trigger/trigger_67.txt");
275  se->registerSubsystem(dptrigger);
276 
277  // Event Filter
278  //EvtFilter *evt_filter = new EvtFilter();
279  //evt_filter->Verbosity(10);
280  //evt_filter->set_trigger_req(1<<5);
281  //se->registerSubsystem(evt_filter);
282 
283  // Tracking module
284  SQReco* reco = new SQReco();
285  reco->Verbosity(0);
286  //reco->set_geom_file_name("support/geom.root"); //not needed as it's created on the fly
287  reco->set_enable_KF(true); //Kalman filter not needed for the track finding, disabling KF saves a lot of initialization time
288  reco->setInputTy(SQReco::E1039); //options are SQReco::E906 and SQReco::E1039
289  reco->setFitterTy(SQReco::KFREF); //not relavant for the track finding
290  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"
291  reco->set_enable_eval(true); //set to true to generate evaluation file which includes final track candidates
292  reco->set_eval_file_name("eval.root");
293  reco->set_enable_eval_dst(false); //set to true to include final track cnadidates in the DST tree
294  if(gen_cosmic) reco->add_eval_list(3); //output of cosmic reco is contained in the eval output for now
295  //reco->add_eval_list(3); //include back partial tracks in eval tree for debuging
296  //reco->add_eval_list(2); //include station-3+/- in eval tree for debuging
297  //reco->add_eval_list(1); //include station-2 in eval tree for debugging
298  se->registerSubsystem(reco);
299 
300  VertexFit* vertexing = new VertexFit();
301  //vertexing->enable_fit_target_center(); //uncomment if you want to fit in the target center
302  //vertexing->enableOptimization(); //uncomment if you want to fit according to new optimization formula
303  se->registerSubsystem(vertexing);
304 
306  //se->registerSubsystem(new SimDstTrimmer());
307 
308  // input - we need a dummy to drive the event loop
309  if(read_hepmc) {
311  in->Verbosity(10);
312  in->set_vertex_distribution_mean(0,0,target_coil_pos_z,0);
313  se->registerInputManager(in);
314  in->fileopen("hepmcout.txt");
315  } else {
317  se->registerInputManager(in);
318  }
319 
321  // Output
323 
324  // DST output manager
325  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "DST.root");
326  se->registerOutputManager(out);
327 
328  //if(gen_pythia8 && !read_hepmc) {
329  // Fun4AllHepMCOutputManager *out = new Fun4AllHepMCOutputManager("HEPMCOUT", "hepmcout.txt");
330  // out->set_embedding_id(1);
331  // se->registerOutputManager(out);
332  //}
333 
334  se->run(nevent);
335 
336  PHGeomUtility::ExportGeomtry(se->topNode(),"geom.root");
337 
338  // finish job - close and save output files
339  se->End();
340  se->PrintTimer();
341  std::cout << "All done" << std::endl;
342 
343  // cleanup - delete the server and exit
344  delete se;
345  gSystem->Exit(0);
346  return 0;
347 }
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_in_tree_name(const std::string &inTreeName)
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
virtual int fileopen(const std::string &filenam)
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)
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.
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")
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
void set_xfRange(const double xmin, const double xmax)
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
void set_road_set_file_name(const std::string &roadSetFileName)
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 set_enable_st1dc(const bool en)
enable/disable certain detectors
Definition: SQDigitizer.h:55
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 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_massRange(const double mmin, const double mmax)
void set_in_name(const std::string &inName)
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
int Fun4Sim(const int nEvents=1)
Definition: Fun4Sim.C:6
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 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
virtual void set_vtx(const double x, const double y, const double z)
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
void set_enable_dphodo(const bool en)
Definition: SQDigitizer.h:56
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)
void set_embedding_id(int id)
Definition: PHPythia8.h:113
void registerSubsystem(PHG4Subsystem *subsystem)
register subsystem
Definition: PHG4Reco.h:65
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