18namespace ADD_CMODE(CP)
21 MuonCalibIntSagittaTool::MuonCalibIntSagittaTool(
const std::string &name) :
asg::AsgTool(name)
24 StatusCode MuonCalibIntSagittaTool::initialize()
46 m_currentParameters =
nullptr;
48 m_Parameters.initialize(affectingSystematics(), [
this](
const CP::SystematicSet &systConfig, ParameterSetSagitta ¶m)
49 {
return calcSystematicVariation(systConfig, param); });
53 return StatusCode::FAILURE;
56 if (registry.registerSystematics(*
this) != StatusCode::SUCCESS)
59 return StatusCode::FAILURE;
62 return StatusCode::SUCCESS;
72 double corrIDpT = mu.ID.calib_pt;
73 applySagittaCorrection(corrIDpT, IDCorrections, mu.ID.calib_charge, mu.ID.isData);
75 double corrMEpT = mu.ME.calib_pt;
76 applySagittaCorrection(corrMEpT, MECorrections, mu.ME.calib_charge, mu.ME.isData);
78 double corrDirectCBpT = mu.CB.calib_pt;
79 applySagittaCorrection(corrDirectCBpT, CBCorrections, mu.CB.calib_charge, mu.CB.isData);
82 double corrStatCombCBpT = statCombCorrection(mu, corrIDpT, corrMEpT, mu.CB.calib_pt);
89 double central(45.2),
width(15.5);
95 double sigmaID = mu.expectedResID;
96 double sigmaME = mu.expectedResME;
97 double denominator = mu.CB.calib_pt * std::sqrt(sigmaID * sigmaID + sigmaME * sigmaME);
98 double res = denominator ? M_SQRT2 * sigmaID * sigmaME / denominator : 0.;
102 central += std::abs(0.5 *
res * central);
105 central -= std::abs(0.5 *
res * central);
112 double sigmas = std::max(1.,(std::abs(mu.CB.calib_pt - central) /
width));
116 else rho = m_fixedRhoValue;
119 double corrCBpT = rho * corrDirectCBpT + (1 - rho) * corrStatCombCBpT;
121 ATH_MSG_DEBUG(
"Saggita correction - corrDirectCBpT: " << corrDirectCBpT <<
" corrStatCombCBpT: " << corrStatCombCBpT <<
" rho " << rho<<
" corrCBPt: "<<corrCBpT);
124 mu.ID.calib_pt = corrIDpT;
125 mu.ME.calib_pt = corrMEpT;
127 if(m_calibMode == MuonCalibTool::correctData_CB) mu.CB.calib_pt = corrCBpT;
128 else if(m_calibMode == MuonCalibTool::correctData_IDMS) mu.CB.calib_pt = corrStatCombCBpT;
129 else if(m_calibMode == MuonCalibTool::correctData_IDonly) mu.CB.calib_pt = corrIDpT;
130 else if(m_calibMode == MuonCalibTool::correctData_MSonly) mu.CB.calib_pt = corrMEpT;
137 void MuonCalibIntSagittaTool::applySagittaCorrection(
double& pt,
const std::vector<double>& correction,
const int&
charge,
const bool& isData)
const
139 for(
const auto& corr: correction)
141 double originalPt = pt;
142 if(isData) pt = pt / (1 +
charge * corr * pt);
143 else pt = pt / (1 -
charge * corr * pt);
144 ATH_MSG_DEBUG(
"CorrectForCharge - in pT: " << originalPt <<
" corrPt: " << pt <<
" applied saggita: " << corr);
151 std::vector<double> MuonCalibIntSagittaTool::getCorrections(
const MCP::TrackCalibObj& trk)
const
155 SagittaCorrConstMap
const *corrMap{
nullptr};
156 SagittaCorrConstMap
const *kinematicTermMap{
nullptr};
159 corrMap = &m_sagittaCorrConst_CB.at(trk.
year);
160 kinematicTermMap = &m_sagittaCorrConst_mcCB.at(trk.
year);
164 corrMap = &m_sagittaCorrConst_ID.at(trk.
year);
165 kinematicTermMap = &m_sagittaCorrConst_mcID.at(trk.
year);
169 corrMap = &m_sagittaCorrConst_ME.at(trk.
year);
170 kinematicTermMap = &m_sagittaCorrConst_mcME.at(trk.
year);
173 std::vector<double> corrections;
176 if(!m_applyCorrectionOnData)
return corrections;
177 else if (m_applyCorrectionOnData)
182 corrections.push_back(corr);
194 ATH_MSG_ERROR(
"Sagitta correction is not applied to data, yet Eta dependant systematics are requested. This configuration is not supported");
200 if(!m_applyCorrectionOnData)
209 corrections.push_back(corr);
221 corrections.push_back(corr);
228 double deltas = m_extraRebiasSys;
231 if(m_release.value().find(
"Recs2023") != std::string::npos) deltas = 1.2 * deltas;
232 else if(std::abs(
eta)>1.05) deltas = 1.5 * deltas;
234 double corr = deltas * scale;
237 corrections.push_back(corr);
251 double deltas = 0.00002;
256 corr += std::abs(450.0 - 45) * deltas;
258 corr += std::abs(pT - 45) * deltas;
261 if (
eta > 2 || (
eta > -2 &&
eta < -1.05)) {
263 corr += std::abs(450.0 - 45) / 100 * deltas;
265 corr += std::abs(pT - 45) / 100 * deltas;
269 corr += std::abs(450.0 - 45) / 200 * deltas;
271 corr += std::abs(pT - 45) / 200 * deltas;
274 if (m_release.value().find(
"Recs2023") != std::string::npos) {
277 else if (
eta < -1.05) corr += 1.1*deltas;
278 else if (
eta > 0.5 ) corr += 0.8*deltas;
282 if (
eta > -2 &&
eta < -1.05) corr = corr*2.5;
283 if (
eta < -2) corr = corr*6;
284 if (
eta > 1.5 &&
eta < 2) {
286 corr += std::abs(450.0 - 45) / 80 * deltas;
288 corr += std::abs(pT - 45) / 80 * deltas;
290 if (
eta > 1.05 &&
eta < 1.5) {
292 corr += std::abs(450.0 - 45) / 40 * deltas;
294 corr += std::abs(pT - 45) / 40 * deltas;
301 corrections.push_back(corr*scale);
302 ATH_MSG_VERBOSE(
"High pT variation for pT "<<pT<<
" deltas "<<deltas<<
" final corr: "<<corr);
312 corr *= (0.5 * scale);
314 corrections.push_back(corr);
330 double MuonCalibIntSagittaTool::statCombCorrection(
const MCP::MuonObj& mu,
double corrIDpT,
double corrMEpT,
double CBpT)
const
337 if(mu.ID.calib_pt == 0)
return CBpT;
338 if(mu.ME.calib_pt == 0)
return CBpT;
339 if(corrIDpT == 0)
return CBpT;
340 if(corrMEpT == 0)
return CBpT;
342 double chi2Nom = -999;
355 using TLV = ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>>;
356 TLV tlv{mu.ID.calib_pt, mu.ID.eta, mu.ID.phi, mu.ID.mass};
358 if(tlv.P() == 0) parsID[4] = 1e12;
359 else parsID[4] = 1.0 / (tlv.P() * 1e3);
361 tlv.SetCoordinates(mu.ME.calib_pt, mu.ME.eta, mu.ME.phi, mu.ME.mass);
363 if(tlv.P() == 0) parsMS[4] = 1e12;
364 else parsMS[4] = 1.0 / (tlv.P() * 1e3);
366 CP::CorrectionCode SysCorrCode = applyStatCombination(parsID, covID, parsMS, covMS, mu.CB.calib_charge, parsCBNom, covCBNom, chi2Nom);
372 tlv.SetCoordinates(corrIDpT, mu.ID.eta, mu.ID.phi, mu.ID.mass);
374 if(tlv.P() == 0) parsID[4] = 1e12;
375 else parsID[4] = 1.0 / (tlv.P() * 1e3);
377 tlv.SetCoordinates(corrMEpT, mu.ME.eta, mu.ME.phi, mu.ME.mass);
379 if(tlv.P() == 0) parsMS[4] = 1e12;
380 else parsMS[4] = 1.0 / (tlv.P() * 1e3);
382 SysCorrCode = applyStatCombination(parsID, covID, parsMS, covMS, mu.CB.calib_charge, parsCBCorr, covCBCorr, chi2Nom);
386 double statCombPtNom = std::sin(parsCBNom[3]) / std::abs(parsCBNom[4]);
387 double statCombPtCorr = std::sin(parsCBCorr[3]) / std::abs(parsCBCorr[4]);
388 double corrCBpT = CBpT * (statCombPtCorr / statCombPtNom);
397 parsID[4] = std::abs(parsID[4]);
398 parsMS[4] = std::abs(parsMS[4]);
402 if (!matID.isInvertible()) {
410 if (!matMS.isInvertible()) {
417 Eigen::FullPivLU<
AmgSymMatrix(5)> matCB(weightID + weightMS);
418 if (!matCB.isInvertible()) {
422 covCB = matCB.inverse();
425 Eigen::FullPivLU<
AmgSymMatrix(5)> matSum(covID + covMS);
426 if (!matSum.isInvertible()) {
434 chi2 = diffPars.transpose() * invCovSum * diffPars;
437 parsCB = covCB * (weightID * parsID + weightMS * parsMS);
440 if (parsCB[2] >
M_PI)
441 parsCB[2] -= 2. *
M_PI;
442 else if (parsCB[2] < -
M_PI)
443 parsCB[2] += 2. *
M_PI;
452 return sys.find(systematic) != sys.end();
461 if (!m_useFixedRho || m_sysScheme ==
"AllSys") {
466 if (m_doEtaSagittaSys) {
493 CP::SystematicSet MuonCalibIntSagittaTool::recommendedSystematics()
const {
return affectingSystematics(); }
495 StatusCode MuonCalibIntSagittaTool::calcSystematicVariation(
const CP::SystematicSet &systConfig, ParameterSetSagitta ¶m)
const
509 else if (!syst.
empty())
return StatusCode::FAILURE;
516 else if (!syst.
empty())
return StatusCode::FAILURE;
523 else if (!syst.
empty())
return StatusCode::FAILURE;
530 else if (!syst.
empty())
return StatusCode::FAILURE;
545 else if (!syst.
empty())
return StatusCode::FAILURE;
560 else if (!syst.
empty())
return StatusCode::FAILURE;
567 else if (!syst.
empty())
return StatusCode::FAILURE;
570 ATH_MSG_DEBUG(
"Systematic variation's parameters, SagittaRho: " << param.SagittaRho);
571 ATH_MSG_DEBUG(
"Systematic variation's parameters, SagittaBias: " << param.SagittaBias);
572 ATH_MSG_DEBUG(
"Systematic variation's parameters, SagittaGlobal: " << param.SagittaGlobal);
573 ATH_MSG_DEBUG(
"Systematic variation's parameters, SagittaPtExtra: " << param.SagittaPtExtra);
574 ATH_MSG_DEBUG(
"Systematic variation's parameters, SagittaDataStat: " << param.SagittaDataStat);
575 ATH_MSG_DEBUG(
"Systematic variation's parameters, SagittaEtaSlice: " << param.SagittaEtaSlice);
577 return StatusCode::SUCCESS;
580 StatusCode MuonCalibIntSagittaTool::applySystematicVariation(
const CP::SystematicSet &systConfig)
582 return m_Parameters.get(systConfig, m_currentParameters);