ATLAS Offline Software
Loading...
Searching...
No Matches
TrigTauMonitorBaseAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#if __GNUC__ >= 16
6// Suppress false-positive warning seen with gcc16.
7# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
8#endif
9
11
13
16
17TrigTauMonitorBaseAlgorithm::TrigTauMonitorBaseAlgorithm(const std::string& name, ISvcLocator* pSvcLocator)
18 : AthMonitorAlgorithm(name, pSvcLocator)
19{}
20
21
24 ATH_CHECK( m_trigDecTool.retrieve() );
25 ATH_CHECK( m_eventInfoDecorKey.initialize() );
26
27 ATH_CHECK( m_offlineTauJetKey.initialize() );
29 ATH_CHECK( m_offlineGNTauDecorKey.initialize() );
30
31 if(m_L1_select_by_et_only) ATH_MSG_INFO("L1 RoI selection by Et cut only! No isolated L1 tau items are allowed!");
32 ATH_CHECK( m_phase1l1eTauRoIKey.initialize() );
34 ATH_CHECK( m_phase1l1jTauRoIKey.initialize() );
36 ATH_CHECK( m_phase1l1cTauRoIKey.initialize() );
39
40 // Parse TauTrigInfo objects
41 for(const std::string& trigger : m_triggers) {
44
45 if(m_trigInfo[trigger].areAnyL1TauIsolated()) {
46 ATH_MSG_FATAL("Cannot use isolated L1 tau items if running with SelectL1ByETOnly = True: " << trigger);
47 return StatusCode::FAILURE;
48 }
49 } else {
51 }
52 }
53
54 for(const TrigTauInfo& info : getTrigInfoMap() | std::views::values) {
55 // First check if we already have the container key for this tau leg suffix
56 const std::string sfx = info.getHLTTauLegContainerSfx();
57 if(m_hltTauJetKeysMap.find(sfx) != m_hltTauJetKeysMap.end()) continue;
58
59 // Add and initialize the container key
60 m_hltTauJetKeysMap[sfx] = SG::ReadHandleKey<xAOD::TauJetContainer>("HLT_TrigTauRecMerged_" + sfx);
61 ATH_CHECK( m_hltTauJetKeysMap.at(sfx).initialize() );
62 }
63
64 return StatusCode::SUCCESS;
65}
66
67
68std::vector<const xAOD::TauJet*> TrigTauMonitorBaseAlgorithm::getOnlineTausAll(const std::string& trigger, bool include_0P, bool filter_legs) const
69{
70 std::vector<const xAOD::TauJet*> tau_vec;
71
72 const TrigTauInfo& info = getTrigInfo(trigger);
73
74 std::vector<int> leg_indices = {-1};
75 if(filter_legs) leg_indices = info.getHLTTauLegIndices();
76 for(size_t i = 0; i < leg_indices.size(); ++i) {
77 const int leg = leg_indices[i];
78 const std::string tau_container_name = getOnlineContainerKey(info.getHLTTauLegContainerSfxs().at(leg == -1 ? 0 : i)).key();
79 ATH_MSG_DEBUG("Tau container name is: " << tau_container_name);
80
82 for(auto& featLinkInfo : vec) {
83 const xAOD::TauJet* feat = *(featLinkInfo.link);
84 if(!feat) continue;
85
86 int nTracks = -1;
88 ATH_MSG_DEBUG("NTracks Online: " << nTracks);
89
90 if(include_0P && nTracks == 0) tau_vec.push_back(feat);
91 else tau_vec.push_back(feat);
92 }
93 }
94
95 return tau_vec;
96}
97
98
99std::tuple<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::getOnlineTaus(const EventContext& ctx, const std::string& trigger) const
100{
101 return classifyOnlineTaus(ctx, getOnlineTausAll(trigger, true), 0.0);
102}
103
104
105std::vector<const xAOD::TauJet*> TrigTauMonitorBaseAlgorithm::getOfflineTausAll(const EventContext& ctx, const float threshold) const
106{
107 ATH_MSG_DEBUG("Retrieving offline Taus");
108
109 std::vector<const xAOD::TauJet*> tau_vec;
110
112 if(!taus.isValid()) {
113 ATH_MSG_WARNING("Failed to retrieve offline Taus");
114 return tau_vec;
115 }
116
117 for(const xAOD::TauJet* const tau : *taus) {
118 // Consider only offline taus with a certain minimum pT
119 if(tau->pt() < threshold*Gaudi::Units::GeV) continue;
120
121 // Consider only offline taus outside of the crack region
122 if(std::abs(tau->eta()) > 1.37 && std::abs(tau->eta()) < 1.52) continue;
123
124 // Consider only offline taus which pass thinning
125 static const SG::ConstAccessor<char> passThinningAcc("passThinning");
126 if(!passThinningAcc.withDefault(*tau, true)) continue;
127
128 int nTracks = -1;
129 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
130 ATH_MSG_DEBUG("NTracks Offline: " << nTracks);
131 if(nTracks == 1 || nTracks == 3) tau_vec.push_back(tau);
132 }
133
134 return tau_vec;
135}
136
137
138std::pair<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::getOfflineTaus(const EventContext& ctx, const float threshold, const TauID tau_id) const
139{
140 return classifyOfflineTaus(ctx, getOfflineTausAll(ctx, threshold), threshold, tau_id);
141}
142
143
144std::vector<const xAOD::eFexTauRoI*> TrigTauMonitorBaseAlgorithm::getL1eTAUs(const EventContext& ctx, const std::string& l1_item) const
145{
146 std::vector<const xAOD::eFexTauRoI*> roi_vec;
147
149 if(!rois.isValid()) {
150 ATH_MSG_WARNING("Failed to retrieve the L1_eTauRoi container");
151 return roi_vec;
152 }
153
155 for(const xAOD::eFexTauRoI* roi : *rois) {
156 // Select by RoI ET value only
157 if(roi->et() > m_L1_Phase1_thresholds.value().at(l1_item)) roi_vec.push_back(roi);
158 }
159 } else {
161 if(!thresholdPatterns.isValid()) {
162 ATH_MSG_WARNING("Failed to create thresholdPatterns property accessor for the L1_eTauRoi container");
163 return roi_vec;
164 }
165
166 for(const xAOD::eFexTauRoI* roi : *rois) {
167 // Check that the RoI passed the threshold selection
168 if(thresholdPatterns(*roi) & m_L1_Phase1_threshold_patterns.value().at(l1_item)) roi_vec.push_back(roi);
169 }
170 }
171
172 return roi_vec;
173}
174
175
176std::vector<std::pair<const xAOD::eFexTauRoI*, const xAOD::jFexTauRoI*>> TrigTauMonitorBaseAlgorithm::getL1cTAUs(const EventContext& ctx, const std::string& l1_item) const
177{
178 std::vector<std::pair<const xAOD::eFexTauRoI*, const xAOD::jFexTauRoI*>> roi_vec;
179
181 if(!rois.isValid()) {
182 ATH_MSG_WARNING("Failed to retrieve the L1_cTauRoi container");
183 return roi_vec;
184 }
186 if(!jTau_roi_link.isValid()) {
187 ATH_MSG_WARNING("Failed to create jTauLink accessor for the L1_cTauRoi container");
188 return roi_vec;
189 }
190
192 for(size_t i = 0; i < rois->size(); i++) {
193 const xAOD::eFexTauRoI* roi = (*rois)[i];
194 const xAOD::jFexTauRoI* jTau_roi = jTau_roi_link(i).isValid() ? *jTau_roi_link(i) : nullptr;
195
196 // Select by RoI ET value only
197 if(roi->et() > m_L1_Phase1_thresholds.value().at(l1_item)) roi_vec.push_back(std::make_pair(roi, jTau_roi));
198 }
199 } else {
201 if(!thresholdPatterns.isValid()) {
202 ATH_MSG_WARNING("Failed to create thresholdPatterns property accessor for the L1_cTauRoi container");
203 return roi_vec;
204 }
205
206 for(size_t i = 0; i < rois->size(); i++) {
207 const xAOD::eFexTauRoI* roi = (*rois)[i];
208 const xAOD::jFexTauRoI* jTau_roi = jTau_roi_link(i).isValid() ? *jTau_roi_link(i) : nullptr;
209
210 // Check that the RoI passed the threshold selection
211 if(thresholdPatterns(*roi) & m_L1_Phase1_threshold_patterns.value().at(l1_item)) roi_vec.push_back(std::make_pair(roi, jTau_roi));
212 }
213 }
214
215
216 return roi_vec;
217}
218
219
221{
222 if(m_hltTauJetKeysMap.find(container_suffix) != m_hltTauJetKeysMap.end()) return m_hltTauJetKeysMap.at(container_suffix);
223 else {
224 if(m_hltTauJetKeysMap.find("MVA") != m_hltTauJetKeysMap.end()) {
225 ATH_MSG_ERROR("HLT TauJet container not registered for suffix \"" << container_suffix << "\". Returning the default \"" << m_hltTauJetKeysMap.at("MVA").key() << "\"");
226 return m_hltTauJetKeysMap.at("MVA");
227 } else {
228 ATH_MSG_ERROR("HLT TauJet container not registered for suffix \"" << container_suffix << "\". Returning the first available container \"" << m_hltTauJetKeysMap.begin()->second.key() << "\"");
229 return m_hltTauJetKeysMap.begin()->second;
230 }
231 }
232}
233
234
235StatusCode TrigTauMonitorBaseAlgorithm::fillHistograms(const EventContext& ctx) const
236{
237 ATH_MSG_DEBUG("Executing Monitoring algorithm");
238
239 // Protect against truncated events
240 // Since this happens very rarely, it won't bias the L1 distributions and efficiencies
241 if(m_trigDecTool->ExperimentalAndExpertMethods().isHLTTruncated()){
242 ATH_MSG_WARNING("HLTResult truncated, skip trigger analysis");
243 return StatusCode::SUCCESS;
244 }
245
246 // Protect against LAr noise bursts and other detector errors
248 ATH_CHECK(eventInfo.isValid());
249 if (eventInfo->errorState(xAOD::EventInfo::LAr) == xAOD::EventInfo::Error
250 || eventInfo->errorState(xAOD::EventInfo::Tile) == xAOD::EventInfo::Error
251 || eventInfo->errorState(xAOD::EventInfo::SCT) == xAOD::EventInfo::Error
252 || eventInfo->isEventFlagBitSet(xAOD::EventInfo::Core, 18)) {
253 return StatusCode::SUCCESS;
254 }
255
257
258 return StatusCode::SUCCESS;
259}
260
261
262std::vector<const xAOD::TauJet*> TrigTauMonitorBaseAlgorithm::classifyTausAll(const EventContext& ctx, const std::vector<const xAOD::TauJet*>& taus, const float threshold, const TauID tau_id) const
263{
264 std::vector<const xAOD::TauJet*> tau_vec;
265
267 if(!tauid_medium.isValid()) {
268 ATH_MSG_WARNING("Cannot retrieve " << tauid_medium.key());
269 return tau_vec;
270 }
271
272 for(const xAOD::TauJet* tau : taus) {
273 if(tau->pt() < threshold*Gaudi::Units::GeV) continue;
274
275 // Consider only offline taus which pass medium ID WP
276 if(tau_id == TauID::RNN) {
277 if(!tau->isTau(xAOD::TauJetParameters::JetRNNSigMedium)) continue;
278 }
279 else if(tau_id == TauID::GNTau) {
280 if(!tauid_medium(*tau)) continue;
281 }
282
283 tau_vec.push_back(tau);
284 }
285
286 return tau_vec;
287}
288
289
290std::tuple<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::classifyOnlineTaus(const EventContext& ctx, const std::vector<const xAOD::TauJet*>& taus, const float threshold) const
291{
292 std::vector<const xAOD::TauJet*> tau_vec_0p, tau_vec_1p, tau_vec_mp;
293
294 for(const xAOD::TauJet* tau : classifyTausAll(ctx, taus, threshold, TauID::None)) {
295 int nTracks = -1;
296 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
297
298 if(nTracks == 0) tau_vec_0p.push_back(tau);
299 else if(nTracks == 1) tau_vec_1p.push_back(tau);
300 else tau_vec_mp.push_back(tau);
301 }
302
303 return {tau_vec_0p, tau_vec_1p, tau_vec_mp};
304}
305
306
307std::pair<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::classifyOfflineTaus(const EventContext& ctx, const std::vector<const xAOD::TauJet*>& taus, const float threshold, const TauID tau_id) const
308{
309 std::vector<const xAOD::TauJet*> tau_vec_1p, tau_vec_3p;
310
311 for(const xAOD::TauJet* const tau : classifyTausAll(ctx, taus, threshold, tau_id)) {
312 int nTracks = -1;
313 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
314
315 if(nTracks == 1) tau_vec_1p.push_back(tau);
316 else if(nTracks == 3) tau_vec_3p.push_back(tau);
317 }
318
319 return {tau_vec_1p, tau_vec_3p};
320}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
static Double_t taus
Handle class for reading a decoration on an object.
virtual StatusCode initialize() override
initialize
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.).
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Tool to tell whether a specific trigger is passed.
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Helper class to provide constant type-safe access to aux data.
const_reference_type withDefault(const ELT &e, const T &deflt) const
Fetch the variable for one element, as a const reference, with a default.
Handle class for reading a decoration on an object.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::vector< const xAOD::eFexTauRoI * > getL1eTAUs(const EventContext &ctx, const std::string &l1_item) const
Gaudi::Property< std::map< std::string, float > > m_L1_Phase1_thresholds
const SG::ReadHandleKey< xAOD::TauJetContainer > & getOnlineContainerKey(const std::string &container_suffix) const
SG::ReadHandleKey< xAOD::jFexTauRoIContainer > m_phase1l1jTauRoIKey
SG::ReadDecorHandleKey< xAOD::eFexTauRoIContainer > m_phase1l1cTauRoIDecorKey
virtual StatusCode initialize() override
initialize
std::map< std::string, TrigTauInfo > m_trigInfo
std::pair< std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * > > classifyOfflineTaus(const EventContext &ctx, const std::vector< const xAOD::TauJet * > &taus, const float threshold=0.0, const TauID tau_id=TauID::None) const
TrigTauMonitorBaseAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< const xAOD::TauJet * > getOfflineTausAll(const EventContext &ctx, const float threshold=20.0) const
std::unordered_map< std::string, SG::ReadHandleKey< xAOD::TauJetContainer > > m_hltTauJetKeysMap
std::pair< std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * > > getOfflineTaus(const EventContext &ctx, const float threshold=20.0, const TauID tau_id=TauID::None) const
Gaudi::Property< std::vector< std::string > > m_triggers
SG::ReadDecorHandleKey< xAOD::eFexTauRoIContainer > m_phase1l1cTauRoIThresholdPatternsKey
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_phase1l1eTauRoIKey
std::tuple< std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * > > classifyOnlineTaus(const EventContext &ctx, const std::vector< const xAOD::TauJet * > &taus, const float threshold=0.0) const
SG::ReadDecorHandleKey< xAOD::jFexTauRoIContainer > m_phase1l1jTauRoIThresholdPatternsKey
std::map< std::string, TrigTauInfo > & getTrigInfoMap()
const TrigTauInfo & getTrigInfo(const std::string &trigger) const
virtual StatusCode processEvent(const EventContext &ctx) const =0
std::vector< const xAOD::TauJet * > classifyTausAll(const EventContext &ctx, const std::vector< const xAOD::TauJet * > &taus, const float threshold=0.0, const TauID tau_id=TauID::None) const
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
SG::ReadDecorHandleKey< xAOD::eFexTauRoIContainer > m_phase1l1eTauRoIThresholdPatternsKey
Gaudi::Property< bool > m_L1_select_by_et_only
SG::ReadDecorHandleKey< xAOD::TauJetContainer > m_offlineGNTauDecorKey
std::tuple< std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * > > getOnlineTaus(const EventContext &ctx, const std::string &trigger) const
std::vector< const xAOD::TauJet * > getOnlineTausAll(const std::string &trigger, bool include_0P=true, bool filter_legs=false) const
std::vector< std::pair< const xAOD::eFexTauRoI *, const xAOD::jFexTauRoI * > > getL1cTAUs(const EventContext &ctx, const std::string &l1_item) const
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_phase1l1cTauRoIKey
Gaudi::Property< std::map< std::string, uint64_t > > m_L1_Phase1_threshold_patterns
SG::ReadDecorHandleKey< xAOD::EventInfo > m_eventInfoDecorKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_offlineTauJetKey
@ Tile
The Tile calorimeter.
@ Core
Core flags describing the event.
@ LAr
The LAr calorimeter.
@ Error
The sub-detector issued an error.
bool detail(TauJetParameters::Detail detail, int &value) const
Get and set values of common details variables via enum.
float et() const
TOB ET (decoded from TOB, stored for convenience).
const std::string & featureString()
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.
TauJet_v3 TauJet
Definition of the current "tau version".
jFexTauRoI_v1 jFexTauRoI
Define the latest version of the jFexSRJetRoI class.
Definition jFexTauRoI.h:13
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
eFexTauRoI_v1 eFexTauRoI
Define the latest version of the eFexTauRoI class.
Definition eFexTauRoI.h:16