CMS 3D CMS Logo

HcalDbHardcode.cc
Go to the documentation of this file.
1 //
2 // F.Ratnikov (UMd), Dec 14, 2005
3 //
4 #include <vector>
5 #include <string>
6 #include <cmath>
7 #include <sstream>
8 #include <iostream>
9 #include <memory>
10 #include <cassert>
11 
12 #include "CLHEP/Random/RandGauss.h"
17 
19  : //"generic" set of conditions
20  theDefaultParameters_(3.0, //pedestal
21  0.5, //pedestal width
22  {0.2, 0.2}, //gains
23  {0.0, 0.0}, //gain widths
24  0, //ZS threshold
25  0, //QIE type
26  {0.0, 0.0, 0.0, 0.0}, //QIE offsets
27  {0.9, 0.9, 0.9, 0.9}, //QIE slopes
28  125, //MC shape
29  105, //Reco shape
30  0.0, //photoelectronsToAnalog
31  {0.0}, //dark current
32  {0.0}, //noise correlation
33  0.0, //PF noise threshold
34  0.1 //PF seed threshold
35  ),
36  setHB_(false),
37  setHE_(false),
38  setHF_(false),
39  setHO_(false),
40  setHBUpgrade_(false),
41  setHEUpgrade_(false),
42  setHFUpgrade_(false),
43  useHBUpgrade_(false),
44  useHEUpgrade_(false),
45  useHOUpgrade_(true),
46  useHFUpgrade_(false),
47  testHFQIE10_(false),
48  testHEPlan1_(false) {}
49 
54  else if (!useHBUpgrade_ && setHB_)
55  return theHBParameters_;
56  else
57  return theDefaultParameters_;
58  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
59  bool b_isHEPlan1 = testHEPlan1_ ? isHEPlan1(fId) : false;
60  if ((useHEUpgrade_ || b_isHEPlan1) && setHEUpgrade_)
62  else if (!useHEUpgrade_ && !b_isHEPlan1 && setHE_)
63  return theHEParameters_;
64  else
65  return theDefaultParameters_;
66  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenForward) {
69  else if (testHFQIE10_ && fId.isHcalDetId()) {
70  HcalDetId hid(fId);
71  //special mixed case for HF 2016
72  if (hid.iphi() == 39 && hid.zside() == 1 &&
73  (hid.depth() >= 3 || (hid.depth() == 2 && (hid.ieta() == 30 || hid.ieta() == 34))) && setHFUpgrade_)
75  else if (setHF_)
76  return theHFParameters_;
77  else
78  return theDefaultParameters_;
79  } else if (!useHFUpgrade_ && setHF_)
80  return theHFParameters_;
81  else
82  return theDefaultParameters_;
83  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
84  if (setHO_)
85  return theHOParameters_;
86  else
87  return theDefaultParameters_;
88  } else
89  return theDefaultParameters_;
90 }
91 
93  int index = 0;
95  HcalDetId hid(fId);
96  if ((hid.ieta() > -5) && (hid.ieta() < 5))
97  index = 0;
98  else
99  index = 1;
100  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenForward) {
101  HcalDetId hid(fId);
102  if (hid.depth() % 2 == 1)
103  index = 0; //depths 1,3
104  else if (hid.depth() % 2 == 0)
105  index = 1; //depths 2,4
106  }
107  return index;
108 }
109 
111  HcalGenericDetId fId, bool fSmear, bool eff, const HcalTopology* topo, double intlumi) {
113  float value0 = getParameters(fId).pedestal();
114  if (eff) {
115  //account for dark current + crosstalk
116  auto sipmpar = makeHardcodeSiPMParameter(fId, topo, intlumi);
117  auto sipmchar = makeHardcodeSiPMCharacteristics();
118  value0 += sipmpar.getDarkCurrent() * 25. / (1. - sipmchar->getCrossTalk(sipmpar.getType()));
119  }
120  float value[4] = {value0, value0, value0, value0};
121  if (fSmear) {
122  for (int i = 0; i < 4; i++) {
123  value[i] = 0.0f;
124  while (value[i] <= 0.0f)
125  // ignore correlations, assume 10K pedestal run
126  value[i] = value0 + (float)CLHEP::RandGauss::shoot(0.0, width.getWidth(i) / 100.);
127  }
128  }
129  HcalPedestal result(fId.rawId(), value[0], value[1], value[2], value[3]);
130  return result;
131 }
132 
134  bool eff,
135  const HcalTopology* topo,
136  double intlumi) {
137  float value = getParameters(fId).pedestalWidth();
138  float width2 = value * value;
139  // everything in fC
140 
141  if (eff) {
142  //account for dark current + crosstalk
143  auto sipmpar = makeHardcodeSiPMParameter(fId, topo, intlumi);
144  auto sipmchar = makeHardcodeSiPMCharacteristics();
145  //add in quadrature
146  width2 += sipmpar.getDarkCurrent() * 25. / std::pow(1 - sipmchar->getCrossTalk(sipmpar.getType()), 3) *
147  sipmpar.getFCByPE();
148  }
149 
151  for (int i = 0; i < 4; i++) {
152  for (int j = 0; j < 4; j++) {
153  result.setSigma(i, j, 0.0);
154  }
155  result.setSigma(i, i, width2);
156  }
157  return result;
158 }
159 
160 HcalGain HcalDbHardcode::makeGain(HcalGenericDetId fId, bool fSmear) const { // GeV/fC
162  float value0 = getParameters(fId).gain(getGainIndex(fId));
163  float value[4] = {value0, value0, value0, value0};
164  if (fSmear) {
165  for (int i = 0; i < 4; i++) {
166  value[i] = 0.0f;
167  while (value[i] <= 0.0f)
168  value[i] = value0 + (float)CLHEP::RandGauss::shoot(0.0, width.getValue(i));
169  }
170  }
171  HcalGain result(fId.rawId(), value[0], value[1], value[2], value[3]);
172  return result;
173 }
174 
176  float value = getParameters(fId).gainWidth(getGainIndex(fId));
178  return result;
179 }
180 
181 HcalPFCut HcalDbHardcode::makePFCut(HcalGenericDetId fId, double intLumi, bool noHE) const { // GeV
182 
183  // assign default dummy parameters
184  float value0 = getParameters(fId).noiseThreshold();
185  float value1 = getParameters(fId).seedThreshold();
186 
187  if (noHE && fId.genericSubdet() == HcalGenericDetId::HcalGenBarrel) { // HB Phase2
188 
189  // aging-independent (lumi=0) intialization for Phase2 using "HBphase1" numbers
190  const float cuts_Phase1[] = {0.1, 0.2, 0.3, 0.3};
191  const float seeds_Phase1[] = {0.125, 0.25, 0.35, 0.35};
192 
193  HcalDetId hid(fId);
194  int depth_m1 = hid.depth() - 1;
195  value0 = cuts_Phase1[depth_m1];
196  value1 = seeds_Phase1[depth_m1];
197 
198  // lumi-dependent stuff for Phase2 from SLHCUpgradeSimulations/Configuration/python/aging.py
199  const double lumis[] = {300, 1000, 3000, 4500}; // integrated lumi points
200  // row by row initialization
201  const float cuts[4][4] = {{0.4, 0.5, 0.6, 0.6}, {0.8, 1.2, 1.2, 1.2}, {1.0, 2.0, 2.0, 2.0}, {1.25, 2.5, 2.5, 2.5}};
202  const float seeds[4][4] = {
203  {0.5, 0.625, 0.75, 0.75}, {1.0, 1.5, 1.5, 1.5}, {1.25, 2.5, 2.5, 2.5}, {1.5, 3.0, 3.0, 3.0}};
204  const double eps = 1.e-6;
205 
206  for (int i = 0; i < 4; i++) {
207  if (std::abs(intLumi - lumis[i]) < eps) {
208  value0 = cuts[i][depth_m1];
209  value1 = seeds[i][depth_m1];
210  }
211  }
212  }
213 
214  HcalPFCut result(fId.rawId(), value0, value1);
215  return result;
216 }
217 
219  int value = getParameters(fId).zsThreshold();
221  return result;
222 }
223 
225  HcalQIECoder result(fId.rawId());
226  // slope in ADC/fC
227  const HcalHardcodeParameters& param(getParameters(fId));
228  for (unsigned range = 0; range < 4; range++) {
229  for (unsigned capid = 0; capid < 4; capid++) {
230  result.setOffset(capid, range, param.qieOffset(range));
231  result.setSlope(capid, range, param.qieSlope(range));
232  }
233  }
234 
235  return result;
236 }
237 
241  return result;
242 }
243 
246  float lowEdges[64];
247  for (int i = 0; i < 64; i++) {
248  lowEdges[i] = -1.5 + i;
249  }
250  result.setMinCharges(lowEdges);
251  return result;
252 }
253 
255 
257  int r1bit[5];
258  r1bit[0] = 9; // [0,9]
259  int syncPhase = 0;
260  r1bit[1] = 1;
261  int binOfMaximum = 0;
262  r1bit[2] = 4;
263  float phase = -25.0f; // [-25.0,25.0]
264  float Xphase = (phase + 32.0f) * 4.0f; // never change this line
265  // (offset 50nsec, 0.25ns step)
266  int Iphase = Xphase;
267  r1bit[3] = 8; // [0,256] offset 50ns, .25ns step
268  int timeSmearing = 0;
269  r1bit[4] = 1; // bool
270 
271  const HcalHardcodeParameters& hparam(getParameters(fId));
272  int pulseShapeID = hparam.mcShape(); // a0
273 
275  syncPhase = 1; // a1 bool
276  binOfMaximum = 5; // a2
277  phase = 5.0f; // a3 [-25.0,25.0]
278  Xphase = (phase + 32.0f) * 4.0f; // never change this line
279  // (offset 50nsec, 0.25ns step)
280  Iphase = Xphase;
281  timeSmearing = 1; // a4
282 
283  }
284 
286  syncPhase = 1; // a1 bool
287  binOfMaximum = 5; // a2
288  phase = 5.0f; // a3 [-25.0,25.0]
289  Xphase = (phase + 32.0f) * 4.0f; // never change this line
290  // (offset 50nsec, 0.25ns step)
291  Iphase = Xphase;
292  timeSmearing = 1; // a4
293 
294  }
295 
296  else if (fId.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
297  syncPhase = 1; // a1 bool
298  binOfMaximum = 5; // a2
299  phase = 5.0f; // a3 [-25.0,25.0]
300  Xphase = (phase + 32.0f) * 4.0f; // never change this line
301  // (offset 50nsec, 0.25ns step)
302  Iphase = Xphase;
303  timeSmearing = 0; // a4
304 
305  HcalDetId cell = HcalDetId(fId);
306  if (cell.ieta() == 1 && cell.iphi() == 1)
307  pulseShapeID = 125;
308 
309  }
310 
312  syncPhase = 1; // a1 bool
313  binOfMaximum = 3; // a2
314  phase = 14.0f; // a3 [-25.0,25.0]
315  Xphase = (phase + 32.0f) * 4.0f; // never change this line
316  // (offset 50nsec, 0.25ns step)
317  Iphase = Xphase;
318  timeSmearing = 0; // a4
319 
320  }
321 
322  else if (fId.genericSubdet() == HcalGenericDetId::HcalGenZDC) {
323  pulseShapeID = 401; // a0
324  syncPhase = 1; // a1 bool
325  binOfMaximum = 5; // a2
326  phase = -4.0f; // a3 [-25.0,25.0]
327  Xphase = (phase + 32.0f) * 4.0f; // never change this line
328  // (offset 50nsec, 0.25ns step)
329  Iphase = Xphase;
330  timeSmearing = 0; // a4
331  }
332 
333  int rshift[7];
334  rshift[0] = 0;
335  for (int k = 0; k < 5; k++) {
336  rshift[k + 1] = rshift[k] + r1bit[k];
337  }
338 
339  int packingScheme = 1; // a5
340  unsigned int param = pulseShapeID | syncPhase << rshift[1] | (binOfMaximum << rshift[2]) | (Iphase << rshift[3]) |
341  (timeSmearing << rshift[4] | packingScheme << 27);
342 
343  HcalMCParam result(fId.rawId(), param);
344  return result;
345 }
346 
348  // Mostly comes from S.Kunori's macro
349  int p1bit[6];
350 
351  // param1
352  int containmentCorrectionFlag = 0;
353  p1bit[0] = 1; // bool
354  int containmentCorrectionPreSample = 0;
355  p1bit[1] = 1; // bool
356  float phase = 13.0; // [-25.0,25.0]
357  float Xphase = (phase + 32.0) * 4.0; //never change this line
358  // (offset 50nsec, 0.25ns step)
359  int Iphase = Xphase;
360  p1bit[2] = 8; // [0,256]
361  // (offset 50ns, 0.25ns step
362  int firstSample = 4;
363  p1bit[3] = 4; // [0,9]
364  int samplesToAdd = 2;
365  p1bit[4] = 4; // [0,9]
366  p1bit[5] = 9; // [0,9]
367 
368  const HcalHardcodeParameters& hparam(getParameters(fId));
369  int pulseShapeID = hparam.recoShape(); // a5
370 
371  int q2bit[10];
372  // param2.
373  int useLeakCorrection = 0;
374  q2bit[0] = 1; // bool
375  int LeakCorrectionID = 0;
376  q2bit[1] = 4; // [0,15]
377  int correctForTimeslew = 0;
378  q2bit[2] = 1; // bool
379  int timeCorrectionID = 0;
380  q2bit[3] = 4; // [0,15]
381  int correctTiming = 0;
382  q2bit[4] = 1; // bool
383  int firstAuxTS = 0;
384  q2bit[5] = 4; // [0,15]
385  int specialCaseID = 0;
386  q2bit[6] = 4; // [0,15]
387  int noiseFlaggingID = 0;
388  q2bit[7] = 4; // [0,15]
389  int pileupCleaningID = 0;
390  q2bit[8] = 4; // [0,15]
391  int packingScheme = 1;
392  q2bit[9] = 4;
393 
396  // param1.
397  containmentCorrectionFlag = 1; // p0
398  containmentCorrectionPreSample = 0; // p1
399  float phase = 6.0;
400  float Xphase = (phase + 32.0) * 4.0; // never change this line
401  //(offset 50nsec, 0.25ns step)
402  Iphase = Xphase; // p2
403  firstSample = 4; // p3
404  samplesToAdd = 2; // p4
405 
406  // param2.
407  useLeakCorrection = 0; // q0
408  LeakCorrectionID = 0; // q1
409  correctForTimeslew = 1; // q2
410  timeCorrectionID = 0; // q3
411  correctTiming = 1; // q4
412  firstAuxTS = 4; // q5
413  specialCaseID = 0; // q6
414  noiseFlaggingID = 1; // q7
415  pileupCleaningID = 0; // q8
416  }
417 
418  else if (fId.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
419  // param1.
420  containmentCorrectionFlag = 1; // p0
421  containmentCorrectionPreSample = 0; // p1
422  float phase = 13.0;
423  float Xphase = (phase + 32.0) * 4.0; // never change this line
424  // (offset 50nsec, 0.25ns step)
425  Iphase = Xphase; // p2
426  firstSample = 4; // p3
427  samplesToAdd = 4; // p4
428 
429  // param2.
430  useLeakCorrection = 0; // q0
431  LeakCorrectionID = 0; // q1
432  correctForTimeslew = 1; // q2
433  timeCorrectionID = 0; // q3
434  correctTiming = 1; // q4
435  firstAuxTS = 4; // q5
436  specialCaseID = 0; // q6
437  noiseFlaggingID = 1; // q7
438  pileupCleaningID = 0; // q8
439 
440  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenForward) {
441  // param1.
442  containmentCorrectionFlag = 0; // p0
443  containmentCorrectionPreSample = 0; // p1
444  float phase = 13.0;
445  float Xphase = (phase + 32.0) * 4.0; // never change this line
446  // (offset 50nsec, 0.25ns step)
447  Iphase = Xphase; // p2
448  firstSample = 2; // p3
449  samplesToAdd = 1; // p4
450 
451  // param2.
452  useLeakCorrection = 0; // q0
453  LeakCorrectionID = 0; // q1
454  correctForTimeslew = 0; // q2
455  timeCorrectionID = 0; // q3
456  correctTiming = 1; // q4
457  firstAuxTS = 1; // q5
458  specialCaseID = 0; // q6
459  noiseFlaggingID = 1; // q7
460  pileupCleaningID = 0; // q8
461  }
462 
463  // Packing parameters in two words
464 
465  int p1shift[7];
466  p1shift[0] = 0;
467  for (int k = 0; k < 6; k++) {
468  int j = k + 1;
469  p1shift[j] = p1shift[k] + p1bit[k];
470  // cout<<" j= "<<j<<" shift "<< p1shift[j]<<endl;
471  }
472  int param1 = 0;
473  param1 = containmentCorrectionFlag | (containmentCorrectionPreSample << p1shift[1]) | (Iphase << p1shift[2]) |
474  (firstSample << p1shift[3]) | (samplesToAdd << p1shift[4]) | (pulseShapeID << p1shift[5]);
475 
476  int q2shift[10];
477  q2shift[0] = 0;
478  for (int k = 0; k < 9; k++) {
479  int j = k + 1;
480  q2shift[j] = q2shift[k] + q2bit[k];
481  // cout<<" j= "<<j<<" shift "<< q2shift[j]<<endl;
482  }
483  int param2 = 0;
484  param2 = useLeakCorrection | (LeakCorrectionID << q2shift[1]) | (correctForTimeslew << q2shift[2]) |
485  (timeCorrectionID << q2shift[3]) | (correctTiming << q2shift[4]) | (firstAuxTS << q2shift[5]) |
486  (specialCaseID << q2shift[6]) | (noiseFlaggingID << q2shift[7]) | (pileupCleaningID << q2shift[8]) |
487  (packingScheme << q2shift[9]);
488 
489  HcalRecoParam result(fId.rawId(), param1, param2);
490 
491  return result;
492 }
493 
495  int nhits = 0;
496  float phase = 0.0;
497  float rms = 0.0;
499  nhits = 4;
500  phase = 4.5;
501  rms = 6.5;
502  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
503  nhits = 4;
504  phase = 9.3;
505  rms = 7.8;
506  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
507  nhits = 4;
508  phase = 8.6;
509  rms = 2.3;
510  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenForward) {
511  nhits = 4;
512  phase = 12.4;
513  rms = 12.29;
514  }
516 
517  return result;
518 }
519 
520 #define EMAP_NHBHECR 9
521 #define EMAP_NHFCR 3
522 #define EMAP_NHOCR 4
523 #define EMAP_NFBR 8
524 #define EMAP_NFCH 3
525 #define EMAP_NHTRS 3
526 #define EMAP_NHSETS 4
527 #define EMAP_NTOPBOT 2
528 #define EMAP_NHTRSHO 4
529 #define EMAP_NHSETSHO 3
530 
531 std::unique_ptr<HcalDcsMap> HcalDbHardcode::makeHardcodeDcsMap() const {
532  HcalDcsMapAddons::Helper dcs_map_helper;
533  dcs_map_helper.mapGeomId2DcsId(HcalDetId(HcalBarrel, -16, 1, 1),
535  dcs_map_helper.mapGeomId2DcsId(HcalDetId(HcalForward, -41, 3, 1),
537  dcs_map_helper.mapGeomId2DcsId(HcalDetId(HcalForward, -26, 25, 2),
539  dcs_map_helper.mapGeomId2DcsId(HcalDetId(HcalBarrel, -15, 68, 1),
541  dcs_map_helper.mapGeomId2DcsId(HcalDetId(HcalOuter, -14, 1, 4),
543  dcs_map_helper.mapGeomId2DcsId(HcalDetId(HcalForward, 41, 71, 2),
545  return std::make_unique<HcalDcsMap>(dcs_map_helper);
546 }
547 
548 std::unique_ptr<HcalElectronicsMap> HcalDbHardcode::makeHardcodeMap(const std::vector<HcalGenericDetId>& cells) const {
549  static const int kUTCAMask = 0x4000000; //set bit 26 for uTCA version
550  static const int kLinearIndexMax = 0x7FFFF; //19 bits
551  static const int kTriggerBitMask = 0x02000000; //2^25
552  uint32_t counter = 0;
553  uint32_t counterTrig = 0;
555  for (const auto& fId : cells) {
556  if (fId.genericSubdet() == HcalGenericDetId::HcalGenBarrel ||
557  fId.genericSubdet() == HcalGenericDetId::HcalGenEndcap ||
558  fId.genericSubdet() == HcalGenericDetId::HcalGenForward ||
559  fId.genericSubdet() == HcalGenericDetId::HcalGenOuter || fId.genericSubdet() == HcalGenericDetId::HcalGenZDC) {
560  ++counter;
561  assert(counter < kLinearIndexMax);
562  uint32_t raw = counter;
563  raw |= kUTCAMask;
564  HcalElectronicsId elId(raw);
565  emapHelper.mapEId2chId(elId, fId);
566  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenTriggerTower) {
567  ++counterTrig;
568  assert(counterTrig < kLinearIndexMax);
569  uint32_t raw = counterTrig;
570  raw |= kUTCAMask | kTriggerBitMask;
571  HcalElectronicsId elId(raw);
572  emapHelper.mapEId2tId(elId, fId);
573  }
574  }
575  return std::make_unique<HcalElectronicsMap>(emapHelper);
576 }
577 
578 std::unique_ptr<HcalFrontEndMap> HcalDbHardcode::makeHardcodeFrontEndMap(
579  const std::vector<HcalGenericDetId>& cells) const {
581  std::stringstream mystream;
582  std::string detector[5] = {"XX", "HB", "HE", "HO", "HF"};
583  for (const auto& fId : cells) {
584  if (fId.isHcalDetId()) {
585  HcalDetId id = HcalDetId(fId.rawId());
586  HcalSubdetector subdet = id.subdet();
587  int ieta = id.ietaAbs();
588  int iside = id.zside();
589  int iphi = id.iphi();
590  std::string det, rbx;
591  int irm(0);
592  char tempbuff[30];
593  char sidesign = (iside == -1) ? 'M' : 'P';
594  if (subdet == HcalBarrel || subdet == HcalEndcap) {
595  det = detector[subdet];
596  irm = (iphi + 1) % 4 + 1;
597  int iwedge(0);
598  if (ieta >= 21 && (irm == 1 || irm == 3))
599  iwedge = (iphi + 1 + irm + 1) / 4;
600  else
601  iwedge = (iphi + irm + 1) / 4;
602  if (iwedge > 18)
603  iwedge -= 18;
604  sprintf(tempbuff, "%s%c%2.2i%c", det.c_str(), sidesign, iwedge, '\0');
605  mystream << tempbuff;
606  rbx = mystream.str();
607  mystream.str("");
608  emapHelper.loadObject(id, irm, rbx);
609  } else if (subdet == HcalForward) {
610  det = detector[subdet];
611  int hfphi(0);
612  if ((iside == 1 && ieta == 40) || (iside == -1 && ieta == 41)) {
613  irm = ((iphi + 1) / 2) % 36 + 1;
614  hfphi = ((iphi + 1) / 6) % 12 + 1;
615  } else {
616  irm = (iphi + 1) / 2;
617  hfphi = (iphi - 1) / 6 + 1;
618  }
619  irm = (irm - 1) % 3 + 1;
620  sprintf(tempbuff, "%s%c%2.2i%c", det.c_str(), sidesign, hfphi, '\0');
621  mystream << tempbuff;
622  rbx = mystream.str();
623  mystream.str("");
624  emapHelper.loadObject(id, irm, rbx);
625  } else if (subdet == HcalOuter) {
626  det = detector[subdet];
627  int ring(0), sector(0);
628  if (ieta <= 4)
629  ring = 0;
630  else if (ieta >= 5 && ieta <= 10)
631  ring = 1;
632  else
633  ring = 2;
634  for (int i = -2; i < iphi; i += 6)
635  sector++;
636  if (sector > 12)
637  sector = 1;
638  irm = ((iphi + 1) / 2) % 6 + 1;
639  if (ring != 0 && sector % 2 != 0)
640  sector++;
641  if (ring == 0)
642  sprintf(tempbuff, "%s%i%2.2d", det.c_str(), ring, sector);
643  else
644  sprintf(tempbuff, "%s%i%c%2.2d", det.c_str(), ring, sidesign, sector);
645  mystream << tempbuff;
646  rbx = mystream.str();
647  mystream.str("");
648  emapHelper.loadObject(id, irm, rbx);
649  }
650  }
651  }
652  return std::make_unique<HcalFrontEndMap>(emapHelper);
653 }
654 
656  //check for cached value
657  auto eta_depth_pair = std::make_pair(ieta, depth);
658  auto nLayers = theLayersInDepths_.find(eta_depth_pair);
659  if (nLayers != theLayersInDepths_.end()) {
660  return nLayers->second;
661  } else {
662  std::vector<int> segmentation;
663  topo->getDepthSegmentation(ieta, segmentation);
664  //assume depth segmentation vector is sorted
665  int nLayersInDepth = std::distance(std::lower_bound(segmentation.begin(), segmentation.end(), depth),
666  std::upper_bound(segmentation.begin(), segmentation.end(), depth));
667  theLayersInDepths_.insert(std::make_pair(eta_depth_pair, nLayersInDepth));
668  return nLayersInDepth;
669  }
670 }
671 
673  if (fId.isHcalDetId()) {
674  HcalDetId hid(fId);
675  //special mixed case for HE 2017
676  if (hid.zside() == 1 && (hid.iphi() == 63 || hid.iphi() == 64 || hid.iphi() == 65 || hid.iphi() == 66))
677  return true;
678  }
679  return false;
680 }
681 
683  const HcalTopology* topo,
684  double intlumi) {
685  // SiPMParameter defined for each DetId the following quantities:
686  // SiPM type, PhotoElectronToAnalog, Dark Current, two auxiliary words
687  // (the second of those containing float noise correlation coefficient
688  // These numbers come from some measurements done with SiPMs
689  // rule for type: cells with >4 layers use larger device (3.3mm diameter), otherwise 2.8mm
690  HcalSiPMType theType = HcalNoSiPM;
691  double thePe2fC = getParameters(fId).photoelectronsToAnalog();
692  double theDC = getParameters(fId).darkCurrent(0, intlumi);
693  double theNoiseCN = getParameters(fId).noiseCorrelation(0);
695  if (useHBUpgrade_) {
696  HcalDetId hid(fId);
697  int nLayersInDepth = getLayersInDepth(hid.ietaAbs(), hid.depth(), topo);
698  if (nLayersInDepth > 4) {
699  theType = HcalHBHamamatsu2;
700  theDC = getParameters(fId).darkCurrent(1, intlumi);
701  theNoiseCN = getParameters(fId).noiseCorrelation(1);
702  } else {
703  theType = HcalHBHamamatsu1;
704  theDC = getParameters(fId).darkCurrent(0, intlumi);
705  theNoiseCN = getParameters(fId).noiseCorrelation(0);
706  }
707  } else
708  theType = HcalHPD;
709  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenEndcap) {
710  if (useHEUpgrade_ || (testHEPlan1_ && isHEPlan1(fId))) {
711  HcalDetId hid(fId);
712  int nLayersInDepth = getLayersInDepth(hid.ietaAbs(), hid.depth(), topo);
713  if (nLayersInDepth > 4) {
714  theType = HcalHEHamamatsu2;
715  theDC = getParameters(fId).darkCurrent(1, intlumi);
716  theNoiseCN = getParameters(fId).noiseCorrelation(1);
717  } else {
718  theType = HcalHEHamamatsu1;
719  theDC = getParameters(fId).darkCurrent(0, intlumi);
720  theNoiseCN = getParameters(fId).noiseCorrelation(0);
721  }
722  } else
723  theType = HcalHPD;
724  } else if (fId.genericSubdet() == HcalGenericDetId::HcalGenOuter) {
725  if (useHOUpgrade_)
726  theType = HcalHOHamamatsu;
727  else
728  theType = HcalHPD;
729  }
730 
731  return HcalSiPMParameter(fId.rawId(), theType, thePe2fC, theDC, 0, (float)theNoiseCN);
732 }
733 
734 std::unique_ptr<HcalSiPMCharacteristics> HcalDbHardcode::makeHardcodeSiPMCharacteristics() const {
735  // SiPMCharacteristics are constants for each type of SiPM:
736  // Type, # of pixels, 3 parameters for non-linearity, cross talk parameter, ..
737  // Obtained from data sheet and measurements
738  // types (in order): HcalHOZecotek=1, HcalHOHamamatsu, HcalHEHamamatsu1, HcalHEHamamatsu2, HcalHBHamamatsu1, HcalHBHamamatsu2, HcalHPD
740  for (unsigned ip = 0; ip < theSiPMCharacteristics_.size(); ++ip) {
741  auto& ps = theSiPMCharacteristics_[ip];
742  sipmHelper.loadObject(ip + 1,
743  ps.getParameter<int>("pixels"),
744  ps.getParameter<double>("nonlin1"),
745  ps.getParameter<double>("nonlin2"),
746  ps.getParameter<double>("nonlin3"),
747  ps.getParameter<double>("crosstalk"),
748  0,
749  0);
750  }
751  return std::make_unique<HcalSiPMCharacteristics>(sipmHelper);
752 }
753 
755  // For each detId parameters for trigger primitive
756  // mask for channel validity and self trigger information, fine grain
757  // bit information and auxiliary words
758  uint32_t bitInfo = ((44 << 16) | 30);
759  return HcalTPChannelParameter(fId.rawId(), 0, bitInfo, 0, 0);
760 }
761 
763  // Parameters for a given TP algorithm:
764  // FineGrain Algorithm Version for HBHE, ADC threshold fof TDC mask of HF,
765  // TDC mask for HF, Self Trigger bits, auxiliary words
766  tppar.loadObject(0, 0, 0xFFFFFFFFFFFFFFFF, 0, 0, 0);
767 }
HcalHardcodeParameters theHOParameters_
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
double photoelectronsToAnalog() const
std::map< std::pair< int, int >, int > theLayersInDepths_
HcalRecoParam makeRecoParam(HcalGenericDetId fId) const
bool loadObject(DetId fId, int rm, std::string rbx)
load a new entry
const HcalHardcodeParameters & getParameters(HcalGenericDetId fId) const
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
void getDepthSegmentation(const unsigned ring, std::vector< int > &readoutDepths, const bool flag=false) const
const int getGainIndex(HcalGenericDetId fId) const
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
double darkCurrent(unsigned index, double intlumi) const
std::vector< edm::ParameterSet > theSiPMCharacteristics_
HcalPFCut makePFCut(HcalGenericDetId fId, double intlumi, bool noHE) const
void makeHardcodeFrontEndMap(HcalFrontEndMap &emap, const std::vector< HcalGenericDetId > &cells) const
assert(be >=bs)
HcalZSThreshold makeZSThreshold(HcalGenericDetId fId) const
HcalHardcodeParameters theDefaultParameters_
double noiseCorrelation(unsigned index) const
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
HcalHardcodeParameters theHEUpgradeParameters_
std::unique_ptr< HcalSiPMCharacteristics > makeHardcodeSiPMCharacteristics() const
bool isHcalDetId() const
HcalGainWidth makeGainWidth(HcalGenericDetId fId) const
HcalHardcodeParameters theHBUpgradeParameters_
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
HcalTimingParam makeTimingParam(HcalGenericDetId fId) const
HcalTPChannelParameter makeHardcodeTPChannelParameter(HcalGenericDetId fId) const
HcalQIECoder makeQIECoder(HcalGenericDetId fId) const
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HcalSiPMType
Definition: HcalSiPMType.h:4
bool isHEPlan1(HcalGenericDetId fId) const
double f[11][100]
HcalQIENum
Definition: HcalQIENum.h:4
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:143
Definition: value.py:1
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
HcalHardcodeParameters theHBParameters_
std::unique_ptr< HcalDcsMap > makeHardcodeDcsMap() const
HcalQIEType makeQIEType(HcalGenericDetId fId) const
double gain(unsigned index) const
HcalGenericSubdetector genericSubdet() const
HcalGain makeGain(HcalGenericDetId fId, bool fSmear=false) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void makeHardcodeTPParameters(HcalTPParameters &tppar) const
std::unique_ptr< HcalElectronicsMap > makeHardcodeMap(const std::vector< HcalGenericDetId > &cells) const
bool loadObject(int type, int pixels, float parLin1, float parLin2, float parLin3, float crossTalk, int auxi1=0, float auxi2=0)
HcalQIEShape makeQIEShape() const
HcalCalibrationQIECoder makeCalibrationQIECoder(HcalGenericDetId fId) const
void loadObject(int version, int adcCut, uint64_t tdcMask, uint32_t tbits, int auxi1, int auxi2)
HcalMCParam makeMCParam(HcalGenericDetId fId) const
static std::atomic< unsigned int > counter
int getLayersInDepth(int ieta, int depth, const HcalTopology *topo)
HcalHardcodeParameters theHFParameters_
HcalPedestal makePedestal(HcalGenericDetId fId, bool fSmear, bool eff, const HcalTopology *topo, double intlumi)
HcalHardcodeParameters theHEParameters_
HcalSiPMParameter makeHardcodeSiPMParameter(HcalGenericDetId fId, const HcalTopology *topo, double intlumi)
double gainWidth(unsigned index) const
Readout chain identification for Hcal.
HcalHardcodeParameters theHFUpgradeParameters_
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
HcalPedestalWidth makePedestalWidth(HcalGenericDetId fId, bool eff, const HcalTopology *topo, double intlumi)
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164