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 if (acc_signal(tau)) {
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 //Set the new systematic variation
173 StatusCode ret = m_tauEffTool->applySystematicVariation(systConfig);
174 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure TauEfficiencyCorrectionsTool for systematic var. " << systConfig.name() ); }
175
176 for (auto& tool : m_tauTrigEffTool) {
177 ret = tool->applySystematicVariation(systConfig);
178 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure " << tool->name() << " for systematic var. " << systConfig.name()); }
179 }
180
181 sf *= GetSignalTauSF(tau, idSF, triggerSF, trigExpr);
182
183 //Roll back to default
184 ret = m_tauEffTool->applySystematicVariation(m_currentSyst);
185 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure TauEfficiencyCorrectionsTool back to default"); }
186
187 for (auto& tool : m_tauTrigEffTool) {
188 ret = tool->applySystematicVariation(m_currentSyst);
189 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure " << tool->name() << " back to default"); }
190 }
191
192 dec_effscalefact(tau) = sf;
193
194 return sf;
195}
196
197
198double SUSYObjDef_xAOD::GetTauTriggerEfficiencySF(const xAOD::TauJet& tau, const std::string& trigExpr) {
199
200 double eff(1.);
201
202 auto map_it = m_tau_trig_support.find(trigExpr);
203 if (map_it == m_tau_trig_support.end()) {
204 ATH_MSG_WARNING("The trigger item requested (" << trigExpr << ") is not supported! Please check. Setting SF to 1.");
205 return eff;
206 }
207
208 // trigger matching (dR=0.2)
209 std::vector<std::string> chains;
210 for (auto part : std::views::split(map_it->second, ',')) chains.emplace_back(&*part.begin(), std::ranges::distance(part));
211 bool match = false;
212 for (const std::string& chain : chains)
213 if (m_trigMatchingTool->match({&tau}, chain, 0.2)) {
214 match = true;
215 break;
216 }
217 if (!match) {
218 ATH_MSG_VERBOSE("Tau did not match trigger " << trigExpr);
219 return eff;
220 }
221
222 int trigIdx = std::distance(std::begin(m_tau_trig_support), map_it);
223 if (m_tauTrigEffTool.at(trigIdx)->getEfficiencyScaleFactor(tau, eff) != CP::CorrectionCode::Ok) {
224 ATH_MSG_ERROR("Some problem found to retrieve SF for trigger item requested (" << trigExpr << ")");
225 eff = -99;
226 }
227
228 return eff;
229}
230
231
232double SUSYObjDef_xAOD::GetTotalTauSF(const xAOD::TauJetContainer& taus, const bool idSF, const bool triggerSF, const std::string& trigExpr) {
233
234 double sf(1.);
235
236 for (const xAOD::TauJet* tau : taus) {
237 // check existence of OR information
238 if (!acc_passOR.isAvailable(*tau)) {
239 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!");
240 break;
241 }
242
243 // Call this for all taus, which will add the decoration
244 double tmpSF = GetSignalTauSF(*tau, idSF, triggerSF, trigExpr);
245 if (acc_signal(*tau) && acc_passOR(*tau)) {
246 sf *= tmpSF;
247 }
248 }
249
250 return sf;
251}
252
253
254double SUSYObjDef_xAOD::GetTotalTauSFsys(const xAOD::TauJetContainer& taus, const CP::SystematicSet& systConfig, const bool idSF, const bool triggerSF, const std::string& trigExpr){
255 double sf(1.);
256
257 //Set the new systematic variation
258 StatusCode ret = m_tauEffTool->applySystematicVariation(systConfig);
259 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure TauEfficiencyCorrectionsTool for systematic var. " << systConfig.name() ); }
260
261 for (auto& tool : m_tauTrigEffTool) {
262 ret = tool->applySystematicVariation(systConfig);
263 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure " << tool->name() << " for systematic var. " << systConfig.name()); }
264 }
265
266 sf = GetTotalTauSF(taus, idSF, triggerSF, trigExpr);
267
268 //Roll back to default
269 ret = m_tauEffTool->applySystematicVariation(m_currentSyst);
270 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure TauEfficiencyCorrectionsTool back to default"); }
271
272 for (auto& tool : m_tauTrigEffTool) {
273 ret = tool->applySystematicVariation(m_currentSyst);
274 if (ret != StatusCode::SUCCESS) { ATH_MSG_ERROR("Cannot configure " << tool->name() << " back to default"); }
275 }
276
277 return sf;
278}
279
280}
#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: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: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:198
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:232
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:254
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".