18namespace ADD_CMODE(CP)
21 MuonCalibIntScaleSmearTool::MuonCalibIntScaleSmearTool(
const std::string &name) :
asg::AsgTool(name)
24 StatusCode MuonCalibIntScaleSmearTool::initialize()
36 for(
const auto & param: m_paramList)
48 m_currentParameters =
nullptr;
50 m_Parameters.initialize(affectingSystematics(), [
this](
const CP::SystematicSet &systConfig, ParameterSetScaleSmear ¶m)
51 {
return calcSystematicVariation(systConfig, param); });
55 return StatusCode::FAILURE;
58 if (registry.registerSystematics(*
this) != StatusCode::SUCCESS)
61 return StatusCode::FAILURE;
64 return StatusCode::SUCCESS;
73 auto IDcorrConstants = getConstants(mu.ID, m_IDparams.at(mu.ID.year), m_currentParameters->m_IDparams);
74 auto MEcorrConstants = getConstants(mu.ME, m_MEparams.at(mu.ME.year), m_currentParameters->m_MEparams);
75 auto CBcorrConstants = getConstants(mu.CB, m_CBparams.at(mu.CB.year), m_currentParameters->m_CBparams);
77 double corrIDpT = getCorrectedPt(mu, mu.ID, IDcorrConstants);
78 double corrMEpT = getCorrectedPt(mu, mu.ME, MEcorrConstants);
79 double corrCBpT = getCorrectedPt(mu, mu.CB, CBcorrConstants);
88 double corrCBpTWithIDME = getCorrectedCBPtWithIDMSComb(mu, IDcorrConstants, MEcorrConstants);
92 mu.ID.calib_pt = corrIDpT * ((corrIDpT < -0.1) ? -1 : 1);
93 mu.ME.calib_pt = corrMEpT * ((corrMEpT < -0.1) ? -1 : 1);
94 mu.CB.calib_pt = corrCBpT * ((corrCBpT < -0.1) ? -1 : 1);
96 mu.ID.calib_charge = mu.ID.uncalib_charge * ((corrIDpT < -0.1) ? -1 : 1);
97 mu.ME.calib_charge = mu.ME.uncalib_charge * ((corrMEpT < -0.1) ? -1 : 1);
98 mu.CB.calib_charge = mu.CB.uncalib_charge * ((corrCBpT < -0.1) ? -1 : 1);
100 if(m_calibMode == MuonCalibTool::correctData_IDMS || m_calibMode == MuonCalibTool::notCorrectData_IDMS) {
101 mu.CB.calib_pt = corrCBpTWithIDME * ((corrCBpTWithIDME < -0.1) ? -1 : 1);
102 mu.CB.calib_charge = mu.CB.uncalib_charge * ((corrCBpTWithIDME < -0.1) ? -1 : 1);
104 else if(m_calibMode == MuonCalibTool::correctData_IDonly) {
105 mu.CB.calib_pt = mu.ID.calib_pt;
106 mu.CB.calib_charge = mu.ID.calib_charge;
108 else if(m_calibMode == MuonCalibTool::correctData_MSonly) {
109 mu.CB.calib_pt = mu.ME.calib_pt;
110 mu.CB.calib_charge = mu.ME.calib_charge;
117 std::map<MCP::ScaleSmearParam, double> MuonCalibIntScaleSmearTool::getConstants(
const MCP::TrackCalibObj& trk,
const std::map<MCP::ScaleSmearParam, ScaleSmearCorrConstMap>&
constants,
const std::map<MCP::ScaleSmearParam, double>& direction)
const
120 std::map<MCP::ScaleSmearParam, double> calibConstants;
123 for(
const auto& param: m_paramList)
125 const auto & contantList =
constants.at(param);
140 val = std::max(0.0, val);
143 calibConstants[param] = val;
146 return calibConstants;
150 double MuonCalibIntScaleSmearTool::getCorrectedPt(
const MCP::MuonObj& mu,
const MCP::TrackCalibObj& trk,
const std::map<MCP::ScaleSmearParam, double>& calibConstant)
const
178 double additional_weight = 1.;
179 if (std::abs(trk.
eta) > 2) additional_weight = sinh(trk.
eta);
181 return r1 * mu.rnd_g3 + r2 * mu.rnd_g4 * pT * additional_weight;
183 return r0 * mu.rnd_g0 / pT + r1 * mu.rnd_g1 + r2 * mu.rnd_g2 * pT;
187 double MuonCalibIntScaleSmearTool::getCorrectedCBPtWithIDMSComb(
const MCP::MuonObj& mu,
const std::map<MCP::ScaleSmearParam, double>& calibIDConstant,
const std::map<MCP::ScaleSmearParam, double>& calibMEConstant)
const
190 double weightID = 0.5;
191 double weightME = 0.5;
193 double deltaCBME = mu.CB.calib_pt - mu.ME.calib_pt;
194 double deltaCBID = mu.CB.calib_pt - mu.ID.calib_pt;
196 if (mu.ME.calib_pt == 0)
201 else if (mu.ID.calib_pt == 0)
206 else if (mu.CB.calib_pt != 0)
208 if (std::abs(deltaCBME) > 0 || std::abs(deltaCBID) > 0)
210 double R = 1, Rplus = 1;
211 if (std::abs(deltaCBME) == std::abs(deltaCBID))
215 else if (std::abs(deltaCBME) != 0 &&
216 std::abs(deltaCBME) > std::abs(deltaCBID)) {
217 R = (-deltaCBID) / deltaCBME;
219 if (Rplus != 0 && R > 0) {
220 weightID = 1 / Rplus;
221 weightME = R / Rplus;
224 else if (std::abs(deltaCBID) != 0 &&
225 std::abs(deltaCBME) < std::abs(deltaCBID)) {
226 R = (-deltaCBME) / (deltaCBID);
228 if (Rplus != 0 && R > 0) {
229 weightID = R / Rplus;
230 weightME = 1 / Rplus;
236 if(weightID == 0.5 && weightME == 0.5)
238 if(mu.expectedPercentResME<std::numeric_limits<double>::epsilon() ||
239 mu.CB.calib_pt<std::numeric_limits<double>::epsilon() || mu.expectedPercentResID<std::numeric_limits<double>::epsilon() ){
240 ATH_MSG_VERBOSE(
"Potential FPE caught! Continue with averaging ID+MS");
241 ATH_MSG_VERBOSE(
"mu.expectedPercentResME = "<<mu.expectedPercentResME);
242 ATH_MSG_VERBOSE(
"mu.expectedPercentResID = "<<mu.expectedPercentResID);
245 double wME = mu.ME.calib_pt / mu.CB.calib_pt / std::pow(mu.expectedPercentResME, 2);
246 double wID = mu.ID.calib_pt / mu.CB.calib_pt / std::pow(mu.expectedPercentResID, 2);
247 weightID = wID / (wME + wID);
248 weightME = wME / (wME + wID);
256 double smearCorr = weightID * smearIDCorr + weightME * smearMECorr;
277 double pT = mu.CB.calib_pt;
278 double corrpT = (pT + pT * scaleCB)/(1 + smearCorr);
287 return sys.find(systematic) != sys.end();
296 if (m_calibMode == MuonCalibTool::correctData_CB || m_calibMode == MuonCalibTool::notCorrectData_CB || m_sysScheme ==
"AllSys") {
301 if (m_calibMode == MuonCalibTool::correctData_IDMS || m_calibMode == MuonCalibTool::notCorrectData_IDMS || m_calibMode == MuonCalibTool::correctData_IDonly || m_sysScheme ==
"AllSys") {
306 if (m_calibMode == MuonCalibTool::correctData_IDMS || m_calibMode == MuonCalibTool::notCorrectData_IDMS || m_calibMode == MuonCalibTool::correctData_MSonly || m_sysScheme ==
"AllSys") {
315 if (m_sysScheme ==
"Corr_Scale") {
319 else if (m_sysScheme ==
"Decorr_Scale" || m_sysScheme ==
"AllSys") {
321 if (m_calibMode == MuonCalibTool::correctData_CB || m_calibMode == MuonCalibTool::notCorrectData_CB || m_sysScheme ==
"AllSys") {
330 if (m_calibMode == MuonCalibTool::correctData_IDMS || m_calibMode == MuonCalibTool::notCorrectData_IDMS || m_calibMode == MuonCalibTool::correctData_IDonly || m_sysScheme ==
"AllSys") {
336 if (m_calibMode == MuonCalibTool::correctData_IDMS || m_calibMode == MuonCalibTool::notCorrectData_IDMS || m_calibMode == MuonCalibTool::correctData_MSonly || m_sysScheme ==
"AllSys") {
351 CP::SystematicSet MuonCalibIntScaleSmearTool::recommendedSystematics()
const {
return affectingSystematics(); }
353 StatusCode MuonCalibIntScaleSmearTool::calcSystematicVariation(
const CP::SystematicSet &systConfig, ParameterSetScaleSmear ¶m)
const
385 }
else if (!syst.
empty())
return StatusCode::FAILURE;
398 }
else if (!syst.
empty())
return StatusCode::FAILURE;
411 }
else if (!syst.
empty())
return StatusCode::FAILURE;
435 }
else if (!syst.
empty())
return StatusCode::FAILURE;
446 }
else if (!syst.
empty())
return StatusCode::FAILURE;
454 }
else if (!syst.
empty())
return StatusCode::FAILURE;
462 }
else if (!syst.
empty())
return StatusCode::FAILURE;
470 }
else if (!syst.
empty())
return StatusCode::FAILURE;
478 }
else if (!syst.
empty())
return StatusCode::FAILURE;
480 return StatusCode::SUCCESS;
483 StatusCode MuonCalibIntScaleSmearTool::applySystematicVariation(
const CP::SystematicSet &systConfig)
485 return m_Parameters.get(systConfig, m_currentParameters);
489 double MuonCalibIntScaleSmearTool::getExpectedResolution(
const int &
DetType,
double pT,
double eta,
double phi,
MCP::DataYear year,
bool addMCCorrectionSmearing)
const
492 const auto & IDcorrConstants = m_IDparams.at(year);
493 const auto & MEcorrConstants = m_MEparams.at(year);
494 const auto & IDExpectedResConstants = m_IDExpectedResparams.at(year);
495 const auto & MEExpectedResConstants = m_MEExpectedResparams.at(year);
506 if (pT == 0)
return 1e12;
512 if(!addMCCorrectionSmearing)
528 p0 = std::sqrt(std::pow(expectedP0, 2) + std::pow(r0, 2));
529 p1 = std::sqrt(std::pow(expectedP1, 2) + std::pow(r1, 2));
530 p2 = std::sqrt(std::pow(expectedP2, 2) + std::pow(r2, 2));
533 expRes = std::sqrt(std::pow(p0 / pT, 2) + std::pow(p1, 2) + std::pow(p2 * pT, 2));
538 if (pT == 0)
return 1e12;
543 if(!addMCCorrectionSmearing)
548 if(p2Tan) p2 = p2Tan;
555 if(p2Tan) expectedP2 = p2Tan;
560 p1 = std::sqrt(std::pow(expectedP1, 2) + std::pow(r1, 2));
561 p2 = std::sqrt(std::pow(expectedP2, 2) + std::pow(r2, 2));
563 if(p2Tan) p2 = p2 * std::sinh(
eta) * std::sinh(
eta);
566 expRes = std::sqrt(std::pow(p1, 2) + std::pow(p2 * pT, 2));