ATLAS Offline Software
TriggerSelectionAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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  m_trigDecisionTool("Trig::TrigDecisionTool/TrigDecisionTool"),
16  m_triggerList(),
17  m_decoEvtInfo(true),
18  m_evtInfoName("EventInfo"),
19  m_varPrefix("pass_"),
20  m_storePrescaleInfo(false),
21  m_varNameList()
22 {
23  declareProperty("TrigDecisionTool", m_trigDecisionTool, "The TrigDecisionTool" );
24  declareProperty("TriggerList", m_triggerList, "The list of triggers to cut on" );
25  declareProperty("DecorateEventInfo", m_decoEvtInfo,
26  "Decide if we also want to decorate the xAOD::EventInfo object with the pass/fail information" );
27  declareProperty("EventInfoName", m_evtInfoName, "Name of the xAOD::EventInfo object that we want to decorate" );
28  declareProperty("VarNamePrefix", m_varPrefix, "Prefix used for the decoration variables" );
29  declareProperty("StorePrescaleInfo", m_storePrescaleInfo,
30  "Decide if we also want to decorate the xAOD::EventInfo object with the full-chain prescale information" );
31 }
32 
33 
35 
36 
38 {
39  ATH_MSG_DEBUG ("Initializing " << name() << "...");
40 
41  // Print the configuration to the log file
42  ATH_MSG_DEBUG( "Using: " << m_trigDecisionTool );
43  ATH_MSG_DEBUG( "Using: " << m_triggerList );
44  ATH_MSG_DEBUG( "Using: " << m_decoEvtInfo );
45  ATH_MSG_DEBUG( "Using: " << m_evtInfoName );
46  ATH_MSG_DEBUG( "Using: " << m_varPrefix );
47  ATH_MSG_DEBUG( "Using: " << m_storePrescaleInfo );
48 
49  // Retrieve the TrigDecisionTool
50  ATH_CHECK(m_trigDecisionTool.retrieve());
51 
52  // Create the list of decoration variables
53  for ( const std::string& trigName : m_triggerList.value() ){
54  m_varNameList.push_back( m_varPrefix.value() + trigName );
55  }
56 
57  return StatusCode::SUCCESS;
58 }
59 
60 
62 {
63  ATH_MSG_DEBUG("Finalizing " << name() << "...");
64 
65  // Release all tools
66  ATH_CHECK( m_trigDecisionTool.release() );
67 
68  return StatusCode::SUCCESS;
69 }
70 
71 
73 {
74  ATH_MSG_DEBUG("Executing " << name() << "...");
75 
76  // Get the xAOD::EventInfo object, if requested
77  const xAOD::EventInfo* evtInfo = nullptr;
78  if ( m_decoEvtInfo.value() ){
79  ATH_CHECK( evtStore()->retrieve( evtInfo, m_evtInfoName.value() ) );
80  }
81 
82  // Create a results Vector
83  std::vector<bool> trigResultsVec( m_triggerList.value().size(), false );
84  std::vector<float> trigPrescalesVec( m_triggerList.value().size(), 0. );
85 
86  //Check if event passes trigger selection
87  bool eventPasses = false;
88  if( !(m_triggerList.value().empty()) ) {
89  for( std::size_t i=0; i<m_triggerList.value().size(); ++i ) {
90  if( m_trigDecisionTool->isPassed(m_triggerList.value().at(i)) ) {
91  trigResultsVec[i] = true;
92  eventPasses = true;
93  ATH_MSG_VERBOSE("Name of passed trigger: " << m_triggerList.value().at(i));
94  if ( !(m_decoEvtInfo.value()) ){
95  break; // Found a trigger which we passed, nothing more to do here
96  }
97  }
98  //We sometimes want to keep track of the chain prescale
99  if (m_storePrescaleInfo) {
100  trigPrescalesVec[i] = m_trigDecisionTool->getPrescale(m_triggerList.value().at(i));
101  ATH_MSG_VERBOSE("Retrieved prescale of " << trigPrescalesVec[i] << " for trigger: " << m_triggerList.value().at(i));
102  }
103  }
104  }
105 
106  // Decorate the EventInfo, if requested
107  if ( m_decoEvtInfo.value() ){
108  const size_t decoSize = trigResultsVec.size();
109  if ( decoSize != m_varNameList.size() ){
110  ATH_MSG_FATAL("Different number of trigger results and variable names");
111  return StatusCode::FAILURE;
112  }
113  // We also want to decorate the xAOD::EventInfo object with the results
114  for( std::size_t i=0; i<decoSize; ++i ) {
116  decoPassTrig(*evtInfo) = static_cast<char>(trigResultsVec[i]);
117  //We sometimes want to keep track of the chain prescale
118  if (m_storePrescaleInfo) {
119  SG::AuxElement::Decorator<float> decoPrescaleTrig("prescale_"+m_triggerList.value().at(i));
120  decoPrescaleTrig(*evtInfo) = static_cast<float>(trigPrescalesVec[i]);
121  }
122  }
123  }
124 
125  // Say if this event should be accepted or not
126  this->setFilterPassed( eventPasses );
127  ATH_MSG_DEBUG("Event passes trigger selection: " << eventPasses );
128 
129  return StatusCode::SUCCESS;
130 }
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::TriggerSelectionAlg
TriggerSelectionAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: TriggerSelectionAlg.cxx:13
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TrigDecisionTool.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TriggerSelectionAlg::m_varPrefix
StringProperty m_varPrefix
Prefix used for the decoration variables.
Definition: TriggerSelectionAlg.h:66
TriggerSelectionAlg::m_varNameList
std::vector< std::string > m_varNameList
The list of all variables names.
Definition: TriggerSelectionAlg.h:77
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:58
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:57
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:63
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:60
TriggerSelectionAlg::~TriggerSelectionAlg
virtual ~TriggerSelectionAlg()
Destructor:
Definition: TriggerSelectionAlg.cxx:34
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:195
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
TriggerSelectionAlg::finalize
virtual StatusCode finalize()
Athena algorithm's finalize hook.
Definition: TriggerSelectionAlg.cxx:61
TriggerSelectionAlg::execute
virtual StatusCode execute()
Athena algorithm's execute hook.
Definition: TriggerSelectionAlg.cxx:72
TriggerSelectionAlg::initialize
virtual StatusCode initialize()
Athena algorithm's initalize hook.
Definition: TriggerSelectionAlg.cxx:37
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:69