10 #include <boost/format.hpp>
43 const double GeV = 1000.;
63 const std::string gain_filename2 =
PathResolverFindCalibFile(
"ElectronPhotonFourMomentumCorrection/v8/FunctionsG_all.root");
64 return std::make_unique<egGain::GainTool>(gain_filename1, gain_filename2);
91 folder =
"egammaMVACalib/v1";
94 folder =
"egammaMVACalib/v1";
100 folder =
"egammaMVACalib/offline/v3";
104 folder =
"egammaMVACalib/offline/v3_E4crack_bis";
113 folder =
"egammaMVACalib/offline/v4.0";
122 folder =
"egammaMVACalib/offline/v7";
132 std::string
tune =
"";
138 tune =
"2011_alt_with_layer2";
152 tune =
"2012_alt_with_layer2";
156 tune =
"es2017_20.7_improved";
159 tune =
"es2017_20.7_final";
166 tune =
"es2017_21.0_v0";
169 tune =
"es2018_21.0_v0";
174 return std::make_unique<egammaLayerRecalibTool>(
tune);
270 m_use_mapping_correction(false), m_currentScaleVariation_MC(
egEnergyCorr::
Scale::None),
272 m_currentResolutionVariation_MC(
egEnergyCorr::Resolution::Nominal),
273 m_currentResolutionVariation_data(
egEnergyCorr::Resolution::None),
278 return 1 +
static_cast<RandomNumber>(std::abs(
egamma.caloCluster()->
phi()) * 1E6 + std::abs(
egamma.caloCluster()->
eta()) * 1E3 + ei.eventNumber()); })
281 declareProperty(
"decorrelationModel", m_decorrelation_model_name =
"");
282 declareProperty(
"decorrelationModelScale", m_decorrelation_model_scale_name =
"");
283 declareProperty(
"decorrelationModelResolution", m_decorrelation_model_resolution_name =
"");
291 declareProperty(
"useLayer2Recalibration", m_useLayer2Recalibration = AUTO);
292 declareProperty(
"useIntermoduleCorrection", m_useIntermoduleCorrection = AUTO);
293 declareProperty(
"usePhiUniformCorrection", m_usePhiUniformCorrection = AUTO);
296 declareProperty(
"layerRecalibrationTune", m_layer_recalibration_tune =
"");
299 declareProperty(
"use_full_statistical_error", m_use_full_statistical_error=
false);
300 declareProperty(
"use_temp_correction201215", m_use_temp_correction201215=AUTO);
301 declareProperty(
"use_uA2MeV_2015_first2weeks_correction", m_use_uA2MeV_2015_first2weeks_correction=AUTO);
304 declareProperty(
"useFastSim", m_useFastSim = -1,
"This should be explicitly set by the user depending on the data type (int)0=full sim, (int)1=fast sim");
305 declareProperty(
"useAFII", m_use_AFII = -1,
"This is now deprecated. Kept for explicit error message for now");
346 return StatusCode::FAILURE;
350 return StatusCode::FAILURE;
358 return StatusCode::FAILURE;
362 ATH_MSG_ERROR(
"Property useAFII is deprecated. It is now replaced with useFastSim, which should be explicitly configured");
363 return StatusCode::FAILURE;
369 ATH_MSG_ERROR(
"Property useFastSim should be explicitly configured");
370 return StatusCode::FAILURE;
375 ATH_MSG_ERROR(
"Sample is FastSim but no AF3 calibration is available yet with es2022_R22_PRE recommendations. Please get in touch with the EGamma CP group in case you are using this");
376 return StatusCode::FAILURE;
394 ATH_MSG_WARNING(
"no decorrelation model specified, assuming full model");
404 return StatusCode::FAILURE;
416 return StatusCode::FAILURE;
426 return StatusCode::FAILURE;
430 ATH_MSG_FATAL(
"not information how to initialize the scale decorrelation model");
431 return StatusCode::FAILURE;
441 return StatusCode::FAILURE;
451 return StatusCode::FAILURE;
459 m_rootTool = std::make_unique<AtlasRoot::egammaEnergyCorrectionTool>();
462 return StatusCode::FAILURE;
500 std::ostringstream mva_service_name;
501 mva_service_name <<
"egammaMVASvc/service_mva_egamma_id" << (
void const *)
this;
503 ATH_CHECK(config_mva_service.addPrivateTool(
"ElectronTool", config_mva_electron));
504 ATH_CHECK(config_mva_service.addPrivateTool(
"UnconvertedPhotonTool", config_mva_unconverted));
505 ATH_CHECK(config_mva_service.addPrivateTool(
"ConvertedPhotonTool", config_mva_converted));
519 ATH_MSG_INFO(
"Layer recalibration already applied at cell level");
523 ATH_MSG_DEBUG(
"initializing layer recalibration tool (if needed)");
543 throw std::runtime_error(
"ep combination not supported yet");
556 ATH_MSG_ERROR(
"cannot instantiate gain tool for this model (you can only disable the gain tool, but not enable it)");
585 if (
registry.registerSystematics( *
this ) != StatusCode::SUCCESS )
return StatusCode::FAILURE;
587 return StatusCode::SUCCESS;
602 throw std::runtime_error(
"particle is not electron or photon");
621 return m_rootTool->resolution(
energy, cl_eta, cl_etaCalo, ptype, withCT,
false);
661 const double e = new_particle->
e();
670 const double e = new_particle->
e();
694 ATH_MSG_DEBUG(
"applying energy recalibration before E0|E1|E2|E3 = "
695 <<
input.caloCluster()->energyBE(0) <<
"|"
696 <<
input.caloCluster()->energyBE(1) <<
"|"
697 <<
input.caloCluster()->energyBE(2) <<
"|"
698 <<
input.caloCluster()->energyBE(3));
704 << Es0Acc(*
input.caloCluster()) <<
"|"
705 << Es1Acc(*
input.caloCluster()) <<
"|"
706 << Es2Acc(*
input.caloCluster()) <<
"|"
707 << Es3Acc(*
input.caloCluster()) <<
"|");
708 if (Es2Acc(*
input.caloCluster()) == 0 and Es1Acc(*
input.caloCluster()) == 0 and
709 Es3Acc(*
input.caloCluster()) == 0 and Es0Acc(*
input.caloCluster()) == 0 and
710 (std::abs(
input.eta()) < 1.37 or (std::abs(
input.eta()) > 1.55 and std::abs(
input.eta()) < 2.47)))
718 double addE2 = 0, addE3 = 0;
724 " but some layer info is not available,"
725 " from L2 : " <<
status%2 <<
" from L3 : " <<
status/2);
733 deco_E2(*
input.caloCluster()) =
input.caloCluster()->energyBE(2) + addE2;
734 deco_E3(*
input.caloCluster()) =
input.caloCluster()->energyBE(3) + addE3;
771 const auto cl_eta =
input.caloCluster()->eta();
773 if ((std::abs(cl_eta) >= 1.52 || std::abs(cl_eta) <= 1.37) and std::abs(cl_eta) < 2.4)
778 const double eraw = ((Es0Acc.
isAvailable(*
input.caloCluster()) ? Es0Acc(*
input.caloCluster()) :
input.caloCluster()->energyBE(0)) +
784 unsigned int runNumber_for_tool = 0;
789 if (randomrunnumber_getter.
isAvailable(event_info)) { runNumber_for_tool = randomrunnumber_getter(event_info); }
791 ATH_MSG_ERROR(
"Pileup tool not run before using ElectronPhotonFourMomentumCorrection! Assuming it is 2016. If you "
792 "want to force a specific period set the property randomRunNumber of the tool, e.g. in the job option: "
793 "tool.randomRunNumber = 123456 or "
794 "tool.randomRunNumber = EgammaCalibrationAndSmearingToolRunNumbersExample.run_2016");
812 input.caloCluster()->eta(),
828 const double p2 = new_energy2 >
m2 ? new_energy2 -
m2 : 0.;
862 const float el_tracketa = eTrack->
eta();
863 const float el_trackmomentum = eTrack->
pt() * cosh(
el->eta());
875 return sys.find( systematic ) !=
sys.end();
883 return affecting_systematics;
903 #define SYSMACRO(name, fullcorrelated, decorrelation, flagup, flagdown) \
904 m_syst_description[CP::SystematicVariation(#name, +1)] = SysInfo{always, flagup}; \
905 m_syst_description[CP::SystematicVariation(#name, -1)] = SysInfo{always, flagdown};
906 #include "ElectronPhotonFourMomentumCorrection/systematics.def"
996 #define SYSMACRO(name, fullcorrelated, decorrelation, flagup, flagdown) \
997 m_syst_description[CP::SystematicVariation(#name, +1)] = SysInfo{always, flagup}; \
998 m_syst_description[CP::SystematicVariation(#name, -1)] = SysInfo{always, flagdown};
999 #include "ElectronPhotonFourMomentumCorrection/systematics_1NPCOR_PLUS_UNCOR.def"
1010 using pairvector = std::vector<std::pair<double, double>>;
1011 const pairvector decorrelation_bins_BE = {{0., 1.45}, {1.52, 2.5}};
1012 const std::vector<double> decorrelation_edges_TWELVE = {0., 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4};
1013 const std::vector<double> decorrelation_edges_MODULE = {0., 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.37, 1.52, 1.8};
1014 const std::vector<double> decorrelation_edges_MATERIAL = {0.0, 1.1, 1.5, 2.1, 2.5};
1016 std::vector<double> decorrelation_edges_S12;
1019 decorrelation_edges_S12.resize(5);
1020 decorrelation_edges_S12={0.,1.35,1.5,2.4,2.5};
1024 decorrelation_edges_S12.resize(6);
1025 decorrelation_edges_S12={0., 0.6, 1.4, 1.5, 2.4, 2.5};
1029 #define SYSMACRO(name, fullcorrelated, decorrelation, flagup, flagdown) \
1030 if (bool(fullcorrelated)) { \
1031 m_syst_description[CP::SystematicVariation(#name, +1)] = SysInfo{always, flagup}; \
1032 m_syst_description[CP::SystematicVariation(#name, -1)] = SysInfo{always, flagdown}; \
1036 for (const auto& p : AbsEtaCaloPredicatesFactory(decorrelation)) { \
1037 m_syst_description[CP::SystematicVariation(#name "__ETABIN" + std::to_string(i), +1)] = SysInfo{p, flagup}; \
1038 m_syst_description[CP::SystematicVariation(#name "__ETABIN" + std::to_string(i), -1)] = SysInfo{p, flagdown}; \
1042 #include "ElectronPhotonFourMomentumCorrection/systematics.def"
1046 #define SYSMACRO(name, fullcorrelated, decorrelation, flagup, flagdown) \
1047 if (bool(fullcorrelated)) { \
1048 m_syst_description[CP::SystematicVariation(#name, +1)] = SysInfo{always, flagup}; \
1049 m_syst_description[CP::SystematicVariation(#name, -1)] = SysInfo{always, flagdown}; \
1053 for (const auto& p : AbsEtaCaloPredicatesFactory(decorrelation)) { \
1054 m_syst_description[CP::SystematicVariation(#name "__ETABIN" + std::to_string(i), +1)] = SysInfo{p, flagup}; \
1055 m_syst_description[CP::SystematicVariation(#name "__ETABIN" + std::to_string(i), -1)] = SysInfo{p, flagdown}; \
1059 #include "ElectronPhotonFourMomentumCorrection/systematics_S12.def"
1066 const TAxis& axis_statistical_error(
m_rootTool->get_ZeeStat_eta_axis());
1067 for (
int ibin = 1; ibin <= axis_statistical_error.GetNbins(); ++ibin) {
1069 axis_statistical_error.GetBinLowEdge(ibin + 1));
1238 if (systConfig.
empty())
return StatusCode::SUCCESS;
1242 bool first_scale =
true;
1243 bool first_resolution =
true;
1244 for (
const auto&
it : systConfig) {
1247 if (not first_scale) {
1249 throw std::runtime_error(
"multiple scale variations not supported");
1251 first_scale =
false;
1258 if (not first_resolution) {
1259 ATH_MSG_ERROR(
"multiple resolution variations not supported");
1260 throw std::runtime_error(
"multiple resolution variations not supported");
1262 first_resolution =
false;
1267 return StatusCode::SUCCESS;
1276 double Ecl_corr = 0.;
1284 phi_mod = fmod(
phi, 2 *
pi / 16.) +
pi / 8.;
1286 phi_mod = fmod(
phi, 2 *
pi / 16.);
1289 if(std::abs(
eta) <= 1.37){
1292 Ecl_corr = Ecl / (1-0.1086 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 175.2759))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-189.3612))))));
1294 Ecl_corr = Ecl / (1-0.0596 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 170.8305))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-233.3782))))));
1296 Ecl_corr = Ecl / (1-0.0596 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 147.1451))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-139.3386))))));
1298 Ecl_corr = Ecl / (1-0.0583 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 168.4644))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-246.2897))))));
1300 Ecl_corr = Ecl / (1-0.0530 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 177.6703))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-198.3227))))));
1302 Ecl_corr = Ecl / (1-0.0672 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 145.0693))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-242.1771))))));
1304 Ecl_corr = Ecl / (1-0.0871 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 132.3303))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-166.1833))))));
1306 Ecl_corr = Ecl / (1-0.0948 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 127.6780))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-150.0700))))));
1308 Ecl_corr = Ecl / (1-0.1166 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 172.0679))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-235.3293))))));
1310 Ecl_corr = Ecl / (1-0.1172 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 190.3524))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-198.9400))))));
1312 Ecl_corr = Ecl / (1-0.1292 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 158.0540))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-165.3893))))));
1314 Ecl_corr = Ecl / (1-0.1557 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 162.2793))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-133.5131))))));
1316 Ecl_corr = Ecl / (1-0.1659 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 180.5270))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-168.5074))))));
1318 Ecl_corr = Ecl / (1-0.1123 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 128.2277))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-154.4455))))));
1320 Ecl_corr = Ecl / (1-0.1394 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 192.1216))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-198.0727))))));
1322 Ecl_corr = Ecl / (1-0.1001 * ((1 / (1 +
exp((phi_mod- 2*
pi/32.) * 199.1735))) * (1 / (1 +
exp((phi_mod- 2*
pi/32.) * (-176.4056))))));
1337 DivInt = (
int) (
phi / ((2 *
pi) / 16.));
1338 double phi_mod =
phi - DivInt * (2 *
pi / 16.);
1342 if (phi_mod < 0) phi_mod +=
pi / 8.;
1345 if(std::abs(
eta) <= 1.4){
1349 Ecl_corr = Ecl / (1-0.131 * ((1 / (1 +
exp((phi_mod-0.2) * 199.08))) * (1 / (1 +
exp((phi_mod-0.2) * (-130.36))))));
1353 if(phi < pi / 4. && phi >= -
pi / 4.){
1354 Ecl_corr = Ecl / (1-0.0879 * ((1 / (1 +
exp((phi_mod-0.2) * 221.01))) * (1 / (1 +
exp((phi_mod-0.2) * (-149.51))))));
1357 if(phi < -pi / 4. && phi >= (-3 *
pi) / 4.){
1358 Ecl_corr = Ecl / (1-0.0605 * ((1 / (1 +
exp((phi_mod-0.2) * 281.37))) * (1 / (1 +
exp((phi_mod-0.2) * (-170.29))))));
1361 if((
phi < (-3 *
pi) / 4.) || (
phi >= (3 *
pi) / 4.)){
1362 Ecl_corr = Ecl / (1-0.102 * ((1 / (1 +
exp((phi_mod-0.2) * 235.37))) * (1 / (1 +
exp((phi_mod-0.2) * (-219.04))))));
1378 constexpr
double PI =
M_PI;
1383 if (eta < -0.4 && eta > -0.6) {
1384 if (
phi < (14 *
PI / 32.) &&
phi > (13 *
PI / 32.)) { Fcorr += 0.035; }
1385 else if (
phi < (13 *
PI / 32.) &&
phi > (12 *
PI / 32.)) { Fcorr -= 0.035; }
1391 if(eta < 0.2 && eta > 0.) {
1392 if (
phi < (-7 * 2 *
PI / 32.) &&
phi > (-8 * 2 *
PI / 32.)) { Fcorr = 1.016314; }
1395 else if (eta < 0.6 && eta > 0.4) {
1396 if (phi < 0 && phi > (-2 *
PI / 32.)) { Fcorr = 1.041591; }
1397 else if (
phi < (-4 * 2 *
PI / 32.) &&
phi > (-5 * 2 *
PI / 32.)) { Fcorr = 1.067346; }
1400 else if (eta < 0.8 && eta > 0.6) {
1401 if (
phi < (7 * 2 *
PI / 32.) &&
phi > (6 * 2 *
PI / 32.)) { Fcorr = 1.027980; }
1404 else if (eta < 1.4 && eta > 1.2) {
1405 if (
phi < (-9 * 2 *
PI / 32.) &&
phi > (-10 * 2 *
PI / 32.)) { Fcorr = 1.020299; }
1406 else if (
phi < (-11 * 2 *
PI / 32.) &&
phi > (-12 * 2 *
PI / 32.)) { Fcorr = 1.051426; }
1409 else if (eta < 2.3 && eta > 2.1) {
1410 if (
phi < (-12 * 2 *
PI / 32.) &&
phi > (-13 * 2 *
PI / 32.)) { Fcorr = 1.071695; }
1413 else if(eta < 0. && eta > -0.2) {
1414 if (
phi < (-12 * 2 *
PI / 32.) &&
phi > (-13 * 2 *
PI / 32.)) { Fcorr = 1.008227; }
1415 else if (
phi < (-8 * 2 *
PI / 32.) &&
phi > (-9 * 2 *
PI / 32.)) { Fcorr = 1.013929; }
1418 else if(eta < -0.2 && eta > -0.4) {
1419 if (
phi < (-9 * 2 *
PI / 32.) &&
phi > (-10 * 2 *
PI / 32.)) { Fcorr = 1.015749; }
1422 else if(eta < -1.2 && eta > -1.4) {
1423 if (
phi < (-6 * 2 *
PI / 32.) &&
phi > (-7 * 2 *
PI / 32.)) { Fcorr = 1.064954; }
1426 else if (eta < -1.6 && eta > -1.8 ) {
1427 if (
phi < (9 * 2 *
PI / 32.) &&
phi > (8 * 2 *
PI / 32.)) { Fcorr = 1.027448; }
1430 else if(eta < -2.3 && eta > -2.5) {
1431 if (
phi < (-8 * 2 *
PI / 32.) &&
phi > (-9 * 2 *
PI / 32.)) { Fcorr = 1.025882; }
1432 else if (
phi < (5 * 2 *
PI / 32.) &&
phi > (4 * 2 *
PI / 32.)) { Fcorr = 1.036616; }
1433 else if (
phi < (9 * 2 *
PI / 32.) &&
phi > (8 * 2 *
PI / 32.)) { Fcorr = 1.053838; }
1434 else if (
phi < (10 * 2 *
PI / 32.) &&
phi > (9 * 2 *
PI / 32.)) { Fcorr = 1.026856; }
1435 else if (
phi < (11 * 2 *
PI / 32.) &&
phi > (10 * 2 *
PI / 32.)) { Fcorr = 0.994382; }
1441 if (eta < 0.6 && eta > 0.4) {
1442 if (phi < 0 && phi > (-2 *
PI / 32.)) { Fcorr = 1.028; }
1443 else if (
phi < (-4 * 2 *
PI / 32.) &&
phi > (-5 * 2 *
PI / 32.)) { Fcorr = 1.044; }
1446 else if (eta < 0.8 && eta > 0.6) {
1447 if (
phi < (7 * 2 *
PI / 32.) &&
phi > (6 * 2 *
PI / 32.)) { Fcorr = 1.022; }
1450 else if (eta < 1.4 && eta > 1.2) {
1451 if (
phi < (-11 * 2 *
PI / 32.) &&
phi > (-12 * 2 *
PI / 32.)) { Fcorr = 1.038; }
1454 else if (eta < 2.0 && eta > 1.9 ) {
1455 if (
phi < (10 * 2 *
PI / 32.) &&
phi > (9 * 2 *
PI / 32.)) { Fcorr = 1.029; }
1458 else if(eta < -1.2 && eta > -1.4) {
1459 if (
phi < (-4 * 2 *
PI / 32.) &&
phi > (-5 * 2 *
PI / 32.)) { Fcorr = 1.048; }
1460 else if (
phi < (-6 * 2 *
PI / 32.) &&
phi > (-7 * 2 *
PI / 32.)) { Fcorr = 1.048; }
1463 else if (eta < -1.6 && eta > -1.8 ) {
1464 if (
phi < (9 * 2 *
PI / 32.) &&
phi > (8 * 2 *
PI / 32.)) { Fcorr = 1.024; }
1467 else if(eta < -2.3 && eta > -2.5) {
1468 if (
phi < (-8 * 2 *
PI / 32.) &&
phi > (-9 * 2 *
PI / 32.)) { Fcorr = 1.037; }
1469 else if (
phi < (5 * 2 *
PI / 32.) &&
phi > (4 * 2 *
PI / 32.)) { Fcorr = 1.031; }
1470 else if (
phi < (9 * 2 *
PI / 32.) &&
phi > (8 * 2 *
PI / 32.)) { Fcorr = 1.040; }
1471 else if (
phi < (10 * 2 *
PI / 32.) &&
phi > (9 * 2 *
PI / 32.)) { Fcorr = 1.030; }
1472 else if (
phi < (11 * 2 *
PI / 32.) &&
phi > (10 * 2 *
PI / 32.)) { Fcorr = 1.020; }