CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 (0), mPedestalWidths (0),
18  mGains (0), mGainWidths (0),
19  mQIEData(0),
20  mElectronicsMap(0),
21  mRespCorrs(0),
22  mL1TriggerObjects(0),
23  mTimeCorrs(0),
24  mLUTCorrs(0),
25  mPFCorrs(0),
26  mLutMetadata(0),
27  mCalibSet(nullptr), mCalibWidthSet(nullptr)
28  {}
29 
31  if (mPedestals && mPedestals->topo()) return mPedestals->topo();
32  if (mGains && mGains->topo()) return mGains->topo();
33  if (mRespCorrs && mRespCorrs->topo()) return mRespCorrs->topo();
35  if (mLutMetadata && mLutMetadata->topo()) return mLutMetadata->topo();
36  return 0;
37 }
38 
39 
41 {
43  return (*mCalibSet.load(std::memory_order_acquire)).getCalibrations(fId);
44 }
45 
47 {
49  return (*mCalibWidthSet.load(std::memory_order_acquire)).getCalibrationWidths(fId);
50 }
51 
53  // we use the set of ids for pedestals as the master list
54  if ((!mPedestals) || (!mGains) || (!mQIEData) || (!mRespCorrs) || (!mTimeCorrs) || (!mLUTCorrs) ) return;
55 
56  if (!mCalibSet.load(std::memory_order_acquire)) {
57 
58  auto ptr = new HcalCalibrationsSet();
59 
60  std::vector<DetId> ids=mPedestals->getAllChannels();
61  bool pedsInADC = mPedestals->isADC();
62  // loop!
63  HcalCalibrations tool;
64 
65  // std::cout << " length of id-vector: " << ids.size() << std::endl;
66  for (std::vector<DetId>::const_iterator id=ids.begin(); id!=ids.end(); ++id) {
67  // make
68  bool ok=makeHcalCalibration(*id,&tool,pedsInADC);
69  // store
70  if (ok) ptr->setCalibrations(*id,tool);
71  // std::cout << "Hcal calibrations built... detid no. " << HcalGenericDetId(*id) << std::endl;
72  }
73  ptr->sort();
74  HcalCalibrationsSet const * cptr = ptr;
75  HcalCalibrationsSet const * expect = nullptr;
76  bool exchanged = mCalibSet.compare_exchange_strong(expect, cptr, std::memory_order_acq_rel);
77  if(!exchanged) {
78  delete ptr;
79  }
80  }
81 }
82 
84  // we use the set of ids for pedestal widths as the master list
85  if ((!mPedestalWidths) || (!mGainWidths) || (!mQIEData) ) return;
86 
87  if (!mCalibWidthSet.load(std::memory_order_acquire)) {
88 
89  auto ptr = new HcalCalibrationWidthsSet();
90 
91  const std::vector<DetId>& ids=mPedestalWidths->getAllChannels();
92  bool pedsInADC = mPedestalWidths->isADC();
93  // loop!
95 
96  // std::cout << " length of id-vector: " << ids.size() << std::endl;
97  for (std::vector<DetId>::const_iterator id=ids.begin(); id!=ids.end(); ++id) {
98  // make
99  bool ok=makeHcalCalibrationWidth(*id,&tool,pedsInADC);
100  // store
101  if (ok) ptr->setCalibrationWidths(*id,tool);
102  // std::cout << "Hcal calibrations built... detid no. " << HcalGenericDetId(*id) << std::endl;
103  }
104  ptr->sort();
105 
106  HcalCalibrationWidthsSet const * cptr = ptr;
107  HcalCalibrationWidthsSet const * expect = nullptr;
108  bool exchanged = mCalibWidthSet.compare_exchange_strong(expect, cptr, std::memory_order_acq_rel);
109  if(!exchanged) {
110  delete ptr;
111  }
112  }
113 }
114 
115 bool HcalDbService::makeHcalCalibration (const HcalGenericDetId& fId, HcalCalibrations* fObject, bool pedestalInADC) const {
116  if (fObject) {
117  const HcalPedestal* pedestal = getPedestal (fId);
118  const HcalGain* gain = getGain (fId);
119  const HcalRespCorr* respcorr = getHcalRespCorr (fId);
120  const HcalTimeCorr* timecorr = getHcalTimeCorr (fId);
121  const HcalLUTCorr* lutcorr = getHcalLUTCorr (fId);
122 
123  if (pedestalInADC) {
124  const HcalQIECoder* coder=getHcalCoder(fId);
125  const HcalQIEShape* shape=getHcalShape(coder);
126  if (pedestal && gain && shape && coder && respcorr && timecorr && lutcorr) {
127  float pedTrue[4];
128  for (int i=0; i<4; i++) {
129  float x=pedestal->getValues()[i];
130  int x1=(int)std::floor(x);
131  int x2=(int)std::floor(x+1);
132  // y = (y2-y1)/(x2-x1) * (x - x1) + y1 [note: x2-x1=1]
133  float y2=coder->charge(*shape,x2,i);
134  float y1=coder->charge(*shape,x1,i);
135  pedTrue[i]=(y2-y1)*(x-x1)+y1;
136  }
137  *fObject = HcalCalibrations (gain->getValues (), pedTrue, respcorr->getValue(), timecorr->getValue(), lutcorr->getValue() );
138  return true;
139  }
140  } else {
141  if (pedestal && gain && respcorr && timecorr && lutcorr) {
142  *fObject = HcalCalibrations (gain->getValues (), pedestal->getValues (), respcorr->getValue(), timecorr->getValue(), lutcorr->getValue() );
143  return true;
144  }
145  }
146  }
147  return false;
148 }
149 
151  HcalCalibrationWidths* fObject, bool pedestalInADC) const {
152  if (fObject) {
153  const HcalPedestalWidth* pedestalwidth = getPedestalWidth (fId);
154  const HcalGainWidth* gainwidth = getGainWidth (fId);
155  if (pedestalInADC) {
156  const HcalQIECoder* coder=getHcalCoder(fId);
157  const HcalQIEShape* shape=getHcalShape(coder);
158  if (pedestalwidth && gainwidth && shape && coder) {
159  float pedTrueWidth[4];
160  for (int i=0; i<4; i++) {
161  float x=pedestalwidth->getWidth(i);
162  // assume QIE is linear in low range and use x1=0 and x2=1
163  // y = (y2-y1) * (x) [do not add any constant, only scale!]
164  float y2=coder->charge(*shape,1,i);
165  float y1=coder->charge(*shape,0,i);
166  pedTrueWidth[i]=(y2-y1)*x;
167  }
168  *fObject = HcalCalibrationWidths (gainwidth->getValues (), pedTrueWidth);
169  return true;
170  }
171  } else {
172  if (pedestalwidth && gainwidth) {
173  float pedestalWidth [4];
174  for (int i = 0; i < 4; i++) pedestalWidth [i] = pedestalwidth->getWidth (i);
175  *fObject = HcalCalibrationWidths (gainwidth->getValues (), pedestalWidth);
176  return true;
177  }
178  }
179  }
180  return false;
181 }
182 
183 
185  if (mRespCorrs) {
186  return mRespCorrs->getValues (fId);
187  }
188  return 0;
189 }
190 
192  if (mPedestals) {
193  return mPedestals->getValues (fId);
194  }
195  return 0;
196 }
197 
199  if (mPedestalWidths) {
200  return mPedestalWidths->getValues (fId);
201  }
202  return 0;
203 }
204 
206  if (mGains) {
207  return mGains->getValues(fId);
208  }
209  return 0;
210 }
211 
213  if (mGainWidths) {
214  return mGainWidths->getValues (fId);
215  }
216  return 0;
217 }
218 
220  if (mQIEData) {
221  return mQIEData->getCoder (fId);
222  }
223  return 0;
224 }
225 
227  if (mQIEData) {
228  return &mQIEData->getShape (fId);
229  }
230  return 0;
231 }
232 
234  if (mQIEData) {
235  return &mQIEData->getShape(coder);
236  }
237  return 0;
238 }
239 
240 
242  return mElectronicsMap;
243 }
244 
246 {
247  return mL1TriggerObjects->getValues (fId);
248 }
249 
251 {
252  return mChannelQuality->getValues (fId);
253 }
254 
256 {
257  return mZSThresholds->getValues (fId);
258 }
259 
261  if (mTimeCorrs) {
262  return mTimeCorrs->getValues (fId);
263  }
264  return 0;
265 }
266 
268  if (mLUTCorrs) {
269  return mLUTCorrs->getValues (fId);
270  }
271  return 0;
272 }
273 
275  if (mPFCorrs) {
276  return mPFCorrs->getValues (fId);
277  }
278  return 0;
279 }
280 
282  return mLutMetadata;
283 }
284 
const HcalLUTCorrs * mLUTCorrs
Definition: HcalDbService.h:88
const HcalGainWidth * getGainWidth(const HcalGenericDetId &fId) const
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:237
bool isADC() const
Definition: HcalPedestals.h:28
std::atomic< HcalCalibrationWidthsSet const * > mCalibWidthSet
Definition: HcalDbService.h:93
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:40
const HcalChannelStatus * getHcalChannelStatus(const HcalGenericDetId &fId) const
const HcalL1TriggerObjects * mL1TriggerObjects
Definition: HcalDbService.h:86
const HcalPFCorrs * mPFCorrs
Definition: HcalDbService.h:89
const Item * getValues(DetId fId, bool throwOnFail=true) const
const HcalGains * mGains
Definition: HcalDbService.h:79
#define nullptr
const HcalChannelQuality * mChannelQuality
Definition: HcalDbService.h:82
const HcalLutMetadata * mLutMetadata
Definition: HcalDbService.h:90
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
bool makeHcalCalibration(const HcalGenericDetId &fId, HcalCalibrations *fObject, bool pedestalInADC) const
const HcalQIEShape & getShape(DetId fId) const
get basic shape
Definition: HcalQIEData.h:37
const HcalLutMetadata * getHcalLutMetadata() const
bool makeHcalCalibrationWidth(const HcalGenericDetId &fId, HcalCalibrationWidths *fObject, bool pedestalInADC) const
const float * getValues() const
get value for all capId = 0..3
Definition: HcalGain.h:20
const HcalPedestalWidths * mPedestalWidths
Definition: HcalDbService.h:78
const HcalRespCorrs * mRespCorrs
Definition: HcalDbService.h:84
const HcalCalibrationWidths & getHcalCalibrationWidths(const HcalGenericDetId &fId) const
HcalDbService(const edm::ParameterSet &)
const HcalZSThreshold * getHcalZSThreshold(const HcalGenericDetId &fId) const
const HcalElectronicsMap * mElectronicsMap
Definition: HcalDbService.h:83
const HcalGainWidths * mGainWidths
Definition: HcalDbService.h:80
const HcalTimeCorrs * mTimeCorrs
Definition: HcalDbService.h:87
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
float getValue() const
Definition: HcalLUTCorr.h:20
const HcalPFCorr * getHcalPFCorr(const HcalGenericDetId &fId) const
const HcalTopology * getTopologyUsed() const
const HcalZSThresholds * mZSThresholds
Definition: HcalDbService.h:85
float getValue() const
Definition: HcalTimeCorr.h:20
const HcalQIEData * mQIEData
Definition: HcalDbService.h:81
const HcalGain * getGain(const HcalGenericDetId &fId) const
float getWidth(int fCapId) const
get width (sqrt(sigma_i_i)) for capId = 0..3
const HcalQIECoder * getHcalCoder(const HcalGenericDetId &fId) const
const HcalQIEShape * getHcalShape(const HcalGenericDetId &fId) const
void buildCalibrations() const
float getValue() const
Definition: HcalRespCorr.h:20
const HcalElectronicsMap * getHcalMapping() const
std::atomic< HcalCalibrationsSet const * > mCalibSet
Definition: HcalDbService.h:92
const float * getValues() const
get value for all capId = 0..3
Definition: HcalPedestal.h:19
const HcalPedestals * mPedestals
Definition: HcalDbService.h:77
Definition: DDAxes.h:10
const HcalCalibrations & getHcalCalibrations(const HcalGenericDetId &fId) const
const HcalPedestal * getPedestal(const HcalGenericDetId &fId) const
const HcalTopology * topo() const
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -&gt; fC conversion.
Definition: HcalQIECoder.cc:22