File indexing completed on 2025-12-16 09:24:02
0001
0002 #ifndef MACRO_G4HCALINREF_C
0003 #define MACRO_G4HCALINREF_C
0004
0005 #include <GlobalVariables.C>
0006
0007 #include <QA.C>
0008
0009 #include <g4calo/HcalRawTowerBuilder.h>
0010 #include <g4calo/RawTowerDigitizer.h>
0011
0012 #include <g4ihcal/PHG4IHCalSubsystem.h>
0013
0014 #include <g4detectors/PHG4CylinderSubsystem.h>
0015 #include <g4detectors/PHG4HcalCellReco.h>
0016 #include <g4detectors/PHG4InnerHcalSubsystem.h>
0017
0018 #include <g4eval/CaloEvaluator.h>
0019
0020 #include <g4main/PHG4Reco.h>
0021
0022 #include <calowaveformsim/CaloWaveformSim.h>
0023
0024 #include <calobase/TowerInfoDefs.h>
0025
0026 #include <caloreco/CaloTowerBuilder.h>
0027 #include <caloreco/CaloTowerCalib.h>
0028 #include <caloreco/CaloTowerStatus.h>
0029 #include <caloreco/CaloWaveformProcessing.h>
0030 #include <caloreco/RawClusterBuilderGraph.h>
0031 #include <caloreco/RawClusterBuilderTemplate.h>
0032 #include <caloreco/RawTowerCalibration.h>
0033
0034 #include <simqa_modules/QAG4SimulationCalorimeter.h>
0035
0036 #include <fun4all/Fun4AllServer.h>
0037
0038 R__LOAD_LIBRARY(libcalo_reco.so)
0039 R__LOAD_LIBRARY(libg4calo.so)
0040 R__LOAD_LIBRARY(libCaloWaveformSim.so)
0041 R__LOAD_LIBRARY(libg4detectors.so)
0042 R__LOAD_LIBRARY(libg4eval.so)
0043 R__LOAD_LIBRARY(libg4ihcal.so)
0044 R__LOAD_LIBRARY(libsimqa_modules.so)
0045
0046 namespace Enable
0047 {
0048 bool HCALIN = false;
0049 bool HCALIN_ABSORBER = false;
0050 bool HCALIN_OVERLAPCHECK = false;
0051 bool HCALIN_CELL = false;
0052 bool HCALIN_TOWER = false;
0053 bool HCALIN_CLUSTER = false;
0054 bool HCALIN_EVAL = false;
0055 bool HCALIN_QA = false;
0056 bool HCALIN_SUPPORT = false;
0057 bool HCALIN_OLD = false;
0058 bool HCALIN_G4Hit = true;
0059 bool HCALIN_TOWERINFO = false;
0060 int HCALIN_VERBOSITY = 0;
0061 }
0062
0063 namespace G4HCALIN
0064 {
0065 double inch = 2.54;
0066 double support_ring_outer_radius = 177.323;
0067 double support_ring_z = 175.375 * inch / 2;
0068 double dz = 4. * inch;
0069
0070 double phistart = NAN;
0071 double tower_emin = NAN;
0072 int light_scint_model = -1;
0073 int tower_energy_source = -1;
0074
0075
0076
0077
0078 bool inner_hcal_material_Al = true;
0079
0080 int inner_hcal_eic = 0;
0081
0082
0083 RawTowerDigitizer::enu_digi_algorithm TowerDigi = RawTowerDigitizer::kSimple_photon_digitization;
0084
0085
0086
0087
0088
0089
0090
0091 enum enu_HCalIn_clusterizer
0092 {
0093 kHCalInGraphClusterizer,
0094
0095 kHCalInTemplateClusterizer
0096 };
0097
0098 bool useTowerInfoV2 = true;
0099
0100 enu_HCalIn_clusterizer HCalIn_clusterizer = kHCalInTemplateClusterizer;
0101
0102
0103 }
0104
0105
0106 void HCalInnerInit(const int iflag = 0)
0107 {
0108 BlackHoleGeometry::max_radius = std::max(BlackHoleGeometry::max_radius, G4HCALIN::support_ring_outer_radius);
0109 BlackHoleGeometry::max_z = std::max(BlackHoleGeometry::max_z, G4HCALIN::support_ring_z + G4HCALIN::dz / 2.);
0110 BlackHoleGeometry::min_z = std::min(BlackHoleGeometry::min_z, -G4HCALIN::support_ring_z - G4HCALIN::dz / 2.);
0111 if (iflag == 1)
0112 {
0113 G4HCALIN::inner_hcal_eic = 1;
0114 }
0115 }
0116
0117 double HCalInner(PHG4Reco *g4Reco,
0118 double radius,
0119 const int )
0120 {
0121 bool AbsorberActive = Enable::ABSORBER || Enable::HCALIN_ABSORBER;
0122 bool OverlapCheck = Enable::OVERLAPCHECK || Enable::HCALIN_OVERLAPCHECK;
0123 int verbosity = std::max(Enable::VERBOSITY, Enable::HCALIN_VERBOSITY);
0124
0125 PHG4DetectorSubsystem *hcal = nullptr;
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 if (Enable::HCALIN_OLD)
0138 {
0139 hcal = new PHG4InnerHcalSubsystem("HCALIN");
0140
0141
0142 if (G4HCALIN::inner_hcal_material_Al)
0143 {
0144 if (verbosity > 0)
0145 {
0146 std::cout << "HCalInner - construct inner HCal absorber with G4_Al" << std::endl;
0147 }
0148 hcal->set_string_param("material", "G4_Al");
0149 }
0150 else
0151 {
0152 if (verbosity > 0)
0153 {
0154 std::cout << "HCalInner - construct inner HCal absorber with SS310" << std::endl;
0155 }
0156 hcal->set_string_param("material", "SS310");
0157 }
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 }
0192 else
0193 {
0194 hcal = new PHG4IHCalSubsystem("HCALIN");
0195
0196 }
0197 if (G4HCALIN::light_scint_model >= 0)
0198 {
0199 hcal->set_int_param("light_scint_model", G4HCALIN::light_scint_model);
0200 }
0201 hcal->SetActive();
0202 hcal->SuperDetector("HCALIN");
0203 if (AbsorberActive) hcal->SetAbsorberActive();
0204 if (!std::isfinite(G4HCALIN::phistart))
0205 {
0206 if (Enable::HCALIN_OLD)
0207 {
0208 G4HCALIN::phistart = 0.0328877688;
0209 }
0210 else
0211 {
0212 G4HCALIN::phistart = 0.0445549893;
0213 }
0214 }
0215 hcal->set_int_param("saveg4hit", Enable::HCALIN_G4Hit);
0216 hcal->set_double_param("phistart", G4HCALIN::phistart);
0217 hcal->OverlapCheck(OverlapCheck);
0218
0219 g4Reco->registerSubsystem(hcal);
0220
0221 radius = hcal->get_double_param("outer_radius");
0222
0223
0224
0225 radius += no_overlapp;
0226 return radius;
0227 }
0228
0229 void HCALInner_Cells()
0230 {
0231 if (!Enable::HCALIN_G4Hit)
0232 {
0233 return;
0234 }
0235 int verbosity = std::max(Enable::VERBOSITY, Enable::HCALIN_VERBOSITY);
0236
0237 Fun4AllServer *se = Fun4AllServer::instance();
0238
0239 PHG4HcalCellReco *hc = new PHG4HcalCellReco("HCALIN_CELLRECO");
0240 hc->Detector("HCALIN");
0241 hc->Verbosity(verbosity);
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252 se->registerSubsystem(hc);
0253
0254 return;
0255 }
0256
0257 void HCALInner_Towers()
0258 {
0259 int verbosity = std::max(Enable::VERBOSITY, Enable::HCALIN_VERBOSITY);
0260 Fun4AllServer *se = Fun4AllServer::instance();
0261
0262 if (!Enable::HCALIN_TOWERINFO)
0263 {
0264 if (Enable::HCALIN_G4Hit)
0265 {
0266 HcalRawTowerBuilder *TowerBuilder = new HcalRawTowerBuilder("HcalInRawTowerBuilder");
0267 TowerBuilder->Detector("HCALIN");
0268 TowerBuilder->set_sim_tower_node_prefix("SIM");
0269 if (!std::isfinite(G4HCALIN::phistart))
0270 {
0271 if (Enable::HCALIN_OLD)
0272 {
0273 G4HCALIN::phistart = 0.0328877688;
0274 }
0275 else
0276 {
0277 G4HCALIN::phistart = 0.0445549893;
0278 }
0279 }
0280 TowerBuilder->set_double_param("phistart", G4HCALIN::phistart);
0281 if (std::isfinite(G4HCALIN::tower_emin))
0282 {
0283 TowerBuilder->set_double_param("emin", G4HCALIN::tower_emin);
0284 }
0285 if (G4HCALIN::tower_energy_source >= 0)
0286 {
0287 TowerBuilder->set_int_param("tower_energy_source", G4HCALIN::tower_energy_source);
0288 }
0289
0290
0291
0292
0293
0294 TowerBuilder->Verbosity(verbosity);
0295 se->registerSubsystem(TowerBuilder);
0296 }
0297
0298 RawTowerDigitizer *TowerDigitizer = new RawTowerDigitizer("HcalInRawTowerDigitizer");
0299 TowerDigitizer->Detector("HCALIN");
0300
0301 TowerDigitizer->set_digi_algorithm(G4HCALIN::TowerDigi);
0302 TowerDigitizer->set_pedstal_central_ADC(0);
0303 TowerDigitizer->set_pedstal_width_ADC(1);
0304 TowerDigitizer->set_photonelec_ADC(32. / 5.);
0305 TowerDigitizer->set_photonelec_yield_visible_GeV(32. / 5 / (0.4e-3));
0306 TowerDigitizer->set_zero_suppression_ADC(-0);
0307 TowerDigitizer->Verbosity(verbosity);
0308 if (!Enable::HCALIN_G4Hit)
0309 {
0310 TowerDigitizer->set_towerinfo(RawTowerDigitizer::ProcessTowerType::kTowerInfoOnly);
0311 }
0312 se->registerSubsystem(TowerDigitizer);
0313
0314
0315 double visible_sample_fraction_HCALIN = 0.0631283;
0316
0317 if (G4HCALIN::inner_hcal_material_Al)
0318 {
0319 visible_sample_fraction_HCALIN = 0.162166;
0320 }
0321
0322 RawTowerCalibration *TowerCalibration = new RawTowerCalibration("HcalInRawTowerCalibration");
0323 TowerCalibration->Detector("HCALIN");
0324 TowerCalibration->set_usetowerinfo_v2(G4HCALIN::useTowerInfoV2);
0325
0326
0327 TowerCalibration->set_calib_algorithm(RawTowerCalibration::kSimple_linear_calibration);
0328 if (G4HCALIN::TowerDigi == RawTowerDigitizer::kNo_digitization)
0329 {
0330
0331 TowerCalibration->set_calib_const_GeV_ADC(1. / 0.176);
0332 }
0333 else
0334 {
0335 TowerCalibration->set_calib_const_GeV_ADC(0.4e-3 / visible_sample_fraction_HCALIN);
0336 }
0337 TowerCalibration->set_pedstal_ADC(0);
0338 TowerCalibration->Verbosity(verbosity);
0339 if (!Enable::HCALIN_G4Hit)
0340 {
0341 TowerCalibration->set_towerinfo(RawTowerCalibration::ProcessTowerType::kTowerInfoOnly);
0342 }
0343 se->registerSubsystem(TowerCalibration);
0344 }
0345 else
0346 {
0347 CaloWaveformSim *caloWaveformSim = new CaloWaveformSim();
0348 caloWaveformSim->set_detector_type(CaloTowerDefs::HCALIN);
0349 caloWaveformSim->set_detector("HCALIN");
0350 caloWaveformSim->set_nsamples(12);
0351 caloWaveformSim->set_pedestalsamples(12);
0352 caloWaveformSim->set_timewidth(0.2);
0353 caloWaveformSim->set_peakpos(6);
0354
0355
0356 se->registerSubsystem(caloWaveformSim);
0357
0358 CaloTowerBuilder *ca2 = new CaloTowerBuilder();
0359 ca2->set_detector_type(CaloTowerDefs::HCALIN);
0360 ca2->set_nsamples(12);
0361 ca2->set_dataflag(false);
0362 ca2->set_processing_type(CaloWaveformProcessing::TEMPLATE);
0363 ca2->set_builder_type(CaloTowerDefs::kWaveformTowerSimv1);
0364 ca2->set_softwarezerosuppression(true, 30);
0365 se->registerSubsystem(ca2);
0366
0367 CaloTowerStatus *statusHCALIN = new CaloTowerStatus("HCALINSTATUS");
0368 statusHCALIN->set_detector_type(CaloTowerDefs::HCALIN);
0369 statusHCALIN->set_time_cut(2);
0370 se->registerSubsystem(statusHCALIN);
0371
0372 CaloTowerCalib *calibIHCal = new CaloTowerCalib("HCALINCALIB");
0373 calibIHCal->set_detector_type(CaloTowerDefs::HCALIN);
0374 calibIHCal->set_outputNodePrefix("TOWERINFO_CALIB_");
0375 se->registerSubsystem(calibIHCal);
0376 }
0377 return;
0378 }
0379
0380 void HCALInner_Clusters()
0381 {
0382 int verbosity = std::max(Enable::VERBOSITY, Enable::HCALIN_VERBOSITY);
0383
0384 Fun4AllServer *se = Fun4AllServer::instance();
0385
0386 if (G4HCALIN::HCalIn_clusterizer == G4HCALIN::kHCalInTemplateClusterizer)
0387 {
0388 RawClusterBuilderTemplate *ClusterBuilder = new RawClusterBuilderTemplate("HcalInRawClusterBuilderTemplate");
0389 ClusterBuilder->Detector("HCALIN");
0390 ClusterBuilder->SetCylindricalGeometry();
0391 ClusterBuilder->Verbosity(verbosity);
0392 if (!Enable::HCALIN_G4Hit || Enable::HCALIN_TOWERINFO)
0393 {
0394 ClusterBuilder->set_UseTowerInfo(1);
0395 }
0396 se->registerSubsystem(ClusterBuilder);
0397 }
0398 else if (G4HCALIN::HCalIn_clusterizer == G4HCALIN::kHCalInGraphClusterizer)
0399 {
0400 RawClusterBuilderGraph *ClusterBuilder = new RawClusterBuilderGraph("HcalInRawClusterBuilderGraph");
0401 ClusterBuilder->Detector("HCALIN");
0402 ClusterBuilder->Verbosity(verbosity);
0403
0404 se->registerSubsystem(ClusterBuilder);
0405 }
0406 else
0407 {
0408 std::cout << "HCalIn_Clusters - unknown clusterizer setting!" << std::endl;
0409 exit(1);
0410 }
0411 return;
0412 }
0413
0414 void HCALInner_Eval(const std::string &outputfile, int start_event = 0)
0415 {
0416 int verbosity = std::max(Enable::VERBOSITY, Enable::HCALIN_VERBOSITY);
0417 Fun4AllServer *se = Fun4AllServer::instance();
0418
0419 CaloEvaluator *eval = new CaloEvaluator("HCALINEVALUATOR", "HCALIN", outputfile);
0420 eval->set_event(start_event);
0421 eval->Verbosity(verbosity);
0422 eval->set_use_towerinfo(Enable::HCALIN_TOWERINFO);
0423 se->registerSubsystem(eval);
0424
0425 return;
0426 }
0427
0428 void HCALInner_QA()
0429 {
0430 int verbosity = std::max(Enable::QA_VERBOSITY, Enable::HCALIN_VERBOSITY);
0431
0432 Fun4AllServer *se = Fun4AllServer::instance();
0433 QAG4SimulationCalorimeter *qa = new QAG4SimulationCalorimeter("HCALIN");
0434 if (Enable::HCALIN_TOWERINFO)
0435 {
0436 qa->set_flags(QAG4SimulationCalorimeter::kProcessTowerinfo);
0437 }
0438 qa->Verbosity(verbosity);
0439 se->registerSubsystem(qa);
0440
0441 return;
0442 }
0443
0444 #endif