ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9using Athena::Units::GeV;
10
11namespace JiveXML {
12
19 CaloClusterRetriever::CaloClusterRetriever(const std::string& type,const std::string& name,const IInterface* parent):
20 AthAlgTool(type,name,parent),
21 m_sgKeyFavourite ("egammaClusters")
22 {
23 //Only declare the interface
24 declareInterface<IDataRetriever>(this);
25
26 declareProperty("FavouriteClusterCollection" ,m_sgKeyFavourite,
27 "Collection to be first in output, shown in Atlantis without switching");
28 declareProperty("OtherClusterCollections" ,m_otherKeys,
29 "Other collections to be retrieved. If list left empty, all available retrieved");
30 declareProperty("DoWriteHLT", m_doWriteHLT = false,"Ignore HLTAutokey object by default."); // ignore HLTAutoKey objects
31 }
32
34 {
35
36 ATH_MSG_DEBUG("Initialising Tool");
37
38 ATH_CHECK(m_sgKeyFavourite.initialize());
39
40 return StatusCode::SUCCESS;
41 }
42
48 StatusCode CaloClusterRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
49
50 ATH_MSG_DEBUG( "in retrieveAll()" );
51
52 //obtain the default collection first
53 ATH_MSG_DEBUG( "Trying to retrieve " << dataTypeName() << " (" << m_sgKeyFavourite.key() << ")" );
54
56 if (ccc_primary.isValid()) {
57 DataMap data = getData(&(*ccc_primary));
58 if (FormatTool->AddToEvent(dataTypeName(), m_sgKeyFavourite.key() + "_ESD", &data).isFailure()) {
59 ATH_MSG_WARNING("Failed to retrieve favourite Collection " << m_sgKeyFavourite.key() );
60 }
61 else {
62 ATH_MSG_DEBUG(dataTypeName() << " (" << m_sgKeyFavourite.key() << ") CaloCluster retrieved");
63 }
64 }
65 else{
66 ATH_MSG_WARNING("Favourite Collection " << m_sgKeyFavourite.key() << " not found in SG ");
67 }
68
69 if ( m_otherKeys.empty() ) {
70 //obtain all other collections from StoreGate
71 std::vector<std::string> allkeys;
72 evtStore()->keys(static_cast<CLID>( ClassID_traits<xAOD::CaloClusterContainer>::ID() ), allkeys);
73 for (const auto& key : allkeys) {
74 if (key!=m_sgKeyFavourite.key()) {
75 ATH_MSG_DEBUG( "Trying to retrieve all " << dataTypeName() << " (" << key << ")" );
77 if (!containerRH.isValid()) {
78 ATH_MSG_DEBUG( "Unable to retrieve CaloCluster collection " << key );
79 } else {
80 std::string::size_type position = key.find("HLTAutoKey",0);
81 if ( m_doWriteHLT ){ position = 99; } // override SG key find
82 if ( position != 0 ){ // SG key doesn't contain HLTAutoKey
83 DataMap data = getData(&*containerRH);
84 if ( FormatTool->AddToEvent(dataTypeName(), containerRH.key()+"_ESD", &data).isFailure()){
85 ATH_MSG_WARNING( "Collection " << containerRH.key() << " not found in SG " );
86 }else{
87 ATH_MSG_DEBUG( dataTypeName() << " (" << containerRH.key() << ") CaloCluster retrieved" );
88 }
89 }
90 }
91 }
92 }
93 }else {
94 //obtain all collections with keys provided by user: m_otherKeys
95 for (const auto& key : m_otherKeys) {
96 if (key!=m_sgKeyFavourite.key()) {
97 ATH_MSG_DEBUG( "Trying to retrieve selected " << dataTypeName() << " (" << key << ")" );
99 if (!containerRH.isValid()) {
100 ATH_MSG_DEBUG( "Unable to retrieve CaloCluster collection " << key );
101 } else {
102 DataMap data = getData(&*containerRH);
103 if ( FormatTool->AddToEvent(dataTypeName(), containerRH.key()+"_ESD", &data).isFailure()){
104 ATH_MSG_WARNING( "Collection " << containerRH.key() << " not found in SG " );
105 }else{
106 ATH_MSG_DEBUG( dataTypeName() << " (" << containerRH.key() << ") retrieved" );
107 }
108 }
109 }
110 }
111 }
112 //All collections retrieved okay
113 return StatusCode::SUCCESS;
114 }
115
116
124
125 ATH_MSG_DEBUG( "getData()" );
126
128
129 DataVect phi; phi.reserve(ccc->size());
130 DataVect eta; eta.reserve(ccc->size());
131 DataVect et; et.reserve(ccc->size());
132 DataVect idVec; idVec.reserve(ccc->size());
133 DataVect numCellsVec; numCellsVec.reserve(ccc->size());
134 DataVect cells; cells.reserve( ccc->size() );
135
136 int noClu = ccc->size();
137 int noCells = 0;
138
139 int id = 0;
140 for (const auto cluster : *ccc) {
141 phi.emplace_back(cluster->phi());
142 eta.emplace_back(cluster->eta());
143 et.emplace_back(cluster->et()*(1./GeV));
144 idVec.emplace_back( ++id );
145
146 int numCells = cluster->size();
147 numCellsVec.emplace_back( numCells );
148 noCells += numCells;
149
150 for (const auto cell : *cluster) {
151 cells.push_back(cell->ID().get_compact());
152 }
153 }
154
155 std::string tagCells;
156 if(noClu){
157 tagCells = "cells multiple=\"" +DataType(noCells/(noClu*1.0)).toString()+"\"";
158 }else{
159 tagCells = "cells multiple=\"1.0\"";
160 }
161
162 // Start with mandatory entries
163 const auto nEntries = phi.size();
164 DataMap["phi"] = std::move(phi);
165 DataMap["eta"] = std::move(eta);
166 DataMap["et"] = std::move(et);
167 DataMap[tagCells] = std::move(cells);
168 DataMap["numCells"] = std::move(numCellsVec);
169 DataMap["id"] = std::move(idVec);
170
171 //Be verbose
172 ATH_MSG_DEBUG( dataTypeName() << " , collection: " << dataTypeName()
173 << " retrieved with " << nEntries << " entries" );
174
175 //All collections retrieved okay
176 return DataMap;
177
178 } // retrieve
179
180 //--------------------------------------------------------------------------
181
182} // 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.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
size_type size() const noexcept
Returns the number of elements in the collection.
CaloClusterRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
StatusCode initialize()
Default AthAlgTool methods.
virtual std::string dataTypeName() const
Return the name of the data type.
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_sgKeyFavourite
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
std::vector< std::string > m_otherKeys
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.