ATLAS Offline Software
Loading...
Searching...
No Matches
TrigTauPrecisionIDHypoTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "GaudiKernel/SystemOfUnits.h"
9
11
12
13using namespace TrigCompositeUtils;
14
15TrigTauPrecisionIDHypoTool::TrigTauPrecisionIDHypoTool(const std::string& type, const std::string& name, const IInterface* parent)
16 : base_class(type, name, parent),
17 m_decisionId(HLT::Identifier::fromToolName(name))
18{
19
20}
21
22
24{
25 ATH_MSG_DEBUG(name() << ": in initialize()");
26
27 ATH_MSG_DEBUG("TrigTauPrecisionIDHypoTool will cut on:");
28 ATH_MSG_DEBUG(" - PtMin: " << m_ptMin.value());
29 ATH_MSG_DEBUG(" - NTracksMin: " << m_numTrackMin.value());
30 ATH_MSG_DEBUG(" - NTracksMax: " << m_numTrackMax.value());
31 ATH_MSG_DEBUG(" - NIsoTracksMax: " << m_numIsoTrackMax.value());
32 if(m_trackPtCut >= 0) ATH_MSG_DEBUG(" - trackPtCut: " << m_trackPtCut.value());
33 ATH_MSG_DEBUG(" - IDMethod: " << m_idMethod.value());
34 ATH_MSG_DEBUG(" - IDWP: " << m_idWP.value());
35 if(m_idMethod == IDMethod::Decorator) ATH_MSG_DEBUG(" - IDWPNames: " << m_idWPNames.value());
36 ATH_MSG_DEBUG(" - HighPtSelectionTrkThr: " << m_highPtTrkThr.value());
37 ATH_MSG_DEBUG(" - HighPtSelectionLooseIDThr: " << m_highPtLooseIDThr.value());
38 ATH_MSG_DEBUG(" - HighPtSelectionJetThr: " << m_highPtJetThr.value());
39
41 ATH_MSG_ERROR("Invalid tool configuration!");
42 return StatusCode::FAILURE;
43 }
44
46 ATH_MSG_ERROR("Invalid IDMethod value, " << m_idMethod.value());
47 return StatusCode::FAILURE;
49 ATH_MSG_ERROR("Invalid IDWP value, " << m_idWP.value());
50 return StatusCode::FAILURE;
52 ATH_MSG_ERROR("IDMethod=0 must be set together with IDWP=-1");
53 return StatusCode::FAILURE;
54 } else if(m_idMethod == IDMethod::Decorator && m_idWPNames.size() != 4) {
55 ATH_MSG_ERROR("There need to be 4 TauID WPs passed to IDWPNames if using IDMethod=2 (Decorator)");
56 return StatusCode::FAILURE;
57 }
58
59 // Now create the "cache" of TauID score accessors for the Monitoring...
60 ATH_MSG_DEBUG("TauID score monitoring: ");
61 for(const auto& [key, p] : m_monitoredIdScores) {
62 ATH_MSG_DEBUG(" - IDName: " << key);
63 ATH_MSG_DEBUG(" - IDScoreName: " << p.first);
64 ATH_MSG_DEBUG(" - IDScoreSigTransName: " << p.second);
65 if(p.first.empty() || p.second.empty()) {
66 ATH_MSG_ERROR("Invalid score variable names; skipping this entry for the monitoring!");
67 continue;
68 }
69
70 m_monitoredIdAccessors.emplace(key, std::make_pair(SG::ConstAccessor<float>(p.first), SG::ConstAccessor<float>(p.second)));
71 }
72
73 return StatusCode::SUCCESS;
74}
75
76
78{
79 ATH_MSG_DEBUG(name() << ": in execute()");
80
81 auto NInputTaus = Monitored::Scalar<int>("NInputTaus", -1);
82 auto passedCuts = Monitored::Scalar<int>("CutCounter", 0);
83 auto PtAccepted = Monitored::Scalar<float>("PtAccepted", -1);
84 auto NTracksAccepted = Monitored::Scalar<int>("NTracksAccepted", -1);
85 auto NIsoTracksAccepted = Monitored::Scalar<int>("NIsoTracksAccepted", -1);
86
87 std::map<std::string, Monitored::Scalar<float>> monitoredIdVariables;
88 for(const auto& [key, p] : m_monitoredIdScores) {
89 monitoredIdVariables.emplace(key + "_TauJetScoreAccepted_0p", Monitored::Scalar<float>(key + "_TauJetScoreAccepted_0p", -1));
90 monitoredIdVariables.emplace(key + "_TauJetScoreTransAccepted_0p", Monitored::Scalar<float>(key + "_TauJetScoreTransAccepted_0p", -1));
91 monitoredIdVariables.emplace(key + "_TauJetScoreAccepted_1p", Monitored::Scalar<float>(key + "_TauJetScoreAccepted_1p", -1));
92 monitoredIdVariables.emplace(key + "_TauJetScoreTransAccepted_1p", Monitored::Scalar<float>(key + "_TauJetScoreTransAccepted_1p", -1));
93 monitoredIdVariables.emplace(key + "_TauJetScoreAccepted_mp", Monitored::Scalar<float>(key + "_TauJetScoreAccepted_mp", -1));
94 monitoredIdVariables.emplace(key + "_TauJetScoreTransAccepted_mp", Monitored::Scalar<float>(key + "_TauJetScoreTransAccepted_mp", -1));
95 }
96
97 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> monVars = {
98 std::ref(NInputTaus), std::ref(passedCuts), std::ref(PtAccepted), std::ref(NTracksAccepted), std::ref(NIsoTracksAccepted)
99 };
100 for(auto& [key, var] : monitoredIdVariables) monVars.push_back(std::ref(var));
101 auto monitorIt = Monitored::Group(m_monTool, monVars);
102
103
104 // Tau pass flag
105 bool pass = false;
106
107 if(m_acceptAll) {
108 pass = true;
109 ATH_MSG_DEBUG("AcceptAll property is set: taking all events");
110 }
111
112 // Debugging location of the TauJet RoI
113 ATH_MSG_DEBUG("Input RoI eta: " << input.roi->eta() << ", phi: " << input.roi->phi() << ", z: " << input.roi->zed());
114
115 const xAOD::TauJetContainer* TauContainer = input.tauContainer;
116 NInputTaus = TauContainer->size();
117 // There should only be a single TauJet in the TauJetContainer; just in case we still run the loop
118 for(const xAOD::TauJet* Tau : *TauContainer) {
119 ATH_MSG_DEBUG(" New HLT TauJet candidate:");
120
121 float pT = Tau->pt();
122
123 //---------------------------------------------------------
124 // Calibrated tau pT cut ('idperf' step)
125 //---------------------------------------------------------
126 ATH_MSG_DEBUG(" pT: " << pT / Gaudi::Units::GeV);
127
128 if(!(pT > m_ptMin)) continue;
129 passedCuts++;
130 PtAccepted = pT / Gaudi::Units::GeV;
131
132
133 //---------------------------------------------------------
134 // Track counting ('perf' step)
135 //---------------------------------------------------------
136 int numTrack = 0, numIsoTrack = 0;
137 if(m_trackPtCut > 0.) {
138 // Raise the track pT threshold when counting tracks in the 'perf' step, to reduce sensitivity to pileup tracks
139 // Overrides the default 1 GeV cut by the InDetTrackSelectorTool used during the TauJet construction
140 for(const auto* track : Tau->tracks(xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)) {
141 if(track->pt() > m_trackPtCut) numTrack++;
142 }
143 for(const auto* track : Tau->tracks(xAOD::TauJetParameters::TauTrackFlag::classifiedIsolation)) {
144 if(track->pt() > m_trackPtCut) numIsoTrack++;
145 }
146 } else {
147 // Use the default 1 GeV selection in the InDetTrackSelectorTool, executed during the TauJet construction
148 numTrack = Tau->nTracks();
149 numIsoTrack = Tau->nTracksIsolation();
150 }
151
152 ATH_MSG_DEBUG(" N Tracks: " << numTrack);
153 ATH_MSG_DEBUG(" N Iso Tracks: " << numIsoTrack);
154
155 // Apply track multiplicity cuts, except for idperf
156 if(!m_acceptAll) {
157 // NTrackMin and NIsoTracksMax
158 if(pT < m_highPtTrkThr) {
159 if(numTrack < m_numTrackMin) continue;
160 if(numIsoTrack > m_numIsoTrackMax) continue;
161 }
162 // NTrackMax
163 if(pT < m_highPtJetThr) {
164 if(numTrack > m_numTrackMax) continue;
165 }
166 }
167 // Note: we disabled the track selection for high pT taus
168
169 passedCuts++;
170 NTracksAccepted = numTrack;
171 NIsoTracksAccepted = numIsoTrack;
172
173
174 //---------------------------------------------------------
175 // ID WP selection (ID step)
176 //---------------------------------------------------------
177 int local_idWP = m_idWP;
178
179 // Loosen/disable the ID WP cut for high pT taus
180 if(pT > m_highPtLooseIDThr && m_idWP > IDWP::Loose) local_idWP = IDWP::Loose; // Set ID WP to Loose
181 if(pT > m_highPtJetThr) local_idWP = IDWP::None; // Disable the ID WP cut
182
183 ATH_MSG_DEBUG(" Local Tau ID WP: " << local_idWP);
184
185 if(m_idMethod == IDMethod::RNN) { // RNN/DeepSet scores
186 if(!Tau->hasDiscriminant(xAOD::TauJetParameters::RNNJetScoreSigTrans)) {
187 ATH_MSG_WARNING(" RNNJetScoreSigTrans not available. Make sure the TauWPDecorator is run for the RNN Tau ID!");
188 }
189
190 if(!m_acceptAll && local_idWP != IDWP::None) {
192 continue;
193 } else if(local_idWP == IDWP::Loose && !Tau->isTau(xAOD::TauJetParameters::JetRNNSigLoose)) {
194 continue;
195 } else if(local_idWP == IDWP::Medium && !Tau->isTau(xAOD::TauJetParameters::JetRNNSigMedium)) {
196 continue;
197 } else if(local_idWP == IDWP::Tight && !Tau->isTau(xAOD::TauJetParameters::JetRNNSigTight)) {
198 continue;
199 }
200 }
201
202 } else if(m_idMethod == IDMethod::Decorator) { // Decorated scores (e.g. for GNTau)
203 const static SG::ConstAccessor<char> tauid_veryloose(m_idWPNames[0]);
204 const static SG::ConstAccessor<char> tauid_loose(m_idWPNames[1]);
205 const static SG::ConstAccessor<char> tauid_medium(m_idWPNames[2]);
206 const static SG::ConstAccessor<char> tauid_tight(m_idWPNames[3]);
207
208 if(!tauid_veryloose.isAvailable(*Tau) || !tauid_loose.isAvailable(*Tau) || !tauid_medium.isAvailable(*Tau) || !tauid_tight.isAvailable(*Tau))
209 ATH_MSG_WARNING("The TauID WP variables for the current configuration are missing! Make sure the correct inferences are included in the chain reconstruction sequence!");
210
211 if(!m_acceptAll && local_idWP != IDWP::None) {
212 if(local_idWP == IDWP::VeryLoose && !tauid_veryloose(*Tau)) {
213 continue;
214 } else if(local_idWP == IDWP::Loose && !tauid_loose(*Tau)) {
215 continue;
216 } else if(local_idWP == IDWP::Medium && !tauid_medium(*Tau)) {
217 continue;
218 } else if(local_idWP == IDWP::Tight && !tauid_tight(*Tau)) {
219 continue;
220 }
221 }
222
223
224 }
225
226 // TauID Score monitoring
227 for(const auto& [key, p] : m_monitoredIdAccessors) {
228 if(!p.first.isAvailable(*Tau))
229 ATH_MSG_WARNING("TauID Score " << m_monitoredIdScores.value().at(key).first << " is not available. Make sure the correct inferences are included in the chain reconstruction sequence!");
230
231 if(!p.second.isAvailable(*Tau))
232 ATH_MSG_WARNING("TauID ScoreSigTrans " << m_monitoredIdScores.value().at(key).second << " is not available. Make sure the correct inferences are included in the chain reconstruction sequence!");
233
234 ATH_MSG_DEBUG(" TauID \"" << key << "\" ScoreSigTrans: " << p.second(*Tau));
235
236 // Monitor ID scores
237 if(Tau->nTracks() == 0) {
238 monitoredIdVariables.at(key + "_TauJetScoreAccepted_0p") = p.first(*Tau);
239 monitoredIdVariables.at(key + "_TauJetScoreTransAccepted_0p") = p.second(*Tau);
240 } else if(Tau->nTracks() == 1) {
241 monitoredIdVariables.at(key + "_TauJetScoreAccepted_1p") = p.first(*Tau);
242 monitoredIdVariables.at(key + "_TauJetScoreTransAccepted_1p") = p.second(*Tau);
243 } else { // MP tau
244 monitoredIdVariables.at(key + "_TauJetScoreAccepted_mp") = p.first(*Tau);
245 monitoredIdVariables.at(key + "_TauJetScoreTransAccepted_mp") = p.second(*Tau);
246 }
247 }
248
249 passedCuts++;
250
251
252 //---------------------------------------------------------
253 // At least one Tau passed all the cuts. Accept the event!
254 //---------------------------------------------------------
255 pass = true;
256
257 ATH_MSG_DEBUG(" Pass hypo tool: " << pass);
258 }
259
260 return pass;
261}
262
263
264StatusCode TrigTauPrecisionIDHypoTool::decide(std::vector<ITrigTauJetHypoTool::ToolInfo>& input) const {
265 for(ITrigTauJetHypoTool::ToolInfo& i : input) {
266 if(passed(m_decisionId.numeric(), i.previousDecisionIDs)) {
267 if(decide(i)) {
268 addDecisionID(m_decisionId, i.decision);
269 }
270 }
271 }
272
273 return StatusCode::SUCCESS;
274}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Header file to be included by clients of the Monitored infrastructure.
size_type size() const noexcept
Returns the number of elements in the collection.
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual StatusCode decide(std::vector< ITrigTauJetHypoTool::ToolInfo > &input) const override
TrigTauPrecisionIDHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< std::map< std::string, std::pair< std::string, std::string > > > m_monitoredIdScores
Gaudi::Property< int > m_numIsoTrackMax
Gaudi::Property< float > m_trackPtCut
Gaudi::Property< float > m_highPtLooseIDThr
std::map< std::string, std::pair< SG::ConstAccessor< float >, SG::ConstAccessor< float > > > m_monitoredIdAccessors
Gaudi::Property< float > m_highPtJetThr
ToolHandle< GenericMonitoringTool > m_monTool
Gaudi::Property< float > m_highPtTrkThr
Gaudi::Property< std::vector< std::string > > m_idWPNames
virtual StatusCode initialize() override
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
@ RNNJetScoreSigTrans
RNN score which is signal transformed/flattened.
Definition TauDefs.h:92
TauJet_v3 TauJet
Definition of the current "tau version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".