14 #include "THashList.h"
23 DiTauSelectionTool::DiTauSelectionTool(
const std::string&
name )
25 , m_sOmniIDWP(
"OMNIIDNONE")
27 , m_aAccept(
"DiTauSelection" )
31 DiTauSelectionTool::~DiTauSelectionTool()
47 bool bConfigViaProperties =
false;
48 if (!bConfigViaProperties and !
m_vPtRegion.empty()) bConfigViaProperties =
true;
49 if (!bConfigViaProperties and !std::isnan(
m_dPtMin.value())) bConfigViaProperties =
true;
50 if (!bConfigViaProperties and !std::isnan(
m_dPtMax.value())) bConfigViaProperties =
true;
51 if (!bConfigViaProperties and !
m_vAbsEtaRegion.empty()) bConfigViaProperties =
true;
52 if (!bConfigViaProperties and !std::isnan(
m_dAbsEtaMin.value())) bConfigViaProperties =
true;
53 if (!bConfigViaProperties and !std::isnan(
m_dAbsEtaMax.value())) bConfigViaProperties =
true;
54 if (!bConfigViaProperties and !
m_vNSubjetsRegion.empty()) bConfigViaProperties =
true;
55 if (!bConfigViaProperties and !std::isnan(
m_dNSubjetsMin.value())) bConfigViaProperties =
true;
56 if (!bConfigViaProperties and !std::isnan(
m_dNSubjetsMax.value())) bConfigViaProperties =
true;
57 if (!bConfigViaProperties and !
m_vAbsCharges.empty()) bConfigViaProperties =
true;
58 if (!bConfigViaProperties and !std::isnan(
m_iAbsCharge.value())) bConfigViaProperties =
true;
59 if (!bConfigViaProperties and !
m_vOmniScoreRegion.empty()) bConfigViaProperties =
true;
60 if (!bConfigViaProperties and !std::isnan(
m_dOmniScoreMin.value())) bConfigViaProperties =
true;
61 if (!bConfigViaProperties and !std::isnan(
m_dOmniScoreMax.value())) bConfigViaProperties =
true;
62 if (!bConfigViaProperties and
m_iOmniIDWP != 0) bConfigViaProperties =
true;
64 if (bConfigViaConfigFile and bConfigViaProperties)
66 ATH_MSG_WARNING(
"Configured tool via setProperty and configuration file, which may lead to unexpected configuration.");
67 ATH_MSG_WARNING(
"In doubt check the configuration that is printed when the tool is initialized and the message level is set to debug");
68 ATH_MSG_WARNING(
"For further details please refer to the documentation:");
69 ATH_MSG_WARNING(
"https://gitlab.cern.ch/atlas/athena/blob/main/PhysicsAnalysis/TauID/TauAnalysisTools/doc/README-DiTauSelectionTool.rst");
71 if (!bConfigViaConfigFile and !bConfigViaProperties)
73 ATH_MSG_WARNING(
"No cut configuration provided, the tool will not do anything. For further details please refer to the documentation:");
74 ATH_MSG_WARNING(
"https://gitlab.cern.ch/atlas/athena/blob/main/PhysicsAnalysis/TauID/TauAnalysisTools/doc/README-DiTauSelectionTool.rst");
77 if (bConfigViaConfigFile)
83 ATH_MSG_WARNING(
"Config file for DiTauSelectionTool with path "<<sInputFilePath<<
" does not contain an empty last line. The tool might not be properly configured!");
85 rEnv.ReadFile(sInputFilePath.c_str(),
88 std::vector<std::string> vCuts;
91 if (rEnv.Defined(
"SelectionCuts"))
95 auto lList = rEnv.GetTable();
96 for( Int_t
i = 0;
i < lList->GetEntries(); ++
i )
98 vCuts.push_back( lList->At(
i )->GetName() );
102 int iSelectionCuts = 0;
104 for (
const std::string& sCut : vCuts)
106 if (sCut ==
"PtRegion")
112 else if (sCut ==
"PtMin")
116 m_dPtMin = rEnv.GetValue(
"PtMin",NAN);
118 else if (sCut ==
"PtMax")
122 m_dPtMax = rEnv.GetValue(
"PtMax",NAN);
124 else if (sCut ==
"AbsEtaRegion")
130 else if (sCut ==
"AbsEtaMin")
136 else if (sCut ==
"AbsEtaMax")
142 else if (sCut ==
"NSubjetsRegion")
148 else if (sCut ==
"NSubjetsMin")
154 else if (sCut ==
"NSubjetsMax")
160 else if (sCut ==
"AbsCharges")
166 else if (sCut ==
"AbsCharge")
172 else if (sCut ==
"OmniScoreRegion")
181 else if (sCut ==
"OmniScoreMin")
188 for (
const std::string& checkCut : vCuts){
189 if (checkCut.find(
"OmniScoreRegion") != std::string::npos) {
190 ATH_MSG_ERROR(
"Misconfig due to OmniScoreRegion and OmniScoreMin cuts both present in the config file. Please CHECK carefully config file again and choose of the two");
191 return StatusCode::FAILURE;
198 else if (sCut ==
"OmniScoreMax")
205 for (
const std::string& checkCut : vCuts){
206 if (checkCut.find(
"OmniScoreRegion") != std::string::npos) {
207 ATH_MSG_ERROR(
"Misconfig due to OmniScoreRegion and OmniScoreMax cuts both present in the config file. Please CHECK carefully config file again and choose of the two");
208 return StatusCode::FAILURE;
215 else if (sCut ==
"OmniIDWP")
222 for (
const std::string& checkCut : vCuts){
223 if (checkCut.find(
"OmniScore") != std::string::npos) {
224 ATH_MSG_ERROR(
"Misconfig due to OmniIDWP and OmniScore cuts both present in the config file. Please CHECK carefully config file again");
225 return StatusCode::FAILURE;
247 using map_type = std::map<DiTauSelectionCuts, std::unique_ptr<TauAnalysisTools::DiTauSelectionCut>>;
248 using pair_type = map_type::value_type;
250 pair_type elements[] =
252 {
DiTauCutPt, std::make_unique<TauAnalysisTools::DiTauSelectionCutPt>(
this)},
253 {
DiTauCutAbsEta, std::make_unique<TauAnalysisTools::DiTauSelectionCutAbsEta>(
this)},
254 {
DiTauCutNSubjets, std::make_unique<TauAnalysisTools::DiTauSelectionCutNSubjets>(
this)},
255 {
DiTauCutAbsCharge, std::make_unique<TauAnalysisTools::DiTauSelectionCutAbsCharge>(
this)},
256 {
DiTauCutOmniScore, std::make_unique<TauAnalysisTools::DiTauSelectionCutOmniScore>(
this)},
257 {
DiTauCutOmniIDWP, std::make_unique<TauAnalysisTools::DiTauSelectionCutOmniIDWP>(
this)},
260 m_cMap = { std::make_move_iterator(
begin(elements) ), std::make_move_iterator(
end(elements) ) };
276 std::string sCuts =
"";
295 return StatusCode::SUCCESS;
302 return StatusCode::SUCCESS;
325 ATH_MSG_FATAL(
"accept(...) Failed to cast particle to tau" );
346 entry.second->fillHistogramCutPre(xDiTau);
354 if (!
entry.second->accept(xDiTau, acceptData))
368 catch (
const std::runtime_error&
error)
375 static std::atomic<uint64_t> warning_count (0
u);
376 auto mycount = ++ warning_count;
389 entry.second->fillHistogramCut(xDiTau);
406 ATH_MSG_WARNING(
"CreateControlPlots was set to true, but no valid file pointer was provided");
416 entry.second->writeControlHistograms();
430 m_hCutFlow = std::make_shared<TH1F>(
"hCutFlow",
"CutFlow;; events",iNBins+1,0,iNBins+1);
439 m_hCutFlow->GetXaxis()->SetBinLabel(iNBins,
entry.second->getName().c_str());
445 template<
typename T,
typename U>
448 if (!vRegion.empty())
450 if (!std::isnan(tMin))
451 vRegion.push_back(tMin);
453 vRegion.push_back(-std::numeric_limits<T>::infinity());
455 if (!std::isnan(tMax))
456 vRegion.push_back(tMax);
458 vRegion.push_back(std::numeric_limits<T>::infinity());
462 template<
typename T,
typename U>
465 if (!vRegion.empty())
468 vRegion.push_back(tVal);
475 unsigned int iNumRegion = vRegion.size()/2;
476 for(
unsigned int iRegion = 0; iRegion < iNumRegion; iRegion++ )
478 ATH_MSG_DEBUG( sCutName<<
": " << vRegion.at(iRegion*2) <<
" to " << vRegion.at(iRegion*2+1) );
486 for (
auto tVal : vRegion)
506 ATH_MSG_ERROR(
"omni ID working point "<<sOmniIDWP<<
" is unknown, the OmniIDWP cut will not accept any ditau!" );
518 return "OMNIIDVERYLOOSE";
520 return "OMNIIDLOOSE";
522 return "OMNIIDMEDIUM";
524 return "OMNIIDTIGHT";
527 ATH_MSG_WARNING(
"OmniID working point with enum " << iOmniIDWP <<
" is unknown, the OmniIDWP cut will not accept any ditau!" );