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)
159 dEfficiencyScaleFactor = 1.;
164 int ntracks = tau.getXAODObject().nTracks();
169 dEfficiencyScaleFactor = 1.;
177 int iDecayMode = acc.m_decayMode(tau);
181 ATH_MSG_WARNING(
"Found tau with unknown decay mode. Skip efficiency correction.");
188 if( ntracks != 1 && ntracks != 3) {
189 dEfficiencyScaleFactor = 1.;
196 std::string sHistName;
198 sHistName =
"sf_all_"+
m_sWP+sMode;
206 dEfficiencyScaleFactor);
209 return tmpCorrectionCode;
216 double dTotalSystematic2 = 0.;
217 double dDirection = 0.;
224 double dUncertaintySyst = 0.;
227 dDirection = syst.parameter();
230 sHistName = it->second;
231 if (dDirection>0.) sHistName+=
"_up";
232 else sHistName+=
"_down";
241 if( (sHistName.find(
"3P") != std::string::npos && sHistName.find(
"1p") != std::string::npos) ||
242 (sHistName.find(
"1P") != std::string::npos && sHistName.find(
"3p") != std::string::npos))
245 if( (sHistName.find(
"1520") != std::string::npos && sHistName.find(
"loose") != std::string::npos) ){
250 tmpCorrectionCode =
getValue(sHistName,
256 return tmpCorrectionCode;
259 dUncertaintySyst *= dDirection;
262 dTotalSystematic2 += dUncertaintySyst * dUncertaintySyst;
266 dDirection = (dDirection > 0.) ? 1. : -1.;
269 dEfficiencyScaleFactor *= 1. + dDirection * std::sqrt(dTotalSystematic2);
285 unsigned int iRunNumber)
296 ATH_MSG_DEBUG(
m_sVarName <<
" decoration is available on first tau processed, switched off applyEfficiencyScaleFactor for further taus.");
297 ATH_MSG_DEBUG(
"If an application of efficiency scale factors needs to be redone, please pass a shallow copy of the original tau.");
308 return tmpCorrectionCode;
320 return sys.find(systematic) != sys.end();
361 return StatusCode::SUCCESS;
365 double dDirection = 0.;
367 for (
auto sSyst : sSystematicSet)
373 ATH_MSG_VERBOSE(
"unsupported systematic variation: "<< sSyst.basename()<<
"; skipping this one");
378 if (sSyst.parameter() * dDirection < 0)
380 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should either use only \"UP\" or only \"DOWN\" systematics in one set!");
382 return StatusCode::FAILURE;
384 dDirection = sSyst.parameter();
388 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should not combine \"TAUS_{TRUE|FAKE}_EFF_*_TOTAL\" with other systematic variations!");
390 return StatusCode::FAILURE;
394 sSystematicSetAvailable.
insert(sSyst);
400 return StatusCode::SUCCESS;
406 return fProngness == 1 ?
"_1p" :
"_3p";
451 TIter itNext(fFile.GetListOfKeys());
452 while ((kKey = (TKey*)itNext()))
456 std::string sKeyName = kKey->GetName();
457 if (sKeyName ==
"Xaxis")
459 TNamed* tObj = (TNamed*)kKey->ReadObj();
460 std::string sTitle = tObj->GetTitle();
462 if (sTitle ==
"TruthDecayMode")
467 if (sTitle ==
"truth visible pt")
472 if (sTitle ==
"|eta|")
480 else if (sKeyName ==
"Yaxis")
482 TNamed* tObj = (TNamed*)kKey->ReadObj();
483 std::string sTitle = tObj->GetTitle();
485 if (sTitle ==
"|eta|")
490 else if (sTitle ==
"truth |eta|")
498 std::vector<std::string> vSplitName = {};
499 split(sKeyName,
'_',vSplitName);
500 if (vSplitName[0] ==
"sf")
507 if (sKeyName.find(
"_up_") != std::string::npos or sKeyName.find(
"_down_") != std::string::npos)
511 size_t iPos = sKeyName.find(
'_');
528 TClass *cClass = gROOT->GetClass(kKey->GetClassName());
529 if (cClass->InheritsFrom(
"TH2"))
531 TH1* oObject = (TH1*)kKey->ReadObj();
532 oObject->SetDirectory(0);
536 else if (cClass->InheritsFrom(
"TH1"))
538 TH1* oObject = (TH1*)kKey->ReadObj();
539 oObject->SetDirectory(0);
543 else if (cClass->InheritsFrom(
"TF1"))
545 TObject* oObject = kKey->ReadObj();
572 std::vector<std::string> vSplitInputFilePath = {};
574 std::string sEfficiencyType = vSplitInputFilePath.at(0);
575 std::string sTruthType = vSplitInputFilePath.at(1);
576 std::transform(sEfficiencyType.begin(), sEfficiencyType.end(), sEfficiencyType.begin(), toupper);
577 std::transform(sTruthType.begin(), sTruthType.end(), sTruthType.begin(), toupper);
578 std::string sSystematicBaseString =
"TAUS_"+sTruthType+
"_EFF_"+sEfficiencyType+
"_";
584 if (sEfficiencyType==
"ELERNN" || sEfficiencyType==
"ELEOLR")
m_bNoMultiprong =
true;
586 for (
auto mSF : *
m_mSF)
589 std::vector<std::string> vSplitNP = {};
590 split(mSF.first,
'_',vSplitNP);
591 std::string sNP = vSplitNP.at(0);
592 std::string sNPUppercase = vSplitNP.at(0);
595 if (sNP ==
"sf")
continue;
601 bool bIsRecommended =
false;
602 if (isupper(sNP.at(0)) || isupper(sNP.at(1)))
603 bIsRecommended =
true;
606 std::transform(sNPUppercase.begin(), sNPUppercase.end(), sNPUppercase.begin(), toupper);
607 std::string sSystematicString = sSystematicBaseString+sNPUppercase;
619 ATH_MSG_DEBUG(
"connected base name " << sNP <<
" with systematic " <<sSystematicString);
631 double& dEfficiencyScaleFactor)
const
636 auto it = mSF.find (sHistName);
639 ATH_MSG_ERROR(
"Object with name "<<sHistName<<
" was not found in input file.");
641 for (
auto eEntry : mSF)
651 double dPt =
m_fX(tau.getXAODObject());
652 double dEta =
m_fY(tau.getXAODObject());
654 double dVars[2] = {dPt, dEta};
658 return (std::get<1>(tTuple))(std::get<0>(tTuple), dEfficiencyScaleFactor, dVars);
668 double& dEfficiencyScaleFactor,
double dVars[])
670 double dPt = dVars[0];
672 const TH1* hHist =
dynamic_cast<const TH1*
>(oObject);
681 dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
683 dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
686 int iBin = hHist->FindFixBin(dPt);
687 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
698 double& dEfficiencyScaleFactor,
double dVars[])
700 double dPt = dVars[0];
701 double dEta = dVars[1];
703 const TH2* hHist =
dynamic_cast<const TH2*
>(oObject);
712 dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
713 dEta = std::max(dEta,hHist->GetYaxis()->GetXmin());
715 dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
716 dEta = std::min(dEta,hHist->GetYaxis()->GetXmax() * .999);
719 int iBin = hHist->FindFixBin(dPt,dEta);
720 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
730 double& dEfficiencyScaleFactor,
double dVars[])
732 double dPt = dVars[0];
733 double dEta = dVars[1];
735 const TF1* fFunc =
static_cast<const TF1*
>(oObject);
744 dEfficiencyScaleFactor = fFunc->Eval(dPt, dEta);
752 unsigned int runNumber = 0;
753 if (!acc.randomrunnumber.isAvailable(event)) {
755 "Pileup tool not run before using ElectronEfficiencyTool! SFs do not "
756 "reflect PU distribution in data");
759 runNumber = acc.randomrunnumber(event);
767 acc.m_sfDec(tau) = sf;
768 acc.m_validDec(tau) =
true;
771 acc.m_sfDec(tau) = sf;
772 acc.m_validDec(tau) =
false;
775 throw std::runtime_error(
"Error in getEfficiencyScaleFactor");
785 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".