CMS 3D CMS Logo

HcalTriggerPrimitiveAlgo.cc
Go to the documentation of this file.
2 
6 
10 
13 
16 
18 
19 #include <iostream>
20 
21 using namespace std;
22 
23 HcalTriggerPrimitiveAlgo::HcalTriggerPrimitiveAlgo( bool pf, const std::vector<double>& w, int latency,
24  uint32_t FG_threshold, uint32_t FG_HF_threshold, uint32_t ZS_threshold,
27  uint32_t minSignalThreshold, uint32_t PMT_NoiseThreshold
28  )
29  : incoder_(0), outcoder_(0),
30  theThreshold(0), peakfind_(pf), weights_(w), latency_(latency),
31  FG_threshold_(FG_threshold), FG_HF_threshold_(FG_HF_threshold), ZS_threshold_(ZS_threshold),
32  numberOfSamples_(numberOfSamples),
33  numberOfPresamples_(numberOfPresamples),
34  numberOfSamplesHF_(numberOfSamplesHF),
35  numberOfPresamplesHF_(numberOfPresamplesHF),
36  minSignalThreshold_(minSignalThreshold),
37  PMT_NoiseThreshold_(PMT_NoiseThreshold),
38  NCTScaleShift(0), RCTScaleShift(0),
39  peak_finder_algorithm_(2),
40  override_parameters_()
41 {
42  //No peak finding setting (for Fastsim)
43  if (!peakfind_){
44  numberOfSamples_ = 1;
46  numberOfSamplesHF_ = 1;
48  }
49  // Switch to integer for comparisons - remove compiler warning
51 }
52 
53 
55 }
56 
57 
58 void
60 {
61  upgrade_hb_ = hb;
62  upgrade_he_ = he;
63  upgrade_hf_ = hf;
64 }
65 
66 
67 void
69 {
71 
72  if (override_parameters_.exists("ADCThresholdHF")) {
73  override_adc_hf_ = true;
74  override_adc_hf_value_ = override_parameters_.getParameter<uint32_t>("ADCThresholdHF");
75  }
76  if (override_parameters_.exists("TDCMaskHF")) {
77  override_tdc_hf_ = true;
78  override_tdc_hf_value_ = override_parameters_.getParameter<unsigned long long>("TDCMaskHF");
79  }
80 }
81 
82 
84  // TODO: Need to add support for seperate 28, 29 in HE
85  //Hack for 300_pre10, should be removed.
86  if (frame.id().depth()==5) return;
87 
88  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(frame.id());
89  assert(ids.size() == 1 || ids.size() == 2);
90  IntegerCaloSamples samples1(ids[0], int(frame.size()));
91 
92  samples1.setPresamples(frame.presamples());
93  incoder_->adc2Linear(frame, samples1);
94 
95  std::vector<bool> msb;
96  incoder_->lookupMSB(frame, msb);
97 
98  if(ids.size() == 2) {
99  // make a second trigprim for the other one, and split the energy
100  IntegerCaloSamples samples2(ids[1], samples1.size());
101  for(int i = 0; i < samples1.size(); ++i) {
102  samples1[i] = uint32_t(samples1[i]*0.5);
103  samples2[i] = samples1[i];
104  }
105  samples2.setPresamples(frame.presamples());
106  addSignal(samples2);
107  addFG(ids[1], msb);
108  }
109  addSignal(samples1);
110  addFG(ids[0], msb);
111 }
112 
113 
115  if(frame.id().depth() == 1 || frame.id().depth() == 2) {
116  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(frame.id());
117  std::vector<HcalTrigTowerDetId>::const_iterator it;
118  for (it = ids.begin(); it != ids.end(); ++it) {
119  HcalTrigTowerDetId trig_tower_id = *it;
120  IntegerCaloSamples samples(trig_tower_id, frame.size());
121  samples.setPresamples(frame.presamples());
122  incoder_->adc2Linear(frame, samples);
123 
124  // Don't add to final collection yet
125  // HF PMT veto sum is calculated in analyzerHF()
126  IntegerCaloSamples zero_samples(trig_tower_id, frame.size());
127  zero_samples.setPresamples(frame.presamples());
128  addSignal(zero_samples);
129 
130  // Pre-LS1 Configuration
131  if (trig_tower_id.version() == 0) {
132  // Mask off depths: fgid is the same for both depths
133  uint32_t fgid = (frame.id().maskDepth());
134 
135  if ( theTowerMapFGSum.find(trig_tower_id) == theTowerMapFGSum.end() ) {
136  SumFGContainer sumFG;
137  theTowerMapFGSum.insert(std::pair<HcalTrigTowerDetId, SumFGContainer>(trig_tower_id, sumFG));
138  }
139 
140  SumFGContainer& sumFG = theTowerMapFGSum[trig_tower_id];
141  SumFGContainer::iterator sumFGItr;
142  for ( sumFGItr = sumFG.begin(); sumFGItr != sumFG.end(); ++sumFGItr) {
143  if (sumFGItr->id() == fgid) { break; }
144  }
145  // If find
146  if (sumFGItr != sumFG.end()) {
147  for (int i=0; i<samples.size(); ++i) {
148  (*sumFGItr)[i] += samples[i];
149  }
150  }
151  else {
152  //Copy samples (change to fgid)
153  IntegerCaloSamples sumFGSamples(DetId(fgid), samples.size());
154  sumFGSamples.setPresamples(samples.presamples());
155  for (int i=0; i<samples.size(); ++i) {
156  sumFGSamples[i] = samples[i];
157  }
158  sumFG.push_back(sumFGSamples);
159  }
160 
161  // set veto to true if Long or Short less than threshold
162  if (HF_Veto.find(fgid) == HF_Veto.end()) {
163  vector<bool> vetoBits(samples.size(), false);
164  HF_Veto[fgid] = vetoBits;
165  }
166  for (int i=0; i<samples.size(); ++i) {
167  if (samples[i] < minSignalThreshold_) {
168  HF_Veto[fgid][i] = true;
169  }
170  }
171  }
172  // HF 1x1
173  else if (trig_tower_id.version() == 1) {
174  uint32_t fgid = (frame.id().maskDepth());
175  HFDetails& details = theHFDetailMap[trig_tower_id][fgid];
176  // Check the frame type to determine long vs short
177  if (frame.id().depth() == 1) { // Long
178  details.long_fiber = samples;
179  details.LongDigi = frame;
180  } else if (frame.id().depth() == 2) { // Short
181  details.short_fiber = samples;
182  details.ShortDigi = frame;
183  } else {
184  // Neither long nor short... So we have no idea what to do
185  edm::LogWarning("HcalTPAlgo") << "Unable to figure out what to do with data frame for " << frame.id();
186  return;
187  }
188  }
189  // Uh oh, we are in a bad/unknown state! Things will start crashing.
190  else {
191  return;
192  }
193  }
194  }
195 }
196 
197 void
199 {
200  auto ids = theTrigTowerGeometry->towerIds(frame.id());
201  for (const auto& id: ids) {
202  if (id.version() == 0) {
203  edm::LogError("HcalTPAlgo") << "Encountered QIE10 data frame mapped to TP version 0:" << id;
204  continue;
205  }
206 
207  IntegerCaloSamples samples(id, frame.samples());
208  samples.setPresamples(frame.presamples());
209  incoder_->adc2Linear(frame, samples);
210 
211  // Don't add to final collection yet
212  // HF PMT veto sum is calculated in analyzerHF()
213  IntegerCaloSamples zero_samples(id, frame.samples());
214  zero_samples.setPresamples(frame.presamples());
215  addSignal(zero_samples);
216 
217  auto fid = HcalDetId(frame.id());
218  auto& details = theHFUpgradeDetailMap[id][fid.maskDepth()];
219  details[fid.depth() - 1].samples = samples;
220  details[fid.depth() - 1].digi = frame;
221  details[fid.depth() - 1].validity.resize(frame.samples());
222  for (int idx = 0; idx < frame.samples(); ++idx)
223  details[fid.depth() - 1].validity[idx] = validChannel(frame, idx);
224  }
225 }
226 
227 void
229 {
230  HcalDetId detId(frame.id());
231  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(detId);
232  assert(ids.size() == 1 || ids.size() == 2);
233  IntegerCaloSamples samples1(ids[0], int(frame.samples()));
234 
235  samples1.setPresamples(frame.presamples());
236  incoder_->adc2Linear(frame, samples1);
237 
238  std::vector<std::bitset<2>> msb(frame.samples(), 0);
239  incoder_->lookupMSB(frame, msb);
240 
241  if(ids.size() == 2) {
242  // make a second trigprim for the other one, and split the energy
243  IntegerCaloSamples samples2(ids[1], samples1.size());
244  for(int i = 0; i < samples1.size(); ++i) {
245  samples1[i] = uint32_t(samples1[i]*0.5);
246  samples2[i] = samples1[i];
247  }
248  samples2.setPresamples(frame.presamples());
249  addSignal(samples2);
250  addUpgradeFG(ids[1], detId.depth(), msb);
251  }
252  addSignal(samples1);
253  addUpgradeFG(ids[0], detId.depth(), msb);
254 }
255 
257  HcalTrigTowerDetId id(samples.id());
258  SumMap::iterator itr = theSumMap.find(id);
259  if(itr == theSumMap.end()) {
260  theSumMap.insert(std::make_pair(id, samples));
261  }
262  else {
263  // wish CaloSamples had a +=
264  for(int i = 0; i < samples.size(); ++i) {
265  (itr->second)[i] += samples[i];
266  }
267  }
268 }
269 
270 
272  int shrink = weights_.size() - 1;
273  std::vector<bool>& msb = fgMap_[samples.id()];
274  IntegerCaloSamples sum(samples.id(), samples.size());
275 
276  //slide algo window
277  for(int ibin = 0; ibin < int(samples.size())- shrink; ++ibin) {
278  int algosumvalue = 0;
279  for(unsigned int i = 0; i < weights_.size(); i++) {
280  //add up value * scale factor
281  algosumvalue += int(samples[ibin+i] * weights_[i]);
282  }
283  if (algosumvalue<0) sum[ibin]=0; // low-side
284  //high-side
285  //else if (algosumvalue>QIE8_LINEARIZATION_ET) sum[ibin]=QIE8_LINEARIZATION_ET;
286  else sum[ibin] = algosumvalue; //assign value to sum[]
287  }
288 
289  // Align digis and TP
290  int dgPresamples=samples.presamples();
291  int tpPresamples=numberOfPresamples_;
292  int shift = dgPresamples - tpPresamples;
293  int dgSamples=samples.size();
294  int tpSamples=numberOfSamples_;
295  if(peakfind_){
296  if((shift<shrink) || (shift + tpSamples + shrink > dgSamples - (peak_finder_algorithm_ - 1) ) ){
297  edm::LogInfo("HcalTriggerPrimitiveAlgo::analyze") <<
298  "TP presample or size from the configuration file is out of the accessible range. Using digi values from data instead...";
299  shift=shrink;
300  tpPresamples=dgPresamples-shrink;
301  tpSamples=dgSamples-(peak_finder_algorithm_-1)-shrink-shift;
302  }
303  }
304 
305  std::vector<int> finegrain(tpSamples,false);
306 
307  IntegerCaloSamples output(samples.id(), tpSamples);
308  output.setPresamples(tpPresamples);
309 
310  for (int ibin = 0; ibin < tpSamples; ++ibin) {
311  // ibin - index for output TP
312  // idx - index for samples + shift
313  int idx = ibin + shift;
314 
315  //Peak finding
316  if (peakfind_) {
317  bool isPeak = false;
318  switch (peak_finder_algorithm_) {
319  case 1 :
320  isPeak = (samples[idx] > samples[idx-1] && samples[idx] >= samples[idx+1] && samples[idx] > theThreshold);
321  break;
322  case 2:
323  isPeak = (sum[idx] > sum[idx-1] && sum[idx] >= sum[idx+1] && sum[idx] > theThreshold);
324  break;
325  default:
326  break;
327  }
328 
329  if (isPeak){
330  output[ibin] = std::min<unsigned int>(sum[idx],QIE8_LINEARIZATION_ET);
331  finegrain[ibin] = msb[idx];
332  }
333  // Not a peak
334  else output[ibin] = 0;
335  }
336  else { // No peak finding, just output running sum
337  output[ibin] = std::min<unsigned int>(sum[idx],QIE8_LINEARIZATION_ET);
338  finegrain[ibin] = msb[idx];
339  }
340 
341  // Only Pegged for 1-TS algo.
342  if (peak_finder_algorithm_ == 1) {
343  if (samples[idx] >= QIE8_LINEARIZATION_ET)
345  }
346  }
347  outcoder_->compress(output, finegrain, result);
348 }
349 
350 
351 void
353 {
354  int shrink = weights_.size() - 1;
355  auto& msb = fgUpgradeMap_[samples.id()];
356  IntegerCaloSamples sum(samples.id(), samples.size());
357 
358  //slide algo window
359  for(int ibin = 0; ibin < int(samples.size())- shrink; ++ibin) {
360  int algosumvalue = 0;
361  for(unsigned int i = 0; i < weights_.size(); i++) {
362  //add up value * scale factor
363  algosumvalue += int(samples[ibin+i] * weights_[i]);
364  }
365  if (algosumvalue<0) sum[ibin]=0; // low-side
366  //high-side
367  //else if (algosumvalue>QIE11_LINEARIZATION_ET) sum[ibin]=QIE11_LINEARIZATION_ET;
368  else sum[ibin] = algosumvalue; //assign value to sum[]
369  }
370 
371  // Align digis and TP
372  int dgPresamples=samples.presamples();
373  int tpPresamples=numberOfPresamples_;
374  int shift = dgPresamples - tpPresamples;
375  int dgSamples=samples.size();
376  int tpSamples=numberOfSamples_;
377 
378  if((shift<shrink) || (shift + tpSamples + shrink > dgSamples - (peak_finder_algorithm_ - 1) ) ){
379  edm::LogInfo("HcalTriggerPrimitiveAlgo::analyze") <<
380  "TP presample or size from the configuration file is out of the accessible range. Using digi values from data instead...";
381  shift=shrink;
382  tpPresamples=dgPresamples-shrink;
383  tpSamples=dgSamples-(peak_finder_algorithm_-1)-shrink-shift;
384  }
385 
386  std::vector<int> finegrain(tpSamples,false);
387 
388  IntegerCaloSamples output(samples.id(), tpSamples);
389  output.setPresamples(tpPresamples);
390 
391  for (int ibin = 0; ibin < tpSamples; ++ibin) {
392  // ibin - index for output TP
393  // idx - index for samples + shift
394  int idx = ibin + shift;
395  bool isPeak = (sum[idx] > sum[idx-1] && sum[idx] >= sum[idx+1] && sum[idx] > theThreshold);
396 
397  if (isPeak){
398  output[ibin] = std::min<unsigned int>(sum[idx],QIE11_MAX_LINEARIZATION_ET);
399  finegrain[ibin] = fg_algo.compute(msb[idx]).to_ulong();
400  } else {
401  // Not a peak
402  output[ibin] = 0;
403  finegrain[ibin] = 0;
404  }
405  }
406  outcoder_->compress(output, finegrain, result);
407 }
408 
409 
411  HcalTrigTowerDetId detId(samples.id());
412 
413  // Align digis and TP
414  int dgPresamples=samples.presamples();
415  int tpPresamples=numberOfPresamplesHF_;
416  int shift = dgPresamples - tpPresamples;
417  int dgSamples=samples.size();
418  int tpSamples=numberOfSamplesHF_;
419  if(shift<0 || shift+tpSamples>dgSamples){
420  edm::LogInfo("HcalTriggerPrimitiveAlgo::analyzeHF") <<
421  "TP presample or size from the configuration file is out of the accessible range. Using digi values from data instead...";
422  tpPresamples=dgPresamples;
423  shift=0;
424  tpSamples=dgSamples;
425  }
426 
427  std::vector<int> finegrain(tpSamples, false);
428 
429  TowerMapFGSum::const_iterator tower2fg = theTowerMapFGSum.find(detId);
430  assert(tower2fg != theTowerMapFGSum.end());
431 
432  const SumFGContainer& sumFG = tower2fg->second;
433  // Loop over all L+S pairs that mapped from samples.id()
434  // Note: 1 samples.id() = 6 x (L+S) without noZS
435  for (SumFGContainer::const_iterator sumFGItr = sumFG.begin(); sumFGItr != sumFG.end(); ++sumFGItr) {
436  const std::vector<bool>& veto = HF_Veto[sumFGItr->id().rawId()];
437  for (int ibin = 0; ibin < tpSamples; ++ibin) {
438  int idx = ibin + shift;
439  // if not vetod, add L+S to total sum and calculate FG
440  bool vetoed = idx<int(veto.size()) && veto[idx];
441  if (!(vetoed && (*sumFGItr)[idx] > PMT_NoiseThreshold_)) {
442  samples[idx] += (*sumFGItr)[idx];
443  finegrain[ibin] = (finegrain[ibin] || (*sumFGItr)[idx] >= FG_threshold_);
444  }
445  }
446  }
447 
448  IntegerCaloSamples output(samples.id(), tpSamples);
449  output.setPresamples(tpPresamples);
450 
451  for (int ibin = 0; ibin < tpSamples; ++ibin) {
452  int idx = ibin + shift;
453  output[ibin] = samples[idx] >> hf_lumi_shift;
454  static const int MAX_OUTPUT = QIE8_LINEARIZATION_ET; // QIE8_LINEARIZATION_ET = 1023
455  if (output[ibin] > MAX_OUTPUT) output[ibin] = MAX_OUTPUT;
456  }
457  outcoder_->compress(output, finegrain, result);
458 }
459 
463  const int hf_lumi_shift,
464  const HcalFeatureBit* embit
465  ) {
466  // Align digis and TP
467  const int SHIFT = samples.presamples() - numberOfPresamplesHF_;
468  assert(SHIFT >= 0);
469  assert((SHIFT + numberOfSamplesHF_) <= samples.size());
470 
471  // Try to find the HFDetails from the map corresponding to our samples
472  const HcalTrigTowerDetId detId(samples.id());
473  HFDetailMap::const_iterator it = theHFDetailMap.find(detId);
474  // Missing values will give an empty digi
475  if (it == theHFDetailMap.end()) {
476  return;
477  }
478 
479  std::vector<std::bitset<2>> finegrain(numberOfSamplesHF_, false);
480 
481  // Set up out output of IntergerCaloSamples
483  output.setPresamples(numberOfPresamplesHF_);
484 
485  for (const auto& item: it->second) {
486  auto& details = item.second;
487  for (int ibin = 0; ibin < numberOfSamplesHF_; ++ibin) {
488  const int IDX = ibin + SHIFT;
489  int long_fiber_val = 0;
490  if (IDX < details.long_fiber.size()) {
491  long_fiber_val = details.long_fiber[IDX];
492  }
493  int short_fiber_val = 0;
494  if (IDX < details.short_fiber.size()) {
495  short_fiber_val = details.short_fiber[IDX];
496  }
497  output[ibin] += (long_fiber_val + short_fiber_val);
498 
499  uint32_t ADCLong = details.LongDigi[ibin].adc();
500  uint32_t ADCShort = details.ShortDigi[ibin].adc();
501 
502  if (details.LongDigi.id().ietaAbs() >= FIRST_FINEGRAIN_TOWER) {
503  finegrain[ibin][1] = (ADCLong > FG_HF_threshold_ || ADCShort > FG_HF_threshold_);
504 
505  if (embit != 0)
506  finegrain[ibin][0] = embit->fineGrainbit(details.ShortDigi, details.LongDigi, ibin);
507  }
508  }
509  }
510 
511  for (int bin = 0; bin < numberOfSamplesHF_; ++bin) {
512  static const unsigned int MAX_OUTPUT = QIE8_LINEARIZATION_ET; // QIE8_LINEARIZATION_ET = 1023
513  output[bin] = min({MAX_OUTPUT, output[bin] >> hf_lumi_shift});
514  }
515 
516  std::vector<int> finegrain_converted;
517  for (const auto& fg: finegrain)
518  finegrain_converted.push_back(fg.to_ulong());
519  outcoder_->compress(output, finegrain_converted, result);
520 }
521 
522 bool
524 {
526  if (mask)
527  return false;
528 
530  auto adc_threshold = parameters->getADCThresholdHF();
531  auto tdc_mask = parameters->getTDCMaskHF();
532 
533  if (override_adc_hf_)
534  adc_threshold = override_adc_hf_value_;
535  if (override_tdc_hf_)
536  tdc_mask = override_tdc_hf_value_;
537 
538  if (digi[ts].adc() < adc_threshold)
539  return true;
540 
541  return (1ul << digi[ts].le_tdc()) & tdc_mask;
542 }
543 
546  const int hf_lumi_shift, const HcalFeatureBit* embit)
547 {
548  // Align digis and TP
549  const int shift = samples.presamples() - numberOfPresamplesHF_;
550  assert(shift >= 0);
551  assert((shift + numberOfSamplesHF_) <= samples.size());
552 
553  // Try to find the HFDetails from the map corresponding to our samples
554  const HcalTrigTowerDetId detId(samples.id());
555  auto it = theHFUpgradeDetailMap.find(detId);
556  // Missing values will give an empty digi
557  if (it == theHFUpgradeDetailMap.end()) {
558  return;
559  }
560 
561  std::vector<std::bitset<2>> finegrain(numberOfSamplesHF_, false);
562 
563  // Set up out output of IntergerCaloSamples
565  output.setPresamples(numberOfPresamplesHF_);
566 
567  for (const auto& item: it->second) {
568  auto& details = item.second;
569  for (int ibin = 0; ibin < numberOfSamplesHF_; ++ibin) {
570  const int idx = ibin + shift;
571 
572  int long_fiber_val = 0;
573  int long_fiber_count = 0;
574  int short_fiber_val = 0;
575  int short_fiber_count = 0;
576 
577  bool saturated = false;
578 
579  for (auto i: {0, 2}) {
580  if (idx < details[i].samples.size() and details[i].validity[idx]) {
581  long_fiber_val += details[i].samples[idx];
582  saturated = saturated || (details[i].samples[idx] == QIE10_LINEARIZATION_ET);
583  ++long_fiber_count;
584  }
585  }
586  for (auto i: {1, 3}) {
587  if (idx < details[i].samples.size() and details[i].validity[idx]) {
588  short_fiber_val += details[i].samples[idx];
589  saturated = saturated || (details[i].samples[idx] == QIE10_LINEARIZATION_ET);
590  ++short_fiber_count;
591  }
592  }
593 
594  if (saturated) {
596  } else {
597  // For details of the energy handling, see:
598  // https://cms-docdb.cern.ch/cgi-bin/DocDB/ShowDocument?docid=12306
599  //
600  // If a channel for one fiber is invalid, use the value of the
601  // other channel (by doubling the sum) to calculate the
602  // energy in the fiber
603  if (long_fiber_count == 1)
604  long_fiber_val *= 2;
605  if (short_fiber_count == 1)
606  short_fiber_val *= 2;
607 
608  auto sum = long_fiber_val + short_fiber_val;
609  // Similar to above, if a fiber is invalid (i.e., both
610  // channels for the fiber invalid), substitute the value of
611  // the other fiber by doubling the sum.
612  if (long_fiber_count == 0 or short_fiber_count == 0)
613  sum *= 2;
614 
615  output[ibin] += sum;
616  }
617 
618  for (const auto& detail: details) {
619  if (idx < int(detail.digi.size()) and detail.validity[idx] and HcalDetId(detail.digi.id()).ietaAbs() >= FIRST_FINEGRAIN_TOWER) {
620  finegrain[ibin][1] = finegrain[ibin][1] or (detail.digi[idx].adc() > (int) FG_HF_threshold_);
621  }
622  }
623 
624  if (embit != 0) {
625  finegrain[ibin][0] = embit->fineGrainbit(
626  details[1].digi, details[3].digi,
627  details[0].digi, details[2].digi,
628  details[1].validity[idx], details[3].validity[idx],
629  details[0].validity[idx], details[2].validity[idx],
630  idx
631  );
632  }
633  }
634  }
635 
636  for (int bin = 0; bin < numberOfSamplesHF_; ++bin) {
637  output[bin] = min({(unsigned int) QIE10_MAX_LINEARIZATION_ET, output[bin]}) >> hf_lumi_shift;
638  }
639  std::vector<int> finegrain_converted;
640  for (const auto& fg: finegrain)
641  finegrain_converted.push_back(fg.to_ulong());
642  outcoder_->compress(output, finegrain_converted, result);
643 }
644 
646  for (HcalTrigPrimDigiCollection::iterator tp = result.begin(); tp != result.end(); ++tp){
647  bool ZS = true;
648  for (int i=0; i<tp->size(); ++i) {
649  if (tp->sample(i).compressedEt() > ZS_threshold_I_) {
650  ZS=false;
651  break;
652  }
653  }
654  if (ZS) tp->setZSInfo(false,true);
655  else tp->setZSInfo(true,false);
656  }
657 }
658 
660  const HcalElectronicsMap *emap,
662  ){
663  std::set<uint32_t> FrontEndErrors;
664 
666  const FEDRawData& raw = rawraw->FEDData(i);
667  if (raw.size()<12) continue;
668  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
669  if(!dccHeader) continue;
670  HcalHTRData htr;
671  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
672  if (!dccHeader->getSpigotPresent(spigot)) continue;
673  dccHeader->getSpigotData(spigot,htr,raw.size());
674  int dccid = dccHeader->getSourceId();
675  int errWord = htr.getErrorsWord() & 0x1FFFF;
676  bool HTRError = (!htr.check() || htr.isHistogramEvent() || (errWord & 0x800)!=0);
677 
678  if(HTRError) {
679  bool valid =false;
680  for(int fchan=0; fchan<3 && !valid; fchan++) {
681  for(int fib=0; fib<9 && !valid; fib++) {
682  HcalElectronicsId eid(fchan,fib,spigot,dccid-FEDNumbering::MINHCALFEDID);
683  eid.setHTR(htr.readoutVMECrateId(),htr.htrSlot(),htr.htrTopBottom());
684  DetId detId = emap->lookup(eid);
685  if(detId.null()) continue;
686  HcalSubdetector subdet=(HcalSubdetector(detId.subdetId()));
687  if (detId.det()!=4||
688  (subdet!=HcalBarrel && subdet!=HcalEndcap &&
689  subdet!=HcalForward )) continue;
690  std::vector<HcalTrigTowerDetId> ids = theTrigTowerGeometry->towerIds(detId);
691  for (std::vector<HcalTrigTowerDetId>::const_iterator triggerId=ids.begin(); triggerId != ids.end(); ++triggerId) {
692  FrontEndErrors.insert(triggerId->rawId());
693  }
694  //valid = true;
695  }
696  }
697  }
698  }
699  }
700 
701  // Loop over TP collection
702  // Set TP to zero if there is FE Format Error
703  HcalTriggerPrimitiveSample zeroSample(0);
704  for (HcalTrigPrimDigiCollection::iterator tp = result.begin(); tp != result.end(); ++tp){
705  if (FrontEndErrors.find(tp->id().rawId()) != FrontEndErrors.end()) {
706  for (int i=0; i<tp->size(); ++i) tp->setSample(i, zeroSample);
707  }
708  }
709 }
710 
711 void HcalTriggerPrimitiveAlgo::addFG(const HcalTrigTowerDetId& id, std::vector<bool>& msb){
712  FGbitMap::iterator itr = fgMap_.find(id);
713  if (itr != fgMap_.end()){
714  std::vector<bool>& _msb = itr->second;
715  for (size_t i=0; i<msb.size(); ++i)
716  _msb[i] = _msb[i] || msb[i];
717  }
718  else fgMap_[id] = msb;
719 }
720 
721 bool
723 {
724  if (depth > LAST_FINEGRAIN_DEPTH)
725  return false;
726  if (id.ietaAbs() > LAST_FINEGRAIN_TOWER)
727  return false;
728  if (id.ietaAbs() == HBHE_OVERLAP_TOWER and not upgrade_hb_)
729  return false;
730  return true;
731 }
732 
733 void
734 HcalTriggerPrimitiveAlgo::addUpgradeFG(const HcalTrigTowerDetId& id, int depth, const std::vector<std::bitset<2>>& bits)
735 {
736  if (not validUpgradeFG(id, depth)) {
737  return;
738  }
739 
740  auto it = fgUpgradeMap_.find(id);
741  if (it == fgUpgradeMap_.end()) {
742  FGUpgradeContainer element;
743  element.resize(bits.size());
744  it = fgUpgradeMap_.insert(std::make_pair(id, element)).first;
745  }
746  for (unsigned int i = 0; i < bits.size(); ++i) {
747  it->second[i][0][depth] = bits[i][0];
748  it->second[i][1][depth] = bits[i][1];
749  }
750 }
751 
753  if (algo <=0 && algo>2)
754  throw cms::Exception("ERROR: Only algo 1 & 2 are supported.") << std::endl;
756 }
757 
760 }
761 
764 }
int adc(sample_type sample)
get the ADC sample (12 bits)
int samples() const
total number of samples in the digi
T getParameter(std::string const &) const
void analyze(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result)
adds the actual RecHits
virtual void adc2Linear(const HBHEDataFrame &df, IntegerCaloSamples &ics) const override
void runFEFormatError(const FEDRawDataCollection *rawraw, const HcalElectronicsMap *emap, HcalTrigPrimDigiCollection &result)
HcalTriggerPrimitiveAlgo(bool pf, const std::vector< double > &w, int latency, uint32_t FG_threshold, uint32_t FG_HF_threshold, uint32_t ZS_threshold, int numberOfSamples, int numberOfPresamples, int numberOfSamplesHF, int numberOfPresamplesHF, uint32_t minSignalThreshold=0, uint32_t PMT_NoiseThreshold=0)
int presamples() const
access presample information
HFUpgradeDetailMap theHFUpgradeDetailMap
void analyzeHF(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result, const int hf_lumi_shift)
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:62
std::vector< HcalTrigTowerDetId > towerIds(const HcalDetId &cellId) const
the mapping to and from DetIds
const double w
Definition: UKUtility.cc:23
const HcalTPChannelParameter * getHcalTPChannelParameter(const HcalGenericDetId &fId) const
unsigned int htrTopBottom() const
HcalElectronicsId-style HTR top/bottom (1=top/0=bottom)
Definition: HcalHTRData.cc:342
static const int QIE10_MAX_LINEARIZATION_ET
void analyzeHF2016(const IntegerCaloSamples &SAMPLES, HcalTriggerPrimitiveDigi &result, const int HF_LUMI_SHIFT, const HcalFeatureBit *HCALFEM)
int presamples() const
for backward compatibility
int size() const
total number of samples in the digi
Definition: HBHEDataFrame.h:26
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::DataFrame::id_type id() const
const HcalTPGCompressor * outcoder_
void setPresamples(int pre)
set presample information
void addFG(const HcalTrigTowerDetId &id, std::vector< bool > &msb)
numberOfSamples
threshold for setting fine grain bit
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
uint32_t maskDepth() const
get the tower depth
Definition: HcalDetId.cc:121
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
bool validChannel(const QIE10DataFrame &digi, int ts) const
std::vector< IntegerCaloSamples > SumFGContainer
int size() const
get the size
unsigned int htrSlot() const
HcalElectronicsId-style HTR slot.
Definition: HcalHTRData.cc:338
int depth() const
get the tower depth
Definition: HcalDetId.cc:108
const HcalTrigTowerGeometry * theTrigTowerGeometry
FG_HF_threshold
threshold for setting fine grain bit
const HcalDbService * conditions_
void lookupMSB(const HBHEDataFrame &df, std::vector< bool > &msb) const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
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
edm::DataFrame::id_type id() const
HcalSubdetector
Definition: HcalAssistant.h:31
bool getSpigotPresent(unsigned int nspigot) const
Read the "PRESENT" bit for this spigot.
std::bitset< 4 > compute(const Tower &) const
T min(T a, T b)
Definition: MathUtil.h:58
void compress(const IntegerCaloSamples &ics, const std::vector< int > &fineGrain, HcalTriggerPrimitiveDigi &digi) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int presamples() const
number of samples before the sample from the triggered beam crossing (according to the hardware) ...
Definition: HBHEDataFrame.h:28
void runZS(HcalTrigPrimDigiCollection &tp)
std::vector< HcalTriggerPrimitiveDigi >::iterator iterator
bin
set the eta bin as selection string.
const_iterator end() const
int getSourceId() const
Definition: HcalDCCHeader.h:32
std::vector< HcalFinegrainBit::Tower > FGUpgradeContainer
Definition: DetId.h:18
void setHTR(int crate, int slot, int tb)
int size() const
total number of samples in the digi
Definition: HFDataFrame.h:26
unsigned long long override_tdc_hf_value_
bool validUpgradeFG(const HcalTrigTowerDetId &id, int depth) const
unsigned int getErrorsWord() const
Get the errors word.
Definition: HcalHTRData.h:157
static const int QIE11_MAX_LINEARIZATION_ET
int version() const
get the version code for the trigger tower
bool null() const
is this a null id ?
Definition: DetId.h:45
const HcalTPParameters * getHcalTPParameters() const
ZS_threshold
threshold for setting fine grain bit
void addUpgradeFG(const HcalTrigTowerDetId &id, int depth, const std::vector< std::bitset< 2 >> &bits)
unsigned int readoutVMECrateId() const
HcalElectronicsId-style VME crate number.
Definition: HcalHTRData.cc:346
int presamples() const
for backward compatibility
const HcaluLUTTPGCoder * incoder_
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
static unsigned int const shift
const HcalDetId & id() const
Definition: HBHEDataFrame.h:22
virtual bool fineGrainbit(const QIE10DataFrame &short1, const QIE10DataFrame &short2, const QIE10DataFrame &long1, const QIE10DataFrame &long2, bool validShort1, bool validShort2, bool validLong1, bool validLong2, int idx) const =0
int presamples() const
number of samples before the sample from the triggered beam crossing (according to the hardware) ...
Definition: HFDataFrame.h:28
const HcalDetId & id() const
Definition: HFDataFrame.h:22
void analyzeHF2017(const IntegerCaloSamples &SAMPLES, HcalTriggerPrimitiveDigi &result, const int HF_LUMI_SHIFT, const HcalFeatureBit *HCALFEM)
DetId id() const
get the (generic) id
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
int samples() const
total number of samples in the digi
latency
hardware algo
Readout chain identification for Hcal.
void addSignal(const HBHEDataFrame &frame)
adds the signal to the map
void setUpgradeFlags(bool hb, bool he, bool hf)
void overrideParameters(const edm::ParameterSet &ps)
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:385
const_iterator begin() const
uint32_t getMask() const
get mask for channel validity and self trigger information
void analyze2017(IntegerCaloSamples &samples, HcalTriggerPrimitiveDigi &result, const HcalFinegrainBit &fg_algo)