Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventDisplay4Sim.C
Go to the documentation of this file.
2 #include "G4_SensitiveDetectors.C"
3 #include "G4_Beamline.C"
4 #include "G4_Target.C"
5 R__LOAD_LIBRARY(libfun4all)
6 R__LOAD_LIBRARY(libPHPythia8)
7 R__LOAD_LIBRARY(libg4detectors)
8 R__LOAD_LIBRARY(libg4testbench)
9 R__LOAD_LIBRARY(libg4eval)
10 R__LOAD_LIBRARY(libg4dst)
11 R__LOAD_LIBRARY(libdptrigger)
12 R__LOAD_LIBRARY(libembedding)
13 R__LOAD_LIBRARY(libevt_filter)
14 R__LOAD_LIBRARY(libktracker)
15 R__LOAD_LIBRARY(libSQPrimaryGen)
16 R__LOAD_LIBRARY(libpheve_display)
17 R__LOAD_LIBRARY(libpheve_modules)
18 R__LOAD_LIBRARY(libpheve_interface)
19 using namespace std;
20 
23 TGLViewer* view;
24 TGNumberEntry* ne_evt_id;
25 TGNumberEntry* ne_trig;
26 
27 class EvNavHandler
28 {
29  public:
30  void NextEvent()
31  {
32  printf("se->run(1)\n");
33  se->run(1, true);
34  }
35  void ReqEvtID() {
36  printf("ReqEvtID: %ld\n",ne_evt_id->GetNumberEntry()->GetIntNumber());
37  evt_filter->set_event_id_req((int)(ne_evt_id->GetNumberEntry()->GetIntNumber()));
38  }
39  void ReqTrig() {
40  printf("ReqTrig: %ld\n",ne_trig->GetNumberEntry()->GetIntNumber());
41  evt_filter->set_trigger_req((int)(ne_trig->GetNumberEntry()->GetIntNumber()));
42  }
43  void TopView()
44  {
45  printf("Top View\n");
46  view->ResetCurrentCamera();
47  view->CurrentCamera().RotateRad(-3.14/2.0, 0);
48  view->CurrentCamera().Zoom(400, 0, 0);
49  view->CurrentCamera().Truck(2800,0);
50  view->DoDraw();
51  }
52  void SideView()
53  {
54  printf("Side View\n");
55  view->ResetCurrentCamera();
56  view->CurrentCamera().Zoom(400, 0, 0);
57  view->CurrentCamera().Truck(2800,0);
58  view->DoDraw();
59  }
60  void View3D()
61  {
62  printf("3D View\n");
63  view->ResetCurrentCamera();
64  view->CurrentCamera().RotateRad(-3.14/4., -3.14/4.);
65  view->CurrentCamera().Zoom(350, 0, 0);
66  view->CurrentCamera().Truck(2000,-1500);
67  view->DoDraw();
68  }
69 
70 };
71 
73 //
74 // Main Function
75 //
76 int EventDisplay4Sim(const int nevent = 10)
77 {
78  const double target_coil_pos_z = -300;
79  const int nmu = 1;
80 
81  const bool do_collimator = true;
82  const bool do_target = true;
83  const bool do_e1039_shielding = true;
84  const bool do_fmag = true;
85  const bool do_kmag = true;
86  const bool do_absorber = true;
87 
88  const double target_l = 7.9; //cm
89  const double target_z = (7.9-target_l)/2.; //cm
90  const int use_g4steps = 1;
91 
92  const double FMAGSTR = -1.054;
93  const double KMAGSTR = -0.951;
94 
95  const bool gen_pythia8 = true;
96  const bool gen_gun = false;
97  const bool gen_particle = false;
98  const bool read_hepmc = false;
99  const bool gen_e906legacy = false;
100 
102  rc->set_DoubleFlag("FMAGSTR", FMAGSTR);
103  rc->set_DoubleFlag("KMAGSTR", KMAGSTR);
104  rc->Print();
105 
106  JobOptsSvc *jobopt_svc = JobOptsSvc::instance();
107  jobopt_svc->init("run7_sim.opts");
108 
109  GeomSvc::UseDbSvc(true);
110  GeomSvc *geom_svc = GeomSvc::instance();
111 
113  // Make the Server
116  se->Verbosity(0);
117 
118  // pythia8
119  if(gen_pythia8) {
120  PHPythia8 *pythia8 = new PHPythia8();
121  //pythia8->Verbosity(99);
122  pythia8->set_config_file("phpythia8_DY.cfg");
123  pythia8->set_vertex_distribution_mean(0, 0, target_coil_pos_z, 0);
124  pythia8->set_embedding_id(1);
125  se->registerSubsystem(pythia8);
126 
127  pythia8->set_trigger_AND();
128 
129  PHPy8ParticleTrigger* trigger_mup = new PHPy8ParticleTrigger();
130  trigger_mup->AddParticles("-13");
131  trigger_mup->SetPzHighLow(120, 10);
132  pythia8->register_trigger(trigger_mup);
133 
134  PHPy8ParticleTrigger* trigger_mum = new PHPy8ParticleTrigger();
135  trigger_mum->AddParticles("13");
136  trigger_mum->SetPzHighLow(120, 10);
137  pythia8->register_trigger(trigger_mum);
138  }
139 
140  if(gen_pythia8 || read_hepmc) {
141  HepMCNodeReader *hr = new HepMCNodeReader();
142  hr->set_particle_filter_on(true);
145  se->registerSubsystem(hr);
146  }
147 
148  // single gun
149  if(gen_gun) {
150  PHG4ParticleGun *gun = new PHG4ParticleGun("GUN");
151  gun->set_name("mu-");
152  gun->set_vtx(30, 10, 590);
153  gun->set_mom(-0.3, 2, 50);
154  se->registerSubsystem(gun);
155  }
156 
157  // multi particle gun
158  if(gen_particle) {
160  //genp->set_seed(123);
161  genp->add_particles("mu+", nmu); // mu+,e+,proton,pi+,Upsilon
165  genp->set_vertex_distribution_mean(0.0, 0.0, target_coil_pos_z);
166  genp->set_vertex_distribution_width(0.0, 0.0, 0.0);
168  genp->set_vertex_size_parameters(0.0, 0.0);
169 
170  if(FMAGSTR>0)
171  //genp->set_pxpypz_range(0,6, -6,6, 10,100);
172  genp->set_pxpypz_range(-3,6, -3,3, 10,100);
173  else
174  //genp->set_pxpypz_range(-6,0, -6,6, 10,100);
175  genp->set_pxpypz_range(-6,3, -3,3, 10,100);
176 
177 
178  genp->Verbosity(0);
179  se->registerSubsystem(genp);
180  }
181 
182  if(gen_particle) {
184  //genm->set_seed(123);
185  genm->add_particles("mu-", nmu); // mu+,e+,proton,pi+,Upsilon
189  genm->set_vertex_distribution_mean(0.0, 0.0, target_coil_pos_z);
190  genm->set_vertex_distribution_width(0.0, 0.0, 0.0);
192  genm->set_vertex_size_parameters(0.0, 0.0);
193 
194  if(FMAGSTR>0)
195  //genm->set_pxpypz_range(-6,0, -6,6, 10,100);
196  genm->set_pxpypz_range(-6,3, -3,3, 10,100);
197  else
198  //genm->set_pxpypz_range(0,6, -6,6, 10,100);
199  genm->set_pxpypz_range(-3,6, -3,3, 10,100);
200 
201  genm->Verbosity(0);
202  se->registerSubsystem(genm);
203  }
204 
205  // E906LegacyGen
206  //@
207  if(gen_e906legacy){
208  SQPrimaryParticleGen *e906legacy = new SQPrimaryParticleGen();
209  const bool pythia_gen = false;
210  const bool drellyan_gen = true;
211  const bool JPsi_gen = false;
212  const bool Psip_gen = false;
213  if(drellyan_gen){
214  e906legacy->set_xfRange(0.1, 0.5); //[-1.,1.]
215  e906legacy->set_massRange(0.23, 10.0);// 0.22 and above
216  e906legacy->enableDrellYanGen();
217  }
218  if(Psip_gen){
219  e906legacy->set_xfRange(0.1, 0.5); //[-1.,1.]
220  e906legacy->enablePsipGen();
221  }
222  if(JPsi_gen){
223  e906legacy->set_xfRange(0.1, 0.5); //[-1.,1.]
224  e906legacy->enableJPsiGen();
225  }
226  if(pythia_gen) e906legacy->enablePythia();
227  se->registerSubsystem(e906legacy);
228  }
229  //@
230 
231  // Fun4All G4 module
232  PHG4Reco *g4Reco = new PHG4Reco();
233  //PHG4Reco::G4Seed(123);
234  //g4Reco->set_field(5.);
235  g4Reco->set_field_map(
236  jobopt_svc->m_fMagFile+" "+
237  jobopt_svc->m_kMagFile+" "+
238  Form("%f",FMAGSTR) + " " +
239  Form("%f",KMAGSTR) + " " +
240  "5.0",
242  // size of the world - every detector has to fit in here
243  g4Reco->SetWorldSizeX(1000);
244  g4Reco->SetWorldSizeY(1000);
245  g4Reco->SetWorldSizeZ(5000);
246  // shape of our world - it is a tube
247  g4Reco->SetWorldShape("G4BOX");
248  // this is what our world is filled with
249  g4Reco->SetWorldMaterial("G4_AIR"); //G4_Galactic, G4_AIR
250  // Geant4 Physics list to use
251  g4Reco->SetPhysicsList("FTFP_BERT");
252 
253  // insensitive elements of the spectrometer
254  SetupInsensitiveVolumes(g4Reco, do_e1039_shielding, do_fmag, do_kmag, do_absorber);
255 
256  // collimator, targer and shielding between target and FMag
257  SetupBeamline(g4Reco, do_collimator, target_coil_pos_z - 302.36); // Is the position correct??
258 
259  if (do_target) {
260  SetupTarget(g4Reco, target_coil_pos_z, target_l, target_z, use_g4steps);
261  }
262 
263  // sensitive elements of the spectrometer
264  SetupSensitiveDetectors(g4Reco, 0);
265 
266  se->registerSubsystem(g4Reco);
267 
268  // save truth info to the Node Tree
269  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
270  g4Reco->registerSubsystem(truth);
271 
272  // Make SQ nodes for truth info
274 
275  // digitizer
276  DPDigitizer *digitizer = new DPDigitizer("DPDigitizer", 0);
277  //digitizer->Verbosity(99);
278  se->registerSubsystem(digitizer);
279 
280  // Trigger Emulator
281  DPTriggerAnalyzer* dptrigger = new DPTriggerAnalyzer();
282  dptrigger->set_road_set_file_name("$E1039_RESOURCE/trigger/trigger_67.txt");
283  //dptrigger->Verbosity(99);
284  se->registerSubsystem(dptrigger);
285 
286  // Event Filter
287  evt_filter = new EvtFilter();
288  //evt_filter->Verbosity(10);
289  //evt_filter->set_trigger_req(1<<5);
291 
292  // trakcing module
293  KalmanFastTrackingWrapper *ktracker = new KalmanFastTrackingWrapper();
294  //ktracker->Verbosity(99);
295  ktracker->set_enable_event_reducer(true);
296  ktracker->set_DS_level(0);
297  ktracker->set_pattern_db_name(gSystem->ExpandPathName("$E1039_RESOURCE/dsearch/v1/pattern.root"));
298  //ktracker->set_sim_db_name(gSystem->ExpandPathName("$E1039_RESOURCE/dsearch/v1/sim.root"));
299  //PatternDBUtil::ResScaleDC3(3);
300  //PatternDBUtil::LooseMode(false);
301  se->registerSubsystem(ktracker);
302 
303  VertexFit* vertexing = new VertexFit();
304  se->registerSubsystem(vertexing);
305 
306  // Event display
307  // (width, height, use_fieldmap, use_geofile, field-map name, geo-file name)
308  PHEventDisplay* disp = new PHEventDisplay(1920, 1080, false, false, "", "geom.root");
309  disp->set_verbosity(3);
310  se->registerSubsystem(disp);
311 
312  // input - we need a dummy to drive the event loop
313  if(read_hepmc) {
315  in->Verbosity(10);
316  in->set_vertex_distribution_mean(0,0,target_coil_pos_z,0);
318  in->fileopen("hepmcout.txt");
319  } else {
322  }
323 
324  //
325  // Make GUI
326  //
327  g4Reco->InitRun(se->topNode());
328  disp ->InitRun(se->topNode());
329  view = gEve->GetDefaultGLViewer();
330 
331  TEveBrowser* browser = gEve->GetBrowser();
332  browser->StartEmbedding(TRootBrowser::kLeft);
333 
334  TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
335  frmMain->SetWindowName("Event Display");
336  frmMain->SetCleanup(kDeepCleanup);
337 
338  TGVerticalFrame* frmVert = new TGVerticalFrame(frmMain);
339  {
340 
341  TGTextButton* b = 0;
342  EvNavHandler* handler = new EvNavHandler;
343  TGHorizontalFrame* frm1 = 0;
344 
345  TGLabel* lab = 0;
346 
347  frm1 = new TGHorizontalFrame(frmVert);
348  lab = new TGLabel(frm1, "Event ID");
349  frm1->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 3, 4));
350  ne_evt_id = new TGNumberEntry(frm1, -1, 9, 999, TGNumberFormat::kNESInteger,
351  TGNumberFormat::kNEAAnyNumber,
352  TGNumberFormat::kNELLimitMinMax,
353  -999999, 999999);
354  ne_evt_id->Connect("ValueSet(Long_t)", "EvNavHandler", handler, "ReqEvtID()");
355  frm1->AddFrame(ne_evt_id, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 5, 5, 5, 5));
356  frmVert->AddFrame(frm1);
357 
358 
359  frm1 = new TGHorizontalFrame(frmVert);
360  lab = new TGLabel(frm1, "Trigger");
361  frm1->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 3, 4));
362  ne_trig = new TGNumberEntry(frm1, -1, 9, 999, TGNumberFormat::kNESInteger,
363  TGNumberFormat::kNEAAnyNumber,
364  TGNumberFormat::kNELLimitMinMax,
365  -999, 999);
366  ne_trig->Connect("ValueSet(Long_t)", "EvNavHandler", handler, "ReqTrig()");
367  frm1->AddFrame(ne_trig, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 5, 5, 5, 5));
368  frmVert->AddFrame(frm1);
369 
370 
371  b = new TGTextButton(frmVert, "Next Event");
372  frmVert->AddFrame(b, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
373  b->Connect("Clicked()", "EvNavHandler", handler, "NextEvent()");
374 
375  b = new TGTextButton(frmVert, "Top View");
376  frmVert->AddFrame(b, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
377  b->Connect("Clicked()", "EvNavHandler", handler, "TopView()");
378 
379  b = new TGTextButton(frmVert, "Side View");
380  frmVert->AddFrame(b, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
381  b->Connect("Clicked()", "EvNavHandler", handler, "SideView()");
382 
383  b = new TGTextButton(frmVert, "3D View");
384  frmVert->AddFrame(b, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
385  b->Connect("Clicked()", "EvNavHandler", handler, "View3D()");
386 
387  }
388  frmMain->AddFrame(frmVert);
389 
390  frmMain->MapSubwindows();
391  frmMain->Resize();
392  frmMain->MapWindow();
393 
394  browser->StopEmbedding();
395  browser->SetTabTitle("Event Control", 0);
396 
397  return 0;
398 }
int registerInputManager(Fun4AllInputManager *InManager)
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 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)
int InitRun(PHCompositeNode *topNode)
Run initialization.
void SetWorldMaterial(const std::string &s)
Definition: PHG4Reco.h:118
SQDigitizer DPDigitizer
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_verbosity(int verb)
void set_particle_filter_on(const bool a)
TGNumberEntry * ne_trig
static Fun4AllServer * instance()
Fun4AllServer * se
int EventDisplay4Sim(const int nevent=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")
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_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_vertex_distribution_mean(const double x, const double y, const double z)
set the mean value of the vertex distribution
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)
EvtFilter * evt_filter
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
TGLViewer * view
void set_event_id_req(int eventIdReq)
Definition: EvtFilter.h:54
PHCompositeNode * topNode() const
Definition: Fun4AllServer.h:59
TGNumberEntry * ne_evt_id
void set_trigger_req(unsigned short triggerReq)
Definition: EvtFilter.h:46
void SetWorldSizeX(const double sx)
Definition: PHG4Reco.h:111
int InitRun(PHCompositeNode *topNode)
Definition: PHG4Reco.cc:320
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
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
virtual void set_name(const std::string &particle="proton")
virtual void set_mom(const double x, const double y, const double z)
void set_embedding_id(int id)
Definition: PHPythia8.h:113
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