Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4_HcalIn_ref.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4_HcalIn_ref.C
1 // Inner HCal reconstruction macro
2 #ifndef MACRO_G4HCALINREF_C
3 #define MACRO_G4HCALINREF_C
4 
5 #include <GlobalVariables.C>
6 #include <QA.C>
7 
10 
12 
16 
17 #include <g4eval/CaloEvaluator.h>
18 
19 #include <g4main/PHG4Reco.h>
20 
21 #include <caloreco/RawClusterBuilderGraph.h>
22 #include <caloreco/RawClusterBuilderTemplate.h>
23 #include <caloreco/RawTowerCalibration.h>
24 
25 #include <qa_modules/QAG4SimulationCalorimeter.h>
26 
27 #include <fun4all/Fun4AllServer.h>
28 
29 R__LOAD_LIBRARY(libcalo_reco.so)
30 R__LOAD_LIBRARY(libg4calo.so)
31 R__LOAD_LIBRARY(libg4detectors.so)
32 R__LOAD_LIBRARY(libg4eval.so)
33 R__LOAD_LIBRARY(libg4ihcal.so)
34 R__LOAD_LIBRARY(libqa_modules.so)
35 
36 namespace Enable
37 {
38  bool HCALIN = false;
39  bool HCALIN_ABSORBER = false;
40  bool HCALIN_OVERLAPCHECK = false;
41  bool HCALIN_CELL = false;
42  bool HCALIN_TOWER = false;
43  bool HCALIN_CLUSTER = false;
44  bool HCALIN_EVAL = false;
45  bool HCALIN_QA = false;
46  bool HCALIN_SUPPORT = false;
47  bool HCALIN_OLD = false;
48  bool HCALIN_G4Hit = true;
49  int HCALIN_VERBOSITY = 0;
50 } // namespace Enable
51 
52 namespace G4HCALIN
53 {
54  double inch = 2.54;
55  double support_ring_outer_radius = 177.323;
56  double support_ring_z = 175.375 * inch / 2;
57  double dz = 4. * inch;
58 
59  double phistart = NAN;
60  double tower_emin = NAN;
63 
64  // Inner HCal absorber material selector:
65  // false - old version, absorber material is SS310
66  // true - default Choose if you want Aluminum
67  bool inner_hcal_material_Al = true;
68 
69  int inner_hcal_eic = 0;
70 
71  // Digitization (default photon digi):
73  // directly pass the energy of sim tower to digitized tower
74  // kNo_digitization
75  // simple digitization with photon statistics, single amplitude ADC conversion and pedestal
76  // kSimple_photon_digitization
77  // digitization with photon statistics on SiPM with an effective pixel N, ADC conversion and pedestal
78  // kSiPM_photon_digitization
79 
81  {
83 
85  };
86 
90  // enu_HCalIn_clusterizer HCalIn_clusterizer = kHCalInGraphClusterizer;
91 } // namespace G4HCALIN
92 
93 // Init is called by G4Setup.C
94 void HCalInnerInit(const int iflag = 0)
95 {
99  if (iflag == 1)
100  {
102  }
103 }
104 
105 double HCalInner(PHG4Reco *g4Reco,
106  double radius,
107  const int crossings)
108 {
109  bool AbsorberActive = Enable::ABSORBER || Enable::HCALIN_ABSORBER;
110  bool OverlapCheck = Enable::OVERLAPCHECK || Enable::HCALIN_OVERLAPCHECK;
112 
114  // Mephi Maps
115  // Maps are different for old/new but how to set is identical
116  // here are the ones for the gdml based inner hcal
117  // use hcal->set_string_param("MapFileName",""); to disable map
118  // hcal->set_string_param("MapFileName",std::string(getenv("CALIBRATIONROOT")) + "/HCALIN/tilemap/ihcalgdmlmap09212022.root");
119  // hcal->set_string_param("MapHistoName","ihcalcombinedgdmlnormtbyt");
120  // use hcal->set_string_param("MapFileName",""); to disable map
121  // hcal->set_string_param("MapFileName",std::string(getenv("CALIBRATIONROOT")) + "/HCALIN/tilemap/ihcalgdmlmap09212022.root");
122  // hcal->set_string_param("MapHistoName","ihcalcombinedgdmlnormtbyt");
123 
124  // all sizes are in cm!
125  if (Enable::HCALIN_OLD)
126  {
127  hcal = new PHG4InnerHcalSubsystem("HCALIN");
128  // these are the parameters you can change with their default settings
129  // hcal->set_string_param("material","SS310");
131  {
132  if (verbosity > 0)
133  {
134  cout << "HCalInner - construct inner HCal absorber with G4_Al" << endl;
135  }
136  hcal->set_string_param("material", "G4_Al");
137  }
138  else
139  {
140  if (verbosity > 0)
141  {
142  cout << "HCalInner - construct inner HCal absorber with SS310" << endl;
143  }
144  hcal->set_string_param("material", "SS310");
145  }
146  // hcal->set_double_param("inner_radius", 117.27);
147  //-----------------------------------------
148  // the light correction can be set in a single call
149  // hcal->set_double_param("light_balance_inner_corr", NAN);
150  // hcal->set_double_param("light_balance_inner_radius", NAN);
151  // hcal->set_double_param("light_balance_outer_corr", NAN);
152  // hcal->set_double_param("light_balance_outer_radius", NAN);
153  // hcal->SetLightCorrection(NAN,NAN,NAN,NAN);
154  //-----------------------------------------
155  // hcal->set_double_param("outer_radius", 134.42);
156  // hcal->set_double_param("place_x", 0.);
157  // hcal->set_double_param("place_y", 0.);
158  // hcal->set_double_param("place_z", 0.);
159  // hcal->set_double_param("rot_x", 0.);
160  // hcal->set_double_param("rot_y", 0.);
161  // hcal->set_double_param("rot_z", 0.);
162  // hcal->set_double_param("scinti_eta_coverage", 1.1);
163  // hcal->set_double_param("scinti_gap_neighbor", 0.1);
164  // hcal->set_double_param("scinti_inner_gap", 0.85);
165  // hcal->set_double_param("scinti_outer_gap", 1.22 * (5.0 / 4.0));
166  // hcal->set_double_param("scinti_outer_radius", 133.3);
167  // hcal->set_double_param("scinti_tile_thickness", 0.7);
168  // hcal->set_double_param("size_z", 175.94 * 2);
169  // hcal->set_double_param("steplimits", NAN);
170  // hcal->set_double_param("tilt_angle", 36.15);
171 
172  // hcal->set_int_param("light_scint_model", 1);
173  // hcal->set_int_param("ncross", 0);
174  // hcal->set_int_param("n_towers", 64);
175  // hcal->set_int_param("n_scinti_plates_per_tower", 4);
176  // hcal->set_int_param("n_scinti_tiles", 12);
177 
178  // hcal->set_string_param("material", "SS310");
179  }
180  else
181  {
182  hcal = new PHG4IHCalSubsystem("HCALIN");
183  // std::string hcaltiles = "/sphenix/u/shuhang98/calibrations/InnerHCalAbsorberTiles_merged.gdml";
184  std::string hcaltiles = std::string(getenv("CALIBRATIONROOT")) + "/HcalGeo/InnerHCalAbsorberTiles_merged.gdml";
185  hcal->set_string_param("GDMPath", hcaltiles);
186  }
188  {
189  hcal->set_int_param("light_scint_model", G4HCALIN::light_scint_model);
190  }
191  hcal->SetActive();
192  hcal->SuperDetector("HCALIN");
193  if (AbsorberActive)
194  {
195  hcal->SetAbsorberActive();
196  }
197  if (!isfinite(G4HCALIN::phistart))
198  {
199  if (Enable::HCALIN_OLD)
200  {
201  G4HCALIN::phistart = 0.0328877688; // offet in phi (from zero) extracted from geantinos
202  }
203  else
204  {
205  G4HCALIN::phistart = 0.0445549893; // offet in phi (from zero) extracted from geantinos
206  }
207  }
208  hcal->set_int_param("saveg4hit", Enable::HCALIN_G4Hit);
209  hcal->set_double_param("phistart", G4HCALIN::phistart);
210  hcal->OverlapCheck(OverlapCheck);
211 
212  g4Reco->registerSubsystem(hcal);
213 
214  radius = hcal->get_double_param("outer_radius");
215 
216  // HCalInner_SupportRing(g4Reco);
217 
218  radius += no_overlapp;
219  return radius;
220 }
221 
223 {
224  if (!Enable::HCALIN_G4Hit) return;
226 
228 
229  PHG4HcalCellReco *hc = new PHG4HcalCellReco("HCALIN_CELLRECO");
230  hc->Detector("HCALIN");
231  hc->Verbosity(verbosity);
232  // check for energy conservation - needs modified "infinite" timing cuts
233  // 0-999999999
234  // hc->checkenergy();
235  // timing cuts with their default settings
236  // hc->set_double_param("tmin",0.);
237  // hc->set_double_param("tmax",60.0);
238  // or all at once:
239  // hc->set_timing_window(0.0,60.0);
240  // this sets all cells to a fixed energy for debugging
241  // hc->set_fixed_energy(1.);
242  se->registerSubsystem(hc);
243 
244  return;
245 }
246 
248 {
252  {
253  HcalRawTowerBuilder *TowerBuilder = new HcalRawTowerBuilder("HcalInRawTowerBuilder");
254  TowerBuilder->Detector("HCALIN");
255  TowerBuilder->set_sim_tower_node_prefix("SIM");
256  if (!isfinite(G4HCALIN::phistart))
257  {
258  if (Enable::HCALIN_OLD)
259  {
260  G4HCALIN::phistart = 0.0328877688; // offet in phi (from zero) extracted from geantinos
261  }
262  else
263  {
264  G4HCALIN::phistart = 0.0445549893; // offet in phi (from zero) extracted from geantinos
265  }
266  }
267  TowerBuilder->set_double_param("phistart", G4HCALIN::phistart);
268  if (isfinite(G4HCALIN::tower_emin))
269  {
270  TowerBuilder->set_double_param("emin", G4HCALIN::tower_emin);
271  }
273  {
274  TowerBuilder->set_int_param("tower_energy_source", G4HCALIN::tower_energy_source);
275  }
276  // this sets specific decalibration factors
277  // for a given cell
278  // TowerBuilder->set_cell_decal_factor(1,10,0.1);
279  // for a whole tower
280  // TowerBuilder->set_tower_decal_factor(0,10,0.2);
281  TowerBuilder->Verbosity(verbosity);
282  se->registerSubsystem(TowerBuilder);
283  }
284  // From 2016 Test beam sim
285  RawTowerDigitizer *TowerDigitizer = new RawTowerDigitizer("HcalInRawTowerDigitizer");
286  TowerDigitizer->Detector("HCALIN");
287  // TowerDigitizer->set_raw_tower_node_prefix("RAW_LG");
288  TowerDigitizer->set_digi_algorithm(G4HCALIN::TowerDigi);
289  TowerDigitizer->set_pedstal_central_ADC(0);
290  TowerDigitizer->set_pedstal_width_ADC(1); // From Jin's guess. No EMCal High Gain data yet! TODO: update
291  TowerDigitizer->set_photonelec_ADC(32. / 5.);
292  TowerDigitizer->set_photonelec_yield_visible_GeV(32. / 5 / (0.4e-3));
293  TowerDigitizer->set_zero_suppression_ADC(-0); // no-zero suppression
294  TowerDigitizer->Verbosity(verbosity);
295  if (!Enable::HCALIN_G4Hit) TowerDigitizer->set_towerinfo(RawTowerDigitizer::ProcessTowerType::kTowerInfoOnly); // just use towerinfo
296  se->registerSubsystem(TowerDigitizer);
297 
298  // Default sampling fraction for SS310
299  double visible_sample_fraction_HCALIN = 0.0631283; //, /gpfs/mnt/gpfs04/sphenix/user/jinhuang/prod_analysis/hadron_shower_res_nightly/./G4Hits_sPHENIX_pi-_eta0_16GeV-0000.root_qa.rootQA_Draw_HCALIN_G4Hit.pdf
300 
301  if (G4HCALIN::inner_hcal_material_Al) visible_sample_fraction_HCALIN = 0.162166; // for "G4_Al", Abhisek Sen <sen.abhisek@gmail.com>
302 
303  RawTowerCalibration *TowerCalibration = new RawTowerCalibration("HcalInRawTowerCalibration");
304  TowerCalibration->Detector("HCALIN");
305  // TowerCalibration->set_raw_tower_node_prefix("RAW_LG");
306  // TowerCalibration->set_calib_tower_node_prefix("CALIB_LG");
309  {
310  // 0.176 extracted from electron sims (edep(scintillator)/edep(total))
311  TowerCalibration->set_calib_const_GeV_ADC(1. / 0.176);
312  }
313  else
314  {
315  TowerCalibration->set_calib_const_GeV_ADC(0.4e-3 / visible_sample_fraction_HCALIN);
316  }
317  TowerCalibration->set_pedstal_ADC(0);
318  TowerCalibration->Verbosity(verbosity);
319  if (!Enable::HCALIN_G4Hit) TowerCalibration->set_towerinfo(RawTowerCalibration::ProcessTowerType::kTowerInfoOnly); // just use towerinfo
320  se->registerSubsystem(TowerCalibration);
321 
322  return;
323 }
324 
326 {
328 
330 
332  {
333  RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("HcalInRawClusterBuilderTemplate");
334  ClusterBuilder->Detector("HCALIN");
335  ClusterBuilder->SetCylindricalGeometry(); // has to be called after Detector()
336  ClusterBuilder->Verbosity(verbosity);
337  if (!Enable::HCALIN_G4Hit) ClusterBuilder->set_UseTowerInfo(1); // just use towerinfo
338  se->registerSubsystem(ClusterBuilder);
339  }
341  {
342  RawClusterBuilderGraph *ClusterBuilder = new RawClusterBuilderGraph("HcalInRawClusterBuilderGraph");
343  ClusterBuilder->Detector("HCALIN");
344  ClusterBuilder->Verbosity(verbosity);
345  //if (!Enable::HCALIN_G4Hit) ClusterBuilder->set_UseTowerInfo(1); // just use towerinfo
346  se->registerSubsystem(ClusterBuilder);
347  }
348  else
349  {
350  cout << "HCalIn_Clusters - unknown clusterizer setting!" << endl;
351  exit(1);
352  }
353  return;
354 }
355 
356 void HCALInner_Eval(const std::string &outputfile, int start_event = 0)
357 {
360 
361  CaloEvaluator *eval = new CaloEvaluator("HCALINEVALUATOR", "HCALIN", outputfile);
362  eval->set_event(start_event);
363  eval->Verbosity(verbosity);
364  se->registerSubsystem(eval);
365 
366  return;
367 }
368 
370 {
372 
375  qa->Verbosity(verbosity);
376  se->registerSubsystem(qa);
377 
378  return;
379 }
380 
381 #endif