ATLAS Offline Software
Loading...
Searching...
No Matches
Taus.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// This source file implements all of the functions related to TauJets
6// in the SUSYObjDef_xAOD class
7
8// Local include(s):
10
13
21#include <string_view>
22#include <ranges>
23
24#ifndef XAOD_STANDALONE // For now metadata is Athena-only
26#endif
27
28namespace ST {
29
30
32 const std::string& taukey, const xAOD::TauJetContainer* containerToBeCopied)
33{
34 if (!m_tool_init) {
35 ATH_MSG_ERROR("SUSYTools was not initialized!!");
36 return StatusCode::FAILURE;
37 }
38
39 if (m_isPHYSLITE && taukey.find("AnalysisTauJets")==std::string::npos){
40 ATH_MSG_ERROR("You are running on PHYSLITE derivation. Please change the Taus container to 'AnalysisTauJets'");
41 return StatusCode::FAILURE;
42 }
43
44 const xAOD::TauJetContainer* taus = nullptr;
45 if (copy==nullptr) { // empty container provided
46 if (containerToBeCopied != nullptr) {
47 taus = containerToBeCopied;
48 }
49 else {
50 ATH_CHECK( evtStore()->retrieve(taus, taukey) );
51 }
53 copy = shallowcopy.first.get();
54 copyaux = shallowcopy.second.get();
55 bool setLinks = xAOD::setOriginalObjectLink(*taus, *copy);
56 if (!setLinks) {
57 ATH_MSG_WARNING("Failed to set original object links on " << taukey);
58 }
59 if (recordSG) {
60 ATH_CHECK( evtStore()->record(std::move(shallowcopy.first), "STCalib" + taukey + m_currentSyst.name()) );
61 ATH_CHECK( evtStore()->record(std::move(shallowcopy.second), "STCalib" + taukey + m_currentSyst.name() + "Aux.") );
62 } else {
63 ATH_MSG_ERROR("Shallow copy not recorded in StoreGate!");
64 return StatusCode::FAILURE;
65 }
66 } else { // use the user-supplied collection instead
67 ATH_MSG_DEBUG("Not retrieving tau collecton, using existing one provided by user");
68 taus=copy;
69 }
70
71 for (const auto tau : *copy) {
72 ATH_CHECK( this->FillTau(*tau) );
73 this->IsSignalTau(*tau, m_tauPt, m_tauEta);
74 }
75
76 return StatusCode::SUCCESS;
77}
78
79
80// Can't be const due to applyCorrection on the smearing tool
82
83 ATH_MSG_VERBOSE( "Starting FillTau on tau with pT = " << input.pt()/1000 << " GeV" );
84 ATH_MSG_VERBOSE( "TAU pT before smearing " << input.pt()/1000 << " GeV");
85
86 // do truth matching first (required unless already done in AOD->DAOD and truth matching info kept in DAOD)
87 if (m_tauDoTTM && !isData()) m_tauTruthMatch->getTruth(input);
88 ATH_MSG_VERBOSE("Tau truth matching done");
89
90 // apply the calibration to data as well (not needed in R22, unless MVA TES gets updated)
91 if (std::abs(input.eta()) <= 2.5 && input.nTracks() > 0) {
92 if (m_tauSmearingTool->applyCorrection(input) != CP::CorrectionCode::Ok) {
93 ATH_MSG_ERROR(" Tau smearing failed " );
94 } else { ATH_MSG_VERBOSE("Tau smearing done"); }
95 }
96
97 ATH_MSG_VERBOSE( "TAU pt after smearing " << input.pt()/1000. );
98
99 // if tauPrePtCut set, apply min pT cut here before calling tau selection tool
100 // (avoid exceptions when running on derivations with removed tracks for low-pT taus, e.g. HIGG4D2)
101 if (input.pt() > m_tauPrePtCut) {
102 dec_baseline(input) = bool(m_tauSelToolBaseline->accept( input ));
103 }
104 else {
105 dec_baseline(input) = false;
106 }
107 if (acc_baseline(input)) dec_selected(input) = 2;
108 else dec_selected(input) = 0;
109
110 if (acc_baseline(input)) ATH_MSG_VERBOSE("FillTau: passed baseline selection");
111 else ATH_MSG_VERBOSE("FillTau: failed baseline selection");
112 return StatusCode::SUCCESS;
113}
114
115
116bool SUSYObjDef_xAOD::IsSignalTau(const xAOD::TauJet& input, float ptcut, float etacut) const {
117
118 dec_signal(input) = false;
119
120 if ( !acc_baseline(input) ) return false;
121
122 if (input.pt() <= ptcut) return false;
123
124 if (std::abs(input.eta()) >= etacut) return false;
125
126 if (!m_tauSelTool->accept( input )) return false;
127
128 dec_signal(input) = true;
129
130 return true;
131}
132
133
135 const bool idSF,
136 const bool triggerSF,
137 const std::string& trigExpr)
138{
139 double sf(1.);
140
141 // TEMPORARY: no recommendations yet for 2024+
142 if (acc_signal(tau) && this->treatAsYear()<2024) {
143 if (idSF) {
144 if (m_tauEffTool->getEfficiencyScaleFactor(tau, sf) != CP::CorrectionCode::Ok) {
145 ATH_MSG_WARNING("Failed to retrieve tau efficiency scale factor.");
146 }
147 ATH_MSG_VERBOSE(" Retrieved tau SF " << sf);
148 }
149
150 if (triggerSF) {
151 double trig_sf = GetTauTriggerEfficiencySF(tau, trigExpr);
152
153 if (trig_sf > -90) {
154 sf *= trig_sf;
155 ATH_MSG_VERBOSE(" Retrieved tau trig SF " << trig_sf);
156 }
157 }
158 }
159
160 dec_effscalefact(tau) = sf;
161 return sf;
162}
163
164
166 const CP::SystematicSet& systConfig,
167 const bool idSF,
168 const bool triggerSF,
169 const std::string& trigExpr)
170{
171 double sf(1.);
172
173 // TEMPORARY: no recommendations yet for 2024+
174 if (this->treatAsYear()<2024) {
175 //Set the new systematic variation
176 StatusCode ret = m_tauEffTool->applySystematicVariation(systConfig);
177 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure TauEfficiencyCorrectionsTool for systematic var. " << systConfig.name() ); }
178
179 for (auto& tool : m_tauTrigEffTool) {
180 ret = tool->applySystematicVariation(systConfig);
181 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure " << tool->name() << " for systematic var. " << systConfig.name()); }
182 }
183
184 sf *= GetSignalTauSF(tau, idSF, triggerSF, trigExpr);
185
186 //Roll back to default
187 ret = m_tauEffTool->applySystematicVariation(m_currentSyst);
188 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure TauEfficiencyCorrectionsTool back to default"); }
189
190 for (auto& tool : m_tauTrigEffTool) {
191 ret = tool->applySystematicVariation(m_currentSyst);
192 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure " << tool->name() << " back to default"); }
193 }
194 }
195
196 dec_effscalefact(tau) = sf;
197
198 return sf;
199}
200
201
202double SUSYObjDef_xAOD::GetTauTriggerEfficiencySF(const xAOD::TauJet& tau, const std::string& trigExpr) {
203
204 double eff(1.);
205
206 auto map_it = m_tau_trig_support.find(trigExpr);
207 if (map_it == m_tau_trig_support.end()) {
208 ATH_MSG_WARNING("The trigger item requested (" << trigExpr << ") is not supported! Please check. Setting SF to 1.");
209 return eff;
210 }
211
212 // trigger matching (dR=0.2)
213 std::vector<std::string> chains;
214 for (auto part : std::views::split(map_it->second, ',')) chains.emplace_back(&*part.begin(), std::ranges::distance(part));
215 bool match = false;
216 for (const std::string& chain : chains)
217 if (m_trigMatchingTool->match({&tau}, chain, 0.2)) {
218 match = true;
219 break;
220 }
221 if (!match) {
222 ATH_MSG_VERBOSE("Tau did not match trigger " << trigExpr);
223 return eff;
224 }
225
226 int trigIdx = std::distance(std::begin(m_tau_trig_support), map_it);
227 if (m_tauTrigEffTool.at(trigIdx)->getEfficiencyScaleFactor(tau, eff) != CP::CorrectionCode::Ok) {
228 ATH_MSG_ERROR("Some problem found to retrieve SF for trigger item requested (" << trigExpr << ")");
229 eff = -99;
230 }
231
232 return eff;
233}
234
235
236double SUSYObjDef_xAOD::GetTotalTauSF(const xAOD::TauJetContainer& taus, const bool idSF, const bool triggerSF, const std::string& trigExpr) {
237
238 double sf(1.);
239
240 for (const xAOD::TauJet* tau : taus) {
241 // check existence of OR information
242 if (!acc_passOR.isAvailable(*tau)) {
243 ATH_MSG_WARNING("Tau does not have Overlap Removal decision set. You should only call GetTotalTauSF with taus that have been passed through OR. SF will NOT be applied!");
244 break;
245 }
246
247 // Call this for all taus, which will add the decoration
248 double tmpSF = GetSignalTauSF(*tau, idSF, triggerSF, trigExpr);
249 if (acc_signal(*tau) && acc_passOR(*tau)) {
250 sf *= tmpSF;
251 }
252 }
253
254 return sf;
255}
256
257
258double SUSYObjDef_xAOD::GetTotalTauSFsys(const xAOD::TauJetContainer& taus, const CP::SystematicSet& systConfig, const bool idSF, const bool triggerSF, const std::string& trigExpr){
259 double sf(1.);
260
261 //Set the new systematic variation
262 StatusCode ret = m_tauEffTool->applySystematicVariation(systConfig);
263 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure TauEfficiencyCorrectionsTool for systematic var. " << systConfig.name() ); }
264
265 for (auto& tool : m_tauTrigEffTool) {
266 ret = tool->applySystematicVariation(systConfig);
267 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure " << tool->name() << " for systematic var. " << systConfig.name()); }
268 }
269
270 sf = GetTotalTauSF(taus, idSF, triggerSF, trigExpr);
271
272 //Roll back to default
273 ret = m_tauEffTool->applySystematicVariation(m_currentSyst);
274 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure TauEfficiencyCorrectionsTool back to default"); }
275
276 for (auto& tool : m_tauTrigEffTool) {
277 ret = tool->applySystematicVariation(m_currentSyst);
278 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure " << tool->name() << " back to default"); }
279 }
280
281 return sf;
282}
283
284}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t taus
ServiceHandle< StoreGateSvc > & evtStore()
@ Ok
The correction was done successfully.
Class to wrap a set of SystematicVariations.
std::string name() const
returns: the systematics joined into a single string.
asg::AnaToolHandle< TauAnalysisTools::ITauSelectionTool > m_tauSelToolBaseline
StatusCode FillTau(xAOD::TauJet &input) override final
Definition Taus.cxx:81
bool IsSignalTau(const xAOD::TauJet &input, const float ptcut, const float etacut) const override final
Definition Taus.cxx:116
asg::AnaToolHandle< TauAnalysisTools::ITauSelectionTool > m_tauSelTool
asg::AnaToolHandle< TauAnalysisTools::ITauEfficiencyCorrectionsTool > m_tauEffTool
bool isData() const override final
double GetSignalTauSFsys(const xAOD::TauJet &tau, const CP::SystematicSet &systConfig, const bool idSF=true, const bool triggerSF=true, const std::string &trigExpr="tau25_medium1_tracktwo") override final
Definition Taus.cxx:165
asg::AnaToolHandle< Trig::IMatchingTool > m_trigMatchingTool
StatusCode GetTaus(xAOD::TauJetContainer *&copy, xAOD::ShallowAuxContainer *&copyaux, const bool recordSG=true, const std::string &taukey="TauJets", const xAOD::TauJetContainer *containerToBeCopied=nullptr) override final
Definition Taus.cxx:31
std::map< std::string, std::string > m_tau_trig_support
double GetTauTriggerEfficiencySF(const xAOD::TauJet &tau, const std::string &trigExpr="tau25_medium1_tracktwo") override final
Definition Taus.cxx:202
double GetSignalTauSF(const xAOD::TauJet &tau, const bool idSF=true, const bool triggerSF=true, const std::string &trigExpr="tau25_medium1_tracktwo") override final
Definition Taus.cxx:134
double GetTotalTauSF(const xAOD::TauJetContainer &taus, const bool idSF=true, const bool triggerSF=true, const std::string &trigExpr="tau25_medium1_tracktwo") override final
Definition Taus.cxx:236
int treatAsYear(const int runNumber=-1) const override final
CP::SystematicSet m_currentSyst
double GetTotalTauSFsys(const xAOD::TauJetContainer &taus, const CP::SystematicSet &systConfig, const bool idSF=true, const bool triggerSF=true, const std::string &trigExpr="tau25_medium1_tracktwo") override final
Definition Taus.cxx:258
asg::AnaToolHandle< TauAnalysisTools::ITauSmearingTool > m_tauSmearingTool
asg::AnaToolHandle< TauAnalysisTools::ITauTruthMatchingTool > m_tauTruthMatch
std::vector< asg::AnaToolHandle< TauAnalysisTools::ITauEfficiencyCorrectionsTool > > m_tauTrigEffTool
Class creating a shallow copy of an existing auxiliary container.
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:359
static const SG::Decorator< double > dec_effscalefact("effscalefact")
static const SG::Decorator< char > dec_baseline("baseline")
static const SG::ConstAccessor< char > acc_signal("signal")
static const SG::ConstAccessor< char > acc_baseline("baseline")
static const SG::ConstAccessor< char > acc_passOR("passOR")
static const SG::Decorator< char > dec_signal("signal")
static const SG::Decorator< char > dec_selected("selected")
typename ShallowCopyResult< T >::type ShallowCopyResult_t
Return type of xAOD::shallowCopy.
Definition ShallowCopy.h:68
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
TauJet_v3 TauJet
Definition of the current "tau version".
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
setBGCode setTAP setLVL2ErrorBits bool
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".