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  if (mTPChannelParameters) {
393  return mTPChannelParameters->getValues(fId);
394  }
395  return nullptr;
396 }
397 
399  if (mMCParams) {
400  return mMCParams->getValues(fId);
401  }
402  return nullptr;
403 }
404 
406  if (mRecoParams) {
407  return mRecoParams->getValues(fId);
408  }
409  return nullptr;
410 }
411 
413 
const HcalLUTCorrs * mLUTCorrs
const HcalQIETypes * mQIETypes
const HcalPedestalWidths * mEffectivePedestalWidths
const HcalQIEShape & getShape(int qieType) const
get basic shape
Definition: HcalQIEData.h:35
const HcalGainWidth * getGainWidth(const HcalGenericDetId &fId) const
const HcalFrontEndMap * getHcalFrontEndMapping() const
const HcalSiPMParameters * mSiPMParameters
int getValue() const
Definition: HcalQIEType.h:19
bool makeHcalCalibration(const HcalGenericDetId &fId, HcalCalibrations *fObject, bool pedestalInADC, bool effPedestalInADC) const
bool isADC() const
Definition: HcalPedestals.h:27
const HcalMCParams * mMCParams
const HcalTPParameters * mTPParameters
const HcalTPChannelParameter * getHcalTPChannelParameter(const HcalGenericDetId &fId) const
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:37
const HcalPedestals * mEffectivePedestals
const HcalRecoParam * getHcalRecoParam(const HcalGenericDetId &fId) const
const HcalChannelStatus * getHcalChannelStatus(const HcalGenericDetId &fId) const
#define nullptr
const HcalL1TriggerObjects * mL1TriggerObjects
const HcalPFCorrs * mPFCorrs
const Item * getValues(DetId fId, bool throwOnFail=true) const
const HcalGains * mGains
const HcalChannelQuality * mChannelQuality
const HcalLutMetadata * mLutMetadata
const HcalTPChannelParameters * mTPChannelParameters
uint32_t rawId() const
Definition: HcalQIECoder.h:36
const float * getValues() const
get value for all capId = 0..3
Definition: HcalGainWidth.h:18
std::atomic< HcalCalibrationsSet const * > mCalibSet
const HcalPedestalWidth * getPedestalWidth(const HcalGenericDetId &fId) const
const HcalRespCorr * getHcalRespCorr(const HcalGenericDetId &fId) const
const HcalLUTCorr * getHcalLUTCorr(const HcalGenericDetId &fId) const
const HcalTimeCorr * getHcalTimeCorr(const HcalGenericDetId &fId) const
void buildCalibWidths() const
std::vector< DetId > getAllChannels() const
const HcalL1TriggerObject * getHcalL1TriggerObject(const HcalGenericDetId &fId) const
const HcalPedestal * getEffectivePedestal(const HcalGenericDetId &fId) const
const HcalLutMetadata * getHcalLutMetadata() const
const HcalMCParam * getHcalMCParam(const HcalGenericDetId &fId) const
const float * getValues() const
get value for all capId = 0..3
Definition: HcalGain.h:19
const HcalPedestalWidths * mPedestalWidths
const HcalRespCorrs * mRespCorrs
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
bool makeHcalCalibrationWidth(const HcalGenericDetId &fId, HcalCalibrationWidths *fObject, bool pedestalInADC, bool effPedestalInADC) const
const HcalZSThreshold * getHcalZSThreshold(const HcalGenericDetId &fId) const
const HcalElectronicsMap * mElectronicsMap
const HcalGainWidths * mGainWidths
const HcalCalibrationsSet * getHcalCalibrationsSet() const
const HcalTimeCorrs * mTimeCorrs
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
const HcalQIEType * getHcalQIEType(const HcalGenericDetId &fId) const
float getValue() const
Definition: HcalLUTCorr.h:19
const HcalPFCorr * getHcalPFCorr(const HcalGenericDetId &fId) const
const HcalTopology * getTopologyUsed() const
const HcalZSThresholds * mZSThresholds
const HcalPedestalWidth * getEffectivePedestalWidth(const HcalGenericDetId &fId) const
float getValue() const
Definition: HcalTimeCorr.h:19
const HcalQIEData * mQIEData
const HcalGain * getGain(const HcalGenericDetId &fId) const
const HcalTPParameters * getHcalTPParameters() const
float getWidth(int fCapId) const
get width (sqrt(sigma_i_i)) for capId = 0..3
const HcalSiPMCharacteristics * getHcalSiPMCharacteristics() const
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
bool convertPedestalWidths(const HcalGenericDetId &fId, const HcalPedestalWidth *pedestalwidth, const HcalPedestal *pedestal, float *pedTrueWidth, bool inADC) const
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
bool convertPedestals(const HcalGenericDetId &fId, const HcalPedestal *pedestal, float *pedTrue, bool inADC) const
void buildCalibrations() const
float getValue() const
Definition: HcalRespCorr.h:19
const HcalElectronicsMap * getHcalMapping() const
const float * getValues() const
get value for all capId = 0..3
Definition: HcalPedestal.h:18
const HcalFrontEndMap * mFrontEndMap
const HcalPedestals * mPedestals
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
const HcalPedestal * getPedestal(const HcalGenericDetId &fId) const
const HcalSiPMParameter * getHcalSiPMParameter(const HcalGenericDetId &fId) const
const HcalRecoParams * mRecoParams
const HcalSiPMCharacteristics * mSiPMCharacteristics
std::atomic< HcalCalibrationWidthsSet const * > mCalibWidthSet
const HcalCalibrationWidthsSet * getHcalCalibrationWidthsSet() const
const HcalTopology * topo() const
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
Definition: HcalQIECoder.cc:20