ATLAS Offline Software
Loading...
Searching...
No Matches
TauAnalysisTools::CommonDiTauEfficiencyTool Class Reference

#include <CommonDiTauEfficiencyTool.h>

Inheritance diagram for TauAnalysisTools::CommonDiTauEfficiencyTool:
Collaboration diagram for TauAnalysisTools::CommonDiTauEfficiencyTool:

Public Member Functions

 CommonDiTauEfficiencyTool (const std::string &sName)
 Create a proper constructor for Athena.
 ~CommonDiTauEfficiencyTool ()
virtual StatusCode initialize ()
 Dummy implementation of the initialisation function.
virtual CP::CorrectionCode getEfficiencyScaleFactor (const xAOD::DiTauJet &xDiTau, double &dEfficiencyScaleFactor)
 Get the Efficiency Scale Factor of ditau jet.
virtual CP::CorrectionCode applyEfficiencyScaleFactor (const xAOD::DiTauJet &xDiTau)
 Get the Efficiency Scale Factor of ditau jet.
virtual bool isAffectedBySystematic (const CP::SystematicVariation &systematic) const
 returns: whether this tool is affected by the given systematics
virtual CP::SystematicSet affectingSystematics () const
 returns: the list of all systematics this tool can be affected by
virtual CP::SystematicSet recommendedSystematics () const
 returns: the list of all systematics this tool recommends to use
virtual StatusCode applySystematicVariation (const CP::SystematicSet &sSystematicSet)
 configure this tool for the given list of systematic variations.
virtual void print () const
 Print the state of the tool.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
Additional helper functions, not directly mimicking Athena
template<class T>
const T * getProperty (const std::string &name) const
 Get one of the tool's properties.
const std::string & msg_level_name () const __attribute__((deprecated))
 A deprecated function for getting the message level's name.
const std::string & getName (const void *ptr) const
 Get the name of an object that is / should be in the event store.
SG::sgkey_t getKey (const void *ptr) const
 Get the (hashed) key of an object that is in the event store.

Public Attributes

std::function< double(const xAOD::DiTauJet &xDiTau)> m_fXDiTau
std::function< double(const xAOD::DiTauJet &xDiTau)> m_fYDiTau
std::function< double(const xAOD::DiTauJet &xDiTau)> m_fZDiTau

Protected Types

typedef std::tuple< TObject *, CP::CorrectionCode(*)(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[]) > tTupleObjectFunc
typedef std::map< std::string, tTupleObjectFunctSFMAP

Protected Member Functions

void ReadInputs (std::unique_ptr< TFile > &fFile)
void addHistogramToSFMap (TKey *kKey, const std::string &sKeyName)
virtual CP::CorrectionCode getValue (const std::string &sHistName, const xAOD::DiTauJet &xDiTau, double &dEfficiencyScaleFactor) const
 Get the scale factor from a particular recommendations histogram.
void generateSystematicSets ()
 generate a set of relevant systematic variations to be applied
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Static Protected Member Functions

static CP::CorrectionCode getValueTH1 (const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[])
static CP::CorrectionCode getValueTH2 (const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[])

Protected Attributes

std::unique_ptr< tSFMAPm_mSF
std::unordered_map< CP::SystematicSet, std::string > m_mSystematicSets
const CP::SystematicSetm_sSystematicSet
std::map< std::string, std::string > m_mSystematicsHistNames
bool m_bSFIsAvailableDiTau
 true if scale factor name is already decorated
bool m_bSFIsAvailableCheckedDiTau
 true if cale factor name is already decorated has already been checked
CP::SystematicSet m_sAffectingSystematics
CP::SystematicSet m_sRecommendedSystematics
Gaudi::Property< bool > m_bSkipTruthMatchCheck {this, "SkipTruthMatchCheck", false}
Gaudi::Property< std::string > m_sInputFilePath {this, "InputFilePath", ""}
Gaudi::Property< std::string > m_sWP {this, "WP", ""}
Gaudi::Property< std::string > m_sVarName {this, "VarName", ""}
std::string m_sInputFileName
std::string m_sSFHistName
TruthMatchedParticleType m_eCheckTruth

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default).
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default).
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 44 of file CommonDiTauEfficiencyTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

◆ tSFMAP

typedef std::map<std::string, tTupleObjectFunc > TauAnalysisTools::CommonDiTauEfficiencyTool::tSFMAP
protected

Definition at line 102 of file CommonDiTauEfficiencyTool.h.

◆ tTupleObjectFunc

typedef std::tuple<TObject*, CP::CorrectionCode (*)(const TObject* oObject, double& dEfficiencyScaleFactor, double dVars[] ) > TauAnalysisTools::CommonDiTauEfficiencyTool::tTupleObjectFunc
protected

Definition at line 101 of file CommonDiTauEfficiencyTool.h.

Constructor & Destructor Documentation

◆ CommonDiTauEfficiencyTool()

CommonDiTauEfficiencyTool::CommonDiTauEfficiencyTool ( const std::string & sName)

Create a proper constructor for Athena.

Definition at line 22 of file CommonDiTauEfficiencyTool.cxx.

23 : asg::AsgTool( sName )
27 , m_sSystematicSet(nullptr)
31{
32}
std::function< double(const xAOD::DiTauJet &xDiTau)> m_fZDiTau
std::function< double(const xAOD::DiTauJet &xDiTau)> m_fXDiTau
bool m_bSFIsAvailableDiTau
true if scale factor name is already decorated
bool m_bSFIsAvailableCheckedDiTau
true if cale factor name is already decorated has already been checked
std::function< double(const xAOD::DiTauJet &xDiTau)> m_fYDiTau
double TruthSubleadPt(const xAOD::DiTauJet &xDiTau)
return the truth vis pT of the subleading pT matched particle.
double TruthDeltaR(const xAOD::DiTauJet &xDiTau)
return the dR of between the leading and subleading pT matched particle.
double TruthLeadPt(const xAOD::DiTauJet &xDiTau)
return the truth vis pT of the leading pT matched particle.

◆ ~CommonDiTauEfficiencyTool()

CommonDiTauEfficiencyTool::~CommonDiTauEfficiencyTool ( )

Definition at line 34 of file CommonDiTauEfficiencyTool.cxx.

35{
36 if (m_mSF)
37 for (auto mEntry : *m_mSF)
38 delete std::get<0>(mEntry.second);
39}

Member Function Documentation

◆ addHistogramToSFMap()

void CommonDiTauEfficiencyTool::addHistogramToSFMap ( TKey * kKey,
const std::string & sKeyName )
protected

Definition at line 328 of file CommonDiTauEfficiencyTool.cxx.

329{
330 // handling for the 3 different input types TH1F/TH1D/TF1, function pointer
331 // handle the access methods for the final scale factor retrieval
332 TClass *cClass = gROOT->GetClass(kKey->GetClassName());
333 if (cClass->InheritsFrom("TH2"))
334 {
335 TH2* oObject = static_cast<TH2*>(kKey->ReadObj());
336 oObject->SetDirectory(0);
337 (*m_mSF)[sKeyName] = tTupleObjectFunc(oObject,&getValueTH2);
338 ATH_MSG_DEBUG("added histogram with name "<<sKeyName);
339 }
340 else if (cClass->InheritsFrom("TH1"))
341 {
342 TH1* oObject = static_cast<TH1*>(kKey->ReadObj());
343 oObject->SetDirectory(0);
344 (*m_mSF)[sKeyName] = tTupleObjectFunc(oObject,&getValueTH1);
345 ATH_MSG_DEBUG("added histogram with name "<<sKeyName);
346 }
347 else
348 {
349 ATH_MSG_DEBUG("ignored object with name "<<sKeyName);
350 }
351}
#define ATH_MSG_DEBUG(x,...)
std::tuple< TObject *, CP::CorrectionCode(*)(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[]) > tTupleObjectFunc
static CP::CorrectionCode getValueTH2(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[])
static CP::CorrectionCode getValueTH1(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[])

◆ affectingSystematics()

CP::SystematicSet CommonDiTauEfficiencyTool::affectingSystematics ( ) const
virtual

returns: the list of all systematics this tool can be affected by

Implements CP::IReentrantSystematicsTool.

Definition at line 210 of file CommonDiTauEfficiencyTool.cxx.

◆ applyEfficiencyScaleFactor()

CP::CorrectionCode CommonDiTauEfficiencyTool::applyEfficiencyScaleFactor ( const xAOD::DiTauJet & xDiTau)
virtual

Get the Efficiency Scale Factor of ditau jet.

Parameters
xDiTau
Returns
CP::CorrectionCode

Implements TauAnalysisTools::IDiTauEfficiencyCorrectionsTool.

Definition at line 169 of file CommonDiTauEfficiencyTool.cxx.

170{
171 double dSf = 0.;
172
175 {
176 m_bSFIsAvailableDiTau = decor.isAvailable(xDiTau);
179 {
180 ATH_MSG_DEBUG(m_sVarName << " decoration is available on first ditau processed, switched of applyEfficiencyScaleFactor for further ditaus.");
181 ATH_MSG_DEBUG("If an application of efficiency scale factors needs to be redone, please pass a shallow copy of the original ditau.");
182 }
183 }
186
187 // retrieve scale factor
188 CP::CorrectionCode tmpCorrectionCode = getEfficiencyScaleFactor(xDiTau, dSf);
189 // adding scale factor to tau as decoration
190 decor(xDiTau) = dSf;
191
192 return tmpCorrectionCode;
193}
@ Ok
The correction was done successfully.
virtual CP::CorrectionCode getEfficiencyScaleFactor(const xAOD::DiTauJet &xDiTau, double &dEfficiencyScaleFactor)
Get the Efficiency Scale Factor of ditau jet.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
Definition AuxElement.h:576

◆ applySystematicVariation()

StatusCode CommonDiTauEfficiencyTool::applySystematicVariation ( const CP::SystematicSet & sSystematicSet)
virtual

configure this tool for the given list of systematic variations.

any requested systematics that are not affecting this tool will be silently ignored

Implements CP::ISystematicsTool.

Definition at line 235 of file CommonDiTauEfficiencyTool.cxx.

236{
237
238 // first check if we already know this systematic configuration
239 auto itSystematicSet = m_mSystematicSets.find(sSystematicSet);
240 if (itSystematicSet != m_mSystematicSets.end())
241 {
242 m_sSystematicSet = &itSystematicSet->first;
243 return StatusCode::SUCCESS;
244 }
245
246 // sanity checks if systematic set is supported
247 double dDirection = 0.;
248 CP::SystematicSet sSystematicSetAvailable;
249 for (const auto & sSyst : sSystematicSet)
250 {
251 // check if systematic is available
252 auto it = m_mSystematicsHistNames.find(sSyst.basename());
253 if (it == m_mSystematicsHistNames.end())
254 {
255 ATH_MSG_VERBOSE("unsupported systematic variation: "<< sSyst.basename()<<"; skipping this one");
256 continue;
257 }
258
259
260 if (sSyst.parameter() * dDirection < 0)
261 {
262 ATH_MSG_ERROR("unsupported set of systematic variations, you should either use only \"UP\" or only \"DOWN\" systematics in one set!");
263 ATH_MSG_ERROR("systematic set will not be applied");
264 return StatusCode::FAILURE;
265 }
266 dDirection = sSyst.parameter();
267
268 if ((m_sRecommendedSystematics.find(sSyst.basename()) != m_sRecommendedSystematics.end()) and sSystematicSet.size() > 1)
269 {
270 ATH_MSG_ERROR("unsupported set of systematic variations, you should not combine \"TAUS_{TRUE|FAKE}_EFF_*_TOTAL\" with other systematic variations!");
271 ATH_MSG_ERROR("systematic set will not be applied");
272 return StatusCode::FAILURE;
273 }
274
275 // finally add the systematic to the set of systematics to process
276 sSystematicSetAvailable.insert(sSyst);
277 }
278
279 // store this calibration for future use, and make it current
280 m_sSystematicSet = &m_mSystematicSets.insert(std::pair<CP::SystematicSet,std::string>(sSystematicSetAvailable, sSystematicSet.name())).first->first;
281
282 return StatusCode::SUCCESS;
283}
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_VERBOSE(x,...)
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
std::unordered_map< CP::SystematicSet, std::string > m_mSystematicSets
std::map< std::string, std::string > m_mSystematicsHistNames

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ generateSystematicSets()

void CommonDiTauEfficiencyTool::generateSystematicSets ( )
protected

generate a set of relevant systematic variations to be applied

Definition at line 367 of file CommonDiTauEfficiencyTool.cxx.

368{
369 // creation of basic string for all NPs, e.g. "TAUS_TRUEHADTAU_EFF_RECO_"
370 std::vector<std::string> vSplitInputFilePath = {};
371 split(m_sInputFileName,'_',vSplitInputFilePath);
372 std::string sEfficiencyType = vSplitInputFilePath.at(0);
373 std::string sTruthType = vSplitInputFilePath.at(1);
374 std::transform(sEfficiencyType.begin(), sEfficiencyType.end(), sEfficiencyType.begin(), toupper);
375 std::transform(sTruthType.begin(), sTruthType.end(), sTruthType.begin(), toupper);
376 std::string sSystematicBaseString = "TAUS_"+sTruthType+"_EFF_"+sEfficiencyType+"_";
377 // set truth type to check for in truth matching
378 if (sTruthType=="TRUEHADTAU") m_eCheckTruth = TauAnalysisTools::TruthHadronicTau;
379 if (sTruthType=="TRUEHADDITAU") m_eCheckTruth = TauAnalysisTools::TruthHadronicDiTau;
380
381 for (const auto & mSF : *m_mSF)
382 {
383 // parse for nuisance parameter in histogram name
384 std::vector<std::string> vSplitNP = {};
385 split(mSF.first,'_',vSplitNP);
386 std::string sNP = vSplitNP.at(0);
387 std::string sNPUppercase = vSplitNP.at(0);
388 // skip nominal scale factors
389 if (sNP == "sf") continue;
390 // test if NP starts with a capital letter indicating that this should be recommended
391 bool bIsRecommended = false;
392 if (isupper(sNP.at(0)))
393 bIsRecommended = true;
394 // make sNP uppercase and build final NP entry name
395 std::transform(sNPUppercase.begin(), sNPUppercase.end(), sNPUppercase.begin(), toupper);
396 std::string sSystematicString = sSystematicBaseString+sNPUppercase;
397 // add all found systematics to the AffectingSystematics
398 m_sAffectingSystematics.insert(CP::SystematicVariation (sSystematicString, 1));
399 m_sAffectingSystematics.insert(CP::SystematicVariation (sSystematicString, -1));
400 // only add found uppercase systematics to the RecommendedSystematics
401 if (bIsRecommended)
402 {
403 m_sRecommendedSystematics.insert(CP::SystematicVariation (sSystematicString, 1));
404 m_sRecommendedSystematics.insert(CP::SystematicVariation (sSystematicString, -1));
405 }
406 ATH_MSG_DEBUG("connected base name " << sNP << " with systematic " <<sSystematicString);
407 m_mSystematicsHistNames.insert({sSystematicString,sNP});
408 }
409}
void split(const std::string &sInput, const char cDelim, std::vector< std::string > &vOut)

◆ getEfficiencyScaleFactor()

CP::CorrectionCode CommonDiTauEfficiencyTool::getEfficiencyScaleFactor ( const xAOD::DiTauJet & xDiTau,
double & dEfficiencyScaleFactor )
virtual

Get the Efficiency Scale Factor of ditau jet.

Parameters
xDiTau: reco DiTauJet
dEfficiencyScaleFactor: reference to output variable where efficiency is returned
Returns
CP::CorrectionCode

Implements TauAnalysisTools::IDiTauEfficiencyCorrectionsTool.

Definition at line 92 of file CommonDiTauEfficiencyTool.cxx.

94{
95 // check which true state is requestet
97 {
98 dEfficiencyScaleFactor = 1.;
100 }
101
102 CP::CorrectionCode tmpCorrectionCode = getValue(m_sSFHistName,
103 xDiTau,
104 dEfficiencyScaleFactor);
105 // return correction code if histogram is not available
106 if (tmpCorrectionCode != CP::CorrectionCode::Ok)
107 return tmpCorrectionCode;
108
109 // skip further process if systematic set is empty
110 if (m_sSystematicSet->size() == 0)
112
113 // get uncertainties summed in quadrature
114 double dTotalSystematic2 = 0.;
115 double dDirection = 0.;
116 for (const auto & syst : *m_sSystematicSet)
117 {
118
119 // check if systematic is available
120 auto it = m_mSystematicsHistNames.find(syst.basename());
121 if (it == m_mSystematicsHistNames.end())[[unlikely]] continue;
122 // get uncertainty value
123 double dUncertaintySyst = 0.;
124
125 // needed for up/down decision
126 dDirection = syst.parameter();
127
128 // build up histogram name
129 std::string sHistName = it->second;
130 if (dDirection>0) sHistName+="_up";
131 else sHistName+="_down";
132 if (!m_sWP.empty()) sHistName+="_"+m_sWP;
133
134 // get the uncertainty from the histogram
135 tmpCorrectionCode = getValue(sHistName,
136 xDiTau,
137 dUncertaintySyst);
138
139 // return correction code if histogram is not available
140 if (tmpCorrectionCode != CP::CorrectionCode::Ok)
141 return tmpCorrectionCode;
142
143 // scale uncertainty with direction, i.e. +/- n*sigma
144 dUncertaintySyst *= dDirection;
145
146 // square uncertainty and add to total uncertainty
147 dTotalSystematic2 += dUncertaintySyst * dUncertaintySyst;
148 }
149
150 // now use dDirection to use up/down uncertainty
151 dDirection = (dDirection > 0.) ? 1. : -1.;
152
153 // finally apply uncertainty (eff * ( 1 +/- \sum )
154 dEfficiencyScaleFactor *= 1. + dDirection * std::sqrt(dTotalSystematic2);
155
157}
virtual CP::CorrectionCode getValue(const std::string &sHistName, const xAOD::DiTauJet &xDiTau, double &dEfficiencyScaleFactor) const
Get the scale factor from a particular recommendations histogram.
TruthMatchedParticleType getTruthParticleType(const xAOD::TauJet &xTau)
return TauJet match type
#define unlikely(x)

◆ getKey()

SG::sgkey_t asg::AsgTool::getKey ( const void * ptr) const
inherited

Get the (hashed) key of an object that is in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::Event both provide ways for getting the SG::sgkey_t key for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getName
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The hashed key of the object in the store. If not found, an invalid (zero) key.

Definition at line 119 of file AsgTool.cxx.

119 {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::Event, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
ServiceHandle< StoreGateSvc > & evtStore()

◆ getName()

const std::string & asg::AsgTool::getName ( const void * ptr) const
inherited

Get the name of an object that is / should be in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::Event both provide ways for getting the std::string name for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getKey
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The string name of the object in the store. If not found, an empty string.

Definition at line 106 of file AsgTool.cxx.

106 {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::Event, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }

◆ getProperty()

template<class T>
const T * asg::AsgTool::getProperty ( const std::string & name) const
inherited

Get one of the tool's properties.

◆ getValue()

CP::CorrectionCode CommonDiTauEfficiencyTool::getValue ( const std::string & sHistName,
const xAOD::DiTauJet & xDiTau,
double & dEfficiencyScaleFactor ) const
protectedvirtual

Get the scale factor from a particular recommendations histogram.

Parameters
sHistName
xDiTau
dEfficiencyScaleFactor
Returns
CP::CorrectionCode

Definition at line 416 of file CommonDiTauEfficiencyTool.cxx.

419{
420 const tSFMAP& mSF = *m_mSF;
421 auto it = mSF.find (sHistName);
422 if (it == mSF.end())
423 {
424 ATH_MSG_ERROR("Object with name "<<sHistName<<" was not found in input file.");
425 ATH_MSG_DEBUG("Content of input file");
426 for (const auto & eEntry : mSF){
427 ATH_MSG_DEBUG(" Entry: "<<eEntry.first);
428 }
430 }
431
432 // get a tuple (TObject*,functionPointer) from the scale factor map
433 tTupleObjectFunc tTuple = it->second;
434
435 // get pt and eta (for x and y axis respectively)
436 double dX = m_fXDiTau(xDiTau);
437 double dY = m_fYDiTau(xDiTau);
438 double dZ = m_fZDiTau(xDiTau);
439
440 double dVars[3] = {dX, dY, dZ};
441 // finally obtain efficiency scale factor from TH1F/TH1D/TF1, by calling the
442 // function pointer stored in the tuple from the scale factor map
443 return (std::get<1>(tTuple))(std::get<0>(tTuple), dEfficiencyScaleFactor, dVars);
444}
@ Error
Some error happened during the object correction.
std::map< std::string, tTupleObjectFunc > tSFMAP

◆ getValueTH1()

CP::CorrectionCode CommonDiTauEfficiencyTool::getValueTH1 ( const TObject * oObject,
double & dEfficiencyScaleFactor,
double dVars[] )
staticprotected

Definition at line 476 of file CommonDiTauEfficiencyTool.cxx.

478{
479 double dPt = dVars[0];
480
481 const TH1* hHist = dynamic_cast<const TH1*>(oObject);
482
483 if (!hHist)
484 {
485 // ATH_MSG_ERROR("Problem with casting TObject of type "<<oObject->ClassName()<<" to TH2F");
487 }
488
489 // protect values from underflow bins
490 dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
491 // protect values from overflow bins (times .999 to keep it inside last bin)
492 dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
493
494 // get bin from TH2 depending on x and y values; finally set the scale factor
495 int iBin = hHist->FindFixBin(dPt);
496 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
498}

◆ getValueTH2()

CP::CorrectionCode CommonDiTauEfficiencyTool::getValueTH2 ( const TObject * oObject,
double & dEfficiencyScaleFactor,
double dVars[] )
staticprotected

Definition at line 506 of file CommonDiTauEfficiencyTool.cxx.

508{
509 double dPt = dVars[0];
510 double dEta = dVars[1];
511
512 const TH2* hHist = dynamic_cast<const TH2*>(oObject);
513
514 if (!hHist)
515 {
516 // ATH_MSG_ERROR("Problem with casting TObject of type "<<oObject->ClassName()<<" to TH2F");
518 }
519
520 // protect values from underflow bins
521 dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
522 dEta = std::max(dEta,hHist->GetYaxis()->GetXmin());
523 // protect values from overflow bins (times .999 to keep it inside last bin)
524 dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
525 dEta = std::min(dEta,hHist->GetYaxis()->GetXmax() * .999);
526
527 // get bin from TH2 depending on x and y values; finally set the scale factor
528 int iBin = hHist->FindFixBin(dPt,dEta);
529 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
531}
bool dEta(const xAOD::TauJet &tau, const xAOD::CaloVertexedTopoCluster &cluster, float &out)

◆ initialize()

StatusCode CommonDiTauEfficiencyTool::initialize ( void )
virtual

Dummy implementation of the initialisation function.

It's here to allow the dual-use tools to skip defining an initialisation function. Since many are doing so...

Reimplemented from asg::AsgTool.

Definition at line 49 of file CommonDiTauEfficiencyTool.cxx.

50{
51 ATH_MSG_INFO( "Initializing CommonDiTauEfficiencyTool" );
52 // only read in histograms once
53 if (m_mSF==nullptr)
54 {
55 std::string sInputFilePath = PathResolverFindCalibFile(m_sInputFilePath);
56
57 m_mSF = std::make_unique< tSFMAP >();
58 std::unique_ptr< TFile > fSF( TFile::Open( sInputFilePath.c_str(), "READ" ) );
59 if(!fSF)
60 {
61 ATH_MSG_FATAL("Could not open file " << sInputFilePath.c_str());
62 return StatusCode::FAILURE;
63 }
64 ReadInputs(fSF);
65 fSF->Close();
66 }
67
68 // needed later on in generateSystematicSets(), maybe move it there
69 std::vector<std::string> vInputFilePath;
70 split(m_sInputFilePath,'/',vInputFilePath);
71 m_sInputFileName = vInputFilePath.back();
72
74
75 if (m_sWP.size()>0)
76 m_sSFHistName = "sf_"+m_sWP;
77
78 // load empty systematic variation by default
79 if (applySystematicVariation(CP::SystematicSet()) != StatusCode::SUCCESS )
80 return StatusCode::FAILURE;
81
82 return StatusCode::SUCCESS;
83}
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
virtual StatusCode applySystematicVariation(const CP::SystematicSet &sSystematicSet)
configure this tool for the given list of systematic variations.
void generateSystematicSets()
generate a set of relevant systematic variations to be applied
void ReadInputs(std::unique_ptr< TFile > &fFile)

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ isAffectedBySystematic()

bool CommonDiTauEfficiencyTool::isAffectedBySystematic ( const CP::SystematicVariation & systematic) const
virtual

returns: whether this tool is affected by the given systematics

Implements CP::ISystematicsTool.

Definition at line 199 of file CommonDiTauEfficiencyTool.cxx.

200{
201 CP::SystematicSet sys = affectingSystematics();
202 return sys.find(systematic) != sys.end();
203}
virtual CP::SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msg_level_name()

const std::string & asg::AsgTool::msg_level_name ( ) const
inherited

A deprecated function for getting the message level's name.

Instead of using this, weirdly named function, user code should get the string name of the current minimum message level (in case they really need it...), with:

MSG::name( msg().level() )

This function's name doesn't follow the ATLAS coding rules, and as such will be removed in the not too distant future.

Returns
The string name of the current minimum message level that's printed

Definition at line 101 of file AsgTool.cxx.

101 {
102
103 return MSG::name( msg().level() );
104 }
MsgStream & msg() const
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ print()

◆ ReadInputs()

void CommonDiTauEfficiencyTool::ReadInputs ( std::unique_ptr< TFile > & fFile)
protected

Definition at line 286 of file CommonDiTauEfficiencyTool.cxx.

287{
288 m_mSF->clear();
289
290 // initialize function pointer
294
295 TKey *kKey;
296 TIter itNext(fFile->GetListOfKeys());
297 while ((kKey = (TKey*)itNext()))
298 {
299 // parse file content for objects of type TNamed, check their title for
300 // known strings and reset funtion pointer
301 std::string sKeyName = kKey->GetName();
302
303 std::vector<std::string> vSplitName = {};
304 split(sKeyName,'_',vSplitName);
305 if (vSplitName[0] == "sf")
306 {
307 addHistogramToSFMap(kKey, sKeyName);
308 }
309 else
310 {
311 if (sKeyName.find("_up_") != std::string::npos or sKeyName.find("_down_") != std::string::npos)
312 addHistogramToSFMap(kKey, sKeyName);
313 else
314 {
315 size_t iPos = sKeyName.find('_');
316 addHistogramToSFMap(kKey, sKeyName.substr(0,iPos)+"_up"+sKeyName.substr(iPos));
317 addHistogramToSFMap(kKey, sKeyName.substr(0,iPos)+"_down"+sKeyName.substr(iPos));
318 }
319 }
320 }
321 ATH_MSG_INFO("data loaded from " << fFile->GetName());
322}
void addHistogramToSFMap(TKey *kKey, const std::string &sKeyName)

◆ recommendedSystematics()

CP::SystematicSet CommonDiTauEfficiencyTool::recommendedSystematics ( ) const
virtual

returns: the list of all systematics this tool recommends to use

Implements CP::IReentrantSystematicsTool.

Definition at line 219 of file CommonDiTauEfficiencyTool.cxx.

220{
222}

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, and AthCheckedComponent<::AthAlgTool >.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_bSFIsAvailableCheckedDiTau

bool TauAnalysisTools::CommonDiTauEfficiencyTool::m_bSFIsAvailableCheckedDiTau
protected

true if cale factor name is already decorated has already been checked

Definition at line 142 of file CommonDiTauEfficiencyTool.h.

◆ m_bSFIsAvailableDiTau

bool TauAnalysisTools::CommonDiTauEfficiencyTool::m_bSFIsAvailableDiTau
protected

true if scale factor name is already decorated

Definition at line 140 of file CommonDiTauEfficiencyTool.h.

◆ m_bSkipTruthMatchCheck

Gaudi::Property<bool> TauAnalysisTools::CommonDiTauEfficiencyTool::m_bSkipTruthMatchCheck {this, "SkipTruthMatchCheck", false}
protected

Definition at line 147 of file CommonDiTauEfficiencyTool.h.

147{this, "SkipTruthMatchCheck", false};

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default).

Definition at line 393 of file AthCommonDataStore.h.

◆ m_eCheckTruth

TruthMatchedParticleType TauAnalysisTools::CommonDiTauEfficiencyTool::m_eCheckTruth
protected

Definition at line 155 of file CommonDiTauEfficiencyTool.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default).

Definition at line 390 of file AthCommonDataStore.h.

◆ m_fXDiTau

std::function<double(const xAOD::DiTauJet& xDiTau)> TauAnalysisTools::CommonDiTauEfficiencyTool::m_fXDiTau

Definition at line 89 of file CommonDiTauEfficiencyTool.h.

◆ m_fYDiTau

std::function<double(const xAOD::DiTauJet& xDiTau)> TauAnalysisTools::CommonDiTauEfficiencyTool::m_fYDiTau

Definition at line 90 of file CommonDiTauEfficiencyTool.h.

◆ m_fZDiTau

std::function<double(const xAOD::DiTauJet& xDiTau)> TauAnalysisTools::CommonDiTauEfficiencyTool::m_fZDiTau

Definition at line 91 of file CommonDiTauEfficiencyTool.h.

◆ m_mSF

std::unique_ptr< tSFMAP > TauAnalysisTools::CommonDiTauEfficiencyTool::m_mSF
protected

Definition at line 109 of file CommonDiTauEfficiencyTool.h.

◆ m_mSystematicSets

std::unordered_map< CP::SystematicSet, std::string > TauAnalysisTools::CommonDiTauEfficiencyTool::m_mSystematicSets
protected

Definition at line 112 of file CommonDiTauEfficiencyTool.h.

◆ m_mSystematicsHistNames

std::map<std::string, std::string> TauAnalysisTools::CommonDiTauEfficiencyTool::m_mSystematicsHistNames
protected

Definition at line 114 of file CommonDiTauEfficiencyTool.h.

◆ m_sAffectingSystematics

CP::SystematicSet TauAnalysisTools::CommonDiTauEfficiencyTool::m_sAffectingSystematics
protected

Definition at line 144 of file CommonDiTauEfficiencyTool.h.

◆ m_sInputFileName

std::string TauAnalysisTools::CommonDiTauEfficiencyTool::m_sInputFileName
protected

Definition at line 152 of file CommonDiTauEfficiencyTool.h.

◆ m_sInputFilePath

Gaudi::Property<std::string> TauAnalysisTools::CommonDiTauEfficiencyTool::m_sInputFilePath {this, "InputFilePath", ""}
protected

Definition at line 148 of file CommonDiTauEfficiencyTool.h.

148{this, "InputFilePath", ""};

◆ m_sRecommendedSystematics

CP::SystematicSet TauAnalysisTools::CommonDiTauEfficiencyTool::m_sRecommendedSystematics
protected

Definition at line 145 of file CommonDiTauEfficiencyTool.h.

◆ m_sSFHistName

std::string TauAnalysisTools::CommonDiTauEfficiencyTool::m_sSFHistName
protected

Definition at line 153 of file CommonDiTauEfficiencyTool.h.

◆ m_sSystematicSet

const CP::SystematicSet* TauAnalysisTools::CommonDiTauEfficiencyTool::m_sSystematicSet
protected

Definition at line 113 of file CommonDiTauEfficiencyTool.h.

◆ m_sVarName

Gaudi::Property<std::string> TauAnalysisTools::CommonDiTauEfficiencyTool::m_sVarName {this, "VarName", ""}
protected

Definition at line 150 of file CommonDiTauEfficiencyTool.h.

150{this, "VarName", ""};

◆ m_sWP

Gaudi::Property<std::string> TauAnalysisTools::CommonDiTauEfficiencyTool::m_sWP {this, "WP", ""}
protected

Definition at line 149 of file CommonDiTauEfficiencyTool.h.

149{this, "WP", ""};

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: