ATLAS Offline Software
Loading...
Searching...
No Matches
xAODCaloClusterRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "CaloGeoHelpers/CaloSampling.h"
8
9using Athena::Units::GeV;
10
11namespace JiveXML {
12
19 xAODCaloClusterRetriever::xAODCaloClusterRetriever(const std::string& type,const std::string& name,const IInterface* parent):
20 AthAlgTool(type,name,parent)
21 {}
22
23
25 ATH_CHECK(m_keys.initialize());
26 return StatusCode::SUCCESS;
27 }
28
29
35 StatusCode xAODCaloClusterRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
36
37 ATH_MSG_DEBUG("In retrieve()");
38
39 // Loop through the keys and retrieve the corresponding data
40 for (const auto& key : m_keys) {
42 if (cont.isValid()) {
43 DataMap data = getData(&(*cont));
44 if (FormatTool->AddToEvent(dataTypeName(), key.key() + "_xAOD", &data).isFailure()) {
45 ATH_MSG_WARNING("Failed to add collection " << key.key());
46 } else {
47 ATH_MSG_DEBUG(" (" << key.key() << ") retrieved");
48 }
49 } else {
50 ATH_MSG_WARNING("Collection " << key.key() << " not found in SG");
51 }
52 }
53
54 return StatusCode::SUCCESS;
55 }
56
57
65
66 ATH_MSG_DEBUG("in getData()");
67
69
70 DataVect phi; phi.reserve(ccc->size());
71 DataVect eta; eta.reserve(ccc->size());
72 DataVect et; et.reserve(ccc->size());
73 DataVect cells; cells.reserve(ccc->size());
74 DataVect numCells; numCells.reserve(ccc->size());
75 DataVect idVec; idVec.reserve(ccc->size());
76 DataVect emfracVec; emfracVec.reserve(ccc->size());
77 DataVect labelVec; labelVec.reserve(ccc->size());
78
79 std::string label="";
80 int id = 0;
81 int s = 0;
82 float eInSample = 0.;
83 float eInSampleFull = 0.;
84 float emfrac = 0.;
85 float rawemfrac = 0.;
86
87 // cells n/a in AOD, but keep this for compatibility
88 // with 'full' clusters in AtlantisJava
89 std::string tagCells;
90 tagCells = "cells multiple=\"1.0\"";
91
93 for (; itr != ccc->end(); ++itr) {
94
95 // sum over samplings to get EMfraction:
97 // full sum:
98 for (s=0;s<CaloSampling::Unknown; s++){
99 eInSampleFull += (*itr)->eSample(CaloSampling::CaloSample(s));
100 }
101 // Now only EMB1-3, EME1-3 and FCAL1:
102 eInSample += (*itr)->eSample(CaloSampling::EMB1);
103 eInSample += (*itr)->eSample(CaloSampling::EMB2);
104 eInSample += (*itr)->eSample(CaloSampling::EMB3);
105 eInSample += (*itr)->eSample(CaloSampling::EME1);
106 eInSample += (*itr)->eSample(CaloSampling::EME2);
107 eInSample += (*itr)->eSample(CaloSampling::EME3);
108 eInSample += (*itr)->eSample(CaloSampling::FCAL1);
109
110 emfrac = eInSample/eInSampleFull;
111 rawemfrac = emfrac;
112 // sanity cut: emfrac should be within [0,1]
113 if ( emfrac > 1.0 ) emfrac = 1.;
114 if ( emfrac < 0.0 ) emfrac = 0.;
115 emfracVec.emplace_back( DataType(emfrac).toString() );
116
117 if ( DataType( eInSample ).toString() != "0." ){
118 label = "AllMeV_SumEMSampl=" + DataType( eInSample ).toString() +
119 "_SumAllSampl=" + DataType( eInSampleFull ).toString() +
120 "_calcEMFrac=" + DataType( rawemfrac ).toString()+
121 "_outEMFrac=" + DataType( emfrac ).toString();
122 }else{ label = "n_a"; }
123 eInSample = 0.;
124 eInSampleFull = 0.;
125
126 labelVec.emplace_back( label );
127 ATH_MSG_VERBOSE("label is " << label);
128
129 // now the standard variables
130 // getBasicEnergy n/a in xAOD !
131
132 phi.emplace_back(DataType((*itr)->phi()));
133 eta.emplace_back(DataType((*itr)->eta()));
134 et.emplace_back(DataType((*itr)->et()/GeV));
135 numCells.emplace_back(DataType( "0" ));
136 cells.emplace_back(DataType( "0" ));
137 idVec.emplace_back(DataType( ++id ));
138
139 ATH_MSG_VERBOSE( dataTypeName() << " cluster #" << id
140 << " ,e=" << (*itr)->e()/GeV << ", et="
141 << (*itr)->et()/GeV << ", eta=" << (*itr)->eta()
142 << ", phi=" << (*itr)->phi());
143 }
144 // Start with mandatory entries
145 const auto n = phi.size();
146 DataMap["phi"] = std::move(phi);
147 DataMap["eta"] = std::move(eta);
148 DataMap["et"] = std::move(et);
149 DataMap[tagCells] = std::move(cells);
150 DataMap["numCells"] = std::move(numCells);
151 DataMap["id"] = std::move(idVec);
152 DataMap["emfrac"] = std::move(emfracVec); // not in Atlantis yet ! Could be used in legoplot
153 DataMap["label"] = std::move(labelVec); // not in Atlantis yet !
154
155 ATH_MSG_DEBUG(dataTypeName() << " (AOD, no cells), collection: " << dataTypeName()
156 << " retrieved with " << n << " entries");
157 return DataMap;
158 }
159
160
161} // 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_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
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:
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
const DataMap getData(const xAOD::CaloClusterContainer *)
Puts the variables into a DataMap.
SG::ReadHandleKeyArray< xAOD::CaloClusterContainer > m_keys
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each cluster collection retrieve basic parameters.
xAODCaloClusterRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string label(const std::string &format, int i)
Definition label.h:19
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.