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