ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9using Athena::Units::GeV;
10
11namespace JiveXML {
12
14 {
15
16 ATH_MSG_DEBUG("Initialising Tool");
17
18 ATH_CHECK(m_sgKeyFavourite.initialize());
19
20 return StatusCode::SUCCESS;
21 }
22
28 StatusCode CaloClusterRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
29
30 ATH_MSG_DEBUG( "in retrieveAll()" );
31
32 //obtain the default collection first
33 ATH_MSG_DEBUG( "Trying to retrieve " << dataTypeName() << " (" << m_sgKeyFavourite.key() << ")" );
34
36 if (ccc_primary.isValid()) {
37 DataMap data = getData(&(*ccc_primary));
38 if (FormatTool->AddToEvent(dataTypeName(), m_sgKeyFavourite.key() + "_ESD", &data).isFailure()) {
39 ATH_MSG_WARNING("Failed to retrieve favourite Collection " << m_sgKeyFavourite.key() );
40 }
41 else {
42 ATH_MSG_DEBUG(dataTypeName() << " (" << m_sgKeyFavourite.key() << ") CaloCluster retrieved");
43 }
44 }
45 else{
46 ATH_MSG_WARNING("Favourite Collection " << m_sgKeyFavourite.key() << " not found in SG ");
47 }
48
49 if ( m_otherKeys.empty() ) {
50 //obtain all other collections from StoreGate
51 std::vector<std::string> allkeys;
52 evtStore()->keys(static_cast<CLID>( ClassID_traits<xAOD::CaloClusterContainer>::ID() ), allkeys);
53 for (const auto& key : allkeys) {
54 if (key!=m_sgKeyFavourite.key()) {
55 ATH_MSG_DEBUG( "Trying to retrieve all " << dataTypeName() << " (" << key << ")" );
57 if (!containerRH.isValid()) {
58 ATH_MSG_DEBUG( "Unable to retrieve CaloCluster collection " << key );
59 } else {
60 std::string::size_type position = key.find("HLTAutoKey",0);
61 if ( m_doWriteHLT ){ position = 99; } // override SG key find
62 if ( position != 0 ){ // SG key doesn't contain HLTAutoKey
63 DataMap data = getData(&*containerRH);
64 if ( FormatTool->AddToEvent(dataTypeName(), containerRH.key()+"_ESD", &data).isFailure()){
65 ATH_MSG_WARNING( "Collection " << containerRH.key() << " not found in SG " );
66 }else{
67 ATH_MSG_DEBUG( dataTypeName() << " (" << containerRH.key() << ") CaloCluster retrieved" );
68 }
69 }
70 }
71 }
72 }
73 }else {
74 //obtain all collections with keys provided by user: m_otherKeys
75 for (const auto& key : m_otherKeys) {
76 if (key!=m_sgKeyFavourite.key()) {
77 ATH_MSG_DEBUG( "Trying to retrieve selected " << dataTypeName() << " (" << key << ")" );
79 if (!containerRH.isValid()) {
80 ATH_MSG_DEBUG( "Unable to retrieve CaloCluster collection " << key );
81 } else {
82 DataMap data = getData(&*containerRH);
83 if ( FormatTool->AddToEvent(dataTypeName(), containerRH.key()+"_ESD", &data).isFailure()){
84 ATH_MSG_WARNING( "Collection " << containerRH.key() << " not found in SG " );
85 }else{
86 ATH_MSG_DEBUG( dataTypeName() << " (" << containerRH.key() << ") retrieved" );
87 }
88 }
89 }
90 }
91 }
92 //All collections retrieved okay
93 return StatusCode::SUCCESS;
94 }
95
96
104
105 ATH_MSG_DEBUG( "getData()" );
106
108
109 DataVect phi; phi.reserve(ccc->size());
110 DataVect eta; eta.reserve(ccc->size());
111 DataVect et; et.reserve(ccc->size());
112 DataVect idVec; idVec.reserve(ccc->size());
113 DataVect numCellsVec; numCellsVec.reserve(ccc->size());
114 DataVect cells; cells.reserve( ccc->size() );
115
116 int noClu = ccc->size();
117 int noCells = 0;
118
119 int id = 0;
120 for (const auto cluster : *ccc) {
121 phi.emplace_back(cluster->phi());
122 eta.emplace_back(cluster->eta());
123 et.emplace_back(cluster->et()*(1./GeV));
124 idVec.emplace_back( ++id );
125
126 int numCells = cluster->size();
127 numCellsVec.emplace_back( numCells );
128 noCells += numCells;
129
130 for (const auto cell : *cluster) {
131 cells.push_back(cell->ID().get_compact());
132 }
133 }
134
135 std::string tagCells;
136 if(noClu){
137 tagCells = "cells multiple=\"" +DataType(noCells/(noClu*1.0)).toString()+"\"";
138 }else{
139 tagCells = "cells multiple=\"1.0\"";
140 }
141
142 // Start with mandatory entries
143 const auto nEntries = phi.size();
144 DataMap["phi"] = std::move(phi);
145 DataMap["eta"] = std::move(eta);
146 DataMap["et"] = std::move(et);
147 DataMap[tagCells] = std::move(cells);
148 DataMap["numCells"] = std::move(numCellsVec);
149 DataMap["id"] = std::move(idVec);
150
151 //Be verbose
152 ATH_MSG_DEBUG( dataTypeName() << " , collection: " << dataTypeName()
153 << " retrieved with " << nEntries << " entries" );
154
155 //All collections retrieved okay
156 return DataMap;
157
158 } // retrieve
159
160 //--------------------------------------------------------------------------
161
162} // JiveXML namespace
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
uint32_t CLID
The Class ID type.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Wrapper to avoid constant divisions when using units.
size_type size() const noexcept
Returns the number of elements in the collection.
Gaudi::Property< std::vector< std::string > > m_otherKeys
virtual StatusCode initialize() override
Default AthAlgTool methods.
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_sgKeyFavourite
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool) override
Retrieve all the data.
Gaudi::Property< bool > m_doWriteHLT
virtual std::string dataTypeName() const override
Return the name of the data type.
const DataMap getData(const xAOD::CaloClusterContainer *)
Retrieve basic parameters, mainly four-vectors.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition DataType.h:58
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Extra patterns decribing particle interation process.