ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellCalcEnergyCorr.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// CaloCellCalcEnergyCorr.cxx
8// Implementation file for class CaloCellCalcEnergyCorr
10
11// CaloCondPhysAlgs includes
15#include "GaudiKernel/ToolHandle.h"
16
25#include "LArHV/HECHVSubgap.h"
27#include "LArHV/FCALHVLine.h"
28
29#include "LArHV/LArHVManager.h"
30
33
34#include "CoolKernel/types.h"
35#include "CoolKernel/Record.h"
36#include "CoralBase/AttributeListSpecification.h"
38#include "GaudiKernel/ThreadLocalContext.h"
39
40
54
55
57 const LArHVIdMapping& hvCabling,
58 const std::vector<const CondAttrListCollection*>& attrvec)
59 : m_hvdata_EMB (manager.getEMBHVManager().getData (hvCabling, attrvec)),
60 m_hvdata_EMBPS (manager.getEMBPresamplerHVManager().getData (hvCabling, attrvec)),
61 m_hvdata_EMEC_IN (manager.getEMECHVManager(EMECHVModule::IOType::INNER).getData (hvCabling, attrvec)),
62 m_hvdata_EMEC_OUT (manager.getEMECHVManager(EMECHVModule::IOType::OUTER).getData (hvCabling, attrvec)),
63 m_hvdata_EMECPS (manager.getEMECPresamplerHVManager().getData (hvCabling, attrvec)),
64 m_hvdata_HEC (manager.getHECHVManager().getData (hvCabling, attrvec)),
65 m_hvdata_FCAL (manager.getFCALHVManager().getData (hvCabling, attrvec))
66{
67}
68
69
71 ISvcLocator* pSvcLocator ):
72 AthAlgorithm( name, pSvcLocator )
73{
74}
75
77= default;
78
80{
81 if(m_calosample.size() != m_value.size() ) {
82 ATH_MSG_ERROR( "CaloSamples and SampleValues vectors not equal length !!! " );
83 return StatusCode::FAILURE;
84 }
85 if(m_hvlines.size() != m_hvvalue.size() ) {
86 ATH_MSG_ERROR( "HVLines and HVvalues vectors not equal length !!! " );
87 return StatusCode::FAILURE;
88 }
89
90// retrieve LArEM id helpers
91
92 const CaloIdManager* mgr = nullptr;
93 ATH_CHECK( detStore()->retrieve( mgr ) );
94
95 m_larem_id = mgr->getEM_ID();
96 m_larhec_id = mgr->getHEC_ID();
97 m_larfcal_id = mgr->getFCAL_ID();
98
99 ATH_CHECK( m_hvCablingKey.initialize() );
100 ATH_CHECK( m_DCSFolderKeys.initialize() );
101 ATH_CHECK( m_caloMgrKey.initialize() );
102
103 return StatusCode::SUCCESS;
104}
105
107{
108 return StatusCode::SUCCESS;
109}
110
112{
113 return StatusCode::SUCCESS;
114}
115
117{
118
119 const CaloCell_ID* calocell_id;
120 CHECK(detStore()->retrieve(calocell_id,"CaloCell_ID"));
121
122
123 IdentifierHash hashMin,hashMax;
124 if(m_calosample.size()==1 && m_calosample[0] < 0 ) {
125 calocell_id->calo_cell_hash_range(CaloCell_ID::TILE, hashMin,hashMax);
126 } else {
127 int maxsubcalo=-1;
128 for (int i=CaloCell_ID::PreSamplerB; i<=CaloCell_ID::EME3; ++i) {
129 if (std::find(m_calosample.begin(), m_calosample.end(), i) != m_calosample.end()) maxsubcalo = CaloCell_ID::LAREM;
130 }
131 for (int i=CaloCell_ID::HEC0; i<=CaloCell_ID::HEC3; ++i) {
132 if (std::find(m_calosample.begin(), m_calosample.end(), i) != m_calosample.end()) maxsubcalo = CaloCell_ID::LARHEC;
133 }
134 for (int i=CaloCell_ID::FCAL0; i<=CaloCell_ID::FCAL2; ++i) {
135 if (std::find(m_calosample.begin(), m_calosample.end(), i) != m_calosample.end()) maxsubcalo = CaloCell_ID::LARFCAL;
136 }
137 for (int i=CaloCell_ID::TileBar0; i<=CaloCell_ID::TileExt2; ++i) {
138 if (std::find(m_calosample.begin(), m_calosample.end(), i) != m_calosample.end()) maxsubcalo = CaloCell_ID::TILE;
139 }
140 if(maxsubcalo < 0 ) {
141 ATH_MSG_ERROR( "Wrong CaloSamples vector " << m_calosample );
142 return StatusCode::FAILURE;
143 } else {
144 calocell_id->calo_cell_hash_range(maxsubcalo, hashMin,hashMax);
145 }
146 }
147
148 ATH_MSG_INFO( "Working on hash range 0 to " << hashMax );
149
150 coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
151 spec->extend("CaloCondBlob16M","blob");// , cool::StorageType::Blob16M);
152 AthenaAttributeList* attrList=new AthenaAttributeList(*spec);
153 coral::Blob& blob=(*attrList)["CaloCondBlob16M"].data<coral::Blob>();
155 spec->release(); // deletes spec
156 // cppcheck-suppress memleak
157 spec = nullptr;
158
159 //Blob Defintion Vector
160 std::vector<std::vector<float> > defVec;
161 defVec.emplace_back(1,1);
162 flt->init(defVec,hashMax,1);
163
164 CHECK(detStore()->record(attrList,m_folder));
165
166 const LArHVManager* manager = nullptr;
167 CHECK( detStore()->retrieve (manager) );
168
169 const EventContext& ctx = Gaudi::Hive::currentContext();
171 std::vector<const CondAttrListCollection*> attrvec;
172 for (const auto& fldkey: m_DCSFolderKeys ) {
174 attrvec.push_back (*dcsHdl);
175 }
176
177 HVData hvdata (*manager, **hvCabling, attrvec);
178
180 ATH_CHECK(caloMgrHandle.isValid());
181 const CaloDetDescrManager* caloMgr = *caloMgrHandle;
182
183 std::vector<float> setVec(1,1);
184 unsigned nSet=0;
185 unsigned nSetHV=0;
186 for(unsigned h=0;h<hashMax;++h) {
187 float value=1.0;
188 std::vector<int>::const_iterator pos;
189 if ((pos = std::find(m_calosample.begin(), m_calosample.end(), calocell_id->calo_sample(h))) != m_calosample.end()) {
190 // find a position in m_calosample vector, and use this value from m_values vector
191 const std::vector<float>::size_type idx = pos - m_calosample.begin();
192 value=m_value[idx];
193 ++nSet;
194 // check if we have also HVLine for this cell
195 if(!m_hvlines.empty() && m_hvlines[0]>0) {
196 Identifier offId=calocell_id->cell_id(h);
197 std::vector<int> hvlineId = GetHVLines(hvdata, offId, caloMgr);
198 int nfound=0;
199 float hvval=-1;
200 std::vector<int>::const_iterator poshv;
201 for(unsigned i=0; i<hvlineId.size(); ++i) {
202 if ((poshv=std::find(m_hvlines.begin(), m_hvlines.end(), hvlineId[i])) != m_hvlines.end()) {
203 if (hvval<0) hvval = m_hvvalue[poshv - m_hvlines.begin()];
204 if (m_hvvalue[poshv - m_hvlines.begin()] == hvval ) ++nfound;
205 }
206 }
207 if(nfound == (int)hvlineId.size()) { // All lines of this channel has the same corr., apply
208 value *= hvval;
209 ++nSetHV;
210 }
211 }
212 }
213 setVec[0]=value;
214 flt->setData(h,0,setVec);
215 }//end loop over hash
216
217 ATH_MSG_INFO( "Found " << nSet << " channels which have a sample correction. " );
218 ATH_MSG_INFO( "Found " << nSetHV << " channels which have a HV correction. " );
219
220 return StatusCode::SUCCESS;
221}
222
223
224std::vector<int> CaloCellCalcEnergyCorr::GetHVLines(const HVData& hvdata
225 , const Identifier& id
226 , const CaloDetDescrManager* caloMgr) {
227 std::set<int> hv;
228
229 // LAr EMB
230 if (m_larem_id->is_lar_em(id) && m_larem_id->sampling(id)>0) {
231 if (abs(m_larem_id->barrel_ec(id))==1) {
232 const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(caloMgr->get_element(id));
233 if (!embElement) std::abort();
234 const EMBCellConstLink cell = embElement->getEMBCell();
235 unsigned int nelec = cell->getNumElectrodes();
236 for (unsigned int i=0;i<nelec;i++) {
237 const EMBHVElectrode& electrode = cell->getElectrode(i);
238 for (unsigned int igap=0;igap<2;igap++) hv.insert(hvdata.m_hvdata_EMB.hvLineNo (electrode, igap));
239 }
240 } else { // LAr EMEC
241 const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(caloMgr->get_element(id));
242 if (!emecElement) std::abort();
243 const EMECCellConstLink cell = emecElement->getEMECCell();
244 unsigned int nelec = cell->getNumElectrodes();
245 for (unsigned int i=0;i<nelec;i++) {
246 const EMECHVElectrode& electrode = cell->getElectrode(i);
247 const EMECHVManager::EMECHVData& hvdata_EMEC =
249 hvdata.m_hvdata_EMEC_IN :
250 hvdata.m_hvdata_EMEC_OUT ;
251 for (unsigned int igap=0;igap<2;igap++) {
252 hv.insert(hvdata_EMEC.hvLineNo (electrode, igap));
253 }
254 }
255 }
256 } else if (m_larhec_id->is_lar_hec(id)) { // LAr HEC
257 const HECDetectorElement* hecElement = dynamic_cast<const HECDetectorElement*>(caloMgr->get_element(id));
258 if (!hecElement) std::abort();
259 const HECCellConstLink cell = hecElement->getHECCell();
260 unsigned int nsubgaps = cell->getNumSubgaps();
261 for (unsigned int igap=0;igap<nsubgaps;igap++) {
262 const HECHVSubgap& subgap = cell->getSubgap(igap);
263 hv.insert(hvdata.m_hvdata_HEC.hvLineNo (subgap));
264 }
265 } else if (m_larfcal_id->is_lar_fcal(id)) { // LAr FCAL
266 const FCALDetectorElement* fcalElement = dynamic_cast<const FCALDetectorElement*>(caloMgr->get_element(id));
267 if (!fcalElement) std::abort();
268 const FCALTile* tile = fcalElement->getFCALTile();
269 unsigned int nlines = tile->getNumHVLines();
270 for (unsigned int i=0;i<nlines;i++) {
271 const FCALHVLine* line = tile->getHVLine(i);
272 if(line) hv.insert(hvdata.m_hvdata_FCAL.hvLineNo (*line));
273 }
274 } else if (m_larem_id->is_lar_em(id) && m_larem_id->sampling(id)==0) { // Presamplers
275 if (abs(m_larem_id->barrel_ec(id))==1) {
276 const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(caloMgr->get_element(id));
277 if (!embElement) std::abort();
278 const EMBCellConstLink cell = embElement->getEMBCell();
279 const EMBPresamplerHVModule& hvmodule = cell->getPresamplerHVModule();
280 for (unsigned int igap=0;igap<2;igap++) hv.insert(hvdata.m_hvdata_EMBPS.hvLineNo (hvmodule, igap));
281 } else {
282 const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(caloMgr->get_element(id));
283 if (!emecElement) std::abort();
284 const EMECCellConstLink cell = emecElement->getEMECCell();
285 const EMECPresamplerHVModule& hvmodule = cell->getPresamplerHVModule ();
286 for (unsigned int igap=0;igap<2;igap++) hv.insert(hvdata.m_hvdata_EMECPS.hvLineNo (hvmodule, igap));
287 }
288 }
289
290 std::vector<int> hvlines;
291 for (std::set<int>::iterator i=hv.begin();i!=hv.end();++i) hvlines.push_back(*i);
292 return hvlines;
293}
294
295
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
Calo Subsystem specific Detector Elements + Dummy element for testing.
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
Header file for AthHistogramAlgorithm.
An AttributeList represents a logical row of attributes in a metadata table.
virtual StatusCode execute() override
Gaudi::Property< std::string > m_folder
virtual StatusCode initialize() override
SG::ReadCondHandleKey< LArHVIdMapping > m_hvCablingKey
Gaudi::Property< std::vector< float > > m_value
virtual ~CaloCellCalcEnergyCorr()
Destructor:
Gaudi::Property< std::vector< float > > m_hvvalue
virtual StatusCode stop() override
CaloCellCalcEnergyCorr(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
std::vector< int > GetHVLines(const HVData &hvdata, const Identifier &id, const CaloDetDescrManager *caloMgr)
SG::ReadCondHandleKeyArray< CondAttrListCollection > m_DCSFolderKeys
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Gaudi::Property< std::vector< int > > m_calosample
virtual StatusCode finalize() override
Gaudi::Property< std::vector< int > > m_hvlines
const LArFCAL_ID * m_larfcal_id
void calo_cell_hash_range(const Identifier id, IdentifierHash &caloCellMin, IdentifierHash &caloCellMax) const
to loop on 'global' cell hashes of one sub-calorimeter alone
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
Class for storing a number of floats (Flt) and functions on those.
static CaloCondBlobFlt * getInstance(coral::Blob &blob)
Returns a pointer to a non-const CaloCondBlobFlt.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
This class initializes the Calo (LAr and Tile) offline identifiers.
LAr EMB Detector Element.
EMBCellConstLink getEMBCell() const
EMB Cell description from LArReadoutGeometry.
int hvLineNo(const EMBHVElectrode &electrode, const int &iGap) const
int hvLineNo(const EMBPresamplerHVModule &module, const int &iGap) const
Describes one HV Module within the EMB Presampler.
LAr EMEC Detector Element.
EMECCellConstLink getEMECCell() const
EMEC Cell description from LArReadoutGeometry.
const EMECHVModule & getModule() const
int hvLineNo(const EMECHVElectrode &electrode, const int &iGap) const
EMECHVModule::IOType getWheelIndex() const
int hvLineNo(const EMECPresamplerHVModule &module, const int &iGap) const
Describes one HV Module within the EMEc Presampler.
LAr FCAL Detector Element.
const FCALTile * getFCALTile() const
FCAL Tile description from LArReadoutGeometry.
int hvLineNo(const FCALHVLine &line) const
A tile of the forward calorimeter readout geometry.
Definition FCALTile.h:27
LAr HEC Detector Element.
HECCellConstLink getHECCell() const
HEC Cell description from LArReadoutGeometry.
int hvLineNo(const HECHVSubgap &subgap) const
This is a "hash" representation of an Identifier.
This class provides access to the High Voltage throughout the LAr.
HVData(const LArHVManager &manager, const LArHVIdMapping &hvCabling, const std::vector< const CondAttrListCollection * > &attrvec)
FCALHVManager::FCALHVData m_hvdata_FCAL
EMECPresamplerHVManager::EMECPresamplerHVData m_hvdata_EMECPS
EMECHVManager::EMECHVData m_hvdata_EMEC_IN
EMECHVManager::EMECHVData m_hvdata_EMEC_OUT
EMBPresamplerHVManager::EMBPresamplerHVData m_hvdata_EMBPS