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