ATLAS Offline Software
egammaRecBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "egammaRecBuilder.h"
6 
8 #include "StoreGate/ReadHandle.h"
10 
17 
18 #include <vector>
19 #include <algorithm>
20 #include <cmath>
21 
23  ISvcLocator* pSvcLocator)
24  : AthReentrantAlgorithm(name, pSvcLocator)
25 {}
26 
29 {
30  // First the data handle keys
32  ATH_CHECK(m_egammaRecContainerKey.initialize());
34  // retrieve track match builder
35  ATH_CHECK(RetrieveTool<IEMTrackMatchBuilder>(m_trackMatchBuilder, m_doTrackMatching));
36  // retrieve conversion builder
37  ATH_CHECK(RetrieveTool<IEMConversionBuilder>(m_conversionBuilder, m_doConversions));
38  return StatusCode::SUCCESS;
39 }
40 
41 template <typename T>
43 egammaRecBuilder::RetrieveTool(ToolHandle<T> &tool, bool tool_requested)
44 {
45  if (!tool_requested) {
46  tool.disable();
47  return StatusCode::SUCCESS;
48  }
49  if (tool.empty()) {
50  ATH_MSG_INFO(tool.type() << " is empty");
51  return StatusCode::FAILURE;
52  }
53  ATH_CHECK(tool.retrieve());
54  return StatusCode::SUCCESS;
55 }
56 
58 egammaRecBuilder::execute(const EventContext& ctx) const
59 {
60  ATH_MSG_DEBUG("Executing egammaRecBuilder");
61 
64 
65  // validity check is only really needed for serial running. Remove when MT is
66  // only way.
67  ATH_CHECK(clusters.isValid());
68 
70  ATH_CHECK(egammaRecs.record(std::make_unique<EgammaRecContainer>()));
71 
72  // one egamma Rec objects per cluster
73  const size_t nClusters = clusters->size();
74  egammaRecs->reserve(nClusters);
75  for (size_t i = 0; i < nClusters; ++i) {
77  *clusters, i, ctx);
78  const std::vector<ElementLink<xAOD::CaloClusterContainer>>
79  clusterLinkVector{ clusterLink };
80  egammaRecs->push_back(std::make_unique<egammaRec>(clusterLinkVector));
81  }
82 
83  // Append track Matching information if requested
84  if (m_doTrackMatching) {
85  ATH_CHECK(m_trackMatchBuilder->executeRec(ctx, egammaRecs.ptr()));
86  }
87 
88  // Append conversion matching information if requested
89  if (m_doConversions) {
90  for (auto egRec : *egammaRecs) {
91  ATH_CHECK(m_conversionBuilder->executeRec(ctx, egRec));
92  }
93  }
94 
95  // create a view of the track matched egRecs if requested
99 
100  auto viewCopy =
101  std::make_unique<ConstDataVector<EgammaRecContainer>>(SG::VIEW_ELEMENTS);
102 
103  if (m_doTrackMatching) {
104  for (const egammaRec* eg : *egammaRecs) {
105  if (eg->getNumberOfTrackParticles() > 0) {
106  viewCopy->push_back(eg);
107  }
108  }
109  }
110  ATH_CHECK(trackMatchedEgammaRecs.record(std::move(viewCopy)));
111  }
112 
113  return StatusCode::SUCCESS;
114 }
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
egammaRecBuilder::m_conversionBuilder
ToolHandle< IEMConversionBuilder > m_conversionBuilder
Tool to perfrom conversion vertex matching.
Definition: egammaRecBuilder.h:84
egammaRecBuilder::m_inputClusterContainerKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_inputClusterContainerKey
Key for the topo cluster input collection.
Definition: egammaRecBuilder.h:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ParticleTest.eg
eg
Definition: ParticleTest.py:29
egammaRecBuilder::m_doTrackMatchedView
Gaudi::Property< bool > m_doTrackMatchedView
private member flag to produce of view of track matched egammaRecs
Definition: egammaRecBuilder.h:105
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
egammaRecBuilder::initialize
virtual StatusCode initialize() override final
Definition: egammaRecBuilder.cxx:28
IegammaCheckEnergyDepositTool.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
egammaRecBuilder::egammaRecBuilder
egammaRecBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: egammaRecBuilder.cxx:22
WriteHandle.h
Handle class for recording to StoreGate.
egammaRecBuilder::m_doTrackMatching
Gaudi::Property< bool > m_doTrackMatching
private member flag to do the track matching
Definition: egammaRecBuilder.h:92
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
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
egammaRecBuilder.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
egammaRecBuilder::RetrieveTool
StatusCode RetrieveTool(ToolHandle< T > &tool, bool tool_requested)
Wrap tool retrieval, ensuring it was named and requested.
Definition: egammaRecBuilder.cxx:43
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
egammaRecBuilder::m_egammaRecContainerKey
SG::WriteHandleKey< EgammaRecContainer > m_egammaRecContainerKey
Key for egammaRec container.
Definition: egammaRecBuilder.h:61
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
IEMConversionBuilder.h
CaloClusterContainer.h
egammaRecBuilder::m_doConversions
Gaudi::Property< bool > m_doConversions
private member flag to do the conversion matching
Definition: egammaRecBuilder.h:98
egammaRec
Definition: egammaRec.h:31
egammaRecContainer.h
IEMTrackMatchBuilder.h
ReadHandle.h
Handle class for reading from StoreGate.
egammaRecBuilder::m_trackMatchBuilder
ToolHandle< IEMTrackMatchBuilder > m_trackMatchBuilder
Tool to perform track matching.
Definition: egammaRecBuilder.h:76
egammaRecBuilder::m_trackMatchedEgammaRecs
SG::WriteHandleKey< ConstDataVector< EgammaRecContainer > > m_trackMatchedEgammaRecs
Definition: egammaRecBuilder.h:69
egammaRecBuilder::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: egammaRecBuilder.cxx:58