ATLAS Offline Software
Loading...
Searching...
No Matches
TrigEventInfoRecorderAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11class ISvcLocator;
12
13TrigEventInfoRecorderAlg::TrigEventInfoRecorderAlg(const std::string & name, ISvcLocator* pSvcLocator)
14: AthReentrantAlgorithm(name, pSvcLocator)
15{
16
17}
18
20{
21 ATH_CHECK( m_TrigEventInfoKey.initialize() );
22
23 ATH_CHECK( m_rhoDecor.initialize() );
24 ATH_CHECK( m_rhoEMTDecor.initialize() );
25 ATH_CHECK( m_muDecor.initialize() );
26 ATH_CHECK( m_numPVDecor.initialize() );
27
28 // initialize only the ReadHandleKeys needed by the sequence that called this algorithm
29 // initialize(false) for variables not used in the present instantiation
33
36 }
40 }
41
42
43 return StatusCode::SUCCESS;
44}
45
46
47StatusCode TrigEventInfoRecorderAlg::execute(const EventContext& context) const
48{
49
50 // Create new TrigComposite(Aux)Container and link them together
51 auto trigEventInfoContainer = std::make_unique< xAOD::TrigCompositeContainer>();
52 auto trigEventInfoContainerAux = std::make_unique< xAOD::TrigCompositeAuxContainer>();
53
54 trigEventInfoContainer->setStore(trigEventInfoContainerAux.get());
55
56 // Create TrigComposite "object" that will serve as the anchor for the decorations
58 trigEventInfoContainer->push_back(trigEI);
59
61 ATH_CHECK(trigEventInfoHandle.record( std::move( trigEventInfoContainer ),
62 std::move( trigEventInfoContainerAux ) ) );
63
64 // Retrieve event info variables and decorate the TrigComposite object with them
65 ATH_CHECK( decorateWithEventInfo(context, trigEI) );
66
67 return StatusCode::SUCCESS;
68}
69
70StatusCode TrigEventInfoRecorderAlg::decorateWithEventInfo(const EventContext& context, xAOD::TrigComposite* trigEI) const
71{
72 // Structure of the function: First retrieve all variables of interest from their respective containers
73 // in StoreGate, then decorate the TrigComposite Object passed down from the execute
74
75 // Average Interactions per bunch crossing
76 float avgmu = m_lumiBlockMuTool->averageInteractionsPerCrossing(context);
77
78 double rho=0, rho_EMT = 0;
79 const xAOD::EventShape * eventShape = 0;
80 int NPV = 0;
81
82 // pflow jet decorations
84
85 SG::ReadHandle<xAOD::EventShape> rhRhoKey_PF(m_rhoKeyPF, context);
86 if ( rhRhoKey_PF.isValid() )
87 {
88 ATH_MSG_VERBOSE("Found event density container "<<m_rhoKeyPF);
89 eventShape = rhRhoKey_PF.cptr();
90
91 if ( !eventShape->getDensity( xAOD::EventShape::Density, rho ) ) {
92 ATH_MSG_WARNING("Event density not found in handle, but handle found.");
93 ATH_MSG_FATAL("Could not retrieve xAOD::EventShape::Density from xAOD::EventShape.");
94 return StatusCode::FAILURE;
95 }
96 }
97 else {
98 if (!m_renounceAll) ATH_MSG_ERROR("EventShape handle "<<m_rhoKeyPF<<" not found.");
99 }
100 ATH_MSG_DEBUG("Retrieved Jet Density Rho(PFlow): " << rho);
101
102 // Number of primary vertices: just counting the number of 'good' vertices in HLT_IDVertex_FS container
104 const xAOD::Vertex* privtx = nullptr;
105 if( vtxCont.isValid() ){
106 const xAOD::VertexContainer* vertex_container = vtxCont.get();
107
108 for (unsigned int i_vtx = 0; i_vtx < vertex_container->size(); i_vtx++)
109 {
110 privtx = vertex_container->at(i_vtx);
111 if ( privtx->nTrackParticles() >= 2) NPV++;
112 }
113
114 }
115 else {
116 if (!m_renounceAll) ATH_MSG_ERROR( "Couldn't retrieve primary vertex container "<< m_PrimaryVxInputName<<". NPV will be 0" );
117 }
118 }
119
121 SG::ReadHandle<xAOD::EventShape> rhRhoKey_EMT(m_rhoKeyEMT, context);
122 if ( rhRhoKey_EMT.isValid() )
123 {
124 ATH_MSG_VERBOSE("Found event density container HLT_Kt4EMTopoEventShape");
125 eventShape = rhRhoKey_EMT.cptr();
126 if ( !eventShape->getDensity( xAOD::EventShape::Density, rho_EMT ) ) {
127 ATH_MSG_WARNING("Event density not found in handle, but handle found.");
128 ATH_MSG_FATAL("Could not retrieve xAOD::EventShape::Density from xAOD::EventShape.");
129 return StatusCode::FAILURE;
130 }
131 }
132 else {
133 if (!m_renounceAll) ATH_MSG_ERROR("EventShape handle "<<m_rhoKeyEMT<<" not found.");
134 }
135 ATH_MSG_DEBUG("Retrieved Jet Density Rho(EMTopo): " << rho_EMT);
136 }
137
138 // Now decorate the TrigComposite object with the variables retrieved above
139 ATH_MSG_DEBUG("Setting PF JetDensity to " << rho);
140 SG::makeHandle<double>(m_rhoDecor, context)(*trigEI) = rho;
141 ATH_MSG_DEBUG("Setting EMT JetDensity to " << rho_EMT);
142 SG::makeHandle<double>(m_rhoEMTDecor, context)(*trigEI) = rho_EMT;
143 ATH_MSG_DEBUG("Setting AverageMu to " << avgmu);
144 SG::makeHandle<float>(m_muDecor, context)(*trigEI) = avgmu;
145 ATH_MSG_DEBUG("Setting NPV to " << NPV);
146 SG::makeHandle<int>(m_numPVDecor, context)(*trigEI) = NPV;
147
148 return StatusCode::SUCCESS;
149}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
An algorithm that can be simultaneously executed in multiple threads.
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Gaudi::Property< bool > m_decoratePFlowInfo
SG::ReadHandleKey< xAOD::EventShape > m_rhoKeyPF
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_rhoDecor
virtual StatusCode initialize() override
ToolHandle< ILumiBlockMuTool > m_lumiBlockMuTool
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_TrigEventInfoKey
SG::ReadHandleKey< xAOD::VertexContainer > m_PrimaryVxInputName
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_rhoEMTDecor
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_muDecor
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_numPVDecor
Gaudi::Property< bool > m_decorateEMTopoInfo
Gaudi::Property< bool > m_renounceAll
SG::ReadHandleKey< xAOD::EventShape > m_rhoKeyEMT
StatusCode decorateWithEventInfo(const EventContext &ctx, xAOD::TrigComposite *trigEI) const
TrigEventInfoRecorderAlg(const std::string &name, ISvcLocator *pSvcLocator)
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
EventShape_v1 EventShape
Definition of the current event format version.
Definition EventShape.h:16