ATLAS Offline Software
LArHVCorrToSCHVCorr.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <fstream>
6 #include "LArHVCorrToSCHVCorr.h"
9 
12 
14 #include "CoralBase/Blob.h"
18 
19 
20 
22  ISvcLocator* pSvcLocator ) :
23  ::AthAlgorithm( name, pSvcLocator )
24 {
25 }
26 
28 {
29 
30  ATH_CHECK(m_scidTool.retrieve());
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  //Retrive 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 
146  // Important, blob is ordered by LAr online hash, but LArHVCorr by cell offline hash !!!!
147  pHV[onlSCID->channel_Hash(cablingSC->createSignalChannelID(scId))]=hvcorr;
148 
149  if(!m_outKey.empty()) vScale[i]=hvcorr;
150 
151  }//end loop over super-cell hash
152 
153  //Add to collection
155  CHECK(detStore()->record(coll,m_folderName));
156  coll->add(0,attrList);
157 
158  ATH_MSG_INFO("Total number of SuperCells:" << nTotalIds << ", filled:" << nFilledIds);
159 
160  if(!m_outKey.empty()) {
161  SG::WriteCondHandle<LArHVCorr> writeHandle{m_outKey, ctx};
162  const EventIDRange fullRange=IOVInfiniteRange::infiniteMixed();
163  writeHandle.addDependency (fullRange);
164  writeHandle.addDependency(hvHdl);
165  writeHandle.addDependency(cablingHdl);
166  writeHandle.addDependency(cablingHdlSC);
167 
168  auto scHvCorr = std::make_unique<LArHVCorr>(std::move(vScale), cablingSC, calosccellID);
169  if (writeHandle.record(std::move(scHvCorr)).isFailure()) {
170  ATH_MSG_ERROR("Could not record LArHVCorr object with " << m_outKey.key()
171  << " with EventRange " << writeHandle.getRange() << " into Conditions Store");
172  return StatusCode::FAILURE;
173  }
174  ATH_MSG_INFO("Recorded new " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
175  ILArHVScaleCorr *imscale = nullptr;
176  if(detStore()->symLink(scHvCorr.get(), imscale).isFailure()) {
177  ATH_MSG_WARNING("Could not symlink " << writeHandle.key() << " to ILArHVScaleCorr");
178  }
179  }
180  return StatusCode::SUCCESS;
181 }
182 
183 float LArHVCorrToSCHVCorr::getWeight(const LArHEC_ID *hecID, const Identifier &id, std::map<int,std::vector<float> > &wmap) {
184  int side = hecID->pos_neg(id);
185  int reg = hecID->region(id);
186  int eta = hecID->eta(id);
187  int ttbin=0;
188  switch(side){
189  case -2: if(reg==0) ttbin=-16-eta; else ttbin=-27-2*eta; if(ttbin==-33) ttbin=-32; break;
190  case 2: if(reg==0) ttbin=15+eta; else ttbin=25+2*eta;
191  }
192  if(ttbin!=0 && wmap.find(ttbin) != wmap.end()){
193  ATH_MSG_DEBUG("Found weight "<<wmap[ttbin][hecID->sampling(id)] <<" for "<<side<<" "<<reg<<" "<<eta);
194  return wmap[ttbin][hecID->sampling(id)];
195  } else {
196  ATH_MSG_DEBUG("Returning 1 for "<<side<<" "<<reg<<" "<<eta);
197  return 1.;
198  }
199 }
200 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArHVCorrToSCHVCorr::initialize
virtual StatusCode initialize() override
Definition: LArHVCorrToSCHVCorr.cxx:27
LArHVCorrToSCHVCorr::stop
virtual StatusCode stop() override
Definition: LArHVCorrToSCHVCorr.cxx:40
checkFileSG.line
line
Definition: checkFileSG.py:75
LArOnlineID_Base::channel_Hash
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
Definition: LArOnlineID_Base.cxx:1636
ILArHVScaleCorr
Definition: ILArHVScaleCorr.h:13
LArHVCorrToSCHVCorr::LArHVCorrToSCHVCorr
LArHVCorrToSCHVCorr(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: LArHVCorrToSCHVCorr.cxx:21
LArHEC_Base_ID::eta
int eta(const Identifier id) const
return eta [0,9] outer part [0,3] inner part
LArHVCorrToSCHVCorr::m_scidTool
ToolHandle< ICaloSuperCellIDTool > m_scidTool
Definition: LArHVCorrToSCHVCorr.h:49
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
LArHVCorrToSCHVCorr::m_cablingKeySC
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeySC
Definition: LArHVCorrToSCHVCorr.h:39
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
IOVInfiniteRange::infiniteMixed
static EventIDRange infiniteMixed()
Produces an mixed EventIDRange that is infinite in Time and RunLumi.
Definition: IOVInfiniteRange.h:55
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
LArHEC_ID
Helper class for LArHEC offline identifiers.
Definition: LArHEC_ID.h:85
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
LArHVCorrToSCHVCorr::m_contKey
SG::ReadCondHandleKey< ILArHVScaleCorr > m_contKey
Definition: LArHVCorrToSCHVCorr.h:41
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
LArCalibErrorCode.h
Defines a common ERRORCODE enum for LAr-Calibration objects.
ICaloSuperCellIDTool.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArHVCorrToSCHVCorr::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArHVCorrToSCHVCorr.h:40
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
TRT::Hit::side
@ side
Definition: HitInfo.h:83
LArHVCorrToSCHVCorr::m_weightsName
StringProperty m_weightsName
Definition: LArHVCorrToSCHVCorr.h:47
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCell_SuperCell_ID
Helper class for offline supercell identifiers.
Definition: CaloCell_SuperCell_ID.h:48
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArHVCorrToSCHVCorr::m_folderName
StringProperty m_folderName
Definition: LArHVCorrToSCHVCorr.h:45
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
file
TFile * file
Definition: tile_monitor.h:29
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
CaloCell_Base_ID::sub_calo
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AtlasDetectorID::is_lar_hec
bool is_lar_hec(Identifier id) const
Definition: AtlasDetectorID.h:829
LArHVCorrToSCHVCorr.h
AthAlgorithm
Definition: AthAlgorithm.h:47
IOVInfiniteRange.h
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArOnlineID_Base::channelHashMax
size_type channelHashMax(void) const
Define channel hash tables max size.
Definition: LArOnlineID_Base.cxx:1901
errorcheck.h
Helpers for checking error return status codes and reporting errors.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCell_Base_ID::cell_id
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,...
LArOnline_SuperCellID
Definition: LArOnline_SuperCellID.h:20
LArHVCorrToSCHVCorr::getWeight
float getWeight(const LArHEC_ID *hecID, const Identifier &id, std::map< int, std::vector< float > > &wmap)
Definition: LArHVCorrToSCHVCorr.cxx:183
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArHEC_Base_ID::sampling
int sampling(const Identifier id) const
return sampling [0,3] (only 0 for supercells)
LArHEC_Base_ID::pos_neg
int pos_neg(const Identifier id) const
return pos_neg -2 (C side) or 2 (A side)
LArOnline_SuperCellID.h
compute_lumi.fin
fin
Definition: compute_lumi.py:19
LArElecCalib::ERRORCODE
@ ERRORCODE
Definition: LArCalibErrorCode.h:17
ILArHVScaleCorr::HVScaleCorr
virtual const float & HVScaleCorr(const HWIdentifier &id) const =0
LArHVCorrToSCHVCorr::m_outKey
SG::WriteCondHandleKey< LArHVCorr > m_outKey
Definition: LArHVCorrToSCHVCorr.h:43
IdentifierHash
Definition: IdentifierHash.h:38
CondAttrListCollection::add
bool add(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs.
Definition: CondAttrListCollection.h:452
LArHEC_Base_ID::region
int region(const Identifier id) const
return region [0,1]
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
readCCLHist.float
float
Definition: readCCLHist.py:83
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max(void) const
cell 'global' hash table max size
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20