89 for (
auto mEntry : *
m_mSF)
90 delete std::get<0>(mEntry.second);
108 m_mSF = std::make_unique< tSFMAP >();
109 std::unique_ptr< TFile > fSF( TFile::Open( sInputFilePath.c_str(),
"READ" ) );
112 ATH_MSG_FATAL(
"Could not open file " << sInputFilePath.c_str());
113 return StatusCode::FAILURE;
120 std::vector<std::string> vInputFilePath;
131 return StatusCode::FAILURE;
135 return StatusCode::SUCCESS;
145 double& dEfficiencyScaleFactor,
unsigned int iRunNumber)
158 ATH_MSG_DEBUG(
"retrieving the SFs while running on data ...");
161 dEfficiencyScaleFactor = 1.;
166 int ntracks = tau.getXAODObject().nTracks();
171 dEfficiencyScaleFactor = 1.;
179 int iDecayMode = acc.m_decayMode(tau);
183 ATH_MSG_WARNING(
"Found tau with unknown decay mode. Skip efficiency correction.");
190 if( ntracks != 1 && ntracks != 3) {
191 dEfficiencyScaleFactor = 1.;
198 std::string sHistName;
200 sHistName =
"sf_all_"+
m_sWP+sMode;
208 dEfficiencyScaleFactor);
211 return tmpCorrectionCode;
218 double dTotalSystematic2 = 0.;
219 double dDirection = 0.;
226 double dUncertaintySyst = 0.;
229 dDirection = syst.parameter();
232 sHistName = it->second;
233 if (dDirection>0.) sHistName+=
"_up";
234 else sHistName+=
"_down";
243 if( (sHistName.find(
"3P") != std::string::npos && sHistName.find(
"1p") != std::string::npos) ||
244 (sHistName.find(
"1P") != std::string::npos && sHistName.find(
"3p") != std::string::npos))
247 if( (sHistName.find(
"1520") != std::string::npos && sHistName.find(
"loose") != std::string::npos) ){
252 tmpCorrectionCode =
getValue(sHistName,
258 return tmpCorrectionCode;
261 dUncertaintySyst *= dDirection;
264 dTotalSystematic2 += dUncertaintySyst * dUncertaintySyst;
268 dDirection = (dDirection > 0.) ? 1. : -1.;
271 dEfficiencyScaleFactor *= 1. + dDirection * std::sqrt(dTotalSystematic2);
287 unsigned int iRunNumber)
298 ATH_MSG_DEBUG(
m_sVarName <<
" decoration is available on first tau processed, switched off applyEfficiencyScaleFactor for further taus.");
299 ATH_MSG_DEBUG(
"If an application of efficiency scale factors needs to be redone, please pass a shallow copy of the original tau.");
310 return tmpCorrectionCode;
322 return sys.find(systematic) != sys.end();
363 return StatusCode::SUCCESS;
367 double dDirection = 0.;
369 for (
auto sSyst : sSystematicSet)
375 ATH_MSG_VERBOSE(
"unsupported systematic variation: "<< sSyst.basename()<<
"; skipping this one");
380 if (sSyst.parameter() * dDirection < 0)
382 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should either use only \"UP\" or only \"DOWN\" systematics in one set!");
384 return StatusCode::FAILURE;
386 dDirection = sSyst.parameter();
390 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should not combine \"TAUS_{TRUE|FAKE}_EFF_*_TOTAL\" with other systematic variations!");
392 return StatusCode::FAILURE;
396 sSystematicSetAvailable.
insert(sSyst);
402 return StatusCode::SUCCESS;
408 return fProngness == 1 ?
"_1p" :
"_3p";
453 TIter itNext(fFile.GetListOfKeys());
454 while ((kKey = (TKey*)itNext()))
458 std::string sKeyName = kKey->GetName();
459 if (sKeyName ==
"Xaxis")
461 TNamed* tObj = (TNamed*)kKey->ReadObj();
462 std::string sTitle = tObj->GetTitle();
464 if (sTitle ==
"TruthDecayMode")
469 if (sTitle ==
"truth visible pt")
474 if (sTitle ==
"|eta|")
482 else if (sKeyName ==
"Yaxis")
484 TNamed* tObj = (TNamed*)kKey->ReadObj();
485 std::string sTitle = tObj->GetTitle();
487 if (sTitle ==
"|eta|")
492 else if (sTitle ==
"truth |eta|")
500 std::vector<std::string> vSplitName = {};
501 split(sKeyName,
'_',vSplitName);
502 if (vSplitName[0] ==
"sf")
509 if (sKeyName.find(
"_up_") != std::string::npos or sKeyName.find(
"_down_") != std::string::npos)
513 size_t iPos = sKeyName.find(
'_');
530 TClass *cClass = gROOT->GetClass(kKey->GetClassName());
531 if (cClass->InheritsFrom(
"TH2"))
533 TH1* oObject = (TH1*)kKey->ReadObj();
534 oObject->SetDirectory(0);
538 else if (cClass->InheritsFrom(
"TH1"))
540 TH1* oObject = (TH1*)kKey->ReadObj();
541 oObject->SetDirectory(0);
545 else if (cClass->InheritsFrom(
"TF1"))
547 TObject* oObject = kKey->ReadObj();
574 std::vector<std::string> vSplitInputFilePath = {};
576 std::string sEfficiencyType = vSplitInputFilePath.at(0);
577 std::string sTruthType = vSplitInputFilePath.at(1);
578 std::transform(sEfficiencyType.begin(), sEfficiencyType.end(), sEfficiencyType.begin(), toupper);
579 std::transform(sTruthType.begin(), sTruthType.end(), sTruthType.begin(), toupper);
580 std::string sSystematicBaseString =
"TAUS_"+sTruthType+
"_EFF_"+sEfficiencyType+
"_";
586 if (sEfficiencyType==
"ELERNN" || sEfficiencyType==
"ELEOLR")
m_bNoMultiprong =
true;
588 for (
auto mSF : *
m_mSF)
591 std::vector<std::string> vSplitNP = {};
592 split(mSF.first,
'_',vSplitNP);
593 std::string sNP = vSplitNP.at(0);
594 std::string sNPUppercase = vSplitNP.at(0);
597 if (sNP ==
"sf")
continue;
603 bool bIsRecommended =
false;
604 if (isupper(sNP.at(0)) || isupper(sNP.at(1)))
605 bIsRecommended =
true;
608 std::transform(sNPUppercase.begin(), sNPUppercase.end(), sNPUppercase.begin(), toupper);
609 std::string sSystematicString = sSystematicBaseString+sNPUppercase;
621 ATH_MSG_DEBUG(
"connected base name " << sNP <<
" with systematic " <<sSystematicString);
633 double& dEfficiencyScaleFactor)
const
638 auto it = mSF.find (sHistName);
641 ATH_MSG_ERROR(
"Object with name "<<sHistName<<
" was not found in input file.");
643 for (
auto eEntry : mSF)
653 double dPt =
m_fX(tau.getXAODObject());
654 double dEta =
m_fY(tau.getXAODObject());
656 double dVars[2] = {dPt, dEta};
660 return (std::get<1>(tTuple))(std::get<0>(tTuple), dEfficiencyScaleFactor, dVars);
670 double& dEfficiencyScaleFactor,
double dVars[])
672 double dPt = dVars[0];
674 const TH1* hHist =
dynamic_cast<const TH1*
>(oObject);
683 dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
685 dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
688 int iBin = hHist->FindFixBin(dPt);
689 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
700 double& dEfficiencyScaleFactor,
double dVars[])
702 double dPt = dVars[0];
703 double dEta = dVars[1];
705 const TH2* hHist =
dynamic_cast<const TH2*
>(oObject);
714 dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
715 dEta = std::max(dEta,hHist->GetYaxis()->GetXmin());
717 dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
718 dEta = std::min(dEta,hHist->GetYaxis()->GetXmax() * .999);
721 int iBin = hHist->FindFixBin(dPt,dEta);
722 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
732 double& dEfficiencyScaleFactor,
double dVars[])
734 double dPt = dVars[0];
735 double dEta = dVars[1];
737 const TF1* fFunc =
static_cast<const TF1*
>(oObject);
746 dEfficiencyScaleFactor = fFunc->Eval(dPt, dEta);
754 unsigned int runNumber = 0;
755 if (!acc.randomrunnumber.isAvailable(event)) {
757 "Pileup tool not run before using ElectronEfficiencyTool! SFs do not "
758 "reflect PU distribution in data");
761 runNumber = acc.randomrunnumber(event);
769 acc.m_sfDec(tau) = sf;
770 acc.m_validDec(tau) =
true;
773 acc.m_sfDec(tau) = sf;
774 acc.m_validDec(tau) =
false;
777 throw std::runtime_error(
"Error in getEfficiencyScaleFactor");
787 auto eventInfo = acc.m_eventInfo(event);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(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".