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