ATLAS Offline Software
TriggerSelectionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // includes
6 #include "TriggerSelectionAlg.h"
7 
8 // Tool includes
11 
12 
13 TriggerSelectionAlg::TriggerSelectionAlg( const std::string& name, ISvcLocator* pSvcLocator ):
14  AthFilterAlgorithm( name, pSvcLocator )
15 {
16 }
17 
18 
20 
21 
23 {
24  ATH_MSG_DEBUG ("Initializing " << name() << "...");
25 
26  // Print the configuration to the log file
27  ATH_MSG_DEBUG( "Using: " << m_trigDecisionTool );
28  ATH_MSG_DEBUG( "Using: " << m_triggerList );
29  ATH_MSG_DEBUG( "Using: " << m_decoEvtInfo );
30  ATH_MSG_DEBUG( "Using: " << m_evtInfoName );
31  ATH_MSG_DEBUG( "Using: " << m_varPrefix );
32  ATH_MSG_DEBUG( "Using: " << m_storePrescaleInfo );
33 
34  // Retrieve the TrigDecisionTool
35  ATH_CHECK(m_trigDecisionTool.retrieve());
36 
37  // Create the list of decoration variables
38  for ( const std::string& trigName : m_triggerList.value() ){
39  m_varNameList.push_back( m_varPrefix.value() + trigName );
40  }
41 
42  return StatusCode::SUCCESS;
43 }
44 
45 
47 {
48  ATH_MSG_DEBUG("Finalizing " << name() << "...");
49 
50  // Release all tools
51  ATH_CHECK( m_trigDecisionTool.release() );
52 
53  return StatusCode::SUCCESS;
54 }
55 
56 
58 {
59  ATH_MSG_DEBUG("Executing " << name() << "...");
60 
61  // Get the xAOD::EventInfo object, if requested
62  const xAOD::EventInfo* evtInfo = nullptr;
63  if ( m_decoEvtInfo.value() ){
64  ATH_CHECK( evtStore()->retrieve( evtInfo, m_evtInfoName.value() ) );
65  }
66 
67  // Create a results Vector
68  std::vector<bool> trigResultsVec( m_triggerList.value().size(), false );
69  std::vector<float> trigPrescalesVec( m_triggerList.value().size(), 0. );
70 
71  //Check if event passes trigger selection
72  bool eventPasses = false;
73  if( !(m_triggerList.value().empty()) ) {
74  for( std::size_t i=0; i<m_triggerList.value().size(); ++i ) {
75  if( m_trigDecisionTool->isPassed(m_triggerList.value().at(i)) ) {
76  trigResultsVec[i] = true;
77  eventPasses = true;
78  ATH_MSG_VERBOSE("Name of passed trigger: " << m_triggerList.value().at(i));
79  if ( !(m_decoEvtInfo.value()) ){
80  break; // Found a trigger which we passed, nothing more to do here
81  }
82  }
83  //We sometimes want to keep track of the chain prescale
84  if (m_storePrescaleInfo) {
85  trigPrescalesVec[i] = m_trigDecisionTool->getPrescale(m_triggerList.value().at(i));
86  ATH_MSG_VERBOSE("Retrieved prescale of " << trigPrescalesVec[i] << " for trigger: " << m_triggerList.value().at(i));
87  }
88  }
89  }
90 
91  // Decorate the EventInfo, if requested
92  if ( m_decoEvtInfo.value() ){
93  const size_t decoSize = trigResultsVec.size();
94  if ( decoSize != m_varNameList.size() ){
95  ATH_MSG_FATAL("Different number of trigger results and variable names");
96  return StatusCode::FAILURE;
97  }
98  // We also want to decorate the xAOD::EventInfo object with the results
99  for( std::size_t i=0; i<decoSize; ++i ) {
101  decoPassTrig(*evtInfo) = static_cast<char>(trigResultsVec[i]);
102  //We sometimes want to keep track of the chain prescale
103  if (m_storePrescaleInfo) {
104  SG::AuxElement::Decorator<float> decoPrescaleTrig("prescale_"+m_triggerList.value().at(i));
105  decoPrescaleTrig(*evtInfo) = static_cast<float>(trigPrescalesVec[i]);
106  }
107  }
108  }
109 
110  // Say if this event should be accepted or not
111  this->setFilterPassed( eventPasses );
112  ATH_MSG_DEBUG("Event passes trigger selection: " << eventPasses );
113 
114  return StatusCode::SUCCESS;
115 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AthFilterAlgorithm::setFilterPassed
virtual void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
Definition: AthFilterAlgorithm.cxx:99
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TriggerSelectionAlg::initialize
virtual StatusCode initialize() override
Athena algorithm's initalize hook.
Definition: TriggerSelectionAlg.cxx:22
TriggerSelectionAlg::TriggerSelectionAlg
TriggerSelectionAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: TriggerSelectionAlg.cxx:13
TriggerSelectionAlg::execute
virtual StatusCode execute() override
Athena algorithm's execute hook.
Definition: TriggerSelectionAlg.cxx:57
TrigDecisionTool.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TriggerSelectionAlg::finalize
virtual StatusCode finalize() override
Athena algorithm's finalize hook.
Definition: TriggerSelectionAlg.cxx:46
TriggerSelectionAlg::m_varPrefix
StringProperty m_varPrefix
Prefix used for the decoration variables.
Definition: TriggerSelectionAlg.h:70
TriggerSelectionAlg::m_varNameList
std::vector< std::string > m_varNameList
The list of all variables names.
Definition: TriggerSelectionAlg.h:83
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
AthFilterAlgorithm
Definition: AthFilterAlgorithm.h:26
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TriggerSelectionAlg::m_triggerList
StringArrayProperty m_triggerList
The list of triggers to cut on.
Definition: TriggerSelectionAlg.h:58
TriggerSelectionAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TriggerSelectionAlg::m_evtInfoName
StringProperty m_evtInfoName
Name of the xAOD::EventInfo object that we want to decorate.
Definition: TriggerSelectionAlg.h:66
TriggerSelectionAlg::m_decoEvtInfo
BooleanProperty m_decoEvtInfo
Decide if we also want to decorate the xAOD::EventInfo object with the pass/fail information.
Definition: TriggerSelectionAlg.h:62
TriggerSelectionAlg::~TriggerSelectionAlg
virtual ~TriggerSelectionAlg()
Destructor:
Definition: TriggerSelectionAlg.cxx:19
TriggerSelectionAlg::m_trigDecisionTool
ToolHandle< Trig::TrigDecisionTool > m_trigDecisionTool
The ToolHandle for the TrigDecisionTool.
Definition: TriggerSelectionAlg.h:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
TriggerSelectionAlg::m_storePrescaleInfo
BooleanProperty m_storePrescaleInfo
Decide if we also want to decorate the xAOD::EventInfo object with the (full-chain) prescale informat...
Definition: TriggerSelectionAlg.h:74