CMS 3D CMS Logo

CSCCathodeLCTProcessor.cc
Go to the documentation of this file.
2 
3 #include <iomanip>
4 #include <memory>
5 
6 // Default values of configuration parameters.
7 const unsigned int CSCCathodeLCTProcessor::def_fifo_tbins = 12;
8 const unsigned int CSCCathodeLCTProcessor::def_fifo_pretrig = 7;
9 const unsigned int CSCCathodeLCTProcessor::def_hit_persist = 6;
10 const unsigned int CSCCathodeLCTProcessor::def_drift_delay = 2;
14 const unsigned int CSCCathodeLCTProcessor::def_min_separation = 10;
16 
17 //----------------
18 // Constructors --
19 //----------------
20 
22  unsigned station,
23  unsigned sector,
24  unsigned subsector,
25  unsigned chamber,
26  const edm::ParameterSet& conf)
27  : CSCBaseboard(endcap, station, sector, subsector, chamber, conf) {
28  static std::atomic<bool> config_dumped{false};
29 
30  // CLCT configuration parameters.
31  fifo_tbins = clctParams_.getParameter<unsigned int>("clctFifoTbins");
32  hit_persist = clctParams_.getParameter<unsigned int>("clctHitPersist");
33  drift_delay = clctParams_.getParameter<unsigned int>("clctDriftDelay");
34  nplanes_hit_pretrig = clctParams_.getParameter<unsigned int>("clctNplanesHitPretrig");
35  nplanes_hit_pattern = clctParams_.getParameter<unsigned int>("clctNplanesHitPattern");
36 
37  // Not used yet.
38  fifo_pretrig = clctParams_.getParameter<unsigned int>("clctFifoPretrig");
39 
40  pid_thresh_pretrig = clctParams_.getParameter<unsigned int>("clctPidThreshPretrig");
41  min_separation = clctParams_.getParameter<unsigned int>("clctMinSeparation");
42 
43  start_bx_shift = clctParams_.getParameter<int>("clctStartBxShift");
44 
45  localShowerZone = clctParams_.getParameter<int>("clctLocalShowerZone");
46 
47  localShowerThresh = clctParams_.getParameter<int>("clctLocalShowerThresh");
48 
49  // Motherboard parameters: common for all configurations.
50  tmb_l1a_window_size = // Common to CLCT and TMB
51  tmbParams_.getParameter<unsigned int>("tmbL1aWindowSize");
52 
53  /*
54  In Summer 2021 the CLCT readout function was updated so that the
55  window is based on a number of time bins around the central CLCT
56  time BX7. In the past the window was based on early_tbins and late_tbins.
57  The parameter is kept, but is not used.
58  */
59  early_tbins = tmbParams_.getParameter<int>("tmbEarlyTbins");
60  if (early_tbins < 0)
62 
63  // wether to readout only the earliest two LCTs in readout window
64  readout_earliest_2 = tmbParams_.getParameter<bool>("tmbReadoutEarliest2");
65 
66  // Verbosity level, set to 0 (no print) by default.
67  infoV = clctParams_.getParameter<int>("verbosity");
68 
69  // Do not exclude pattern 0 and 1 when the Run-3 patterns are enabled!!
70  // Valid Run-3 patterns are 0,1,2,3,4
71  if (runCCLUT_) {
73  }
74 
75  // Check and print configuration parameters.
77  if ((infoV > 0) && !config_dumped) {
79  config_dumped = true;
80  }
81 
82  numStrips_ = 0; // Will be set later.
83  // Provisional, but should be OK for all stations except ME1.
84  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
85  if ((i_layer + 1) % 2 == 0)
86  stagger[i_layer] = 0;
87  else
88  stagger[i_layer] = 1;
89  }
90 
91  // which patterns should we use?
92  if (runCCLUT_) {
94  // comparator code lookup table algorithm for Phase-2
95  cclut_ = std::make_unique<ComparatorCodeLUT>(conf);
96  } else {
98  }
99 
100  const auto& shower = showerParams_.getParameterSet("cathodeShower");
101  thresholds_ = shower.getParameter<std::vector<unsigned>>("showerThresholds");
102  showerNumTBins_ = shower.getParameter<unsigned>("showerNumTBins");
103  minLayersCentralTBin_ = shower.getParameter<unsigned>("minLayersCentralTBin");
104  peakCheck_ = shower.getParameter<bool>("peakCheck");
108 
109  thePreTriggerDigis.clear();
110 
111  // quality control of stubs
112  qualityControl_ = std::make_unique<LCTQualityControl>(endcap, station, sector, subsector, chamber, conf);
113 }
114 
116  // Set default values for configuration parameters.
128 }
129 
130 // Set configuration parameters obtained via EventSetup mechanism.
132  static std::atomic<bool> config_dumped{false};
133 
134  fifo_tbins = conf->clctFifoTbins();
135  fifo_pretrig = conf->clctFifoPretrig();
136  hit_persist = conf->clctHitPersist();
137  drift_delay = conf->clctDriftDelay();
142 
143  // Check and print configuration parameters.
145  if (!config_dumped) {
147  config_dumped = true;
148  }
151 }
152 
153 void CSCCathodeLCTProcessor::setESLookupTables(const CSCL1TPLookupTableCCLUT* conf) { cclut_->setESLookupTables(conf); }
154 
156  // Make sure that the parameter values are within the allowed range.
157 
158  // Max expected values.
159  static const unsigned int max_fifo_tbins = 1 << 5;
160  static const unsigned int max_fifo_pretrig = 1 << 5;
161  static const unsigned int max_hit_persist = 1 << 4;
162  static const unsigned int max_drift_delay = 1 << 2;
163  static const unsigned int max_nplanes_hit_pretrig = 1 << 3;
164  static const unsigned int max_nplanes_hit_pattern = 1 << 3;
165  static const unsigned int max_pid_thresh_pretrig = 1 << 4;
166  static const unsigned int max_min_separation = CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER;
167  static const unsigned int max_tmb_l1a_window_size = 1 << 4;
168 
169  // Checks.
170  CSCBaseboard::checkConfigParameters(fifo_tbins, max_fifo_tbins, def_fifo_tbins, "fifo_tbins");
171  CSCBaseboard::checkConfigParameters(fifo_pretrig, max_fifo_pretrig, def_fifo_pretrig, "fifo_pretrig");
172  CSCBaseboard::checkConfigParameters(hit_persist, max_hit_persist, def_hit_persist, "hit_persist");
173  CSCBaseboard::checkConfigParameters(drift_delay, max_drift_delay, def_drift_delay, "drift_delay");
175  nplanes_hit_pretrig, max_nplanes_hit_pretrig, def_nplanes_hit_pretrig, "nplanes_hit_pretrig");
177  nplanes_hit_pattern, max_nplanes_hit_pattern, def_nplanes_hit_pattern, "nplanes_hit_pattern");
179  pid_thresh_pretrig, max_pid_thresh_pretrig, def_pid_thresh_pretrig, "pid_thresh_pretrig");
180  CSCBaseboard::checkConfigParameters(min_separation, max_min_separation, def_min_separation, "min_separation");
182  tmb_l1a_window_size, max_tmb_l1a_window_size, def_tmb_l1a_window_size, "tmb_l1a_window_size");
184 }
185 
187  thePreTriggerDigis.clear();
188  thePreTriggerBXs.clear();
189  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
190  bestCLCT[bx].clear();
191  secondCLCT[bx].clear();
193  localShowerFlag[bx] = false; //init with no shower around CLCT
194  }
195 }
196 
197 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::run(const CSCComparatorDigiCollection* compdc) {
198  // This is the version of the run() function that is called when running
199  // over the entire detector. It gets the comparator & timing info from the
200  // comparator digis and then passes them on to another run() function.
201 
202  static std::atomic<bool> config_dumped{false};
203  if ((infoV > 0) && !config_dumped) {
205  config_dumped = true;
206  }
207 
208  // Get the number of strips and stagger of layers for the given chamber.
209  // Do it only once per chamber.
210  if (numStrips_ <= 0 or numStrips_ > CSCConstants::MAX_NUM_STRIPS_RUN2) {
211  if (cscChamber_) {
213 
214  // ME1/a is known to the readout hardware as strips 65-80 of ME1/1.
215  // Still need to decide whether we do any special adjustments to
216  // reconstruct LCTs in this region (3:1 ganged strips); for now, we
217  // simply allow for hits in ME1/a and apply standard reconstruction
218  // to them.
219  // For Phase2 ME1/1 is set to have 4 CFEBs in ME1/b and 3 CFEBs in ME1/a
220  if (isME11_) {
221  if (theRing == 4) {
222  edm::LogError("CSCCathodeLCTProcessor|SetupError")
223  << "+++ Invalid ring number for this processor " << theRing << " was set in the config."
224  << " +++\n"
225  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
226  }
227  if (!disableME1a_ && theRing == 1 && !gangedME1a_)
229  if (!disableME1a_ && theRing == 1 && gangedME1a_)
231  if (disableME1a_ && theRing == 1)
233  }
234 
235  numHalfStrips_ = 2 * numStrips_ + 1;
237 
239  edm::LogError("CSCCathodeLCTProcessor|SetupError")
240  << "+++ Number of strips, " << numStrips_ << " found in " << theCSCName_ << " (sector " << theSector
241  << " subsector " << theSubsector << " trig id. " << theTrigChamber << ")"
242  << " exceeds max expected, " << CSCConstants::MAX_NUM_STRIPS_RUN2 << " +++\n"
243  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
244  numStrips_ = -1;
245  numHalfStrips_ = -1;
246  numCFEBs_ = -1;
247  }
248  // The strips for a given layer may be offset from the adjacent layers.
249  // This was done in order to improve resolution. We need to find the
250  // 'staggering' for each layer and make necessary conversions in our
251  // arrays. -JM
252  // In the TMB-07 firmware, half-strips in odd layers (layers are
253  // counted as ly0-ly5) are shifted by -1 half-strip, whereas in
254  // the previous firmware versions half-strips in even layers
255  // were shifted by +1 half-strip. This difference is due to a
256  // change from ly3 to ly2 in the choice of the key layer, and
257  // the intention to keep half-strips in the key layer unchanged.
258  // In the emulator, we use the old way for both cases, to avoid
259  // negative half-strip numbers. This will necessitate a
260  // subtraction of 1 half-strip for TMB-07 later on. -SV.
261  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
262  stagger[i_layer] = (cscChamber_->layer(i_layer + 1)->geometry()->stagger() + 1) / 2;
263  }
264  } else {
265  edm::LogError("CSCCathodeLCTProcessor|ConfigError")
266  << " " << theCSCName_ << " (sector " << theSector << " subsector " << theSubsector << " trig id. "
267  << theTrigChamber << ")"
268  << " is not defined in current geometry! +++\n"
269  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
270  numStrips_ = -1;
271  numHalfStrips_ = -1;
272  numCFEBs_ = -1;
273  }
274  }
275 
276  if (numStrips_ <= 0 or 2 * (unsigned)numStrips_ > qualityControl_->get_csc_max_halfstrip(theStation, theRing)) {
277  edm::LogError("CSCCathodeLCTProcessor|ConfigError")
278  << " " << theCSCName_ << " (sector " << theSector << " subsector " << theSubsector << " trig id. "
279  << theTrigChamber << "):"
280  << " numStrips_ = " << numStrips_ << "; CLCT emulation skipped! +++";
281  std::vector<CSCCLCTDigi> emptyV;
282  return emptyV;
283  }
284 
285  // Get comparator digis in this chamber.
286  bool hasDigis = getDigis(compdc);
287 
288  if (hasDigis) {
289  // Get halfstrip times from comparator digis.
291  readComparatorDigis(halfStripTimes);
292 
293  // Pass arrays of halfstrips on to another run() doing the
294  // LCT search.
295  // If the number of layers containing digis is smaller than that
296  // required to trigger, quit right away. (If LCT-based digi suppression
297  // is implemented one day, this condition will have to be changed
298  // to the number of planes required to pre-trigger.)
299  unsigned int layersHit = 0;
300  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
301  for (int i_hstrip = 0; i_hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; i_hstrip++) {
302  if (!halfStripTimes[i_layer][i_hstrip].empty()) {
303  layersHit++;
304  break;
305  }
306  }
307  }
308  // Run the algorithm only if the probability for the pre-trigger
309  // to fire is not null. (Pre-trigger decisions are used for the
310  // strip read-out conditions in DigiToRaw.)
311  if (layersHit >= nplanes_hit_pretrig)
312  run(halfStripTimes);
313 
314  // Get the high multiplicity bits in this chamber
316  }
317 
318  // Return vector of CLCTs.
319  std::vector<CSCCLCTDigi> tmpV = getCLCTs();
320 
321  // shift the BX from 7 to 8
322  // the unpacked real data CLCTs have central BX at bin 7
323  // however in simulation the central BX is bin 8
324  // to make a proper comparison with ALCTs we need
325  // CLCT and ALCT to have the central BX in the same bin
326  // this shift does not affect the readout of the CLCTs
327  // emulated CLCTs put in the event should be centered at bin 7 (as in data)
328  for (auto& p : tmpV) {
329  p.setBX(p.getBX() + CSCConstants::ALCT_CLCT_OFFSET);
330  }
331 
332  return tmpV;
333 }
334 
337  // This version of the run() function can either be called in a standalone
338  // test, being passed the halfstrip times, or called by the
339  // run() function above. It uses the findLCTs() method to find vectors
340  // of LCT candidates. These candidates are already sorted and the best two per bx
341  // are returned.
342 
343  // initialize the pulse array.
344  // add 1 for possible stagger
346 
347  std::vector<CSCCLCTDigi> CLCTlist = findLCTs(halfstrip);
348 
349  for (const auto& p : CLCTlist) {
350  const int bx = p.getBX();
352  if (infoV > 0)
353  edm::LogWarning("L1CSCTPEmulatorOutOfTimeCLCT")
354  << "+++ Bx of CLCT candidate, " << bx << ", exceeds max allowed, " << CSCConstants::MAX_CLCT_TBINS - 1
355  << "; skipping it... +++\n";
356  continue;
357  }
358 
359  if (!bestCLCT[bx].isValid()) {
360  bestCLCT[bx] = p;
361  } else if (!secondCLCT[bx].isValid()) {
362  secondCLCT[bx] = p;
363  }
364  }
365 
366  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
367  if (bestCLCT[bx].isValid()) {
368  bestCLCT[bx].setTrknmb(1);
369 
370  // check if the LCT is valid
371  qualityControl_->checkValid(bestCLCT[bx]);
372 
373  if (infoV > 0)
374  LogDebug("CSCCathodeLCTProcessor")
376  << " (sector " << theSector << " subsector " << theSubsector << " trig id. " << theTrigChamber << ")"
377  << "\n";
378  }
379  if (secondCLCT[bx].isValid()) {
380  secondCLCT[bx].setTrknmb(2);
381 
382  // check if the LCT is valid
383  qualityControl_->checkValid(secondCLCT[bx]);
384 
385  if (infoV > 0)
386  LogDebug("CSCCathodeLCTProcessor")
388  << " (sector " << theSector << " subsector " << theSubsector << " trig id. " << theTrigChamber << ")"
389  << "\n";
390  }
391  }
392  checkLocalShower(localShowerZone, halfstrip);
393  // Now that we have our best CLCTs, they get correlated with the best
394  // ALCTs and then get sent to the MotherBoard. -JM
395 }
396 
398  int zone,
400  // Fire half-strip one-shots for hit_persist bx's (4 bx's by default).
401  //check local shower after pulse extension
402  pulseExtension(halfstrip);
403 
404  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
405  if (not bestCLCT[bx].isValid())
406  continue;
407 
408  //only check the region around best CLCT
409  int keyHS = bestCLCT[bx].getKeyStrip();
410  int minHS = (keyHS - zone) >= stagger[CSCConstants::KEY_CLCT_LAYER - 1] ? keyHS - zone
412  int maxHS = (keyHS + zone) >= numHalfStrips_ ? numHalfStrips_ : keyHS + zone;
413  int totalHits = 0;
414  for (int hstrip = minHS; hstrip < maxHS; hstrip++) {
415  for (int this_layer = 0; this_layer < CSCConstants::NUM_LAYERS; this_layer++)
416  if (pulse_.isOneShotHighAtBX(this_layer, hstrip, bx + drift_delay))
417  totalHits++;
418  }
419 
420  localShowerFlag[bx] = totalHits >= localShowerThresh;
421  if (infoV > 1)
422  LogDebug("CSCCathodeLCTProcessor") << " bx " << bx << " bestCLCT key HS " << keyHS
423  << " localshower zone: " << minHS << ", " << maxHS << " totalHits "
424  << totalHits
425  << (localShowerFlag[bx] ? " Validlocalshower " : " NolocalShower ");
426  }
427 }
428 
430  bool hasDigis = false;
431 
432  // Loop over layers and save comparator digis on each one into digiV[layer].
433  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
434  digiV[i_layer].clear();
435 
436  CSCDetId detid(theEndcap, theStation, theRing, theChamber, i_layer + 1);
437  getDigis(compdc, detid);
438 
439  if (isME11_ && !disableME1a_) {
440  CSCDetId detid_me1a(theEndcap, theStation, 4, theChamber, i_layer + 1);
441  getDigis(compdc, detid_me1a);
442  }
443 
444  if (!digiV[i_layer].empty()) {
445  hasDigis = true;
446  if (infoV > 1) {
447  LogTrace("CSCCathodeLCTProcessor") << "found " << digiV[i_layer].size() << " comparator digi(s) in layer "
448  << i_layer << " of " << detid.chamberName() << " (trig. sector " << theSector
449  << " subsector " << theSubsector << " id " << theTrigChamber << ")";
450  }
451  }
452  }
453 
454  return hasDigis;
455 }
456 
458  const bool me1a = (id.station() == 1) && (id.ring() == 4);
459  const CSCComparatorDigiCollection::Range rcompd = compdc->get(id);
460  for (CSCComparatorDigiCollection::const_iterator digiIt = rcompd.first; digiIt != rcompd.second; ++digiIt) {
461  const unsigned int origStrip = digiIt->getStrip();
462  const unsigned int maxStripsME1a =
464  // this special case can only be reached in MC
465  // in real data, the comparator digis have always ring==1
466  if (me1a && origStrip <= maxStripsME1a && !disableME1a_) {
467  // Move ME1/A comparators from CFEB=0 to CFEB=4 if this has not
468  // been done already.
469  CSCComparatorDigi digi_corr(
470  origStrip + CSCConstants::NUM_STRIPS_ME1B, digiIt->getComparator(), digiIt->getTimeBinWord());
471  digiV[id.layer() - 1].push_back(digi_corr);
472  } else {
473  digiV[id.layer() - 1].push_back(*digiIt);
474  }
475  }
476 }
477 
480  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
481  int i_digi = 0; // digi counter, for dumps.
482  for (std::vector<CSCComparatorDigi>::iterator pld = digiV[i_layer].begin(); pld != digiV[i_layer].end();
483  pld++, i_digi++) {
484  // Dump raw digi info.
485  if (infoV > 1) {
486  std::ostringstream strstrm;
487  strstrm << "Comparator digi: comparator = " << pld->getComparator() << " strip #" << pld->getStrip()
488  << " time bins on:";
489  std::vector<int> bx_times = pld->getTimeBinsOn();
490  for (unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
491  strstrm << " " << bx_times[tbin];
492  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
493  }
494 
495  // Get comparator: 0/1 for left/right halfstrip for each comparator
496  // that fired.
497  int thisComparator = pld->getComparator();
498  if (thisComparator != 0 && thisComparator != 1) {
499  if (infoV >= 0)
500  edm::LogWarning("L1CSCTPEmulatorWrongInput")
501  << "+++ station " << theStation << " ring " << theRing << " chamber " << theChamber
502  << " Found comparator digi with wrong comparator value = " << thisComparator << "; skipping it... +++\n";
503  continue;
504  }
505 
506  // Get strip number.
507  int thisStrip = pld->getStrip() - 1; // count from 0
508  if (thisStrip < 0 || thisStrip >= numStrips_) {
509  if (infoV >= 0)
510  edm::LogWarning("L1CSCTPEmulatorWrongInput")
511  << "+++ station " << theStation << " ring " << theRing << " chamber " << theChamber
512  << " Found comparator digi with wrong strip number = " << thisStrip << " (max strips = " << numStrips_
513  << "); skipping it... +++\n";
514  continue;
515  }
516  // 2*strip: convert strip to 1/2 strip
517  // comp : comparator output
518  // stagger: stagger for this layer
519  int thisHalfstrip = 2 * thisStrip + thisComparator + stagger[i_layer];
520  if (thisHalfstrip >= numHalfStrips_) {
521  if (infoV >= 0)
522  edm::LogWarning("L1CSCTPEmulatorWrongInput")
523  << "+++ station " << theStation << " ring " << theRing << " chamber " << theChamber
524  << " Found wrong halfstrip number = " << thisHalfstrip << "; skipping this digi... +++\n";
525  continue;
526  }
527 
528  // Get bx times on this digi and check that they are within the bounds.
529  std::vector<int> bx_times = pld->getTimeBinsOn();
530  for (unsigned int i = 0; i < bx_times.size(); i++) {
531  // Total number of time bins in DAQ readout is given by fifo_tbins,
532  // which thus determines the maximum length of time interval.
533  //
534  // In data, only the CLCT in the time bin that was matched with L1A are read out
535  // while comparator digi is read out by 12 time bin, which includes 12 time bin info
536  // in other word, CLCTs emulated from comparator digis usually showed the OTMB behavior in 12 time bin
537  // while CLCT from data only showed 1 time bin OTMB behavior
538  // the CLCT emulated from comparator digis usually is centering at time bin 7 (BX7) and
539  // it is definitly safe to ignore any CLCTs in bx 0 or 1 and those CLCTs will never impacts on any triggers
540  if (bx_times[i] > 1 && bx_times[i] < static_cast<int>(fifo_tbins)) {
541  if (i == 0 || (i > 0 && bx_times[i] - bx_times[i - 1] >= static_cast<int>(hit_persist))) {
542  // A later hit on the same strip is ignored during the
543  // number of clocks defined by the "hit_persist" parameter
544  // (i.e., 6 bx's by default).
545  if (infoV > 1)
546  LogTrace("CSCCathodeLCTProcessor")
547  << "Comp digi: layer " << i_layer + 1 << " digi #" << i_digi + 1 << " strip " << thisStrip
548  << " halfstrip " << thisHalfstrip << " time " << bx_times[i] << " comparator " << thisComparator
549  << " stagger " << stagger[i_layer];
550  halfstrip[i_layer][thisHalfstrip].push_back(bx_times[i]);
551  } else if (i > 0) {
552  if (infoV > 1)
553  LogTrace("CSCCathodeLCTProcessor")
554  << "+++ station " << theStation << " ring " << theRing << " chamber " << theChamber
555  << " Skipping comparator digi: strip = " << thisStrip << ", layer = " << i_layer + 1
556  << ", bx = " << bx_times[i] << ", bx of previous hit = " << bx_times[i - 1];
557  }
558  } else {
559  if (infoV > 1)
560  LogTrace("CSCCathodeLCTProcessor") << "+++ station " << theStation << " ring " << theRing << " chamber "
561  << theChamber << "+++ Skipping comparator digi: strip = " << thisStrip
562  << ", layer = " << i_layer + 1 << ", bx = " << bx_times[i] << " +++";
563  }
564  }
565  }
566  }
567 }
568 
569 // TMB-07 version.
570 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::findLCTs(
572  std::vector<CSCCLCTDigi> lctList;
573 
574  if (infoV > 1)
575  dumpDigis(halfstrip);
576 
577  // Fire half-strip one-shots for hit_persist bx's (4 bx's by default).
578  pulseExtension(halfstrip);
579 
580  unsigned int start_bx = start_bx_shift;
581  // Stop drift_delay bx's short of fifo_tbins since at later bx's we will
582  // not have a full set of hits to start pattern search anyway.
583  unsigned int stop_bx = fifo_tbins - drift_delay;
584  // Allow for more than one pass over the hits in the time window.
585  while (start_bx < stop_bx) {
586  // temp CLCT objects
587  CSCCLCTDigi tempBestCLCT;
588  CSCCLCTDigi tempSecondCLCT;
589 
590  // All half-strip pattern envelopes are evaluated simultaneously, on every
591  // clock cycle.
592  int first_bx = 999;
593  bool pre_trig = preTrigger(start_bx, first_bx);
594 
595  // If any of half-strip envelopes has enough layers hit in it, TMB
596  // will pre-trigger.
597  if (pre_trig) {
598  thePreTriggerBXs.push_back(first_bx);
599  if (infoV > 1)
600  LogTrace("CSCCathodeLCTProcessor") << "..... pretrigger at bx = " << first_bx << "; waiting drift delay .....";
601 
602  // TMB latches LCTs drift_delay clocks after pretrigger.
603  // in the configuration the drift_delay is set to 2bx by default
604  // this is the time that is required for the electrons to drift to the
605  // cathode strips. 15ns drift time --> 45 ns is 3 sigma for the delay
606  // this corresponds to 2bx
607  int latch_bx = first_bx + drift_delay;
608 
609  // define a new pattern map
610  // for each key half strip, and for each pattern, store the 2D collection of fired comparator digis
611  std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
612  hits_in_patterns.clear();
613 
614  // We check if there is at least one key half strip for which at least
615  // one pattern id has at least the minimum number of hits
616  bool hits_in_time = patternFinding(latch_bx, hits_in_patterns);
617  if (infoV > 1) {
618  if (hits_in_time) {
619  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
620  if (nhits[hstrip] > 0) {
621  LogTrace("CSCCathodeLCTProcessor")
622  << " bx = " << std::setw(2) << latch_bx << " --->"
623  << " halfstrip = " << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip]
624  << " nhits = " << nhits[hstrip];
625  }
626  }
627  }
628  }
629  // This trigger emulator does not have an active CFEB flag for DAQ (csc trigger hardware: AFF)
630  // This is a fundamental difference with the firmware where the TMB prepares the DAQ to
631  // read out the chamber
632 
633  // The pattern finder runs continuously, so another pre-trigger
634  // could occur already at the next bx.
635 
636  // Quality for sorting.
638  int best_halfstrip[CSCConstants::MAX_CLCTS_PER_PROCESSOR];
639  int best_quality[CSCConstants::MAX_CLCTS_PER_PROCESSOR];
640 
641  for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++) {
642  best_halfstrip[ilct] = -1;
643  best_quality[ilct] = 0;
644  }
645 
646  // Calculate quality from pattern id and number of hits, and
647  // simultaneously select best-quality LCT.
648  if (hits_in_time) {
649  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
650  // The bend-direction bit pid[0] is ignored (left and right
651  // bends have equal quality).
652  quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
653  if (quality[hstrip] > best_quality[0]) {
654  best_halfstrip[0] = hstrip;
655  best_quality[0] = quality[hstrip];
656  }
657  // temporary alias
658  const int best_hs(best_halfstrip[0]);
659  // construct a CLCT if the trigger condition has been met
660  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
661  // overwrite the current best CLCT
662  tempBestCLCT = constructCLCT(first_bx, best_hs, hits_in_patterns[best_hs][best_pid[best_hs]]);
663  }
664  }
665  }
666 
667  // If 1st best CLCT is found, look for the 2nd best.
668  if (best_halfstrip[0] >= 0) {
669  // Get the half-strip of the best CLCT in this BX that was put into the list.
670  // You do need to re-add the any stagger, because the busy keys are based on
671  // the pulse array which takes into account strip stagger!!!
672  const unsigned halfStripBestCLCT(tempBestCLCT.getKeyStrip() + stagger[CSCConstants::KEY_CLCT_LAYER - 1]);
673 
674  // Mark keys near best CLCT as busy by setting their quality to
675  // zero, and repeat the search.
676  markBusyKeys(halfStripBestCLCT, best_pid[halfStripBestCLCT], quality);
677 
678  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
679  if (quality[hstrip] > best_quality[1]) {
680  best_halfstrip[1] = hstrip;
681  best_quality[1] = quality[hstrip];
682  }
683  // temporary alias
684  const int best_hs(best_halfstrip[1]);
685  // construct a CLCT if the trigger condition has been met
686  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
687  // overwrite the current second best CLCT
688  tempSecondCLCT = constructCLCT(first_bx, best_hs, hits_in_patterns[best_hs][best_pid[best_hs]]);
689  }
690  }
691 
692  // Sort bestCLCT and secondALCT by quality
693  // if qualities are the same, sort by run-2 or run-3 pattern
694  // if qualities and patterns are the same, sort by half strip number
695  bool changeOrder = false;
696 
697  unsigned qualityBest = 0, qualitySecond = 0;
698  unsigned patternBest = 0, patternSecond = 0;
699  unsigned halfStripBest = 0, halfStripSecond = 0;
700 
701  if (tempBestCLCT.isValid() and tempSecondCLCT.isValid()) {
702  qualityBest = tempBestCLCT.getQuality();
703  qualitySecond = tempSecondCLCT.getQuality();
704  if (!runCCLUT_) {
705  patternBest = tempBestCLCT.getPattern();
706  patternSecond = tempSecondCLCT.getPattern();
707  } else {
708  patternBest = tempBestCLCT.getRun3Pattern();
709  patternSecond = tempSecondCLCT.getRun3Pattern();
710  }
711  halfStripBest = tempBestCLCT.getKeyStrip();
712  halfStripSecond = tempSecondCLCT.getKeyStrip();
713 
714  if (qualitySecond > qualityBest)
715  changeOrder = true;
716  else if ((qualitySecond == qualityBest) and (int(patternSecond / 2) > int(patternBest / 2)))
717  changeOrder = true;
718  else if ((qualitySecond == qualityBest) and (int(patternSecond / 2) == int(patternBest / 2)) and
719  (halfStripSecond < halfStripBest))
720  changeOrder = true;
721  }
722 
723  CSCCLCTDigi tempCLCT;
724  if (changeOrder) {
725  tempCLCT = tempBestCLCT;
726  tempBestCLCT = tempSecondCLCT;
727  tempSecondCLCT = tempCLCT;
728  }
729 
730  // add the CLCTs to the collection
731  if (tempBestCLCT.isValid()) {
732  lctList.push_back(tempBestCLCT);
733  }
734  if (tempSecondCLCT.isValid()) {
735  lctList.push_back(tempSecondCLCT);
736  }
737  } //find CLCT, end of best_halfstrip[0] >= 0
738 
739  // If there is a trigger, CLCT pre-trigger state machine
740  // checks the number of hits that lie within a pattern template
741  // at every bx, and waits for it to drop below threshold.
742  // The search for CLCTs resumes only when the number of hits
743  // drops below threshold.
744  start_bx = fifo_tbins;
745  // Stop checking drift_delay bx's short of fifo_tbins since
746  // at later bx's we won't have a full set of hits for a
747  // pattern search anyway.
748  unsigned int stop_time = fifo_tbins - drift_delay;
749  for (unsigned int bx = latch_bx + 1; bx < stop_time; bx++) {
750  bool return_to_idle = true;
751  bool hits_in_time = patternFinding(bx, hits_in_patterns);
752  if (hits_in_time) {
753  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
754  // the dead-time is done at the pre-trigger, not at the trigger
755  if (nhits[hstrip] >= nplanes_hit_pretrig) {
756  if (infoV > 1)
757  LogTrace("CSCCathodeLCTProcessor") << " State machine busy at bx = " << bx;
758  return_to_idle = false;
759  break;
760  }
761  }
762  }
763  if (return_to_idle) {
764  if (infoV > 1)
765  LogTrace("CSCCathodeLCTProcessor") << " State machine returns to idle state at bx = " << bx;
766  start_bx = bx;
767  break;
768  }
769  }
770  } //pre_trig
771  else {
772  start_bx = first_bx + 1; // no dead time
773  }
774  }
775 
776  return lctList;
777 } // findLCTs -- TMB-07 version.
778 
779 // Common to all versions.
782  const unsigned bits_in_pulse = pulse_.bitsInPulse();
783 
784  // Clear pulse array. This array will be used as a bit representation of
785  // hit times. For example: if strip[1][2] has a value of 3, then 1 shifted
786  // left 3 will be bit pattern of pulse[1][2]. This would make the pattern
787  // look like 0000000000001000. Then add on additional bits to signify
788  // the duration of a signal (hit_persist, formerly bx_width) to simulate
789  // the TMB's drift delay. So for the same pulse[1][2] with a hit_persist
790  // of 3 would look like 0000000000111000. This is similating the digital
791  // one-shot in the TMB.
792  pulse_.clear();
793 
794  // Loop over all layers and halfstrips.
795  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
796  for (int i_strip = 0; i_strip < numHalfStrips_; i_strip++) {
797  // If there is a hit, simulate digital one-shot persistence starting
798  // in the bx of the initial hit. Fill this into pulse[][].
799  if (!time[i_layer][i_strip].empty()) {
800  std::vector<int> bx_times = time[i_layer][i_strip];
801  for (unsigned int i = 0; i < bx_times.size(); i++) {
802  // Check that min and max times are within the allowed range.
803  if (bx_times[i] < 0 || bx_times[i] + hit_persist >= bits_in_pulse) {
804  if (infoV > 0)
805  edm::LogWarning("L1CSCTPEmulatorOutOfTimeDigi")
806  << "+++ BX time of comparator digi (halfstrip = " << i_strip << " layer = " << i_layer
807  << ") bx = " << bx_times[i] << " is not within the range (0-" << bits_in_pulse
808  << "] allowed for pulse extension. Skip this digi! +++\n";
809  continue;
810  }
811  if (bx_times[i] >= start_bx_shift) {
812  pulse_.extend(i_layer, i_strip, bx_times[i], hit_persist);
813  }
814  }
815  }
816  }
817  }
818 } // pulseExtension.
819 
820 // TMB-07 version.
821 bool CSCCathodeLCTProcessor::preTrigger(const int start_bx, int& first_bx) {
822  if (infoV > 1)
823  LogTrace("CSCCathodeLCTProcessor") << "....................PreTrigger...........................";
824 
825  int nPreTriggers = 0;
826 
827  bool pre_trig = false;
828  // Now do a loop over bx times to see (if/when) track goes over threshold
829  for (unsigned int bx_time = start_bx; bx_time < fifo_tbins; bx_time++) {
830  // For any given bunch-crossing, start at the lowest keystrip and look for
831  // the number of separate layers in the pattern for that keystrip that have
832  // pulses at that bunch-crossing time. Do the same for the next keystrip,
833  // etc. Then do the entire process again for the next bunch-crossing, etc
834  // until you find a pre-trigger.
835 
836  std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>> hits_in_patterns;
837  hits_in_patterns.clear();
838 
839  bool hits_in_time = patternFinding(bx_time, hits_in_patterns);
840  if (hits_in_time) {
841  // clear the pretriggers
843 
844  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
845  // check the properties of the pattern on this halfstrip
846  if (infoV > 1) {
847  if (nhits[hstrip] > 0) {
848  LogTrace("CSCCathodeLCTProcessor")
849  << " bx = " << std::setw(2) << bx_time << " --->"
850  << " halfstrip = " << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip]
851  << " nhits = " << nhits[hstrip];
852  }
853  }
854  // a pretrigger was found
855  if (nhits[hstrip] >= nplanes_hit_pretrig && best_pid[hstrip] >= pid_thresh_pretrig) {
856  pre_trig = true;
857  ispretrig_[hstrip] = true;
858 
859  // write each pre-trigger to output
860  nPreTriggers++;
861  thePreTriggerDigis.push_back(constructPreCLCT(bx_time, hstrip, nPreTriggers));
862  }
863  }
864 
865  // upon the first pretrigger, we save first BX and exit
866  if (pre_trig) {
867  first_bx = bx_time; // bx at time of pretrigger
868  return true;
869  }
870  }
871  } // end loop over bx times
872 
873  if (infoV > 1)
874  LogTrace("CSCCathodeLCTProcessor") << "no pretrigger, returning \n";
875  first_bx = fifo_tbins;
876  return false;
877 } // preTrigger -- TMB-07 version.
878 
879 // TMB-07 version.
881  const unsigned int bx_time, std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer>>& hits_in_patterns) {
882  if (bx_time >= fifo_tbins)
883  return false;
884 
885  unsigned layers_hit = pulse_.numberOfLayersAtBX(bx_time);
886  if (layers_hit < nplanes_hit_pretrig)
887  return false;
888 
889  for (int key_hstrip = 0; key_hstrip < numHalfStrips_; key_hstrip++) {
890  best_pid[key_hstrip] = 0;
891  nhits[key_hstrip] = 0;
892  }
893 
894  bool hit_layer[CSCConstants::NUM_LAYERS];
895 
896  // Loop over candidate key strips.
897  for (int key_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; key_hstrip < numHalfStrips_; key_hstrip++) {
898  // Loop over patterns and look for hits matching each pattern.
899  for (unsigned int pid = clct_pattern_.size() - 1; pid >= pid_thresh_pretrig and pid < clct_pattern_.size(); pid--) {
900  layers_hit = 0;
901  // clear all layers
902  for (int ilayer = 0; ilayer < CSCConstants::NUM_LAYERS; ilayer++) {
903  hit_layer[ilayer] = false;
904  }
905 
906  // clear a single pattern!
907  CSCCLCTDigi::ComparatorContainer hits_single_pattern;
908  hits_single_pattern.resize(6);
909  for (auto& p : hits_single_pattern) {
911  }
912 
913  // clear all medians
914  double num_pattern_hits = 0., times_sum = 0.;
915  std::multiset<int> mset_for_median;
916  mset_for_median.clear();
917 
918  // Loop over halfstrips in trigger pattern mask and calculate the
919  // "absolute" halfstrip number for each.
920  for (int this_layer = 0; this_layer < CSCConstants::NUM_LAYERS; this_layer++) {
921  for (int strip_num = 0; strip_num < CSCConstants::CLCT_PATTERN_WIDTH; strip_num++) {
922  // ignore "0" half-strips in the pattern
923  if (clct_pattern_[pid][this_layer][strip_num] == 0)
924  continue;
925 
926  // the current strip is the key half-strip plus the offset (can be negative or positive)
927  int this_strip = CSCPatternBank::clct_pattern_offset_[strip_num] + key_hstrip;
928 
929  // current strip should be valid of course
930  if (this_strip >= 0 && this_strip < numHalfStrips_) {
931  if (infoV > 3) {
932  LogTrace("CSCCathodeLCTProcessor") << " In patternFinding: key_strip = " << key_hstrip << " pid = " << pid
933  << " layer = " << this_layer << " strip = " << this_strip << std::endl;
934  }
935  // Determine if "one shot" is high at this bx_time
936  if (pulse_.isOneShotHighAtBX(this_layer, this_strip, bx_time)) {
937  if (hit_layer[this_layer] == false) {
938  hit_layer[this_layer] = true;
939  layers_hit++; // determines number of layers hit
940  // add this strip in this layer to the pattern we are currently considering
941  hits_single_pattern[this_layer][strip_num] = this_strip - stagger[this_layer];
942  }
943 
944  // find at what bx did pulse on this halsfstrip & layer have started
945  // use hit_persist constraint on how far back we can go
946  int first_bx_layer = bx_time;
947  for (unsigned int dbx = 0; dbx < hit_persist; dbx++) {
948  if (pulse_.isOneShotHighAtBX(this_layer, this_strip, first_bx_layer - 1))
949  first_bx_layer--;
950  else
951  break;
952  }
953  times_sum += (double)first_bx_layer;
954  num_pattern_hits += 1.;
955  mset_for_median.insert(first_bx_layer);
956  if (infoV > 2)
957  LogTrace("CSCCathodeLCTProcessor") << " 1st bx in layer: " << first_bx_layer << " sum bx: " << times_sum
958  << " #pat. hits: " << num_pattern_hits;
959  }
960  }
961  } // end loop over strips in pretrigger pattern
962  } // end loop over layers
963 
964  // save the pattern information when a trigger was formed!
965  if (layers_hit >= nplanes_hit_pattern) {
966  hits_in_patterns[key_hstrip][pid] = hits_single_pattern;
967  }
968 
969  // determine the current best pattern!
970  if (layers_hit > nhits[key_hstrip]) {
971  best_pid[key_hstrip] = pid;
972  nhits[key_hstrip] = layers_hit;
973  // Do not loop over the other (worse) patterns if max. numbers of
974  // hits is found.
975  if (nhits[key_hstrip] == CSCConstants::NUM_LAYERS)
976  break;
977  }
978  } // end loop over pid
979  } // end loop over candidate key strips
980 
981  // At this point there exists at least one halfstrip for which at least one pattern
982  // has at least 3 layers --> definition of a pre-trigger
983  return true;
984 } // patternFinding -- TMB-07 version.
985 
986 // TMB-07 version.
987 void CSCCathodeLCTProcessor::markBusyKeys(const int best_hstrip,
988  const int best_patid,
990  int nspan = min_separation;
991  int pspan = min_separation;
992 
993  for (int hstrip = best_hstrip - nspan; hstrip <= best_hstrip + pspan; hstrip++) {
994  if (hstrip >= 0 && hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER) {
995  quality[hstrip] = 0;
996  }
997  }
998 } // markBusyKeys -- TMB-07 version.
999 
1001  const unsigned halfstrip_withstagger,
1003  // Assign the CLCT properties
1004  const unsigned quality = nhits[halfstrip_withstagger];
1005  const unsigned pattern = best_pid[halfstrip_withstagger];
1006  const unsigned bend = CSCPatternBank::getPatternBend(clct_pattern_[pattern]);
1007  const unsigned keyhalfstrip = halfstrip_withstagger - stagger[CSCConstants::KEY_CLCT_LAYER - 1];
1008  const unsigned cfeb = keyhalfstrip / CSCConstants::NUM_HALF_STRIPS_PER_CFEB;
1009  const unsigned halfstrip = keyhalfstrip % CSCConstants::NUM_HALF_STRIPS_PER_CFEB;
1010 
1011  // set the Run-2 properties
1012  CSCCLCTDigi clct(1,
1013  quality,
1014  pattern,
1015  // CLCTs are always of type halfstrip (not strip or distrip)
1016  1,
1017  bend,
1018  halfstrip,
1019  cfeb,
1020  bx,
1021  0,
1022  0,
1023  -1,
1025 
1026  // set the hit collection
1027  clct.setHits(hits);
1028 
1029  // do the CCLUT procedures for Run-3
1030  if (runCCLUT_) {
1031  cclut_->run(clct, numCFEBs_);
1032  }
1033 
1034  // purge the comparator digi collection from the obsolete "65535" entries...
1036 
1037  if (infoV > 1) {
1038  LogTrace("CSCCathodeLCTProcessor") << "Produce CLCT " << clct << std::endl;
1039  }
1040 
1041  return clct;
1042 }
1043 
1045  const unsigned hstrip,
1046  const unsigned nPreTriggers) const {
1048  const int halfstrip = hstrip % CSCConstants::NUM_HALF_STRIPS_PER_CFEB;
1049  const int cfeb = hstrip / CSCConstants::NUM_HALF_STRIPS_PER_CFEB;
1050  return CSCCLCTPreTriggerDigi(1, nhits[hstrip], best_pid[hstrip], 1, bend, halfstrip, cfeb, bx_time, nPreTriggers, 0);
1051 }
1052 
1054  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
1055  ispretrig_[hstrip] = false;
1056  }
1057 }
1058 
1060  CSCCLCTDigi::ComparatorContainer newHits = clct.getHits();
1061  for (auto& p : newHits) {
1062  p.erase(
1063  std::remove_if(p.begin(), p.end(), [](unsigned i) -> bool { return i == CSCConstants::INVALID_HALF_STRIP; }),
1064  p.end());
1065  }
1066  clct.setHits(newHits);
1067 }
1068 
1069 // --------------------------------------------------------------------------
1070 // Auxiliary code.
1071 // --------------------------------------------------------------------------
1072 // Dump of configuration parameters.
1074  std::ostringstream strm;
1075  strm << "\n";
1076  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1077  strm << "+ CLCT configuration parameters: +\n";
1078  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1079  strm << " fifo_tbins [total number of time bins in DAQ readout] = " << fifo_tbins << "\n";
1080  strm << " fifo_pretrig [start time of cathode raw hits in DAQ readout] = " << fifo_pretrig << "\n";
1081  strm << " hit_persist [duration of signal pulse, in 25 ns bins] = " << hit_persist << "\n";
1082  strm << " drift_delay [time after pre-trigger before TMB latches LCTs] = " << drift_delay << "\n";
1083  strm << " nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = " << nplanes_hit_pretrig << "\n";
1084  strm << " nplanes_hit_pattern [min. number of layers hit for trigger] = " << nplanes_hit_pattern << "\n";
1085  strm << " pid_thresh_pretrig [lower threshold on pattern id] = " << pid_thresh_pretrig << "\n";
1086  strm << " min_separation [region of busy key strips] = " << min_separation << "\n";
1087  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1088  LogDebug("CSCCathodeLCTProcessor") << strm.str();
1089 }
1090 
1091 // Reasonably nice dump of digis on half-strips.
1094  LogDebug("CSCCathodeLCTProcessor") << theCSCName_ << " strip type: half-strip, numHalfStrips " << numHalfStrips_;
1095 
1096  std::ostringstream strstrm;
1097  for (int i_strip = 0; i_strip < numHalfStrips_; i_strip++) {
1098  if (i_strip % 10 == 0) {
1099  if (i_strip < 100)
1100  strstrm << i_strip / 10;
1101  else
1102  strstrm << (i_strip - 100) / 10;
1103  } else
1104  strstrm << " ";
1105  if ((i_strip + 1) % CSCConstants::NUM_HALF_STRIPS_PER_CFEB == 0)
1106  strstrm << " ";
1107  }
1108  strstrm << "\n";
1109  for (int i_strip = 0; i_strip < numHalfStrips_; i_strip++) {
1110  strstrm << i_strip % 10;
1111  if ((i_strip + 1) % CSCConstants::NUM_HALF_STRIPS_PER_CFEB == 0)
1112  strstrm << " ";
1113  }
1114  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
1115  strstrm << "\n";
1116  for (int i_strip = 0; i_strip < numHalfStrips_; i_strip++) {
1117  if (!strip[i_layer][i_strip].empty()) {
1118  std::vector<int> bx_times = strip[i_layer][i_strip];
1119  // Dump only the first in time.
1120  strstrm << std::hex << bx_times[0] << std::dec;
1121  } else {
1122  strstrm << "-";
1123  }
1124  if ((i_strip + 1) % CSCConstants::NUM_HALF_STRIPS_PER_CFEB == 0)
1125  strstrm << " ";
1126  }
1127  }
1128  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
1129 }
1130 
1131 // Returns vector of read-out CLCTs, if any. Starts with the vector
1132 // of all found CLCTs and selects the ones in the read-out time window.
1133 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::readoutCLCTs() const {
1134  // temporary container for further selection
1135  std::vector<CSCCLCTDigi> tmpV;
1136 
1137  /*
1138  CLCTs in the BX window [early_tbin,...,late_tbin] are considered good for physics
1139  The central CLCT BX is time bin 7.
1140  For tmb_l1a_window_size set to 7 (Run-1, Run-2), the window is [4, 5, 6, 7, 8, 9, 10]
1141  For tmb_l1a_window_size set to 5 (Run-3), the window is [5, 6, 7, 8, 9]
1142  For tmb_l1a_window_size set to 3 (Run-4?), the window is [6, 7, 8]
1143  */
1144  const unsigned delta_tbin = tmb_l1a_window_size / 2;
1145  int early_tbin = CSCConstants::CLCT_CENTRAL_BX - delta_tbin;
1146  int late_tbin = CSCConstants::CLCT_CENTRAL_BX + delta_tbin;
1147  /*
1148  Special case for an even-numbered time-window,
1149  For instance tmb_l1a_window_size set to 6: [4, 5, 6, 7, 8, 9]
1150  */
1151  if (tmb_l1a_window_size % 2 == 0)
1152  late_tbin = CSCConstants::CLCT_CENTRAL_BX + delta_tbin - 1;
1153  const int max_late_tbin = CSCConstants::MAX_CLCT_TBINS - 1;
1154 
1155  // debugging messages when early_tbin or late_tbin has a suspicious value
1156  if (early_tbin < 0) {
1157  edm::LogWarning("CSCCathodeLCTProcessor|SuspiciousParameters")
1158  << "Early time bin (early_tbin) smaller than minimum allowed, which is 0. set early_tbin to 0.";
1159  early_tbin = 0;
1160  }
1161  if (late_tbin > max_late_tbin) {
1162  edm::LogWarning("CSCCathodeLCTProcessor|SuspiciousParameters")
1163  << "Late time bin (late_tbin) larger than maximum allowed, which is " << max_late_tbin
1164  << ". set early_tbin to max allowed";
1165  late_tbin = CSCConstants::MAX_CLCT_TBINS - 1;
1166  }
1167 
1168  // get the valid LCTs. No BX selection is done here
1169  const auto& all_clcts = getCLCTs();
1170 
1171  // Start from the vector of all found CLCTs and select those within
1172  // the CLCT*L1A coincidence window.
1173  int bx_readout = -1;
1174  for (const auto& clct : all_clcts) {
1175  // only consider valid CLCTs
1176  if (!clct.isValid())
1177  continue;
1178 
1179  const int bx = clct.getBX();
1180  // Skip CLCTs found too early relative to L1Accept.
1181  if (bx < early_tbin) {
1182  if (infoV > 1)
1183  LogDebug("CSCCathodeLCTProcessor")
1184  << " Do not report correlated CLCT on key halfstrip " << clct.getStrip() << ": found at bx " << bx
1185  << ", whereas the earliest allowed bx is " << early_tbin;
1186  continue;
1187  }
1188 
1189  // Skip CLCTs found too late relative to L1Accept.
1190  if (bx > late_tbin) {
1191  if (infoV > 1)
1192  LogDebug("CSCCathodeLCTProcessor")
1193  << " Do not report correlated CLCT on key halfstrip " << clct.getStrip() << ": found at bx " << bx
1194  << ", whereas the latest allowed bx is " << late_tbin;
1195  continue;
1196  }
1197 
1198  // If (readout_earliest_2) take only CLCTs in the earliest bx in the read-out window:
1199  if (readout_earliest_2) {
1200  // the first CLCT passes
1201  // the second CLCT passes if the BX matches to the first
1202  if (bx_readout == -1 || bx == bx_readout) {
1203  tmpV.push_back(clct);
1204  if (bx_readout == -1)
1205  bx_readout = bx;
1206  }
1207  } else
1208  tmpV.push_back(clct);
1209  }
1210 
1211  // do a final check on the CLCTs in readout
1212  qualityControl_->checkMultiplicityBX(tmpV);
1213  for (const auto& clct : tmpV) {
1214  qualityControl_->checkValid(clct);
1215  }
1216 
1217  return tmpV;
1218 }
1219 
1220 // Returns vector of all found CLCTs, if any. Used for ALCT-CLCT matching.
1221 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::getCLCTs() const {
1222  std::vector<CSCCLCTDigi> tmpV;
1223  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
1224  if (bestCLCT[bx].isValid())
1225  tmpV.push_back(bestCLCT[bx]);
1226  if (secondCLCT[bx].isValid())
1227  tmpV.push_back(secondCLCT[bx]);
1228  }
1229  return tmpV;
1230 }
1231 
1232 // shift the BX from 7 to 8
1233 // the unpacked real data CLCTs have central BX at bin 7
1234 // however in simulation the central BX is bin 8
1235 // to make a proper comparison with ALCTs we need
1236 // CLCT and ALCT to have the central BX in the same bin
1238  if (bx >= CSCConstants::MAX_CLCT_TBINS or bx < 0)
1239  return CSCCLCTDigi();
1240  CSCCLCTDigi lct = bestCLCT[bx];
1242  return lct;
1243 }
1244 
1246  if (bx >= CSCConstants::MAX_CLCT_TBINS or bx < 0)
1247  return CSCCLCTDigi();
1248  CSCCLCTDigi lct = secondCLCT[bx];
1250  return lct;
1251 }
1252 
1254  if (bx >= CSCConstants::MAX_CLCT_TBINS or bx < 0)
1255  return false;
1256  return localShowerFlag[bx];
1257 }
1258 
1260 std::vector<CSCShowerDigi> CSCCathodeLCTProcessor::getAllShower() const {
1261  std::vector<CSCShowerDigi> vshowers(cathode_showers_, cathode_showers_ + CSCConstants::MAX_CLCT_TBINS);
1262  return vshowers;
1263 };
1264 
1266 std::vector<CSCShowerDigi> CSCCathodeLCTProcessor::readoutShower() const {
1267  std::vector<CSCShowerDigi> showerOut;
1268  for (unsigned bx = minbx_readout_; bx < maxbx_readout_; bx++)
1269  if (cathode_showers_[bx].isValid())
1270  showerOut.push_back(cathode_showers_[bx]);
1271  return showerOut;
1272 }
1273 
1275  //inTimeHMT_ = 0;
1276 
1277  //numer of layer with hits and number of hits for 0-15 BXs
1278  std::set<unsigned> layersWithHits[CSCConstants::MAX_CLCT_TBINS];
1279  unsigned hitsInTime[CSCConstants::MAX_CLCT_TBINS];
1280  // Calculate layers with hits
1281  for (unsigned bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
1282  hitsInTime[bx] = 0;
1283  for (unsigned i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
1284  bool atLeastOneCompHit = false;
1285  for (const auto& compdigi : digiV[i_layer]) {
1286  std::vector<int> bx_times = compdigi.getTimeBinsOn();
1287  // there is at least one comparator digi in this bx
1288  if (std::find(bx_times.begin(), bx_times.end(), bx) != bx_times.end()) {
1289  hitsInTime[bx] += 1;
1290  atLeastOneCompHit = true;
1291  }
1292  }
1293  // add this layer to the number of layers hit
1294  if (atLeastOneCompHit) {
1295  layersWithHits[bx].insert(i_layer);
1296  }
1297  }
1298  } //end of full bx loop
1299 
1300  // convert station and ring number to index
1301  // index runs from 2 to 10, subtract 2
1302  unsigned csc_idx = CSCDetId::iChamberType(theStation, theRing) - 2;
1303 
1304  // loose, nominal and tight
1305  std::vector<unsigned> station_thresholds = {
1306  thresholds_[csc_idx * 3], thresholds_[csc_idx * 3 + 1], thresholds_[csc_idx * 3 + 2]};
1307 
1308  //hard coded dead time as 2Bx, since showerNumTBins = 3, like firmware
1309  // for example, nhits = 0 at bx7; = 100 at bx8; = 0 at bx9
1310  //cathode HMT must be triggered at bx8, not bx7 and bx9
1311  //meanwhile we forced 2BX dead time after active shower trigger
1312  unsigned int deadtime =
1313  showerNumTBins_ - 1; // firmware hard coded dead time as 2Bx, since showerNumTBins = 3 in firmware
1314  unsigned int dead_count = 0;
1315 
1316  for (unsigned bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
1317  unsigned minbx = bx >= showerNumTBins_ / 2 ? bx - showerNumTBins_ / 2 : bx;
1318  unsigned maxbx = bx < CSCConstants::MAX_CLCT_TBINS - showerNumTBins_ / 2 ? bx + showerNumTBins_ / 2
1320  unsigned this_hitsInTime = 0;
1321  bool isPeak = true; //check whether total hits in bx is peak of nhits over time bins
1322  /*following is to count number of hits over [minbx, maxbx], showerNumTBins=3 =>[n-1, n+1]*/
1323  for (unsigned mbx = minbx; mbx <= maxbx; mbx++) {
1324  this_hitsInTime += hitsInTime[mbx];
1325  }
1326 
1328  if (hitsInTime[minbx] < hitsInTime[maxbx + 1] or
1329  (hitsInTime[minbx] == hitsInTime[maxbx + 1] and hitsInTime[bx] < hitsInTime[bx + 1]))
1330  isPeak = false; //next bx would have more hits or in the center
1331  }
1332  bool dead_status = dead_count > 0;
1333  if (dead_status)
1334  dead_count--;
1335 
1336  unsigned this_inTimeHMT = 0;
1337  // require at least nLayersWithHits for the central time bin
1338  // do nothing if there are not enough layers with hits
1339  if (layersWithHits[bx].size() >= minLayersCentralTBin_ and !dead_status and isPeak) {
1340  // assign the bits
1341  if (!station_thresholds.empty()) {
1342  for (int i = station_thresholds.size() - 1; i >= 0; i--) {
1343  if (this_hitsInTime >= station_thresholds[i]) {
1344  this_inTimeHMT = i + 1;
1345  dead_count = deadtime;
1346  break;
1347  }
1348  }
1349  }
1350  }
1351  //CLCTshower constructor with showerType_ = 2, wirehits = 0;
1353  this_inTimeHMT, false, theTrigChamber, bx, CSCShowerDigi::ShowerType::kCLCTShower, 0, this_hitsInTime);
1354  }
1355 }
std::unique_ptr< ComparatorCodeLUT > cclut_
void setESLookupTables(const CSCL1TPLookupTableCCLUT *conf)
size
Write out results.
unsigned int clctNplanesHitPattern() const
static const unsigned int def_drift_delay
std::vector< CSCCLCTDigi > readoutCLCTs() const
CSCCLCTDigi bestCLCT[CSCConstants::MAX_CLCT_TBINS]
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void clear()
Definition: PulseArray.cc:14
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:30
static const unsigned int def_fifo_tbins
CSCCathodeLCTProcessor(unsigned endcap, unsigned station, unsigned sector, unsigned subsector, unsigned chamber, const edm::ParameterSet &conf)
bool isOneShotHighAtBX(const unsigned layer, const unsigned channel, const unsigned bx) const
Definition: PulseArray.cc:37
unsigned int clctMinSeparation() const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
const unsigned theEndcap
Definition: CSCBaseboard.h:42
static std::string chamberName(int endcap, int station, int ring, int chamber)
Definition: CSCDetId.cc:74
const CSCChamber * cscChamber_
Definition: CSCBaseboard.h:72
void checkConfigParameters(unsigned int &var, const unsigned int var_max, const unsigned int var_def, const std::string &var_str)
unsigned int clctFifoTbins() const
uint16_t getQuality() const
return quality of a pattern (number of layers hit!)
Definition: CSCCLCTDigi.h:56
ParameterSet const & getParameterSet(std::string const &) const
void pulseExtension(const std::vector< int > time[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
uint16_t getKeyStrip(const uint16_t n=2) const
Definition: CSCCLCTDigi.cc:107
unsigned int clctNplanesHitPretrig() const
const unsigned theSector
Definition: CSCBaseboard.h:44
static const unsigned int def_min_separation
CSCPatternBank::LCTPatterns clct_pattern_
bool patternFinding(const unsigned int bx_time, std::map< int, std::map< int, CSCCLCTDigi::ComparatorContainer > > &hits_in_patterns)
bool disableME1a_
Definition: CSCBaseboard.h:97
bool getLocalShowerFlag(int bx) const
Log< level::Error, false > LogError
std::unique_ptr< LCTQualityControl > qualityControl_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
unsigned short iChamberType() const
Definition: CSCDetId.h:96
assert(be >=bs)
std::string theCSCName_
Definition: CSCBaseboard.h:90
static const unsigned int def_nplanes_hit_pretrig
CSCShowerDigi cathode_showers_[CSCConstants::MAX_CLCT_TBINS]
std::vector< CSCShowerDigi > readoutShower() const
void cleanComparatorContainer(CSCCLCTDigi &lct) const
#define LogTrace(id)
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:44
bool gangedME1a_
Definition: CSCBaseboard.h:97
static const unsigned int def_pid_thresh_pretrig
string quality
std::vector< std::vector< uint16_t > > ComparatorContainer
Definition: CSCCLCTDigi.h:19
unsigned int nhits[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
const unsigned theTrigChamber
Definition: CSCBaseboard.h:46
CSCCLCTPreTriggerDigi constructPreCLCT(const int bx, const unsigned halfstrip, const unsigned index) const
static const LCTPatterns clct_pattern_run3_
CSCCLCTDigi getSecondCLCT(int bx) const
std::string chamberName() const
Definition: CSCDetId.cc:92
std::vector< CSCCLCTDigi > getCLCTs() const
int numberOfStrips() const
static const unsigned int def_tmb_l1a_window_size
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
unsigned int clctFifoPretrig() const
bool getDigis(const CSCComparatorDigiCollection *compdc)
static const unsigned int def_nplanes_hit_pattern
void setHits(const ComparatorContainer &hits)
Definition: CSCCLCTDigi.h:178
unsigned int clctPidThreshPretrig() const
static const int clct_pattern_offset_[CSCConstants::CLCT_PATTERN_WIDTH]
unsigned theChamber
Definition: CSCBaseboard.h:49
bool isValid() const
check CLCT validity (1 - valid CLCT)
Definition: CSCCLCTDigi.h:50
static int getPatternBend(const LCTPattern &pattern)
edm::ParameterSet clctParams_
Definition: CSCBaseboard.h:84
unsigned int clctHitPersist() const
std::vector< CSCCLCTPreTriggerDigi > thePreTriggerDigis
unsigned numberOfLayersAtBX(const unsigned bx) const
Definition: PulseArray.cc:41
static const LCTPatterns clct_pattern_legacy_
edm::ParameterSet tmbParams_
Definition: CSCBaseboard.h:78
virtual std::vector< CSCCLCTDigi > findLCTs(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
void markBusyKeys(const int best_hstrip, const int best_patid, int quality[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
static const unsigned int def_fifo_pretrig
bool localShowerFlag[CSCConstants::MAX_CLCT_TBINS]
std::vector< int > thePreTriggerBXs
std::pair< const_iterator, const_iterator > Range
static const unsigned int def_hit_persist
void dumpDigis(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const
const unsigned theStation
Definition: CSCBaseboard.h:43
CSCCLCTDigi getBestCLCT(int bx) const
int stagger[CSCConstants::NUM_LAYERS]
std::vector< DigiType >::const_iterator const_iterator
uint16_t getBX() const
return BX
Definition: CSCCLCTDigi.h:123
uint16_t getPattern() const
return pattern
Definition: CSCCLCTDigi.h:62
std::vector< CSCCLCTDigi > run(const CSCComparatorDigiCollection *compdc)
void initialize(unsigned numberOfChannels)
Definition: PulseArray.cc:5
void setBX(const uint16_t bx)
set bx
Definition: CSCCLCTDigi.h:129
const ComparatorContainer & getHits() const
Definition: CSCCLCTDigi.h:176
virtual bool preTrigger(const int start_bx, int &first_bx)
uint16_t getRun3Pattern() const
return pattern
Definition: CSCCLCTDigi.h:68
CSCCLCTDigi secondCLCT[CSCConstants::MAX_CLCT_TBINS]
void clear()
clear this CLCT
Definition: CSCCLCTDigi.cc:73
std::vector< CSCComparatorDigi > digiV[CSCConstants::NUM_LAYERS]
unsigned bitsInPulse() const
Definition: PulseArray.cc:25
void clear()
clear this Shower
unsigned theRing
Definition: CSCBaseboard.h:48
Log< level::Warning, false > LogWarning
edm::ParameterSet showerParams_
Definition: CSCBaseboard.h:87
void readComparatorDigis(std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
CSCCLCTDigi constructCLCT(const int bx, const unsigned halfstrip_withstagger, const CSCCLCTDigi::ComparatorContainer &hits)
std::vector< CSCShowerDigi > getAllShower() const
void extend(const unsigned layer, const unsigned channel, const unsigned bx, const unsigned hit_persist)
Definition: PulseArray.cc:27
bool ispretrig_[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
void setConfigParameters(const CSCDBL1TPParameters *conf)
const unsigned theSubsector
Definition: CSCBaseboard.h:45
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting CLCTs.
Definition: CSCCLCTDigi.h:162
void checkLocalShower(int zone, const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
unsigned int clctDriftDelay() const
#define LogDebug(id)
unsigned int best_pid[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
std::vector< unsigned > thresholds_