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 tau_vec.push_back(feat);
91 }
92 }
93
94 return tau_vec;
95}
96
97
98std::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
99{
100 return classifyOnlineTaus(ctx, getOnlineTausAll(trigger, true), 0.0);
101}
102
103
104std::vector<const xAOD::TauJet*> TrigTauMonitorBaseAlgorithm::getOfflineTausAll(const EventContext& ctx, const float threshold) const
105{
106 ATH_MSG_DEBUG("Retrieving offline Taus");
107
108 std::vector<const xAOD::TauJet*> tau_vec;
109
111 if(!taus.isValid()) {
112 ATH_MSG_WARNING("Failed to retrieve offline Taus");
113 return tau_vec;
114 }
115
116 for(const xAOD::TauJet* const tau : *taus) {
117 // Consider only offline taus with a certain minimum pT
118 if(tau->pt() < threshold*Gaudi::Units::GeV) continue;
119
120 // Consider only offline taus outside of the crack region
121 if(std::abs(tau->eta()) > 1.37 && std::abs(tau->eta()) < 1.52) continue;
122
123 // Consider only offline taus which pass thinning
124 static const SG::ConstAccessor<char> passThinningAcc("passThinning");
125 if(!passThinningAcc.withDefault(*tau, true)) continue;
126
127 int nTracks = -1;
128 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
129 ATH_MSG_DEBUG("NTracks Offline: " << nTracks);
130 if(nTracks == 1 || nTracks == 3) tau_vec.push_back(tau);
131 }
132
133 return tau_vec;
134}
135
136
137std::pair<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::getOfflineTaus(const EventContext& ctx, const float threshold, const TauID tau_id) const
138{
139 return classifyOfflineTaus(ctx, getOfflineTausAll(ctx, threshold), threshold, tau_id);
140}
141
142
143std::vector<const xAOD::eFexTauRoI*> TrigTauMonitorBaseAlgorithm::getL1eTAUs(const EventContext& ctx, const std::string& l1_item) const
144{
145 std::vector<const xAOD::eFexTauRoI*> roi_vec;
146
148 if(!rois.isValid()) {
149 ATH_MSG_WARNING("Failed to retrieve the L1_eTauRoi container");
150 return roi_vec;
151 }
152
154 for(const xAOD::eFexTauRoI* roi : *rois) {
155 // Select by RoI ET value only
156 if(roi->et() > m_L1_Phase1_thresholds.value().at(l1_item)) roi_vec.push_back(roi);
157 }
158 } else {
160 if(!thresholdPatterns.isValid()) {
161 ATH_MSG_WARNING("Failed to create thresholdPatterns property accessor for the L1_eTauRoi container");
162 return roi_vec;
163 }
164
165 for(const xAOD::eFexTauRoI* roi : *rois) {
166 // Check that the RoI passed the threshold selection
167 if(thresholdPatterns(*roi) & m_L1_Phase1_threshold_patterns.value().at(l1_item)) roi_vec.push_back(roi);
168 }
169 }
170
171 return roi_vec;
172}
173
174
175std::vector<std::pair<const xAOD::eFexTauRoI*, const xAOD::jFexTauRoI*>> TrigTauMonitorBaseAlgorithm::getL1cTAUs(const EventContext& ctx, const std::string& l1_item) const
176{
177 std::vector<std::pair<const xAOD::eFexTauRoI*, const xAOD::jFexTauRoI*>> roi_vec;
178
180 if(!rois.isValid()) {
181 ATH_MSG_WARNING("Failed to retrieve the L1_cTauRoi container");
182 return roi_vec;
183 }
185 if(!jTau_roi_link.isValid()) {
186 ATH_MSG_WARNING("Failed to create jTauLink accessor for the L1_cTauRoi container");
187 return roi_vec;
188 }
189
191 for(size_t i = 0; i < rois->size(); i++) {
192 const xAOD::eFexTauRoI* roi = (*rois)[i];
193 const xAOD::jFexTauRoI* jTau_roi = jTau_roi_link(i).isValid() ? *jTau_roi_link(i) : nullptr;
194
195 // Select by RoI ET value only
196 if(roi->et() > m_L1_Phase1_thresholds.value().at(l1_item)) roi_vec.push_back(std::make_pair(roi, jTau_roi));
197 }
198 } else {
200 if(!thresholdPatterns.isValid()) {
201 ATH_MSG_WARNING("Failed to create thresholdPatterns property accessor for the L1_cTauRoi container");
202 return roi_vec;
203 }
204
205 for(size_t i = 0; i < rois->size(); i++) {
206 const xAOD::eFexTauRoI* roi = (*rois)[i];
207 const xAOD::jFexTauRoI* jTau_roi = jTau_roi_link(i).isValid() ? *jTau_roi_link(i) : nullptr;
208
209 // Check that the RoI passed the threshold selection
210 if(thresholdPatterns(*roi) & m_L1_Phase1_threshold_patterns.value().at(l1_item)) roi_vec.push_back(std::make_pair(roi, jTau_roi));
211 }
212 }
213
214
215 return roi_vec;
216}
217
218
220{
221 if(m_hltTauJetKeysMap.find(container_suffix) != m_hltTauJetKeysMap.end()) return m_hltTauJetKeysMap.at(container_suffix);
222 else {
223 if(m_hltTauJetKeysMap.find("MVA") != m_hltTauJetKeysMap.end()) {
224 ATH_MSG_ERROR("HLT TauJet container not registered for suffix \"" << container_suffix << "\". Returning the default \"" << m_hltTauJetKeysMap.at("MVA").key() << "\"");
225 return m_hltTauJetKeysMap.at("MVA");
226 } else {
227 ATH_MSG_ERROR("HLT TauJet container not registered for suffix \"" << container_suffix << "\". Returning the first available container \"" << m_hltTauJetKeysMap.begin()->second.key() << "\"");
228 return m_hltTauJetKeysMap.begin()->second;
229 }
230 }
231}
232
233
234StatusCode TrigTauMonitorBaseAlgorithm::fillHistograms(const EventContext& ctx) const
235{
236 ATH_MSG_DEBUG("Executing Monitoring algorithm");
237
238 // Protect against truncated events
239 // Since this happens very rarely, it won't bias the L1 distributions and efficiencies
240 if(m_trigDecTool->ExperimentalAndExpertMethods().isHLTTruncated()){
241 ATH_MSG_WARNING("HLTResult truncated, skip trigger analysis");
242 return StatusCode::SUCCESS;
243 }
244
245 // Protect against LAr noise bursts and other detector errors
247 ATH_CHECK(eventInfo.isValid());
248 if (eventInfo->errorState(xAOD::EventInfo::LAr) == xAOD::EventInfo::Error
249 || eventInfo->errorState(xAOD::EventInfo::Tile) == xAOD::EventInfo::Error
250 || eventInfo->errorState(xAOD::EventInfo::SCT) == xAOD::EventInfo::Error
251 || eventInfo->isEventFlagBitSet(xAOD::EventInfo::Core, 18)) {
252 return StatusCode::SUCCESS;
253 }
254
256
257 return StatusCode::SUCCESS;
258}
259
260
261std::vector<const xAOD::TauJet*> TrigTauMonitorBaseAlgorithm::classifyTausAll(const EventContext& ctx, const std::vector<const xAOD::TauJet*>& taus, const float threshold, const TauID tau_id) const
262{
263 std::vector<const xAOD::TauJet*> tau_vec;
264
265 // Protection since GNTau is not run for taus below 13 GeV
266 float upd_threshold = threshold;
267 if(tau_id == TauID::GNTau){
268 if( upd_threshold < 13){
269 upd_threshold = 13;
270 }
271 }
272
274 if(!tauid_medium.isValid()) {
275 ATH_MSG_WARNING("Cannot retrieve " << tauid_medium.key());
276 return tau_vec;
277 }
278
279 for(const xAOD::TauJet* tau : taus) {
280 if(tau->pt() < upd_threshold*Gaudi::Units::GeV) continue;
281
282 // Consider only offline taus which pass medium ID WP
283 if(tau_id == TauID::RNN) {
284 if(!tau->isTau(xAOD::TauJetParameters::JetRNNSigMedium)) continue;
285 }
286 else if(tau_id == TauID::GNTau) {
287 if(!tauid_medium(*tau)) continue;
288 }
289
290 tau_vec.push_back(tau);
291 }
292
293 return tau_vec;
294}
295
296
297std::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
298{
299 std::vector<const xAOD::TauJet*> tau_vec_0p, tau_vec_1p, tau_vec_mp;
300
301 for(const xAOD::TauJet* tau : classifyTausAll(ctx, taus, threshold, TauID::None)) {
302 int nTracks = -1;
303 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
304
305 if(nTracks == 0) tau_vec_0p.push_back(tau);
306 else if(nTracks == 1) tau_vec_1p.push_back(tau);
307 else tau_vec_mp.push_back(tau);
308 }
309
310 return {tau_vec_0p, tau_vec_1p, tau_vec_mp};
311}
312
313
314std::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
315{
316 std::vector<const xAOD::TauJet*> tau_vec_1p, tau_vec_3p;
317
318 for(const xAOD::TauJet* const tau : classifyTausAll(ctx, taus, threshold, tau_id)) {
319 int nTracks = -1;
320 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
321
322 if(nTracks == 1) tau_vec_1p.push_back(tau);
323 else if(nTracks == 3) tau_vec_3p.push_back(tau);
324 }
325
326 return {tau_vec_1p, tau_vec_3p};
327}
#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::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
std::unordered_map< std::string, SG::ReadHandleKey< xAOD::TauJetContainer >, CxxUtils::TransparentStringHash, std::equal_to<> > m_hltTauJetKeysMap
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::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".
Definition TauJet.h:17
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