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), mPedestalWidths (nullptr),
18  mEffectivePedestals (nullptr), mEffectivePedestalWidths (nullptr),
19  mGains (nullptr), mGainWidths (nullptr),
20  mQIEData(nullptr),
21  mQIETypes(nullptr),
22  mElectronicsMap(nullptr), mFrontEndMap(nullptr),
23  mRespCorrs(nullptr),
24  mL1TriggerObjects(nullptr),
25  mTimeCorrs(nullptr),
26  mLUTCorrs(nullptr),
27  mPFCorrs(nullptr),
28  mLutMetadata(nullptr),
29  mSiPMParameters(nullptr), mSiPMCharacteristics(nullptr),
30  mTPChannelParameters(nullptr), mTPParameters(nullptr),
31  mMCParams(nullptr), mRecoParams(nullptr),
32  mCalibSet(nullptr), mCalibWidthSet(nullptr)
33  {}
34 
36  delete mCalibSet.load();
37  delete mCalibWidthSet.load();
38 }
39 
41  if (mPedestals && mPedestals->topo()) return mPedestals->topo();
43  if (mGains && mGains->topo()) return mGains->topo();
44  if (mRespCorrs && mRespCorrs->topo()) return mRespCorrs->topo();
45  if (mQIETypes && mQIETypes->topo()) return mQIETypes->topo();
47  if (mLutMetadata && mLutMetadata->topo()) return mLutMetadata->topo();
48  return nullptr;
49 }
50 
51 
53 {
55  return (*mCalibSet.load(std::memory_order_acquire)).getCalibrations(fId);
56 }
57 
59 {
61  return (*mCalibWidthSet.load(std::memory_order_acquire)).getCalibrationWidths(fId);
62 }
63 
65 {
67  return mCalibSet.load(std::memory_order_acquire);
68 }
69 
71 {
73  return mCalibWidthSet.load(std::memory_order_acquire);
74 }
75 
77  // we use the set of ids for pedestals as the master list
78  if ((!mPedestals) || (!mEffectivePedestals) || (!mGains) || (!mQIEData) || (!mQIETypes) || (!mRespCorrs) || (!mTimeCorrs) || (!mLUTCorrs) ) return;
79 
80  if (!mCalibSet.load(std::memory_order_acquire)) {
81 
82  auto ptr = new HcalCalibrationsSet();
83 
84  std::vector<DetId> ids=mPedestals->getAllChannels();
85  bool pedsInADC = mPedestals->isADC();
86  bool effPedsInADC = mEffectivePedestals->isADC();
87  // loop!
88  HcalCalibrations tool;
89 
90  // std::cout << " length of id-vector: " << ids.size() << std::endl;
91  for (std::vector<DetId>::const_iterator id=ids.begin(); id!=ids.end(); ++id) {
92  // make
93  bool ok=makeHcalCalibration(*id,&tool,pedsInADC,effPedsInADC);
94  // store
95  if (ok) ptr->setCalibrations(*id,tool);
96  // std::cout << "Hcal calibrations built... detid no. " << HcalGenericDetId(*id) << std::endl;
97  }
98  HcalCalibrationsSet const * cptr = ptr;
99  HcalCalibrationsSet const * expect = nullptr;
100  bool exchanged = mCalibSet.compare_exchange_strong(expect, cptr, std::memory_order_acq_rel);
101  if(!exchanged) {
102  delete ptr;
103  }
104  }
105 }
106 
108  // we use the set of ids for pedestal widths as the master list
109  if ((!mPedestalWidths) || (!mEffectivePedestalWidths) || (!mGainWidths) || (!mQIEData) ) return;
110 
111  if (!mCalibWidthSet.load(std::memory_order_acquire)) {
112 
113  auto ptr = new HcalCalibrationWidthsSet();
114 
115  const std::vector<DetId>& ids=mPedestalWidths->getAllChannels();
116  bool pedsInADC = mPedestalWidths->isADC();
117  bool effPedsInADC = mEffectivePedestalWidths->isADC();
118  // loop!
120 
121  // std::cout << " length of id-vector: " << ids.size() << std::endl;
122  for (std::vector<DetId>::const_iterator id=ids.begin(); id!=ids.end(); ++id) {
123  // make
124  bool ok=makeHcalCalibrationWidth(*id,&tool,pedsInADC,effPedsInADC);
125  // store
126  if (ok) ptr->setCalibrationWidths(*id,tool);
127  // std::cout << "Hcal calibrations built... detid no. " << HcalGenericDetId(*id) << std::endl;
128  }
129  HcalCalibrationWidthsSet const * cptr = ptr;
130  HcalCalibrationWidthsSet const * expect = nullptr;
131  bool exchanged = mCalibWidthSet.compare_exchange_strong(expect, cptr, std::memory_order_acq_rel);
132  if(!exchanged) {
133  delete ptr;
134  }
135  }
136 }
137 
138 bool HcalDbService::convertPedestals(const HcalGenericDetId& fId, const HcalPedestal* pedestal, float* pedTrue, bool inADC) const {
139  if(!pedestal) return false;
140  const HcalQIECoder* coder = nullptr;
141  const HcalQIEShape* shape = nullptr;
142  if(inADC){
143  coder = getHcalCoder(fId);
144  shape = getHcalShape(coder);
145  if(!coder || !shape) return false;
146  }
147  for (int i=0; i<4; i++) {
148  float x=pedestal->getValues()[i];
149  if(!inADC){
150  pedTrue[i] = x;
151  continue;
152  }
153  int x1=(int)std::floor(x);
154  int x2=(int)std::floor(x+1);
155  float y2=coder->charge(*shape,x2,i);
156  float y1=coder->charge(*shape,x1,i);
157  pedTrue[i]=(y2-y1)*(x-x1)+y1;
158  }
159  return true;
160 }
161 
162 bool HcalDbService::makeHcalCalibration (const HcalGenericDetId& fId, HcalCalibrations* fObject, bool pedestalInADC, bool effPedestalInADC) const {
163  if (fObject) {
164  const HcalPedestal* pedestal = getPedestal (fId);
165  const HcalPedestal* effpedestal = getEffectivePedestal (fId);
166  const HcalGain* gain = getGain (fId);
167  const HcalRespCorr* respcorr = getHcalRespCorr (fId);
168  const HcalTimeCorr* timecorr = getHcalTimeCorr (fId);
169  const HcalLUTCorr* lutcorr = getHcalLUTCorr (fId);
170 
171  float pedTrue[4];
172  bool converted = convertPedestals(fId,pedestal,pedTrue,pedestalInADC);
173 
174  float effPedTrue[4];
175  bool effconverted = convertPedestals(fId,effpedestal,effPedTrue,effPedestalInADC);
176 
177  if (pedestal && effpedestal && converted && effconverted && gain && respcorr && timecorr && lutcorr) {
178  *fObject = HcalCalibrations (gain->getValues(), pedTrue, effPedTrue, respcorr->getValue(), timecorr->getValue(), lutcorr->getValue() );
179  return true;
180  }
181  }
182  return false;
183 }
184 
185 bool HcalDbService::convertPedestalWidths(const HcalGenericDetId& fId, const HcalPedestalWidth* pedestalwidth, float* pedTrueWidth, bool inADC) const {
186  if(!pedestalwidth) return false;
187  const HcalQIECoder* coder = nullptr;
188  const HcalQIEShape* shape = nullptr;
189  if(inADC){
190  coder = getHcalCoder(fId);
191  shape = getHcalShape(coder);
192  if(!coder || !shape) return false;
193  }
194  for (int i=0; i<4; i++) {
195  float x=pedestalwidth->getWidth(i);
196  if(!inADC){
197  pedTrueWidth[i] = x;
198  continue;
199  }
200  // assume QIE is linear in low range and use x1=0 and x2=1
201  // y = (y2-y1) * (x) [do not add any constant, only scale!]
202  float y2=coder->charge(*shape,1,i);
203  float y1=coder->charge(*shape,0,i);
204  pedTrueWidth[i]=(y2-y1)*x;
205  }
206  return true;
207 }
208 
209 
211  HcalCalibrationWidths* fObject, bool pedestalInADC, bool effPedestalInADC) const {
212  if (fObject) {
213  const HcalPedestalWidth* pedestalwidth = getPedestalWidth (fId);
214  const HcalPedestalWidth* effpedestalwidth = getEffectivePedestalWidth (fId);
215  const HcalGainWidth* gainwidth = getGainWidth (fId);
216 
217  float pedTrueWidth[4];
218  bool converted = convertPedestalWidths(fId,pedestalwidth,pedTrueWidth,pedestalInADC);
219 
220  float effPedTrueWidth[4];
221  bool effconverted = convertPedestalWidths(fId,effpedestalwidth,effPedTrueWidth,effPedestalInADC);
222  if (pedestalwidth && effpedestalwidth&& gainwidth && converted && effconverted) {
223  *fObject = HcalCalibrationWidths (gainwidth->getValues (), pedTrueWidth, effPedTrueWidth);
224  return true;
225  }
226  }
227  return false;
228 }
229 
231  if (mQIETypes) {
232  return mQIETypes->getValues (fId);
233  }
234  return nullptr;
235 }
236 
238  if (mRespCorrs) {
239  return mRespCorrs->getValues (fId);
240  }
241  return nullptr;
242 }
243 
245  if (mPedestals) {
246  return mPedestals->getValues (fId);
247  }
248  return nullptr;
249 }
250 
252  if (mPedestalWidths) {
253  return mPedestalWidths->getValues (fId);
254  }
255  return nullptr;
256 }
257 
259  if (mEffectivePedestals) {
260  return mEffectivePedestals->getValues (fId);
261  }
262  return nullptr;
263 }
264 
267  return mEffectivePedestalWidths->getValues (fId);
268  }
269  return nullptr;
270 }
271 
273  if (mGains) {
274  return mGains->getValues(fId);
275  }
276  return nullptr;
277 }
278 
280  if (mGainWidths) {
281  return mGainWidths->getValues (fId);
282  }
283  return nullptr;
284 }
285 
287  if (mQIEData) {
288  return mQIEData->getCoder (fId);
289  }
290  return nullptr;
291 }
292 
294  if (mQIEData && mQIETypes) {
295  //currently 3 types of QIEs exist: QIE8, QIE10, QIE11
296  int qieType = mQIETypes->getValues(fId)->getValue();
297  //QIE10 and QIE11 have same shape (ADC ladder)
298  if(qieType>0) qieType = 1;
299  return &mQIEData->getShape(qieType);
300  }
301  return nullptr;
302 }
303 
305  HcalGenericDetId fId(coder->rawId());
306  return getHcalShape(fId);
307 }
308 
310  return mElectronicsMap;
311 }
312 
314  return mFrontEndMap;
315 }
316 
318 {
319  return mL1TriggerObjects->getValues (fId);
320 }
321 
323 {
324  return mChannelQuality->getValues (fId);
325 }
326 
328 {
329  return mZSThresholds->getValues (fId);
330 }
331 
333  if (mTimeCorrs) {
334  return mTimeCorrs->getValues (fId);
335  }
336  return nullptr;
337 }
338 
340  if (mLUTCorrs) {
341  return mLUTCorrs->getValues (fId);
342  }
343  return nullptr;
344 }
345 
347  if (mPFCorrs) {
348  return mPFCorrs->getValues (fId);
349  }
350  return nullptr;
351 }
352 
354  return mLutMetadata;
355 }
356 
358  if (mSiPMParameters) {
359  return mSiPMParameters->getValues (fId);
360  }
361  return nullptr;
362 }
363 
365  return mSiPMCharacteristics;
366 }
367 
369  if (mTPChannelParameters) {
370  return mTPChannelParameters->getValues (fId);
371  }
372  return nullptr;
373 }
374 
376  if (mMCParams) {
377  return mMCParams->getValues (fId);
378  }
379  return nullptr;
380 }
381 
383  if (mRecoParams) {
384  return mRecoParams->getValues (fId);
385  }
386  return nullptr;
387 }
388 
390  return mTPParameters;
391 }
392 
const HcalLUTCorrs * mLUTCorrs
const HcalQIETypes * mQIETypes
const HcalPedestalWidths * mEffectivePedestalWidths
const HcalQIEShape & getShape(int qieType) const
get basic shape
Definition: HcalQIEData.h:37
const HcalGainWidth * getGainWidth(const HcalGenericDetId &fId) const
const HcalFrontEndMap * getHcalFrontEndMapping() const
const HcalSiPMParameters * mSiPMParameters
int getValue() const
Definition: HcalQIEType.h:20
bool makeHcalCalibration(const HcalGenericDetId &fId, HcalCalibrations *fObject, bool pedestalInADC, bool effPedestalInADC) const
bool isADC() const
Definition: HcalPedestals.h:28
const HcalMCParams * mMCParams
const HcalTPParameters * mTPParameters
std::atomic< HcalCalibrationWidthsSet const * > mCalibWidthSet
const HcalTPChannelParameter * getHcalTPChannelParameter(const HcalGenericDetId &fId) const
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:39
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:37
const float * getValues() const
get value for all capId = 0..3
Definition: HcalGainWidth.h:19
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:20
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:20
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:20
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
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:20
const HcalElectronicsMap * getHcalMapping() const
std::atomic< HcalCalibrationsSet const * > mCalibSet
const float * getValues() const
get value for all capId = 0..3
Definition: HcalPedestal.h:19
const HcalFrontEndMap * mFrontEndMap
const HcalPedestals * mPedestals
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
bool convertPedestalWidths(const HcalGenericDetId &fId, const HcalPedestalWidth *pedestalwidth, float *pedTrueWidth, bool inADC) const
const HcalPedestal * getPedestal(const HcalGenericDetId &fId) const
const HcalSiPMParameter * getHcalSiPMParameter(const HcalGenericDetId &fId) const
const HcalRecoParams * mRecoParams
const HcalSiPMCharacteristics * mSiPMCharacteristics
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