75 :
asg::AsgTool( sName )
77 , m_sSystematicSet(nullptr)
81 , m_bNoMultiprong(false)
83 , m_bSFIsAvailable(false)
84 , m_bSFIsAvailableChecked(false)
105 for (
auto mEntry : *
m_mSF)
106 delete std::get<0>(mEntry.second);
124 m_mSF = std::make_unique< tSFMAP >();
125 std::unique_ptr< TFile > fSF( TFile::Open( sInputFilePath.c_str(),
"READ" ) );
128 ATH_MSG_FATAL(
"Could not open file " << sInputFilePath.c_str());
129 return StatusCode::FAILURE;
136 std::vector<std::string> vInputFilePath;
147 return StatusCode::FAILURE;
149 return StatusCode::SUCCESS;
159 double& dEfficiencyScaleFactor,
unsigned int iRunNumber,
unsigned int iMu)
164 dEfficiencyScaleFactor = 1.;
171 dEfficiencyScaleFactor = 1.;
184 ATH_MSG_WARNING(
"Found tau with unknown decay mode. Skip efficiency correction.");
192 dEfficiencyScaleFactor = 1.;
199 std::string sMu =
"";
200 std::string sMCCampaign =
"";
204 std::string sHistName =
m_sSFHistName + sMode + sMu + sMCCampaign;
209 dEfficiencyScaleFactor);
212 return tmpCorrectionCode;
219 double dTotalSystematic2 = 0.;
220 double dDirection = 0.;
227 double dUncertaintySyst = 0.;
230 dDirection = syst.parameter();
233 sHistName =
it->second;
234 if (dDirection>0.) sHistName+=
"_up";
235 else sHistName+=
"_down";
237 sHistName += sMode + sMu + sMCCampaign;
240 if( (sHistName.find(
"3P") != std::string::npos && sHistName.find(
"1p") != std::string::npos) ||
241 (sHistName.find(
"1P") != std::string::npos && sHistName.find(
"3p") != std::string::npos))
245 tmpCorrectionCode =
getValue(sHistName,
251 return tmpCorrectionCode;
254 dUncertaintySyst *= dDirection;
257 dTotalSystematic2 += dUncertaintySyst * dUncertaintySyst;
261 dDirection = (dDirection > 0.) ? 1. : -1.;
264 dEfficiencyScaleFactor *= 1. + dDirection * std::sqrt(dTotalSystematic2);
280 unsigned int iRunNumber,
unsigned int iMu)
291 ATH_MSG_DEBUG(
m_sVarName <<
" decoration is available on first tau processed, switched off applyEfficiencyScaleFactor for further taus.");
292 ATH_MSG_DEBUG(
"If an application of efficiency scale factors needs to be redone, please pass a shallow copy of the original tau.");
303 return tmpCorrectionCode;
313 return sys.find(systematic) !=
sys.end();
354 return StatusCode::SUCCESS;
358 double dDirection = 0.;
360 for (
auto sSyst : sSystematicSet)
366 ATH_MSG_VERBOSE(
"unsupported systematic variation: "<< sSyst.basename()<<
"; skipping this one");
371 if (sSyst.parameter() * dDirection < 0)
373 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should either use only \"UP\" or only \"DOWN\" systematics in one set!");
375 return StatusCode::FAILURE;
377 dDirection = sSyst.parameter();
381 ATH_MSG_ERROR(
"unsupported set of systematic variations, you should not combine \"TAUS_{TRUE|FAKE}_EFF_*_TOTAL\" with other systematic variations!");
383 return StatusCode::FAILURE;
387 sSystematicSetAvailable.
insert(sSyst);
393 return StatusCode::SUCCESS;
399 return fProngness == 1 ?
"_1p" :
"_3p";
431 if (iRunNumber > 324320 )
479 TIter itNext(fFile.GetListOfKeys());
480 while ((kKey = (TKey*)itNext()))
484 std::string sKeyName = kKey->GetName();
485 if (sKeyName ==
"Xaxis")
487 TNamed* tObj = (TNamed*)kKey->ReadObj();
488 std::string sTitle = tObj->GetTitle();
490 if (sTitle ==
"P" || sTitle ==
"PFinalCalib")
495 if (sTitle ==
"TruthDecayMode")
500 if (sTitle ==
"truth pt")
505 if (sTitle ==
"|eta|")
513 else if (sKeyName ==
"Yaxis")
515 TNamed* tObj = (TNamed*)kKey->ReadObj();
516 std::string sTitle = tObj->GetTitle();
518 if (sTitle ==
"track-eta")
523 else if (sTitle ==
"|eta|")
528 else if (sTitle ==
"mu")
532 if (
evtStore()->retrieve(xEventInfo,
"EventInfo").isFailure()) {
547 else if (sTitle ==
"truth |eta|")
555 std::vector<std::string> vSplitName = {};
556 split(sKeyName,
'_',vSplitName);
557 if (vSplitName[0] ==
"sf")
564 if (sKeyName.find(
"_up_") != std::string::npos or sKeyName.find(
"_down_") != std::string::npos)
568 size_t iPos = sKeyName.find(
'_');
585 TClass *cClass = gROOT->GetClass(kKey->GetClassName());
586 if (cClass->InheritsFrom(
"TH2"))
588 TH1* oObject = (TH1*)kKey->ReadObj();
589 oObject->SetDirectory(0);
593 else if (cClass->InheritsFrom(
"TH3"))
595 TH1* oObject = (TH1*)kKey->ReadObj();
596 oObject->SetDirectory(0);
599 }
else if (cClass->InheritsFrom(
"TH1"))
601 TH1* oObject = (TH1*)kKey->ReadObj();
602 oObject->SetDirectory(0);
606 else if (cClass->InheritsFrom(
"TF1"))
608 TObject* oObject = kKey->ReadObj();
635 std::vector<std::string> vSplitInputFilePath = {};
637 std::string sEfficiencyType = vSplitInputFilePath.at(0);
638 std::string sTruthType = vSplitInputFilePath.at(1);
639 std::transform(sEfficiencyType.begin(), sEfficiencyType.end(), sEfficiencyType.begin(), toupper);
640 std::transform(sTruthType.begin(), sTruthType.end(), sTruthType.begin(), toupper);
641 std::string sSystematicBaseString =
"TAUS_"+sTruthType+
"_EFF_"+sEfficiencyType+
"_";
650 if (sEfficiencyType==
"ELERNN" || sEfficiencyType==
"ELEOLR")
m_bNoMultiprong =
true;
652 for (
auto mSF : *
m_mSF)
655 std::vector<std::string> vSplitNP = {};
656 split(mSF.first,
'_',vSplitNP);
657 std::string sNP = vSplitNP.at(0);
658 std::string sNPUppercase = vSplitNP.at(0);
661 if (sNP ==
"sf")
continue;
667 bool bIsRecommended =
false;
668 if (isupper(sNP.at(0)) || isupper(sNP.at(1)))
669 bIsRecommended =
true;
672 std::transform(sNPUppercase.begin(), sNPUppercase.end(), sNPUppercase.begin(), toupper);
673 std::string sSystematicString = sSystematicBaseString+sNPUppercase;
685 ATH_MSG_DEBUG(
"connected base name " << sNP <<
" with systematic " <<sSystematicString);
697 double& dEfficiencyScaleFactor)
const
700 auto it = mSF.find (sHistName);
703 ATH_MSG_ERROR(
"Object with name "<<sHistName<<
" was not found in input file.");
705 for (
auto eEntry : mSF)
714 double dPt =
m_fX(xTau);
717 double dVars[2] = {dPt,
dEta};
721 return (std::get<1>(tTuple))(std::get<0>(tTuple), dEfficiencyScaleFactor, dVars);
731 double& dEfficiencyScaleFactor,
double dVars[])
733 double dPt = dVars[0];
735 const TH1* hHist =
dynamic_cast<const TH1*
>(oObject);
744 dPt =
std::max(dPt,hHist->GetXaxis()->GetXmin());
746 dPt =
std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
749 int iBin = hHist->FindFixBin(dPt);
750 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
761 double& dEfficiencyScaleFactor,
double dVars[])
763 double dPt = dVars[0];
764 double dEta = dVars[1];
766 const TH2* hHist =
dynamic_cast<const TH2*
>(oObject);
775 dPt =
std::max(dPt,hHist->GetXaxis()->GetXmin());
778 dPt =
std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
782 int iBin = hHist->FindFixBin(dPt,
dEta);
783 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
793 double& dEfficiencyScaleFactor,
double dVars[])
795 double dX = dVars[0];
796 double dY = dVars[1];
797 double dZ = dVars[2];
799 const TH3* hHist =
dynamic_cast<const TH3*
>(oObject);
808 dX =
std::max(dX,hHist->GetXaxis()->GetXmin());
809 dY =
std::max(dY,hHist->GetYaxis()->GetXmin());
810 dZ =
std::max(dZ,hHist->GetZaxis()->GetXmin());
812 dX =
std::min(dX,hHist->GetXaxis()->GetXmax() * .999);
813 dY =
std::min(dY,hHist->GetYaxis()->GetXmax() * .999);
814 dZ =
std::min(dZ,hHist->GetZaxis()->GetXmax() * .999);
817 int iBin = hHist->FindFixBin(dX,dY,dZ);
818 dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
828 double& dEfficiencyScaleFactor,
double dVars[])
830 double dPt = dVars[0];
831 double dEta = dVars[1];
833 const TF1* fFunc =
static_cast<const TF1*
>(oObject);
842 dEfficiencyScaleFactor = fFunc->Eval(dPt,
dEta);