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