CMS 3D CMS Logo

HcalDbService.cc
Go to the documentation of this file.
1 //
2 // F.Ratnikov (UMd), Aug. 9, 2005
3 //
4 
6 
11 
13 
14 #include <cmath>
15 
17  : mPedestals(nullptr),
18  mPedestalWidths(nullptr),
19  mEffectivePedestals(nullptr),
20  mEffectivePedestalWidths(nullptr),
21  mGains(nullptr),
22  mGainWidths(nullptr),
23  mQIEData(nullptr),
24  mQIETypes(nullptr),
25  mElectronicsMap(nullptr),
26  mFrontEndMap(nullptr),
27  mRespCorrs(nullptr),
28  mL1TriggerObjects(nullptr),
29  mTimeCorrs(nullptr),
30  mLUTCorrs(nullptr),
31  mPFCorrs(nullptr),
32  mLutMetadata(nullptr),
33  mSiPMParameters(nullptr),
34  mSiPMCharacteristics(nullptr),
35  mTPChannelParameters(nullptr),
36  mTPParameters(nullptr),
37  mMCParams(nullptr),
38  mRecoParams(nullptr),
39  mCalibSet(nullptr),
40  mCalibWidthSet(nullptr) {}
41 
43  delete mCalibSet.load();
44  delete mCalibWidthSet.load();
45 }
46 
48  if (mPedestals && mPedestals->topo())
49  return mPedestals->topo();
51  return mEffectivePedestals->topo();
52  if (mGains && mGains->topo())
53  return mGains->topo();
54  if (mRespCorrs && mRespCorrs->topo())
55  return mRespCorrs->topo();
56  if (mQIETypes && mQIETypes->topo())
57  return mQIETypes->topo();
59  return mL1TriggerObjects->topo();
60  if (mLutMetadata && mLutMetadata->topo())
61  return mLutMetadata->topo();
62  return nullptr;
63 }
64 
67  return (*mCalibSet.load(std::memory_order_acquire)).getCalibrations(fId);
68 }
69 
72  return (*mCalibWidthSet.load(std::memory_order_acquire)).getCalibrationWidths(fId);
73 }
74 
77  return mCalibSet.load(std::memory_order_acquire);
78 }
79 
82  return mCalibWidthSet.load(std::memory_order_acquire);
83 }
84 
86  // we use the set of ids for pedestals as the master list
87  if ((!mPedestals) || (!mEffectivePedestals) || (!mGains) || (!mQIEData) || (!mQIETypes) || (!mRespCorrs) ||
88  (!mTimeCorrs) || (!mLUTCorrs))
89  return;
90 
91  if (!mCalibSet.load(std::memory_order_acquire)) {
92  auto ptr = new HcalCalibrationsSet();
93 
94  std::vector<DetId> ids = mPedestals->getAllChannels();
95  bool pedsInADC = mPedestals->isADC();
96  bool effPedsInADC = mEffectivePedestals->isADC();
97  // loop!
98  HcalCalibrations tool;
99 
100  // std::cout << " length of id-vector: " << ids.size() << std::endl;
101  for (std::vector<DetId>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
102  // make
103  bool ok = makeHcalCalibration(*id, &tool, pedsInADC, effPedsInADC);
104  // store
105  if (ok)
106  ptr->setCalibrations(*id, tool);
107  // std::cout << "Hcal calibrations built... detid no. " << HcalGenericDetId(*id) << std::endl;
108  }
109  HcalCalibrationsSet const* cptr = ptr;
110  HcalCalibrationsSet const* expect = nullptr;
111  bool exchanged = mCalibSet.compare_exchange_strong(expect, cptr, std::memory_order_acq_rel);
112  if (!exchanged) {
113  delete ptr;
114  }
115  }
116 }
117 
119  // we use the set of ids for pedestal widths as the master list
121  return;
122 
123  if (!mCalibWidthSet.load(std::memory_order_acquire)) {
124  auto ptr = new HcalCalibrationWidthsSet();
125 
126  const std::vector<DetId>& ids = mPedestalWidths->getAllChannels();
127  bool pedsInADC = mPedestalWidths->isADC();
128  bool effPedsInADC = mEffectivePedestalWidths->isADC();
129  // loop!
131 
132  // std::cout << " length of id-vector: " << ids.size() << std::endl;
133  for (std::vector<DetId>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
134  // make
135  bool ok = makeHcalCalibrationWidth(*id, &tool, pedsInADC, effPedsInADC);
136  // store
137  if (ok)
138  ptr->setCalibrationWidths(*id, tool);
139  // std::cout << "Hcal calibrations built... detid no. " << HcalGenericDetId(*id) << std::endl;
140  }
141  HcalCalibrationWidthsSet const* cptr = ptr;
142  HcalCalibrationWidthsSet const* expect = nullptr;
143  bool exchanged = mCalibWidthSet.compare_exchange_strong(expect, cptr, std::memory_order_acq_rel);
144  if (!exchanged) {
145  delete ptr;
146  }
147  }
148 }
149 
151  const HcalPedestal* pedestal,
152  float* pedTrue,
153  bool inADC) const {
154  if (!pedestal)
155  return false;
156  const HcalQIECoder* coder = nullptr;
157  const HcalQIEShape* shape = nullptr;
158  if (inADC) {
159  coder = getHcalCoder(fId);
160  shape = getHcalShape(coder);
161  if (!coder || !shape)
162  return false;
163  }
164  for (int i = 0; i < 4; i++) {
165  float x = pedestal->getValues()[i];
166  if (!inADC) {
167  pedTrue[i] = x;
168  continue;
169  }
170  int x1 = (int)std::floor(x);
171  int x2 = (int)std::floor(x + 1);
172  float y2 = coder->charge(*shape, x2, i);
173  float y1 = coder->charge(*shape, x1, i);
174  pedTrue[i] = (y2 - y1) * (x - x1) + y1;
175  }
176  return true;
177 }
178 
180  HcalCalibrations* fObject,
181  bool pedestalInADC,
182  bool effPedestalInADC) const {
183  if (fObject) {
184  const HcalPedestal* pedestal = getPedestal(fId);
185  const HcalPedestal* effpedestal = getEffectivePedestal(fId);
186  const HcalGain* gain = getGain(fId);
187  const HcalRespCorr* respcorr = getHcalRespCorr(fId);
188  const HcalTimeCorr* timecorr = getHcalTimeCorr(fId);
189  const HcalLUTCorr* lutcorr = getHcalLUTCorr(fId);
190 
191  float pedTrue[4];
192  bool converted = convertPedestals(fId, pedestal, pedTrue, pedestalInADC);
193 
194  float effPedTrue[4];
195  bool effconverted = convertPedestals(fId, effpedestal, effPedTrue, effPedestalInADC);
196 
197  if (pedestal && effpedestal && converted && effconverted && gain && respcorr && timecorr && lutcorr) {
198  *fObject = HcalCalibrations(
199  gain->getValues(), pedTrue, effPedTrue, respcorr->getValue(), timecorr->getValue(), lutcorr->getValue());
200  return true;
201  }
202  }
203  return false;
204 }
205 
207  const HcalPedestalWidth* pedestalwidth,
208  const HcalPedestal* pedestal,
209  float* pedTrueWidth,
210  bool inADC) const {
211  if (!pedestalwidth)
212  return false;
213  const HcalQIECoder* coder = nullptr;
214  const HcalQIEShape* shape = nullptr;
215  if (inADC) {
216  coder = getHcalCoder(fId);
217  shape = getHcalShape(coder);
218  if (!coder || !shape)
219  return false;
220  }
221  for (int i = 0; i < 4; i++) {
222  float x = pedestalwidth->getWidth(i);
223  if (!inADC) {
224  pedTrueWidth[i] = x;
225  continue;
226  }
227  float y = pedestal->getValues()[i];
228  unsigned x1 = static_cast<unsigned>(std::floor(y));
229  unsigned x2 = static_cast<unsigned>(std::floor(y + 1.));
230  unsigned iun = static_cast<unsigned>(i);
231  float y1 = coder->charge(*shape, x1, iun);
232  float y2 = coder->charge(*shape, x2, iun);
233  pedTrueWidth[i] = (y2 - y1) * x;
234  }
235  return true;
236 }
237 
239  HcalCalibrationWidths* fObject,
240  bool pedestalInADC,
241  bool effPedestalInADC) const {
242  if (fObject) {
243  const HcalPedestal* pedestal = getPedestal(fId);
244  const HcalPedestal* effpedestal = getEffectivePedestal(fId);
245 
246  const HcalPedestalWidth* pedestalwidth = getPedestalWidth(fId);
247  const HcalPedestalWidth* effpedestalwidth = getEffectivePedestalWidth(fId);
248  const HcalGainWidth* gainwidth = getGainWidth(fId);
249 
250  float pedTrueWidth[4];
251  bool converted = convertPedestalWidths(fId, pedestalwidth, pedestal, pedTrueWidth, pedestalInADC);
252 
253  float effPedTrueWidth[4];
254  bool effconverted = convertPedestalWidths(fId, effpedestalwidth, effpedestal, effPedTrueWidth, effPedestalInADC);
255  if (pedestalwidth && effpedestalwidth && gainwidth && converted && effconverted) {
256  *fObject = HcalCalibrationWidths(gainwidth->getValues(), pedTrueWidth, effPedTrueWidth);
257  return true;
258  }
259  }
260  return false;
261 }
262 
264  if (mQIETypes) {
265  return mQIETypes->getValues(fId);
266  }
267  return nullptr;
268 }
269 
271  if (mRespCorrs) {
272  return mRespCorrs->getValues(fId);
273  }
274  return nullptr;
275 }
276 
278  if (mPedestals) {
279  return mPedestals->getValues(fId);
280  }
281  return nullptr;
282 }
283 
285  if (mPedestalWidths) {
286  return mPedestalWidths->getValues(fId);
287  }
288  return nullptr;
289 }
290 
292  if (mEffectivePedestals) {
293  return mEffectivePedestals->getValues(fId);
294  }
295  return nullptr;
296 }
297 
300  return mEffectivePedestalWidths->getValues(fId);
301  }
302  return nullptr;
303 }
304 
306  if (mGains) {
307  return mGains->getValues(fId);
308  }
309  return nullptr;
310 }
311 
313  if (mGainWidths) {
314  return mGainWidths->getValues(fId);
315  }
316  return nullptr;
317 }
318 
320  if (mQIEData) {
321  return mQIEData->getCoder(fId);
322  }
323  return nullptr;
324 }
325 
327  if (mQIEData && mQIETypes) {
328  //currently 3 types of QIEs exist: QIE8, QIE10, QIE11
329  int qieType = mQIETypes->getValues(fId)->getValue();
330  //QIE10 and QIE11 have same shape (ADC ladder)
331  if (qieType > 0)
332  qieType = 1;
333  return &mQIEData->getShape(qieType);
334  }
335  return nullptr;
336 }
337 
339  HcalGenericDetId fId(coder->rawId());
340  return getHcalShape(fId);
341 }
342 
344 
346 
348  return mL1TriggerObjects->getValues(fId);
349 }
350 
352  return mChannelQuality->getValues(fId);
353 }
354 
356  return mZSThresholds->getValues(fId);
357 }
358 
360  if (mTimeCorrs) {
361  return mTimeCorrs->getValues(fId);
362  }
363  return nullptr;
364 }
365 
367  if (mLUTCorrs) {
368  return mLUTCorrs->getValues(fId);
369  }
370  return nullptr;
371 }
372 
374  if (mPFCorrs) {
375  return mPFCorrs->getValues(fId);
376  }
377  return nullptr;
378 }
379 
381 
383  if (mSiPMParameters) {
384  return mSiPMParameters->getValues(fId);
385  }
386  return nullptr;
387 }
388 
390 
392  bool throwOnFail) const {
393  if (mTPChannelParameters) {
394  return mTPChannelParameters->getValues(fId, throwOnFail);
395  }
396  return nullptr;
397 }
398 
400  if (mMCParams) {
401  return mMCParams->getValues(fId);
402  }
403  return nullptr;
404 }
405 
407  if (mRecoParams) {
408  return mRecoParams->getValues(fId);
409  }
410  return nullptr;
411 }
412 
414 
const HcalLUTCorrs * mLUTCorrs
const HcalQIETypes * mQIETypes
const HcalPedestalWidths * mEffectivePedestalWidths
const float * getValues() const
get value for all capId = 0..3
Definition: HcalGainWidth.h:18
const HcalGainWidth * getGainWidth(const HcalGenericDetId &fId) const
const HcalSiPMParameters * mSiPMParameters
const HcalZSThreshold * getHcalZSThreshold(const HcalGenericDetId &fId) const
const HcalPedestal * getPedestal(const HcalGenericDetId &fId) const
const HcalMCParams * mMCParams
const HcalTPParameters * mTPParameters
float getValue() const
Definition: HcalLUTCorr.h:22
int getValue() const
Definition: HcalQIEType.h:19
const HcalPedestals * mEffectivePedestals
bool convertPedestalWidths(const HcalGenericDetId &fId, const HcalPedestalWidth *pedestalwidth, const HcalPedestal *pedestal, float *pedTrueWidth, bool inADC) const
bool convertPedestals(const HcalGenericDetId &fId, const HcalPedestal *pedestal, float *pedTrue, bool inADC) const
const HcalL1TriggerObjects * mL1TriggerObjects
const HcalCalibrationWidthsSet * getHcalCalibrationWidthsSet() const
const HcalPFCorrs * mPFCorrs
const HcalElectronicsMap * getHcalMapping() const
const HcalGains * mGains
const HcalChannelQuality * mChannelQuality
const HcalPedestalWidth * getPedestalWidth(const HcalGenericDetId &fId) const
const HcalLutMetadata * mLutMetadata
const HcalTPChannelParameters * mTPChannelParameters
const Item * getValues(DetId fId, bool throwOnFail=true) const
const HcalSiPMCharacteristics * getHcalSiPMCharacteristics() const
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
std::atomic< HcalCalibrationsSet const * > mCalibSet
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:37
const HcalMCParam * getHcalMCParam(const HcalGenericDetId &fId) const
const HcalCalibrationsSet * getHcalCalibrationsSet() const
const HcalTopology * topo() const
const HcalQIEShape & getShape(int qieType) const
get basic shape
Definition: HcalQIEData.h:35
void buildCalibrations() const
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
const HcalRespCorr * getHcalRespCorr(const HcalGenericDetId &fId) const
const HcalLutMetadata * getHcalLutMetadata() const
bool makeHcalCalibrationWidth(const HcalGenericDetId &fId, HcalCalibrationWidths *fObject, bool pedestalInADC, bool effPedestalInADC) const
float getValue() const
Definition: HcalTimeCorr.h:19
const HcalTopology * getTopologyUsed() const
const HcalL1TriggerObject * getHcalL1TriggerObject(const HcalGenericDetId &fId) const
std::vector< DetId > getAllChannels() const
const HcalLUTCorr * getHcalLUTCorr(const HcalGenericDetId &fId) const
const HcalTPChannelParameter * getHcalTPChannelParameter(const HcalGenericDetId &fId, bool throwOnFail=true) const
const HcalPedestalWidths * mPedestalWidths
const HcalPFCorr * getHcalPFCorr(const HcalGenericDetId &fId) const
const HcalRespCorrs * mRespCorrs
void buildCalibWidths() const
const HcalTPParameters * getHcalTPParameters() const
const HcalElectronicsMap * mElectronicsMap
const HcalGainWidths * mGainWidths
const HcalTimeCorrs * mTimeCorrs
const HcalRecoParam * getHcalRecoParam(const HcalGenericDetId &fId) const
const HcalPedestal * getEffectivePedestal(const HcalGenericDetId &fId) const
const HcalPedestalWidth * getEffectivePedestalWidth(const HcalGenericDetId &fId) const
float getValue() const
Definition: HcalRespCorr.h:19
const HcalZSThresholds * mZSThresholds
bool makeHcalCalibration(const HcalGenericDetId &fId, HcalCalibrations *fObject, bool pedestalInADC, bool effPedestalInADC) const
const HcalQIEData * mQIEData
const HcalGain * getGain(const HcalGenericDetId &fId) const
bool isADC() const
Definition: HcalPedestals.h:30
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
const HcalFrontEndMap * mFrontEndMap
const HcalPedestals * mPedestals
const HcalSiPMParameter * getHcalSiPMParameter(const HcalGenericDetId &fId) const
uint32_t rawId() const
Definition: HcalQIECoder.h:36
const HcalRecoParams * mRecoParams
const HcalFrontEndMap * getHcalFrontEndMapping() const
const HcalTimeCorr * getHcalTimeCorr(const HcalGenericDetId &fId) const
const HcalSiPMCharacteristics * mSiPMCharacteristics
std::atomic< HcalCalibrationWidthsSet const * > mCalibWidthSet
const HcalQIEType * getHcalQIEType(const HcalGenericDetId &fId) const
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
Definition: HcalQIECoder.cc:20
float getWidth(int fCapId) const
get width (sqrt(sigma_i_i)) for capId = 0..3
const HcalChannelStatus * getHcalChannelStatus(const HcalGenericDetId &fId) const