22 std::unique_ptr<TFile> calFile(TFile::Open(calFilePath.c_str(),
"READ"));
28 std::string histName =
"";
29 for (
size_t decayModeIndex = 0; decayModeIndex <
DecayModeBinning; ++ decayModeIndex) {
31 hist =
dynamic_cast<TH1F*
> (calFile->Get(histName.c_str()));
33 hist->SetDirectory(
nullptr);
38 ATH_MSG_FATAL(
"Failed to get an object with name " << histName);
39 return StatusCode::FAILURE;
43 tf1 =
dynamic_cast<TF1*
> (calFile->Get(histName.c_str()));
49 ATH_MSG_FATAL(
"Failed to get an object with name " << histName);
50 return StatusCode::FAILURE;
55 TGraph* graph =
nullptr;
56 std::string graphName=
"";
57 for (
size_t decayModeIndex = 0; decayModeIndex <
DecayModeBinning; ++decayModeIndex) {
58 for (
size_t etaIndex = 0; etaIndex <
EtaBinning; ++etaIndex) {
61 graph =
dynamic_cast<TGraph*
> (calFile->Get(graphName.c_str()));
63 m_caloRelBiasMaxEt[decayModeIndex][etaIndex] = TMath::MaxElement(graph->GetN(), graph->GetX());
64 m_caloRelBias[decayModeIndex][etaIndex] = std::unique_ptr<TGraph>(graph);
68 ATH_MSG_FATAL(
"Failed to get an object with name " << graphName);
69 return StatusCode::FAILURE;
74 graph =
dynamic_cast<TGraph*
> (calFile->Get(graphName.c_str()));
76 m_caloResMaxEt[decayModeIndex][etaIndex] = TMath::MaxElement(graph->GetN(), graph->GetX());
77 m_caloRes[decayModeIndex][etaIndex] = std::unique_ptr<TGraph>(graph);
81 ATH_MSG_FATAL(
"Failed to get an object with name " << graphName);
82 return StatusCode::FAILURE;
87 graph =
dynamic_cast<TGraph*
> (calFile->Get(graphName.c_str()));
89 m_panTauRelBiasMaxEt[decayModeIndex][etaIndex] = TMath::MaxElement(graph->GetN(), graph->GetX());
90 m_panTauRelBias[decayModeIndex][etaIndex] = std::unique_ptr<TGraph>(graph);
94 ATH_MSG_FATAL(
"Failed to get an object with name " << graphName);
95 return StatusCode::FAILURE;
100 graph =
dynamic_cast<TGraph*
> (calFile->Get(graphName.c_str()));
102 m_panTauResMaxEt[decayModeIndex][etaIndex] = TMath::MaxElement(graph->GetN(), graph->GetX());
103 m_panTauRes[decayModeIndex][etaIndex] = std::unique_ptr<TGraph>(graph);
107 ATH_MSG_FATAL(
"Failed to get an object with name " << graphName);
108 return StatusCode::FAILURE;
114 graph =
dynamic_cast<TGraph*
> (calFile->Get(graphName.c_str()));
116 m_mvaResMaxEt.at(decayModeIndex).at(etaIndex) = TMath::MaxElement(graph->GetN(), graph->GetX());
117 m_mvaRes.at(decayModeIndex).at(etaIndex) = std::unique_ptr<TGraph>(graph);
121 ATH_MSG_FATAL(
"Failed to get an object with name " << graphName);
122 return StatusCode::FAILURE;
129 return StatusCode::SUCCESS;
134 const EventContext& )
const {
149 decPtCombined(tau) = combinedP4.Pt();
150 decEtaCombined(tau) = combinedP4.Eta();
151 decPhiCombined(tau) = combinedP4.Phi();
152 decMCombined(tau) = combinedP4.M();
154 return StatusCode::SUCCESS;
160 if (!
isValid(tau))
return false;
165 int etaIndex =
getEtaIndex(tau.etaTauEnergyScale());
167 double caloSigma = tau.ptTauEnergyScale() *
getCaloResolution(tau.ptTauEnergyScale(), decayModeIndex, etaIndex);
168 double deltaEt = tau.ptFinalCalib() - tau.ptTauEnergyScale();
170 bool compatibility =
true;
173 if (std::abs(deltaEt) > 5 * caloSigma) {
174 compatibility =
false;
177 return compatibility;
184 float abseta = std::abs(
eta);
218 return static_cast<int>(decayMode);
230 int etaIndex =
getEtaIndex(tau.etaTauEnergyScale());
249 int etaIndex)
const {
256 ratio =
m_caloRelBias.at(decayModeIndex).at(etaIndex)->Eval(caloEt);
259 double caloCalEt = caloEt - ratio * caloEt;
268 int etaIndex)
const {
274 ratio =
m_panTauRelBias.at(decayModeIndex).at(etaIndex)->Eval(panTauEt);
277 double panTauCalEt = panTauEt - ratio * panTauEt;
294 double pt = std::min(tau.ptFinalCalib(),
m_mvaResMaxEt.at(decayModeIndex).at(etaIndex));
295 double resolution =
m_mvaRes.at(decayModeIndex).at(etaIndex)->Eval(pt);
304 double resolution =
m_caloRes.at(decayModeIndex).at(etaIndex)->Eval(
x);
313 double resolution =
m_panTauRes.at(decayModeIndex).at(etaIndex)->Eval(
x);
322 double correlation)
const {
323 double cov = correlation * caloSigma * panTauSigma;
324 double caloWeight = std::pow(panTauSigma, 2) - cov;
325 double panTauWeight = std::pow(caloSigma, 2) - cov;
327 double weight = (caloWeight + panTauWeight !=0.) ? caloWeight/(caloWeight + panTauWeight) : 0.;
329 return std::clamp(weight, 0., 1.);
334 double correlation)
const {
335 double compatibilitySigma2 = std::pow(caloSigma, 2) + std::pow(panTauSigma, 2) - 2 * correlation * caloSigma * panTauSigma;
337 return std::sqrt(compatibilitySigma2);
345 if (nsigma < 0.)
return 0.;
366 if (0. == caloSigma) {
368 m_caloRes.at(decayModeIndex)[etaIndex]->Print(
"all");
374 if (0. == panTauSigma) {
376 m_panTauRes.at(decayModeIndex).at(etaIndex)->Print(
"all");
381 double caloCalEt =
getCaloCalEt(caloEt, decayModeIndex, etaIndex);
384 double panTauCalEt =
getPanTauCalEt(panTauEt, decayModeIndex, etaIndex);
388 double weight =
getWeight(caloSigma, panTauSigma, correlation);
389 double weightedEt = weight * caloCalEt + (1 - weight) * panTauCalEt;
395 double deltaEt = caloCalEt - panTauCalEt;
402 "coff: " << correlation <<
" sigma(calo): " << caloSigma <<
" sigma(constituent): " << panTauSigma <<
403 "\ncalibrated et(calo): " << caloCalEt <<
" calibrated et(constituent): " << panTauCalEt <<
404 "\nweight:" << weight <<
" combined et: " << weightedEt <<
" compatibility sigma: " << compatibilitySigma);
415 ATH_MSG_DEBUG(
"Four momentum at calo TES, pt: " << caloP4.Pt() <<
" eta: " << caloP4.Eta() <<
416 " phi: " << caloP4.Phi() <<
" mass: " << caloP4.M());
417 ATH_MSG_DEBUG(
"Four momentum at PanTau, pt: " << panTauP4.Pt() <<
" eta: " << panTauP4.Eta() <<
418 " phi: " << panTauP4.Phi() <<
" mass: " << panTauP4.M());
422 double combinedEt =
getCombinedEt(caloP4.Et(), panTauP4.Et(), decayMode, caloP4.Eta());
425 TLorentzVector combinedP4;
426 combinedP4.SetPtEtaPhiM(combinedEt, panTauP4.Eta(), panTauP4.Phi(), 0.);
428 ATH_MSG_DEBUG(
"Combined four momentum, pt: " << combinedP4.Pt() <<
" eta: " << combinedP4.Eta() <<
429 " phi: " << combinedP4.Phi() <<
" mass: " << combinedP4.M());
Scalar eta() const
pseudorapidity method
bool isValid() const
Test to see if the link can be dereferenced.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
Helper class to provide type-safe access to aux data.
const std::array< std::string, DecayModeBinning > m_decayModeNames
Decay mode binning in the calibration graph/hist.
const std::array< std::string, EtaBinning > m_etaBinNames
Eta binning in the calibration graph.
double getWeight(double caloSigma, double panTauSigma, double correlatioon) const
Get the weight of calo TES.
Gaudi::Property< std::string > m_calFileName
std::array< std::array< std::unique_ptr< TGraph >, EtaBinning >, DecayModeBinning > m_caloRelBias
Calibration graph: mean of bias/caloEt as a function of caloEt.
int getEtaIndex(float eta) const
Get the index of eta in the calibration histogram.
xAOD::TauJetParameters::DecayMode getDecayMode(const xAOD::TauJet &tau) const
Get the decay mode of the tau candidate.
double getCaloResolution(double et, int decayModeIndex, int etaIndex) const
Get the resolution of Et at the calo TES.
std::array< std::unique_ptr< TH1F >, DecayModeBinning > m_correlationHists
Calibration histogram: correlation coefficient of calo TES and PanTau.
std::array< std::array< double, EtaBinning >, DecayModeBinning > m_caloRelBiasMaxEt
Maximum Et of m_caloRelBias.
std::array< std::array< double, EtaBinning >, DecayModeBinning > m_panTauRelBiasMaxEt
Maximum Et of m_panTauRelBias.
double getMvaEnergyResolution(const xAOD::TauJet &tau) const
Get MVA Et resolution, invoked by METSignificance.
bool isValid(const xAOD::TauJet &tau) const
Whether the tau candidate is valid for the calculation.
bool getTESCompatibility(const xAOD::TauJet &tau) const
Check if MVA TES and CaloTES are compatible, invoked by TauSmearing tool.
std::array< std::array< double, EtaBinning >, DecayModeBinning > m_mvaResMaxEt
Maximum Et of m_mvaRes.
virtual StatusCode initialize() override
Tool initializer.
std::array< std::array< std::unique_ptr< TGraph >, EtaBinning >, DecayModeBinning > m_mvaRes
Calibration graph: MVA TES resolution as a function of MVA pt.
double getPanTauResolution(double et, int decayModeIndex, int etaIndex) const
Get the resolution of Et at PanTau.
double getCombinedEt(double caloEt, double et_substructure, xAOD::TauJetParameters::DecayMode decayMode, float eta) const
Get the combined Et of calo TES and PanTau.
double getCompatibilitySigma(double caloSigma, double panTauSigma, double correlation) const
Get the compatibility sigma of calo TES and PanTau.
std::array< std::array< std::unique_ptr< TGraph >, EtaBinning >, DecayModeBinning > m_panTauRes
Calibration graph: resolution at PanTau as a function of panTauEt.
virtual StatusCode executeTool(xAOD::TauJet &xTau, const EventContext &ctx) const override
Execute - called for each tau candidate.
std::array< std::array< std::unique_ptr< TGraph >, EtaBinning >, DecayModeBinning > m_panTauRelBias
Calibration graph: mean of bias/panTauEt as a funtion of panTauEt.
std::array< std::array< double, EtaBinning >, DecayModeBinning > m_caloResMaxEt
Maximum Et of m_caloRes.
std::array< std::array< double, EtaBinning >, DecayModeBinning > m_panTauResMaxEt
Maximum Et of m_panTauRes.
Gaudi::Property< bool > m_useMvaResolution
double getCaloCalEt(double et, int decayModeIndex, int etaIndex) const
Get the Et at the calo TES after calibration correction.
std::array< std::array< std::unique_ptr< TGraph >, EtaBinning >, DecayModeBinning > m_caloRes
Calibration graph: resolution at Calo TES as a function of caloEt.
int getDecayModeIndex(xAOD::TauJetParameters::DecayMode decayMode) const
Get the index of decay mode in the calibration histogram.
double getCorrelation(int decayModeIndex, int etaIndex) const
Get correlation coefficient between the calo TES and PanTau.
TLorentzVector getCombinedP4(const xAOD::TauJet &tau) const
Get the weighted four momentum of calo TES and PanTau.
double getNsigmaCompatibility(double caloEt, int decayModeIndex) const
Get the allowed difference between calo TES and PanTau.
double getPanTauCalEt(double panTauEt, int decayModeIndex, int etaIndex) const
Get the Et at PanTau after calibration correction.
TauCombinedTES(const std::string &name="TauCombinedTES")
std::array< std::unique_ptr< TF1 >, DecayModeBinning > m_nSigmaCompatibility
Maximum tolerence in unit of combined sigma, as a function of calo Et.
TauJet_v3 TauJet
Definition of the current "tau version".
Extra patterns decribing particle interation process.