EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4_EHCAL.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4_EHCAL.C
1 #ifndef MACRO_G4EHCAL_C
2 #define MACRO_G4EHCAL_C
3 
4 #include <GlobalVariables.C>
5 
8 
9 // #include <g4eiccalos/PHG4ForwardCalCellReco.h>
11 
12 #include <g4eval/CaloEvaluator.h>
13 
14 #include <g4main/PHG4Reco.h>
15 
16 #include <caloreco/RawClusterBuilderFwd.h>
17 #include <caloreco/RawClusterBuilderTemplate.h>
18 #include <caloreco/RawTowerCalibration.h>
19 
20 #include <fun4all/Fun4AllServer.h>
21 
22 R__LOAD_LIBRARY(libcalo_reco.so)
23 R__LOAD_LIBRARY(libg4calo.so)
24 R__LOAD_LIBRARY(libg4detectors.so)
25 R__LOAD_LIBRARY(libg4eval.so)
26 
27 namespace Enable
28 {
29  bool EHCAL = false;
30  bool EHCAL_ABSORBER = false;
31  bool EHCAL_CELL = false;
32  bool EHCAL_TOWER = false;
33  bool EHCAL_CLUSTER = false;
34  bool EHCAL_EVAL = false;
35  bool EHCAL_OVERLAPCHECK = false;
36  int EHCAL_VERBOSITY = 0;
37 } // namespace Enable
38 
39 namespace G4EHCAL
40 {
41  // from ForwardHcal/mapping/towerMap_EHCAL_v005.txt
42  double Gz0 = -360.0;
43  double Gdz = 100.;
44  double outer_radius = 260.;
46  {
49  };
50  //template clusterizer, as developed by Sasha Bazilevsky
52  // graph clusterizer
53  //enu_FHcal_clusterizer FHcal_clusterizer = kFHcalGraphClusterizer;
54  namespace SETTING
55  {
56  bool FullEtaAcc = false;
57  bool HC2x = false;
58  bool HC4x = false;
59  bool towercalib1 = false;
60  bool towercalibSiPM = false;
61  bool towercalibHCALIN = false;
62  bool towercalib3 = false;
63  } // namespace SETTING
64 } // namespace G4EHCAL
65 
66 void EHCALInit()
67 {
68  // simple way to check if only 1 of the settings is true
69  if ((G4EHCAL::SETTING::FullEtaAcc ? 1 : 0) + (G4EHCAL::SETTING::HC4x ? 1 : 0) + (G4EHCAL::SETTING::HC2x ? 1 : 0) > 1)
70  {
71  cout << "use only G4EHCAL::SETTING::FullEtaAcc=true or G4EHCAL::SETTING::HC2x=true or G4EHCAL::SETTING::HC4x=true" << endl;
72  gSystem->Exit(1);
73  }
76  1)
77  {
78  cout << "use only G4EHCAL::SETTING::towercalib1 = true or G4EHCAL::SETTING::towercalibSiPM = true"
79  << " or G4EHCAL::SETTING::towercalibHCALIN = true or G4EHCAL::SETTING::towercalib3 = true" << endl;
80  gSystem->Exit(1);
81  }
82 
86 
87 
88 }
89 
90 void EHCALSetup(PHG4Reco *g4Reco)
91 {
92  const bool AbsorberActive = Enable::ABSORBER || Enable::EHCAL_ABSORBER;
93  bool OverlapCheck = Enable::OVERLAPCHECK || Enable::EHCAL_OVERLAPCHECK;
95 
98 
99  ostringstream mapping_EHCAL;
100 
101  // Switch to desired calo setup
102  // HCal Fe-Scint with doubled granularity
104  {
105  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_2x.txt";
106  }
107  // full HCal Fe-Scint with nominal acceptance doubled granularity
109  {
110  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_2x_fullEtaCov.txt";
111  }
112  // HCal Fe-Scint with four times granularity
113  else if (G4EHCAL::SETTING::HC4x )
114  {
115  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_4x.txt";
116  }
117  // full HCal Fe-Scint with nominal acceptance four times granularity
119  {
120  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_4x_fullEtaCov.txt";
121  }
122  // full HCal Fe-Scint with nominal acceptance
124  {
125  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_default_fullEtaCov.txt";
126  }
127  // full HCal Fe-Scint with enlarged beam pipe opening for Mar 2020 beam pipe
128  else
129  {
130  mapping_EHCAL << getenv("CALIBRATIONROOT")
131  << "/BackwardHcal/mapping/towerMap_EHCAL_default.txt";
132  }
133 
134  ehcal->SetTowerMappingFile(mapping_EHCAL.str());
135  ehcal->OverlapCheck(OverlapCheck);
136  ehcal->SetActive();
137  ehcal->SetDetailed(false);
138  ehcal->SuperDetector("EHCAL");
139  if (AbsorberActive) ehcal->SetAbsorberActive();
140 
141  g4Reco->registerSubsystem(ehcal);
142 }
143 
144 void EHCAL_Cells(int verbosity = 0)
145 {
146  return;
147 }
148 
150 {
152 
154 
155  ostringstream mapping_EHCAL;
156 
157  // Switch to desired calo setup
158  // HCal Fe-Scint with doubled granularity
160  {
161  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_2x.txt";
162  }
163  // full HCal Fe-Scint with nominal acceptance doubled granularity
165  {
166  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_2x_fullEtaCov.txt";
167  }
168  // HCal Fe-Scint with four times granularity
169  else if (G4EHCAL::SETTING::HC4x )
170  {
171  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_4x.txt";
172  }
173  // full HCal Fe-Scint with nominal acceptance four times granularity
175  {
176  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_4x_fullEtaCov.txt";
177  }
178  // full HCal Fe-Scint with nominal acceptance
180  {
181  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_default_fullEtaCov.txt";
182  }
183  // full HCal Fe-Scint with enlarged beam pipe opening for Mar 2020 beam pipe
184  else
185  {
186  mapping_EHCAL << getenv("CALIBRATIONROOT") << "/BackwardHcal/mapping/towerMap_EHCAL_default.txt";
187  }
188 
189  RawTowerBuilderByHitIndex *tower_EHCAL = new RawTowerBuilderByHitIndex("TowerBuilder_EHCAL");
190  tower_EHCAL->Detector("EHCAL");
191  tower_EHCAL->set_sim_tower_node_prefix("SIM");
192  tower_EHCAL->GeometryTableFile(mapping_EHCAL.str());
193 
194  se->registerSubsystem(tower_EHCAL);
195 
196  // enable usage of different tower calibrations for systematic studies
198  {
199  cout << "1: using towercalib1 for EHCAL towers" << endl;
200  const double EHCAL_photoelectron_per_GeV = 500;
201  RawTowerDigitizer *TowerDigitizer_EHCAL = new RawTowerDigitizer("EHCALRawTowerDigitizer");
202 
203  TowerDigitizer_EHCAL->Detector("EHCAL");
204  TowerDigitizer_EHCAL->Verbosity(verbosity);
205  TowerDigitizer_EHCAL->set_raw_tower_node_prefix("RAW");
207  TowerDigitizer_EHCAL->set_pedstal_central_ADC(0);
208  TowerDigitizer_EHCAL->set_pedstal_width_ADC(8); // eRD1 test beam setting
209  TowerDigitizer_EHCAL->set_photonelec_ADC(1); //not simulating ADC discretization error
210  TowerDigitizer_EHCAL->set_photonelec_yield_visible_GeV(EHCAL_photoelectron_per_GeV);
211  TowerDigitizer_EHCAL->set_zero_suppression_ADC(16); // eRD1 test beam setting
212 
213  se->registerSubsystem(TowerDigitizer_EHCAL);
214 
215  RawTowerCalibration *TowerCalibration_EHCAL = new RawTowerCalibration("EHCALRawTowerCalibration");
216  TowerCalibration_EHCAL->Detector("EHCAL");
217  TowerCalibration_EHCAL->Verbosity(verbosity);
219  TowerCalibration_EHCAL->set_calib_const_GeV_ADC(1. / EHCAL_photoelectron_per_GeV);
220  TowerCalibration_EHCAL->set_pedstal_ADC(0);
221 
222  se->registerSubsystem(TowerCalibration_EHCAL);
223  }
225  {
226  //from https://sphenix-collaboration.github.io/doxygen/d4/d58/Fun4All__G4__Prototype4_8C_source.html
227  const double sampling_fraction = 0.019441; // +/- 0.019441 from 0 Degree indenting 12 GeV electron showers
228  const double photoelectron_per_GeV = 500; //500 photon per total GeV deposition
229  const double ADC_per_photoelectron_HG = 3.8; // From Sean Stoll, Mar 29
230  const double ADC_per_photoelectron_LG = 0.24; // From Sean Stoll, Mar 29
231 
232  cout << "2: using towercalibSiPM for EHCAL towers" << endl;
233  RawTowerDigitizer *TowerDigitizer = new RawTowerDigitizer("EHCALRawTowerDigitizer");
234  TowerDigitizer->Detector("EHCAL");
235  TowerDigitizer->set_raw_tower_node_prefix("RAW");
237  TowerDigitizer->set_pedstal_central_ADC(0);
238  TowerDigitizer->set_pedstal_width_ADC(1);
239  TowerDigitizer->set_photonelec_ADC(1. / ADC_per_photoelectron_LG);
240  TowerDigitizer->set_photonelec_yield_visible_GeV(photoelectron_per_GeV / sampling_fraction);
241  TowerDigitizer->set_zero_suppression_ADC(-1000); // no-zero suppression
242  se->registerSubsystem(TowerDigitizer);
243 
244  RawTowerCalibration *TowerCalibration = new RawTowerCalibration("EHCALRawTowerCalibration");
245  TowerCalibration->Detector("EHCAL");
246  TowerCalibration->set_raw_tower_node_prefix("RAW");
248  TowerCalibration->set_calib_const_GeV_ADC(1. / ADC_per_photoelectron_LG / photoelectron_per_GeV);
249  TowerCalibration->set_pedstal_ADC(0);
250  TowerCalibration->set_zero_suppression_GeV(-1); // no-zero suppression
251  se->registerSubsystem(TowerCalibration);
252  }
254  {
255  const double visible_sample_fraction_HCALIN = 7.19505e-02; // 1.34152e-02
256  RawTowerDigitizer *TowerDigitizer = new RawTowerDigitizer("EHCALRawTowerDigitizer");
257  TowerDigitizer->Detector("EHCAL");
258  TowerDigitizer->set_raw_tower_node_prefix("RAW");
260  TowerDigitizer->set_pedstal_central_ADC(0);
261  TowerDigitizer->set_pedstal_width_ADC(1);
262  TowerDigitizer->set_photonelec_ADC(32. / 5.);
263  TowerDigitizer->set_photonelec_yield_visible_GeV(32. / 5 / (0.4e-3));
264  TowerDigitizer->set_zero_suppression_ADC(-1000); // no-zero suppression
265  se->registerSubsystem(TowerDigitizer);
266 
267  RawTowerCalibration *TowerCalibration = new RawTowerCalibration("EHCALRawTowerCalibration");
268  TowerCalibration->Detector("EHCAL");
269  TowerCalibration->set_raw_tower_node_prefix("RAW");
271  TowerCalibration->set_calib_const_GeV_ADC(0.4e-3 / visible_sample_fraction_HCALIN);
272  TowerCalibration->set_pedstal_ADC(0);
273  TowerCalibration->set_zero_suppression_GeV(-1); // no-zero suppression
274  se->registerSubsystem(TowerCalibration);
275  }
277  {
278  cout << "3: using towercalib3 for EHCAL towers" << endl;
279  RawTowerDigitizer *TowerDigitizer = new RawTowerDigitizer("EHCALRawTowerDigitizer");
280  TowerDigitizer->Detector("EHCAL");
281  TowerDigitizer->set_pedstal_central_ADC(0);
282  TowerDigitizer->set_pedstal_width_ADC(8); // eRD1 test beam setting
283  TowerDigitizer->Verbosity(verbosity);
285  se->registerSubsystem(TowerDigitizer);
286 
287  RawTowerCalibration *TowerCalibration = new RawTowerCalibration("EHCALRawTowerCalibration");
288  TowerCalibration->Detector("EHCAL");
289  TowerCalibration->Verbosity(verbosity);
291  TowerCalibration->set_calib_const_GeV_ADC(1. / 0.03898); // calibrated with muons
292  TowerCalibration->set_pedstal_ADC(0);
293  se->registerSubsystem(TowerCalibration);
294  }
295  else
296  {
297  cout << "def: using default for EHCAL towers" << endl;
298  RawTowerDigitizer *TowerDigitizer = new RawTowerDigitizer("EHCALRawTowerDigitizer");
299  TowerDigitizer->Detector("EHCAL");
300  TowerDigitizer->Verbosity(verbosity);
302  se->registerSubsystem(TowerDigitizer);
303 
304  RawTowerCalibration *TowerCalibration = new RawTowerCalibration("EHCALRawTowerCalibration");
305  TowerCalibration->Detector("EHCAL");
306  TowerCalibration->Verbosity(verbosity);
308  TowerCalibration->set_calib_const_GeV_ADC(1. / (0.03898*0.5)); // temporary factor 0.5 to fix calibration for new tower design
309  TowerCalibration->set_pedstal_ADC(0);
310  se->registerSubsystem(TowerCalibration);
311  }
312 }
313 
315 {
318 
320  {
321  RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("EHCALRawClusterBuilderTemplate");
322  ClusterBuilder->Detector("EHCAL");
323  ClusterBuilder->SetPlanarGeometry(); // has to be called after Detector()
324  ClusterBuilder->Verbosity(verbosity);
325  ClusterBuilder->set_threshold_energy(0.100);
326  se->registerSubsystem(ClusterBuilder);
327  }
329  {
330  RawClusterBuilderFwd *ClusterBuilder = new RawClusterBuilderFwd("EHCALRawClusterBuilderFwd");
331  ClusterBuilder->Detector("EHCAL");
332  ClusterBuilder->Verbosity(verbosity);
333  ClusterBuilder->set_threshold_energy(0.100);
334  se->registerSubsystem(ClusterBuilder);
335  }
336  else
337  {
338  cout << "EHCAL_Clusters - unknown clusterizer setting " << G4EHCAL::EHCAL_clusterizer << endl;
339  gSystem->Exit(1);
340  }
341 
342  return;
343 }
344 
345 void EHCAL_Eval(const std::string &outputfile)
346 {
349 
350  CaloEvaluator *eval = new CaloEvaluator("EHCALEVALUATOR", "EHCAL", outputfile.c_str());
351  eval->Verbosity(verbosity);
352  se->registerSubsystem(eval);
353 
354  return;
355 }
356 #endif