ATLAS Offline Software
TauScaleFactorCalculator.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 // $Id: TauScaleFactorCalculator.cxx 805414 2017-05-24 12:21:29Z yili $
6 #include <string>
7 
10 #include "TopEvent/EventTools.h"
11 
14 
15 namespace top {
17  asg::AsgTool(name),
18  m_config(nullptr),
19  m_tauEffCorrTool("TauAnalysisTools::TauEfficiencyCorrectionsTool"),
20  m_tauEffCorrToolLoose("TauAnalysisTools::TauEfficiencyCorrectionsToolLoose"),
21 
22  m_systNominal(CP::SystematicSet()) {
23  declareProperty("config", m_config);
24  }
25 
27  ATH_MSG_INFO(" top::TauScaleFactorCalculator initialize");
28 
29  top::check(m_tauEffCorrTool.retrieve(),
30  "Failed to retrieve tau efficiency corrections tool");
31 
32  // How to get the recommended/affecting systematics...
33  // Should be empty- but lets be sure
34  m_syst_map.clear();
35  // Add all recommended systematics to be clear
36  // Tau-electron overlap removal up/down, true hadtau
37 
38  for (auto tauSFpair : top::tauSF_name) {
39  m_syst_map[tauSFpair.second.Data()] = CP::SystematicSet(tauSFpair.second.Data());
40  }
41 
42  return StatusCode::SUCCESS;
43  }
44 
47  for (auto currentSystematic : *m_config->systSgKeyMapTaus()) {
48  const xAOD::TauJetContainer* taus(nullptr);
49  top::check(evtStore()->retrieve(taus, currentSystematic.second),
50  "failed to retrieve taus");
51 
53 
55  for (auto tauPtr : *taus) {
57  bool passSelection(false);
58  if (tauPtr->isAvailable<char>("passPreORSelection")) {
59  if (tauPtr->auxdataConst<char>("passPreORSelection") == 1) {
60  passSelection = true;
61  }
62  }
63  if (tauPtr->isAvailable<char>("passPreORSelectionLoose")) {
64  if (tauPtr->auxdataConst<char>("passPreORSelectionLoose") == 1) {
65  passSelection = true;
66  }
67  }
68 
70  if (!passSelection) continue;
71 
72  //============================================================
73  // Find the nominal SF for the tight/loose tau IDs for every
74  // systematic uncertainty.
75  //
76  // Make sure we set both tools to nominal for each tau
77  //============================================================
78 
79  top::check(m_tauEffCorrTool->applySystematicVariation(m_systNominal),
80  "Failed to set tau efficiency correction"
81  " tool to nominal value");
82  top::check(m_tauEffCorrToolLoose->applySystematicVariation(m_systNominal),
83  "Failed to set (loose) tau efficiency correction"
84  " tool to nominal value");
85 
86  double nominalSF(0.0), nominalSFLoose(0.0);
87 
88  top::check(m_tauEffCorrTool->getEfficiencyScaleFactor(*tauPtr, nominalSF),
89  "Failed to get nominal tau SF");
90  top::check(m_tauEffCorrToolLoose->getEfficiencyScaleFactor(*tauPtr,
91  nominalSFLoose),
92  "Failed to get nominal (loose) tau SF");
93 
95  tauPtr->auxdecor<float>("TAU_SF_NOMINAL") = nominalSF;
96  tauPtr->auxdecor<float>("TAU_SF_NOMINAL_loose") = nominalSFLoose;
97 
99  if (currentSystematic.first == m_config->nominalHashValue()) {
100  for (const auto& i : m_syst_map) {
101  double SF(0.0), SF_loose(0.0);
102  const std::string decoration_name = i.first;
103  const std::string decoration_name_loose = i.first + "_loose";
104  top::check(m_tauEffCorrTool->applySystematicVariation(i.second),
105  "Failed to set tau efficiency correction"
106  " tool to nominal value");
107  top::check(m_tauEffCorrToolLoose->applySystematicVariation(i.second),
108  "Failed to set (loose) tau efficiency correction"
109  " tool to nominal value");
110  top::check(m_tauEffCorrTool->getEfficiencyScaleFactor(*tauPtr, SF),
111  "Failed to get nominal tau SF");
112  top::check(m_tauEffCorrToolLoose->getEfficiencyScaleFactor(*tauPtr,
113  SF_loose),
114  "Failed to get nominal (loose) tau SF");
115  tauPtr->auxdecor<float>(decoration_name) = SF;
116  tauPtr->auxdecor<float>(decoration_name_loose) = SF_loose;
117  }
118  } // Calibration systematic is nominal, so calculate SF systematics
119  }
120  }
121 
122 
123  return StatusCode::SUCCESS;
124  }
125 } // namespace top
TauScaleFactorCalculator.h
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
asg
Definition: DataHandleTestTool.h:28
TRT_PAI_gasdata::SF
const float SF[NF]
Cross sections for Fluor.
Definition: TRT_PAI_gasdata.h:285
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
top::TauScaleFactorCalculator::m_systNominal
CP::SystematicSet m_systNominal
Definition: TauScaleFactorCalculator.h:47
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
top::TauScaleFactorCalculator::m_syst_map
std::map< std::string, CP::SystematicSet > m_syst_map
Definition: TauScaleFactorCalculator.h:48
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
TauJetContainer.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TopConfig.h
top::TauScaleFactorCalculator::m_tauEffCorrToolLoose
ToolHandle< TauAnalysisTools::ITauEfficiencyCorrectionsTool > m_tauEffCorrToolLoose
Definition: TauScaleFactorCalculator.h:45
top::TauScaleFactorCalculator::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: TauScaleFactorCalculator.h:42
top::TauScaleFactorCalculator::execute
StatusCode execute()
Definition: TauScaleFactorCalculator.cxx:45
top::tauSF_name
const std::map< topSFSyst, TString > tauSF_name
Definition: ScaleFactorRetriever.h:131
ScaleFactorRetriever.h
top::TauScaleFactorCalculator::m_tauEffCorrTool
ToolHandle< TauAnalysisTools::ITauEfficiencyCorrectionsTool > m_tauEffCorrTool
Definition: TauScaleFactorCalculator.h:44
top::TauScaleFactorCalculator::TauScaleFactorCalculator
TauScaleFactorCalculator(const std::string &name)
Definition: TauScaleFactorCalculator.cxx:16
top::TauScaleFactorCalculator::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: TauScaleFactorCalculator.cxx:26