ATLAS Offline Software
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 
5 #include "StoreGate/ReadHandle.h"
10 
11 class ISvcLocator;
12 
13 TrigEventInfoRecorderAlg::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 
47 StatusCode 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 
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();
77 
78  double rho=0, rho_EMT = 0;
79  const xAOD::EventShape * eventShape = 0;
80  int NPV = 0;
81 
82  // pflow jet decorations
83  if (m_decoratePFlowInfo) {
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 
120  if (m_decorateEMTopoInfo) {
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 }
TrigEventInfoRecorderAlg::m_muDecor
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_muDecor
Definition: TrigEventInfoRecorderAlg.h:40
xAOD::EventShape_v1::getDensity
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
Definition: EventShape_v1.cxx:135
TrigEventInfoRecorderAlg::m_rhoKeyEMT
SG::ReadHandleKey< xAOD::EventShape > m_rhoKeyEMT
Definition: TrigEventInfoRecorderAlg.h:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
TrigCompositeUtils.h
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:16
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::renounce
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)
Definition: AthCommonDataStore.h:380
TrigEventInfoRecorderAlg::m_rhoDecor
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_rhoDecor
Definition: TrigEventInfoRecorderAlg.h:38
TrigEventInfoRecorderAlg::m_rhoEMTDecor
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_rhoEMTDecor
Definition: TrigEventInfoRecorderAlg.h:39
TrigEventInfoRecorderAlg.h
TrigEventInfoRecorderAlg::m_lumiBlockMuTool
ToolHandle< ILumiBlockMuTool > m_lumiBlockMuTool
Definition: TrigEventInfoRecorderAlg.h:51
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TrigEventInfoRecorderAlg::m_decoratePFlowInfo
Gaudi::Property< bool > m_decoratePFlowInfo
Definition: TrigEventInfoRecorderAlg.h:44
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAOD::EventShape_v1::Density
@ Density
Definition: EventShape_v1.h:47
WriteHandle.h
Handle class for recording to StoreGate.
TrigEventInfoRecorderAlg::m_numPVDecor
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_numPVDecor
Definition: TrigEventInfoRecorderAlg.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigEventInfoRecorderAlg::m_decorateEMTopoInfo
Gaudi::Property< bool > m_decorateEMTopoInfo
Definition: TrigEventInfoRecorderAlg.h:46
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
TrigEventInfoRecorderAlg::m_TrigEventInfoKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_TrigEventInfoKey
Definition: TrigEventInfoRecorderAlg.h:36
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigEventInfoRecorderAlg::decorateWithEventInfo
StatusCode decorateWithEventInfo(const EventContext &ctx, xAOD::TrigComposite *trigEI) const
Definition: TrigEventInfoRecorderAlg.cxx:70
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::EventShape_v1
Data class for event shapes.
Definition: EventShape_v1.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrigEventInfoRecorderAlg::m_renounceAll
Gaudi::Property< bool > m_renounceAll
Definition: TrigEventInfoRecorderAlg.h:48
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TrigEventInfoRecorderAlg::TrigEventInfoRecorderAlg
TrigEventInfoRecorderAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigEventInfoRecorderAlg.cxx:13
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigEventInfoRecorderAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigEventInfoRecorderAlg.cxx:47
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
ReadHandle.h
Handle class for reading from StoreGate.
TrigEventInfoRecorderAlg::m_PrimaryVxInputName
SG::ReadHandleKey< xAOD::VertexContainer > m_PrimaryVxInputName
Definition: TrigEventInfoRecorderAlg.h:54
TrigEventInfoRecorderAlg::m_rhoKeyPF
SG::ReadHandleKey< xAOD::EventShape > m_rhoKeyPF
Definition: TrigEventInfoRecorderAlg.h:52
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
fitman.rho
rho
Definition: fitman.py:532
TrigEventInfoRecorderAlg::initialize
virtual StatusCode initialize() override
Definition: TrigEventInfoRecorderAlg.cxx:19