14 #include "THashList.h"
23 DiTauSelectionTool::DiTauSelectionTool(
const std::string&
name )
26 , m_aAccept(
"DiTauSelection" )
30 DiTauSelectionTool::~DiTauSelectionTool()
46 bool bConfigViaProperties =
false;
47 if (!bConfigViaProperties and !
m_vPtRegion.empty()) bConfigViaProperties =
true;
48 if (!bConfigViaProperties and !std::isnan(
m_dPtMin.value())) bConfigViaProperties =
true;
49 if (!bConfigViaProperties and !std::isnan(
m_dPtMax.value())) bConfigViaProperties =
true;
50 if (!bConfigViaProperties and !
m_vAbsEtaRegion.empty()) bConfigViaProperties =
true;
51 if (!bConfigViaProperties and !std::isnan(
m_dAbsEtaMin.value())) bConfigViaProperties =
true;
52 if (!bConfigViaProperties and !std::isnan(
m_dAbsEtaMax.value())) bConfigViaProperties =
true;
53 if (!bConfigViaProperties and !
m_vNSubjetsRegion.empty()) bConfigViaProperties =
true;
54 if (!bConfigViaProperties and !std::isnan(
m_dNSubjetsMin.value())) bConfigViaProperties =
true;
55 if (!bConfigViaProperties and !std::isnan(
m_dNSubjetsMax.value())) bConfigViaProperties =
true;
56 if (!bConfigViaProperties and !
m_vAbsCharges.empty()) bConfigViaProperties =
true;
57 if (!bConfigViaProperties and !std::isnan(
m_iAbsCharge.value())) bConfigViaProperties =
true;
58 if (!bConfigViaProperties and !
m_vOmniScoreRegion.empty()) bConfigViaProperties =
true;
59 if (!bConfigViaProperties and !std::isnan(
m_dOmniScoreMin.value())) bConfigViaProperties =
true;
60 if (!bConfigViaProperties and !std::isnan(
m_dOmniScoreMax.value())) bConfigViaProperties =
true;
63 if (bConfigViaConfigFile and bConfigViaProperties)
65 ATH_MSG_WARNING(
"Configured tool via setProperty and configuration file, which may lead to unexpected configuration.");
66 ATH_MSG_WARNING(
"In doubt check the configuration that is printed when the tool is initialized and the message level is set to debug");
67 ATH_MSG_WARNING(
"For further details please refer to the documentation:");
68 ATH_MSG_WARNING(
"https://gitlab.cern.ch/atlas/athena/blob/main/PhysicsAnalysis/TauID/TauAnalysisTools/doc/README-DiTauSelectionTool.rst");
70 if (!bConfigViaConfigFile and !bConfigViaProperties)
72 ATH_MSG_WARNING(
"No cut configuration provided, the tool will not do anything. For further details please refer to the documentation:");
73 ATH_MSG_WARNING(
"https://gitlab.cern.ch/atlas/athena/blob/main/PhysicsAnalysis/TauID/TauAnalysisTools/doc/README-DiTauSelectionTool.rst");
76 if (bConfigViaConfigFile)
82 ATH_MSG_WARNING(
"Config file for DiTauSelectionTool with path "<<sInputFilePath<<
" does not contain an empty last line. The tool might not be properly configured!");
84 rEnv.ReadFile(sInputFilePath.c_str(),
87 std::vector<std::string> vCuts;
90 if (rEnv.Defined(
"SelectionCuts"))
94 auto lList = rEnv.GetTable();
95 for( Int_t
i = 0;
i < lList->GetEntries(); ++
i )
97 vCuts.push_back( lList->At(
i )->GetName() );
101 int iSelectionCuts = 0;
103 for (
const std::string& sCut : vCuts)
105 if (sCut ==
"PtRegion")
111 else if (sCut ==
"PtMin")
115 m_dPtMin = rEnv.GetValue(
"PtMin",NAN);
117 else if (sCut ==
"PtMax")
121 m_dPtMax = rEnv.GetValue(
"PtMax",NAN);
123 else if (sCut ==
"AbsEtaRegion")
129 else if (sCut ==
"AbsEtaMin")
135 else if (sCut ==
"AbsEtaMax")
141 else if (sCut ==
"NSubjetsRegion")
147 else if (sCut ==
"NSubjetsMin")
153 else if (sCut ==
"NSubjetsMax")
159 else if (sCut ==
"AbsCharges")
165 else if (sCut ==
"AbsCharge")
171 else if (sCut ==
"OmniScoreRegion")
180 else if (sCut ==
"OmniScoreMin")
187 for (
const std::string& checkCut : vCuts){
188 if (checkCut.find(
"OmniScoreRegion") != std::string::npos) {
189 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");
190 return StatusCode::FAILURE;
197 else if (sCut ==
"OmniScoreMax")
204 for (
const std::string& checkCut : vCuts){
205 if (checkCut.find(
"OmniScoreRegion") != std::string::npos) {
206 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");
207 return StatusCode::FAILURE;
230 using map_type = std::map<DiTauSelectionCuts, std::unique_ptr<TauAnalysisTools::DiTauSelectionCut>>;
231 using pair_type = map_type::value_type;
233 pair_type elements[] =
235 {
DiTauCutPt, std::make_unique<TauAnalysisTools::DiTauSelectionCutPt>(
this)},
236 {
DiTauCutAbsEta, std::make_unique<TauAnalysisTools::DiTauSelectionCutAbsEta>(
this)},
237 {
DiTauCutNSubjets, std::make_unique<TauAnalysisTools::DiTauSelectionCutNSubjets>(
this)},
238 {
DiTauCutAbsCharge, std::make_unique<TauAnalysisTools::DiTauSelectionCutAbsCharge>(
this)},
239 {
DiTauCutOmniScore, std::make_unique<TauAnalysisTools::DiTauSelectionCutOmniScore>(
this)},
242 m_cMap = { std::make_move_iterator(
begin(elements) ), std::make_move_iterator(
end(elements) ) };
257 std::string sCuts =
"";
275 return StatusCode::SUCCESS;
282 return StatusCode::SUCCESS;
305 ATH_MSG_FATAL(
"accept(...) Failed to cast particle to tau" );
326 entry.second->fillHistogramCutPre(xDiTau);
334 if (!
entry.second->accept(xDiTau, acceptData))
348 catch (
const std::runtime_error&
error)
355 static std::atomic<uint64_t> warning_count (0
u);
356 auto mycount = ++ warning_count;
369 entry.second->fillHistogramCut(xDiTau);
386 ATH_MSG_WARNING(
"CreateControlPlots was set to true, but no valid file pointer was provided");
396 entry.second->writeControlHistograms();
410 m_hCutFlow = std::make_shared<TH1F>(
"hCutFlow",
"CutFlow;; events",iNBins+1,0,iNBins+1);
419 m_hCutFlow->GetXaxis()->SetBinLabel(iNBins,
entry.second->getName().c_str());
425 template<
typename T,
typename U>
428 if (!vRegion.empty())
430 if (!std::isnan(tMin))
431 vRegion.push_back(tMin);
433 vRegion.push_back(-std::numeric_limits<T>::infinity());
435 if (!std::isnan(tMax))
436 vRegion.push_back(tMax);
438 vRegion.push_back(std::numeric_limits<T>::infinity());
442 template<
typename T,
typename U>
445 if (!vRegion.empty())
448 vRegion.push_back(tVal);
455 unsigned int iNumRegion = vRegion.size()/2;
456 for(
unsigned int iRegion = 0; iRegion < iNumRegion; iRegion++ )
458 ATH_MSG_DEBUG( sCutName<<
": " << vRegion.at(iRegion*2) <<
" to " << vRegion.at(iRegion*2+1) );
466 for (
auto tVal : vRegion)