ATLAS Offline Software
Loading...
Searching...
No Matches
LArHVCorrToSCHVCorr.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <fstream>
9
12
14#include "CoralBase/Blob.h"
18
19
20
22 ISvcLocator* pSvcLocator ) :
23 ::AthCondAlgorithm( name, pSvcLocator )
24{
25}
26
28{
29
30 ATH_CHECK(m_scidTool.retrieve());
31 ATH_CHECK(m_cablingKeySC.initialize());
32 ATH_CHECK(m_cablingKey.initialize());
33 ATH_CHECK(m_contKey.initialize());
34 ATH_CHECK(m_outKey.initialize(!m_outKey.empty()));
35
36 return StatusCode::SUCCESS;
37}
38
39
41{
42
43 //Retrieve HVCorr for regular cells
44 const EventContext& ctx = Gaudi::Hive::currentContext();
46 if(!hvHdl.isValid()) {
47 ATH_MSG_ERROR( "Do not have HVScaleCorr from key " << m_contKey.key() );
48 return StatusCode::FAILURE;
49 }
50
51 //Retrieve SuperCell online id
52 const LArOnline_SuperCellID* onlSCID = nullptr;
53 CHECK(detStore()->retrieve(onlSCID));
54
56 const LArOnOffIdMapping* cabling{*cablingHdl};
57 if(!cabling) {
58 ATH_MSG_ERROR( "Do not have cabling mapping from key " << m_cablingKey.key() );
59 return StatusCode::FAILURE;
60 }
61
63 const LArOnOffIdMapping* cablingSC{*cablingHdlSC};
64 if(!cablingSC) {
65 ATH_MSG_ERROR( "Do not have cabling mapping from key " << m_cablingKeySC.key() );
66 return StatusCode::FAILURE;
67 }
68
69 const CaloCell_SuperCell_ID* calosccellID=nullptr;
70 ATH_CHECK( detStore()->retrieve (calosccellID, "CaloCell_SuperCell_ID") );
71 const unsigned hashMax=calosccellID->calo_cell_hash_max();
72 ATH_MSG_INFO("SuperCell hash max: " << hashMax);
73
74 // get the HEC layer weights
75 std::string file = PathResolver::find_file (m_weightsName.value(), "JOBOPTSEARCHPATH");
76 ATH_MSG_INFO( "Reading file " << file << " configured: " << m_weightsName.value() );
77 std::ifstream fin(file.c_str());
78 if (!fin.is_open()) {
79 ATH_MSG_ERROR( "Could not open input file " << file );
80 return StatusCode::FAILURE;
81 }
82 std::string line;
83 int ttbin;
84 float em0,em1,em2,em3,em4;
85 float had0,had1,had2,had3;
86 std::map<int,std::vector<float> > wmap;
87 while (std::getline(fin, line)){
88 int nread = sscanf(line.c_str(), "%d %f %f %f %f %f %f %f %f %f",
89 &ttbin,&em0,&em1,&em2,&em3,&em4,&had0,&had1,&had2,&had3);
90 if(nread != 10) continue;
91 wmap[ttbin]=std::vector<float>{had0,had1,had2,had3};
92 }
93 // need also online ID helper
94 const LArHEC_ID* hecID = nullptr;
95 ATH_CHECK(detStore()->retrieve(hecID,"LArHEC_ID"));
96
97 //Set up AttributeListCollection
98 coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
99 spec->extend("HVScaleCorr", "blob");
100 spec->extend<unsigned>("version");
101
102 coral::AttributeList attrList(*spec);
103 attrList["version"].setValue(0U);
104 coral::Blob& hvBlob=attrList["HVScaleCorr"].data<coral::Blob>();
105
106 spec->release();
107 // cppcheck-suppress memleak
108 spec = nullptr;
109
110 // Important, blob is ordered by LAr online hash, but LArHVCorr by cell offline hash !!!!
111 hvBlob.resize(onlSCID->channelHashMax()*sizeof(float));
112
113 float *pHV=static_cast<float*>(hvBlob.startingAddress());
114 std::vector<float> vScale;
115 //Initialize blobs to ERRORCODE
116 for (unsigned i=0;i<onlSCID->channelHashMax();++i) {
118 }
119 if(!m_outKey.empty()) vScale.resize(hashMax,(float)1.0);
120
121 unsigned nFilledIds=0;
122 unsigned nTotalIds=0;
123 for (unsigned i=0; i < hashMax; ++i) {
124 if(calosccellID->sub_calo(IdentifierHash(i)) > 2) continue; // not a LAr channel
125 const Identifier scId=calosccellID->cell_id(IdentifierHash(i));
126 nTotalIds += 1;
127 const std::vector<Identifier> &cellIds=m_scidTool->superCellToOfflineID(scId);
128 if (cellIds.empty()) {
129 ATH_MSG_ERROR("Got empty vector of cell ids for super cell id 0x"
130 << std::hex << scId.get_compact()<<std::dec);
131 return StatusCode::FAILURE;
132 }
133 float hvcorr=0.;
134 float weight=1.;
135 float wsum=0.;
136 for(const Identifier cellId : cellIds) {
137 if(hecID->is_lar_hec(cellId)) { // find a weight
138 weight = getWeight(hecID,cellId,wmap);
139 }
140 hvcorr += weight * hvHdl->HVScaleCorr(cabling->createSignalChannelID(cellId));
141 wsum += weight;
142 }
143 if(wsum>0.) hvcorr /= wsum;
144 nFilledIds += 1;
145 if (m_isHI) {
146 // Hack for excessive corr. in EMBC
147 // this part is eventually needed for HI running
148 //if(hvcorr >= 1.6 && calosccellID->is_em_barrel(scId) ) {
149 if(hvcorr >= 1.6 ) {
150 ATH_MSG_INFO("Set manually HVCorr to "<<m_patchHI<<" for SC "<< scId.get_identifier32().get_compact()<<" "<<calosccellID->cell_name(scId));
151 ATH_MSG_INFO( calosccellID->is_em_barrel(scId) << " " << calosccellID->pos_neg(scId));
152 hvcorr=m_patchHI;
153 }
154 }
155
156 // Important, blob is ordered by LAr online hash, but LArHVCorr by cell offline hash !!!!
157 pHV[onlSCID->channel_Hash(cablingSC->createSignalChannelID(scId))]=hvcorr;
158
159 if(!m_outKey.empty()) vScale[i]=hvcorr;
160
161 }//end loop over super-cell hash
162
163 //Add to collection
165 CHECK(detStore()->record(coll,m_folderName));
166 coll->add(0,attrList);
167
168 ATH_MSG_INFO("Total number of SuperCells:" << nTotalIds << ", filled:" << nFilledIds);
169
170 if(!m_outKey.empty()) {
172 const EventIDRange fullRange=IOVInfiniteRange::infiniteMixed();
173 writeHandle.addDependency (fullRange);
174 writeHandle.addDependency(hvHdl);
175 writeHandle.addDependency(cablingHdl);
176 writeHandle.addDependency(cablingHdlSC);
177
178 auto scHvCorr = std::make_unique<LArHVCorr>(std::move(vScale), cablingSC, calosccellID);
179 if (writeHandle.record(std::move(scHvCorr)).isFailure()) {
180 ATH_MSG_ERROR("Could not record LArHVCorr object with " << m_outKey.key()
181 << " with EventRange " << writeHandle.getRange() << " into Conditions Store");
182 return StatusCode::FAILURE;
183 }
184 ATH_MSG_INFO("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
185 }
186 return StatusCode::SUCCESS;
187}
188
189float LArHVCorrToSCHVCorr::getWeight(const LArHEC_ID *hecID, const Identifier &id, std::map<int,std::vector<float> > &wmap) {
190 int side = hecID->pos_neg(id);
191 int reg = hecID->region(id);
192 int eta = hecID->eta(id);
193 int ttbin=0;
194 switch(side){
195 case -2: if(reg==0) ttbin=-16-eta; else ttbin=-27-2*eta; if(ttbin==-33) ttbin=-32; break;
196 case 2: if(reg==0) ttbin=15+eta; else ttbin=25+2*eta;
197 }
198 if(ttbin!=0 && wmap.find(ttbin) != wmap.end()){
199 ATH_MSG_DEBUG("Found weight "<<wmap[ttbin][hecID->sampling(id)] <<" for "<<side<<" "<<reg<<" "<<eta);
200 return wmap[ttbin][hecID->sampling(id)];
201 } else {
202 ATH_MSG_DEBUG("Returning 1 for "<<side<<" "<<reg<<" "<<eta);
203 return 1.;
204 }
205}
206
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Helper class for offline supercell identifiers.
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Defines a common ERRORCODE enum for LAr-Calibration objects.
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
bool is_lar_hec(Identifier id) const
std::string cell_name(const Identifier id) const
Returns the cell-location in a human readable form.
bool is_em_barrel(const Identifier id) const
test if the id belongs to the EM barrel
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
size_type calo_cell_hash_max() const
cell 'global' hash table max size
int pos_neg(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
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 supercell identifiers.
This class is a collection of AttributeLists where each one is associated with a channel number.
bool add(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs.
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
int region(const Identifier id) const
return region [0,1]
int eta(const Identifier id) const
return eta [0,9] outer part [0,3] inner part
int pos_neg(const Identifier id) const
return pos_neg -2 (C side) or 2 (A side)
int sampling(const Identifier id) const
return sampling [0,3] (only 0 for supercells)
Helper class for LArHEC offline identifiers.
Definition LArHEC_ID.h:76
float getWeight(const LArHEC_ID *hecID, const Identifier &id, std::map< int, std::vector< float > > &wmap)
LArHVCorrToSCHVCorr(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeySC
SG::ReadCondHandleKey< ILArHVScaleCorr > m_contKey
virtual StatusCode initialize() override
SG::WriteCondHandleKey< LArHVCorr > m_outKey
StringProperty m_folderName
ToolHandle< ICaloSuperCellIDTool > m_scidTool
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
StringProperty m_weightsName
virtual StatusCode stop() override
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
size_type channelHashMax() const
Define channel hash tables max size.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
TFile * file