75 :
asg::AsgTool( sName )
77 , m_sSystematicSet(nullptr)
81 , m_bNoMultiprong(false)
83 , m_bSFIsAvailable(false)
84 , m_bSFIsAvailableChecked(false)
102 for (
auto mEntry : *
m_mSF)
103 delete std::get<0>(mEntry.second);
121 m_mSF = std::make_unique< tSFMAP >();
122 std::unique_ptr< TFile > fSF( TFile::Open( sInputFilePath.c_str(),
"READ" ) );
125 ATH_MSG_FATAL(
"Could not open file " << sInputFilePath.c_str());
126 return StatusCode::FAILURE;
133 std::vector<std::string> vInputFilePath;
144 return StatusCode::FAILURE;
146 return StatusCode::SUCCESS;
156 double& dEfficiencyScaleFactor,
unsigned int ,
unsigned int iMu)
161 dEfficiencyScaleFactor = 1.;
168 dEfficiencyScaleFactor = 1.;
181 ATH_MSG_WARNING(
"Found tau with unknown decay mode. Skip efficiency correction.");
189 dEfficiencyScaleFactor = 1.;
196 std::string sMu =
"";
197 std::string sMCCampaign =
"";
205 dEfficiencyScaleFactor);
208 return tmpCorrectionCode;
215 double dTotalSystematic2 = 0.;
216 double dDirection = 0.;
223 double dUncertaintySyst = 0.;
226 dDirection = syst.parameter();
229 sHistName =
it->second;
230 if (dDirection>0.) sHistName+=
"_up";
231 else sHistName+=
"_down";
233 sHistName += sMode + sMu + sMCCampaign;
236 if( (sHistName.find(
"3P") != std::string::npos && sHistName.find(
"1p") != std::string::npos) ||
237 (sHistName.find(
"1P") != std::string::npos && sHistName.find(
"3p") != std::string::npos))
241 tmpCorrectionCode =
getValue(sHistName,
247 return tmpCorrectionCode;
250 dUncertaintySyst *= dDirection;
253 dTotalSystematic2 += dUncertaintySyst * dUncertaintySyst;
257 dDirection = (dDirection > 0.) ? 1. : -1.;
260 dEfficiencyScaleFactor *= 1. + dDirection * std::sqrt(dTotalSystematic2);
276 unsigned int iRunNumber,
unsigned int iMu)
287 ATH_MSG_DEBUG(
m_sVarName <<
" decoration is available on first tau processed, switched off applyEfficiencyScaleFactor for further taus.");
288 ATH_MSG_DEBUG(
"If an application of efficiency scale factors needs to be redone, please pass a shallow copy of the original tau.");
299 return tmpCorrectionCode;
309 return sys.find(systematic) !=
sys.end();
350 return StatusCode::SUCCESS;
354 double dDirection = 0.;
356 for (
auto sSyst : sSystematicSet)
362 ATH_MSG_VERBOSE(
"unsupported systematic variation: "<< sSyst.basename()<<
"; skipping this one");
367 if (sSyst.parameter() * dDirection < 0)
369 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should either use only \"UP\" or only \"DOWN\" systematics in one set!");
371 return StatusCode::FAILURE;
373 dDirection = sSyst.parameter();
377 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should not combine \"TAUS_{TRUE|FAKE}_EFF_*_TOTAL\" with other systematic variations!");
379 return StatusCode::FAILURE;
383 sSystematicSetAvailable.
insert(sSyst);
389 return StatusCode::SUCCESS;
395 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 ==
"P" || sTitle ==
"PFinalCalib")
469 if (sTitle ==
"TruthDecayMode")
474 if (sTitle ==
"truth 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 ==
"track-eta")
497 else if (sTitle ==
"|eta|")
502 else if (sTitle ==
"mu")
506 if (
evtStore()->retrieve(xEventInfo,
"EventInfo").isFailure()) {
521 else if (sTitle ==
"truth |eta|")
529 std::vector<std::string> vSplitName = {};
530 split(sKeyName,
'_',vSplitName);
531 if (vSplitName[0] ==
"sf")
538 if (sKeyName.find(
"_up_") != std::string::npos or sKeyName.find(
"_down_") != std::string::npos)
542 size_t iPos = sKeyName.find(
'_');
559 TClass *cClass = gROOT->GetClass(kKey->GetClassName());
560 if (cClass->InheritsFrom(
"TH2"))
562 TH1* oObject = (TH1*)kKey->ReadObj();
563 oObject->SetDirectory(0);
567 else if (cClass->InheritsFrom(
"TH3"))
569 TH1* oObject = (TH1*)kKey->ReadObj();
570 oObject->SetDirectory(0);
573 }
else if (cClass->InheritsFrom(
"TH1"))
575 TH1* oObject = (TH1*)kKey->ReadObj();
576 oObject->SetDirectory(0);
580 else if (cClass->InheritsFrom(
"TF1"))
582 TObject* oObject = kKey->ReadObj();
609 std::vector<std::string> vSplitInputFilePath = {};
611 std::string sEfficiencyType = vSplitInputFilePath.at(0);
612 std::string sTruthType = vSplitInputFilePath.at(1);
613 std::transform(sEfficiencyType.begin(), sEfficiencyType.end(), sEfficiencyType.begin(), toupper);
614 std::transform(sTruthType.begin(), sTruthType.end(), sTruthType.begin(), toupper);
615 std::string sSystematicBaseString =
"TAUS_"+sTruthType+
"_EFF_"+sEfficiencyType+
"_";
624 if (sEfficiencyType==
"ELERNN" || sEfficiencyType==
"ELEOLR")
m_bNoMultiprong =
true;
626 for (
auto mSF : *
m_mSF)
629 std::vector<std::string> vSplitNP = {};
630 split(mSF.first,
'_',vSplitNP);
631 std::string sNP = vSplitNP.at(0);
632 std::string sNPUppercase = vSplitNP.at(0);
635 if (sNP ==
"sf")
continue;
641 bool bIsRecommended =
false;
642 if (isupper(sNP.at(0)) || isupper(sNP.at(1)))
643 bIsRecommended =
true;
646 std::transform(sNPUppercase.begin(), sNPUppercase.end(), sNPUppercase.begin(), toupper);
647 std::string sSystematicString = sSystematicBaseString+sNPUppercase;
659 ATH_MSG_DEBUG(
"connected base name " << sNP <<
" with systematic " <<sSystematicString);
671 double& dEfficiencyScaleFactor)
const
674 auto it = mSF.find (sHistName);
677 ATH_MSG_ERROR(
"Object with name "<<sHistName<<
" was not found in input file.");
679 for (
auto eEntry : mSF)
688 double dPt =
m_fX(xTau);
691 double dVars[2] = {dPt,
dEta};
695 return (std::get<1>(tTuple))(std::get<0>(tTuple), dEfficiencyScaleFactor, dVars);
705 double& dEfficiencyScaleFactor,
double dVars[])
707 double dPt = dVars[0];
709 const TH1* hHist =
dynamic_cast<const TH1*
>(oObject);
718 dPt =
std::max(dPt,hHist->GetXaxis()->GetXmin());
720 dPt =
std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
723 int iBin = hHist->FindFixBin(dPt);
724 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
735 double& dEfficiencyScaleFactor,
double dVars[])
737 double dPt = dVars[0];
738 double dEta = dVars[1];
740 const TH2* hHist =
dynamic_cast<const TH2*
>(oObject);
749 dPt =
std::max(dPt,hHist->GetXaxis()->GetXmin());
752 dPt =
std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
756 int iBin = hHist->FindFixBin(dPt,
dEta);
757 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
767 double& dEfficiencyScaleFactor,
double dVars[])
769 double dX = dVars[0];
770 double dY = dVars[1];
771 double dZ = dVars[2];
773 const TH3* hHist =
dynamic_cast<const TH3*
>(oObject);
782 dX =
std::max(dX,hHist->GetXaxis()->GetXmin());
783 dY =
std::max(dY,hHist->GetYaxis()->GetXmin());
784 dZ =
std::max(dZ,hHist->GetZaxis()->GetXmin());
786 dX =
std::min(dX,hHist->GetXaxis()->GetXmax() * .999);
787 dY =
std::min(dY,hHist->GetYaxis()->GetXmax() * .999);
788 dZ =
std::min(dZ,hHist->GetZaxis()->GetXmax() * .999);
791 int iBin = hHist->FindFixBin(dX,dY,dZ);
792 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
802 double& dEfficiencyScaleFactor,
double dVars[])
804 double dPt = dVars[0];
805 double dEta = dVars[1];
807 const TF1* fFunc =
static_cast<const TF1*
>(oObject);
816 dEfficiencyScaleFactor = fFunc->Eval(dPt,
dEta);