File indexing completed on 2025-12-16 09:24:05
0001 #ifndef SYS_CALO_C
0002 #define SYS_CALO_C
0003
0004 #include <caloreco/CaloTowerCalib.h>
0005
0006 #include <ffamodules/CDBInterface.h>
0007 #include <fun4all/Fun4AllServer.h>
0008 #include <fun4all/SubsysReco.h>
0009
0010 R__LOAD_LIBRARY(libfun4all.so)
0011 R__LOAD_LIBRARY(libcalo_reco.so)
0012
0013
0014
0015
0016 namespace CALOSYS
0017 {
0018
0019 struct SysConfig {
0020 std::string label;
0021 std::string payload;
0022 bool do_calo[3];
0023 };
0024
0025 inline std::vector<SysConfig> default_variations()
0026 {
0027 return {
0028 {"EMCal calib unc up", "_calib_unc_up_syst", {true, false, false}},
0029 {"HCal calib unc up", "_calib_unc_up_syst", {false, true, true}},
0030 {"EMCal calib stat unc", "_calib_stat_syst", {true, false, false}},
0031 {"IHCal calib stat unc", "_calib_stat_syst", {false, true, false}},
0032 {"OHCal calib stat unc", "_calib_stat_syst", {false, false, true}},
0033
0034
0035
0036 {"Had Resp up", "_had_resp_up_syst", {true, true, true}},
0037 {"EMCal calib unc down", "_calib_unc_down_syst", {true, false, false}},
0038 {"HCal calib unc down", "_calib_unc_down_syst", {false, true, true}},
0039 {"Had Resp down", "_had_resp_down_syst", {true, true, true}},
0040 };
0041 }
0042
0043 static const std::string inputPrefix = "TOWERINFO_CALIB_";
0044 std::string detName[3] = {"CEMC","HCALIN","HCALOUT"};
0045
0046 }
0047
0048
0049
0050
0051 void Register_Tower_sys(int syst_index, const std::vector<CALOSYS::SysConfig>& variations)
0052 {
0053 size_t nsyst = variations.size();
0054 if(syst_index < 1 || syst_index > (int)nsyst) {
0055 std::cerr << "ERROR: Systematic index " << syst_index << " is out of range (1–" << nsyst << ")\n";
0056 return;
0057 }
0058
0059 Fun4AllServer* se = Fun4AllServer::instance();
0060 const CALOSYS::SysConfig& cfg = variations[syst_index - 1];
0061 const std::string outputPrefix = "TOWERINFO_CALIB_SYST" + std::to_string(syst_index) + "_";
0062
0063 for(int ic = 0; ic < 3; ++ic)
0064 {
0065 std::string det = CALOSYS::detName[ic];
0066 std::string fullPayload = det + "_no_calib_syst";
0067 if (cfg.do_calo[ic]) {
0068 fullPayload = det + cfg.payload;
0069 }
0070
0071 std::string caliburl = CDBInterface::instance()->getUrl(fullPayload);
0072 CaloTowerCalib* calib = new CaloTowerCalib("CaloCalib_syst_" + det + "_" + std::to_string(syst_index));
0073 calib->set_inputNodePrefix(CALOSYS::inputPrefix);
0074 calib->set_outputNodePrefix(outputPrefix);
0075 calib->set_directURL(caliburl);
0076 calib->setFieldName("calo_sys");
0077 calib->set_doCalibOnly(true);
0078
0079 if(ic == 0) calib->set_detector_type(CaloTowerDefs::CEMC);
0080 else if(ic == 1) calib->set_detector_type(CaloTowerDefs::HCALIN);
0081 else calib->set_detector_type(CaloTowerDefs::HCALOUT);
0082 se->registerSubsystem(calib);
0083 }
0084 }
0085
0086
0087
0088
0089 void Register_Tower_sys(int syst_index)
0090 {
0091 auto vars = CALOSYS::default_variations();
0092 std::cout << ">>> [Sys_Calo] Running ONE default systematic: index SYST" << syst_index << " of " << vars.size() << " (“" << vars[syst_index-1].label << "”)" << std::endl;
0093 Register_Tower_sys(syst_index, vars);
0094 }
0095
0096
0097
0098
0099 void Register_Tower_sys()
0100 {
0101 auto vars = CALOSYS::default_variations();
0102 std::cout << ">>> [Sys_Calo] Running ALL default systematics (" << vars.size() << " variations)" << std::endl;
0103 for (size_t i = 1; i <= vars.size(); ++i) {
0104 std::cout << ">>> Running SYST" << i << " / " << vars.size() << " (“" << vars[i-1].label << "”)" << std::endl;
0105 Register_Tower_sys(i, vars);
0106 }
0107 }
0108
0109
0110
0111
0112 void Register_Tower_sys(const std::vector<CALOSYS::SysConfig>& vars)
0113 {
0114 std::cout << ">>> [Sys_Calo] Running ALL USER-PROVIDED systematics (" << vars.size() << " variations)" << std::endl;
0115 for (size_t i = 1; i <= vars.size(); ++i)
0116 {
0117 std::cout << ">>> Running SYST" << i << " / " << vars.size() << " (“" << vars[i-1].label << "”)" << std::endl;
0118 Register_Tower_sys(i, vars);
0119 }
0120 }
0121
0122 #endif