ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellCalcEnergyCorr.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2023 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 m_larem_id(nullptr),
74 m_larhec_id(nullptr),
75 m_larfcal_id(nullptr)
76{
77 declareProperty("Folder",m_folder="/LAR/CellCorrOfl/EnergyCorr");
78 std::vector<int> ivec; ivec.push_back(-1);
79 declareProperty("CaloSamples",m_calosample=ivec);
80 std::vector<float> fvec; fvec.push_back(1.0);
81 declareProperty("SampleValues",m_value=fvec);
82 std::vector<int> iivec; iivec.push_back(-1);
83 declareProperty("HVLines",m_hvlines=iivec);
84 std::vector<float> ffvec; ffvec.push_back(1.0);
85 declareProperty("HVvalues",m_hvvalue=ffvec);
86}
87
88
90= default;
91
92
94{
95 if(m_calosample.size() != m_value.size() ) {
96 ATH_MSG_ERROR( "CaloSamples and SampleValues vectors not equal length !!! " );
97 return StatusCode::FAILURE;
98 }
99 if(m_hvlines.size() != m_hvvalue.size() ) {
100 ATH_MSG_ERROR( "HVLines and HVvalues vectors not equal length !!! " );
101 return StatusCode::FAILURE;
102 }
103
104// retrieve LArEM id helpers
105
106 const CaloIdManager* mgr = nullptr;
107 ATH_CHECK( detStore()->retrieve( mgr ) );
108
109 m_larem_id = mgr->getEM_ID();
110 m_larhec_id = mgr->getHEC_ID();
111 m_larfcal_id = mgr->getFCAL_ID();
112
113 ATH_CHECK( m_hvCablingKey.initialize() );
114 ATH_CHECK( m_DCSFolderKeys.initialize() );
115 ATH_CHECK( m_caloMgrKey.initialize() );
116
117 return StatusCode::SUCCESS;
118}
119
121{
122 return StatusCode::SUCCESS;
123}
124
126{
127 return StatusCode::SUCCESS;
128}
129
131{
132
133 const CaloCell_ID* calocell_id;
134 CHECK(detStore()->retrieve(calocell_id,"CaloCell_ID"));
135
136
137 IdentifierHash hashMin,hashMax;
138 if(m_calosample.size()==1 && m_calosample[0] < 0 ) {
139 calocell_id->calo_cell_hash_range(CaloCell_ID::TILE, hashMin,hashMax);
140 } else {
141 int maxsubcalo=-1;
142 for (int i=CaloCell_ID::PreSamplerB; i<=CaloCell_ID::EME3; ++i) {
143 if (std::find(m_calosample.begin(), m_calosample.end(), i) != m_calosample.end()) maxsubcalo = CaloCell_ID::LAREM;
144 }
145 for (int i=CaloCell_ID::HEC0; i<=CaloCell_ID::HEC3; ++i) {
146 if (std::find(m_calosample.begin(), m_calosample.end(), i) != m_calosample.end()) maxsubcalo = CaloCell_ID::LARHEC;
147 }
148 for (int i=CaloCell_ID::FCAL0; i<=CaloCell_ID::FCAL2; ++i) {
149 if (std::find(m_calosample.begin(), m_calosample.end(), i) != m_calosample.end()) maxsubcalo = CaloCell_ID::LARFCAL;
150 }
151 for (int i=CaloCell_ID::TileBar0; i<=CaloCell_ID::TileExt2; ++i) {
152 if (std::find(m_calosample.begin(), m_calosample.end(), i) != m_calosample.end()) maxsubcalo = CaloCell_ID::TILE;
153 }
154 if(maxsubcalo < 0 ) {
155 ATH_MSG_ERROR( "Wrong CaloSamples vector " << m_calosample );
156 return StatusCode::FAILURE;
157 } else {
158 calocell_id->calo_cell_hash_range(maxsubcalo, hashMin,hashMax);
159 }
160 }
161
162 ATH_MSG_INFO( "Working on hash range 0 to " << hashMax );
163
164 coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
165 spec->extend("CaloCondBlob16M","blob");// , cool::StorageType::Blob16M);
166 AthenaAttributeList* attrList=new AthenaAttributeList(*spec);
167 coral::Blob& blob=(*attrList)["CaloCondBlob16M"].data<coral::Blob>();
169 spec->release(); // deletes spec
170 // cppcheck-suppress memleak
171 spec = nullptr;
172
173 //Blob Defintion Vector
174 std::vector<std::vector<float> > defVec;
175 defVec.emplace_back(1,1);
176 flt->init(defVec,hashMax,1);
177
178 CHECK(detStore()->record(attrList,m_folder));
179
180 const LArHVManager* manager = nullptr;
181 CHECK( detStore()->retrieve (manager) );
182
183 const EventContext& ctx = Gaudi::Hive::currentContext();
185 std::vector<const CondAttrListCollection*> attrvec;
186 for (const auto& fldkey: m_DCSFolderKeys ) {
188 attrvec.push_back (*dcsHdl);
189 }
190
191 HVData hvdata (*manager, **hvCabling, attrvec);
192
194 ATH_CHECK(caloMgrHandle.isValid());
195 const CaloDetDescrManager* caloMgr = *caloMgrHandle;
196
197 std::vector<float> setVec(1,1);
198 unsigned nSet=0;
199 unsigned nSetHV=0;
200 for(unsigned h=0;h<hashMax;++h) {
201 float value=1.0;
202 std::vector<int>::const_iterator pos;
203 if ((pos = std::find(m_calosample.begin(), m_calosample.end(), calocell_id->calo_sample(h))) != m_calosample.end()) {
204 // find a position in m_calosample vector, and use this value from m_values vector
205 const std::vector<float>::size_type idx = pos - m_calosample.begin();
206 value=m_value[idx];
207 ++nSet;
208 // check if we have also HVLine for this cell
209 if(!m_hvlines.empty() && m_hvlines[0]>0) {
210 Identifier offId=calocell_id->cell_id(h);
211 std::vector<int> hvlineId = GetHVLines(hvdata, offId, caloMgr);
212 int nfound=0;
213 float hvval=-1;
214 std::vector<int>::const_iterator poshv;
215 for(unsigned i=0; i<hvlineId.size(); ++i) {
216 if ((poshv=std::find(m_hvlines.begin(), m_hvlines.end(), hvlineId[i])) != m_hvlines.end()) {
217 if (hvval<0) hvval = m_hvvalue[poshv - m_hvlines.begin()];
218 if (m_hvvalue[poshv - m_hvlines.begin()] == hvval ) ++nfound;
219 }
220 }
221 if(nfound == (int)hvlineId.size()) { // All lines of this channel has the same corr., apply
222 value *= hvval;
223 ++nSetHV;
224 }
225 }
226 }
227 setVec[0]=value;
228 flt->setData(h,0,setVec);
229 }//end loop over hash
230
231 ATH_MSG_INFO( "Found " << nSet << " channels which have a sample correction. " );
232 ATH_MSG_INFO( "Found " << nSetHV << " channels which have a HV correction. " );
233
234 return StatusCode::SUCCESS;
235}
236
237
238std::vector<int> CaloCellCalcEnergyCorr::GetHVLines(const HVData& hvdata
239 , const Identifier& id
240 , const CaloDetDescrManager* caloMgr) {
241 std::set<int> hv;
242
243 // LAr EMB
244 if (m_larem_id->is_lar_em(id) && m_larem_id->sampling(id)>0) {
245 if (abs(m_larem_id->barrel_ec(id))==1) {
246 const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(caloMgr->get_element(id));
247 if (!embElement) std::abort();
248 const EMBCellConstLink cell = embElement->getEMBCell();
249 unsigned int nelec = cell->getNumElectrodes();
250 for (unsigned int i=0;i<nelec;i++) {
251 const EMBHVElectrode& electrode = cell->getElectrode(i);
252 for (unsigned int igap=0;igap<2;igap++) hv.insert(hvdata.m_hvdata_EMB.hvLineNo (electrode, igap));
253 }
254 } else { // LAr EMEC
255 const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(caloMgr->get_element(id));
256 if (!emecElement) std::abort();
257 const EMECCellConstLink cell = emecElement->getEMECCell();
258 unsigned int nelec = cell->getNumElectrodes();
259 for (unsigned int i=0;i<nelec;i++) {
260 const EMECHVElectrode& electrode = cell->getElectrode(i);
261 const EMECHVManager::EMECHVData& hvdata_EMEC =
263 hvdata.m_hvdata_EMEC_IN :
264 hvdata.m_hvdata_EMEC_OUT ;
265 for (unsigned int igap=0;igap<2;igap++) {
266 hv.insert(hvdata_EMEC.hvLineNo (electrode, igap));
267 }
268 }
269 }
270 } else if (m_larhec_id->is_lar_hec(id)) { // LAr HEC
271 const HECDetectorElement* hecElement = dynamic_cast<const HECDetectorElement*>(caloMgr->get_element(id));
272 if (!hecElement) std::abort();
273 const HECCellConstLink cell = hecElement->getHECCell();
274 unsigned int nsubgaps = cell->getNumSubgaps();
275 for (unsigned int igap=0;igap<nsubgaps;igap++) {
276 const HECHVSubgap& subgap = cell->getSubgap(igap);
277 hv.insert(hvdata.m_hvdata_HEC.hvLineNo (subgap));
278 }
279 } else if (m_larfcal_id->is_lar_fcal(id)) { // LAr FCAL
280 const FCALDetectorElement* fcalElement = dynamic_cast<const FCALDetectorElement*>(caloMgr->get_element(id));
281 if (!fcalElement) std::abort();
282 const FCALTile* tile = fcalElement->getFCALTile();
283 unsigned int nlines = tile->getNumHVLines();
284 for (unsigned int i=0;i<nlines;i++) {
285 const FCALHVLine* line = tile->getHVLine(i);
286 if(line) hv.insert(hvdata.m_hvdata_FCAL.hvLineNo (*line));
287 }
288 } else if (m_larem_id->is_lar_em(id) && m_larem_id->sampling(id)==0) { // Presamplers
289 if (abs(m_larem_id->barrel_ec(id))==1) {
290 const EMBDetectorElement* embElement = dynamic_cast<const EMBDetectorElement*>(caloMgr->get_element(id));
291 if (!embElement) std::abort();
292 const EMBCellConstLink cell = embElement->getEMBCell();
293 const EMBPresamplerHVModule& hvmodule = cell->getPresamplerHVModule();
294 for (unsigned int igap=0;igap<2;igap++) hv.insert(hvdata.m_hvdata_EMBPS.hvLineNo (hvmodule, igap));
295 } else {
296 const EMECDetectorElement* emecElement = dynamic_cast<const EMECDetectorElement*>(caloMgr->get_element(id));
297 if (!emecElement) std::abort();
298 const EMECCellConstLink cell = emecElement->getEMECCell();
299 const EMECPresamplerHVModule& hvmodule = cell->getPresamplerHVModule ();
300 for (unsigned int igap=0;igap<2;igap++) hv.insert(hvdata.m_hvdata_EMECPS.hvLineNo (hvmodule, igap));
301 }
302 }
303
304 std::vector<int> hvlines;
305 for (std::set<int>::iterator i=hv.begin();i!=hv.end();++i) hvlines.push_back(*i);
306 return hvlines;
307}
308
309
#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:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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
virtual StatusCode initialize() override
SG::ReadCondHandleKey< LArHVIdMapping > m_hvCablingKey
virtual ~CaloCellCalcEnergyCorr()
Destructor:
virtual StatusCode stop() override
CaloCellCalcEnergyCorr(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
std::vector< int > m_calosample
std::vector< int > GetHVLines(const HVData &hvdata, const Identifier &id, const CaloDetDescrManager *caloMgr)
SG::ReadCondHandleKeyArray< CondAttrListCollection > m_DCSFolderKeys
std::vector< float > m_value
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
std::vector< float > m_hvvalue
virtual StatusCode finalize() override
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