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