ATLAS Offline Software
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 
14 #include "TauAnalysisTools/Enums.h"
21 #include <string_view>
22 #include <ranges>
23 
24 #ifndef XAOD_STANDALONE // For now metadata is Athena-only
26 #endif
27 
28 namespace 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) {
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 
112 bool 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) {
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
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
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 
194 double 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 
228 double 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 
250 double 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
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
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 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ST::SUSYObjDef_xAOD::GetTauTriggerEfficiencySF
double GetTauTriggerEfficiencySF(const xAOD::TauJet &tau, const std::string &trigExpr="tau25_medium1_tracktwo") override final
Definition: Taus.cxx:194
ST::SUSYObjDef_xAOD::m_tauSelTool
asg::AnaToolHandle< TauAnalysisTools::ITauSelectionTool > m_tauSelTool
Definition: SUSYObjDef_xAOD.h:916
ST::SUSYObjDef_xAOD::GetTotalTauSF
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
ST::SUSYObjDef_xAOD::GetSignalTauSFsys
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
Enums.h
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
TrackParticlexAODHelpers.h
ST
Definition: Electrons.cxx:41
ST::SUSYObjDef_xAOD::m_tauSmearingTool
asg::AnaToolHandle< TauAnalysisTools::ITauSmearingTool > m_tauSmearingTool
Definition: SUSYObjDef_xAOD.h:918
TauAnalysisTools::ITauSmearingTool::applyCorrection
virtual CP::CorrectionCode applyCorrection(xAOD::TauJet &xTau) const =0
Declare the interface that the class provides.
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
xAOD::ShallowAuxContainer
Class creating a shallow copy of an existing auxiliary container.
Definition: ShallowAuxContainer.h:54
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
TauAnalysisTools::ITauSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *p) const =0
Get the decision using a generic IParticle pointer.
CP::SystematicSet::name
std::string name() const
returns: the systematics joined into a single string.
Definition: SystematicSet.cxx:277
SUSYObjDef_xAOD.h
ITauSelectionTool.h
ST::SUSYObjDef_xAOD::m_trigMatchingTool
asg::AnaToolHandle< Trig::IMatchingTool > m_trigMatchingTool
Definition: SUSYObjDef_xAOD.h:965
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ITauEfficiencyCorrectionsTool.h
Pythia8_A14_NNPDF23LO_forMGHT_EvtGen.ptcut
float ptcut
Definition: Pythia8_A14_NNPDF23LO_forMGHT_EvtGen.py:9
ST::SUSYObjDef_xAOD::m_tool_init
bool m_tool_init
Definition: SUSYObjDef_xAOD.h:562
ST::SUSYObjDef_xAOD::m_tau_trig_support
std::map< std::string, std::string > m_tau_trig_support
Definition: SUSYObjDef_xAOD.h:639
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ST::SUSYObjDef_xAOD::m_isPHYSLITE
bool m_isPHYSLITE
Definition: SUSYObjDef_xAOD.h:804
ITauTruthMatchingTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ST::SUSYObjDef_xAOD::m_tauSelToolBaseline
asg::AnaToolHandle< TauAnalysisTools::ITauSelectionTool > m_tauSelToolBaseline
Definition: SUSYObjDef_xAOD.h:917
ST::SUSYObjDef_xAOD::isData
bool isData() const override final
Definition: SUSYObjDef_xAOD.h:157
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
ST::SUSYObjDef_xAOD::m_tauTruthMatch
asg::AnaToolHandle< TauAnalysisTools::ITauTruthMatchingTool > m_tauTruthMatch
Definition: SUSYObjDef_xAOD.h:919
TauAnalysisTools::ITauEfficiencyCorrectionsTool::getEfficiencyScaleFactor
virtual CP::CorrectionCode getEfficiencyScaleFactor(const xAOD::TauJet &xTau, double &eff, unsigned int iRunNumber=0)=0
Declare the interface that the class provides.
ST::SUSYObjDef_xAOD::GetTotalTauSFsys
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
ST::SUSYObjDef_xAOD::m_tauEffTool
asg::AnaToolHandle< TauAnalysisTools::ITauEfficiencyCorrectionsTool > m_tauEffTool
Definition: SUSYObjDef_xAOD.h:920
ST::SUSYObjDef_xAOD::m_tauPt
double m_tauPt
Definition: SUSYObjDef_xAOD.h:726
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
ST::SUSYObjDef_xAOD::FillTau
StatusCode FillTau(xAOD::TauJet &input) override final
Definition: Taus.cxx:77
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
ITauToolBase.h
TauAnalysisTools::ITauTruthMatchingTool::getTruth
virtual const xAOD::TruthParticle * getTruth(const xAOD::TauJet &xTau)=0
AthAnalysisHelper.h
python.copyTCTOutput.chains
chains
Definition: copyTCTOutput.py:78
ST::SUSYObjDef_xAOD::GetSignalTauSF
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
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
IMatchingTool.h
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::setOriginalObjectLink
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...
Definition: IParticleHelpers.cxx:30
ST::SUSYObjDef_xAOD::m_currentSyst
CP::SystematicSet m_currentSyst
Definition: SUSYObjDef_xAOD.h:816
ST::SUSYObjDef_xAOD::m_tauEta
double m_tauEta
Definition: SUSYObjDef_xAOD.h:727
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
IParticleHelpers.h
calibdata.copy
bool copy
Definition: calibdata.py:26
ST::SUSYObjDef_xAOD::m_tauPrePtCut
double m_tauPrePtCut
Definition: SUSYObjDef_xAOD.h:725
Trig::IMatchingTool::match
virtual bool match(const xAOD::IParticle &recoObject, const std::string &chain, double matchThreshold=0.1, bool rerun=false) const =0
single object trigger matching. matchThreshold is typically the deltaR requirement to obtain positive...
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
CP::ISystematicsTool::applySystematicVariation
virtual StatusCode applySystematicVariation(const SystematicSet &systConfig)=0
effects: configure this tool for the given list of systematic variations.
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
ST::SUSYObjDef_xAOD::GetTaus
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
ST::SUSYObjDef_xAOD::m_tauDoTTM
bool m_tauDoTTM
Definition: SUSYObjDef_xAOD.h:730
ST::SUSYObjDef_xAOD::m_tauTrigEffTool
std::vector< asg::AnaToolHandle< TauAnalysisTools::ITauEfficiencyCorrectionsTool > > m_tauTrigEffTool
Definition: SUSYObjDef_xAOD.h:921
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
ITauSmearingTool.h
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
ST::SUSYObjDef_xAOD::IsSignalTau
bool IsSignalTau(const xAOD::TauJet &input, const float ptcut, const float etacut) const override final
Definition: Taus.cxx:112