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
6
8
11
12TrigTauMonitorBaseAlgorithm::TrigTauMonitorBaseAlgorithm(const std::string& name, ISvcLocator* pSvcLocator)
13 : AthMonitorAlgorithm(name, pSvcLocator)
14{}
15
16
19 ATH_CHECK( m_trigDecTool.retrieve() );
20 ATH_CHECK( m_eventInfoDecorKey.initialize() );
21
22 ATH_CHECK( m_offlineTauJetKey.initialize() );
24 ATH_CHECK( m_offlineGNTauDecorKey.initialize() );
25
26 if(m_L1_select_by_et_only) ATH_MSG_INFO("L1 RoI selection by Et cut only! No isolated L1 tau items are allowed!");
27 ATH_CHECK( m_phase1l1eTauRoIKey.initialize() );
29 ATH_CHECK( m_phase1l1jTauRoIKey.initialize() );
31 ATH_CHECK( m_phase1l1cTauRoIKey.initialize() );
34
35 // Parse TauTrigInfo objects
36 for(const std::string& trigger : m_triggers) {
39
40 if(m_trigInfo[trigger].areAnyL1TauIsolated()) {
41 ATH_MSG_FATAL("Cannot use isolated L1 tau items if running with SelectL1ByETOnly = True: " << trigger);
42 return StatusCode::FAILURE;
43 }
44 } else {
46 }
47 }
48
49 for(const TrigTauInfo& info : getTrigInfoMap() | std::views::values) {
50 // First check if we already have the container key for this tau leg suffix
51 const std::string sfx = info.getHLTTauLegContainerSfx();
52 if(m_hltTauJetKeysMap.find(sfx) != m_hltTauJetKeysMap.end()) continue;
53
54 // Add and initialize the container key
55 m_hltTauJetKeysMap[sfx] = SG::ReadHandleKey<xAOD::TauJetContainer>("HLT_TrigTauRecMerged_" + sfx);
56 ATH_CHECK( m_hltTauJetKeysMap.at(sfx).initialize() );
57 }
58
59 return StatusCode::SUCCESS;
60}
61
62
63std::vector<const xAOD::TauJet*> TrigTauMonitorBaseAlgorithm::getOnlineTausAll(const std::string& trigger, bool include_0P, bool filter_legs) const
64{
65 std::vector<const xAOD::TauJet*> tau_vec;
66
67 const TrigTauInfo& info = getTrigInfo(trigger);
68
69 std::vector<int> leg_indices = {-1};
70 if(filter_legs) leg_indices = info.getHLTTauLegIndices();
71 for(size_t i = 0; i < leg_indices.size(); ++i) {
72 const int leg = leg_indices[i];
73 const std::string tau_container_name = getOnlineContainerKey(info.getHLTTauLegContainerSfxs().at(leg == -1 ? 0 : i)).key();
74 ATH_MSG_DEBUG("Tau container name is: " << tau_container_name);
75
77 for(auto& featLinkInfo : vec) {
78 const xAOD::TauJet* feat = *(featLinkInfo.link);
79 if(!feat) continue;
80
81 int nTracks = -1;
83 ATH_MSG_DEBUG("NTracks Online: " << nTracks);
84
85 if(include_0P && nTracks == 0) tau_vec.push_back(feat);
86 else tau_vec.push_back(feat);
87 }
88 }
89
90 return tau_vec;
91}
92
93
94std::tuple<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::getOnlineTaus(const std::string& trigger) const
95{
96 return classifyOnlineTaus(getOnlineTausAll(trigger, true), 0.0);
97}
98
99
100std::vector<const xAOD::TauJet*> TrigTauMonitorBaseAlgorithm::getOfflineTausAll(const EventContext& ctx, const float threshold) const
101{
102 ATH_MSG_DEBUG("Retrieving offline Taus");
103
104 std::vector<const xAOD::TauJet*> tau_vec;
105
107 if(!taus.isValid()) {
108 ATH_MSG_WARNING("Failed to retrieve offline Taus");
109 return tau_vec;
110 }
111
112 for(const xAOD::TauJet* const tau : *taus) {
113 // Consider only offline taus with a certain minimum pT
114 if(tau->pt() < threshold*Gaudi::Units::GeV) continue;
115
116 // Consider only offline taus outside of the crack region
117 if(std::abs(tau->eta()) > 1.37 && std::abs(tau->eta()) < 1.52) continue;
118
119 // Consider only offline taus which pass RNN medium WP
120 if(!tau->isTau(xAOD::TauJetParameters::JetRNNSigMedium)) continue;
121
122 // Consider only offline taus which pass thinning
123 static const SG::ConstAccessor<char> passThinningAcc("passThinning");
124 if(!passThinningAcc.withDefault(*tau, true)) continue;
125
126 int nTracks = -1;
127 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
128 ATH_MSG_DEBUG("NTracks Offline: " << nTracks);
129 if(nTracks == 1 || nTracks == 3) tau_vec.push_back(tau);
130 }
131
132 return tau_vec;
133}
134
135
136std::pair<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::getOfflineTaus(const EventContext& ctx, const float threshold, const TauID tau_id) const
137{
139}
140
141
142std::vector<const xAOD::eFexTauRoI*> TrigTauMonitorBaseAlgorithm::getL1eTAUs(const EventContext& ctx, const std::string& l1_item) const
143{
144 std::vector<const xAOD::eFexTauRoI*> roi_vec;
145
147 if(!rois.isValid()) {
148 ATH_MSG_WARNING("Failed to retrieve the L1_eTauRoi container");
149 return roi_vec;
150 }
151
153 for(const xAOD::eFexTauRoI* roi : *rois) {
154 // Select by RoI ET value only
155 if(roi->et() > m_L1_Phase1_thresholds.value().at(l1_item)) roi_vec.push_back(roi);
156 }
157 } else {
159 if(!thresholdPatterns.isValid()) {
160 ATH_MSG_WARNING("Failed to create thresholdPatterns property accessor for the L1_eTauRoi container");
161 return roi_vec;
162 }
163
164 for(const xAOD::eFexTauRoI* roi : *rois) {
165 // Check that the RoI passed the threshold selection
166 if(thresholdPatterns(*roi) & m_L1_Phase1_threshold_patterns.value().at(l1_item)) roi_vec.push_back(roi);
167 }
168 }
169
170 return roi_vec;
171}
172
173
174std::vector<const xAOD::jFexTauRoI*> TrigTauMonitorBaseAlgorithm::getL1jTAUs(const EventContext& ctx, const std::string& l1_item) const
175{
176 std::vector<const xAOD::jFexTauRoI*> roi_vec;
177
179 if(!rois.isValid()) {
180 ATH_MSG_WARNING("Failed to retrieve the L1_jTauRoi container");
181 return roi_vec;
182 }
183
185 for(const xAOD::jFexTauRoI* roi : *rois) {
186 // Select by RoI ET value only
187 if(roi->et() > m_L1_Phase1_thresholds.value().at(l1_item)) roi_vec.push_back(roi);
188 }
189 } else {
191 if(!thresholdPatterns.isValid()) {
192 ATH_MSG_WARNING("Failed to create thresholdPatterns property accessor for the L1_jTauRoi container");
193 return roi_vec;
194 }
195
196 for(const xAOD::jFexTauRoI* roi : *rois) {
197 // Check that the RoI passed the threshold selection
198 if(thresholdPatterns(*roi) & m_L1_Phase1_threshold_patterns.value().at(l1_item)) roi_vec.push_back(roi);
199 }
200 }
201
202 return roi_vec;
203}
204
205
206std::vector<std::pair<const xAOD::eFexTauRoI*, const xAOD::jFexTauRoI*>> TrigTauMonitorBaseAlgorithm::getL1cTAUs(const EventContext& ctx, const std::string& l1_item) const
207{
208 std::vector<std::pair<const xAOD::eFexTauRoI*, const xAOD::jFexTauRoI*>> roi_vec;
209
211 if(!rois.isValid()) {
212 ATH_MSG_WARNING("Failed to retrieve the L1_cTauRoi container");
213 return roi_vec;
214 }
216 if(!jTau_roi_link.isValid()) {
217 ATH_MSG_WARNING("Failed to create jTauLink accessor for the L1_cTauRoi container");
218 return roi_vec;
219 }
220
222 for(size_t i = 0; i < rois->size(); i++) {
223 const xAOD::eFexTauRoI* roi = (*rois)[i];
224 const xAOD::jFexTauRoI* jTau_roi = jTau_roi_link(i).isValid() ? *jTau_roi_link(i) : nullptr;
225
226 // Select by RoI ET value only
227 if(roi->et() > m_L1_Phase1_thresholds.value().at(l1_item)) roi_vec.push_back(std::make_pair(roi, jTau_roi));
228 }
229 } else {
231 if(!thresholdPatterns.isValid()) {
232 ATH_MSG_WARNING("Failed to create thresholdPatterns property accessor for the L1_cTauRoi container");
233 return roi_vec;
234 }
235
236 for(size_t i = 0; i < rois->size(); i++) {
237 const xAOD::eFexTauRoI* roi = (*rois)[i];
238 const xAOD::jFexTauRoI* jTau_roi = jTau_roi_link(i).isValid() ? *jTau_roi_link(i) : nullptr;
239
240 // Check that the RoI passed the threshold selection
241 if(thresholdPatterns(*roi) & m_L1_Phase1_threshold_patterns.value().at(l1_item)) roi_vec.push_back(std::make_pair(roi, jTau_roi));
242 }
243 }
244
245
246 return roi_vec;
247}
248
249
251{
252 if(m_hltTauJetKeysMap.find(container_suffix) != m_hltTauJetKeysMap.end()) return m_hltTauJetKeysMap.at(container_suffix);
253 else {
254 if(m_hltTauJetKeysMap.find("MVA") != m_hltTauJetKeysMap.end()) {
255 ATH_MSG_ERROR("HLT TauJet container not registered for suffix \"" << container_suffix << "\". Returning the default \"" << m_hltTauJetKeysMap.at("MVA").key() << "\"");
256 return m_hltTauJetKeysMap.at("MVA");
257 } else {
258 ATH_MSG_ERROR("HLT TauJet container not registered for suffix \"" << container_suffix << "\". Returning the first available container \"" << m_hltTauJetKeysMap.begin()->second.key() << "\"");
259 return m_hltTauJetKeysMap.begin()->second;
260 }
261 }
262}
263
264
265StatusCode TrigTauMonitorBaseAlgorithm::fillHistograms(const EventContext& ctx) const
266{
267 ATH_MSG_DEBUG("Executing Monitoring algorithm");
268
269 // Protect against truncated events
270 // Since this happens very rarely, it won't bias the L1 distributions and efficiencies
271 if(m_trigDecTool->ExperimentalAndExpertMethods().isHLTTruncated()){
272 ATH_MSG_WARNING("HLTResult truncated, skip trigger analysis");
273 return StatusCode::SUCCESS;
274 }
275
276 // Protect against LAr noise bursts and other detector errors
278 ATH_CHECK(eventInfo.isValid());
279 if (eventInfo->errorState(xAOD::EventInfo::LAr) == xAOD::EventInfo::Error
280 || eventInfo->errorState(xAOD::EventInfo::Tile) == xAOD::EventInfo::Error
281 || eventInfo->errorState(xAOD::EventInfo::SCT) == xAOD::EventInfo::Error
282 || eventInfo->isEventFlagBitSet(xAOD::EventInfo::Core, 18)) {
283 return StatusCode::SUCCESS;
284 }
285
287
288 return StatusCode::SUCCESS;
289}
290
291
292std::vector<const xAOD::TauJet*> TrigTauMonitorBaseAlgorithm::classifyTausAll(const std::vector<const xAOD::TauJet*>& taus, const float threshold, const TauID tau_id) const
293{
294 std::vector<const xAOD::TauJet*> tau_vec;
295
296 SG::ReadDecorHandle<xAOD::TauJetContainer, char> tauid_medium{m_offlineGNTauDecorKey, Gaudi::Hive::currentContext()};
297 if(!tauid_medium.isValid()) {
298 ATH_MSG_WARNING("Cannot retrieve " << tauid_medium.key());
299 return tau_vec;
300 }
301
302 for(const xAOD::TauJet* tau : taus) {
303 if(tau->pt() < threshold*Gaudi::Units::GeV) continue;
304
305 // Consider only offline taus which pass medium ID WP
306 if(tau_id == TauID::RNN) {
307 if(!tau->isTau(xAOD::TauJetParameters::JetRNNSigMedium)) continue;
308 }
309 else if(tau_id == TauID::GNTau) {
310 if(!tauid_medium(*tau)) continue;
311 }
312
313 tau_vec.push_back(tau);
314 }
315
316 return tau_vec;
317}
318
319
320std::tuple<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::classifyOnlineTaus(const std::vector<const xAOD::TauJet*>& taus, const float threshold) const
321{
322 std::vector<const xAOD::TauJet*> tau_vec_0p, tau_vec_1p, tau_vec_mp;
323
325 int nTracks = -1;
326 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
327
328 if(nTracks == 0) tau_vec_0p.push_back(tau);
329 else if(nTracks == 1) tau_vec_1p.push_back(tau);
330 else tau_vec_mp.push_back(tau);
331 }
332
333 return {tau_vec_0p, tau_vec_1p, tau_vec_mp};
334}
335
336
337std::pair<std::vector<const xAOD::TauJet*>, std::vector<const xAOD::TauJet*>> TrigTauMonitorBaseAlgorithm::classifyOfflineTaus(const std::vector<const xAOD::TauJet*>& taus, const float threshold, const TauID tau_id) const
338{
339 std::vector<const xAOD::TauJet*> tau_vec_1p, tau_vec_3p;
340
341 for(const xAOD::TauJet* const tau : classifyTausAll(taus, threshold, tau_id)) {
342 int nTracks = -1;
343 tau->detail(xAOD::TauJetParameters::nChargedTracks, nTracks);
344
345 if(nTracks == 1) tau_vec_1p.push_back(tau);
346 else if(nTracks == 3) tau_vec_3p.push_back(tau);
347 }
348
349 return {tau_vec_1p, tau_vec_3p};
350}
#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
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
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
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::vector< const xAOD::jFexTauRoI * > getL1jTAUs(const EventContext &ctx, const std::string &l1_item) 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
std::vector< const xAOD::TauJet * > classifyTausAll(const std::vector< const xAOD::TauJet * > &taus, const float threshold=0.0, const TauID tau_id=TauID::None) const
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_phase1l1cTauRoIKey
std::tuple< std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * > > getOnlineTaus(const std::string &trigger) const
std::pair< std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * > > classifyOfflineTaus(const std::vector< const xAOD::TauJet * > &taus, const float threshold=0.0, const TauID tau_id=TauID::None) const
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
std::tuple< std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * >, std::vector< const xAOD::TauJet * > > classifyOnlineTaus(const std::vector< const xAOD::TauJet * > &taus, const float threshold=0.0) const
@ 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