CMS 3D CMS Logo

CastorDbService.cc
Go to the documentation of this file.
1 //
2 // F.Ratnikov (UMd), Aug. 9, 2005
3 // Adapted for CASTOR by L. Mundim
4 //
5 
7 
11 
13 
14 #include <cmath>
15 
17  : mPedestals(nullptr),
18  mPedestalWidths(nullptr),
19  mGains(nullptr),
20  mGainWidths(nullptr),
21  mQIEData(nullptr),
22  mChannelQuality(nullptr),
23  mElectronicsMap(nullptr) {}
24 
26  CastorCalibrations* fObject,
27  bool pedestalInADC) const {
28  if (fObject) {
29  const CastorPedestal* pedestal = getPedestal(fId);
30  const CastorGain* gain = getGain(fId);
31 
32  if (pedestalInADC) {
34  const CastorQIECoder* coder = getCastorCoder(fId);
35  if (pedestal && gain && shape && coder) {
36  float pedTrue[4];
37  for (int i = 0; i < 4; i++) {
38  float x = pedestal->getValues()[i];
39  int x1 = (int)std::floor(x);
40  int x2 = (int)std::floor(x + 1);
41  // y = (y2-y1)/(x2-x1) * (x - x1) + y1 [note: x2-x1=1]
42  float y2 = coder->charge(*shape, x2, i);
43  float y1 = coder->charge(*shape, x1, i);
44  pedTrue[i] = (y2 - y1) * (x - x1) + y1;
45  }
46  *fObject = CastorCalibrations(gain->getValues(), pedTrue);
47  return true;
48  }
49  } else {
50  if (pedestal && gain) {
51  *fObject = CastorCalibrations(gain->getValues(), pedestal->getValues());
52  return true;
53  }
54  }
55  }
56  return false;
57 }
58 
60  // we use the set of ids for pedestals as the master list
61  if ((!mPedestals) || (!mGains) || (!mQIEData))
62  return;
63  std::vector<DetId> ids = mPedestals->getAllChannels();
64  bool pedsInADC = mPedestals->isADC();
65  // clear the calibrations set
66  mCalibSet.clear();
67  // loop!
68  CastorCalibrations tool;
69 
70  // std::cout << " length of id-vector: " << ids.size() << std::endl;
71  for (std::vector<DetId>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
72  // make
73  bool ok = makeCastorCalibration(*id, &tool, pedsInADC);
74  // store
75  if (ok)
76  mCalibSet.setCalibrations(*id, tool);
77  // std::cout << "Castor calibrations built... detid no. " << HcalGenericDetId(*id) << std::endl;
78  }
79  mCalibSet.sort();
80 }
81 
83  // we use the set of ids for pedestal widths as the master list
84  if ((!mPedestalWidths) || (!mGainWidths) || (!mQIEData))
85  return;
86 
87  std::vector<DetId> ids = mPedestalWidths->getAllChannels();
88  bool pedsInADC = mPedestalWidths->isADC();
89  // clear the calibrations set
91  // loop!
93 
94  // std::cout << " length of id-vector: " << ids.size() << std::endl;
95  for (std::vector<DetId>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
96  // make
97  bool ok = makeCastorCalibrationWidth(*id, &tool, pedsInADC);
98  // store
99  if (ok)
101  // std::cout << "Castor calibrations built... detid no. " << HcalGenericDetId(*id) << std::endl;
102  }
104 }
105 
107  CastorCalibrationWidths* fObject,
108  bool pedestalInADC) const {
109  if (fObject) {
110  const CastorPedestalWidth* pedestalwidth = getPedestalWidth(fId);
111  const CastorGainWidth* gainwidth = getGainWidth(fId);
112  if (pedestalInADC) {
114  const CastorQIECoder* coder = getCastorCoder(fId);
115  if (pedestalwidth && gainwidth && shape && coder) {
116  float pedTrueWidth[4];
117  for (int i = 0; i < 4; i++) {
118  float x = pedestalwidth->getWidth(i);
119  // assume QIE is linear in low range and use x1=0 and x2=1
120  // y = (y2-y1) * (x) [do not add any constant, only scale!]
121  float y2 = coder->charge(*shape, 1, i);
122  float y1 = coder->charge(*shape, 0, i);
123  pedTrueWidth[i] = (y2 - y1) * x;
124  }
125  *fObject = CastorCalibrationWidths(gainwidth->getValues(), pedTrueWidth);
126  return true;
127  }
128  } else {
129  if (pedestalwidth && gainwidth) {
130  float pedestalWidth[4];
131  for (int i = 0; i < 4; i++)
132  pedestalWidth[i] = pedestalwidth->getWidth(i);
133  *fObject = CastorCalibrationWidths(gainwidth->getValues(), pedestalWidth);
134  return true;
135  }
136  }
137  }
138  return false;
139 }
140 
142  if (mPedestals) {
143  return mPedestals->getValues(fId);
144  }
145  return nullptr;
146 }
147 
149  if (mPedestalWidths) {
150  return mPedestalWidths->getValues(fId);
151  }
152  return nullptr;
153 }
154 
156  if (mGains) {
157  return mGains->getValues(fId);
158  }
159  return nullptr;
160 }
161 
163  if (mGainWidths) {
164  return mGainWidths->getValues(fId);
165  }
166  return nullptr;
167 }
168 
170  if (mQIEData) {
171  return mQIEData->getCoder(fId);
172  }
173  return nullptr;
174 }
175 
177  if (mQIEData) {
178  return &mQIEData->getShape();
179  }
180  return nullptr;
181 }
182 
184 
186  return mChannelQuality->getValues(fId);
187 }
188 
float charge(const CastorQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
bool isADC() const
const Item * getValues(DetId fId, bool throwOnFail=true) const
void setCalibrationWidths(const DetId id, const CastorCalibrationWidths &ca)
const CastorQIEData * mQIEData
const CastorPedestals * mPedestals
const float * getValues() const
get value for all capId = 0..3
const CastorGainWidth * getGainWidth(const HcalGenericDetId &fId) const
const CastorGainWidths * mGainWidths
std::vector< DetId > getAllChannels() const
const CastorQIEShape * getCastorShape() const
const CastorElectronicsMap * mElectronicsMap
CastorCalibrationsSet mCalibSet
void setCalibrations(const DetId id, const CastorCalibrations &ca)
const CastorGain * getGain(const HcalGenericDetId &fId) const
bool makeCastorCalibrationWidth(const HcalGenericDetId &fId, CastorCalibrationWidths *fObject, bool pedestalInADC) const
const CastorElectronicsMap * getCastorMapping() const
const CastorPedestalWidths * mPedestalWidths
const CastorPedestalWidth * getPedestalWidth(const HcalGenericDetId &fId) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
const CastorPedestal * getPedestal(const HcalGenericDetId &fId) const
const CastorChannelQuality * mChannelQuality
const CastorGains * mGains
CastorCalibrationWidthsSet mCalibWidthSet
const CastorQIEShape & getShape() const
get basic shape
Definition: CastorQIEData.h:35
const CastorChannelStatus * getCastorChannelStatus(const HcalGenericDetId &fId) const
const CastorQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: CastorQIEData.h:37
const CastorQIECoder * getCastorCoder(const HcalGenericDetId &fId) const
float getWidth(int fCapId) const
get width (sqrt(sigma_i_i)) for capId = 0..3
bool makeCastorCalibration(const HcalGenericDetId &fId, CastorCalibrations *fObject, bool pedestalInADC) const