Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4All_HCalJetPhiShift.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4All_HCalJetPhiShift.C
1 #ifndef MACRO_FUN4ALLG4SPHENIX_C
2 #define MACRO_FUN4ALLG4SPHENIX_C
3 
4 #include <GlobalVariables.C>
5 
6 #include <DisplayOn.C>
7 #include <G4Setup_sPHENIX.C>
8 #include <G4_Bbc.C>
9 #include <G4_CaloTrigger.C>
10 #include <G4_Centrality.C>
11 #include <G4_DSTReader.C>
12 #include <G4_Global.C>
13 #include <G4_HIJetReco.C>
14 #include <G4_Input.C>
15 #include <G4_Jets.C>
16 #include <G4_KFParticle.C>
17 #include <G4_ParticleFlow.C>
18 #include <G4_Production.C>
19 #include <G4_TopoClusterReco.C>
20 
21 #include <G4_User.C>
22 #include <QA.C>
23 
24 #include <ffamodules/FlagHandler.h>
25 #include <ffamodules/HeadReco.h>
26 #include <ffamodules/SyncReco.h>
28 
31 #include <fun4all/Fun4AllServer.h>
32 
33 #include <phool/PHRandomSeed.h>
34 #include <phool/recoConsts.h>
35 
36 #include <hcaljetphishift/HCalJetPhiShift.h>
37 
38 R__LOAD_LIBRARY(libfun4all.so)
39 R__LOAD_LIBRARY(libffamodules.so)
40 R__LOAD_LIBRARY(libHCalJetPhiShift.so)
41 
42 // For HepMC Hijing
43 // try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
44 
46  const int nEvents = 1,
47  const int index = 0,
48  const string &outdir = ".")
49 {
50 
51  int event_number = (int)index*nEvents;
52 
53  // string outputFile = "HCalJetPhiShift"
54  string outputroot = outdir + "/HCalJetPhiShift";
55  if (index>-1) {
56  outputroot += "_" + to_string(index);
57  }
58 
59  string outputFile = outputroot + ".root";
60 
62  se->Verbosity(0);
63 
64  //Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
65 // PHRandomSeed::Verbosity(1);
66 
67  // just if we set some flags somewhere in this macro
69  // By default every random number generator uses
70  // PHRandomSeed() which reads /dev/urandom to get its seed
71  // if the RANDOMSEED flag is set its value is taken as seed
72  // You can either set this to a random value using PHRandomSeed()
73  // which will make all seeds identical (not sure what the point of
74  // this would be:
75  // rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
76  // or set it to a fixed value so you can debug your code
77  // rc->set_IntFlag("RANDOMSEED", 12345);
78 
79 
80  //===============
81  // Input options
82  //===============
83  // verbosity setting (applies to all input managers)
84  Input::VERBOSITY = 0;
85 
86  Input::SIMPLE = true;
87  // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
89 
90 
91  //-----------------
92  // Initialize the selected Input/Event generation
93  //-----------------
94  // This creates the input generator(s)
95  InputInit();
96 
97  //--------------
98  // Set generator specific options
99  //--------------
100  // can only be set after InputInit() is called
101 
102  // Simple Input generator:
103  // if you run more than one of these Input::SIMPLE_NUMBER > 1
104  // add the settings for other with [1], next with [2]...
105  if (Input::SIMPLE)
106  {
107  INPUTGENERATOR::SimpleEventGenerator[0]->add_particles("pi-", 1);
108  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_function(PHG4SimpleEventGenerator::Gaus,
111  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_mean(0., 0., 0.);
112  INPUTGENERATOR::SimpleEventGenerator[0]->set_vertex_distribution_width(0.0, 0.0, 0.0);
113  INPUTGENERATOR::SimpleEventGenerator[0]->set_eta_range(-1, 1);
114  INPUTGENERATOR::SimpleEventGenerator[0]->set_phi_range(-M_PI, M_PI);
115  INPUTGENERATOR::SimpleEventGenerator[0]->set_pt_range(1., 30.);
116  }
117 
118  //--------------
119  // Set Input Manager specific options
120  //--------------
121 
122  // register all input generators with Fun4All
123  InputRegister();
124 
125  rc->set_IntFlag("RUNNUMBER",1);
126 
127  SyncReco *sync = new SyncReco();
128  se->registerSubsystem(sync);
129 
130  HeadReco *head = new HeadReco();
131  se->registerSubsystem(head);
132 
133 // Flag Handler is always needed to read flags from input (if used)
134 // and update our rc flags with them. At the end it saves all flags
135 // again on the DST in the Flags node under the RUN node
136  FlagHandler *flag = new FlagHandler();
137  se->registerSubsystem(flag);
138 
139  //======================
140  // Write the DST
141  //======================
142 
143  //Enable::DSTOUT = true;
144  Enable::DSTOUT_COMPRESS = false;
145  DstOut::OutputDir = outdir;
146  DstOut::OutputFile = outputFile;
147 
148  //Option to convert DST to human command readable TTree for quick poke around the outputs
149  // Enable::DSTREADER = true;
150 
151  // turn the display on (default off)
152  //Enable::DISPLAY = true;
153 
154  //======================
155  // What to run
156  //======================
157 
158  // QA, main switch
159  Enable::QA = false;
160 
161  // Global options (enabled for all enables subsystems - if implemented)
162  // Enable::ABSORBER = true;
163  // Enable::OVERLAPCHECK = true;
164  // Enable::VERBOSITY = 1;
165 
166  // Enable::BBC = true;
167  // Enable::BBC_SUPPORT = true; // save hist in bbc support structure
168  // Enable::BBCRECO = Enable::BBC && true
169  Enable::BBCFAKE = false; // Smeared vtx and t0, use if you don't want real BBC in simulation
170 
171  Enable::PIPE = false;
172  Enable::PIPE_ABSORBER = false;
173 
174  // central tracking
175  Enable::MVTX = false;
179 
180  Enable::INTT = false;
181 // Enable::INTT_ABSORBER = true; // enables layerwise support structure readout
182 // Enable::INTT_SUPPORT = true; // enable global support structure readout
185  Enable::INTT_QA = Enable::INTT_CLUSTER && Enable::QA && true;
186 
187  Enable::TPC = false;
188  Enable::TPC_ABSORBER = false;
189  Enable::TPC_CELL = Enable::TPC && true;
191  Enable::TPC_QA = Enable::TPC_CLUSTER && Enable::QA && true;
192 
193  Enable::MICROMEGAS = false;
196  Enable::MICROMEGAS_QA = Enable::MICROMEGAS_CLUSTER && Enable::QA && true;
197 
200  Enable::TRACKING_QA = Enable::TRACKING_TRACK && Enable::QA && true;
201 
202  //G4CEMC::TowerDigi = RawTowerDigitizer::kNo_digitization;
203 
204  Enable::CEMC = true;
205  Enable::CEMC_ABSORBER = true;
206 
211  Enable::CEMC_QA = Enable::CEMC_CLUSTER && Enable::QA && true;
212 
213  Enable::HCALIN = true;
219  Enable::HCALIN_QA = Enable::HCALIN_CLUSTER && Enable::QA && true;
220 
221  Enable::MAGNET = false;
222  Enable::MAGNET_ABSORBER = false;
223 
224  Enable::HCALOUT = true;
230  Enable::HCALOUT_QA = Enable::HCALOUT_CLUSTER && Enable::QA && true;
231 
232  Enable::EPD = false;
233  Enable::EPD_TILE = Enable::EPD && true;
234 
235  Enable::BEAMLINE = false;
236 // Enable::BEAMLINE_ABSORBER = true; // makes the beam line magnets sensitive volumes
237 // Enable::BEAMLINE_BLACKHOLE = true; // turns the beamline magnets into black holes
238  Enable::ZDC = false;
239 // Enable::ZDC_ABSORBER = true;
240 // Enable::ZDC_SUPPORT = true;
241 // Enable::ZDC_TOWER = Enable::ZDC && true;
242 // Enable::ZDC_EVAL = Enable::ZDC_TOWER && true;
243 
245  //Enable::PLUGDOOR = true;
247 
248 // Enable::GLOBAL_RECO = (Enable::BBCFAKE || Enable::TRACKING_TRACK) && true;
249  //Enable::GLOBAL_FASTSIM = true;
250 
251  //Enable::KFPARTICLE = true;
252  //Enable::KFPARTICLE_VERBOSITY = 1;
253  //Enable::KFPARTICLE_TRUTH_MATCH = true;
254  //Enable::KFPARTICLE_SAVE_NTUPLE = true;
255 
257 
260  Enable::JETS_QA = Enable::JETS && Enable::QA && true;
261 
262  // HI Jet Reco for p+Au / Au+Au collisions (default is false for
263  // single particle / p+p-only simulations, or for p+Au / Au+Au
264  // simulations which don't particularly care about jets)
265  Enable::HIJETS = Enable::JETS && Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
266 
267  // 3-D topoCluster reconstruction, potentially in all calorimeter layers
268  Enable::TOPOCLUSTER = Enable::CEMC_TOWER && Enable::HCALIN_TOWER && Enable::HCALOUT_TOWER && false;
269  // particle flow jet reconstruction - needs topoClusters!
271  // centrality reconstruction
272  Enable::CENTRALITY = false;
273 
274  // new settings using Enable namespace in GlobalVariables.C
275  Enable::BLACKHOLE = false;
276  //Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
277  //Enable::BLACKHOLE_FORWARD_SAVEHITS = false; // disable forward/backward hits
278  //BlackHoleGeometry::visible = true;
279 
280  // run user provided code (from local G4_User.C)
281  //Enable::USER = true;
282 
283  //===============
284  // conditions DB flags
285  //===============
286  Enable::CDB = false;
287  // global tag
288  rc->set_StringFlag("CDB_GLOBALTAG",CDB::global_tag);
289  // 64 bit timestamp
290  rc->set_uint64Flag("TIMESTAMP",CDB::timestamp);
291  //---------------
292  // World Settings
293  //---------------
294  G4WORLD::PhysicsList = "FTFP_BERT"; //FTFP_BERT_HP best for calo
295  // G4WORLD::WorldMaterial = "G4_AIR"; // set to G4_GALACTIC for material scans
296 
297  //---------------
298  // Magnet Settings
299  //---------------
300 
301  //G4MAGNET::magfield = string(getenv("CALIBRATIONROOT"))+ string("/Field/Map/sphenix3dbigmapxyz.root"); // default map from the calibration database
302  G4MAGNET::magfield = "0."; // alternatively to specify a constant magnetic field, give a float number, which will be translated to solenoidal field in T, if string use as fieldmap name (including path)
303 // G4MAGNET::magfield_rescale = 1.; // make consistent with expected Babar field strength of 1.4T
304 
305  //---------------
306  // Pythia Decayer
307  //---------------
308  // list of decay types in
309  // $OFFLINE_MAIN/include/g4decayer/EDecayType.hh
310  // default is All:
311  // G4P6DECAYER::decayType = EDecayType::kAll;
312 
313  // Initialize the selected subsystems
314  G4Init();
315 
316  //---------------------
317  // GEANT4 Detector description
318  //---------------------
319  if (!Input::READHITS)
320  {
321  G4Setup();
322  }
323 
324  //------------------
325  // Detector Division
326  //------------------
327 
328 // if ((Enable::BBC && Enable::BBCRECO) || Enable::BBCFAKE) Bbc_Reco();
329 //
330 // if (Enable::MVTX_CELL) Mvtx_Cells();
331 // if (Enable::INTT_CELL) Intt_Cells();
332 // if (Enable::TPC_CELL) TPC_Cells();
333 // if (Enable::MICROMEGAS_CELL) Micromegas_Cells();
334 
336 
338 
340 
341  //-----------------------------
342  // CEMC towering and clustering
343  //-----------------------------
344 
347 
348  //--------------
349  // EPD tile reconstruction
350  //--------------
351 
352 // if (Enable::EPD_TILE) EPD_Tiles();
353 
354  //-----------------------------
355  // HCAL towering and clustering
356  //-----------------------------
357 
360 
361  if (Enable::HCALOUT_TOWER) HCALOuter_Towers();
363 
364  // if enabled, do topoClustering early, upstream of any possible jet reconstruction
365 // if (Enable::TOPOCLUSTER) TopoClusterReco();
366 
367  //--------------
368  // SVTX tracking
369  //--------------
370 // if(Enable::TRACKING_TRACK)
371 // {
372 // TrackingInit();
373 // }
374 // if (Enable::MVTX_CLUSTER) Mvtx_Clustering();
375 // if (Enable::INTT_CLUSTER) Intt_Clustering();
376 // if (Enable::TPC_CLUSTER)
377 // {
378 // if(G4TPC::ENABLE_DIRECT_LASER_HITS || G4TPC::ENABLE_CENTRAL_MEMBRANE_HITS)
379 // {
380 // TPC_LaserClustering();
381 // }
382 // else
383 // {
384 // TPC_Clustering();
385 // }
386 // }
387 // if (Enable::MICROMEGAS_CLUSTER) Micromegas_Clustering();
388 //
389 // if (Enable::TRACKING_TRACK)
390 // {
391 // Tracking_Reco();
392 // }
393 //
394 // if(Enable::TRACKING_DIAGNOSTICS)
395 // {
396 // const std::string kshortFile = "./kshort_" + outputFile;
397 // const std::string residualsFile = "./residuals_" + outputFile;
398 //
399 // G4KshortReconstruction(kshortFile);
400 // seedResiduals(residualsFile);
401 // }
402 
403  //-----------------
404  // Global Vertexing
405  //-----------------
406 
407 // if (Enable::GLOBAL_RECO && Enable::GLOBAL_FASTSIM)
408 // {
409 // cout << "You can only enable Enable::GLOBAL_RECO or Enable::GLOBAL_FASTSIM, not both" << endl;
410 // gSystem->Exit(1);
411 // }
412 // if (Enable::GLOBAL_RECO)
413 // {
414 // Global_Reco();
415 // }
416 // else if (Enable::GLOBAL_FASTSIM)
417 // {
418 // Global_FastSim();
419 // }
420 
421  //-----------------
422  // Centrality Determination
423  //-----------------
424 
425  if (Enable::CENTRALITY)
426  {
427  Centrality();
428  }
429 
430  //-----------------
431  // Calo Trigger Simulation
432  //-----------------
433 
435  {
436  CaloTrigger_Sim();
437  }
438 
439  //---------
440  // Jet reco
441  //---------
442 
443 // if (Enable::JETS) Jet_Reco();
444 // if (Enable::HIJETS) HIJetReco();
445 //
446 // if (Enable::PARTICLEFLOW) ParticleFlow();
447 
448  //----------------------
449  // Simulation evaluation
450  //----------------------
451 // string outputroot = outputFile;
452 // string remove_this = ".root";
453 // size_t pos = outputroot.find(remove_this);
454 // if (pos != string::npos)
455 // {
456 // outputroot.erase(pos, remove_this.length());
457 // }
458 // int start_event = (int) index*10;
459 // if (Enable::HCALOUT_EVAL) HCALOuter_Eval(outputroot + "_g4hcalout_eval.root", start_event);
460 // if (Enable::HCALIN_EVAL) HCALInner_Eval(outputroot + "_g4hcalin_eval.root", start_event);
461 
462  //--------------
463  // Set up Input Managers
464  //--------------
465 
466  InputManagers();
467 
468  if (Enable::PRODUCTION)
469  {
471  }
472 
473  if (Enable::DSTOUT)
474  {
475  string FullOutFile = DstOut::OutputDir + "/" + DstOut::OutputFile;
476  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", FullOutFile);
478  {
479  ShowerCompress();
480  DstCompress(out);
481  }
482  se->registerOutputManager(out);
483  }
484  //-----------------
485  // Event processing
486  //-----------------
487 
488  // if we use a negative number of events we go back to the command line here
489  if (nEvents < 0)
490  {
491  return 0;
492  }
493  // if we run the particle generator and use 0 it'll run forever
494  // for embedding it runs forever if the repeat flag is set
495  if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
496  {
497  cout << "using 0 for number of events is a bad idea when using particle generators" << endl;
498  cout << "it will run forever, so I just return without running anything" << endl;
499  return 0;
500  }
501 
502  RawTowerCalibration *TowerCalibration = new RawTowerCalibration("EmcRawTowerCalibration");
503  TowerCalibration->Detector("CEMC");
505  TowerCalibration->set_calib_const_GeV_ADC(1. / 0.023);
506  TowerCalibration->set_pedstal_ADC(0);
507  se->registerSubsystem(TowerCalibration);
508 
509  HCalJetPhiShift *caloPhiShift = new HCalJetPhiShift("caloPhiShift",outputFile);
510  caloPhiShift->SetEventNumber(event_number);
511  se->registerSubsystem(caloPhiShift);
512  se->run(nEvents);
513 
514  //-----
515  // QA output
516  //-----
517 
518  if (Enable::QA) QA_Output(outputroot + "_qa.root");
519 
520  //-----
521  // Exit
522  //-----
523 
524 // CDBInterface::instance()->Print(); // print used DB files
525  se->End();
526  std::cout << "All done" << std::endl;
527  delete se;
528 
529  gSystem->Exit(0);
530  return 0;
531 }
532 #endif
533 
534 // initial val setter in evaluator, set ievent --> call function to set ievent in macro
535 // then modify g4 macro or put line in my macro