Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4All_EventDisplay.C
Go to the documentation of this file.
1 
3  const int nEvents = 10,
4  const char * inputFile = "/sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/fieldmap/G4Hits_sPHENIX_e-_eta0_8GeV-0002.root",
5  const char * outputFile = "G4sPHENIXCells.root",
6  const char * embed_input_file = "/sphenix/sim/sim01/production/2016-07-12/sHijing/spacal2d/G4Hits_sPHENIX_sHijing-0-4.4fm.list"
7  )
8 {
9  //===============
10  // Input options
11  //===============
12 
13  // Either:
14  // read previously generated g4-hits files, in this case it opens a DST and skips
15  // the simulations step completely. The G4Setup macro is only loaded to get information
16  // about the number of layers used for the cell reco code
17  //
18  // In case reading production output, please double check your G4Setup_sPHENIX.C and G4_*.C consistent with those in the production macro folder
19  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
20  const bool readhits = false;
21  // Or:
22  // read files in HepMC format (typically output from event generators like hijing or pythia)
23  const bool readhepmc = false; // read HepMC files
24  // Or:
25  // Use particle generator
26  const bool runpythia8 = true;
27  const bool runpythia6 = false;
28  // And
29  // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
30  // In case embedding into a production output, please double check your G4Setup_sPHENIX.C and G4_*.C consistent with those in the production macro folder
31  // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
32  const bool do_embedding = false;
33 
34  //======================
35  // What to run
36  //======================
37 
38  bool do_bbc =true;
39  bool do_pipe = false;
40 
41  bool do_svtx = true;
42  bool do_svtx_cell = true;
43  bool do_svtx_track = true;
44  bool do_svtx_eval = true;
45 
46  bool do_preshower = false;
47 
48  bool do_cemc = true;
49  bool do_cemc_cell = true;
50  bool do_cemc_twr = true;
51  bool do_cemc_cluster = true;
52  bool do_cemc_eval = false;
53 
54  bool do_hcalin = true;
55  bool do_hcalin_cell = true;
56  bool do_hcalin_twr = true;
57  bool do_hcalin_cluster = true;
58  bool do_hcalin_eval = false;
59 
60  bool do_magnet = true;
61 
62  bool do_hcalout = true;
63  bool do_hcalout_cell = true;
64  bool do_hcalout_twr = true;
65  bool do_hcalout_cluster = true;
66  bool do_hcalout_eval = false;
67 
68  bool do_global = true;
69  bool do_global_fastsim = false;
70 
71  bool do_jet_reco = true;
72  bool do_jet_eval = false;
73 
74  bool do_dst_compress = false;
75 
76  //Option to convert DST to human command readable TTree for quick poke around the outputs
77  bool do_DSTReader = false;
78  //---------------
79  // Load libraries
80  //---------------
81 
82  gSystem->Load("libfun4all.so");
83  gSystem->Load("libphgeom.so");
84  gSystem->Load("libg4detectors.so");
85  gSystem->Load("libphhepmc.so");
86  gSystem->Load("libg4testbench.so");
87  gSystem->Load("libg4hough.so");
88  gSystem->Load("libcemc.so");
89  gSystem->Load("libg4eval.so");
90 
91  gSystem->ListLibraries();
92  // establish the geometry and reconstruction setup
93  gROOT->LoadMacro("G4Setup_sPHENIX.C");
94  G4Init(do_svtx,do_preshower,do_cemc,do_hcalin,do_magnet,do_hcalout,do_pipe);
95 
96  int absorberactive = 1; // set to 1 to make all absorbers active volumes
97  // const string magfield = "1.5"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
98  const string magfield = "/phenix/upgrades/decadal/fieldmaps/sPHENIX.2d.root"; // if like float -> solenoidal field in T, if string use as fieldmap name (including path)
99  const float magfield_rescale = 1.4/1.5; // scale the map to a 1.4 T field
100 
101  //---------------
102  // Fun4All server
103  //---------------
104 
106  se->Verbosity(2);
107  // just if we set some flags somewhere in this macro
109  // By default every random number generator uses
110  // PHRandomSeed() which reads /dev/urandom to get its seed
111  // if the RANDOMSEED flag is set its value is taken as seed
112  // You ca neither set this to a random value using PHRandomSeed()
113  // which will make all seeds identical (not sure what the point of
114  // this would be:
115  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
116  // or set it to a fixed value so you can debug your code
117  // rc->set_IntFlag("RANDOMSEED", 12345);
118 
119  //-----------------
120  // Event generation
121  //-----------------
122 
123  if (readhits)
124  {
125  // Get the hits from a file
126  // The input manager is declared later
127 
128  if (do_embedding)
129  {
130  cout <<"Do not support read hits and embed background at the same time."<<endl;
131  exit(1);
132  }
133 
134  }
135  else if (readhepmc)
136  {
137  // this module is needed to read the HepMC records into our G4 sims
138  // but only if you read HepMC input files
139  HepMCNodeReader *hr = new HepMCNodeReader();
140  se->registerSubsystem(hr);
141  }
142  else if (runpythia8)
143  {
144  gSystem->Load("/afs/rhic.bnl.gov/sphenix/sys/x8664_sl6/new.2/lib/libPHPythia8.so");
145 
146  PHPythia8* pythia8 = new PHPythia8();
147  // see coresoftware/generators/PHPythia8 for example config
148  pythia8->set_config_file("phpythia8.cfg");
149  se->registerSubsystem(pythia8);
150 
151  HepMCNodeReader *hr = new HepMCNodeReader();
152  se->registerSubsystem(hr);
153  }
154  else if (runpythia6)
155  {
156  gSystem->Load("libPHPythia6.so");
157 
158  PHPythia6 *pythia6 = new PHPythia6();
159  pythia6->set_config_file("phpythia6.cfg");
160  se->registerSubsystem(pythia6);
161 
162  HepMCNodeReader *hr = new HepMCNodeReader();
163  se->registerSubsystem(hr);
164  }
165  else
166  {
167  // toss low multiplicity dummy events
169  gen->add_particles("e-",1); // mu+,e+,proton,pi+,Upsilon
170  // gen->add_particles("e+",5); // mu-,e-,anti_proton,pi-
171  if (readhepmc || do_embedding) {
172  gen->set_reuse_existing_vertex(true);
173  gen->set_existing_vertex_offset_vector(0.0,0.0,0.0);
174  } else {
178  gen->set_vertex_distribution_mean(0.0,0.0,0.0);
179  gen->set_vertex_distribution_width(0.0,0.0,5.0);
180  }
182  gen->set_vertex_size_parameters(0.0,0.0);
183  gen->set_eta_range(-0.5, 0.5);
184  gen->set_phi_range(-1.0*TMath::Pi(), 1.0*TMath::Pi());
185  gen->set_pt_range(0.1, 10.0);
186  gen->Embed(1);
187  gen->Verbosity(0);
188  se->registerSubsystem(gen);
189  }
190 
191  if (!readhits)
192  {
193  //---------------------
194  // Detector description
195  //---------------------
196 
197  G4Setup(absorberactive, magfield, TPythia6Decayer::kAll,
198  do_svtx, do_preshower, do_cemc, do_hcalin, do_magnet, do_hcalout, do_pipe, magfield_rescale);
199  }
200 
201  //---------
202  // BBC Reco
203  //---------
204 
205  if (do_bbc)
206  {
207  gROOT->LoadMacro("G4_Bbc.C");
208  BbcInit();
209  Bbc_Reco();
210  }
211  //------------------
212  // Detector Division
213  //------------------
214 
215  if (do_svtx_cell) Svtx_Cells();
216 
217  if (do_cemc_cell) CEMC_Cells();
218 
219  if (do_hcalin_cell) HCALInner_Cells();
220 
221  if (do_hcalout_cell) HCALOuter_Cells();
222 
223  //-----------------------------
224  // CEMC towering and clustering
225  //-----------------------------
226 
227  if (do_cemc_twr) CEMC_Towers();
228  if (do_cemc_cluster) CEMC_Clusters();
229 
230  //-----------------------------
231  // HCAL towering and clustering
232  //-----------------------------
233 
234  if (do_hcalin_twr) HCALInner_Towers();
235  if (do_hcalin_cluster) HCALInner_Clusters();
236 
237  if (do_hcalout_twr) HCALOuter_Towers();
238  if (do_hcalout_cluster) HCALOuter_Clusters();
239 
240  if (do_dst_compress) ShowerCompress();
241 
242  //--------------
243  // SVTX tracking
244  //--------------
245 
246  if (do_svtx_track) Svtx_Reco();
247 
248  //-----------------
249  // Global Vertexing
250  //-----------------
251 
252  if (do_global)
253  {
254  gROOT->LoadMacro("G4_Global.C");
255  Global_Reco();
256  }
257 
258  else if (do_global_fastsim)
259  {
260  gROOT->LoadMacro("G4_Global.C");
261  Global_FastSim();
262  }
263 
264  //---------
265  // Jet reco
266  //---------
267 
268  if (do_jet_reco)
269  {
270  gROOT->LoadMacro("G4_Jets.C");
271  Jet_Reco();
272  }
273  //----------------------
274  // Simulation evaluation
275  //----------------------
276 
277  if (do_svtx_eval) Svtx_Eval("g4svtx_eval.root");
278 
279  if (do_cemc_eval) CEMC_Eval("g4cemc_eval.root");
280 
281  if (do_hcalin_eval) HCALInner_Eval("g4hcalin_eval.root");
282 
283  if (do_hcalout_eval) HCALOuter_Eval("g4hcalout_eval.root");
284 
285  if (do_jet_eval) Jet_Eval("g4jet_eval.root");
286 
287 
288 
289  //--------------
290  // IO management
291  //--------------
292 
293  if (readhits)
294  {
295  // Hits file
296  Fun4AllInputManager *hitsin = new Fun4AllDstInputManager("DSTin");
297  hitsin->fileopen(inputFile);
298  se->registerInputManager(hitsin);
299  }
300  if (do_embedding)
301  {
302  if (embed_input_file == NULL)
303  {
304  cout << "Missing embed_input_file! Exit";
305  exit(3);
306  }
307 
308  Fun4AllDstInputManager *in1 = new Fun4AllNoSyncDstInputManager("DSTinEmbed");
309  // in1->AddFile(embed_input_file); // if one use a single input file
310  in1->AddListFile(embed_input_file); // RecommendedL: if one use a text list of many input files
311  se->registerInputManager(in1);
312  }
313  if (readhepmc)
314  {
315  Fun4AllInputManager *in = new Fun4AllHepMCInputManager( "DSTIN");
316  se->registerInputManager( in );
317  se->fileopen( in->Name().c_str(), inputFile );
318  }
319  else
320  {
321  // for single particle generators we just need something which drives
322  // the event loop, the Dummy Input Mgr does just that
324  se->registerInputManager( in );
325  }
326 
327  if (do_DSTReader)
328  {
329  //Convert DST to human command readable TTree for quick poke around the outputs
330  gROOT->LoadMacro("G4_DSTReader.C");
331 
332  G4DSTreader( outputFile, //
333  /*int*/ absorberactive ,
334  /*bool*/ do_svtx ,
335  /*bool*/ do_preshower ,
336  /*bool*/ do_cemc ,
337  /*bool*/ do_hcalin ,
338  /*bool*/ do_magnet ,
339  /*bool*/ do_hcalout ,
340  /*bool*/ do_cemc_twr ,
341  /*bool*/ do_hcalin_twr ,
342  /*bool*/ do_magnet ,
343  /*bool*/ do_hcalout_twr
344  );
345  }
346 
347  // Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outputFile);
348  // if (do_dst_compress) DstCompress(out);
349  // se->registerOutputManager(out);
350 
351 
352  //-----------------
353  // Event processing
354  //-----------------
355  if (nEvents < 0)
356  {
357  return;
358  }
359  // if we run the particle generator and use 0 it'll run forever
360  if (nEvents == 0 && !readhits && !readhepmc)
361  {
362  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
363  cout << "it will run forever, so I just return without running anything" << endl;
364  return;
365  }
366 
367  //---------------
368  // Event display
369  //---------------
370 
371  gSystem->Exec("/bin/env");
372  gSystem->Load("libpheve.so");
373  gSystem->Load("libPHBFieldMap.so");
374  // width height use_fieldmap use_geofile field-map name geo-fiel name
375  PHEventDisplay* event_display
376  = new PHEventDisplay(1920,860, true, false, "sPHENIX.2d.root", "sphenix_maps+tpc_geo.root");
377  // location of geometry file : /gpfs/mnt/gpfs02/sphenix/user/shlee/svtx/stage1_jobs
378  event_display->set_jet_pt_threshold(10.);//GeV/c
379  event_display->set_jet_e_scale(30.);//GeV
380  event_display->set_calo_e_threshold(0.0009);//GeV
381  event_display->set_svtx_on(true);
382  event_display->set_cemc_on(true);
383  event_display->set_hcalin_on(false);
384  event_display->set_hcalout_on(false);
385  event_display->set_jet_on(false);
386  event_display->set_truth_on(false);
387  event_display->set_verbosity(2);
388 
389  se->registerSubsystem(event_display);
390  //event_display->start_rotation();
391  timer = new TTimer();
392  timer->Connect("Timeout()", "PHEventDisplay", event_display,"run_evt_in_thread()");
393  timer->Start(100000,kFALSE);
394 
395 }
int registerInputManager(Fun4AllInputManager *InManager)
void set_jet_e_scale(float e_scale)
void set_reuse_existing_vertex(const int i=1)
void add_particles(const std::string &name, const unsigned int count)
interface for adding particles by name
void set_verbosity(int verb)
int fileopen(const char *managername="NONE", const char *filename="NONE")
static Fun4AllServer * instance()
Fun4AllServer * se
void set_jet_pt_threshold(float pt)
static recoConsts * instance()
Definition: recoConsts.cc:7
#define NULL
Definition: Pdb.h:9
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
virtual const std::string Name() const
Returns the name of this module.
Definition: Fun4AllBase.h:23
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
int AddListFile(const std::string &filename, const int do_it=0)
void set_truth_on(bool truth_on)
int Fun4All_EventDisplay(const int nEvents=10, const char *inputFile="/sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/fieldmap/G4Hits_sPHENIX_e-_eta0_8GeV-0002.root", const char *outputFile="G4sPHENIXCells.root", const char *embed_input_file="/sphenix/sim/sim01/production/2016-07-12/sHijing/spacal2d/G4Hits_sPHENIX_sHijing-0-4.4fm.list")
void set_vertex_size_parameters(const double mean, const double width)
set the dimensions of the distribution of particles about the vertex
void set_calo_e_threshold(float e)
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
void set_existing_vertex_offset_vector(const double x, const double y, const double z)
set an offset vector from the existing vertex
virtual void Embed(const int i=1)
void set_eta_range(const double eta_min, const double eta_max)
range of randomized eta values
virtual int fileopen(const std::string &)
void set_pt_range(const double pt_min, const double pt_max, const double pt_gaus_width=0)
void set_phi_range(const double phi_min, const double phi_max)
range of randomized phi values