ATLAS Offline Software
TRTOccupancyInclude.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /* *******************************************************************
6 
7  TRTOccupancyInclude.cxx : Simple code to include Occupancy inside event info xAOD
8 
9 * ***************************************************************** */
10 
13 
14 #include "StoreGate/ReadHandle.h"
16 
17 TRTOccupancyInclude::TRTOccupancyInclude(const std::string& name, ISvcLocator* pSvcLocator) :
18  AthAlgorithm (name, pSvcLocator),
19  m_LocalOccTool()
20 {
21  declareProperty("TRT_LocalOccupancyTool", m_LocalOccTool);
22 }
23 
24 //---------------------------------------------------------------------
25 
27 {}
28 
29 //--------------------------------------------------------------------------
30 
32 {
33  if ( m_LocalOccTool.retrieve().isFailure() ){
34  ATH_MSG_ERROR(" Failed to retrieve TRT Local Occupancy tool: " << m_LocalOccTool );
35  return StatusCode::FAILURE;
36  }
37  else {
38  ATH_MSG_INFO("Retrieved tool " << m_LocalOccTool);
39  }
40 
42 
43  return StatusCode::SUCCESS;
44 }
45 
46 //---------------------------------------------------------------------
47 
49 {
50  msg(MSG::DEBUG) << "execute()" << endmsg;
51 
52  const EventContext& ctx = Gaudi::Hive::currentContext();
53 
55  if (not evtInfo.isValid()) {
56  ATH_MSG_WARNING(" Cannot access to event info.");
57  return StatusCode::SUCCESS;
58  }
59 
60  const xAOD::EventInfo* eventInfo = evtInfo.cptr();
61 
62  std::vector<float> TRTOccu = m_LocalOccTool->GlobalOccupancy(ctx);
63  if (TRTOccu.size() > 6) {
64 
65  static const SG::AuxElement::Decorator< float > decEventInfo_occupancy0("TRTOccGlobal");
66  decEventInfo_occupancy0( *eventInfo ) = TRTOccu.at(0);
67 
68  static const SG::AuxElement::Decorator< float > decEventInfo_occupancy1("TRTOccBarrelC");
69  decEventInfo_occupancy1( *eventInfo ) = TRTOccu.at(1);
70 
71  static const SG::AuxElement::Decorator< float > decEventInfo_occupancy2("TRTOccEndcapAC");
72  decEventInfo_occupancy2( *eventInfo ) = TRTOccu.at(2);
73 
74  static const SG::AuxElement::Decorator< float > decEventInfo_occupancy3("TRTOccEndcapBC");
75  decEventInfo_occupancy3( *eventInfo ) = TRTOccu.at(3);
76 
77  static const SG::AuxElement::Decorator< float > decEventInfo_occupancy4("TRTOccBarrelA");
78  decEventInfo_occupancy4( *eventInfo ) = TRTOccu.at(4);
79 
80  static const SG::AuxElement::Decorator< float > decEventInfo_occupancy5("TRTOccEndcapAA");
81  decEventInfo_occupancy5( *eventInfo ) = TRTOccu.at(5);
82 
83  static const SG::AuxElement::Decorator< float > decEventInfo_occupancy6("TRTOccEndcapBA");
84  decEventInfo_occupancy6( *eventInfo ) = TRTOccu.at(6);
85  }
86 
87  return StatusCode::SUCCESS;
88 }
89 
90 //---------------------------------------------------------------------
91 
93 {
94  msg(MSG::INFO) << "finalise()" << endmsg;
95  return StatusCode::SUCCESS;
96 }
TRTOccupancyInclude::TRTOccupancyInclude
TRTOccupancyInclude(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRTOccupancyInclude.cxx:17
TRTOccupancyInclude::m_LocalOccTool
ToolHandle< InDet::ITRT_LocalOccupancy > m_LocalOccTool
the track selector tool
Definition: TRTOccupancyInclude.h:50
TRTOccupancyInclude::finalize
StatusCode finalize(void)
Definition: TRTOccupancyInclude.cxx:92
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TRTOccupancyInclude.h
TRTOccupancyInclude::~TRTOccupancyInclude
~TRTOccupancyInclude(void)
Definition: TRTOccupancyInclude.cxx:26
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TRTOccupancyInclude::execute
StatusCode execute(void)
Definition: TRTOccupancyInclude.cxx:48
TRTOccupancyInclude::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: TRTOccupancyInclude.h:51
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ReadHandle.h
Handle class for reading from StoreGate.
checker_macros.h
Define macros for attributes used to control the static checker.
TRTOccupancyInclude::initialize
StatusCode initialize(void)
Definition: TRTOccupancyInclude.cxx:31