ATLAS Offline Software
Loading...
Searching...
No Matches
TauResolutionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include "TFile.h"
9
11
12namespace ADD_CMODE(TauAnalysisTools)
13{
14
15TauResolutionTool::TauResolutionTool( const std::string& sName )
16 : asg::AsgMetadataTool( sName )
17{}
18
19TauResolutionTool::~TauResolutionTool()
20{}
21
22StatusCode TauResolutionTool::initialize()
23{
24 ATH_MSG_INFO( "Initializing TauResolutionTool" );
25
26
27 std::string calFilePath = PathResolverFindCalibFile(m_calFileName);
28 std::unique_ptr<TFile> calFile(TFile::Open(calFilePath.c_str(), "READ"));
29 ATH_MSG_INFO("Using calibration file: " << calFilePath);
30
31 // 2D array with (eta, decay mode) as index
32 TGraph* graph = nullptr;
33 std::string graphName="";
34 for (size_t decayModeIndex = 0; decayModeIndex < DecayModeBinning; ++decayModeIndex) {
35 for (size_t etaIndex = 0; etaIndex < EtaBinning; ++etaIndex) {
36
37 // Calo TES: resolution
38 graphName = "tauRec/Graph_from_ResolutionEt_tauRec_" + m_decayModeNames[decayModeIndex] + "_" + m_etaBinNames[etaIndex];
39 graph = dynamic_cast<TGraph*> (calFile->Get(graphName.c_str()));
40 if(graph){
41 m_caloResMaxEt[decayModeIndex][etaIndex] = TMath::MaxElement(graph->GetN(), graph->GetX());
42 m_caloRes[decayModeIndex][etaIndex] = std::unique_ptr<TGraph>(graph);
43 ATH_MSG_DEBUG("Adding graph: " << graphName);
44 }
45 else {
46 ATH_MSG_FATAL("Failed to get an object with name " << graphName);
47 return StatusCode::FAILURE;
48 }
49
50 graphName = "FinalCalib/Graph_from_ResolutionEt_FinalCalib_" + m_decayModeNames[decayModeIndex] + "_" + m_etaBinNames.at(etaIndex);
51 graph = dynamic_cast<TGraph*> (calFile->Get(graphName.c_str()));
52 if(graph){
53 m_mvaResMaxEt.at(decayModeIndex).at(etaIndex) = TMath::MaxElement(graph->GetN(), graph->GetX());
54 m_mvaRes.at(decayModeIndex).at(etaIndex) = std::unique_ptr<TGraph>(graph);
55 ATH_MSG_DEBUG("Adding graph: " << graphName);
56 }
57 else {
58 ATH_MSG_FATAL("Failed to get an object with name " << graphName);
59 return StatusCode::FAILURE;
60 }
61 }
62 }
63 calFile->Close();
64
65 return StatusCode::SUCCESS;
66}
67
68
69bool TauResolutionTool::isValid(const xAOD::TauJet& tau) const {
70 xAOD::TauJetParameters::DecayMode decayMode = getDecayMode(tau);
71 if (decayMode < xAOD::TauJetParameters::Mode_1p0n || decayMode > xAOD::TauJetParameters::Mode_3pXn) {
72 ATH_MSG_DEBUG("Decay mode is not supported !");
73 return false;
74 }
75
76 int etaIndex = getEtaIndex(tau.etaTauEnergyScale());
77 if (etaIndex > 4) {
78 ATH_MSG_DEBUG("Eta is out of the supported range !");
79 return false;
80 }
81
82 return true;
83}
84
85int TauResolutionTool::getEtaIndex(float eta) const {
86 float abseta = std::abs(eta);
87
88 if (abseta < 0.3) {
89 return 0;
90 }
91 if (abseta < 0.8) {
92 return 1;
93 }
94 if (abseta < 1.3) {
95 return 2;
96 }
97 if (abseta < 1.6) {
98 return 3;
99 }
100 if (abseta < 2.6) {
101 return 4;
102 }
103
104 return 99;
105}
106
107xAOD::TauJetParameters::DecayMode TauResolutionTool::getDecayMode(const xAOD::TauJet& tau) const {
110
111 return static_cast<xAOD::TauJetParameters::DecayMode>(decayMode);
112}
113
114int TauResolutionTool::getDecayModeIndex(xAOD::TauJetParameters::DecayMode decayMode) const {
115 return static_cast<int>(decayMode);
116}
117
118double TauResolutionTool::getMvaEnergyResolution(const xAOD::TauJet& tau) const {
119
120 // Assume the resolution to be 100% when no parametrisation is available
121 if (!isValid(tau)) return 1.0;
122
123 xAOD::TauJetParameters::DecayMode decayMode = getDecayMode(tau);
124 int decayModeIndex = getDecayModeIndex(decayMode);
125
126 int etaIndex = getEtaIndex(tau.etaFinalCalib());
127
128 double pt = std::min(tau.ptFinalCalib(), m_mvaResMaxEt.at(decayModeIndex).at(etaIndex));
129 double resolution = m_mvaRes.at(decayModeIndex).at(etaIndex)->Eval(pt);
130
131 return resolution;
132}
133
134double TauResolutionTool::getCaloResolution(double et, int decayModeIndex, int etaIndex) const {
135 double x = std::min(et, m_caloResMaxEt.at(decayModeIndex).at(etaIndex));
136 double resolution = m_caloRes.at(decayModeIndex).at(etaIndex)->Eval(x);
137
138 return resolution;
139}
140
141bool TauResolutionTool::getTESCompatibility(const xAOD::TauJet& tau) const {
142 if (! isValid(tau)) return false;
143
144 xAOD::TauJetParameters::DecayMode decayMode = getDecayMode(tau); //can return 7
145 int decayModeIndex = getDecayModeIndex(decayMode);
146
147 int etaIndex = getEtaIndex(tau.etaTauEnergyScale());
148
149 double caloSigma = tau.ptTauEnergyScale() * getCaloResolution(tau.ptTauEnergyScale(), decayModeIndex, etaIndex);
150 double deltaEt = tau.ptFinalCalib() - tau.ptTauEnergyScale();
151
152 bool compatibility = true;
153
154 if (std::abs(deltaEt) > 5 * caloSigma) {
155 compatibility = false;
156 }
157
158 return compatibility;
159}
160
161} // namespace TauAnalysisTools
Scalar eta() const
pseudorapidity method
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
#define x
Base class for dual-use tools that provide file metadata access.
TauJet_v3 TauJet
Definition of the current "tau version".
Definition TauJet.h:17
Extra patterns decribing particle interation process.