CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HcaluLUTTPGCoder.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <cmath>
4 #include <string>
5 #include <algorithm>
31 
32 const float HcaluLUTTPGCoder::lsb_ = 1. / 16;
33 
38 
39 constexpr double MaximumFractionalError = 0.002; // 0.2% error allowed from this source
40 
42  : topo_{},
43  delay_{},
44  LUTGenerationMode_{},
45  FG_HF_thresholds_{},
46  bitToMask_{},
47  firstHBEta_{},
48  lastHBEta_{},
49  nHBEta_{},
50  maxDepthHB_{},
51  sizeHB_{},
52  firstHEEta_{},
53  lastHEEta_{},
54  nHEEta_{},
55  maxDepthHE_{},
56  sizeHE_{},
57  firstHFEta_{},
58  lastHFEta_{},
59  nHFEta_{},
60  maxDepthHF_{},
61  sizeHF_{},
62  sizeZDC_{},
63  cosh_ieta_28_HE_low_depths_{},
64  cosh_ieta_28_HE_high_depths_{},
65  cosh_ieta_29_HE_{},
66  allLinear_{},
67  contain1TSHB_{},
68  contain1TSHE_{},
69  applyFixPCC_{},
70  linearLSB_QIE8_{},
71  linearLSB_QIE11_{},
72  linearLSB_QIE11Overlap_{} {}
73 
75 
77  topo_ = top;
78  delay_ = delay;
79  LUTGenerationMode_ = true;
80  FG_HF_thresholds_ = {0, 0};
81  bitToMask_ = 0;
82  allLinear_ = false;
83  contain1TSHB_ = false;
84  contain1TSHE_ = false;
85  applyFixPCC_ = false;
86  linearLSB_QIE8_ = 1.;
87  linearLSB_QIE11_ = 1.;
89  pulseCorr_ = std::make_unique<HcalPulseContainmentManager>(MaximumFractionalError, false);
92  nHBEta_ = (lastHBEta_ - firstHBEta_ + 1);
94  sizeHB_ = 2 * nHBEta_ * nFi_ * maxDepthHB_;
97  nHEEta_ = (lastHEEta_ - firstHEEta_ + 1);
99  sizeHE_ = 2 * nHEEta_ * nFi_ * maxDepthHE_;
102  nHFEta_ = (lastHFEta_ - firstHFEta_ + 1);
104  sizeHF_ = 2 * nHFEta_ * nFi_ * maxDepthHF_;
105  sizeZDC_ = 2 * 9;
106  size_t nluts = (size_t)(sizeHB_ + sizeHE_ + sizeHF_ + sizeZDC_ * 2 + 1);
107  inputLUT_ = std::vector<HcaluLUTTPGCoder::Lut>(nluts);
108  gain_ = std::vector<float>(nluts, 0.);
109  ped_ = std::vector<float>(nluts, 0.);
111 }
112 
114  const std::vector<bool>& featureBits,
115  HcalTriggerPrimitiveDigi& tp) const {
116  throw cms::Exception("PROBLEM: This method should never be invoked!");
117 }
118 
120 
122  int retval(0);
123  if (id == HcalBarrel) {
124  retval = (depth - 1) + maxDepthHB_ * (iphi - 1);
125  if (ieta > 0)
126  retval += maxDepthHB_ * nFi_ * (ieta - firstHBEta_);
127  else
128  retval += maxDepthHB_ * nFi_ * (ieta + lastHBEta_ + nHBEta_);
129  } else if (id == HcalEndcap) {
130  retval = sizeHB_;
131  retval += (depth - 1) + maxDepthHE_ * (iphi - 1);
132  if (ieta > 0)
133  retval += maxDepthHE_ * nFi_ * (ieta - firstHEEta_);
134  else
135  retval += maxDepthHE_ * nFi_ * (ieta + lastHEEta_ + nHEEta_);
136  } else if (id == HcalForward) {
137  retval = sizeHB_ + sizeHE_;
138  retval += (depth - 1) + maxDepthHF_ * (iphi - 1);
139  if (ieta > 0)
140  retval += maxDepthHF_ * nFi_ * (ieta - firstHFEta_);
141  else
142  retval += maxDepthHF_ * nFi_ * (ieta + lastHFEta_ + nHFEta_);
143  } else if (id == HcalOther) {
144  retval = sizeHB_ + sizeHE_ + sizeHF_;
145  retval += depth;
146  if (iphi != 1)
147  retval += 5;
148  if (ieta <= 0)
149  retval += 9;
150  }
151  return retval;
152 }
153 
154 int HcaluLUTTPGCoder::getLUTId(uint32_t rawid) const {
155  HcalDetId detid(rawid);
156  return getLUTId(detid.subdet(), detid.ieta(), detid.iphi(), detid.depth());
157 }
158 
160  return getLUTId(detid.subdet(), detid.ieta(), detid.iphi(), detid.depth());
161 }
162 
164  if (detid.section() == HcalZDCDetId::EM) {
165  return getLUTId(HcalOther, detid.zside(), 1, detid.channel());
166  } else if (detid.section() == HcalZDCDetId::HAD) {
167  return getLUTId(HcalOther, detid.zside(), 2, detid.channel());
168  } else if (detid.section() == HcalZDCDetId::LUM) {
169  return getLUTId(HcalOther, detid.zside(), 3, detid.channel());
170  } else {
171  return getLUTId(HcalOther, detid.zside(), 4, detid.channel());
172  }
173 }
174 
175 void HcaluLUTTPGCoder::update(const char* filename, bool appendMSB) {
176  std::ifstream file(filename, std::ios::in);
177  assert(file.is_open());
178 
179  std::vector<HcalSubdetector> subdet;
181 
182  // Drop first (comment) line
183  std::getline(file, buffer);
184  std::getline(file, buffer);
185 
186  unsigned int index = buffer.find('H', 0);
187  while (index < buffer.length()) {
188  std::string subdetStr = buffer.substr(index, 2);
189  if (subdetStr == "HB")
190  subdet.push_back(HcalBarrel);
191  else if (subdetStr == "HE")
192  subdet.push_back(HcalEndcap);
193  else if (subdetStr == "HF")
194  subdet.push_back(HcalForward);
195  //TODO Check subdet
196  //else exception
197  index += 2;
198  index = buffer.find('H', index);
199  }
200 
201  // Get upper/lower ranges for ieta/iphi/depth
202  size_t nCol = subdet.size();
203  assert(nCol > 0);
204 
205  std::vector<int> ietaU;
206  std::vector<int> ietaL;
207  std::vector<int> iphiU;
208  std::vector<int> iphiL;
209  std::vector<int> depU;
210  std::vector<int> depL;
211  std::vector<Lut> lutFromFile(nCol);
212  LutElement lutValue;
213 
214  for (size_t i = 0; i < nCol; ++i) {
215  int ieta;
216  file >> ieta;
217  ietaL.push_back(ieta);
218  }
219 
220  for (size_t i = 0; i < nCol; ++i) {
221  int ieta;
222  file >> ieta;
223  ietaU.push_back(ieta);
224  }
225 
226  for (size_t i = 0; i < nCol; ++i) {
227  int iphi;
228  file >> iphi;
229  iphiL.push_back(iphi);
230  }
231 
232  for (size_t i = 0; i < nCol; ++i) {
233  int iphi;
234  file >> iphi;
235  iphiU.push_back(iphi);
236  }
237 
238  for (size_t i = 0; i < nCol; ++i) {
239  int dep;
240  file >> dep;
241  depL.push_back(dep);
242  }
243 
244  for (size_t i = 0; i < nCol; ++i) {
245  int dep;
246  file >> dep;
247  depU.push_back(dep);
248  }
249 
250  // Read Lut Entry
251  for (size_t i = 0; file >> lutValue; i = (i + 1) % nCol) {
252  lutFromFile[i].push_back(lutValue);
253  }
254 
255  // Check lut size
256  for (size_t i = 0; i < nCol; ++i)
257  assert(lutFromFile[i].size() == INPUT_LUT_SIZE);
258 
259  for (size_t i = 0; i < nCol; ++i) {
260  for (int ieta = ietaL[i]; ieta <= ietaU[i]; ++ieta) {
261  for (int iphi = iphiL[i]; iphi <= iphiU[i]; ++iphi) {
262  for (int depth = depL[i]; depth <= depU[i]; ++depth) {
263  HcalDetId id(subdet[i], ieta, iphi, depth);
264  if (!topo_->valid(id))
265  continue;
266 
267  int lutId = getLUTId(id);
268  for (size_t adc = 0; adc < INPUT_LUT_SIZE; ++adc) {
269  if (appendMSB) {
270  // Append FG bit LUT to MSB
271  // MSB = Most Significant Bit = bit 10
272  // Overwrite bit 10
273  LutElement msb = (lutFromFile[i][adc] != 0 ? QIE8_LUT_MSB : 0);
274  inputLUT_[lutId][adc] = (msb | (inputLUT_[lutId][adc] & QIE8_LUT_BITMASK));
275  } else
276  inputLUT_[lutId][adc] = lutFromFile[i][adc];
277  } // for adc
278  } // for depth
279  } // for iphi
280  } // for ieta
281  } // for nCol
282 }
283 
285  LutXml* _xml = new LutXml(filename);
286  _xml->create_lut_map();
289  for (unsigned int iphi = 0; iphi <= HcalDetId::kHcalPhiMask2; ++iphi) {
290  for (unsigned int depth = 1; depth < HcalDetId::kHcalDepthMask2; ++depth) {
291  for (int isub = 0; isub < 3; ++isub) {
292  HcalDetId detid(subdet[isub], ieta, iphi, depth);
293  if (!topo_->valid(detid))
294  continue;
295  int id = getLUTId(subdet[isub], ieta, iphi, depth);
296  std::vector<unsigned int>* lut = _xml->getLutFast(detid);
297  if (lut == nullptr)
298  throw cms::Exception("PROBLEM: No inputLUT_ in xml file for ") << detid << std::endl;
299  if (lut->size() != UPGRADE_LUT_SIZE)
300  throw cms::Exception("PROBLEM: Wrong inputLUT_ size in xml file for ") << detid << std::endl;
301  Lut& lutRaw = inputLUT_[id];
302  lutRaw.resize(UPGRADE_LUT_SIZE, 0);
303  for (unsigned int i = 0; i < UPGRADE_LUT_SIZE; ++i)
304  inputLUT_[id][i] = (LutElement)lut->at(i);
305  }
306  }
307  }
308  }
309  delete _xml;
311 }
312 
314  // ieta = 28 and 29 are both associated with trigger tower 28
315  // so special handling is required. HF ieta=29 channels included in TT30
316  // are already handled correctly in cosh_ieta_
317  if (abs(ieta) >= 28 && subdet == HcalEndcap && allLinear_) {
318  if (abs(ieta) == 29)
319  return cosh_ieta_29_HE_;
320  if (abs(ieta) == 28) {
321  if (depth <= 3)
323  else
325  }
326  }
327 
328  return cosh_ieta_[ieta];
329 }
330 
332  cosh_ieta_ = std::vector<double>(lastHFEta_ + 1, -1.0);
333 
334  HcalTrigTowerGeometry triggeo(topo_);
335 
336  for (int i = 1; i <= firstHFEta_; ++i) {
337  double eta_low = 0., eta_high = 0.;
338  triggeo.towerEtaBounds(i, 0, eta_low, eta_high);
339  cosh_ieta_[i] = cosh((eta_low + eta_high) / 2.);
340  }
341  for (int i = firstHFEta_; i <= lastHFEta_; ++i) {
342  std::pair<double, double> etas = topo_->etaRange(HcalForward, i);
343  double eta1 = etas.first;
344  double eta2 = etas.second;
345  cosh_ieta_[i] = cosh((eta1 + eta2) / 2.);
346  }
347 
348  // trigger tower 28 in HE has a more complicated geometry
349  std::pair<double, double> eta28 = topo_->etaRange(HcalEndcap, 28);
350  std::pair<double, double> eta29 = topo_->etaRange(HcalEndcap, 29);
351  cosh_ieta_29_HE_ = cosh((eta29.first + eta29.second) / 2.);
352  cosh_ieta_28_HE_low_depths_ = cosh((eta28.first + eta28.second) / 2.);
353  // for higher depths in ieta = 28, the trigger tower extends past
354  // the ieta = 29 channels
355  cosh_ieta_28_HE_high_depths_ = cosh((eta28.first + eta29.second) / 2.);
356 }
357 
359  const HcalLutMetadata* metadata = conditions.getHcalLutMetadata();
360  assert(metadata != nullptr);
361  float nominalgain_ = metadata->getNominalGain();
362 
363  pulseCorr_ = std::make_unique<HcalPulseContainmentManager>(MaximumFractionalError, applyFixPCC_);
364  pulseCorr_->beginRun(&conditions, delay_);
365 
367 
368  // Here we will determine if we are using new version of TPs (1TS)
369  // i.e. are we using a new pulse filter scheme.
370  const HcalElectronicsMap* emap = conditions.getHcalMapping();
371 
372  int lastHBRing = topo_->lastHBRing();
373  int lastHERing = topo_->lastHERing();
374 
375  // First, determine if we should configure for the filter scheme
376  // Check the tp version to make this determination
377  bool foundHB = false;
378  bool foundHE = false;
379  bool newHBtp = false;
380  bool newHEtp = false;
381  std::vector<HcalElectronicsId> vIds = emap->allElectronicsIdTrigger();
382  for (std::vector<HcalElectronicsId>::const_iterator eId = vIds.begin(); eId != vIds.end(); eId++) {
383  // The first HB or HE id is enough to tell whether to use new scheme in HB or HE
384  if (foundHB and foundHE)
385  break;
386 
387  HcalTrigTowerDetId hcalTTDetId(emap->lookupTrigger(*eId));
388  if (hcalTTDetId.null())
389  continue;
390 
391  int aieta = abs(hcalTTDetId.ieta());
392  // The absence of TT channels in the HcalTPChannelParameters
393  // is intepreted as to not use the new filter
394  int weight = -1.0;
395  auto tpParam = conditions.getHcalTPChannelParameter(hcalTTDetId, false);
396  if (tpParam)
397  weight = tpParam->getauxi1();
398 
399  if (aieta <= lastHBRing) {
400  foundHB = true;
401  if (weight != -1.0)
402  newHBtp = true;
403  } else if (aieta > lastHBRing and aieta < lastHERing) {
404  foundHE = true;
405  if (weight != -1.0)
406  newHEtp = true;
407  }
408  }
409 
410  for (const auto& id : metadata->getAllChannels()) {
411  if (id.det() == DetId::Hcal and topo_->valid(id)) {
412  HcalDetId cell(id);
413  HcalSubdetector subdet = cell.subdet();
414 
415  if (subdet != HcalBarrel and subdet != HcalEndcap and subdet != HcalForward and subdet != HcalOther)
416  continue;
417 
418  const HcalQIECoder* channelCoder = conditions.getHcalCoder(cell);
419  const HcalQIEShape* shape = conditions.getHcalShape(cell);
420  HcalCoderDb coder(*channelCoder, *shape);
421  const HcalLutMetadatum* meta = metadata->getValues(cell);
422 
423  // defaults for energy requirement for bits 12-15 are high / low to avoid FG bit 0-4 being set when not intended
424  unsigned int bit12_energy = 0;
425  unsigned int bit13_energy = 0;
426  unsigned int bit14_energy = 999;
427  unsigned int bit15_energy = 999;
428 
429  bool is2018OrLater = topo_->triggerMode() >= HcalTopologyMode::TriggerMode_2018 or
431  if (is2018OrLater or topo_->dddConstants()->isPlan1(cell)) {
432  bit12_energy = 16; // depths 1,2 max energy
433  bit13_energy = 80; // depths 3+ min energy
434  bit14_energy = 64; // prompt min energy
435  bit15_energy = 64; // delayed min energy
436  }
437 
438  int lutId = getLUTId(cell);
439  Lut& lut = inputLUT_[lutId];
440  float ped = 0;
441  float gain = 0;
442  uint32_t status = 0;
443 
444  if (LUTGenerationMode_) {
445  const HcalCalibrations& calibrations = conditions.getHcalCalibrations(cell);
446  for (auto capId : {0, 1, 2, 3}) {
447  ped += calibrations.effpedestal(capId);
448  gain += calibrations.LUTrespcorrgain(capId);
449  }
450  ped /= 4.0;
451  gain /= 4.0;
452 
453  //Get Channel Quality
454  const HcalChannelStatus* channelStatus = conditions.getHcalChannelStatus(cell);
455  status = channelStatus->getValue();
456 
457  } else {
458  const HcalL1TriggerObject* myL1TObj = conditions.getHcalL1TriggerObject(cell);
459  ped = myL1TObj->getPedestal();
460  gain = myL1TObj->getRespGain();
461  status = myL1TObj->getFlag();
462  } // LUTGenerationMode_
463 
464  ped_[lutId] = ped;
465  gain_[lutId] = gain;
466  bool isMasked = ((status & bitToMask_) > 0);
467  float rcalib = meta->getRCalib();
468 
469  auto adc2fC = [channelCoder, shape](unsigned int adc) {
470  float fC = 0;
471  for (auto capId : {0, 1, 2, 3})
472  fC += channelCoder->charge(*shape, adc, capId);
473  return fC / 4;
474  };
475 
476  int qieType = conditions.getHcalQIEType(cell)->getValue();
477 
478  const size_t SIZE = qieType == QIE8 ? INPUT_LUT_SIZE : UPGRADE_LUT_SIZE;
480  double linearLSB = linearLSB_QIE8_;
481  if (qieType == QIE11 and cell.ietaAbs() == topo_->lastHBRing())
482  linearLSB = linearLSB_QIE11Overlap_;
483  else if (qieType == QIE11)
484  linearLSB = linearLSB_QIE11_;
485 
486  lut.resize(SIZE, 0);
487 
488  // Input LUT for HB/HE/HF
489  if (subdet == HcalBarrel || subdet == HcalEndcap) {
490  int granularity = meta->getLutGranularity();
491 
492  double correctionPhaseNS = conditions.getHcalRecoParam(cell)->correctionPhaseNS();
493 
494  if (qieType == QIE11) {
495  if (overrideDBweightsAndFilterHB_ and cell.ietaAbs() <= lastHBRing)
497  else if (overrideDBweightsAndFilterHE_ and cell.ietaAbs() > lastHBRing)
499  }
500  for (unsigned int adc = 0; adc < SIZE; ++adc) {
501  if (isMasked)
502  lut[adc] = 0;
503  else {
504  double nonlinearityCorrection = 1.0;
505  double containmentCorrection = 1.0;
506  // SiPM nonlinearity was not corrected in 2017
507  // and containment corrections were not
508  // ET-dependent prior to 2018
509  if (is2018OrLater) {
510  double containmentCorrection1TS = pulseCorr_->correction(cell, 1, correctionPhaseNS, adc2fC(adc));
511  // Use the 1-TS containment correction to estimate the charge of the pulse
512  // from the individual samples
513  double correctedCharge = containmentCorrection1TS * adc2fC(adc);
514  double containmentCorrection2TSCorrected =
515  pulseCorr_->correction(cell, 2, correctionPhaseNS, correctedCharge);
516  if (qieType == QIE11) {
517  // When contain1TS_ is set, it should still only apply for QIE11-related things
518  if ((((contain1TSHB_ and overrideDBweightsAndFilterHB_) or newHBtp) and cell.ietaAbs() <= lastHBRing) or
519  (((contain1TSHE_ and overrideDBweightsAndFilterHE_) or newHEtp) and cell.ietaAbs() > lastHBRing)) {
520  containmentCorrection = containmentCorrection1TS;
521  } else {
522  containmentCorrection = containmentCorrection2TSCorrected;
523  }
524 
525  const HcalSiPMParameter& siPMParameter(*conditions.getHcalSiPMParameter(cell));
527  conditions.getHcalSiPMCharacteristics()->getNonLinearities(siPMParameter.getType()));
528  const double fcByPE = siPMParameter.getFCByPE();
529  const double effectivePixelsFired = correctedCharge / fcByPE;
530  nonlinearityCorrection = corr.getRecoCorrectionFactor(effectivePixelsFired);
531  } else {
532  containmentCorrection = containmentCorrection2TSCorrected;
533  }
534  }
535  if (allLinear_)
536  lut[adc] = (LutElement)std::min(
537  std::max(0,
538  int((adc2fC(adc) - ped) * gain * rcalib * nonlinearityCorrection * containmentCorrection /
539  linearLSB / cosh_ieta(cell.ietaAbs(), cell.depth(), HcalEndcap))),
540  MASK);
541  else
542  lut[adc] =
544  int((adc2fC(adc) - ped) * gain * rcalib * nonlinearityCorrection *
545  containmentCorrection / nominalgain_ / granularity)),
546  MASK);
547 
548  unsigned int linearizedADC =
549  lut[adc]; // used for bits 12, 13, 14, 15 for Group 0 LUT for LLP time and depth bits that rely on linearized energies
550 
551  if (qieType == QIE11) {
552  if (subdet == HcalBarrel) { // edit since bits 12-15 not supported in HE yet
553  if ((linearizedADC < bit12_energy and cell.depth() <= 2) or (cell.depth() >= 3))
554  lut[adc] |= 1 << 12;
555  if (linearizedADC >= bit13_energy and cell.depth() >= 3)
556  lut[adc] |= 1 << 13;
557  if (linearizedADC >= bit14_energy)
558  lut[adc] |= 1 << 14;
559  if (linearizedADC >= bit15_energy)
560  lut[adc] |= 1 << 15;
561  }
562  }
563 
564  //Zeroing the 4th depth in the trigger towers where |ieta| = 16 to match the behavior in the uHTR firmware in Run3, where the 4th depth is not included in the sum over depths when constructing the TP energy for this tower.
565  if (abs(cell.ieta()) == 16 && cell.depth() == 4 &&
567  lut[adc] = 0;
568  }
569  }
570  }
571  } else if (subdet == HcalForward) {
572  for (unsigned int adc = 0; adc < SIZE; ++adc) {
573  if (isMasked)
574  lut[adc] = 0;
575  else {
576  lut[adc] = std::min(
577  std::max(0, int((adc2fC(adc) - ped) * gain * rcalib / lsb_ / cosh_ieta_[cell.ietaAbs()])), MASK);
578  if (adc > FG_HF_thresholds_[0])
579  lut[adc] |= QIE10_LUT_MSB0;
580  if (adc > FG_HF_thresholds_[1])
581  lut[adc] |= QIE10_LUT_MSB1;
582  }
583  }
584  }
585  } else if (id.det() == DetId::Calo && id.subdetId() == HcalZDCDetId::SubdetectorId) {
586  HcalZDCDetId cell(id.rawId());
587 
588  if (cell.section() != HcalZDCDetId::EM && cell.section() != HcalZDCDetId::HAD)
589  continue;
590 
591  const HcalQIECoder* channelCoder = conditions.getHcalCoder(cell);
592  const HcalQIEShape* shape = conditions.getHcalShape(cell);
593  const HcalPedestal* effPedestals = conditions.getEffectivePedestal(cell);
594  HcalCoderDb coder(*channelCoder, *shape);
595  const HcalLutMetadatum* meta = metadata->getValues(cell);
596 
597  auto tpParam = conditions.getHcalTPChannelParameter(cell, false);
598  const int weight = tpParam->getauxi1();
599  int factorGeVPerCount = tpParam->getauxi2();
600  if (factorGeVPerCount == 0) {
601  edm::LogWarning("HcaluLUTTPGCoder")
602  << "WARNING: ZDC trigger spacing factor, taken from auxi2 field of HCALTPChannelParameters for the cell "
603  "with (zside, section, channel) = ("
604  << cell.zside() << " , " << cell.section() << " , " << cell.channel()
605  << ") is set to the "
606  "default value of 0, which is an incompatible value for a spacing factor. Setting the value to 50 and "
607  "continuing.";
608  factorGeVPerCount = 50;
609  }
610 
611  const int lutId = getLUTId(cell);
612  const int lutId_ootpu = lutId + sizeZDC_;
613  Lut& lut = inputLUT_[lutId];
614  Lut& lut_ootpu = inputLUT_[lutId_ootpu];
615  float ped = 0;
616  float gain = 0;
617  float pedWidth = 0;
618  uint32_t status = 0;
619 
620  if (LUTGenerationMode_) {
621  const HcalCalibrations& calibrations = conditions.getHcalCalibrations(cell);
622  for (auto capId : {0, 1, 2, 3}) {
623  ped += calibrations.effpedestal(capId);
624  gain += calibrations.LUTrespcorrgain(capId);
625  pedWidth += effPedestals->getWidth(capId);
626  }
627  ped /= 4.0;
628  gain /= 4.0;
629  pedWidth /= 4.0;
630 
631  const HcalChannelStatus* channelStatus = conditions.getHcalChannelStatus(cell);
632  status = channelStatus->getValue();
633 
634  } else {
635  const HcalL1TriggerObject* myL1TObj = conditions.getHcalL1TriggerObject(cell);
636  ped = myL1TObj->getPedestal();
637  gain = myL1TObj->getRespGain();
638  status = myL1TObj->getFlag();
639  } // LUTGenerationMode_
640 
641  ped_[lutId] = ped;
642  gain_[lutId] = gain;
643  bool isMasked = ((status & bitToMask_) > 0);
644  float rcalib = meta->getRCalib();
645 
646  auto adc2fC = [channelCoder, shape](unsigned int adc) {
647  float fC = 0;
648  for (auto capId : {0, 1, 2, 3})
649  fC += channelCoder->charge(*shape, adc, capId);
650  return fC / 4;
651  };
652 
653  int qieType = conditions.getHcalQIEType(cell)->getValue();
654 
655  const size_t SIZE = qieType == QIE8 ? INPUT_LUT_SIZE : UPGRADE_LUT_SIZE;
656  const int MASK = QIE10_ZDC_LUT_BITMASK;
657 
658  lut.resize(SIZE, 0);
659  lut_ootpu.resize(SIZE, 0);
660 
661  for (unsigned int adc = 0; adc < SIZE; ++adc) {
662  if (isMasked) {
663  lut[adc] = 0;
664  lut_ootpu[adc] = 0;
665  } else {
666  if ((adc2fC(adc) - ped) < pedWidth) {
667  lut[adc] = 0;
668  lut_ootpu[adc] = 0;
669  } else {
670  auto lut_term = (adc2fC(adc) - ped) * gain * rcalib / factorGeVPerCount;
671  lut[adc] = std::clamp(int(lut_term), 0, MASK);
672  lut_ootpu[adc] = std::clamp(int(lut_term * weight / 256), 0, MASK);
673  }
674  }
675  }
676  } else {
677  continue;
678  }
679  }
680 }
681 
683  int lutId = getLUTId(df.id());
684  const Lut& lut = inputLUT_.at(lutId);
685  for (int i = 0; i < df.size(); i++) {
686  ics[i] = (lut.at(df[i].adc()) & QIE8_LUT_BITMASK);
687  }
688 }
689 
691  int lutId = getLUTId(df.id());
692  const Lut& lut = inputLUT_.at(lutId);
693  for (int i = 0; i < df.size(); i++) {
694  ics[i] = (lut.at(df[i].adc()) & QIE8_LUT_BITMASK);
695  }
696 }
697 
699  DetId detId = DetId(df.detid());
700  if (detId.det() == DetId::Hcal) {
701  int lutId = getLUTId(HcalDetId(df.id()));
702  const Lut& lut = inputLUT_.at(lutId);
703  for (int i = 0; i < df.samples(); i++) {
704  ics[i] = (lut.at(df[i].adc()) & QIE10_LUT_BITMASK);
705  }
706  } else {
707  int lutId = getLUTId(HcalZDCDetId(df.id()));
708  if (ootpu_lut)
709  lutId = lutId + sizeZDC_;
710  const Lut& lut = inputLUT_.at(lutId);
711  for (int i = 0; i < df.samples(); i++) {
712  ics[i] = (lut.at(df[i].adc()) & QIE10_ZDC_LUT_BITMASK);
713  }
714  }
715 }
716 
718  int lutId = getLUTId(HcalDetId(df.id()));
719  const Lut& lut = inputLUT_.at(lutId);
720  for (int i = 0; i < df.samples(); i++) {
721  ics[i] = (lut.at(df[i].adc()) & QIE11_LUT_BITMASK);
722  }
723 }
724 
726  int lutId = getLUTId(id);
727  return ((inputLUT_.at(lutId)).at(sample.adc()) & QIE8_LUT_BITMASK);
728 }
729 
730 std::vector<unsigned short> HcaluLUTTPGCoder::group0FGbits(const QIE11DataFrame& df) const {
731  int lutId = getLUTId(HcalDetId(df.id()));
732  const Lut& lut = inputLUT_.at(lutId);
733  std::vector<unsigned short> group0LLPbits;
734  group0LLPbits.reserve(df.samples());
735  for (int i = 0; i < df.samples(); i++) {
736  group0LLPbits.push_back((lut.at(df[i].adc()) >> 12) &
737  0xF); // four bits (12-15) of LUT used to set 6 finegrain bits from uHTR
738  }
739  return group0LLPbits;
740 }
741 
743  int lutId = getLUTId(id);
744  return ped_.at(lutId);
745 }
746 
748  int lutId = getLUTId(id);
749  return gain_.at(lutId);
750 }
751 
752 std::vector<unsigned short> HcaluLUTTPGCoder::getLinearizationLUT(HcalDetId id) const {
753  int lutId = getLUTId(id);
754  return inputLUT_.at(lutId);
755 }
756 
757 std::vector<unsigned short> HcaluLUTTPGCoder::getLinearizationLUT(HcalZDCDetId id, bool ootpu_lut) const {
758  int lutId = getLUTId(id);
759  if (ootpu_lut)
760  return inputLUT_.at(lutId + sizeZDC_);
761  else
762  return inputLUT_.at(lutId);
763 }
764 
765 void HcaluLUTTPGCoder::lookupMSB(const HBHEDataFrame& df, std::vector<bool>& msb) const {
766  msb.resize(df.size());
767  for (int i = 0; i < df.size(); ++i)
768  msb[i] = getMSB(df.id(), df.sample(i).adc());
769 }
770 
771 bool HcaluLUTTPGCoder::getMSB(const HcalDetId& id, int adc) const {
772  int lutId = getLUTId(id);
773  const Lut& lut = inputLUT_.at(lutId);
774  return (lut.at(adc) & QIE8_LUT_MSB);
775 }
776 
777 void HcaluLUTTPGCoder::lookupMSB(const QIE10DataFrame& df, std::vector<std::bitset<2>>& msb) const {
778  msb.resize(df.samples());
779  int lutId = getLUTId(HcalDetId(df.id()));
780  const Lut& lut = inputLUT_.at(lutId);
781  for (int i = 0; i < df.samples(); ++i) {
782  msb[i][0] = lut.at(df[i].adc()) & QIE10_LUT_MSB0;
783  msb[i][1] = lut.at(df[i].adc()) & QIE10_LUT_MSB1;
784  }
785 }
786 
787 void HcaluLUTTPGCoder::lookupMSB(const QIE11DataFrame& df, std::vector<std::bitset<2>>& msb) const {
788  int lutId = getLUTId(HcalDetId(df.id()));
789  const Lut& lut = inputLUT_.at(lutId);
790  for (int i = 0; i < df.samples(); ++i) {
791  msb[i][0] = lut.at(df[i].adc()) & QIE11_LUT_MSB0;
792  msb[i][1] = lut.at(df[i].adc()) & QIE11_LUT_MSB1;
793  }
794 }
std::vector< uint32_t > FG_HF_thresholds_
float getRCalib() const
size
Write out results.
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
uint32_t getFlag() const
static const int nFi_
static constexpr uint32_t kHcalPhiMask2
Definition: HcalDetId.h:15
double cosh_ieta_28_HE_high_depths_
Definition: LutXml.h:27
double linearLSB_QIE11Overlap_
static const int QIE11_LUT_MSB1
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
static const int QIE11_LUT_BITMASK
uint8_t getLutGranularity() const
Definition: HcalQIENum.h:4
bool valid(const DetId &id) const override
int create_lut_map(void)
Definition: LutXml.cc:352
const HcalTopology * topo_
static const int QIE11_LUT_MSB0
static const float lsb_
Definition: weight.py:1
void lookupMSB(const HBHEDataFrame &df, std::vector< bool > &msb) const
std::vector< unsigned short > group0FGbits(const QIE11DataFrame &df) const
double cosh_ieta_28_HE_low_depths_
static const int QIE10_ZDC_LUT_BITMASK
void init(const HcalTopology *top, const HcalTimeSlew *delay)
bool overrideDBweightsAndFilterHB_
static const int QIE8_LUT_BITMASK
bool getMSB(const HcalDetId &id, int adc) const
assert(be >=bs)
unsigned short LutElement
void update(const HcalDbService &conditions)
void updateXML(const char *filename)
static const int QIE10_LUT_MSB0
int firstHBRing() const
Definition: HcalTopology.h:88
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
static const size_t UPGRADE_LUT_SIZE
float getLUTGain(HcalDetId id) const override
std::vector< Lut > inputLUT_
dictionary corr
std::vector< unsigned short > getLinearizationLUT(HcalDetId id) const override
Get the full linearization LUT (128 elements). Default implementation just uses adc2Linear to get all...
int terminate(void)
HcalTopologyMode::TriggerMode triggerMode() const
Definition: HcalTopology.h:31
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
int lastHBRing() const
Definition: HcalTopology.h:89
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::pair< double, double > etaRange(HcalSubdetector subdet, int ieta) const
const HcalTimeSlew * delay_
int maxDepth(void) const
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const float adc2fC[128]
bool overrideDBweightsAndFilterHE_
float getLUTPedestal(HcalDetId id) const override
static const int QIE8_LUT_MSB
uint32_t getValue() const
static constexpr uint32_t kHcalEtaMask2
Definition: HcalDetId.h:19
static const int QIE10_LUT_BITMASK
std::vector< double > cosh_ieta_
std::vector< float > ped_
Definition: DetId.h:17
double cosh_ieta(int ieta, int depth, HcalSubdetector subdet)
constexpr double MaximumFractionalError
float getWidth(int fCapId) const
get width for capId = 0..3
Definition: HcalPedestal.h:25
std::vector< float > gain_
~HcaluLUTTPGCoder() override
void adc2Linear(const HBHEDataFrame &df, IntegerCaloSamples &ics) const override
std::vector< unsigned int > * getLutFast(uint32_t det_id)
Definition: LutXml.cc:74
static const size_t INPUT_LUT_SIZE
constexpr Section section() const
get the section
Definition: HcalZDCDetId.h:92
void towerEtaBounds(int ieta, int version, double &eta1, double &eta2) const
where this tower begins and ends in eta
int lastHERing() const
Definition: HcalTopology.h:91
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:161
void compress(const IntegerCaloSamples &ics, const std::vector< bool > &featureBits, HcalTriggerPrimitiveDigi &tp) const override
int lastHFRing() const
Definition: HcalTopology.h:94
static constexpr int32_t SubdetectorId
Definition: HcalZDCDetId.h:35
constexpr int32_t channel() const
get the channel
Definition: HcalZDCDetId.h:112
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
constexpr int32_t zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:90
Log< level::Warning, false > LogWarning
void make_cosh_ieta_map(void)
int getLUTId(HcalSubdetector id, int ieta, int iphi, int depth) const
std::unique_ptr< HcalPulseContainmentManager > pulseCorr_
bool isPlan1(const HcalDetId &id) const
static const int QIE10_LUT_MSB1
static XMLProcessor * getInstance()
Definition: XMLProcessor.h:134
int firstHFRing() const
Definition: HcalTopology.h:93
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
Definition: HcalQIECoder.cc:20
Definition: Lut.h:31
uint16_t *__restrict__ uint16_t const *__restrict__ adc
int firstHERing() const
Definition: HcalTopology.h:90
static constexpr uint32_t kHcalDepthMask2
Definition: HcalDetId.h:25
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164