ATLAS Offline Software
DiTauEfficiencyCorrectionsTool.cxx
Go to the documentation of this file.
1 
11 // EDM include(s):
14 
15 // Local include(s):
17 #include "TauAnalysisTools/Enums.h"
19 
20 
21 namespace TauAnalysisTools
22 {
23 
24 //______________________________________________________________________________
26  : asg::AsgMetadataTool( sName )
27  , m_vCommonEfficiencyTools()
28  , m_bIsData(false)
29  , m_bIsConfigured(false)
30 {
31  declareProperty( "EfficiencyCorrectionTypes", m_vEfficiencyCorrectionTypes = {} );
32  declareProperty( "InputFilePathJetIDHadTau", m_sInputFilePathJetIDHadTau = "" );
33  declareProperty( "VarNameJetIDHadTau", m_sVarNameJetIDHadTau = "" );
34  declareProperty( "RecommendationTag", m_sRecommendationTag = "2017-moriond" );
35  declareProperty( "JetIDLevel", m_iJetIDLevel = (int)JETIDBDTTIGHT );
36  declareProperty( "SkipTruthMatchCheck", m_bSkipTruthMatchCheck = false );
37 }
38 
39 
40 //______________________________________________________________________________
42 {
43  for (auto tTool : m_vCommonEfficiencyTools)
44  delete tTool;
45 }
46 
47 
48 //______________________________________________________________________________
50 {
51  // Greet the user:
52  ATH_MSG_INFO( "Initializing DiTauEfficiencyCorrectionsTool" );
53 
55  ATH_MSG_WARNING("Truth match check will be skipped. This is ONLY FOR TESTING PURPOSE!");
56 
57  // configure default set of variations if not set by the constructor using TauSelectionTool or the user
58  if ((m_sRecommendationTag== "2017-moriond") and m_vEfficiencyCorrectionTypes.empty())
60  };
61 
62  if (m_sRecommendationTag == "2017-moriond")
64  else
65  {
66  ATH_MSG_FATAL("Unknown RecommendationTag: "<<m_sRecommendationTag);
67  return StatusCode::FAILURE;
68  }
69 
70  for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
71  {
72  ATH_CHECK((**it).setProperty("OutputLevel", this->msg().level()));
73  ATH_CHECK((**it).initialize());
74  }
75 
76  // Add the affecting systematics to the global registry
78  if (!registry.registerSystematics(*this))
79  {
80  ATH_MSG_ERROR ("Unable to register the systematics");
81  return StatusCode::FAILURE;
82  }
83 
84  printConfig();
85 
86  return StatusCode::SUCCESS;
87 }
88 
89 
90 //______________________________________________________________________________
92 {
93  if (!m_bIsConfigured)
94  {
95  const xAOD::EventInfo* xEventInfo = nullptr;
96  ATH_CHECK(evtStore()->retrieve(xEventInfo,"EventInfo"));
98  m_bIsConfigured = true;
99  }
100 
101  return StatusCode::SUCCESS;
102 }
103 
104 
105 //______________________________________________________________________________
107 {
108  ATH_MSG_DEBUG( "DiTauEfficiencyCorrectionsTool with name " << name() << " is configured as follows:" );
109  for (auto iEfficiencyCorrectionType : m_vEfficiencyCorrectionTypes) {
110  ATH_MSG_DEBUG( " EfficiencyCorrectionTypes " << iEfficiencyCorrectionType );
111  }
112  ATH_MSG_DEBUG( " InputFilePathJetIDHadTau " << m_sInputFilePathJetIDHadTau );
113  ATH_MSG_DEBUG( " VarNameJetIDHadTau " << m_sVarNameJetIDHadTau );
114  ATH_MSG_DEBUG( " RecommendationTag " << m_sRecommendationTag );
115 }
116 
117 //______________________________________________________________________________
119  double& eff, unsigned int /*iRunNumber*/, unsigned int /*iMu*/ )
120 {
121  eff = 1.;
122 
123  if (m_bIsData)
124  return CP::CorrectionCode::Ok;
125 
126  for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
127  {
128  double dToolEff = 1.;
129  CP::CorrectionCode tmpCorrectionCode = (**it)->getEfficiencyScaleFactor(xDiTau, dToolEff);
130  if (tmpCorrectionCode != CP::CorrectionCode::Ok)
131  return tmpCorrectionCode;
132  eff *= dToolEff;
133  }
134  return CP::CorrectionCode::Ok;
135 }
136 
137 //______________________________________________________________________________
139  unsigned int iRunNumber, unsigned int iMu)
140 {
141  if (m_bIsData)
142  return CP::CorrectionCode::Ok;
143 
144  for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
145  {
146  CP::CorrectionCode tmpCorrectionCode = (**it)->applyEfficiencyScaleFactor(xDiTau, iRunNumber, iMu);
147  if (tmpCorrectionCode != CP::CorrectionCode::Ok)
148  {
149  return tmpCorrectionCode;
150  }
151  }
152  return CP::CorrectionCode::Ok;
153 }
154 
156 //______________________________________________________________________________
158 {
159  for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
160  if ((**it)->isAffectedBySystematic(systematic))
161  return true;
162  return false;
163 }
164 
166 //______________________________________________________________________________
168 {
169  CP::SystematicSet sAffectingSystematics;
170  for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
171  sAffectingSystematics.insert((**it)->affectingSystematics());
172  return sAffectingSystematics;
173 }
174 
176 //______________________________________________________________________________
178 {
179  CP::SystematicSet sRecommendedSystematics;
180  for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
181  {
182  sRecommendedSystematics.insert((**it)->recommendedSystematics());
183  }
184  return sRecommendedSystematics;
185 }
186 
187 //______________________________________________________________________________
189 {
190  for (auto it = m_vCommonEfficiencyTools.begin(); it != m_vCommonEfficiencyTools.end(); it++)
191  if ((**it)->applySystematicVariation(sSystematicSet) == StatusCode::FAILURE)
192  {
193  return StatusCode::FAILURE;
194  }
195  return StatusCode::SUCCESS;
196 }
197 
198 //=================================PRIVATE-PART=================================
199 
200 //______________________________________________________________________________
202 {
203  std::string sDirectory = "TauAnalysisTools/" + std::string(sSharedFilesVersion) + "/EfficiencyCorrections/";
204  for (auto iEfficiencyCorrectionType : m_vEfficiencyCorrectionTypes)
205  {
206  if (iEfficiencyCorrectionType == SFJetIDHadTau)
207  {
208  // only set vars if they have been configured by the user
209  if (m_sInputFilePathJetIDHadTau.empty()) m_sInputFilePathJetIDHadTau = sDirectory+"JetID_TrueHadDiTau_2017-fall.root";
210  if (m_sVarNameJetIDHadTau.empty()) m_sVarNameJetIDHadTau = "DiTauScaleFactorJetIDHadTau";
211 
213  m_vCommonEfficiencyTools.push_back(tTool);
215  ATH_CHECK(tTool->setProperty("InputFilePath", m_sInputFilePathJetIDHadTau));
216  ATH_CHECK(tTool->setProperty("VarName", m_sVarNameJetIDHadTau));
217  ATH_CHECK(tTool->setProperty("SkipTruthMatchCheck", m_bSkipTruthMatchCheck));
219  }
220  else
221  {
222  ATH_MSG_WARNING("unsupported EfficiencyCorrectionsType with enum " << iEfficiencyCorrectionType);
223  }
224  }
225  return StatusCode::SUCCESS;
226 }
227 
228 //______________________________________________________________________________
229 std::string DiTauEfficiencyCorrectionsTool::ConvertJetIDToString(const int iLevel) const
230 {
231  switch(iLevel)
232  {
233  case JETIDNONE:
234  return "ditaureconstruction";
235  break;
236  case JETIDBDTVERYLOOSE:
237  return "jetbdtsigveryloose";
238  break;
239  case JETIDBDTLOOSE:
240  return "jetbdtsigloose";
241  break;
242  case JETIDBDTMEDIUM:
243  return "jetbdtsigmedium";
244  break;
245  case JETIDBDTTIGHT:
246  return "jetbdtsigtight";
247  break;
248  default:
249  assert(false && "No valid ID level passed. Breaking up ...");
250  break;
251  }
252  return "";
253 }
254 
255 
256 } // namespace TauAnalysisTools
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
TauAnalysisTools::JETIDBDTLOOSE
@ JETIDBDTLOOSE
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:16
DiTauEfficiencyCorrectionsTool.h
Efficiency scale factors and uncertainties for ditau jets.
TauAnalysisTools
Definition: TruthCollectionMakerTau.h:16
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
asg::AnaToolHandle
a modified tool handle that allows its owner to configure new tools from the C++ side
Definition: AnaToolHandle.h:34
TauAnalysisTools::CommonDiTauEfficiencyTool
Definition: CommonDiTauEfficiencyTool.h:42
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::beginEvent
StatusCode beginEvent()
Function called when a new events is loaded.
Definition: DiTauEfficiencyCorrectionsTool.cxx:91
Enums.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_sInputFilePathJetIDHadTau
std::string m_sInputFilePathJetIDHadTau
Definition: DiTauEfficiencyCorrectionsTool.h:115
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TauAnalysisTools::JETIDBDTMEDIUM
@ JETIDBDTMEDIUM
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:17
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::DiTauEfficiencyCorrectionsTool
DiTauEfficiencyCorrectionsTool(const std::string &sName)
Create a proper constructor for Athena.
Definition: DiTauEfficiencyCorrectionsTool.cxx:25
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::getEfficiencyScaleFactor
virtual CP::CorrectionCode getEfficiencyScaleFactor(const xAOD::DiTauJet &xDiTau, double &eff, unsigned int iRunNumber=0, unsigned int iMu=0)
Get the ditau Efficiency Scale Factor as a return value.
Definition: DiTauEfficiencyCorrectionsTool.cxx:118
skel.it
it
Definition: skel.GENtoEVGEN.py:396
asg
Definition: DataHandleTestTool.h:28
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_bIsConfigured
bool m_bIsConfigured
Definition: DiTauEfficiencyCorrectionsTool.h:120
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::applySystematicVariation
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig)
apply systematic variations
Definition: DiTauEfficiencyCorrectionsTool.cxx:188
CP::SystematicVariation
Definition: SystematicVariation.h:47
ASG_MAKE_ANA_TOOL
#define ASG_MAKE_ANA_TOOL(handle, type)
create the tool in the given tool handle
Definition: AnaToolHandle.h:690
TauAnalysisTools::JETIDNONE
@ JETIDNONE
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:14
asg::AnaToolHandle::setProperty
StatusCode setProperty(const std::string &property, const T2 &value)
set the given property of the tool.
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_sVarNameJetIDHadTau
std::string m_sVarNameJetIDHadTau
Definition: DiTauEfficiencyCorrectionsTool.h:116
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::~DiTauEfficiencyCorrectionsTool
~DiTauEfficiencyCorrectionsTool()
Definition: DiTauEfficiencyCorrectionsTool.cxx:41
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::printConfig
virtual void printConfig() const
Print tool configuration.
Definition: DiTauEfficiencyCorrectionsTool.cxx:106
SharedFilesVersion.h
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_bSkipTruthMatchCheck
bool m_bSkipTruthMatchCheck
Definition: DiTauEfficiencyCorrectionsTool.h:118
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::affectingSystematics
virtual CP::SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by
Definition: DiTauEfficiencyCorrectionsTool.cxx:167
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TauAnalysisTools::JETIDBDTTIGHT
@ JETIDBDTTIGHT
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:18
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::ConvertJetIDToString
std::string ConvertJetIDToString(const int iLevel) const
Definition: DiTauEfficiencyCorrectionsTool.cxx:229
SystematicRegistry.h
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
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_vEfficiencyCorrectionTypes
std::vector< int > m_vEfficiencyCorrectionTypes
Definition: DiTauEfficiencyCorrectionsTool.h:113
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::recommendedSystematics
virtual CP::SystematicSet recommendedSystematics() const
returns: the list of all systematics this tool recommends to use
Definition: DiTauEfficiencyCorrectionsTool.cxx:177
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::applyEfficiencyScaleFactor
virtual CP::CorrectionCode applyEfficiencyScaleFactor(const xAOD::DiTauJet &xDiTau, unsigned int iRunNumber=0, unsigned int iMu=0)
decorate the ditau jet with eff scale factor
Definition: DiTauEfficiencyCorrectionsTool.cxx:138
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_bIsData
bool m_bIsData
Definition: DiTauEfficiencyCorrectionsTool.h:119
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::initialize
virtual StatusCode initialize()
Function initialising the tool.
Definition: DiTauEfficiencyCorrectionsTool.cxx:49
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TauAnalysisTools::SFJetIDHadTau
@ SFJetIDHadTau
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:70
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_iJetIDLevel
int m_iJetIDLevel
Definition: DiTauEfficiencyCorrectionsTool.h:121
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::isAffectedBySystematic
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const
returns whether this tool is affected by the given systematic
Definition: DiTauEfficiencyCorrectionsTool.cxx:157
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
xAOD::DiTauJet_v1
Definition: DiTauJet_v1.h:31
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::initializeTools_2017_moriond
StatusCode initializeTools_2017_moriond()
Initialize Moriond 2017 recommendations.
Definition: DiTauEfficiencyCorrectionsTool.cxx:201
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_sRecommendationTag
std::string m_sRecommendationTag
Definition: DiTauEfficiencyCorrectionsTool.h:117
TauAnalysisTools::JETIDBDTVERYLOOSE
@ JETIDBDTVERYLOOSE
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:15
TauAnalysisTools::DiTauEfficiencyCorrectionsTool::m_vCommonEfficiencyTools
std::vector< asg::AnaToolHandle< IDiTauEfficiencyCorrectionsTool > * > m_vCommonEfficiencyTools
Definition: DiTauEfficiencyCorrectionsTool.h:114
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25