21TauSelectionTool::TauSelectionTool(
const std::string& name )
23 , m_sJetIDWP(
"JETIDNONE")
24 , m_sEleIDWP(
"ELEIDNONE")
26 , m_aAccept(
"TauSelection" )
30TauSelectionTool::~TauSelectionTool()
36StatusCode TauSelectionTool::initialize()
39 m_vAbsEtaRegion = m_vecAbsEtaRegion.value();
40 m_vAbsCharges = m_vecAbsCharges.value();
41 m_vNTracks = m_vecNTracks.value();
43 bool bConfigViaConfigFile = !m_sConfigPath.empty();
44 bool bConfigViaProperties =
false;
45 if (!bConfigViaProperties and !std::isnan(m_dPtMin.value())) bConfigViaProperties =
true;
46 if (!bConfigViaProperties and !m_vAbsEtaRegion.empty()) bConfigViaProperties =
true;
47 if (!bConfigViaProperties and !std::isnan(m_dAbsEtaMin.value())) bConfigViaProperties =
true;
48 if (!bConfigViaProperties and !std::isnan(m_dAbsEtaMax.value())) bConfigViaProperties =
true;
49 if (!bConfigViaProperties and !m_vAbsCharges.empty()) bConfigViaProperties =
true;
50 if (!bConfigViaProperties and !std::isnan(m_iAbsCharge.value())) bConfigViaProperties =
true;
51 if (!bConfigViaProperties and !m_vNTracks.empty()) bConfigViaProperties =
true;
52 if (!bConfigViaProperties and !std::isnan(m_iNTrack.value())) bConfigViaProperties =
true;
53 if (!bConfigViaProperties and !std::isnan(m_dJetRNNSigTransMin.value())) bConfigViaProperties =
true;
54 if (!bConfigViaProperties and !std::isnan(m_dGNTauSigTransMin.value())) bConfigViaProperties =
true;
56 if (!bConfigViaProperties and !std::isnan(m_dEleRNNSigTransMin.value())) bConfigViaProperties =
true;
57 if (!bConfigViaProperties and m_iEleIDWP != 0) bConfigViaProperties =
true;
58 if (!bConfigViaProperties and m_bMuonOLR) bConfigViaProperties =
true;
60 if (bConfigViaConfigFile and bConfigViaProperties)
62 ATH_MSG_ERROR(
"Configured tool via setProperty and configuration file, which may lead to unexpected configuration. Please setup the TauSelectionTool using only one of the two methods. For further details please refer to the documentation https://gitlab.cern.ch/atlas/athena/blob/main/PhysicsAnalysis/TauID/TauAnalysisTools/doc/README-TauSelectionTool.rst or contact the TauCP group.");
63 return StatusCode::FAILURE;
65 if (!bConfigViaConfigFile and !bConfigViaProperties)
67 ATH_MSG_WARNING(
"No cut configuration provided, the tool will not do anything. 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-TauSelectionTool.rst");
69 return StatusCode::SUCCESS;
72 if (bConfigViaConfigFile)
77 if (!testFileForEOFContainsCharacters(sInputFilePath))
78 ATH_MSG_WARNING(
"Config file for TauSelectionTool with path "<<sInputFilePath<<
" does not contain an empty last line. The tool might not be properly configured!");
80 rEnv.ReadFile(sInputFilePath.c_str(),
83 std::vector<std::string> vCuts;
86 if (rEnv.Defined(
"SelectionCuts"))
90 auto lList = rEnv.GetTable();
91 for( Int_t i = 0;
i < lList->GetEntries(); ++
i )
93 vCuts.push_back( lList->At( i )->GetName() );
97 int iSelectionCuts = 0;
99 for (
const std::string& sCut : vCuts)
103 iSelectionCuts = iSelectionCuts |
CutPt;
104 if (std::isnan(m_dPtMin.value()))
105 m_dPtMin = rEnv.GetValue(
"PtMin",NAN);
107 else if (sCut ==
"AbsEtaRegion")
109 iSelectionCuts = iSelectionCuts |
CutAbsEta;
110 if (m_vAbsEtaRegion.empty())
113 else if (sCut ==
"AbsEtaMin")
115 iSelectionCuts = iSelectionCuts |
CutAbsEta;
116 if (std::isnan(m_dAbsEtaMin.value()))
117 m_dAbsEtaMin = rEnv.GetValue(
"AbsEtaMin",NAN);
119 else if (sCut ==
"AbsEtaMax")
121 iSelectionCuts = iSelectionCuts |
CutAbsEta;
122 if (std::isnan(m_dAbsEtaMax.value()))
123 m_dAbsEtaMax = rEnv.GetValue(
"AbsEtaMax",NAN);
125 else if (sCut ==
"AbsCharges")
128 if (m_vAbsCharges.empty())
131 else if (sCut ==
"AbsCharge")
134 if (std::isnan(m_iAbsCharge.value()))
135 m_iAbsCharge = rEnv.GetValue(
"AbsCharge",NAN);
137 else if (sCut ==
"NTracks")
139 iSelectionCuts = iSelectionCuts |
CutNTrack;
140 if (m_vNTracks.empty())
143 else if (sCut ==
"NTrack")
145 iSelectionCuts = iSelectionCuts |
CutNTrack;
146 if (std::isnan(m_iNTrack.value()))
147 m_iNTrack = rEnv.GetValue(
"NTrack",NAN);
149 else if (sCut ==
"JetRNNSigTransMin")
152 if (std::isnan(m_dJetRNNSigTransMin.value()))
153 m_dJetRNNSigTransMin = rEnv.GetValue(
"JetRNNSigTransMin",NAN);
155 else if (sCut ==
"GNTauSigTransMin")
158 if (std::isnan(m_dGNTauSigTransMin.value()))
159 m_dGNTauSigTransMin = rEnv.GetValue(
"GNTauSigTransMin",NAN);
164 else if (sCut ==
"EleRNNSigTransMin")
167 if (std::isnan(m_dEleRNNSigTransMin.value()))
168 m_dEleRNNSigTransMin = rEnv.GetValue(
"EleRNNSigTransMin",NAN);
170 else if (sCut ==
"JetIDWP")
174 m_sJetIDWP = rEnv.GetValue(
"JetIDWP",
"JETIDNONE");
175 m_iJetIDWP = convertStrToJetIDWP(m_sJetIDWP);
178 for (
const std::string& checkCut : vCuts){
179 if (checkCut.find(
"SigTrans") != std::string::npos) {
180 ATH_MSG_ERROR(
"Misconfig due to JetIDWP and SigTrans cuts both present in the config file. Please CHECK carefully config file again");
181 return StatusCode::FAILURE;
185 else if (sCut ==
"EleIDWP")
189 m_sEleIDWP = rEnv.GetValue(
"EleIDWP",
"ELEIDNONE");
190 m_iEleIDWP = convertStrToEleIDWP(m_sEleIDWP);
193 else if (sCut ==
"MuonOLR")
197 m_bMuonOLR = rEnv.GetValue(
"MuonOLR",
false);
202 if (m_iSelectionCuts ==
NoCut)
203 m_iSelectionCuts = iSelectionCuts;
207 if(m_sJetIDWP.find(
"GNTAU") != std::string::npos)
213 ATH_CHECK( m_tauContainerKey.initialize() );
217 ATH_CHECK( m_GNTauDecorKey.assign(m_tauContainerKey.key()+
".GNTauScoreSigTrans_v0prune"));
219 ATH_CHECK( m_GNTauDecorKey.initialize( m_useGNTau ) );
223 ATH_CHECK( m_eVetoDecorKey.assign(m_tauContainerKey.key()+
".RNNEleScoreSigTrans_v"+std::to_string(m_iEleIDVersion)) );
228 using map_type = std::map<SelectionCuts, std::unique_ptr<TauSelectionCut>>;
229 using pair_type = map_type::value_type;
231 pair_type elements[] =
233 {
CutPt, std::make_unique<TauSelectionCutPt>(
this)},
234 {
CutAbsEta, std::make_unique<TauSelectionCutAbsEta>(
this)},
235 {
CutAbsCharge, std::make_unique<TauSelectionCutAbsCharge>(
this)},
236 {
CutNTrack, std::make_unique<TauSelectionCutNTracks>(
this)},
239 {
CutJetIDWP, std::make_unique<TauSelectionCutJetIDWP>(
this)},
241 {
CutEleIDWP, std::make_unique<TauSelectionCutEleIDWP>(
this)},
242 {
CutMuonOLR, std::make_unique<TauSelectionCutMuonOLR>(
this)}
245 m_cMap = { std::make_move_iterator(
begin(elements) ), std::make_move_iterator(
end(elements) ) };
248 FillRegionVector(m_vPtRegion, m_dPtMin.value(), NAN);
249 FillRegionVector(m_vAbsEtaRegion, m_dAbsEtaMin.value(), m_dAbsEtaMax.value());
250 FillRegionVector(m_vJetRNNSigTransRegion, m_dJetRNNSigTransMin.value(), NAN );
251 FillRegionVector(m_vGNTauSigTransRegion, m_dGNTauSigTransMin.value(), NAN );
252 FillRegionVector(m_vEleRNNSigTransRegion, m_dEleRNNSigTransMin.value(), NAN );
253 FillValueVector(m_vAbsCharges, m_iAbsCharge.value());
254 FillValueVector(m_vNTracks, m_iNTrack.value());
256 PrintConfigRegion (
"Pt", m_vPtRegion);
257 PrintConfigRegion (
"AbsEta", m_vAbsEtaRegion);
258 PrintConfigValue (
"AbsCharge", m_vAbsCharges);
259 PrintConfigValue (
"NTrack", m_vNTracks);
260 PrintConfigRegion (
"RNNJetScoreSigTrans", m_vJetRNNSigTransRegion);
261 PrintConfigRegion (
"GNTauScoreSigTrans", m_vGNTauSigTransRegion);
262 PrintConfigRegion (
"RNNEleScoreSigTrans", m_vEleRNNSigTransRegion);
263 PrintConfigValue (
"JetIDWP", m_sJetIDWP);
264 PrintConfigValue (
"JetIDWP ENUM",m_iJetIDWP);
265 PrintConfigValue (
"EleIDWP", m_sEleIDWP);
266 PrintConfigValue (
"EleIDWP ENUM",m_iEleIDWP);
267 PrintConfigValue (
"EleIDVersion",m_iEleIDVersion);
268 PrintConfigValue (
"MuonOLR", m_bMuonOLR);
270 std::string sCuts =
"";
271 if (m_iSelectionCuts &
CutPt) sCuts +=
"Pt ";
272 if (m_iSelectionCuts &
CutAbsEta) sCuts +=
"AbsEta ";
273 if (m_iSelectionCuts &
CutAbsCharge) sCuts +=
"AbsCharge ";
274 if (m_iSelectionCuts &
CutNTrack) sCuts +=
"NTrack ";
277 if (m_iSelectionCuts &
CutJetIDWP) sCuts +=
"JetIDWP ";
279 if (m_iSelectionCuts &
CutEleIDWP) sCuts +=
"EleIDWP ";
280 if (m_iSelectionCuts &
CutMuonOLR) sCuts +=
"MuonOLR ";
284 if (m_bCreateControlPlots)
285 setupCutFlowHistogram();
287 for (
const auto& entry : m_cMap ) {
288 if ( m_iSelectionCuts &
entry.first ) {
289 entry.second->setAcceptInfo(m_aAccept);
293 return StatusCode::SUCCESS;
298StatusCode TauSelectionTool::beginEvent()
300 return StatusCode::SUCCESS;
323 ATH_MSG_FATAL(
"accept(...) Failed to cast particle to tau" );
338 if (m_bCreateControlPlots)
341 m_hCutFlow->Fill(iNBin);
343 for (
const auto& entry : m_cMap)
344 entry.second->fillHistogramCutPre(xTau);
348 for (
const auto& entry : m_cMap)
350 if (m_iSelectionCuts &
entry.first)
352 if (!
entry.second->accept(xTau, acceptData))
356 if (m_bCreateControlPlots)
360 m_hCutFlow->Fill(iNBin);
366 catch (
const std::runtime_error&
error)
373 static std::atomic<uint64_t> warning_count (0u);
374 auto mycount = ++ warning_count;
384 if (m_bCreateControlPlots)
386 for (
const auto& entry : m_cMap)
387 entry.second->fillHistogramCut(xTau);
395void TauSelectionTool::setOutFile( TFile* fOutFile )
397 m_fOutFile = fOutFile;
401void TauSelectionTool::writeControlHistograms()
403 if (m_bCreateControlPlots and !m_fOutFile)
404 ATH_MSG_WARNING(
"CreateControlPlots was set to true, but no valid file pointer was provided");
405 if (m_bCreateControlPlots and m_fOutFile)
408 m_fOutFile->mkdir((this->
name()+
"_control").c_str());
409 m_fOutFile->cd((this->
name()+
"_control").c_str());
413 for (
const auto& entry : m_cMap)
414 entry.second->writeControlHistograms();
420void TauSelectionTool::setupCutFlowHistogram()
424 for (
const auto& entry : m_cMap)
425 if (m_iSelectionCuts &
entry.first)
428 m_hCutFlow = std::make_shared<TH1F>(
"hCutFlow",
"CutFlow;; events",iNBins+1,0,iNBins+1);
429 m_hCutFlow->GetXaxis()->SetBinLabel(1,
"All");
434 for (
const auto& entry : m_cMap)
435 if (m_iSelectionCuts &
entry.first)
437 m_hCutFlow->GetXaxis()->SetBinLabel(iNBins,
entry.second->getName().c_str());
443template<
typename T,
typename U>
444void TauSelectionTool::FillRegionVector(std::vector<T>& vRegion, U tMin, U tMax)
const
446 if (!vRegion.empty())
449 vRegion.push_back(tMin);
451 vRegion.push_back(-std::numeric_limits<T>::infinity());
454 vRegion.push_back(tMax);
456 vRegion.push_back(std::numeric_limits<T>::infinity());
460template<
typename T,
typename U>
461void TauSelectionTool::FillValueVector(std::vector<T>& vRegion, U tVal)
const
463 if (!vRegion.empty())
466 vRegion.push_back(tVal);
471void TauSelectionTool::PrintConfigRegion(
const std::string& sCutName, std::vector<T>& vRegion)
const
473 unsigned int iNumRegion = vRegion.size()/2;
474 for(
unsigned int iRegion = 0; iRegion < iNumRegion; iRegion++ )
476 ATH_MSG_DEBUG( sCutName<<
": " << vRegion.at(iRegion*2) <<
" to " << vRegion.at(iRegion*2+1) );
482void TauSelectionTool::PrintConfigValue(
const std::string& sCutName, std::vector<T>& vRegion)
const
484 for (
auto tVal : vRegion)
490void TauSelectionTool::PrintConfigValue(
const std::string& sCutName, T& tVal)
const
496int TauSelectionTool::convertStrToJetIDWP(
const std::string& sJetIDWP)
const
498 if (sJetIDWP ==
"JETIDNONE")
return int(
JETIDNONE);
500 else if (sJetIDWP ==
"JETIDRNNLOOSE")
return int(
JETIDRNNLOOSE);
501 else if (sJetIDWP ==
"JETIDRNNMEDIUM")
return int(
JETIDRNNMEDIUM);
502 else if (sJetIDWP ==
"JETIDRNNTIGHT")
return int(
JETIDRNNTIGHT);
508 ATH_MSG_ERROR(
"jet ID working point "<<sJetIDWP<<
" is unknown, the JetIDWP cut will not accept any tau!" );
513int TauSelectionTool::convertStrToEleIDWP(
const std::string& sEleIDWP)
const
515 if (sEleIDWP ==
"ELEIDNONE")
return int(
ELEIDNONE);
516 else if (sEleIDWP ==
"ELEIDRNNLOOSE")
return int(
ELEIDRNNLOOSE);
517 else if (sEleIDWP ==
"ELEIDRNNMEDIUM")
return int(
ELEIDRNNMEDIUM);
518 else if (sEleIDWP ==
"ELEIDRNNTIGHT")
return int(
ELEIDRNNTIGHT);
520 ATH_MSG_ERROR(
"electron ID working point " << sEleIDWP <<
" is unknown, the EleIDWP cut will not accept any tau!" );
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Class providing the definition of the 4-vector interface.
virtual Type::ObjectType type() const =0
The type of the object as a simple enumeration.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
StatusCode accept(const xAOD::Muon *mu)
@ Tau
The object is a tau (jet).
TauJet_v3 TauJet
Definition of the current "tau version".