Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4_HcalOut_ref.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4_HcalOut_ref.C
1 #ifndef MACRO_G4HCALOUTREF_C
2 #define MACRO_G4HCALOUTREF_C
3 
4 #include <GlobalVariables.C>
5 #include <QA.C>
6 
9 
11 
14 
15 #include <g4eval/CaloEvaluator.h>
16 
17 #include <g4main/PHG4Reco.h>
18 
19 #include <caloreco/RawClusterBuilderGraph.h>
20 #include <caloreco/RawClusterBuilderTemplate.h>
21 #include <caloreco/RawTowerCalibration.h>
22 
23 #include <qa_modules/QAG4SimulationCalorimeter.h>
24 
25 #include <fun4all/Fun4AllServer.h>
26 
27 R__LOAD_LIBRARY(libcalo_reco.so)
28 R__LOAD_LIBRARY(libg4calo.so)
29 R__LOAD_LIBRARY(libg4detectors.so)
30 R__LOAD_LIBRARY(libg4eval.so)
31 R__LOAD_LIBRARY(libg4ohcal.so)
32 R__LOAD_LIBRARY(libqa_modules.so)
33 
34 namespace Enable
35 {
36  bool HCALOUT = false;
37  bool HCALOUT_ABSORBER = false;
38  bool HCALOUT_OVERLAPCHECK = false;
39  bool HCALOUT_CELL = false;
40  bool HCALOUT_TOWER = false;
41  bool HCALOUT_CLUSTER = false;
42  bool HCALOUT_EVAL = false;
43  bool HCALOUT_QA = false;
44  bool HCALOUT_OLD = false;
45  bool HCALOUT_G4Hit = true;
46  int HCALOUT_VERBOSITY = 0;
47 } // namespace Enable
48 
49 namespace G4HCALOUT
50 {
51  double outer_radius = 269.317 + 5;
52  double size_z = 639.240 + 10;
53  double phistart = NAN;
54  double tower_emin = NAN;
57 
58  // Digitization (default photon digi):
60  // directly pass the energy of sim tower to digitized tower
61  // kNo_digitization
62  // simple digitization with photon statistics, single amplitude ADC conversion and pedestal
63  // kSimple_photon_digitization
64  // digitization with photon statistics on SiPM with an effective pixel N, ADC conversion and pedestal
65  // kSiPM_photon_digitization
66 
68  {
71  };
72 
76  // enu_HCalOut_clusterizer HCalOut_clusterizer = kHCalOutGraphClusterizer;
77 } // namespace G4HCALOUT
78 
79 // Init is called by G4Setup.C
81 {
85 }
86 
87 double HCalOuter(PHG4Reco *g4Reco,
88  double radius,
89  const int crossings)
90 {
91  bool AbsorberActive = Enable::ABSORBER || Enable::HCALOUT_ABSORBER;
94 
96  // Mephi Maps
97  // Maps are different for old/new but how to set is identical
98  // here are the ones for the old outer hcal since the new maps do not exist yet
99  // use hcal->set_string_param("MapFileName",""); to disable map
100  // hcal->set_string_param("MapFileName",std::string(getenv("CALIBRATIONROOT")) + "/HCALOUT/tilemap/oHCALMaps092021.root");
101  // hcal->set_string_param("MapHistoName","hCombinedMap");
102 
104  {
105  hcal = new PHG4OuterHcalSubsystem("HCALOUT");
106  // hcal->set_double_param("inner_radius", 183.3);
107  //-----------------------------------------
108  // the light correction can be set in a single call
109  // hcal->set_double_param("light_balance_inner_corr", NAN);
110  // hcal->set_double_param("light_balance_inner_radius", NAN);
111  // hcal->set_double_param("light_balance_outer_corr", NAN);
112  // hcal->set_double_param("light_balance_outer_radius", NAN);
113  // hcal->set_double_param("magnet_cutout_radius", 195.31);
114  // hcal->set_double_param("magnet_cutout_scinti_radius", 195.96);
115  // hcal->SetLightCorrection(NAN,NAN,NAN,NAN);
116  //-----------------------------------------
117  // hcal->set_double_param("outer_radius", G4HCALOUT::outer_radius);
118  // hcal->set_double_param("place_x", 0.);
119  // hcal->set_double_param("place_y", 0.);
120  // hcal->set_double_param("place_z", 0.);
121  // hcal->set_double_param("rot_x", 0.);
122  // hcal->set_double_param("rot_y", 0.);
123  // hcal->set_double_param("rot_z", 0.);
124  // hcal->set_double_param("scinti_eta_coverage", 1.1);
125  // hcal->set_double_param("scinti_gap", 0.85);
126  // hcal->set_double_param("scinti_gap_neighbor", 0.1);
127  // hcal->set_double_param("scinti_inner_radius",183.89);
128  // hcal->set_double_param("scinti_outer_radius",263.27);
129  // hcal->set_double_param("scinti_tile_thickness", 0.7);
130  // hcal->set_double_param("size_z", G4HCALOUT::size_z);
131  // hcal->set_double_param("steplimits", NAN);
132  // hcal->set_double_param("tilt_angle", -11.23);
133 
134  // hcal->set_int_param("light_scint_model", 1);
135  // hcal->set_int_param("magnet_cutout_first_scinti", 8);
136  // hcal->set_int_param("ncross", 0);
137  // hcal->set_int_param("n_towers", 64);
138  // hcal->set_int_param("n_scinti_plates_per_tower", 5);
139  // hcal->set_int_param("n_scinti_tiles", 12);
140 
141  // hcal->set_string_param("material", "Steel_1006");
142  }
143  else
144  {
145  hcal = new PHG4OHCalSubsystem("HCALOUT");
146  std::string hcaltiles = std::string(getenv("CALIBRATIONROOT")) + "/HcalGeo/OuterHCalAbsorberTiles_merged.gdml";
147  // std::string hcaltiles = "/sphenix/u/shuhang98/calibrations/OuterHCalAbsorberTiles_merged.gdml";
148  hcal->set_string_param("GDMPath", hcaltiles);
149  hcal->set_string_param("IronFieldMapPath", G4MAGNET::magfield_OHCAL_steel);
150  hcal->set_double_param("IronFieldMapScale", G4MAGNET::magfield_rescale);
151  }
152 
154  {
155  hcal->set_int_param("light_scint_model", G4HCALOUT::light_scint_model);
156  }
157  // hcal->set_int_param("field_check", 1); // for validating the field in HCal
158  hcal->SetActive();
159  hcal->SuperDetector("HCALOUT");
160  if (AbsorberActive)
161  {
162  hcal->SetAbsorberActive();
163  }
164  hcal->OverlapCheck(OverlapCheck);
165  if (!isfinite(G4HCALOUT::phistart))
166  {
168  {
169  G4HCALOUT::phistart = 0.026598397; // offet in phi (from zero) extracted from geantinos
170  }
171  else
172  {
173  G4HCALOUT::phistart = 0.0240615415; // offet in phi (from zero) extracted from geantinos
174  }
175  }
176  hcal->set_int_param("saveg4hit", Enable::HCALOUT_G4Hit);
177  hcal->set_double_param("phistart", G4HCALOUT::phistart);
178  g4Reco->registerSubsystem(hcal);
179 
180  if (!Enable::HCALOUT_OLD)
181  {
182  // HCal support rings, approximated as solid rings
183  // note there is only one ring on either side, but to allow part of the ring inside the HCal envelope two rings are used
184  const double inch = 2.54;
185  const double support_ring_outer_radius = 74.061 * inch;
186  const double innerradius = 56.188 * inch;
187  const double hcal_envelope_radius = 182.423 - 5.;
188  const double support_ring_z = 175.375 * inch / 2.;
189  const double support_ring_dz = 4. * inch;
190  const double z_rings[] =
191  {-support_ring_z, support_ring_z};
193  PHG4CylinderSubsystem *cylout;
194 
195  for (int i = 0; i < 2; i++)
196  {
197  // rings outside of HCal envelope
198  cyl = new PHG4CylinderSubsystem("HCAL_SPT_N1", i);
199  cyl->set_double_param("place_z", z_rings[i]);
200  cyl->SuperDetector("HCALIN_SPT");
201  cyl->set_double_param("radius", innerradius);
202  cyl->set_int_param("lengthviarapidity", 0);
203  cyl->set_double_param("length", support_ring_dz);
204  cyl->set_string_param("material", "G4_Al");
205  cyl->set_double_param("thickness", hcal_envelope_radius - 0.1 - innerradius);
206  cyl->set_double_param("start_phi_rad", 1.867);
207  cyl->set_double_param("delta_phi_rad", 5.692);
209  if (AbsorberActive)
210  {
211  cyl->SetActive();
212  }
213  g4Reco->registerSubsystem(cyl);
214 
215  // rings inside outer HCal envelope
216  cylout = new PHG4CylinderSubsystem("HCAL_SPT_N1", i + 2);
217  cylout->set_double_param("place_z", z_rings[i]);
218  cylout->SuperDetector("HCALIN_SPT");
219  cylout->set_double_param("radius", hcal_envelope_radius + 0.1); // add a mm to avoid overlaps
220  cylout->set_int_param("lengthviarapidity", 0);
221  cylout->set_double_param("length", support_ring_dz);
222  cylout->set_string_param("material", "G4_Al");
223  cylout->set_double_param("thickness", support_ring_outer_radius - (hcal_envelope_radius + 0.1));
224  cylout->set_double_param("start_phi_rad", 1.867);
225  cylout->set_double_param("delta_phi_rad", 5.692);
226  if (AbsorberActive)
227  {
228  cylout->SetActive();
229  }
230  cylout->SetMotherSubsystem(hcal);
231  cylout->OverlapCheck(OverlapCheck);
232  g4Reco->registerSubsystem(cylout);
233  }
234  }
235 
236  radius = hcal->get_double_param("outer_radius");
237 
238  radius += no_overlapp;
239 
240  return radius;
241 }
242 
244 {
245  if (!Enable::HCALOUT_G4Hit) return;
247 
249 
250  PHG4HcalCellReco *hc = new PHG4HcalCellReco("HCALOUT_CELLRECO");
251  hc->Detector("HCALOUT");
252  hc->Verbosity(verbosity);
253  // check for energy conservation - needs modified "infinite" timing cuts
254  // 0-999999999
255  // hc->checkenergy();
256  // timing cuts with their default settings
257  // hc->set_double_param("tmin",0.);
258  // hc->set_double_param("tmax",60.0);
259  // or all at once:
260  // hc->set_timing_window(0.0,60.0);
261  // this sets all cells to a fixed energy for debugging
262  // hc->set_fixed_energy(1.);
263  se->registerSubsystem(hc);
264 
265  return;
266 }
267 
269 {
273  {
274  HcalRawTowerBuilder *TowerBuilder = new HcalRawTowerBuilder("HcalOutRawTowerBuilder");
275  TowerBuilder->Detector("HCALOUT");
276  TowerBuilder->set_sim_tower_node_prefix("SIM");
277  if (!isfinite(G4HCALOUT::phistart))
278  {
280  {
281  G4HCALOUT::phistart = 0.026598397; // offet in phi (from zero) extracted from geantinos
282  }
283  else
284  {
285  G4HCALOUT::phistart = 0.0240615415; // offet in phi (from zero) extracted from geantinos
286  }
287  }
288  TowerBuilder->set_double_param("phistart", G4HCALOUT::phistart);
289  if (isfinite(G4HCALOUT::tower_emin))
290  {
291  TowerBuilder->set_double_param("emin", G4HCALOUT::tower_emin);
292  }
294  {
295  TowerBuilder->set_int_param("tower_energy_source", G4HCALOUT::tower_energy_source);
296  }
297  // this sets specific decalibration factors
298  // for a given cell
299  // TowerBuilder->set_cell_decal_factor(1,10,0.1);
300  // for a whole tower
301  // TowerBuilder->set_tower_decal_factor(0,10,0.2);
302  // TowerBuilder->set_cell_decal_factor(1,10,0.1);
303  // TowerBuilder->set_tower_decal_factor(0,10,0.2);
304  TowerBuilder->Verbosity(verbosity);
305  se->registerSubsystem(TowerBuilder);
306  }
307  // From 2016 Test beam sim
308  RawTowerDigitizer *TowerDigitizer = new RawTowerDigitizer("HcalOutRawTowerDigitizer");
309  TowerDigitizer->Detector("HCALOUT");
310  // TowerDigitizer->set_raw_tower_node_prefix("RAW_LG");
311  TowerDigitizer->set_digi_algorithm(G4HCALOUT::TowerDigi);
312  TowerDigitizer->set_pedstal_central_ADC(0);
313  TowerDigitizer->set_pedstal_width_ADC(1); // From Jin's guess. No EMCal High Gain data yet! TODO: update
314  TowerDigitizer->set_photonelec_ADC(16. / 5.);
315  TowerDigitizer->set_photonelec_yield_visible_GeV(16. / 5 / (0.2e-3));
316  TowerDigitizer->set_zero_suppression_ADC(-0); // no-zero suppression
317  TowerDigitizer->Verbosity(verbosity);
318  if (!Enable::HCALOUT_G4Hit) TowerDigitizer->set_towerinfo(RawTowerDigitizer::ProcessTowerType::kTowerInfoOnly); // just use towerinfo
319  se->registerSubsystem(TowerDigitizer);
320 
321  const double visible_sample_fraction_HCALOUT = 3.38021e-02; // /gpfs/mnt/gpfs04/sphenix/user/jinhuang/prod_analysis/hadron_shower_res_nightly/./G4Hits_sPHENIX_pi-_eta0_16GeV.root_qa.rootQA_Draw_HCALOUT_G4Hit.pdf
322 
323  RawTowerCalibration *TowerCalibration = new RawTowerCalibration("HcalOutRawTowerCalibration");
324  TowerCalibration->Detector("HCALOUT");
325  // TowerCalibration->set_raw_tower_node_prefix("RAW_LG");
326  // TowerCalibration->set_calib_tower_node_prefix("CALIB_LG");
329  {
330  // 0.033 extracted from electron sims (edep(scintillator)/edep(total))
331  TowerCalibration->set_calib_const_GeV_ADC(1. / 0.033);
332  }
333  else
334  {
335  TowerCalibration->set_calib_const_GeV_ADC(0.2e-3 / visible_sample_fraction_HCALOUT);
336  }
337  TowerCalibration->set_pedstal_ADC(0);
338  TowerCalibration->Verbosity(verbosity);
339  if (!Enable::HCALOUT_G4Hit) TowerCalibration->set_towerinfo(RawTowerCalibration::ProcessTowerType::kTowerInfoOnly); // just use towerinfo
340  se->registerSubsystem(TowerCalibration);
341 
342  return;
343 }
344 
346 {
348 
350 
352  {
353  RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("HcalOutRawClusterBuilderTemplate");
354  ClusterBuilder->Detector("HCALOUT");
355  ClusterBuilder->SetCylindricalGeometry(); // has to be called after Detector()
356  ClusterBuilder->Verbosity(verbosity);
357  if (!Enable::HCALOUT_G4Hit) ClusterBuilder->set_UseTowerInfo(1); // just use towerinfo
358  se->registerSubsystem(ClusterBuilder);
359  }
361  {
362  RawClusterBuilderGraph *ClusterBuilder = new RawClusterBuilderGraph("HcalOutRawClusterBuilderGraph");
363  ClusterBuilder->Detector("HCALOUT");
364  ClusterBuilder->Verbosity(verbosity);
365  //if (!Enable::HCALOUT_G4Hit) ClusterBuilder->set_UseTowerInfo(1); // just use towerinfo
366  se->registerSubsystem(ClusterBuilder);
367  }
368  else
369  {
370  cout << "HCALOuter_Clusters - unknown clusterizer setting!" << endl;
371  exit(1);
372  }
373 
374  return;
375 }
376 
377 void HCALOuter_Eval(const std::string &outputfile, int start_event = 0)
378 {
380 
382 
383  CaloEvaluator *eval = new CaloEvaluator("HCALOUTEVALUATOR", "HCALOUT", outputfile);
384  eval->set_event(start_event);
385  eval->Verbosity(verbosity);
386  se->registerSubsystem(eval);
387 
388  return;
389 }
390 
392 {
394 
397  qa->Verbosity(verbosity);
398  se->registerSubsystem(qa);
399 
400  return;
401 }
402 
403 #endif