ATLAS Offline Software
FixLArElecSCCalib.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
24 #include "FixLArElecSCCalib.h"
25 #include "Gaudi/Property.h"
26 #include "GaudiKernel/IToolSvc.h"
27 
33 #include "StoreGate/StoreGateSvc.h"
34 
37 
40 #include "CoralBase/Blob.h"
41 
42 #include <fstream>
43 
44 FixLArElecSCCalib::FixLArElecSCCalib(const std::string& name, ISvcLocator* pSvcLocator) :
45  AthAlgorithm(name,pSvcLocator),
46  m_fixFlag(0),
47  m_em_idhelper(nullptr),
48  m_hec_idhelper(nullptr),
49  m_fcal_idhelper(nullptr),
50  m_online_idhelper(nullptr),
51  m_sem_idhelper(nullptr),
52  m_shec_idhelper(nullptr),
53  m_sfcal_idhelper(nullptr),
54  m_sonline_idhelper(nullptr),
55  m_scell_idhelper(nullptr)
56 {
57 
58  declareProperty("FixFlag", m_fixFlag);
59  declareProperty("FixFactor", m_fixFactor);
60 
61 }
62 
64 { }
65 
67  ATH_MSG_INFO ( " in initialize " );
68 
78 
81 
82  return StatusCode::SUCCESS;
83 }
84 
86 
87  ATH_MSG_INFO ( " in execute " );
88  return StatusCode::SUCCESS;
89 }
90 
92 
93  ATH_MSG_INFO ( " in stop " );
94 
95  switch(m_fixFlag) {
96  case 1: return fix1();
97  case 2: {
99  const LArOnOffIdMapping* cabling{*cablingHdl};
100  if(!cabling) {
101  ATH_MSG_ERROR( "Do not have cabling mapping from key " << m_cablingKeySC.key() );
102  return StatusCode::FAILURE;
103  }
105  const LArCalibLineMapping *clCont {*clHdl};
106  if(!clCont) {
107  ATH_MSG_ERROR( "Do not have calib line mapping !!!" );
108  return StatusCode::FAILURE;
109  }
110  return fix2(cabling, clCont);
111  }
112  default: return StatusCode::SUCCESS;
113  }
114 }
115 
117 
118  ATH_MSG_INFO ( " in fix1() " );
119 
120  // Fix1 is for scaling the Pedestals and Rams
121  int n=0;
122 
123  const LArPedestalSC *ped = nullptr;
124  CHECK(detStore()->retrieve(ped, "Pedestal_orig"));
125 
126  coral::AttributeListSpecification* spec = new coral::AttributeListSpecification();
127  spec->extend("Pedestal", "blob");
128  spec->extend("PedestalRMS", "blob");
129  spec->extend<unsigned>("version");
130 
132 
133  unsigned gain=0;
134  unsigned hashMax=m_sonline_idhelper->channelHashMax();
136  (*attrList)["version"].setValue(0U);
137  coral::Blob& blobPed=(*attrList)["Pedestal"].data<coral::Blob>();
138  coral::Blob& blobRMS=(*attrList)["PedestalRMS"].data<coral::Blob>();
139  blobPed.resize(hashMax*sizeof(float));
140  blobRMS.resize(hashMax*sizeof(float));
141  float* pblobPed=static_cast<float*>(blobPed.startingAddress());
142  float* pblobRMS=static_cast<float*>(blobRMS.startingAddress());
143 
144  for (unsigned hs=0;hs<hashMax;++hs) {
146  float p=ped->pedestal(chid,gain);
147  float rms=ped->pedestalRMS(chid,gain);
148 
149  pblobPed[hs]=p*m_fixFactor;
150  pblobRMS[hs]=rms;
151  ++n;
152  }//end loop over hash ids
153  collPed->add(gain,*attrList);
154 
155  StatusCode sc=detStore()->record(collPed,"/LAR/ElecCalibMCSC/Pedestal");
156  if (sc.isFailure()) {
157  ATH_MSG_ERROR( "Failed to record CondAttrListCollection for pedestal " );
158  return sc;
159  }
160 
161  ATH_MSG_DEBUG(" Number of entries changes in pedestals = " <<n );
162 
163  // Now ramp
164  n=0;
165  const LArRampSC *ramp = nullptr;
166  CHECK(detStore()->retrieve(ramp, "Ramp_orig"));
167 
168  spec = new coral::AttributeListSpecification();
169  spec->extend("RampVec", "blob");
170  spec->extend<unsigned>("nPoints");
171  spec->extend<unsigned>("version");
173 
174 
175  std::vector<float> defaultRamp={0.0,1.0};
176 
177  gain=0;
178 
179  unsigned nPoints=0;
180  unsigned nDefault=0;
181  for (unsigned hs=0;hs<hashMax && nPoints==0;++hs) {
183  const ILArRamp::RampRef_t rampref= ramp->ADC2DAC(chid,gain);
184  nPoints=rampref.size();
185  }
186  if (nPoints==0) {
187  ATH_MSG_ERROR( "All input Ramps for gain " << gain << " have 0 points!" );
188  return StatusCode::FAILURE;
189  }
190 
191  defaultRamp.resize(nPoints,0.0); //fill remaining points if needed
192  ATH_MSG_DEBUG( "Gain " << gain << ": Found a ramp polynom of degree " << nPoints << " in input data" );
193  attrList = new coral::AttributeList(*spec);
194  (*attrList)["version"].setValue(0U);
195  coral::Blob& blobRamp=(*attrList)["RampVec"].data<coral::Blob>();
196  (*attrList)["nPoints"].setValue(nPoints);
197  blobRamp.resize(hashMax*sizeof(float)*nPoints);
198  float* pblobRamp=static_cast<float*>(blobRamp.startingAddress());
199 
200  for (unsigned hs=0;hs<hashMax;++hs) {
202  std::vector<float> rampVec(ramp->ADC2DAC(chid,gain).asVector());
203 
204  if (rampVec.size()>=nPoints) {
205  for (size_t i=0;i<nPoints;++i) {
206  pblobRamp[nPoints*hs+i]=rampVec[i]*m_fixFactor;
207  }
208  }
209  else {
210  std::stringstream message;
211  message <<"Polynom degree doesn't match. Expect " << nPoints << ", got " << rampVec.size() << ".";
212  for (size_t i=0;i<nPoints;++i) {
213  pblobRamp[nPoints*hs+i]=defaultRamp[i];
214  }
215  ++nDefault;
216  }
217  ++n;
218  }//end loop over hash ids
219  coll->add(gain,*attrList);
220 
221  sc=detStore()->record(coll,"/LAR/ElecCalibMCSC/Ramp");
222  if (sc.isFailure()) {
223  ATH_MSG_ERROR( "Failed to record CondAttrListCollection for ramp " );
224  return StatusCode::FAILURE;
225  }
226 
227  ATH_MSG_INFO( "Converted Ramps to inline storage. Total number of channels " << n );
228  ATH_MSG_INFO( "Number of channels filled with default ramp {0,1} " << nDefault << " (including disconnected)" );
229 
230  return StatusCode::SUCCESS;
231 }
232 
234 
235  ATH_MSG_INFO ( " in fix2() " );
236 
237  const uint32_t onlHashMax=m_sonline_idhelper->channelHashMax(); // all SC cells
238 
239  coral::AttributeListSpecification* spec_calib = new coral::AttributeListSpecification();
240  spec_calib->extend("OnlineHashToCalibIds", "blob");
241  spec_calib->extend<unsigned>("version");
242  AthenaAttributeList* al_calib = new AthenaAttributeList(*spec_calib);
243  coral::Blob& blobCalib=(*al_calib)["OnlineHashToCalibIds"].data<coral::Blob>();
244  (*al_calib)["version"].setValue(0U);
245  blobCalib.resize(onlHashMax*sizeof(uint32_t)*5); //Bigger than necessary
246  ATH_MSG_DEBUG("blobCalib size: "<<onlHashMax<<"*5");
247 
248  spec_calib->release();
249  spec_calib = nullptr;
250 
251  uint32_t* pBlobCalib=static_cast<uint32_t*>(blobCalib.startingAddress());
252 
253  size_t calibIndex=0;
254 
255  std::vector<unsigned> calibHist(17,0);
256  unsigned calibHistMax=0;
257 
258  std::ofstream outfile("SCIdentifiers.txt");
259 
260  outfile << "hash id bec pn FT SL chan id calo pn sampl reg eta phi calib" << std::endl;
261 
262  for (uint32_t onlHash=0;onlHash<onlHashMax;++onlHash) {
263  const HWIdentifier hwid=m_sonline_idhelper->channel_Id(onlHash);
264 
265  const std::vector<HWIdentifier>& calibIDs_tmp=cl->calibSlotLine(hwid);
266  std::vector<HWIdentifier> calibIDs;
267  for (unsigned i=0; i<calibIDs_tmp.size(); ++i) {
268  if(std::find(calibIDs.begin(), calibIDs.end(), calibIDs_tmp[i]) == calibIDs.end()) calibIDs.push_back(calibIDs_tmp[i]);
269  }
270  // deduplicate
271  Identifier *id= new Identifier();
272  if (cabling->isOnlineConnected(hwid)) {
273  *id=cabling->cnvToIdentifier(hwid);
274  print(hwid,dynamic_cast<const LArOnlineID_Base*>(m_sonline_idhelper), dynamic_cast<const CaloCell_Base_ID*>(m_scell_idhelper),
275  id,&calibIDs,outfile);
276  } else {
277  print(hwid,dynamic_cast<const LArOnlineID_Base*>(m_sonline_idhelper), dynamic_cast<const CaloCell_Base_ID*>(m_scell_idhelper),
278  nullptr,&calibIDs,outfile);
279  }
280  const size_t nCalibLines=calibIDs.size();
281  if (nCalibLines > calibHistMax ) calibHistMax=nCalibLines;
282  if(calibHistMax > 17) {
283  ATH_MSG_ERROR( "Too much calib lines, adjust please !!!" << calibHistMax);
284  return StatusCode::FAILURE;
285  }
286  (calibHist[nCalibLines])++;
287  pBlobCalib[calibIndex++]=nCalibLines;
288  for(uint32_t iCalib=0;iCalib<nCalibLines;++iCalib)
289  pBlobCalib[calibIndex++]=calibIDs[iCalib].get_identifier32().get_compact();
290  }
291 
292  blobCalib.resize(calibIndex*sizeof(uint32_t)); //Size down to actual size
293 
294 
295  outfile.close();
296 
297  ATH_MSG_INFO( "calibHistMax: " << calibHistMax);
298  ATH_MSG_INFO( "BlobSize CalibId:" << calibIndex);
299  msg(MSG::INFO) << "nCalib[i] ";
300  for (unsigned j=0;j<17;++j)
301  msg() << calibHist[j] << "/";
302  msg() << endmsg;
303 
304  ATH_CHECK(detStore()->record(al_calib,"/LAR/IdentifierOfl/CalibIdMap_SC"));
305 
306  return StatusCode::SUCCESS;
307 }
308 
309 void FixLArElecSCCalib::print (const HWIdentifier& hwid, const LArOnlineID_Base* onlineID, const CaloCell_Base_ID* caloCellID,
310  const Identifier *id, std::vector<HWIdentifier>* calibIDs, std::ostream& out) {
311  const IdentifierHash hwid_hash=onlineID->channel_Hash(hwid);
312  out << hwid_hash << " " << std::hex << "0x" << hwid.get_identifier32().get_compact() << std::dec << " "
313  << onlineID->barrel_ec(hwid) << " "
314  << onlineID->pos_neg(hwid) << " "
315  << onlineID->feedthrough(hwid) << " "
316  << onlineID->slot(hwid) << " "
317  << onlineID->channel(hwid) << " : ";
318  if (id) {
319  out << std::hex << "0x" << id->get_identifier32().get_compact() << std::dec << " "
320  << caloCellID->sub_calo(*id) << " "
321  << caloCellID->pos_neg(*id) << " "
322  << caloCellID->sampling(*id) << " "
323  << caloCellID->region(*id) << " "
324  << caloCellID->eta(*id) << " "
325  << caloCellID->phi(*id) << " ";
326  }
327  else
328  out << " disconnected ";
329 
330  if(calibIDs){
331  for (size_t i=0;i<calibIDs->size();++i) {
332  out << std::hex << "0x" << calibIDs->at(i).get_identifier32().get_compact() << " ";
333  }
334  } else
335  out << " no calib ";
336 
337  out << std::dec << std::endl;
338 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArOnlineID_Base::channel_Hash
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
Definition: LArOnlineID_Base.cxx:1636
LArEM_ID.h
CaloCell_Base_ID::region
int region(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
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
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
FixLArElecSCCalib::m_hec_idhelper
const LArHEC_ID * m_hec_idhelper
Definition: FixLArElecSCCalib.h:58
FixLArElecSCCalib::~FixLArElecSCCalib
virtual ~FixLArElecSCCalib()
Definition: FixLArElecSCCalib.cxx:63
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCell_Base_ID::pos_neg
int pos_neg(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
LArCalibLineMapping
Definition: LArCalibLineMapping.h:17
LArPedestalSC.h
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArRampSC.h
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
LArRampSC
Definition: LArRampSC.h:18
FixLArElecSCCalib::m_scell_idhelper
const CaloCell_SuperCell_ID * m_scell_idhelper
Definition: FixLArElecSCCalib.h:65
LArOnlineID_Base::slot
int slot(const HWIdentifier id) const
Return the slot number of a hardware cell identifier: slot = [1,15] Slot-ID in top part of the crat...
Definition: LArOnlineID_Base.cxx:1961
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
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
FixLArElecSCCalib::initialize
virtual StatusCode initialize() override
Definition: FixLArElecSCCalib.cxx:66
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::barrel_ec
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
Definition: LArOnlineID_Base.cxx:1942
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
AthenaAttributeList.h
ReweightUtils.message
message
Definition: ReweightUtils.py:15
FixLArElecSCCalib::fix2
StatusCode fix2(const LArOnOffIdMapping *cabling, const LArCalibLineMapping *cl)
Definition: FixLArElecSCCalib.cxx:233
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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
FixLArElecSCCalib::fix1
StatusCode fix1()
Definition: FixLArElecSCCalib.cxx:116
FixLArElecSCCalib.h
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1967
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
FixLArElecSCCalib::m_shec_idhelper
const LArHEC_SuperCell_ID * m_shec_idhelper
Definition: FixLArElecSCCalib.h:62
lumiFormat.i
int i
Definition: lumiFormat.py:92
CreatePhysValWebPage.hs
hs
Definition: CreatePhysValWebPage.py:107
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
beamspotman.n
n
Definition: beamspotman.py:731
CaloCell_Base_ID::sampling
int sampling(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloCell_Base_ID.h
Helper base class for offline cell identifiers.
FixLArElecSCCalib::m_sem_idhelper
const LArEM_SuperCell_ID * m_sem_idhelper
Definition: FixLArElecSCCalib.h:61
LArOnlineID_Base::channel_Id
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
Definition: LArOnlineID_Base.cxx:1569
LArPedestalSC
Definition: LArPedestalSC.h:21
LArOnlineID_Base::pos_neg
int pos_neg(const HWIdentifier id) const
Return the side of a hardware cell identifier pos_neg = [0,1] positive-side or negative-side Barrel...
Definition: LArOnlineID_Base.cxx:1954
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
CaloCell_Base_ID::eta
int eta(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
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
AthenaAttributeList
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Definition: PersistentDataModel/PersistentDataModel/AthenaAttributeList.h:45
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AthAlgorithm
Definition: AthAlgorithm.h:47
FixLArElecSCCalib::m_em_idhelper
const LArEM_ID * m_em_idhelper
Definition: FixLArElecSCCalib.h:57
LArOnlineID_Base
Helper for the Liquid Argon Calorimeter cell identifiers.
Definition: LArOnlineID_Base.h:105
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FixLArElecSCCalib::execute
virtual StatusCode execute() override
Definition: FixLArElecSCCalib.cxx:85
FixLArElecSCCalib::print
void print(const HWIdentifier &hwid, const LArOnlineID_Base *onlineID, const CaloCell_Base_ID *caloCellID, const Identifier *id=nullptr, std::vector< HWIdentifier > *calibIDs=nullptr, std::ostream &out=std::cout)
Definition: FixLArElecSCCalib.cxx:309
FixLArElecSCCalib::FixLArElecSCCalib
FixLArElecSCCalib(const std::string &name, ISvcLocator *pSvcLocator)
Definition: FixLArElecSCCalib.cxx:44
LArOnlineID_Base::channelHashMax
size_type channelHashMax(void) const
Define channel hash tables max size.
Definition: LArOnlineID_Base.cxx:1901
FixLArElecSCCalib::m_CLKeySC
SG::ReadCondHandleKey< LArCalibLineMapping > m_CLKeySC
Definition: FixLArElecSCCalib.h:49
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCell_Base_ID::phi
int phi(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
LArRampSC::ADC2DAC
virtual RampRef_t ADC2DAC(const HWIdentifier &CellID, int gain) const
Definition: LArRampSC.cxx:26
Example_ReadSampleNoise.ped
ped
Definition: Example_ReadSampleNoise.py:45
FixLArElecSCCalib::m_sfcal_idhelper
const LArFCAL_SuperCell_ID * m_sfcal_idhelper
Definition: FixLArElecSCCalib.h:63
FixLArElecSCCalib::m_cablingKeySC
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeySC
Definition: FixLArElecSCCalib.h:48
LArOnlineID_Base::feedthrough
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
Definition: LArOnlineID_Base.cxx:1948
FixLArElecSCCalib::m_fixFactor
double m_fixFactor
Definition: FixLArElecSCCalib.h:53
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArVectorProxy::asVector
std::vector< value_type > asVector() const
Convert back to a vector.
beamspotnt.rms
rms
Definition: bin/beamspotnt.py:1266
FixLArElecSCCalib::m_fixFlag
int m_fixFlag
Definition: FixLArElecSCCalib.h:52
LArOnline_SuperCellID.h
FixLArElecSCCalib::m_fcal_idhelper
const LArFCAL_ID * m_fcal_idhelper
Definition: FixLArElecSCCalib.h:59
IdentifierHash
Definition: IdentifierHash.h:38
FixLArElecSCCalib::m_online_idhelper
const LArOnlineID * m_online_idhelper
Definition: FixLArElecSCCalib.h:60
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
CaloGain.h
CaloCell_Base_ID
Helper base class for offline cell identifiers.
Definition: CaloCell_Base_ID.h:41
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
StoreGateSvc.h
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
FixLArElecSCCalib::stop
virtual StatusCode stop() override
Definition: FixLArElecSCCalib.cxx:91
LArVectorProxy
Proxy for accessing a range of float values like a vector.
Definition: LArVectorProxy.h:38
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
FixLArElecSCCalib::m_sonline_idhelper
const LArOnline_SuperCellID * m_sonline_idhelper
Definition: FixLArElecSCCalib.h:64