CMS 3D CMS Logo

CSCCathodeLCTProcessor.cc
Go to the documentation of this file.
2 
3 #include <iomanip>
4 #include <iostream>
5 
6 //-----------------
7 // Static variables
8 //-----------------
9 
11  { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,
12  -2, -1, 0, 1, 2,
13  0,
14  -2, -1, 0, 1, 2,
15  -4, -3, -2, -1, 0, 1, 2, 3, 4,
16  -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 };
17 
19  { 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
20  999, 999, 999, 999, 999,
21  999, // pid=0: no pattern found
22  999, 999, 999, 999, 999,
23  999, 999, 999, 999, 999, 999, 999, 999, 999,
24  999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, -1, 0},
25  //-------------------------------------------------------------
26  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27  1, 1, 1, 1, 1,
28  2, // pid=1: layer-OR trigger
29  3, 3, 3, 3, 3,
30  4, 4, 4, 4, 4, 4, 4, 4, 4,
31  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, -1, 11},
32  //-------------------------------------------------------------
33  { 999, 999, 999, 999, 999, 999, 999, 999, 0, 0, 0,
34  999, 999, 999, 1, 1,
35  2, // pid=2: right-bending (large)
36  3, 3, 3, 999, 999,
37  4, 4, 4, 999, 999, 999, 999, 999, 999,
38  5, 5, 5, 999, 999, 999, 999, 999, 999, 999, 999, 0, 11},
39  //-------------------------------------------------------------
40  { 0, 0, 0, 999, 999, 999, 999, 999, 999, 999, 999,
41  1, 1, 999, 999, 999,
42  2, // pid=3: left-bending (large)
43  999, 999, 3, 3, 3,
44  999, 999, 999, 999, 999, 999, 4, 4, 4,
45  999, 999, 999, 999, 999, 999, 999, 999, 5, 5, 5, 1, 11},
46  //-------------------------------------------------------------
47  { 999, 999, 999, 999, 999, 999, 999, 0, 0, 0, 999,
48  999, 999, 999, 1, 1,
49  2, // pid=4: right-bending (medium)
50  3, 3, 999, 999, 999,
51  4, 4, 4, 999, 999, 999, 999, 999, 999,
52  999, 5, 5, 5, 999, 999, 999, 999, 999, 999, 999, 0, 9},
53  //-------------------------------------------------------------
54  { 999, 0, 0, 0, 999, 999, 999, 999, 999, 999, 999,
55  1, 1, 999, 999, 999,
56  2, // pid=5: left-bending (medium)
57  999, 999, 999, 3, 3,
58  999, 999, 999, 999, 999, 999, 4, 4, 4,
59  999, 999, 999, 999, 999, 999, 999, 5, 5, 5, 999, 1, 9},
60  //-------------------------------------------------------------
61  { 999, 999, 999, 999, 999, 999, 0, 0, 0, 999, 999,
62  999, 999, 1, 1, 999,
63  2, // pid=6: right-bending (medium)
64  999, 3, 3, 999, 999,
65  999, 999, 4, 4, 999, 999, 999, 999, 999,
66  999, 999, 5, 5, 5, 999, 999, 999, 999, 999, 999, 0, 7},
67  //-------------------------------------------------------------
68  { 999, 999, 0, 0, 0, 999, 999, 999, 999, 999, 999,
69  999, 1, 1, 999, 999,
70  2, // pid=7: left-bending (medium)
71  999, 999, 3, 3, 999,
72  999, 999, 999, 999, 999, 4, 4, 999, 999,
73  999, 999, 999, 999, 999, 999, 5, 5, 5, 999, 999, 1, 7},
74  //-------------------------------------------------------------
75  { 999, 999, 999, 999, 999, 0, 0, 0, 999, 999, 999,
76  999, 999, 1, 1, 999,
77  2, // pid=8: right-bending (small)
78  999, 3, 3, 999, 999,
79  999, 999, 4, 4, 4, 999, 999, 999, 999,
80  999, 999, 999, 5, 5, 5, 999, 999, 999, 999, 999, 0, 5},
81  //-------------------------------------------------------------
82  { 999, 999, 999, 0, 0, 0, 999, 999, 999, 999, 999,
83  999, 1, 1, 999, 999,
84  2, // pid=9: left-bending (small)
85  999, 999, 3, 3, 999,
86  999, 999, 999, 999, 4, 4, 4, 999, 999,
87  999, 999, 999, 999, 999, 5, 5, 5, 999, 999, 999, 1, 5},
88  //-------------------------------------------------------------
89  { 999, 999, 999, 999, 0, 0, 0, 999, 999, 999, 999,
90  999, 999, 1, 999, 999,
91  2, // pid=A: straight-through
92  999, 999, 3, 999, 999,
93  999, 999, 999, 4, 4, 4, 999, 999, 999,
94  999, 999, 999, 999, 5, 5, 5, 999, 999, 999, 999, 0, 3}
95  // pid's=B-F are not yet defined
96 };
97 
98 // Default values of configuration parameters.
99 const unsigned int CSCCathodeLCTProcessor::def_fifo_tbins = 12;
100 const unsigned int CSCCathodeLCTProcessor::def_fifo_pretrig = 7;
101 const unsigned int CSCCathodeLCTProcessor::def_hit_persist = 6;
102 const unsigned int CSCCathodeLCTProcessor::def_drift_delay = 2;
106 const unsigned int CSCCathodeLCTProcessor::def_min_separation = 10;
108 
109 //----------------
110 // Constructors --
111 //----------------
112 
114  unsigned station,
115  unsigned sector,
116  unsigned subsector,
117  unsigned chamber,
118  const edm::ParameterSet& conf) :
119  CSCBaseboard(endcap, station, sector, subsector, chamber, conf)
120 {
121  static std::atomic<bool> config_dumped{false};
122 
123  // CLCT configuration parameters.
124  fifo_tbins = clctParams_.getParameter<unsigned int>("clctFifoTbins");
125  hit_persist = clctParams_.getParameter<unsigned int>("clctHitPersist");
126  drift_delay = clctParams_.getParameter<unsigned int>("clctDriftDelay");
128  clctParams_.getParameter<unsigned int>("clctNplanesHitPretrig");
130  clctParams_.getParameter<unsigned int>("clctNplanesHitPattern");
131 
132  // Not used yet.
133  fifo_pretrig = clctParams_.getParameter<unsigned int>("clctFifoPretrig");
134 
136  clctParams_.getParameter<unsigned int>("clctPidThreshPretrig");
138  clctParams_.getParameter<unsigned int>("clctMinSeparation");
139 
140  start_bx_shift = clctParams_.getParameter<int>("clctStartBxShift");
141 
142  // Motherboard parameters: common for all configurations.
143  tmb_l1a_window_size = // Common to CLCT and TMB
144  tmbParams_.getParameter<unsigned int>("tmbL1aWindowSize");
145 
146  // separate handle for early time bins
147  early_tbins = tmbParams_.getParameter<int>("tmbEarlyTbins");
148  if (early_tbins<0) early_tbins = fifo_pretrig - CSCConstants::CLCT_EMUL_TIME_OFFSET;
149 
150  // wether to readout only the earliest two LCTs in readout window
151  readout_earliest_2 = tmbParams_.getParameter<bool>("tmbReadoutEarliest2");
152 
153  // Verbosity level, set to 0 (no print) by default.
154  infoV = clctParams_.getParameter<int>("verbosity");
155 
156  // Check and print configuration parameters.
158  if ((infoV > 0) && !config_dumped) {
160  config_dumped = true;
161  }
162 
163  numStrips = 0; // Will be set later.
164  // Provisional, but should be OK for all stations except ME1.
165  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
166  if ((i_layer+1)%2 == 0) stagger[i_layer] = 0;
167  else stagger[i_layer] = 1;
168  }
169 
170 
171  thePreTriggerDigis.clear();
172 }
173 
175  CSCBaseboard()
176 {
177  // constructor for debugging.
178  static std::atomic<bool> config_dumped{false};
179 
180  // CLCT configuration parameters.
182  infoV = 2;
183 
184  early_tbins = 4;
185 
186  start_bx_shift = 0;
187 
188  // Check and print configuration parameters.
190  if (!config_dumped) {
192  config_dumped = true;
193  }
194 
196  // Should be OK for all stations except ME1.
197  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
198  if ((i_layer+1)%2 == 0) stagger[i_layer] = 0;
199  else stagger[i_layer] = 1;
200  }
201 
202  thePreTriggerDigis.clear();
203 }
204 
206 {
207  // Set default values for configuration parameters.
217 }
218 
219 // Set configuration parameters obtained via EventSetup mechanism.
221 {
222  static std::atomic<bool> config_dumped{false};
223 
224  fifo_tbins = conf->clctFifoTbins();
225  fifo_pretrig = conf->clctFifoPretrig();
226  hit_persist = conf->clctHitPersist();
227  drift_delay = conf->clctDriftDelay();
232 
233  // Check and print configuration parameters.
235  if (!config_dumped) {
237  config_dumped = true;
238  }
239 }
240 
242  // Make sure that the parameter values are within the allowed range.
243 
244  // Max expected values.
245  static const unsigned int max_fifo_tbins = 1 << 5;
246  static const unsigned int max_fifo_pretrig = 1 << 5;
247  static const unsigned int max_hit_persist = 1 << 4;
248  static const unsigned int max_drift_delay = 1 << 2;
249  static const unsigned int max_nplanes_hit_pretrig = 1 << 3;
250  static const unsigned int max_nplanes_hit_pattern = 1 << 3;
251  static const unsigned int max_pid_thresh_pretrig = 1 << 4;
252  static const unsigned int max_min_separation = CSCConstants::NUM_HALF_STRIPS_7CFEBS;
253  static const unsigned int max_tmb_l1a_window_size = 1 << 4;
254 
255  // Checks.
256  if (fifo_tbins >= max_fifo_tbins) {
257  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
258  << "+++ Value of fifo_tbins, " << fifo_tbins
259  << ", exceeds max allowed, " << max_fifo_tbins-1 << " +++\n"
260  << "+++ Try to proceed with the default value, fifo_tbins="
261  << def_fifo_tbins << " +++\n";
263  }
264  if (fifo_pretrig >= max_fifo_pretrig) {
265  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
266  << "+++ Value of fifo_pretrig, " << fifo_pretrig
267  << ", exceeds max allowed, " << max_fifo_pretrig-1 << " +++\n"
268  << "+++ Try to proceed with the default value, fifo_pretrig="
269  << def_fifo_pretrig << " +++\n";
271  }
272  if (hit_persist >= max_hit_persist) {
273  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
274  << "+++ Value of hit_persist, " << hit_persist
275  << ", exceeds max allowed, " << max_hit_persist-1 << " +++\n"
276  << "+++ Try to proceed with the default value, hit_persist="
277  << def_hit_persist << " +++\n";
279  }
280  if (drift_delay >= max_drift_delay) {
281  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
282  << "+++ Value of drift_delay, " << drift_delay
283  << ", exceeds max allowed, " << max_drift_delay-1 << " +++\n"
284  << "+++ Try to proceed with the default value, drift_delay="
285  << def_drift_delay << " +++\n";
287  }
288  if (nplanes_hit_pretrig >= max_nplanes_hit_pretrig) {
289  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
290  << "+++ Value of nplanes_hit_pretrig, " << nplanes_hit_pretrig
291  << ", exceeds max allowed, " << max_nplanes_hit_pretrig-1 << " +++\n"
292  << "+++ Try to proceed with the default value, nplanes_hit_pretrig="
293  << def_nplanes_hit_pretrig << " +++\n";
295  }
296  if (nplanes_hit_pattern >= max_nplanes_hit_pattern) {
297  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
298  << "+++ Value of nplanes_hit_pattern, " << nplanes_hit_pattern
299  << ", exceeds max allowed, " << max_nplanes_hit_pattern-1 << " +++\n"
300  << "+++ Try to proceed with the default value, nplanes_hit_pattern="
301  << def_nplanes_hit_pattern << " +++\n";
303  }
304 
305  if (pid_thresh_pretrig >= max_pid_thresh_pretrig) {
306  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
307  << "+++ Value of pid_thresh_pretrig, " << pid_thresh_pretrig
308  << ", exceeds max allowed, " << max_pid_thresh_pretrig-1 << " +++\n"
309  << "+++ Try to proceed with the default value, pid_thresh_pretrig="
310  << def_pid_thresh_pretrig << " +++\n";
312  }
313  if (min_separation >= max_min_separation) {
314  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
315  << "+++ Value of min_separation, " << min_separation
316  << ", exceeds max allowed, " << max_min_separation-1 << " +++\n"
317  << "+++ Try to proceed with the default value, min_separation="
318  << def_min_separation << " +++\n";
320  }
321 
322  if (tmb_l1a_window_size >= max_tmb_l1a_window_size) {
323  if (infoV > 0) edm::LogError("L1CSCTPEmulatorConfigError")
324  << "+++ Value of tmb_l1a_window_size, " << tmb_l1a_window_size
325  << ", exceeds max allowed, " << max_tmb_l1a_window_size-1 << " +++\n"
326  << "+++ Try to proceed with the default value, tmb_l1a_window_size="
327  << def_tmb_l1a_window_size << " +++\n";
329  }
330 }
331 
333  thePreTriggerDigis.clear();
334  thePreTriggerBXs.clear();
335  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
336  bestCLCT[bx].clear();
337  secondCLCT[bx].clear();
338  }
339 }
340 
341 std::vector<CSCCLCTDigi>
343 {
344  // This is the version of the run() function that is called when running
345  // over the entire detector. It gets the comparator & timing info from the
346  // comparator digis and then passes them on to another run() function.
347 
348  // clear(); // redundant; called by L1MuCSCMotherboard.
349 
350  static std::atomic<bool> config_dumped{false};
351  if ((infoV > 0) && !config_dumped) {
353  config_dumped = true;
354  }
355 
356  // Get the number of strips and stagger of layers for the given chamber.
357  // Do it only once per chamber.
358  if (numStrips == 0) {
359  if (cscChamber_) {
361  // ME1/a is known to the readout hardware as strips 65-80 of ME1/1.
362  // Still need to decide whether we do any special adjustments to
363  // reconstruct LCTs in this region (3:1 ganged strips); for now, we
364  // simply allow for hits in ME1/a and apply standard reconstruction
365  // to them.
366  // For SLHC ME1/1 is set to have 4 CFEBs in ME1/b and 3 CFEBs in ME1/a
367  if (isME11_) {
368  if (theRing == 4) {
369  if (infoV >= 0) {
370  edm::LogError("L1CSCTPEmulatorSetupError")
371  << "+++ Invalid ring number for this processor " << theRing
372  << " was set in the config."
373  << " +++\n"
374  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
375  }
376  }
380  }
381 
383  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorSetupError")
384  << "+++ Number of strips, " << numStrips
386  << " (sector " << theSector << " subsector " << theSubsector
387  << " trig id. " << theTrigChamber << ")"
388  << " exceeds max expected, " << CSCConstants::MAX_NUM_STRIPS_7CFEBS
389  << " +++\n"
390  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
391  numStrips = -1;
392  }
393  // The strips for a given layer may be offset from the adjacent layers.
394  // This was done in order to improve resolution. We need to find the
395  // 'staggering' for each layer and make necessary conversions in our
396  // arrays. -JM
397  // In the TMB-07 firmware, half-strips in odd layers (layers are
398  // counted as ly0-ly5) are shifted by -1 half-strip, whereas in
399  // the previous firmware versions half-strips in even layers
400  // were shifted by +1 half-strip. This difference is due to a
401  // change from ly3 to ly2 in the choice of the key layer, and
402  // the intention to keep half-strips in the key layer unchanged.
403  // In the emulator, we use the old way for both cases, to avoid
404  // negative half-strip numbers. This will necessitate a
405  // subtraction of 1 half-strip for TMB-07 later on. -SV.
406  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
407  stagger[i_layer] =
408  (cscChamber_->layer(i_layer+1)->geometry()->stagger() + 1) / 2;
409  }
410  }
411  else {
412  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
414  << " (sector " << theSector << " subsector " << theSubsector
415  << " trig id. " << theTrigChamber << ")"
416  << " is not defined in current geometry! +++\n"
417  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
418  numStrips = -1;
419  }
420  }
421 
422  if (numStrips < 0) {
423  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
425  << " (sector " << theSector << " subsector " << theSubsector
426  << " trig id. " << theTrigChamber << "):"
427  << " numStrips = " << numStrips << "; CLCT emulation skipped! +++";
428  std::vector<CSCCLCTDigi> emptyV;
429  return emptyV;
430  }
431 
432  // Get comparator digis in this chamber.
433  bool noDigis = getDigis(compdc);
434 
435  if (!noDigis) {
436  // Get halfstrip times from comparator digis.
437  std::vector<int>
439  readComparatorDigis(halfstrip);
440 
441  // Pass arrays of halfstrips on to another run() doing the
442  // LCT search.
443  // If the number of layers containing digis is smaller than that
444  // required to trigger, quit right away. (If LCT-based digi suppression
445  // is implemented one day, this condition will have to be changed
446  // to the number of planes required to pre-trigger.)
447  unsigned int layersHit = 0;
448  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
449  for (int i_hstrip = 0; i_hstrip < CSCConstants::NUM_HALF_STRIPS_7CFEBS;
450  i_hstrip++) {
451  if (!halfstrip[i_layer][i_hstrip].empty()) {layersHit++; break;}
452  }
453  }
454  // Run the algorithm only if the probability for the pre-trigger
455  // to fire is not null. (Pre-trigger decisions are used for the
456  // strip read-out conditions in DigiToRaw.)
457  if (layersHit >= nplanes_hit_pretrig) run(halfstrip);
458  }
459 
460  // Return vector of CLCTs.
461  std::vector<CSCCLCTDigi> tmpV = getCLCTs();
462 
463  // shift the BX from 7 to 8
464  // the unpacked real data CLCTs have central BX at bin 7
465  // however in simulation the central BX is bin 8
466  // to make a proper comparison with ALCTs we need
467  // CLCT and ALCT to have the central BX in the same bin
468  // this shift does not affect the readout of the CLCTs
469  // emulated CLCTs put in the event should be centered at bin 7 (as in data)
470  for (auto& p : tmpV){
471  p.setBX(p.getBX() + alctClctOffset_);
472  }
473 
474  return tmpV;
475 }
476 
478 {
479  // This version of the run() function can either be called in a standalone
480  // test, being passed the halfstrip times, or called by the
481  // run() function above. It uses the findLCTs() method to find vectors
482  // of LCT candidates. These candidates are sorted and the best two per bx
483  // are returned.
484  std::vector<CSCCLCTDigi> CLCTlist = findLCTs(halfstrip);
485 
486  // LCT sorting.
487  if (CLCTlist.size() > 1)
488  sort(CLCTlist.begin(), CLCTlist.end(), std::greater<CSCCLCTDigi>());
489 
490  // Take the best two candidates per bx.
491  for (const auto& p : CLCTlist) {
492  const int bx = p.getBX();
493  if (bx >= CSCConstants::MAX_CLCT_TBINS) {
494  if (infoV > 0) edm::LogWarning("L1CSCTPEmulatorOutOfTimeCLCT")
495  << "+++ Bx of CLCT candidate, " << bx << ", exceeds max allowed, "
496  << CSCConstants::MAX_CLCT_TBINS-1 << "; skipping it... +++\n";
497  continue;
498  }
499 
500  if (!bestCLCT[bx].isValid()) {
501  bestCLCT[bx] = p;
502  }
503  else if (!secondCLCT[bx].isValid()) {
504  secondCLCT[bx] = p;
505  }
506  }
507 
508  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
509  if (bestCLCT[bx].isValid()) {
510  bestCLCT[bx].setTrknmb(1);
511  if (infoV > 0) LogDebug("CSCCathodeLCTProcessor")
512  << bestCLCT[bx] << " found in " <<
514  << " (sector " << theSector << " subsector " << theSubsector
515  << " trig id. " << theTrigChamber << ")" << "\n";
516  }
517  if (secondCLCT[bx].isValid()) {
518  secondCLCT[bx].setTrknmb(2);
519  if (infoV > 0) LogDebug("CSCCathodeLCTProcessor")
520  << secondCLCT[bx] << " found in " <<
522  << " (sector " << theSector << " subsector " << theSubsector
523  << " trig id. " << theTrigChamber << ")" << "\n";
524  }
525  }
526  // Now that we have our best CLCTs, they get correlated with the best
527  // ALCTs and then get sent to the MotherBoard. -JM
528 }
529 
531 {
532  bool noDigis = true;
533 
534  // Loop over layers and save comparator digis on each one into digiV[layer].
535  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
536  digiV[i_layer].clear();
537 
538  CSCDetId detid(theEndcap, theStation, theRing, theChamber, i_layer+1);
539  getDigis(compdc, detid);
540 
541  if (isME11_ && !disableME1a_) {
542  CSCDetId detid_me1a(theEndcap, theStation, 4, theChamber, i_layer+1);
543  getDigis(compdc, detid_me1a);
544  }
545 
546  if (!digiV[i_layer].empty()) {
547  noDigis = false;
548  if (infoV > 1) {
549  LogTrace("CSCCathodeLCTProcessor")
550  << "found " << digiV[i_layer].size()
551  << " comparator digi(s) in layer " << i_layer << " of " <<
552  detid.chamberName() << " (trig. sector " << theSector
553  << " subsector " << theSubsector << " id " << theTrigChamber << ")";
554  }
555  }
556  }
557 
558  return noDigis;
559 }
560 
562  const CSCDetId& id)
563 {
564  const bool me1a = (id.station() == 1) && (id.ring() == 4);
565  const CSCComparatorDigiCollection::Range rcompd = compdc->get(id);
566  for (CSCComparatorDigiCollection::const_iterator digiIt = rcompd.first;
567  digiIt != rcompd.second; ++digiIt) {
568  const unsigned int origStrip = digiIt->getStrip();
569  const unsigned int maxStripsME1a = gangedME1a_ ?
571  // this special case can only be reached in MC
572  // in real data, the comparator digis have always ring==1
573  if (me1a && origStrip <= maxStripsME1a && !disableME1a_) {
574  // Move ME1/A comparators from CFEB=0 to CFEB=4 if this has not
575  // been done already.
577  digiIt->getComparator(),
578  digiIt->getTimeBinWord());
579  digiV[id.layer()-1].push_back(digi_corr);
580  }
581  else {
582  digiV[id.layer()-1].push_back(*digiIt);
583  }
584  }
585 }
586 
589 {
590  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
591  int i_digi = 0; // digi counter, for dumps.
592  for (std::vector<CSCComparatorDigi>::iterator pld = digiV[i_layer].begin();
593  pld != digiV[i_layer].end(); pld++, i_digi++) {
594  // Dump raw digi info.
595  if (infoV > 1) {
596  std::ostringstream strstrm;
597  strstrm << "Comparator digi: comparator = " << pld->getComparator()
598  << " strip #" << pld->getStrip()
599  << " time bins on:";
600  std::vector<int> bx_times = pld->getTimeBinsOn();
601  for (unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
602  strstrm << " " << bx_times[tbin];
603  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
604  }
605 
606  // Get comparator: 0/1 for left/right halfstrip for each comparator
607  // that fired.
608  int thisComparator = pld->getComparator();
609  if (thisComparator != 0 && thisComparator != 1) {
610  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
611  << "+++ station "<< theStation<<" ring "<< theRing<<" chamber "<< theChamber
612  << " Found comparator digi with wrong comparator value = "
613  << thisComparator << "; skipping it... +++\n";
614  continue;
615  }
616 
617  // Get strip number.
618  int thisStrip = pld->getStrip() - 1; // count from 0
619  if (thisStrip < 0 || thisStrip >= numStrips) {
620  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
621  << "+++ station "<< theStation<<" ring "<< theRing<<" chamber "<< theChamber
622  <<" Found comparator digi with wrong strip number = "
623  << thisStrip
624  << " (max strips = " << numStrips << "); skipping it... +++\n";
625  continue;
626  }
627  // 2*strip: convert strip to 1/2 strip
628  // comp : comparator output
629  // stagger: stagger for this layer
630  int thisHalfstrip = 2*thisStrip + thisComparator + stagger[i_layer];
631  if (thisHalfstrip >= 2*numStrips + 1) {
632  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
633  << "+++ station "<< theStation<<" ring "<< theRing<<" chamber "<< theChamber
634  << " Found wrong halfstrip number = " << thisHalfstrip
635  << "; skipping this digi... +++\n";
636  continue;
637  }
638 
639  // Get bx times on this digi and check that they are within the bounds.
640  std::vector<int> bx_times = pld->getTimeBinsOn();
641  for (unsigned int i = 0; i < bx_times.size(); i++) {
642  // Total number of time bins in DAQ readout is given by fifo_tbins,
643  // which thus determines the maximum length of time interval.
644  //
645  // In data, only the CLCT in the time bin that was matched with L1A are read out
646  // while comparator digi is read out by 12 time bin, which includes 12 time bin info
647  // in other word, CLCTs emulated from comparator digis usually showed the OTMB behavior in 12 time bin
648  // while CLCT from data only showed 1 time bin OTMB behavior
649  // the CLCT emulated from comparator digis usually is centering at time bin 7 (BX7) and
650  // it is definitly safe to ignore any CLCTs in bx 0 or 1 and those CLCTs will never impacts on any triggers
651  if (bx_times[i] > 1 && bx_times[i] < static_cast<int>(fifo_tbins)) {
652 
653  if (i == 0 || (i > 0 && bx_times[i]-bx_times[i-1] >=
654  static_cast<int>(hit_persist))) {
655  // A later hit on the same strip is ignored during the
656  // number of clocks defined by the "hit_persist" parameter
657  // (i.e., 6 bx's by default).
658  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
659  << "Comp digi: layer " << i_layer+1
660  << " digi #" << i_digi+1
661  << " strip " << thisStrip
662  << " halfstrip " << thisHalfstrip
663  << " time " << bx_times[i]
664  << " comparator " << thisComparator
665  << " stagger " << stagger[i_layer];
666  halfstrip[i_layer][thisHalfstrip].push_back(bx_times[i]);
667  }
668  else if (i > 0) {
669  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
670  << "+++ station "<< theStation<<" ring "<< theRing<<" chamber "<< theChamber
671  << " Skipping comparator digi: strip = " << thisStrip
672  << ", layer = " << i_layer+1 << ", bx = " << bx_times[i]
673  << ", bx of previous hit = " << bx_times[i-1];
674  }
675  }
676  else {
677  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
678  << "+++ station "<< theStation<<" ring "<< theRing<<" chamber "<< theChamber
679  << "+++ Skipping comparator digi: strip = " << thisStrip
680  << ", layer = " << i_layer+1 << ", bx = " << bx_times[i] << " +++";
681  }
682  }
683  }
684  }
685 }
686 
687 
688 // TMB-07 version.
689 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::findLCTs(const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
690 {
691  std::vector<CSCCLCTDigi> lctList;
692 
693  // Max. number of half-strips for this chamber.
694  const int maxHalfStrips = 2*numStrips + 1;
695 
696  if (infoV > 1) dumpDigis(halfstrip, maxHalfStrips);
697 
698  // 2 possible LCTs per CSC x 7 LCT quantities
701 
702  // Fire half-strip one-shots for hit_persist bx's (4 bx's by default).
703  pulseExtension(halfstrip, maxHalfStrips, pulse);
704 
705  unsigned int start_bx = start_bx_shift;
706  // Stop drift_delay bx's short of fifo_tbins since at later bx's we will
707  // not have a full set of hits to start pattern search anyway.
708  unsigned int stop_bx = fifo_tbins - drift_delay;
709  // Allow for more than one pass over the hits in the time window.
710  while (start_bx < stop_bx) {
711  // All half-strip pattern envelopes are evaluated simultaneously, on every
712  // clock cycle.
713  int first_bx = 999;
714  bool pre_trig = preTrigger(pulse, start_bx, first_bx);
715 
716  // If any of half-strip envelopes has enough layers hit in it, TMB
717  // will pre-trigger.
718  if (pre_trig) {
719  thePreTriggerBXs.push_back(first_bx);
720  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
721  << "..... pretrigger at bx = " << first_bx
722  << "; waiting drift delay .....";
723 
724  // TMB latches LCTs drift_delay clocks after pretrigger.
725  int latch_bx = first_bx + drift_delay;
726  bool hits_in_time = patternFinding(pulse, maxHalfStrips, latch_bx);
727  if (infoV > 1) {
728  if (hits_in_time) {
729  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
730  hstrip < maxHalfStrips; hstrip++) {
731  if (nhits[hstrip] > 0) {
732  LogTrace("CSCCathodeLCTProcessor")
733  << " bx = " << std::setw(2) << latch_bx << " --->"
734  << " halfstrip = " << std::setw(3) << hstrip
735  << " best pid = " << std::setw(2) << best_pid[hstrip]
736  << " nhits = " << nhits[hstrip];
737  }
738  }
739  }
740  }
741  // The pattern finder runs continuously, so another pre-trigger
742  // could occur already at the next bx.
743  //start_bx = first_bx + 1;
744 
745  // Quality for sorting.
748  for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++) {
749  best_halfstrip[ilct] = -1;
750  best_quality[ilct] = 0;
751  }
752 
753  // Calculate quality from pattern id and number of hits, and
754  // simultaneously select best-quality LCT.
755  if (hits_in_time) {
756  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
757  hstrip < maxHalfStrips; hstrip++) {
758  // The bend-direction bit pid[0] is ignored (left and right
759  // bends have equal quality).
760  quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
761  if (quality[hstrip] > best_quality[0]) {
762  best_halfstrip[0] = hstrip;
763  best_quality[0] = quality[hstrip];
764  }
765  if (infoV > 1 && quality[hstrip] > 0) {
766  LogTrace("CSCCathodeLCTProcessor")
767  << " 1st CLCT: halfstrip = " << std::setw(3) << hstrip
768  << " quality = " << std::setw(3) << quality[hstrip]
769  << " nhits = " << std::setw(3) << nhits[hstrip]
770  << " pid = " << std::setw(3) << best_pid[hstrip]
771  << " best halfstrip = " << std::setw(3) << best_halfstrip[0]
772  << " best quality = " << std::setw(3) << best_quality[0];
773  }
774  }
775  }
776 
777  // If 1st best CLCT is found, look for the 2nd best.
778  if (best_halfstrip[0] >= 0) {
779  // Mark keys near best CLCT as busy by setting their quality to
780  // zero, and repeat the search.
781  markBusyKeys(best_halfstrip[0], best_pid[best_halfstrip[0]], quality);
782 
783  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
784  hstrip < maxHalfStrips; hstrip++) {
785  if (quality[hstrip] > best_quality[1]) {
786  best_halfstrip[1] = hstrip;
787  best_quality[1] = quality[hstrip];
788  }
789  if (infoV > 1 && quality[hstrip] > 0) {
790  LogTrace("CSCCathodeLCTProcessor")
791  << " 2nd CLCT: halfstrip = " << std::setw(3) << hstrip
792  << " quality = " << std::setw(3) << quality[hstrip]
793  << " nhits = " << std::setw(3) << nhits[hstrip]
794  << " pid = " << std::setw(3) << best_pid[hstrip]
795  << " best halfstrip = " << std::setw(3) << best_halfstrip[1]
796  << " best quality = " << std::setw(3) << best_quality[1];
797  }
798  }
799 
800  // Pattern finder.
801  //bool ptn_trig = false;
802  for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++) {
803  int best_hs = best_halfstrip[ilct];
804  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
805  //ptn_trig = true;
806  keystrip_data[ilct][CLCT_PATTERN] = best_pid[best_hs];
807  keystrip_data[ilct][CLCT_BEND] =
809  // Remove stagger if any.
810  keystrip_data[ilct][CLCT_STRIP] =
812  keystrip_data[ilct][CLCT_BX] = first_bx;
813  keystrip_data[ilct][CLCT_STRIP_TYPE] = 1; // obsolete
814  keystrip_data[ilct][CLCT_QUALITY] = nhits[best_hs];
815  keystrip_data[ilct][CLCT_CFEB] =
817  int halfstrip_in_cfeb = keystrip_data[ilct][CLCT_STRIP] -
819 
820  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
821  << " Final selection: ilct " << ilct
822  << " key halfstrip " << keystrip_data[ilct][CLCT_STRIP]
823  << " quality " << keystrip_data[ilct][CLCT_QUALITY]
824  << " pattern " << keystrip_data[ilct][CLCT_PATTERN]
825  << " bx " << keystrip_data[ilct][CLCT_BX];
826 
827  CSCCLCTDigi thisLCT(1, keystrip_data[ilct][CLCT_QUALITY],
828  keystrip_data[ilct][CLCT_PATTERN],
829  keystrip_data[ilct][CLCT_STRIP_TYPE],
830  keystrip_data[ilct][CLCT_BEND],
831  halfstrip_in_cfeb,
832  keystrip_data[ilct][CLCT_CFEB],
833  keystrip_data[ilct][CLCT_BX]);
834  lctList.push_back(thisLCT);
835  }
836  }
837  }//find CLCT, end of best_halfstrip[0] >= 0
838 
839  //if (ptn_trig) {
840  // Once there was a trigger, CLCT pre-trigger state machine
841  // checks the number of hits that lie on a pattern template
842  // at every bx, and waits for it to drop below threshold.
843  // The search for CLCTs resumes only when the number of hits
844  // drops below threshold.
845  start_bx = fifo_tbins;
846  // Stop checking drift_delay bx's short of fifo_tbins since
847  // at later bx's we won't have a full set of hits for a
848  // pattern search anyway.
849  unsigned int stop_time = fifo_tbins - drift_delay;
850  for (unsigned int bx = latch_bx + 1; bx < stop_time; bx++) {
851  bool return_to_idle = true;
852  bool hits_in_time = patternFinding(pulse, maxHalfStrips, bx);
853  if (hits_in_time) {
854  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
855  hstrip < maxHalfStrips; hstrip++) {
856  //if (nhits[hstrip] >= nplanes_hit_pattern) {
857  if (nhits[hstrip] >= nplanes_hit_pretrig) {//Tao, move dead time to pretrigger level
858  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
859  << " State machine busy at bx = " << bx;
860  return_to_idle = false;
861  break;
862  }
863  }
864  }
865  if (return_to_idle) {
866  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
867  << " State machine returns to idle state at bx = " << bx;
868  start_bx = bx;
869  break;
870  }
871  }
872  //}
873  }//pre_trig
874  else {
875  start_bx = first_bx + 1; // no dead time
876  }
877  }
878 
879  return lctList;
880 } // findLCTs -- TMB-07 version.
881 
882 
883 // Common to all versions.
886  const int nStrips,
887  unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
888 {
889  static const unsigned int bits_in_pulse = 8*sizeof(pulse[0][0]);
890 
891  // Clear pulse array. This array will be used as a bit representation of
892  // hit times. For example: if strip[1][2] has a value of 3, then 1 shifted
893  // left 3 will be bit pattern of pulse[1][2]. This would make the pattern
894  // look like 0000000000001000. Then add on additional bits to signify
895  // the duration of a signal (hit_persist, formerly bx_width) to simulate
896  // the TMB's drift delay. So for the same pulse[1][2] with a hit_persist
897  // of 3 would look like 0000000000111000. This is similating the digital
898  // one-shot in the TMB.
899  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
900  for (int i_strip = 0; i_strip < nStrips; i_strip++)
901  pulse[i_layer][i_strip] = 0;
902 
903  // Loop over all layers and halfstrips.
904  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
905  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
906  // If there is a hit, simulate digital one-shot persistence starting
907  // in the bx of the initial hit. Fill this into pulse[][].
908  if (!time[i_layer][i_strip].empty()) {
909  std::vector<int> bx_times = time[i_layer][i_strip];
910  for (unsigned int i = 0; i < bx_times.size(); i++) {
911  // Check that min and max times are within the allowed range.
912  if (bx_times[i] < 0 || bx_times[i] + hit_persist >= bits_in_pulse) {
913  if (infoV > 0) edm::LogWarning("L1CSCTPEmulatorOutOfTimeDigi")
914  << "+++ BX time of comparator digi (halfstrip = " << i_strip
915  << " layer = " << i_layer << ") bx = " << bx_times[i]
916  << " is not within the range (0-" << bits_in_pulse
917  << "] allowed for pulse extension. Skip this digi! +++\n";
918  continue;
919  }
920  if (bx_times[i] >= start_bx_shift) {
921  for (unsigned int bx = bx_times[i]; bx < bx_times[i] + hit_persist; ++bx)
922  pulse[i_layer][i_strip] = pulse[i_layer][i_strip] | (1 << bx);
923  }
924  }
925  }
926  }
927  }
928 } // pulseExtension.
929 
930 
931 // TMB-07 version.
934  const int start_bx, int& first_bx)
935 {
936  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
937  << "....................PreTrigger...........................";
938 
939  // Max. number of half-strips for this chamber.
940  const int nStrips = 2*numStrips + 1;
941 
942  int nPreTriggers = 0;
943 
944  bool pre_trig = false;
945  // Now do a loop over bx times to see (if/when) track goes over threshold
946  for (unsigned int bx_time = start_bx; bx_time < fifo_tbins; bx_time++) {
947  // For any given bunch-crossing, start at the lowest keystrip and look for
948  // the number of separate layers in the pattern for that keystrip that have
949  // pulses at that bunch-crossing time. Do the same for the next keystrip,
950  // etc. Then do the entire process again for the next bunch-crossing, etc
951  // until you find a pre-trigger.
952  bool hits_in_time = patternFinding(pulse, nStrips, bx_time);
953  if (hits_in_time) {
954  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
955  hstrip < nStrips; hstrip++) {
956  if (infoV > 1) {
957  if (nhits[hstrip] > 0) {
958  LogTrace("CSCCathodeLCTProcessor")
959  << " bx = " << std::setw(2) << bx_time << " --->"
960  << " halfstrip = " << std::setw(3) << hstrip
961  << " best pid = " << std::setw(2) << best_pid[hstrip]
962  << " nhits = " << nhits[hstrip];
963  }
964  }
965  ispretrig[hstrip] = false;
966  if (nhits[hstrip] >= nplanes_hit_pretrig &&
967  best_pid[hstrip] >= pid_thresh_pretrig) {
968  pre_trig = true;
969  ispretrig[hstrip] = true;
970 
971  // write each pre-trigger to output
972  nPreTriggers++;
974  const int halfstrip = hstrip%CSCConstants::NUM_HALF_STRIPS_PER_CFEB;
975  const int cfeb = hstrip/CSCConstants::NUM_HALF_STRIPS_PER_CFEB;
976  thePreTriggerDigis.push_back(CSCCLCTPreTriggerDigi(1, nhits[hstrip], best_pid[hstrip],
977  1, bend, halfstrip, cfeb, bx_time, nPreTriggers, 0));
978 
979  }
980  }
981 
982  if (pre_trig) {
983  first_bx = bx_time; // bx at time of pretrigger
984  return true;
985  }
986  }
987  } // end loop over bx times
988 
989  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor") <<
990  "no pretrigger, returning \n";
991  first_bx = fifo_tbins;
992  return false;
993 } // preTrigger -- TMB-07 version.
994 
995 
996 // TMB-07 version.
999  const int nStrips, const unsigned int bx_time)
1000 {
1001  if (bx_time >= fifo_tbins) return false;
1002 
1003  // This loop is a quick check of a number of layers hit at bx_time: since
1004  // most of the time it is 0, this check helps to speed-up the execution
1005  // substantially.
1006  unsigned int layers_hit = 0;
1007  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
1008  {
1009  for (int i_hstrip = 0; i_hstrip < nStrips; i_hstrip++)
1010  {
1011  if (((pulse[i_layer][i_hstrip] >> bx_time) & 1) == 1)
1012  {
1013  layers_hit++;
1014  break;
1015  }
1016  }
1017  }
1018  if (layers_hit < nplanes_hit_pretrig) return false;
1019 
1020  for (int key_hstrip = 0; key_hstrip < nStrips; key_hstrip++)
1021  {
1022  best_pid[key_hstrip] = 0;
1023  nhits[key_hstrip] = 0;
1024  first_bx_corrected[key_hstrip] = -999;
1025  }
1026 
1027  // Loop over candidate key strips.
1028  bool hit_layer[CSCConstants::NUM_LAYERS];
1029  for (int key_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; key_hstrip < nStrips; key_hstrip++)
1030  {
1031  // Loop over patterns and look for hits matching each pattern.
1032  for (unsigned int pid = CSCConstants::NUM_CLCT_PATTERNS - 1; pid >= pid_thresh_pretrig; pid--)
1033  {
1034  layers_hit = 0;
1035  for (int ilayer = 0; ilayer < CSCConstants::NUM_LAYERS; ilayer++)
1036  hit_layer[ilayer] = false;
1037 
1038  double num_pattern_hits=0., times_sum=0.;
1039  std::multiset<int> mset_for_median;
1040  mset_for_median.clear();
1041 
1042  // Loop over halfstrips in trigger pattern mask and calculate the
1043  // "absolute" halfstrip number for each.
1044  for (int strip_num = 0; strip_num < CSCConstants::MAX_HALFSTRIPS_IN_PATTERN; strip_num++)
1045  {
1046  int this_layer = pattern2007[pid][strip_num];
1047  if (this_layer >= 0 && this_layer < CSCConstants::NUM_LAYERS)
1048  {
1049  int this_strip = pattern2007_offset[strip_num] + key_hstrip;
1050  if (this_strip >= 0 && this_strip < nStrips) {
1051  if (infoV > 3) LogTrace("CSCCathodeLCTProcessor")
1052  << " In patternFinding: key_strip = " << key_hstrip
1053  << " pid = " << pid << " strip_num = " << strip_num
1054  << " layer = " << this_layer << " strip = " << this_strip;
1055  // Determine if "one shot" is high at this bx_time
1056  if (((pulse[this_layer][this_strip] >> bx_time) & 1) == 1)
1057  {
1058  if (hit_layer[this_layer] == false)
1059  {
1060  hit_layer[this_layer] = true;
1061  layers_hit++; // determines number of layers hit
1062  }
1063 
1064  // find at what bx did pulse on this halsfstrip&layer have started
1065  // use hit_pesrist constraint on how far back we can go
1066  int first_bx_layer = bx_time;
1067  for (unsigned int dbx = 0; dbx < hit_persist; dbx++)
1068  {
1069  if (((pulse[this_layer][this_strip] >> (first_bx_layer - 1)) & 1) == 1)
1070  first_bx_layer--;
1071  else
1072  break;
1073  }
1074  times_sum += (double) first_bx_layer;
1075  num_pattern_hits += 1.;
1076  mset_for_median.insert(first_bx_layer);
1077  if (infoV > 2)
1078  LogTrace("CSCCathodeLCTProcessor") << " 1st bx in layer: " << first_bx_layer << " sum bx: " << times_sum
1079  << " #pat. hits: " << num_pattern_hits;
1080  }
1081  }
1082  }
1083  } // end loop over strips in pretrigger pattern
1084 
1085  if (layers_hit > nhits[key_hstrip])
1086  {
1087  best_pid[key_hstrip] = pid;
1088  nhits[key_hstrip] = layers_hit;
1089 
1090  // calculate median
1091  const int sz = mset_for_median.size();
1092  if (sz>0){
1093  std::multiset<int>::iterator im = mset_for_median.begin();
1094  if (sz>1) std::advance(im,sz/2-1);
1095  if (sz==1) first_bx_corrected[key_hstrip] = *im;
1096  else if ((sz % 2) == 1) first_bx_corrected[key_hstrip] = *(++im);
1097  else first_bx_corrected[key_hstrip] = ((*im) + (*(++im)))/2;
1098 
1099 #if defined(EDM_ML_DEBUG)
1100  //LogTrace only ever prints if EDM_ML_DEBUG is defined
1101  if (infoV > 1) {
1102  auto lt = LogTrace("CSCCathodeLCTProcessor")
1103  <<"bx="<<bx_time<<" bx_cor="<< first_bx_corrected[key_hstrip]<<" bxset=";
1104  for (im = mset_for_median.begin(); im != mset_for_median.end(); im++) {
1105  lt<<" "<<*im;
1106  }
1107  }
1108 #endif
1109  }
1110  // Do not loop over the other (worse) patterns if max. numbers of
1111  // hits is found.
1112  if (nhits[key_hstrip] == CSCConstants::NUM_LAYERS) break;
1113  }
1114  } // end loop over pid
1115  } // end loop over candidate key strips
1116  return true;
1117 } // patternFinding -- TMB-07 version.
1118 
1119 
1120 // TMB-07 version.
1121 void CSCCathodeLCTProcessor::markBusyKeys(const int best_hstrip,
1122  const int best_patid,
1124 {
1125  int nspan = min_separation;
1126  int pspan = min_separation;
1127 
1128  for (int hstrip = best_hstrip-nspan; hstrip <= best_hstrip+pspan; hstrip++) {
1129  if (hstrip >= 0 && hstrip < CSCConstants::NUM_HALF_STRIPS_7CFEBS) {
1130  quality[hstrip] = 0;
1131  }
1132  }
1133 } // markBusyKeys -- TMB-07 version.
1134 
1135 
1136 // --------------------------------------------------------------------------
1137 // Auxiliary code.
1138 // --------------------------------------------------------------------------
1139 // Dump of configuration parameters.
1141  std::ostringstream strm;
1142  strm << "\n";
1143  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1144  strm << "+ CLCT configuration parameters: +\n";
1145  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1146  strm << " fifo_tbins [total number of time bins in DAQ readout] = "
1147  << fifo_tbins << "\n";
1148  strm << " fifo_pretrig [start time of cathode raw hits in DAQ readout] = "
1149  << fifo_pretrig << "\n";
1150  strm << " hit_persist [duration of signal pulse, in 25 ns bins] = "
1151  << hit_persist << "\n";
1152  strm << " drift_delay [time after pre-trigger before TMB latches LCTs] = "
1153  << drift_delay << "\n";
1154  strm << " nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = "
1155  << nplanes_hit_pretrig << "\n";
1156  strm << " nplanes_hit_pattern [min. number of layers hit for trigger] = "
1157  << nplanes_hit_pattern << "\n";
1158  strm << " pid_thresh_pretrig [lower threshold on pattern id] = "
1159  << pid_thresh_pretrig << "\n";
1160  strm << " min_separation [region of busy key strips] = "
1161  << min_separation << "\n";
1162  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1163  LogDebug("CSCCathodeLCTProcessor") << strm.str();
1164 }
1165 
1166 // Reasonably nice dump of digis on half-strips.
1168 {
1169  LogDebug("CSCCathodeLCTProcessor")
1171  << " strip type: half-strip, nStrips " << nStrips;
1172 
1173  std::ostringstream strstrm;
1174  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
1175  if (i_strip%10 == 0) {
1176  if (i_strip < 100) strstrm << i_strip/10;
1177  else strstrm << (i_strip-100)/10;
1178  }
1179  else strstrm << " ";
1180  if ((i_strip+1)%CSCConstants::NUM_HALF_STRIPS_PER_CFEB == 0) strstrm << " ";
1181  }
1182  strstrm << "\n";
1183  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
1184  strstrm << i_strip%10;
1185  if ((i_strip+1)%CSCConstants::NUM_HALF_STRIPS_PER_CFEB == 0) strstrm << " ";
1186  }
1187  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
1188  strstrm << "\n";
1189  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
1190  if (!strip[i_layer][i_strip].empty()) {
1191  std::vector<int> bx_times = strip[i_layer][i_strip];
1192  // Dump only the first in time.
1193  strstrm << std::hex << bx_times[0] << std::dec;
1194  }
1195  else {
1196  strstrm << "-";
1197  }
1198  if ((i_strip+1)%CSCConstants::NUM_HALF_STRIPS_PER_CFEB == 0) strstrm << " ";
1199  }
1200  }
1201  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
1202 }
1203 
1204 // Returns vector of read-out CLCTs, if any. Starts with the vector
1205 // of all found CLCTs and selects the ones in the read-out time window.
1206 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::readoutCLCTs() const
1207 {
1208  std::vector<CSCCLCTDigi> tmpV;
1209 
1210  // The start time of the L1A*CLCT coincidence window should be
1211  // related to the fifo_pretrig parameter, but I am not completely
1212  // sure how. For now, just choose it such that the window is
1213  // centered at bx=7. This may need further tweaking if the value of
1214  // tmb_l1a_window_size changes.
1215 
1216  // The number of CLCT bins in the read-out is given by the
1217  // tmb_l1a_window_size parameter, but made even by setting the LSB
1218  // of tmb_l1a_window_size to 0.
1219  //
1220  static std::atomic<int> lct_bins;
1222  static std::atomic<int> late_tbins;
1223  late_tbins = early_tbins + lct_bins;
1224 
1225  static std::atomic<int> ifois{0};
1226  if (ifois == 0) {
1227  if (infoV >= 0 && early_tbins < 0) {
1228  edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
1229  << "+++ early_tbins = " << early_tbins
1230  << "; in-time CLCTs are not getting read-out!!! +++" << "\n";
1231  }
1232 
1233  if (late_tbins > CSCConstants::MAX_CLCT_TBINS-1) {
1234  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
1235  << "+++ Allowed range of time bins, [0-" << late_tbins
1236  << "] exceeds max allowed, " << CSCConstants::MAX_CLCT_TBINS-1 << " +++\n"
1237  << "+++ Set late_tbins to max allowed +++\n";
1238  late_tbins = CSCConstants::MAX_CLCT_TBINS-1;
1239  }
1240  ifois = 1;
1241  }
1242 
1243  // Start from the vector of all found CLCTs and select those within
1244  // the CLCT*L1A coincidence window.
1245  int bx_readout = -1;
1246  const std::vector<CSCCLCTDigi>& all_lcts = getCLCTs();
1247  for (const auto& p : all_lcts) {
1248  if (!p.isValid()) continue;
1249 
1250  const int bx = p.getBX();
1251  // Skip CLCTs found too early relative to L1Accept.
1252  if (bx <= early_tbins) {
1253  if (infoV > 1) LogDebug("CSCCathodeLCTProcessor")
1254  << " Do not report CLCT on key halfstrip " << p.getKeyStrip()
1255  << ": found at bx " << bx << ", whereas the earliest allowed bx is "
1256  << early_tbins+1;
1257  continue;
1258  }
1259 
1260  // Skip CLCTs found too late relative to L1Accept.
1261  if (bx > late_tbins) {
1262  if (infoV > 1) LogDebug("CSCCathodeLCTProcessor")
1263  << " Do not report CLCT on key halfstrip " << p.getKeyStrip()
1264  << ": found at bx " << bx << ", whereas the latest allowed bx is "
1265  << late_tbins;
1266  continue;
1267  }
1268 
1269  // If (readout_earliest_2) take only CLCTs in the earliest bx in the read-out window:
1270  // in digi->raw step, LCTs have to be packed into the TMB header, and
1271  // currently there is room just for two.
1272  if (readout_earliest_2) {
1273  if (bx_readout == -1 || bx == bx_readout) {
1274  tmpV.push_back(p);
1275  if (bx_readout == -1) bx_readout = bx;
1276  }
1277  }
1278  else tmpV.push_back(p);
1279  }
1280  return tmpV;
1281 }
1282 
1283 // Returns vector of read-out CLCTs, if any. Starts with the vector
1284 // of all found CLCTs and selects the ones in the read-out time window.
1285 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::readoutCLCTsME1a() const
1286 {
1287  std::vector<CSCCLCTDigi> tmpV;
1288  if (not (theStation == 1 and (theRing == 1 or theRing == 4)) )
1289  return tmpV;
1290  const std::vector<CSCCLCTDigi>& allCLCTs = readoutCLCTs();
1291  for (const auto& clct : allCLCTs)
1292  if (clct.getCFEB() >= 4 )
1293  tmpV.push_back(clct);
1294  return tmpV;
1295 }
1296 
1297 
1298 // Returns vector of read-out CLCTs, if any. Starts with the vector
1299 // of all found CLCTs and selects the ones in the read-out time window.
1300 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::readoutCLCTsME1b() const
1301 {
1302  std::vector<CSCCLCTDigi> tmpV;
1303  if (not (theStation == 1 and (theRing == 1 or theRing == 4)) )
1304  return tmpV;
1305  const std::vector<CSCCLCTDigi>& allCLCTs = readoutCLCTs();
1306  for (const auto& clct : allCLCTs)
1307  if (clct.getCFEB() < 4 )
1308  tmpV.push_back(clct);
1309  return tmpV;
1310 }
1311 
1312 
1313 std::vector<CSCCLCTPreTriggerDigi> CSCCathodeLCTProcessor::preTriggerDigisME1a() const
1314 {
1315  std::vector<CSCCLCTPreTriggerDigi> tmpV;
1316  if (not (theStation == 1 and (theRing == 1 or theRing == 4)) )
1317  return tmpV;
1318  const std::vector<CSCCLCTPreTriggerDigi>& allPretriggerdigis = preTriggerDigis();
1319  for (const auto& preclct : allPretriggerdigis)
1320  if (preclct.getCFEB() >= 4 )
1321  tmpV.push_back(preclct);
1322  return tmpV;
1323 }
1324 
1325 
1326 std::vector<CSCCLCTPreTriggerDigi> CSCCathodeLCTProcessor::preTriggerDigisME1b() const
1327 {
1328  std::vector<CSCCLCTPreTriggerDigi> tmpV;
1329  if (not (theStation == 1 and (theRing == 1 or theRing == 4)) )
1330  return tmpV;
1331  const std::vector<CSCCLCTPreTriggerDigi>& allPretriggerdigis = preTriggerDigis();
1332  for (const auto& preclct : allPretriggerdigis)
1333  if (preclct.getCFEB() < 4 )
1334  tmpV.push_back(preclct);
1335  return tmpV;
1336 }
1337 
1338 
1339 // Returns vector of all found CLCTs, if any. Used for ALCT-CLCT matching.
1340 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::getCLCTs() const
1341 {
1342  std::vector<CSCCLCTDigi> tmpV;
1343  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
1344  if (bestCLCT[bx].isValid()) tmpV.push_back(bestCLCT[bx]);
1345  if (secondCLCT[bx].isValid()) tmpV.push_back(secondCLCT[bx]);
1346  }
1347  return tmpV;
1348 }
#define LogDebug(id)
static const unsigned int def_drift_delay
T getParameter(std::string const &) const
CSCCLCTDigi bestCLCT[CSCConstants::MAX_CLCT_TBINS]
void dumpDigis(const std::vector< int > strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const int nStrips) const
bool patternFinding(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const int nStrips, const unsigned int bx_time)
std::vector< CSCCLCTDigi > readoutCLCTs() const
static const unsigned int def_fifo_tbins
bool ispretrig[CSCConstants::NUM_HALF_STRIPS_7CFEBS]
const unsigned theEndcap
Definition: CSCBaseboard.h:33
unsigned int clctHitPersist() const
virtual std::vector< CSCCLCTDigi > findLCTs(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
static std::string chamberName(int endcap, int station, int ring, int chamber)
Definition: CSCDetId.cc:65
const CSCChamber * cscChamber_
Definition: CSCBaseboard.h:55
int first_bx_corrected[CSCConstants::NUM_HALF_STRIPS_7CFEBS]
unsigned int clctNplanesHitPattern() const
const unsigned theSector
Definition: CSCBaseboard.h:35
static const int pattern2007_offset[CSCConstants::MAX_HALFSTRIPS_IN_PATTERN]
static const unsigned int def_min_separation
int numberOfStrips() const
std::vector< CSCCLCTDigi > readoutCLCTsME1b() const
bool disableME1a_
Definition: CSCBaseboard.h:77
unsigned int clctMinSeparation() const
unsigned int clctNplanesHitPretrig() const
static const unsigned int def_nplanes_hit_pretrig
virtual bool preTrigger(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const int start_bx, int &first_bx)
unsigned int clctDriftDelay() const
bool gangedME1a_
Definition: CSCBaseboard.h:77
static const unsigned int def_pid_thresh_pretrig
unsigned int best_pid[CSCConstants::NUM_HALF_STRIPS_7CFEBS]
void markBusyKeys(const int best_hstrip, const int best_patid, int quality[CSCConstants::NUM_HALF_STRIPS_7CFEBS])
const unsigned theTrigChamber
Definition: CSCBaseboard.h:37
unsigned int clctPidThreshPretrig() const
void readComparatorDigis(std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
static const int pattern2007[CSCConstants::NUM_CLCT_PATTERNS][CSCConstants::MAX_HALFSTRIPS_IN_PATTERN+2]
std::vector< CSCCLCTDigi > readoutCLCTsME1a() 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
bool getDigis(const CSCComparatorDigiCollection *compdc)
static const unsigned int def_nplanes_hit_pattern
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:39
unsigned theChamber
Definition: CSCBaseboard.h:40
unsigned int clctFifoPretrig() const
edm::ParameterSet clctParams_
Definition: CSCBaseboard.h:67
#define LogTrace(id)
std::vector< CSCCLCTPreTriggerDigi > thePreTriggerDigis
std::vector< CSCCLCTPreTriggerDigi > preTriggerDigisME1b() const
edm::ParameterSet tmbParams_
Definition: CSCBaseboard.h:61
std::string chamberName() const
Definition: CSCDetId.cc:71
int stagger() const
std::vector< CSCCLCTDigi > getCLCTs() const
double pulse(double x, double y, double z, double t)
static const unsigned int def_fifo_pretrig
std::vector< int > thePreTriggerBXs
static const unsigned int def_hit_persist
const unsigned theStation
Definition: CSCBaseboard.h:34
int stagger[CSCConstants::NUM_LAYERS]
std::vector< DigiType >::const_iterator const_iterator
unsigned int nhits[CSCConstants::NUM_HALF_STRIPS_7CFEBS]
std::vector< CSCCLCTDigi > run(const CSCComparatorDigiCollection *compdc)
unsigned int clctFifoTbins() const
#define begin
Definition: vmac.h:32
CSCCLCTDigi secondCLCT[CSCConstants::MAX_CLCT_TBINS]
void clear()
clear this CLCT
Definition: CSCCLCTDigi.cc:54
std::vector< CSCComparatorDigi > digiV[CSCConstants::NUM_LAYERS]
std::pair< const_iterator, const_iterator > Range
unsigned theRing
Definition: CSCBaseboard.h:39
void pulseExtension(const std::vector< int > time[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const int nStrips, unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
std::vector< CSCCLCTPreTriggerDigi > preTriggerDigisME1a() const
unsigned int alctClctOffset_
Definition: CSCBaseboard.h:86
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:47
std::vector< CSCCLCTPreTriggerDigi > preTriggerDigis() const
void setConfigParameters(const CSCDBL1TPParameters *conf)
const unsigned theSubsector
Definition: CSCBaseboard.h:36
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting CLCTs.
Definition: CSCCLCTDigi.h:100