92 for (
auto mEntry : *
m_mSF)
93 delete std::get<0>(mEntry.second);
111 m_mSF = std::make_unique< tSFMAP >();
112 std::unique_ptr< TFile > fSF( TFile::Open( sInputFilePath.c_str(),
"READ" ) );
115 ATH_MSG_FATAL(
"Could not open file " << sInputFilePath.c_str());
116 return StatusCode::FAILURE;
123 std::vector<std::string> vInputFilePath;
134 return StatusCode::FAILURE;
138 return StatusCode::SUCCESS;
148 double& dEfficiencyScaleFactor,
unsigned int iRunNumber)
161 ATH_MSG_DEBUG(
"retrieving the SFs while running on data ...");
164 dEfficiencyScaleFactor = 1.;
169 int ntracks = tau.getXAODObject().nTracks();
174 dEfficiencyScaleFactor = 1.;
182 int iDecayMode = acc.m_decayMode(tau);
186 ATH_MSG_WARNING(
"Found tau with unknown decay mode. Skip efficiency correction.");
193 if( ntracks != 1 && ntracks != 3) {
194 dEfficiencyScaleFactor = 1.;
201 std::string sHistName;
203 sHistName =
"sf_all_"+
m_sWP+sMode;
211 dEfficiencyScaleFactor);
214 return tmpCorrectionCode;
221 double dTotalSystematic2 = 0.;
222 double dDirection = 0.;
231 double dUncertaintySyst = 0.;
234 dDirection = syst.parameter();
237 sHistName = it->second;
238 if (dDirection>0.) sHistName+=
"_up";
239 else sHistName+=
"_down";
248 if( (sHistName.find(
"3P") != std::string::npos && sHistName.find(
"1p") != std::string::npos) ||
249 (sHistName.find(
"1P") != std::string::npos && sHistName.find(
"3p") != std::string::npos))
252 if( (sHistName.find(
"1520") != std::string::npos && sHistName.find(
"loose") != std::string::npos) ){
257 tmpCorrectionCode =
getValue(sHistName,
263 return tmpCorrectionCode;
266 dUncertaintySyst *= dDirection;
269 dTotalSystematic2 += dUncertaintySyst * dUncertaintySyst;
273 dDirection = (dDirection > 0.) ? 1. : -1.;
276 dEfficiencyScaleFactor *= 1. + dDirection * std::sqrt(dTotalSystematic2);
292 unsigned int iRunNumber)
303 ATH_MSG_DEBUG(
m_sVarName <<
" decoration is available on first tau processed, switched off applyEfficiencyScaleFactor for further taus.");
304 ATH_MSG_DEBUG(
"If an application of efficiency scale factors needs to be redone, please pass a shallow copy of the original tau.");
315 return tmpCorrectionCode;
327 return sys.find(systematic) != sys.end();
368 return StatusCode::SUCCESS;
372 double dDirection = 0.;
374 for (
const auto & sSyst : sSystematicSet)
380 ATH_MSG_VERBOSE(
"unsupported systematic variation: "<< sSyst.basename()<<
"; skipping this one");
385 if (sSyst.parameter() * dDirection < 0)
387 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should either use only \"UP\" or only \"DOWN\" systematics in one set!");
389 return StatusCode::FAILURE;
391 dDirection = sSyst.parameter();
395 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should not combine \"TAUS_{TRUE|FAKE}_EFF_*_TOTAL\" with other systematic variations!");
397 return StatusCode::FAILURE;
401 sSystematicSetAvailable.
insert(sSyst);
407 return StatusCode::SUCCESS;
413 return fProngness == 1 ?
"_1p" :
"_3p";
458 TIter itNext(fFile.GetListOfKeys());
459 while ((kKey = (TKey*)itNext()))
463 std::string sKeyName = kKey->GetName();
464 if (sKeyName ==
"Xaxis")
466 TNamed* tObj = (TNamed*)kKey->ReadObj();
467 std::string sTitle = tObj->GetTitle();
469 if (sTitle ==
"TruthDecayMode")
474 if (sTitle ==
"truth visible pt")
479 if (sTitle ==
"|eta|")
487 else if (sKeyName ==
"Yaxis")
489 TNamed* tObj = (TNamed*)kKey->ReadObj();
490 std::string sTitle = tObj->GetTitle();
492 if (sTitle ==
"|eta|")
497 else if (sTitle ==
"truth |eta|")
505 std::vector<std::string> vSplitName = {};
506 split(sKeyName,
'_',vSplitName);
507 if (vSplitName[0] ==
"sf")
514 if (sKeyName.find(
"_up_") != std::string::npos or sKeyName.find(
"_down_") != std::string::npos)
518 size_t iPos = sKeyName.find(
'_');
535 TClass *cClass = gROOT->GetClass(kKey->GetClassName());
536 if (cClass->InheritsFrom(
"TH2"))
538 TH1* oObject = (TH1*)kKey->ReadObj();
539 oObject->SetDirectory(0);
543 else if (cClass->InheritsFrom(
"TH1"))
545 TH1* oObject = (TH1*)kKey->ReadObj();
546 oObject->SetDirectory(0);
550 else if (cClass->InheritsFrom(
"TF1"))
552 TObject* oObject = kKey->ReadObj();
579 std::vector<std::string> vSplitInputFilePath = {};
581 std::string sEfficiencyType = vSplitInputFilePath.at(0);
582 std::string sTruthType = vSplitInputFilePath.at(1);
583 std::transform(sEfficiencyType.begin(), sEfficiencyType.end(), sEfficiencyType.begin(), toupper);
584 std::transform(sTruthType.begin(), sTruthType.end(), sTruthType.begin(), toupper);
585 std::string sSystematicBaseString =
"TAUS_"+sTruthType+
"_EFF_"+sEfficiencyType+
"_";
591 if (sEfficiencyType==
"ELERNN" || sEfficiencyType==
"ELEOLR")
m_bNoMultiprong =
true;
593 for (
const auto & mSF : *
m_mSF)
596 std::vector<std::string> vSplitNP = {};
597 split(mSF.first,
'_',vSplitNP);
598 std::string sNP = vSplitNP.at(0);
599 std::string sNPUppercase = vSplitNP.at(0);
602 if (sNP ==
"sf")
continue;
608 bool bIsRecommended =
false;
609 if (isupper(sNP.at(0)) || isupper(sNP.at(1)))
610 bIsRecommended =
true;
613 std::transform(sNPUppercase.begin(), sNPUppercase.end(), sNPUppercase.begin(), toupper);
614 std::string sSystematicString = sSystematicBaseString+sNPUppercase;
626 ATH_MSG_DEBUG(
"connected base name " << sNP <<
" with systematic " <<sSystematicString);
638 double& dEfficiencyScaleFactor)
const
643 auto it = mSF.find (sHistName);
646 ATH_MSG_ERROR(
"Object with name "<<sHistName<<
" was not found in input file.");
648 for (
const auto & eEntry : mSF)
658 double dPt =
m_fX(tau.getXAODObject());
659 double dEta =
m_fY(tau.getXAODObject());
661 double dVars[2] = {dPt, dEta};
665 return (std::get<1>(tTuple))(std::get<0>(tTuple), dEfficiencyScaleFactor, dVars);
675 double& dEfficiencyScaleFactor,
double dVars[])
677 double dPt = dVars[0];
679 const TH1* hHist =
dynamic_cast<const TH1*
>(oObject);
688 dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
690 dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
693 int iBin = hHist->FindFixBin(dPt);
694 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
705 double& dEfficiencyScaleFactor,
double dVars[])
707 double dPt = dVars[0];
708 double dEta = dVars[1];
710 const TH2* hHist =
dynamic_cast<const TH2*
>(oObject);
719 dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
720 dEta = std::max(dEta,hHist->GetYaxis()->GetXmin());
722 dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
723 dEta = std::min(dEta,hHist->GetYaxis()->GetXmax() * .999);
726 int iBin = hHist->FindFixBin(dPt,dEta);
727 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
737 double& dEfficiencyScaleFactor,
double dVars[])
739 double dPt = dVars[0];
740 double dEta = dVars[1];
742 const TF1* fFunc =
static_cast<const TF1*
>(oObject);
751 dEfficiencyScaleFactor = fFunc->Eval(dPt, dEta);
759 unsigned int runNumber = 0;
760 if (!acc.randomrunnumber.isAvailable(event)) {
762 "Pileup tool not run before using ElectronEfficiencyTool! SFs do not "
763 "reflect PU distribution in data");
766 runNumber = acc.randomrunnumber(event);
774 acc.m_sfDec(tau) = sf;
775 acc.m_validDec(tau) =
true;
778 acc.m_sfDec(tau) = sf;
779 acc.m_validDec(tau) =
false;
782 throw std::runtime_error(
"Error in getEfficiencyScaleFactor");
792 auto eventInfo = acc.m_eventInfo(event);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
Class to wrap a set of SystematicVariations.
std::string name() const
returns: the systematics joined into a single string.
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
size_t size() const
returns: size of the set
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
ObjectRange< TauJetDef > TauJetRange
ObjectRange< EventContextDef > EventContextRange
ObjectId< EventContextDef > EventContextId
ObjectId< TauJetDef > TauJetId
ObjectId< EventInfoDef > EventInfoId
TauJet_v3 TauJet
Definition of the current "tau version".