25#include "Gaudi/Property.h"
26#include "GaudiKernel/IToolSvc.h"
40#include "CoralBase/Blob.h"
68 return StatusCode::SUCCESS;
74 return StatusCode::SUCCESS;
82 case 1:
return fix1();
88 return StatusCode::FAILURE;
94 return StatusCode::FAILURE;
96 return fix2(cabling, clCont);
103 return StatusCode::FAILURE;
109 return StatusCode::FAILURE;
111 return fix3(cabling,sym);
113 default:
return StatusCode::SUCCESS;
127 coral::AttributeListSpecification* spec =
new coral::AttributeListSpecification();
128 spec->extend(
"Pedestal",
"blob");
129 spec->extend(
"PedestalRMS",
"blob");
130 spec->extend<
unsigned>(
"version");
136 coral::AttributeList* attrList =
new coral::AttributeList(*spec);
137 (*attrList)[
"version"].setValue(0U);
138 coral::Blob& blobPed=(*attrList)[
"Pedestal"].data<coral::Blob>();
139 coral::Blob& blobRMS=(*attrList)[
"PedestalRMS"].data<coral::Blob>();
140 blobPed.resize(hashMax*
sizeof(
float));
141 blobRMS.resize(hashMax*
sizeof(
float));
142 float* pblobPed=
static_cast<float*
>(blobPed.startingAddress());
143 float* pblobRMS=
static_cast<float*
>(blobRMS.startingAddress());
145 for (
unsigned hs=0;hs<hashMax;++hs) {
147 float p=ped->pedestal(chid,gain);
148 float rms=ped->pedestalRMS(chid,gain);
154 collPed->add(gain,*attrList);
156 StatusCode
sc=
detStore()->record(collPed,
"/LAR/ElecCalibMCSC/Pedestal");
157 if (
sc.isFailure()) {
158 ATH_MSG_ERROR(
"Failed to record CondAttrListCollection for pedestal " );
162 ATH_MSG_DEBUG(
" Number of entries changes in pedestals = " <<n );
169 spec =
new coral::AttributeListSpecification();
170 spec->extend(
"RampVec",
"blob");
171 spec->extend<
unsigned>(
"nPoints");
172 spec->extend<
unsigned>(
"version");
176 std::vector<float> defaultRamp={0.0,1.0};
182 for (
unsigned hs=0;hs<hashMax && nPoints==0;++hs) {
185 nPoints=rampref.size();
188 ATH_MSG_ERROR(
"All input Ramps for gain " << gain <<
" have 0 points!" );
189 return StatusCode::FAILURE;
192 defaultRamp.resize(nPoints,0.0);
193 ATH_MSG_DEBUG(
"Gain " << gain <<
": Found a ramp polynom of degree " << nPoints <<
" in input data" );
194 attrList =
new coral::AttributeList(*spec);
195 (*attrList)[
"version"].setValue(0U);
196 coral::Blob& blobRamp=(*attrList)[
"RampVec"].data<coral::Blob>();
197 (*attrList)[
"nPoints"].setValue(nPoints);
198 blobRamp.resize(hashMax*
sizeof(
float)*nPoints);
199 float* pblobRamp=
static_cast<float*
>(blobRamp.startingAddress());
201 for (
unsigned hs=0;hs<hashMax;++hs) {
205 if (rampVec.size()>=nPoints) {
206 for (
size_t i=0;i<nPoints;++i) {
211 std::stringstream message;
212 message <<
"Polynom degree doesn't match. Expect " << nPoints <<
", got " << rampVec.size() <<
".";
213 for (
size_t i=0;i<nPoints;++i) {
214 pblobRamp[nPoints*hs+i]=defaultRamp[i];
220 coll->add(gain,*attrList);
222 sc=
detStore()->record(coll,
"/LAR/ElecCalibMCSC/Ramp");
223 if (
sc.isFailure()) {
224 ATH_MSG_ERROR(
"Failed to record CondAttrListCollection for ramp " );
225 return StatusCode::FAILURE;
228 ATH_MSG_INFO(
"Converted Ramps to inline storage. Total number of channels " << n );
229 ATH_MSG_INFO(
"Number of channels filled with default ramp {0,1} " << nDefault <<
" (including disconnected)" );
231 return StatusCode::SUCCESS;
240 coral::AttributeListSpecification* spec_calib =
new coral::AttributeListSpecification();
241 spec_calib->extend(
"OnlineHashToCalibIds",
"blob");
242 spec_calib->extend<
unsigned>(
"version");
243 auto al_calib = std::make_unique<AthenaAttributeList>(*spec_calib);
244 coral::Blob& blobCalib=(*al_calib)[
"OnlineHashToCalibIds"].data<coral::Blob>();
245 (*al_calib)[
"version"].setValue(0U);
246 blobCalib.resize(onlHashMax*
sizeof(uint32_t)*5);
249 spec_calib->release();
250 spec_calib =
nullptr;
252 uint32_t* pBlobCalib=
static_cast<uint32_t*
>(blobCalib.startingAddress());
256 std::vector<unsigned> calibHist(17,0);
257 unsigned calibHistMax=0;
259 std::ofstream outfile(
"SCIdentifiers.txt");
261 outfile <<
"hash id bec pn FT SL chan id calo pn sampl reg eta phi calib" << std::endl;
263 for (uint32_t onlHash=0;onlHash<onlHashMax;++onlHash) {
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]);
274 if ((pLArIdBase ==
nullptr) or (pCaloCellBase==
nullptr)){
275 ATH_MSG_ERROR(
"dynamic_cast failed in FixLArElecSCCalib::fix2");
276 return StatusCode::FAILURE;
278 if (cabling->isOnlineConnected(hwid)) {
279 id=cabling->cnvToIdentifier(hwid);
280 print(hwid,pLArIdBase, pCaloCellBase,&
id,&calibIDs,outfile);
282 print(hwid,pLArIdBase, pCaloCellBase,
nullptr,&calibIDs,outfile);
284 const size_t nCalibLines=calibIDs.size();
285 if (nCalibLines > calibHistMax ) calibHistMax=nCalibLines;
286 if(calibHistMax > 17) {
287 ATH_MSG_ERROR(
"Too much calib lines, adjust please !!!" << calibHistMax);
288 return StatusCode::FAILURE;
290 (calibHist[nCalibLines])++;
291 pBlobCalib[calibIndex++]=nCalibLines;
292 for(uint32_t iCalib=0;iCalib<nCalibLines;++iCalib)
293 pBlobCalib[calibIndex++]=calibIDs[iCalib].get_identifier32().get_compact();
295 blobCalib.resize(calibIndex*
sizeof(uint32_t));
299 msg(MSG::INFO) <<
"nCalib[i] ";
300 for (
unsigned j=0;j<17;++j)
301 msg() << calibHist[j] <<
"/";
303 ATH_CHECK(
detStore()->record(std::move(al_calib),
"/LAR/IdentifierOfl/CalibIdMap_SC"));
304 return StatusCode::SUCCESS;
308 const Identifier *
id, std::vector<HWIdentifier>* calibIDs, std::ostream& out) {
312 << onlineID->
pos_neg(hwid) <<
" "
314 << onlineID->
slot(hwid) <<
" "
315 << onlineID->
channel(hwid) <<
" : ";
317 out << std::hex <<
"0x" <<
id->get_identifier32().get_compact() << std::dec <<
" "
319 << caloCellID->
pos_neg(*
id) <<
" "
321 << caloCellID->
region(*
id) <<
" "
322 << caloCellID->
eta(*
id) <<
" "
323 << caloCellID->
phi(*
id) <<
" ";
326 out <<
" disconnected ";
329 for (
size_t i=0;i<calibIDs->size();++i) {
330 out << std::hex <<
"0x" << calibIDs->at(i).get_identifier32().get_compact() <<
" ";
335 out << std::dec << std::endl;
344 auto spec =
new coral::AttributeListSpecification();
345 spec->extend(
"MinBias",
"blob");
346 spec->extend<
unsigned>(
"version");
347 auto coll=std::make_unique<CondAttrListCollection>(
true);
349 auto specav =
new coral::AttributeListSpecification();
350 specav->extend(
"MinBiasAverage",
"blob");
351 specav->extend<
unsigned>(
"version");
355 coral::AttributeList attrList = coral::AttributeList(*spec);
356 attrList[
"version"].setValue(0U);
357 coral::Blob& blob = attrList[
"MinBias"].data<coral::Blob>();
358 blob.resize(hashMax*
sizeof(
float));
359 float* pblob=
static_cast<float*
>(blob.startingAddress());
361 coral::AttributeList attrListav = coral::AttributeList(*specav);
362 attrListav[
"version"].setValue(0U);
363 coral::Blob& blobav= attrListav[
"MinBiasAverage"].data<coral::Blob>();
364 blobav.resize(hashMax*
sizeof(
float));
365 float* pblobav=
static_cast<float*
>(blobav.startingAddress());
367 std::unique_ptr<TFile> fin= std::make_unique<TFile>(
m_infile.value().c_str());
368 TTree *tin=
dynamic_cast<TTree*
>(fin->Get(
"m_tree"));
369 if (not tin)
return StatusCode::FAILURE;
371 int * identifier =
new int[2862];
372 int * layer =
new int[2862];
373 int * region =
new int[2862];
374 int * ieta =
new int[2862];
375 float *
eta =
new float[2862];
376 double * average =
new double[2862];
377 double * rms =
new double[2862];
379 TBranch *b_identifier{};
384 TBranch *b_average{};
386 tin->SetMakeClass(1);
387 tin->SetBranchAddress(
"ncell", &ncell, &b_ncell);
388 tin->SetBranchAddress(
"identifier", identifier, &b_identifier);
389 tin->SetBranchAddress(
"layer", layer, &b_layer);
390 tin->SetBranchAddress(
"region", region, &b_region);
391 tin->SetBranchAddress(
"ieta", ieta, &b_ieta);
392 tin->SetBranchAddress(
"eta",
eta, &b_eta);
393 tin->SetBranchAddress(
"average", average, &b_average);
394 tin->SetBranchAddress(
"rms", rms, &b_rms);
399 std::map<Identifier, float> vmap, vmapav;
400 for(
int icell=0; icell<ncell; ++icell) {
404 vmapav[id] = average[icell];
405 vmap[id] = rms[icell];
409 for (
unsigned onlHash=0;onlHash<hashMax;++onlHash) {
411 const Identifier id = cabling->cnvToIdentifier(hwid);
413 const Identifier idsym = cabling->cnvToIdentifier(hwid2);
414 if (vmap.count(idsym)==0 || vmapav.count(idsym)==0) {
417 pblob[onlHash] = vmap[idsym];
418 pblobav[onlHash] = vmapav[idsym];
422 coll->add(0,attrList);
423 collav->add(0,attrListav);
425 auto sz = coll->size();
427 ATH_MSG_DEBUG(
"Stored coll with size "<<
sz<<
" into /LAR/ElecCalibMCSC/MinBias");
429 auto szav = collav->size();
431 ATH_MSG_DEBUG(
"Stored coll with size "<<szav<<
" into /LAR/ElecCalibMCSC/MinBiasAverage");
433 return StatusCode::SUCCESS;
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
Helper base class for offline cell identifiers.
Helper class for offline supercell identifiers.
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
#define CHECK(...)
Evaluate an expression and check for errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
Helper base class for offline cell identifiers.
int phi(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
int sampling(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
int sub_calo(const Identifier id) const
returns an int taken from SUBCALO enum and describing the subCalo to which the Id belongs.
int region(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
int pos_neg(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
int eta(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
This class is a collection of AttributeLists where each one is associated with a channel number.
SG::ReadCondHandleKey< LArCalibLineMapping > m_CLKeySC
virtual ~FixLArElecSCCalib()
StatusCode fix2(const LArOnOffIdMapping *cabling, const LArCalibLineMapping *cl)
const LArHEC_SuperCell_ID * m_shec_idhelper
const LArEM_SuperCell_ID * m_sem_idhelper
const LArFCAL_SuperCell_ID * m_sfcal_idhelper
virtual StatusCode initialize() override
DoubleProperty m_fixFactor
virtual StatusCode execute() override
const CaloCell_SuperCell_ID * m_scell_idhelper
IntegerProperty m_fixFlag
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeySC
FixLArElecSCCalib(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< LArMCSym > m_mcSymKey
virtual StatusCode stop() override
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)
StatusCode fix3(const LArOnOffIdMapping *cabling, const LArMCSym *sym)
const LArOnline_SuperCellID * m_sonline_idhelper
LArVectorProxy RampRef_t
This class defines the interface for accessing Ramp @stereotype Interface.
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Helper class to handle z-phi symmetry of calibration constants in MC.
HWIdentifier ZPhiSymOfl(const Identifier notSymOffId) const
Find the symmetric HWID for an offline cell identifier.
Helper for the Liquid Argon Calorimeter cell identifiers.
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
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...
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
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...
virtual RampRef_t ADC2DAC(const HWIdentifier &CellID, int gain) const
std::vector< value_type > asVector() const
Convert back to a vector.