CMS 3D CMS Logo

CSCCathodeLCTProcessor.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Class: CSCCathodeLCTProcessor
4 //
5 // Description:
6 // This class simulates the functionality of the cathode LCT card. It is
7 // run by the MotherBoard and returns up to two CathodeLCTs. It can be
8 // run either in a test mode, where it is passed arrays of halfstrip
9 // times, or in normal mode where it determines
10 // the time and comparator information from the comparator digis.
11 //
12 // Additional comments by Jason Mumford 01/31/01 (mumford@physics.ucla.edu)
13 // Removed the card boundaries. Changed the Pretrigger to emulate
14 // the hardware electronic logic. Also changed the keylayer to be the 4th
15 // layer in a chamber instead of the 3rd layer from the interaction region.
16 // The code is a more realistic simulation of hardware LCT logic now.
17 //
18 // Author List: Benn Tannenbaum (1999), Jason Mumford (2001-2), Slava Valuev.
19 // Porting from ORCA by S. Valuev (Slava.Valuev@cern.ch),
20 // May 2006.
21 //
22 //
23 // Modifications:
24 //
25 //-----------------------------------------------------------------------------
26 
29 
32 
33 #include <algorithm>
34 #include <iomanip>
35 #include <iostream>
36 #include <set>
37 
38 //-----------------
39 // Static variables
40 //-----------------
41 
42 // New set of halfstrip patterns for 2007 version of the algorithm.
43 // For the given pattern, set the unused parts of the pattern to 999.
44 // Pattern[i][CSCConstants::MAX_HALFSTRIPS_IN_PATTERN] contains bend direction.
45 // Bend of 0 is right/straight and bend of 1 is left.
46 // Pattern[i][CSCConstants::MAX_HALFSTRIPS_IN_PATTERN+1] contains pattern maximum width
48  { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,
49  -2, -1, 0, 1, 2,
50  0,
51  -2, -1, 0, 1, 2,
52  -4, -3, -2, -1, 0, 1, 2, 3, 4,
53  -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 };
54 
56  { 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
57  999, 999, 999, 999, 999,
58  999, // pid=0: no pattern found
59  999, 999, 999, 999, 999,
60  999, 999, 999, 999, 999, 999, 999, 999, 999,
61  999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, -1, 0},
62  //-------------------------------------------------------------
63  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64  1, 1, 1, 1, 1,
65  2, // pid=1: layer-OR trigger
66  3, 3, 3, 3, 3,
67  4, 4, 4, 4, 4, 4, 4, 4, 4,
68  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, -1, 11},
69  //-------------------------------------------------------------
70  { 999, 999, 999, 999, 999, 999, 999, 999, 0, 0, 0,
71  999, 999, 999, 1, 1,
72  2, // pid=2: right-bending (large)
73  3, 3, 3, 999, 999,
74  4, 4, 4, 999, 999, 999, 999, 999, 999,
75  5, 5, 5, 999, 999, 999, 999, 999, 999, 999, 999, 0, 11},
76  //-------------------------------------------------------------
77  { 0, 0, 0, 999, 999, 999, 999, 999, 999, 999, 999,
78  1, 1, 999, 999, 999,
79  2, // pid=3: left-bending (large)
80  999, 999, 3, 3, 3,
81  999, 999, 999, 999, 999, 999, 4, 4, 4,
82  999, 999, 999, 999, 999, 999, 999, 999, 5, 5, 5, 1, 11},
83  //-------------------------------------------------------------
84  { 999, 999, 999, 999, 999, 999, 999, 0, 0, 0, 999,
85  999, 999, 999, 1, 1,
86  2, // pid=4: right-bending (medium)
87  3, 3, 999, 999, 999,
88  4, 4, 4, 999, 999, 999, 999, 999, 999,
89  999, 5, 5, 5, 999, 999, 999, 999, 999, 999, 999, 0, 9},
90  //-------------------------------------------------------------
91  { 999, 0, 0, 0, 999, 999, 999, 999, 999, 999, 999,
92  1, 1, 999, 999, 999,
93  2, // pid=5: left-bending (medium)
94  999, 999, 999, 3, 3,
95  999, 999, 999, 999, 999, 999, 4, 4, 4,
96  999, 999, 999, 999, 999, 999, 999, 5, 5, 5, 999, 1, 9},
97  //-------------------------------------------------------------
98  { 999, 999, 999, 999, 999, 999, 0, 0, 0, 999, 999,
99  999, 999, 1, 1, 999,
100  2, // pid=6: right-bending (medium)
101  999, 3, 3, 999, 999,
102  999, 999, 4, 4, 999, 999, 999, 999, 999,
103  999, 999, 5, 5, 5, 999, 999, 999, 999, 999, 999, 0, 7},
104  //-------------------------------------------------------------
105  { 999, 999, 0, 0, 0, 999, 999, 999, 999, 999, 999,
106  999, 1, 1, 999, 999,
107  2, // pid=7: left-bending (medium)
108  999, 999, 3, 3, 999,
109  999, 999, 999, 999, 999, 4, 4, 999, 999,
110  999, 999, 999, 999, 999, 999, 5, 5, 5, 999, 999, 1, 7},
111  //-------------------------------------------------------------
112  { 999, 999, 999, 999, 999, 0, 0, 0, 999, 999, 999,
113  999, 999, 1, 1, 999,
114  2, // pid=8: right-bending (small)
115  999, 3, 3, 999, 999,
116  999, 999, 4, 4, 4, 999, 999, 999, 999,
117  999, 999, 999, 5, 5, 5, 999, 999, 999, 999, 999, 0, 5},
118  //-------------------------------------------------------------
119  { 999, 999, 999, 0, 0, 0, 999, 999, 999, 999, 999,
120  999, 1, 1, 999, 999,
121  2, // pid=9: left-bending (small)
122  999, 999, 3, 3, 999,
123  999, 999, 999, 999, 4, 4, 4, 999, 999,
124  999, 999, 999, 999, 999, 5, 5, 5, 999, 999, 999, 1, 5},
125  //-------------------------------------------------------------
126  { 999, 999, 999, 999, 0, 0, 0, 999, 999, 999, 999,
127  999, 999, 1, 999, 999,
128  2, // pid=A: straight-through
129  999, 999, 3, 999, 999,
130  999, 999, 999, 4, 4, 4, 999, 999, 999,
131  999, 999, 999, 999, 5, 5, 5, 999, 999, 999, 999, 0, 3}
132  // pid's=B-F are not yet defined
133 };
134 
135 // Default values of configuration parameters.
136 const unsigned int CSCCathodeLCTProcessor::def_fifo_tbins = 12;
137 const unsigned int CSCCathodeLCTProcessor::def_fifo_pretrig = 7;
138 const unsigned int CSCCathodeLCTProcessor::def_hit_persist = 6;
139 const unsigned int CSCCathodeLCTProcessor::def_drift_delay = 2;
143 const unsigned int CSCCathodeLCTProcessor::def_min_separation = 10;
145 
146 // Number of di-strips/half-strips per CFEB.
150 };
151 
152 //----------------
153 // Constructors --
154 //----------------
155 
157  unsigned station,
158  unsigned sector,
159  unsigned subsector,
160  unsigned chamber,
161  const edm::ParameterSet& conf,
162  const edm::ParameterSet& comm,
163  const edm::ParameterSet& ctmb) :
164  theEndcap(endcap), theStation(station), theSector(sector),
165  theSubsector(subsector), theTrigChamber(chamber) {
166  static std::atomic<bool> config_dumped{false};
167 
168  // CLCT configuration parameters.
169  fifo_tbins = conf.getParameter<unsigned int>("clctFifoTbins");
170  hit_persist = conf.getParameter<unsigned int>("clctHitPersist");
171  drift_delay = conf.getParameter<unsigned int>("clctDriftDelay");
173  conf.getParameter<unsigned int>("clctNplanesHitPretrig");
175  conf.getParameter<unsigned int>("clctNplanesHitPattern");
176 
177  // Not used yet.
178  fifo_pretrig = conf.getParameter<unsigned int>("clctFifoPretrig");
179 
180  // Flag for SLHC studies
181  isSLHC = comm.getParameter<bool>("isSLHC");
182 
183  // shift the BX from 7 to 8
184  // the unpacked real data CLCTs have central BX at bin 7
185  // however in simulation the central BX is bin 8
186  // to make a proper comparison with ALCTs we need
187  // CLCT and ALCT to have the central BX in the same bin
188  // this shift does not affect the readout of the CLCTs
189  // emulated CLCTs put in the event should be centered at bin 7 (as in data)
190  alctClctOffset = comm.getParameter<unsigned int>("alctClctOffset");
191 
192  // special configuration parameters for ME11 treatment
193  smartME1aME1b = comm.getParameter<bool>("smartME1aME1b");
194  disableME1a = comm.getParameter<bool>("disableME1a");
195  gangedME1a = comm.getParameter<bool>("gangedME1a");
196 
197  if (isSLHC && !smartME1aME1b) edm::LogError("L1CSCTPEmulatorConfigError")
198  << "+++ SLHC upgrade configuration is used (isSLHC=True) but smartME1aME1b=False!\n"
199  << "Only smartME1aME1b algorithm is so far supported for upgrade! +++\n";
200 
202  conf.getParameter<unsigned int>("clctPidThreshPretrig");
204  conf.getParameter<unsigned int>("clctMinSeparation");
205 
206  start_bx_shift = conf.getParameter<int>("clctStartBxShift");
207 
208  if (smartME1aME1b) {
209  // use of localized dead-time zones
210  use_dead_time_zoning = conf.existsAs<bool>("useDeadTimeZoning")?conf.getParameter<bool>("useDeadTimeZoning"):true;
211  clct_state_machine_zone = conf.existsAs<unsigned int>("clctStateMachineZone")?conf.getParameter<unsigned int>("clctStateMachineZone"):8;
212  dynamic_state_machine_zone = conf.existsAs<bool>("useDynamicStateMachineZone")?conf.getParameter<bool>("useDynamicStateMachineZone"):true;
213 
214  // how far away may trigger happen from pretrigger
215  pretrig_trig_zone = conf.existsAs<unsigned int>("clctPretriggerTriggerZone")?conf.getParameter<unsigned int>("clctPretriggerTriggerZone"):5;
216 
217  // whether to calculate bx as corrected_bx instead of pretrigger one
218  use_corrected_bx = conf.existsAs<bool>("clctUseCorrectedBx")?conf.getParameter<bool>("clctUseCorrectedBx"):true;
219  }
220 
221  // Motherboard parameters: common for all configurations.
222  tmb_l1a_window_size = // Common to CLCT and TMB
223  ctmb.getParameter<unsigned int>("tmbL1aWindowSize");
224 
225  // separate handle for early time bins
226  early_tbins = ctmb.getParameter<int>("tmbEarlyTbins");
227  if (early_tbins<0) early_tbins = fifo_pretrig - CSCConstants::CLCT_EMUL_TIME_OFFSET;
228 
229  // wether to readout only the earliest two LCTs in readout window
230  readout_earliest_2 = ctmb.getParameter<bool>("tmbReadoutEarliest2");
231 
232  // Verbosity level, set to 0 (no print) by default.
233  infoV = conf.getParameter<int>("verbosity");
234 
235  // Check and print configuration parameters.
237  if ((infoV > 0 || isSLHC) && !config_dumped) {
238  //std::cerr<<"**** CLCT constructor parameters dump ****"<<std::endl;
240  config_dumped = true;
241  }
242 
243  numStrips = 0; // Will be set later.
244  // Provisional, but should be OK for all stations except ME1.
245  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
246  if ((i_layer+1)%2 == 0) stagger[i_layer] = 0;
247  else stagger[i_layer] = 1;
248  }
249 
251 
254 
255  // trigger numbering doesn't distinguish between ME1a and ME1b chambers:
256  isME11 = (theStation == 1 && theRing == 1);
257 
258  thePreTriggerDigis.clear();
259 }
260 
262  theEndcap(1), theStation(1), theSector(1),
264  // constructor for debugging.
265  static std::atomic<bool> config_dumped{false};
266 
267  // CLCT configuration parameters.
269  infoV = 2;
270 
271  smartME1aME1b = false;
272  disableME1a = false;
273  gangedME1a = true;
274 
275  early_tbins = 4;
276 
277  start_bx_shift = 0;
278  use_dead_time_zoning = true;
280 
281  // Check and print configuration parameters.
283  if (!config_dumped) {
285  config_dumped = true;
286  }
287 
289  // Should be OK for all stations except ME1.
290  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
291  if ((i_layer+1)%2 == 0) stagger[i_layer] = 0;
292  else stagger[i_layer] = 1;
293  }
294 
296  isME11 = (theStation == 1 && theRing == 1);
297 
298  thePreTriggerDigis.clear();
299 }
300 
302 {
303  // Set default values for configuration parameters.
313 }
314 
315 // Set configuration parameters obtained via EventSetup mechanism.
317 {
318  static std::atomic<bool> config_dumped{false};
319 
320  fifo_tbins = conf->clctFifoTbins();
321  fifo_pretrig = conf->clctFifoPretrig();
322  hit_persist = conf->clctHitPersist();
323  drift_delay = conf->clctDriftDelay();
328 
329  // Check and print configuration parameters.
331  if (!config_dumped) {
332  //std::cerr<<"**** CLCT setConfigParams parameters dump ****"<<std::endl;
334  config_dumped = true;
335  }
336 }
337 
339  // Make sure that the parameter values are within the allowed range.
340 
341  // Max expected values.
342  static const unsigned int max_fifo_tbins = 1 << 5;
343  static const unsigned int max_fifo_pretrig = 1 << 5;
344  static const unsigned int max_hit_persist = 1 << 4;
345  static const unsigned int max_drift_delay = 1 << 2;
346  static const unsigned int max_nplanes_hit_pretrig = 1 << 3;
347  static const unsigned int max_nplanes_hit_pattern = 1 << 3;
348  static const unsigned int max_pid_thresh_pretrig = 1 << 4;
349  static const unsigned int max_min_separation = CSCConstants::NUM_HALF_STRIPS_7CFEBS;
350  static const unsigned int max_tmb_l1a_window_size = 1 << 4;
351 
352  // Checks.
353  if (fifo_tbins >= max_fifo_tbins) {
354  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
355  << "+++ Value of fifo_tbins, " << fifo_tbins
356  << ", exceeds max allowed, " << max_fifo_tbins-1 << " +++\n"
357  << "+++ Try to proceed with the default value, fifo_tbins="
358  << def_fifo_tbins << " +++\n";
360  }
361  if (fifo_pretrig >= max_fifo_pretrig) {
362  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
363  << "+++ Value of fifo_pretrig, " << fifo_pretrig
364  << ", exceeds max allowed, " << max_fifo_pretrig-1 << " +++\n"
365  << "+++ Try to proceed with the default value, fifo_pretrig="
366  << def_fifo_pretrig << " +++\n";
368  }
369  if (hit_persist >= max_hit_persist) {
370  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
371  << "+++ Value of hit_persist, " << hit_persist
372  << ", exceeds max allowed, " << max_hit_persist-1 << " +++\n"
373  << "+++ Try to proceed with the default value, hit_persist="
374  << def_hit_persist << " +++\n";
376  }
377  if (drift_delay >= max_drift_delay) {
378  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
379  << "+++ Value of drift_delay, " << drift_delay
380  << ", exceeds max allowed, " << max_drift_delay-1 << " +++\n"
381  << "+++ Try to proceed with the default value, drift_delay="
382  << def_drift_delay << " +++\n";
384  }
385  if (nplanes_hit_pretrig >= max_nplanes_hit_pretrig) {
386  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
387  << "+++ Value of nplanes_hit_pretrig, " << nplanes_hit_pretrig
388  << ", exceeds max allowed, " << max_nplanes_hit_pretrig-1 << " +++\n"
389  << "+++ Try to proceed with the default value, nplanes_hit_pretrig="
390  << def_nplanes_hit_pretrig << " +++\n";
392  }
393  if (nplanes_hit_pattern >= max_nplanes_hit_pattern) {
394  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
395  << "+++ Value of nplanes_hit_pattern, " << nplanes_hit_pattern
396  << ", exceeds max allowed, " << max_nplanes_hit_pattern-1 << " +++\n"
397  << "+++ Try to proceed with the default value, nplanes_hit_pattern="
398  << def_nplanes_hit_pattern << " +++\n";
400  }
401 
402  if (pid_thresh_pretrig >= max_pid_thresh_pretrig) {
403  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
404  << "+++ Value of pid_thresh_pretrig, " << pid_thresh_pretrig
405  << ", exceeds max allowed, " << max_pid_thresh_pretrig-1 << " +++\n"
406  << "+++ Try to proceed with the default value, pid_thresh_pretrig="
407  << def_pid_thresh_pretrig << " +++\n";
409  }
410  if (min_separation >= max_min_separation) {
411  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
412  << "+++ Value of min_separation, " << min_separation
413  << ", exceeds max allowed, " << max_min_separation-1 << " +++\n"
414  << "+++ Try to proceed with the default value, min_separation="
415  << def_min_separation << " +++\n";
417  }
418 
419  if (tmb_l1a_window_size >= max_tmb_l1a_window_size) {
420  if (infoV > 0) edm::LogError("L1CSCTPEmulatorConfigError")
421  << "+++ Value of tmb_l1a_window_size, " << tmb_l1a_window_size
422  << ", exceeds max allowed, " << max_tmb_l1a_window_size-1 << " +++\n"
423  << "+++ Try to proceed with the default value, tmb_l1a_window_size="
424  << def_tmb_l1a_window_size << " +++\n";
426  }
427 }
428 
430  thePreTriggerDigis.clear();
431  thePreTriggerBXs.clear();
432  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
433  bestCLCT[bx].clear();
434  secondCLCT[bx].clear();
435  }
436 }
437 
438 std::vector<CSCCLCTDigi>
440  // This is the version of the run() function that is called when running
441  // over the entire detector. It gets the comparator & timing info from the
442  // comparator digis and then passes them on to another run() function.
443 
444  // clear(); // redundant; called by L1MuCSCMotherboard.
445 
446  static std::atomic<bool> config_dumped{false};
447  if ((infoV > 0 || isSLHC) && !config_dumped) {
448  //std::cerr<<"**** CLCT run parameters dump ****"<<std::endl;
450  config_dumped = true;
451  }
452 
453  // Get the number of strips and stagger of layers for the given chamber.
454  // Do it only once per chamber.
455  if (numStrips == 0) {
458  CSCDetId detid(theEndcap, theStation, ring, chid, 0);
459  const auto& chamber = csc_g->chamber(detid);
460 
461  if (chamber) {
462  numStrips = chamber->layer(1)->geometry()->numberOfStrips();
463  // ME1/a is known to the readout hardware as strips 65-80 of ME1/1.
464  // Still need to decide whether we do any special adjustments to
465  // reconstruct LCTs in this region (3:1 ganged strips); for now, we
466  // simply allow for hits in ME1/a and apply standard reconstruction
467  // to them.
468  // For SLHC ME1/1 is set to have 4 CFEBs in ME1/b and 3 CFEBs in ME1/a
469  if (isME11) {
470  if (!smartME1aME1b && !disableME1a && theRing == 1 && !gangedME1a) numStrips = 112;
471  if (!smartME1aME1b && !disableME1a && theRing == 1 && gangedME1a) numStrips = 80;
472  if (!smartME1aME1b && disableME1a && theRing == 1 ) numStrips = 64;
473  if ( smartME1aME1b && !disableME1a && theRing == 1 ) numStrips = 64;
474  if ( smartME1aME1b && !disableME1a && theRing == 4 ) {
475  if (gangedME1a) numStrips = 16;
476  else numStrips = 48;
477  }
478  }
479 
481  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorSetupError")
482  << "+++ Number of strips, " << numStrips
483  << " found in " << detid.chamberName()
484  << " (sector " << theSector << " subsector " << theSubsector
485  << " trig id. " << theTrigChamber << ")"
486  << " exceeds max expected, " << CSCConstants::MAX_NUM_STRIPS_7CFEBS
487  << " +++\n"
488  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
489  numStrips = -1;
490  }
491  // The strips for a given layer may be offset from the adjacent layers.
492  // This was done in order to improve resolution. We need to find the
493  // 'staggering' for each layer and make necessary conversions in our
494  // arrays. -JM
495  // In the TMB-07 firmware, half-strips in odd layers (layers are
496  // counted as ly0-ly5) are shifted by -1 half-strip, whereas in
497  // the previous firmware versions half-strips in even layers
498  // were shifted by +1 half-strip. This difference is due to a
499  // change from ly3 to ly2 in the choice of the key layer, and
500  // the intention to keep half-strips in the key layer unchanged.
501  // In the emulator, we use the old way for both cases, to avoid
502  // negative half-strip numbers. This will necessitate a
503  // subtraction of 1 half-strip for TMB-07 later on. -SV.
504  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
505  stagger[i_layer] =
506  (chamber->layer(i_layer+1)->geometry()->stagger() + 1) / 2;
507  }
508  }
509  else {
510  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
512  << " (sector " << theSector << " subsector " << theSubsector
513  << " trig id. " << theTrigChamber << ")"
514  << " is not defined in current geometry! +++\n"
515  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
516  numStrips = -1;
517  }
518  }
519 
520  if (numStrips < 0) {
521  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
523  << " (sector " << theSector << " subsector " << theSubsector
524  << " trig id. " << theTrigChamber << "):"
525  << " numStrips = " << numStrips << "; CLCT emulation skipped! +++";
526  std::vector<CSCCLCTDigi> emptyV;
527  return emptyV;
528  }
529 
530  // Get comparator digis in this chamber.
531  bool noDigis = getDigis(compdc);
532 
533  if (!noDigis) {
534  // Get halfstrip times from comparator digis.
535  std::vector<int>
537  readComparatorDigis(halfstrip);
538 
539  // Pass arrays of halfstrips on to another run() doing the
540  // LCT search.
541  // If the number of layers containing digis is smaller than that
542  // required to trigger, quit right away. (If LCT-based digi suppression
543  // is implemented one day, this condition will have to be changed
544  // to the number of planes required to pre-trigger.)
545  unsigned int layersHit = 0;
546  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
547  for (int i_hstrip = 0; i_hstrip < CSCConstants::NUM_HALF_STRIPS_7CFEBS;
548  i_hstrip++) {
549  if (!halfstrip[i_layer][i_hstrip].empty()) {layersHit++; break;}
550  }
551  }
552  // Run the algorithm only if the probability for the pre-trigger
553  // to fire is not null. (Pre-trigger decisions are used for the
554  // strip read-out conditions in DigiToRaw.)
555  if (layersHit >= nplanes_hit_pretrig) run(halfstrip);
556  }
557 
558  // Return vector of CLCTs.
559  std::vector<CSCCLCTDigi> tmpV = getCLCTs();
560 
561  // shift the BX from 7 to 8
562  // the unpacked real data CLCTs have central BX at bin 7
563  // however in simulation the central BX is bin 8
564  // to make a proper comparison with ALCTs we need
565  // CLCT and ALCT to have the central BX in the same bin
566  // this shift does not affect the readout of the CLCTs
567  // emulated CLCTs put in the event should be centered at bin 7 (as in data)
568  for (auto& p : tmpV){
569  p.setBX(p.getBX() + alctClctOffset);
570  }
571 
572  return tmpV;
573 }
574 
576 {
577  // This version of the run() function can either be called in a standalone
578  // test, being passed the halfstrip times, or called by the
579  // run() function above. It uses the findLCTs() method to find vectors
580  // of LCT candidates. These candidates are sorted and the best two per bx
581  // are returned.
582  std::vector<CSCCLCTDigi> CLCTlist;
583 
584  // Upgrade version for ME11 with better dead-time handling
585  if (isSLHC && smartME1aME1b && isME11 && use_dead_time_zoning) CLCTlist = findLCTsSLHC(halfstrip);
586  // TMB07 version of the CLCT algorithm.
587  else CLCTlist = findLCTs(halfstrip);
588 
589  // LCT sorting.
590  if (CLCTlist.size() > 1)
591  sort(CLCTlist.begin(), CLCTlist.end(), std::greater<CSCCLCTDigi>());
592 
593  // Take the best two candidates per bx.
594  for (std::vector<CSCCLCTDigi>::const_iterator plct = CLCTlist.begin();
595  plct != CLCTlist.end(); plct++) {
596  int bx = plct->getBX();
597  if (bx >= CSCConstants::MAX_CLCT_TBINS) {
598  if (infoV > 0) edm::LogWarning("L1CSCTPEmulatorOutOfTimeCLCT")
599  << "+++ Bx of CLCT candidate, " << bx << ", exceeds max allowed, "
600  << CSCConstants::MAX_CLCT_TBINS-1 << "; skipping it... +++\n";
601  continue;
602  }
603 
604  if (!bestCLCT[bx].isValid()) bestCLCT[bx] = *plct;
605  else if (!secondCLCT[bx].isValid()) {
606  secondCLCT[bx] = *plct;
607  }
608  }
609 
610  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
611  if (bestCLCT[bx].isValid()) {
612  bestCLCT[bx].setTrknmb(1);
613  if (infoV > 0) LogDebug("CSCCathodeLCTProcessor")
614  << bestCLCT[bx] << " found in " <<
616  << " (sector " << theSector << " subsector " << theSubsector
617  << " trig id. " << theTrigChamber << ")" << "\n";
618  }
619  if (secondCLCT[bx].isValid()) {
620  secondCLCT[bx].setTrknmb(2);
621  if (infoV > 0) LogDebug("CSCCathodeLCTProcessor")
622  << secondCLCT[bx] << " found in " <<
624  << " (sector " << theSector << " subsector " << theSubsector
625  << " trig id. " << theTrigChamber << ")" << "\n";
626  }
627  }
628  // Now that we have our best CLCTs, they get correlated with the best
629  // ALCTs and then get sent to the MotherBoard. -JM
630 }
631 
633  bool noDigis = true;
634 
635  // Loop over layers and save comparator digis on each one into digiV[layer].
636  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
637  digiV[i_layer].clear();
638 
639  CSCDetId detid(theEndcap, theStation, theRing, theChamber, i_layer+1);
640  getDigis(compdc, detid);
641 
642  // If this is ME1/1, fetch digis in corresponding ME1/A (ring=4) as well.
643  if (theStation == 1 && theRing == 1 && !disableME1a && !smartME1aME1b) {
644  CSCDetId detid_me1a(theEndcap, theStation, 4, theChamber, i_layer+1);
645  getDigis(compdc, detid_me1a);
646  }
647 
648  // If this is ME1/1, fetch digis in corresponding ME1/B (ring=1) as well.
649  // needed only for the "smart" A/B case; and, actually, only for data
650  if (theStation == 1 && theRing == 4 && !disableME1a && smartME1aME1b
651  && digiV[i_layer].empty()) {
652  CSCDetId detid_me1b(theEndcap, theStation, 1, theChamber, i_layer+1);
653  getDigis(compdc, detid_me1b);
654  }
655 
656  if (!digiV[i_layer].empty()) {
657  noDigis = false;
658  if (infoV > 1) {
659  LogTrace("CSCCathodeLCTProcessor")
660  << "found " << digiV[i_layer].size()
661  << " comparator digi(s) in layer " << i_layer << " of " <<
662  detid.chamberName() << " (trig. sector " << theSector
663  << " subsector " << theSubsector << " id " << theTrigChamber << ")";
664  }
665  }
666  }
667 
668  return noDigis;
669 }
670 
672  const CSCDetId& id) {
673  bool me1bProc = theStation == 1 && theRing == 1;
674  bool me1aProc = theStation == 1 && theRing == 4;
675  bool me1b = (id.station() == 1) && (id.ring() == 1);
676  bool me1a = (id.station() == 1) && (id.ring() == 4);
677  const CSCComparatorDigiCollection::Range rcompd = compdc->get(id);
678  for (CSCComparatorDigiCollection::const_iterator digiIt = rcompd.first;
679  digiIt != rcompd.second; ++digiIt) {
680  unsigned int origStrip = digiIt->getStrip();
681  unsigned int maxStripsME1a = gangedME1a ? 16 : 48;
682  if (me1a && origStrip <= maxStripsME1a && !disableME1a && !smartME1aME1b) {
683  // Move ME1/A comparators from CFEB=0 to CFEB=4 if this has not
684  // been done already.
685  CSCComparatorDigi digi_corr(origStrip+64,
686  digiIt->getComparator(),
687  digiIt->getTimeBinWord());
688  digiV[id.layer()-1].push_back(digi_corr);
689  }
690  else if (smartME1aME1b && (me1bProc || me1aProc)){
691  //stay within bounds; in data all comps are in ME11B DetId
692 
693  if (me1aProc && me1b && origStrip > 64){//this is data
694  //shift back to start from 1
695  CSCComparatorDigi digi_corr(origStrip-64,
696  digiIt->getComparator(),
697  digiIt->getTimeBinWord());
698  digiV[id.layer()-1].push_back(digi_corr);
699  } else if ((me1bProc && me1b && origStrip <= 64)
700  || ((me1aProc && me1a))//this is MC for ME11a
701  ){
702  digiV[id.layer()-1].push_back(*digiIt);
703  }
704  }
705  else {
706  digiV[id.layer()-1].push_back(*digiIt);
707  }
708  }
709 }
710 
712  std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS]) {
713  // Single-argument version for TMB07 (halfstrip-only) firmware.
714  // Takes the comparator & time info and stuffs it into halfstrip vector.
715  // Multiple hits on the same strip are allowed.
716 
717  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
718  int i_digi = 0; // digi counter, for dumps.
719  for (std::vector<CSCComparatorDigi>::iterator pld = digiV[i_layer].begin();
720  pld != digiV[i_layer].end(); pld++, i_digi++) {
721  // Dump raw digi info.
722  if (infoV > 1) {
723  std::ostringstream strstrm;
724  strstrm << "Comparator digi: comparator = " << pld->getComparator()
725  << " strip #" << pld->getStrip()
726  << " time bins on:";
727  std::vector<int> bx_times = pld->getTimeBinsOn();
728  for (unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
729  strstrm << " " << bx_times[tbin];
730  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
731  }
732 
733  // Get comparator: 0/1 for left/right halfstrip for each comparator
734  // that fired.
735  int thisComparator = pld->getComparator();
736  if (thisComparator != 0 && thisComparator != 1) {
737  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
738  << "+++ Found comparator digi with wrong comparator value = "
739  << thisComparator << "; skipping it... +++\n";
740  continue;
741  }
742 
743  // Get strip number.
744  int thisStrip = pld->getStrip() - 1; // count from 0
745  if (thisStrip < 0 || thisStrip >= numStrips) {
746  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
747  << "+++ Found comparator digi with wrong strip number = "
748  << thisStrip
749  << " (max strips = " << numStrips << "); skipping it... +++\n";
750  continue;
751  }
752  // 2*strip: convert strip to 1/2 strip
753  // comp : comparator output
754  // stagger: stagger for this layer
755  int thisHalfstrip = 2*thisStrip + thisComparator + stagger[i_layer];
756  if (thisHalfstrip >= 2*numStrips + 1) {
757  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
758  << "+++ Found wrong halfstrip number = " << thisHalfstrip
759  << "; skipping this digi... +++\n";
760  continue;
761  }
762 
763  // Get bx times on this digi and check that they are within the bounds.
764  std::vector<int> bx_times = pld->getTimeBinsOn();
765  for (unsigned int i = 0; i < bx_times.size(); i++) {
766  // Total number of time bins in DAQ readout is given by fifo_tbins,
767  // which thus determines the maximum length of time interval.
768  //
769  // In TMB07 version, better data-emulator agreement is
770  // achieved when hits in the first 2 time bins are excluded.
771  // As of May 2009, the reasons for this are not fully
772  // understood yet (the work is on-going).
773  if (bx_times[i] > 1 && bx_times[i] < static_cast<int>(fifo_tbins)) {
774 
775  if (i == 0 || (i > 0 && bx_times[i]-bx_times[i-1] >=
776  static_cast<int>(hit_persist))) {
777  // A later hit on the same strip is ignored during the
778  // number of clocks defined by the "hit_persist" parameter
779  // (i.e., 6 bx's by default).
780  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
781  << "Comp digi: layer " << i_layer+1
782  << " digi #" << i_digi+1
783  << " strip " << thisStrip
784  << " halfstrip " << thisHalfstrip
785  << " time " << bx_times[i]
786  << " comparator " << thisComparator
787  << " stagger " << stagger[i_layer];
788  halfstrip[i_layer][thisHalfstrip].push_back(bx_times[i]);
789  }
790  else if (i > 0) {
791  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
792  << " Skipping comparator digi: strip = " << thisStrip
793  << ", layer = " << i_layer+1 << ", bx = " << bx_times[i]
794  << ", bx of previous hit = " << bx_times[i-1];
795  }
796  }
797  else {
798  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
799  << "+++ Skipping comparator digi: strip = " << thisStrip
800  << ", layer = " << i_layer+1 << ", bx = " << bx_times[i] << " +++";
801  }
802  }
803  }
804  }
805 }
806 
807 
808 // --------------------------------------------------------------------------
809 // The code below is a description of the 2007 version of the CLCT
810 // algorithm (half-strips only). It was first used in 2008 CRUZET runs,
811 // and later in CRAFT. The algorithm became the default version for
812 // Monte Carlo studies in March 2008 (CMSSW_2_0_0).
813 // --------------------------------------------------------------------------
814 // TMB-07 version.
815 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::findLCTs(const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS]) {
816  std::vector<CSCCLCTDigi> lctList;
817 
818  // Max. number of half-strips for this chamber.
819  const int maxHalfStrips = 2*numStrips + 1;
820 
821  if (infoV > 1) dumpDigis(halfstrip, 1, maxHalfStrips);
822 
823  // 2 possible LCTs per CSC x 7 LCT quantities
826 
827  // Fire half-strip one-shots for hit_persist bx's (4 bx's by default).
828  pulseExtension(halfstrip, maxHalfStrips, pulse);
829 
830  unsigned int start_bx = start_bx_shift;
831  // Stop drift_delay bx's short of fifo_tbins since at later bx's we will
832  // not have a full set of hits to start pattern search anyway.
833  unsigned int stop_bx = fifo_tbins - drift_delay;
834  // Allow for more than one pass over the hits in the time window.
835  while (start_bx < stop_bx) {
836  // All half-strip pattern envelopes are evaluated simultaneously, on every
837  // clock cycle.
838  int first_bx = 999;
839  bool pre_trig = preTrigger(pulse, start_bx, first_bx);
840 
841  // If any of half-strip envelopes has enough layers hit in it, TMB
842  // will pre-trigger.
843  if (pre_trig) {
844  thePreTriggerBXs.push_back(first_bx);
845  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
846  << "..... pretrigger at bx = " << first_bx
847  << "; waiting drift delay .....";
848 
849  // TMB latches LCTs drift_delay clocks after pretrigger.
850  int latch_bx = first_bx + drift_delay;
851  bool hits_in_time = ptnFinding(pulse, maxHalfStrips, latch_bx);
852  if (infoV > 1) {
853  if (hits_in_time) {
854  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
855  hstrip < maxHalfStrips; hstrip++) {
856  if (nhits[hstrip] > 0) {
857  LogTrace("CSCCathodeLCTProcessor")
858  << " bx = " << std::setw(2) << latch_bx << " --->"
859  << " halfstrip = " << std::setw(3) << hstrip
860  << " best pid = " << std::setw(2) << best_pid[hstrip]
861  << " nhits = " << nhits[hstrip];
862  }
863  }
864  }
865  }
866  // The pattern finder runs continuously, so another pre-trigger
867  // could occur already at the next bx.
868  start_bx = first_bx + 1;
869 
870  // Quality for sorting.
873  for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++) {
874  best_halfstrip[ilct] = -1;
875  best_quality[ilct] = 0;
876  }
877 
878  // Calculate quality from pattern id and number of hits, and
879  // simultaneously select best-quality LCT.
880  if (hits_in_time) {
881  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
882  hstrip < maxHalfStrips; hstrip++) {
883  // The bend-direction bit pid[0] is ignored (left and right
884  // bends have equal quality).
885  quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
886  if (quality[hstrip] > best_quality[0]) {
887  best_halfstrip[0] = hstrip;
888  best_quality[0] = quality[hstrip];
889  }
890  if (infoV > 1 && quality[hstrip] > 0) {
891  LogTrace("CSCCathodeLCTProcessor")
892  << " 1st CLCT: halfstrip = " << std::setw(3) << hstrip
893  << " quality = " << std::setw(3) << quality[hstrip]
894  << " nhits = " << std::setw(3) << nhits[hstrip]
895  << " pid = " << std::setw(3) << best_pid[hstrip]
896  << " best halfstrip = " << std::setw(3) << best_halfstrip[0]
897  << " best quality = " << std::setw(3) << best_quality[0];
898  }
899  }
900  }
901 
902  // If 1st best CLCT is found, look for the 2nd best.
903  if (best_halfstrip[0] >= 0) {
904  // Mark keys near best CLCT as busy by setting their quality to
905  // zero, and repeat the search.
906  markBusyKeys(best_halfstrip[0], best_pid[best_halfstrip[0]], quality);
907 
908  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
909  hstrip < maxHalfStrips; hstrip++) {
910  if (quality[hstrip] > best_quality[1]) {
911  best_halfstrip[1] = hstrip;
912  best_quality[1] = quality[hstrip];
913  }
914  if (infoV > 1 && quality[hstrip] > 0) {
915  LogTrace("CSCCathodeLCTProcessor")
916  << " 2nd CLCT: halfstrip = " << std::setw(3) << hstrip
917  << " quality = " << std::setw(3) << quality[hstrip]
918  << " nhits = " << std::setw(3) << nhits[hstrip]
919  << " pid = " << std::setw(3) << best_pid[hstrip]
920  << " best halfstrip = " << std::setw(3) << best_halfstrip[1]
921  << " best quality = " << std::setw(3) << best_quality[1];
922  }
923  }
924 
925  // Pattern finder.
926  bool ptn_trig = false;
927  for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++) {
928  int best_hs = best_halfstrip[ilct];
929  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
930  ptn_trig = true;
931  keystrip_data[ilct][CLCT_PATTERN] = best_pid[best_hs];
932  keystrip_data[ilct][CLCT_BEND] =
934  // Remove stagger if any.
935  keystrip_data[ilct][CLCT_STRIP] =
937  keystrip_data[ilct][CLCT_BX] = first_bx;
938  keystrip_data[ilct][CLCT_STRIP_TYPE] = 1; // obsolete
939  keystrip_data[ilct][CLCT_QUALITY] = nhits[best_hs];
940  keystrip_data[ilct][CLCT_CFEB] =
942  int halfstrip_in_cfeb = keystrip_data[ilct][CLCT_STRIP] -
944 
945  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
946  << " Final selection: ilct " << ilct
947  << " key halfstrip " << keystrip_data[ilct][CLCT_STRIP]
948  << " quality " << keystrip_data[ilct][CLCT_QUALITY]
949  << " pattern " << keystrip_data[ilct][CLCT_PATTERN]
950  << " bx " << keystrip_data[ilct][CLCT_BX];
951 
952  CSCCLCTDigi thisLCT(1, keystrip_data[ilct][CLCT_QUALITY],
953  keystrip_data[ilct][CLCT_PATTERN],
954  keystrip_data[ilct][CLCT_STRIP_TYPE],
955  keystrip_data[ilct][CLCT_BEND],
956  halfstrip_in_cfeb,
957  keystrip_data[ilct][CLCT_CFEB],
958  keystrip_data[ilct][CLCT_BX]);
959  lctList.push_back(thisLCT);
960  }
961  }
962 
963  if (ptn_trig) {
964  // Once there was a trigger, CLCT pre-trigger state machine
965  // checks the number of hits that lie on a pattern template
966  // at every bx, and waits for it to drop below threshold.
967  // The search for CLCTs resumes only when the number of hits
968  // drops below threshold.
969  start_bx = fifo_tbins;
970  // Stop checking drift_delay bx's short of fifo_tbins since
971  // at later bx's we won't have a full set of hits for a
972  // pattern search anyway.
973  unsigned int stop_time = fifo_tbins - drift_delay;
974  for (unsigned int bx = latch_bx + 1; bx < stop_time; bx++) {
975  bool return_to_idle = true;
976  bool hits_in_time = ptnFinding(pulse, maxHalfStrips, bx);
977  if (hits_in_time) {
978  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
979  hstrip < maxHalfStrips; hstrip++) {
980  if (nhits[hstrip] >= nplanes_hit_pattern) {
981  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
982  << " State machine busy at bx = " << bx;
983  return_to_idle = false;
984  break;
985  }
986  }
987  }
988  if (return_to_idle) {
989  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
990  << " State machine returns to idle state at bx = " << bx;
991  start_bx = bx;
992  break;
993  }
994  }
995  }
996  }
997  }
998  else {
999  start_bx = first_bx + 1; // no dead time
1000  }
1001  }
1002 
1003  return lctList;
1004 } // findLCTs -- TMB-07 version.
1005 
1006 
1007 // Common to all versions.
1010  const int nStrips,
1011  unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS]) {
1012 
1013  static const unsigned int bits_in_pulse = 8*sizeof(pulse[0][0]);
1014 
1015  // Clear pulse array. This array will be used as a bit representation of
1016  // hit times. For example: if strip[1][2] has a value of 3, then 1 shifted
1017  // left 3 will be bit pattern of pulse[1][2]. This would make the pattern
1018  // look like 0000000000001000. Then add on additional bits to signify
1019  // the duration of a signal (hit_persist, formerly bx_width) to simulate
1020  // the TMB's drift delay. So for the same pulse[1][2] with a hit_persist
1021  // of 3 would look like 0000000000111000. This is similating the digital
1022  // one-shot in the TMB.
1023  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
1024  for (int i_strip = 0; i_strip < nStrips; i_strip++)
1025  pulse[i_layer][i_strip] = 0;
1026 
1027  // Loop over all layers and halfstrips.
1028  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
1029  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
1030  // If there is a hit, simulate digital one-shot persistence starting
1031  // in the bx of the initial hit. Fill this into pulse[][].
1032  if (!time[i_layer][i_strip].empty()) {
1033  std::vector<int> bx_times = time[i_layer][i_strip];
1034  for (unsigned int i = 0; i < bx_times.size(); i++) {
1035  // Check that min and max times are within the allowed range.
1036  if (bx_times[i] < 0 || bx_times[i] + hit_persist >= bits_in_pulse) {
1037  if (infoV > 0) edm::LogWarning("L1CSCTPEmulatorOutOfTimeDigi")
1038  << "+++ BX time of comparator digi (halfstrip = " << i_strip
1039  << " layer = " << i_layer << ") bx = " << bx_times[i]
1040  << " is not within the range (0-" << bits_in_pulse
1041  << "] allowed for pulse extension. Skip this digi! +++\n";
1042  continue;
1043  }
1044  if (bx_times[i] >= start_bx_shift) {
1045  for (unsigned int bx = bx_times[i]; bx < bx_times[i] + hit_persist; ++bx)
1046  pulse[i_layer][i_strip] = pulse[i_layer][i_strip] | (1 << bx);
1047  }
1048  }
1049  }
1050  }
1051  }
1052 } // pulseExtension.
1053 
1054 
1055 // TMB-07 version.
1058  const int start_bx, int& first_bx) {
1059  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1060  << "....................PreTrigger...........................";
1061 
1062  // Max. number of half-strips for this chamber.
1063  const int nStrips = 2*numStrips + 1;
1064 
1065  int nPreTriggers = 0;
1066 
1067  bool pre_trig = false;
1068  // Now do a loop over bx times to see (if/when) track goes over threshold
1069  for (unsigned int bx_time = start_bx; bx_time < fifo_tbins; bx_time++) {
1070  // For any given bunch-crossing, start at the lowest keystrip and look for
1071  // the number of separate layers in the pattern for that keystrip that have
1072  // pulses at that bunch-crossing time. Do the same for the next keystrip,
1073  // etc. Then do the entire process again for the next bunch-crossing, etc
1074  // until you find a pre-trigger.
1075  bool hits_in_time = ptnFinding(pulse, nStrips, bx_time);
1076  if (hits_in_time) {
1077  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
1078  hstrip < nStrips; hstrip++) {
1079  if (infoV > 1) {
1080  if (nhits[hstrip] > 0) {
1081  LogTrace("CSCCathodeLCTProcessor")
1082  << " bx = " << std::setw(2) << bx_time << " --->"
1083  << " halfstrip = " << std::setw(3) << hstrip
1084  << " best pid = " << std::setw(2) << best_pid[hstrip]
1085  << " nhits = " << nhits[hstrip];
1086  }
1087  }
1088  ispretrig[hstrip] = false;
1089  if (nhits[hstrip] >= nplanes_hit_pretrig &&
1090  best_pid[hstrip] >= pid_thresh_pretrig) {
1091  pre_trig = true;
1092  ispretrig[hstrip] = true;
1093 
1094  // write each pre-trigger to output
1095  nPreTriggers++;
1097  thePreTriggerDigis.push_back(CSCCLCTPreTriggerDigi(1, nhits[hstrip], best_pid[hstrip],
1098  1, bend, hstrip%32, hstrip/32, bx_time, nPreTriggers, 0));
1099 
1100  }
1101  }
1102 
1103  if (pre_trig) {
1104  first_bx = bx_time; // bx at time of pretrigger
1105  return true;
1106  }
1107  }
1108  } // end loop over bx times
1109 
1110  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor") <<
1111  "no pretrigger, returning \n";
1112  first_bx = fifo_tbins;
1113  return false;
1114 } // preTrigger -- TMB-07 version.
1115 
1116 
1117 // TMB-07 version.
1120  const int nStrips, const unsigned int bx_time)
1121 {
1122  if (bx_time >= fifo_tbins) return false;
1123 
1124  // This loop is a quick check of a number of layers hit at bx_time: since
1125  // most of the time it is 0, this check helps to speed-up the execution
1126  // substantially.
1127  unsigned int layers_hit = 0;
1128  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
1129  {
1130  for (int i_hstrip = 0; i_hstrip < nStrips; i_hstrip++)
1131  {
1132  if (((pulse[i_layer][i_hstrip] >> bx_time) & 1) == 1)
1133  {
1134  layers_hit++;
1135  break;
1136  }
1137  }
1138  }
1139  if (layers_hit < nplanes_hit_pretrig) return false;
1140 
1141  for (int key_hstrip = 0; key_hstrip < nStrips; key_hstrip++)
1142  {
1143  best_pid[key_hstrip] = 0;
1144  nhits[key_hstrip] = 0;
1145  first_bx_corrected[key_hstrip] = -999;
1146  }
1147 
1148  // Loop over candidate key strips.
1149  bool hit_layer[CSCConstants::NUM_LAYERS];
1150  for (int key_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; key_hstrip < nStrips; key_hstrip++)
1151  {
1152  // Loop over patterns and look for hits matching each pattern.
1153  for (unsigned int pid = CSCConstants::NUM_CLCT_PATTERNS - 1; pid >= pid_thresh_pretrig; pid--)
1154  {
1155  layers_hit = 0;
1156  for (int ilayer = 0; ilayer < CSCConstants::NUM_LAYERS; ilayer++)
1157  hit_layer[ilayer] = false;
1158 
1159  double num_pattern_hits=0., times_sum=0.;
1160  std::multiset<int> mset_for_median;
1161  mset_for_median.clear();
1162 
1163  // Loop over halfstrips in trigger pattern mask and calculate the
1164  // "absolute" halfstrip number for each.
1165  for (int strip_num = 0; strip_num < CSCConstants::MAX_HALFSTRIPS_IN_PATTERN; strip_num++)
1166  {
1167  int this_layer = pattern2007[pid][strip_num];
1168  if (this_layer >= 0 && this_layer < CSCConstants::NUM_LAYERS)
1169  {
1170  int this_strip = pattern2007_offset[strip_num] + key_hstrip;
1171  if (this_strip >= 0 && this_strip < nStrips) {
1172  if (infoV > 3) LogTrace("CSCCathodeLCTProcessor")
1173  << " In ptnFinding: key_strip = " << key_hstrip
1174  << " pid = " << pid << " strip_num = " << strip_num
1175  << " layer = " << this_layer << " strip = " << this_strip;
1176  // Determine if "one shot" is high at this bx_time
1177  if (((pulse[this_layer][this_strip] >> bx_time) & 1) == 1)
1178  {
1179  if (hit_layer[this_layer] == false)
1180  {
1181  hit_layer[this_layer] = true;
1182  layers_hit++; // determines number of layers hit
1183  }
1184 
1185  // find at what bx did pulse on this halsfstrip&layer have started
1186  // use hit_pesrist constraint on how far back we can go
1187  int first_bx_layer = bx_time;
1188  for (unsigned int dbx = 0; dbx < hit_persist; dbx++)
1189  {
1190  if (((pulse[this_layer][this_strip] >> (first_bx_layer - 1)) & 1) == 1)
1191  first_bx_layer--;
1192  else
1193  break;
1194  }
1195  times_sum += (double) first_bx_layer;
1196  num_pattern_hits += 1.;
1197  mset_for_median.insert(first_bx_layer);
1198  if (infoV > 2)
1199  LogTrace("CSCCathodeLCTProcessor") << " 1st bx in layer: " << first_bx_layer << " sum bx: " << times_sum
1200  << " #pat. hits: " << num_pattern_hits;
1201  }
1202  }
1203  }
1204  } // end loop over strips in pretrigger pattern
1205 
1206  if (layers_hit > nhits[key_hstrip])
1207  {
1208  best_pid[key_hstrip] = pid;
1209  nhits[key_hstrip] = layers_hit;
1210 
1211  // calculate median
1212  const int sz = mset_for_median.size();
1213  if (sz>0){
1214  std::multiset<int>::iterator im = mset_for_median.begin();
1215  if (sz>1) std::advance(im,sz/2-1);
1216  if (sz==1) first_bx_corrected[key_hstrip] = *im;
1217  else if ((sz % 2) == 1) first_bx_corrected[key_hstrip] = *(++im);
1218  else first_bx_corrected[key_hstrip] = ((*im) + (*(++im)))/2;
1219 
1220 #if defined(EDM_ML_DEBUG)
1221  //LogTrace only ever prints if EDM_ML_DEBUG is defined
1222  if (infoV > 1) {
1223  auto lt = LogTrace("CSCCathodeLCTProcessor")
1224  <<"bx="<<bx_time<<" bx_cor="<< first_bx_corrected[key_hstrip]<<" bxset=";
1225  for (im = mset_for_median.begin(); im != mset_for_median.end(); im++) {
1226  lt<<" "<<*im;
1227  }
1228  }
1229 #endif
1230  }
1231  // Do not loop over the other (worse) patterns if max. numbers of
1232  // hits is found.
1233  if (nhits[key_hstrip] == CSCConstants::NUM_LAYERS) break;
1234  }
1235  } // end loop over pid
1236  } // end loop over candidate key strips
1237  return true;
1238 } // ptnFinding -- TMB-07 version.
1239 
1240 
1241 // TMB-07 version.
1242 void CSCCathodeLCTProcessor::markBusyKeys(const int best_hstrip,
1243  const int best_patid,
1245  int nspan = min_separation;
1246  int pspan = min_separation;
1247 
1248  // if dynamic spacing is enabled, separation is defined by pattern width
1249  //if (dynamic_spacing)
1250  // nspan = pspan = pattern2007[best_patid][CSCConstants::MAX_HALFSTRIPS_IN_PATTERN+1]-1;
1251 
1252  for (int hstrip = best_hstrip-nspan; hstrip <= best_hstrip+pspan; hstrip++) {
1253  if (hstrip >= 0 && hstrip < CSCConstants::NUM_HALF_STRIPS_7CFEBS) {
1254  quality[hstrip] = 0;
1255  }
1256  }
1257 } // markBusyKeys -- TMB-07 version.
1258 
1259 
1260 
1261 // --------------------------------------------------------------------------
1262 // The code below is for SLHC studies of the CLCT algorithm (half-strips only).
1263 // --------------------------------------------------------------------------
1264 // SLHC version.
1265 std::vector<CSCCLCTDigi>
1267 {
1268  std::vector<CSCCLCTDigi> lctList;
1269 
1270  // Max. number of half-strips for this chamber.
1271  const int maxHalfStrips = 2 * numStrips + 1;
1272 
1273  if (infoV > 1) dumpDigis(halfstrip, 1, maxHalfStrips);
1274 
1275  // keeps dead-time zones around key halfstrips of triggered CLCTs
1277  for (int i = 0; i < CSCConstants::NUM_HALF_STRIPS_7CFEBS; i++)
1278  for (int j = 0; j < CSCConstants::MAX_CLCT_TBINS; j++)
1279  busyMap[i][j] = false;
1280 
1281  std::vector<CSCCLCTDigi> lctListBX;
1282 
1284 
1285  // Fire half-strip one-shots for hit_persist bx's (4 bx's by default).
1286  pulseExtension(halfstrip, maxHalfStrips, pulse);
1287 
1288  unsigned int start_bx = start_bx_shift;
1289  // Stop drift_delay bx's short of fifo_tbins since at later bx's we will
1290  // not have a full set of hits to start pattern search anyway.
1291  unsigned int stop_bx = fifo_tbins - drift_delay;
1292 
1293  // Allow for more than one pass over the hits in the time window.
1294  // Do search in every BX
1295  while (start_bx < stop_bx)
1296  {
1297  lctListBX.clear();
1298 
1299  // All half-strip pattern envelopes are evaluated simultaneously, on every clock cycle.
1300  int first_bx = 999;
1301  bool pre_trig = preTrigger(pulse, start_bx, first_bx);
1302 
1303  // If any of half-strip envelopes has enough layers hit in it, TMB
1304  // will pre-trigger.
1305  if (pre_trig)
1306  {
1307  if (infoV > 1)
1308  LogTrace("CSCCathodeLCTProcessor") << "..... pretrigger at bx = " << first_bx << "; waiting drift delay .....";
1309 
1310  // TMB latches LCTs drift_delay clocks after pretrigger.
1311  int latch_bx = first_bx + drift_delay;
1312  bool hits_in_time = ptnFinding(pulse, maxHalfStrips, latch_bx);
1313  if (infoV > 1)
1314  {
1315  if (hits_in_time)
1316  {
1317  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < maxHalfStrips; hstrip++)
1318  {
1319  if (nhits[hstrip] > 0)
1320  {
1321  LogTrace("CSCCathodeLCTProcessor") << " bx = " << std::setw(2) << latch_bx << " --->" << " halfstrip = "
1322  << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip] << " nhits = " << nhits[hstrip];
1323  }
1324  }
1325  }
1326  }
1327  // The pattern finder runs continuously, so another pre-trigger
1328  // could occur already at the next bx.
1329  start_bx = first_bx + 1;
1330 
1331  // 2 possible LCTs per CSC x 7 LCT quantities per BX
1332  int keystrip_data[CSCConstants::MAX_CLCTS_PER_PROCESSOR][CLCT_NUM_QUANTITIES] = {{0}};
1333 
1334  // Quality for sorting.
1337  for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++)
1338  {
1339  best_halfstrip[ilct] = -1;
1340  best_quality[ilct] = 0;
1341  }
1342 
1343  bool pretrig_zone[CSCConstants::NUM_HALF_STRIPS_7CFEBS];
1344 
1345  // Calculate quality from pattern id and number of hits, and
1346  // simultaneously select best-quality LCT.
1347  if (hits_in_time)
1348  {
1349  // first, mark half-strip zones around pretriggers
1350  // that happened at the current first_bx
1351  for (int hstrip = 0; hstrip < CSCConstants::NUM_HALF_STRIPS_7CFEBS; hstrip++)
1352  pretrig_zone[hstrip] = false;
1353  for (int hstrip = 0; hstrip < CSCConstants::NUM_HALF_STRIPS_7CFEBS; hstrip++)
1354  {
1355  if (ispretrig[hstrip])
1356  {
1357  int min_hs = hstrip - pretrig_trig_zone;
1358  int max_hs = hstrip + pretrig_trig_zone;
1359  if (min_hs < 0)
1360  min_hs = 0;
1361  if (max_hs > CSCConstants::NUM_HALF_STRIPS_7CFEBS - 1)
1362  max_hs = CSCConstants::NUM_HALF_STRIPS_7CFEBS - 1;
1363  for (int hs = min_hs; hs <= max_hs; hs++)
1364  pretrig_zone[hs] = true;
1365  if (infoV > 1)
1366  LogTrace("CSCCathodeLCTProcessor") << " marked pretrigger halfstrip zone [" << min_hs << "," << max_hs << "]";
1367  }
1368  }
1369 
1370  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < maxHalfStrips; hstrip++)
1371  {
1372  // The bend-direction bit pid[0] is ignored (left and right bends have equal quality).
1373  quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
1374  // do not consider halfstrips:
1375  // - out of pretrigger-trigger zones
1376  // - in busy zones from previous trigger
1377  if (quality[hstrip] > best_quality[0] &&
1378  pretrig_zone[hstrip] &&
1379  !busyMap[hstrip][first_bx] )
1380  {
1381  best_halfstrip[0] = hstrip;
1382  best_quality[0] = quality[hstrip];
1383  if (infoV > 1)
1384  {
1385  LogTrace("CSCCathodeLCTProcessor") << " 1st CLCT: halfstrip = " << std::setw(3) << hstrip << " quality = "
1386  << std::setw(3) << quality[hstrip] << " best halfstrip = " << std::setw(3) << best_halfstrip[0]
1387  << " best quality = " << std::setw(3) << best_quality[0];
1388  }
1389  }
1390  }
1391  }
1392 
1393  // If 1st best CLCT is found, look for the 2nd best.
1394  if (best_halfstrip[0] >= 0)
1395  {
1396  // Mark keys near best CLCT as busy by setting their quality to zero, and repeat the search.
1397  markBusyKeys(best_halfstrip[0], best_pid[best_halfstrip[0]], quality);
1398 
1399  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < maxHalfStrips; hstrip++)
1400  {
1401  if (quality[hstrip] > best_quality[1] &&
1402  pretrig_zone[hstrip] &&
1403  !busyMap[hstrip][first_bx] )
1404  {
1405  best_halfstrip[1] = hstrip;
1406  best_quality[1] = quality[hstrip];
1407  if (infoV > 1)
1408  {
1409  LogTrace("CSCCathodeLCTProcessor") << " 2nd CLCT: halfstrip = " << std::setw(3) << hstrip << " quality = "
1410  << std::setw(3) << quality[hstrip] << " best halfstrip = " << std::setw(3) << best_halfstrip[1]
1411  << " best quality = " << std::setw(3) << best_quality[1];
1412  }
1413  }
1414  }
1415 
1416  // Pattern finder.
1417  bool ptn_trig = false;
1418  for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++)
1419  {
1420  int best_hs = best_halfstrip[ilct];
1421  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern)
1422  {
1423  int bx = first_bx;
1424  int fbx = first_bx_corrected[best_hs];
1425  if (use_corrected_bx) {
1426  bx = fbx;
1427  fbx = first_bx;
1428  }
1429  ptn_trig = true;
1430  keystrip_data[ilct][CLCT_PATTERN] = best_pid[best_hs];
1431  keystrip_data[ilct][CLCT_BEND] = pattern2007[best_pid[best_hs]][CSCConstants::MAX_HALFSTRIPS_IN_PATTERN];
1432  // Remove stagger if any.
1433  keystrip_data[ilct][CLCT_STRIP] = best_hs - stagger[CSCConstants::KEY_CLCT_LAYER - 1];
1434  keystrip_data[ilct][CLCT_BX] = bx;
1435  keystrip_data[ilct][CLCT_STRIP_TYPE] = 1; // obsolete
1436  keystrip_data[ilct][CLCT_QUALITY] = nhits[best_hs];
1437  keystrip_data[ilct][CLCT_CFEB] = keystrip_data[ilct][CLCT_STRIP] / CSCConstants::NUM_HALF_STRIPS_PER_CFEB;
1438  int halfstrip_in_cfeb = keystrip_data[ilct][CLCT_STRIP] - CSCConstants::NUM_HALF_STRIPS_PER_CFEB * keystrip_data[ilct][CLCT_CFEB];
1439 
1440  if (infoV > 1)
1441  LogTrace("CSCCathodeLCTProcessor") << " Final selection: ilct " << ilct << " key halfstrip "
1442  << keystrip_data[ilct][CLCT_STRIP] << " quality " << keystrip_data[ilct][CLCT_QUALITY] << " pattern "
1443  << keystrip_data[ilct][CLCT_PATTERN] << " bx " << keystrip_data[ilct][CLCT_BX];
1444 
1445  CSCCLCTDigi thisLCT(1, keystrip_data[ilct][CLCT_QUALITY], keystrip_data[ilct][CLCT_PATTERN],
1446  keystrip_data[ilct][CLCT_STRIP_TYPE], keystrip_data[ilct][CLCT_BEND], halfstrip_in_cfeb,
1447  keystrip_data[ilct][CLCT_CFEB], keystrip_data[ilct][CLCT_BX]);
1448  thisLCT.setFullBX(fbx);
1449  lctList.push_back(thisLCT);
1450  lctListBX.push_back(thisLCT);
1451  }
1452  }
1453 
1454  // state-machine
1455  if (ptn_trig)
1456  {
1457  // Once there was a trigger, CLCT pre-trigger state machine checks the number of hits
1458  // that lie on a key halfstrip pattern template at every bx, and waits for it to drop below threshold.
1459  // During that time no CLCTs could be found with its key halfstrip in the area of
1460  // [clct_key-clct_state_machine_zone, clct_key+clct_state_machine_zone]
1461  // starting from first_bx+1.
1462  // The search for CLCTs resumes only when the number of hits on key halfstrip drops below threshold.
1463  for (unsigned int ilct = 0; ilct < lctListBX.size(); ilct++)
1464  {
1465  int key_hstrip = lctListBX[ilct].getKeyStrip() + stagger[CSCConstants::KEY_CLCT_LAYER - 1];
1466 
1467  int delta_hs = clct_state_machine_zone;
1469  delta_hs = pattern2007[lctListBX[ilct].getPattern()][CSCConstants::MAX_HALFSTRIPS_IN_PATTERN + 1] - 1;
1470 
1471  int min_hstrip = key_hstrip - delta_hs;
1472  int max_hstrip = key_hstrip + delta_hs;
1473 
1474  if (min_hstrip < stagger[CSCConstants::KEY_CLCT_LAYER - 1])
1475  min_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1];
1476  if (max_hstrip > maxHalfStrips)
1477  max_hstrip = maxHalfStrips;
1478 
1479  if (infoV > 2)
1480  LogTrace("CSCCathodeLCTProcessor") << " marking post-trigger zone after bx=" << lctListBX[ilct].getBX() << " ["
1481  << min_hstrip << "," << max_hstrip << "]";
1482 
1483  // Stop checking drift_delay bx's short of fifo_tbins since
1484  // at later bx's we won't have a full set of hits for a
1485  // pattern search anyway.
1486  //int stop_time = fifo_tbins - drift_delay;
1487  // -- no, need to extend busyMap over fifo_tbins - drift_delay
1488  for (size_t bx = first_bx + 1; bx < fifo_tbins; bx++)
1489  {
1490  bool busy_bx = false;
1491  if (bx <= (size_t)latch_bx)
1492  busy_bx = true; // always busy before drift time
1493  if (!busy_bx)
1494  {
1495  bool hits_in_time = ptnFinding(pulse, maxHalfStrips, bx);
1496  if (hits_in_time && nhits[key_hstrip] >= nplanes_hit_pattern)
1497  busy_bx = true;
1498  if (infoV > 2)
1499  LogTrace("CSCCathodeLCTProcessor") << " at bx=" << bx << " hits_in_time=" << hits_in_time << " nhits="
1500  << nhits[key_hstrip];
1501  }
1502  if (infoV > 2)
1503  LogTrace("CSCCathodeLCTProcessor") << " at bx=" << bx << " busy=" << busy_bx;
1504  if (busy_bx)
1505  for (int hstrip = min_hstrip; hstrip <= max_hstrip; hstrip++)
1506  busyMap[hstrip][bx] = true;
1507  else
1508  break;
1509  }
1510  }
1511  } // if (ptn_trig)
1512  }
1513  }
1514  else
1515  {
1516  start_bx = first_bx + 1; // no dead time
1517  }
1518  }
1519 
1520  return lctList;
1521 } // findLCTs -- SLHC version.
1522 
1523 
1524 // --------------------------------------------------------------------------
1525 // Auxiliary code.
1526 // --------------------------------------------------------------------------
1527 // Dump of configuration parameters.
1529  std::ostringstream strm;
1530  strm << "\n";
1531  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1532  strm << "+ CLCT configuration parameters: +\n";
1533  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1534  strm << " fifo_tbins [total number of time bins in DAQ readout] = "
1535  << fifo_tbins << "\n";
1536  strm << " fifo_pretrig [start time of cathode raw hits in DAQ readout] = "
1537  << fifo_pretrig << "\n";
1538  strm << " hit_persist [duration of signal pulse, in 25 ns bins] = "
1539  << hit_persist << "\n";
1540  strm << " drift_delay [time after pre-trigger before TMB latches LCTs] = "
1541  << drift_delay << "\n";
1542  strm << " nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = "
1543  << nplanes_hit_pretrig << "\n";
1544  strm << " nplanes_hit_pattern [min. number of layers hit for trigger] = "
1545  << nplanes_hit_pattern << "\n";
1546  strm << " pid_thresh_pretrig [lower threshold on pattern id] = "
1547  << pid_thresh_pretrig << "\n";
1548  strm << " min_separation [region of busy key strips] = "
1549  << min_separation << "\n";
1550  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
1551  LogDebug("CSCCathodeLCTProcessor") << strm.str();
1552  //std::cerr<<strm.str()<<std::endl;
1553 }
1554 
1555 // Reasonably nice dump of digis on half-strips and di-strips.
1556 void CSCCathodeLCTProcessor::dumpDigis(const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const int stripType, const int nStrips) const
1557 {
1558  LogDebug("CSCCathodeLCTProcessor")
1560  << " strip type " << stripType << " nStrips " << nStrips;
1561 
1562  std::ostringstream strstrm;
1563  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
1564  if (i_strip%10 == 0) {
1565  if (i_strip < 100) strstrm << i_strip/10;
1566  else strstrm << (i_strip-100)/10;
1567  }
1568  else strstrm << " ";
1569  if ((i_strip+1)%cfeb_strips[stripType] == 0) strstrm << " ";
1570  }
1571  strstrm << "\n";
1572  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
1573  strstrm << i_strip%10;
1574  if ((i_strip+1)%cfeb_strips[stripType] == 0) strstrm << " ";
1575  }
1576  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
1577  strstrm << "\n";
1578  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
1579  if (!strip[i_layer][i_strip].empty()) {
1580  std::vector<int> bx_times = strip[i_layer][i_strip];
1581  // Dump only the first in time.
1582  strstrm << std::hex << bx_times[0] << std::dec;
1583  }
1584  else {
1585  strstrm << "-";
1586  }
1587  if ((i_strip+1)%cfeb_strips[stripType] == 0) strstrm << " ";
1588  }
1589  }
1590  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
1591 }
1592 
1593 // Returns vector of read-out CLCTs, if any. Starts with the vector
1594 // of all found CLCTs and selects the ones in the read-out time window.
1595 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::readoutCLCTs() {
1596  std::vector<CSCCLCTDigi> tmpV;
1597 
1598  // The start time of the L1A*CLCT coincidence window should be
1599  // related to the fifo_pretrig parameter, but I am not completely
1600  // sure how. For now, just choose it such that the window is
1601  // centered at bx=7. This may need further tweaking if the value of
1602  // tmb_l1a_window_size changes.
1603 
1604  // The number of CLCT bins in the read-out is given by the
1605  // tmb_l1a_window_size parameter, but made even by setting the LSB
1606  // of tmb_l1a_window_size to 0.
1607  //
1608  static std::atomic<int> lct_bins;
1610  static std::atomic<int> late_tbins;
1611  late_tbins = early_tbins + lct_bins;
1612 
1613  static std::atomic<int> ifois{0};
1614  if (ifois == 0) {
1615  if (infoV >= 0 && early_tbins < 0) {
1616  edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
1617  << "+++ early_tbins = " << early_tbins
1618  << "; in-time CLCTs are not getting read-out!!! +++" << "\n";
1619  }
1620 
1621  if (late_tbins > CSCConstants::MAX_CLCT_TBINS-1) {
1622  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
1623  << "+++ Allowed range of time bins, [0-" << late_tbins
1624  << "] exceeds max allowed, " << CSCConstants::MAX_CLCT_TBINS-1 << " +++\n"
1625  << "+++ Set late_tbins to max allowed +++\n";
1626  late_tbins = CSCConstants::MAX_CLCT_TBINS-1;
1627  }
1628  ifois = 1;
1629  }
1630 
1631  // Start from the vector of all found CLCTs and select those within
1632  // the CLCT*L1A coincidence window.
1633  int bx_readout = -1;
1634  std::vector<CSCCLCTDigi> all_lcts = getCLCTs();
1635  for (std::vector <CSCCLCTDigi>::const_iterator plct = all_lcts.begin();
1636  plct != all_lcts.end(); plct++) {
1637  if (!plct->isValid()) continue;
1638 
1639  int bx = (*plct).getBX();
1640  // Skip CLCTs found too early relative to L1Accept.
1641  if (bx <= early_tbins) {
1642  if (infoV > 1) LogDebug("CSCCathodeLCTProcessor")
1643  << " Do not report CLCT on key halfstrip " << plct->getKeyStrip()
1644  << ": found at bx " << bx << ", whereas the earliest allowed bx is "
1645  << early_tbins+1;
1646  continue;
1647  }
1648 
1649  // Skip CLCTs found too late relative to L1Accept.
1650  if (bx > late_tbins) {
1651  if (infoV > 1) LogDebug("CSCCathodeLCTProcessor")
1652  << " Do not report CLCT on key halfstrip " << plct->getKeyStrip()
1653  << ": found at bx " << bx << ", whereas the latest allowed bx is "
1654  << late_tbins;
1655  continue;
1656  }
1657 
1658  // If (readout_earliest_2) take only CLCTs in the earliest bx in the read-out window:
1659  // in digi->raw step, LCTs have to be packed into the TMB header, and
1660  // currently there is room just for two.
1661  if (readout_earliest_2) {
1662  if (bx_readout == -1 || bx == bx_readout) {
1663  tmpV.push_back(*plct);
1664  if (bx_readout == -1) bx_readout = bx;
1665  }
1666  }
1667  else tmpV.push_back(*plct);
1668  }
1669  return tmpV;
1670 }
1671 
1672 // Returns vector of all found CLCTs, if any. Used for ALCT-CLCT matching.
1673 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::getCLCTs() {
1674  std::vector<CSCCLCTDigi> tmpV;
1675  for (int bx = 0; bx < CSCConstants::MAX_CLCT_TBINS; bx++) {
1676  if (bestCLCT[bx].isValid()) tmpV.push_back(bestCLCT[bx]);
1677  if (secondCLCT[bx].isValid()) tmpV.push_back(secondCLCT[bx]);
1678  }
1679  return tmpV;
1680 }
1681 
1682 
1683 
1685  // test to make sure what goes into an LCT is what comes out.
1686  for (int ptn = 0; ptn < 8; ptn++) {
1687  for (int bend = 0; bend < 2; bend++) {
1688  for (int cfeb = 0; cfeb < CSCConstants::MAX_CFEBS; cfeb++) {
1689  for (int key_strip = 0; key_strip < CSCConstants::NUM_HALF_STRIPS_PER_CFEB; key_strip++) {
1690  for (int bx = 0; bx < 7; bx++) {
1691  for (int stripType = 0; stripType < 2; stripType++) {
1692  for (int quality = 3; quality < 6; quality++) {
1693  CSCCLCTDigi thisLCT(1, quality, ptn, stripType, bend,
1694  key_strip, cfeb, bx);
1695  if (ptn != thisLCT.getPattern())
1696  LogTrace("CSCCathodeLCTProcessor")
1697  << "pattern mismatch: " << ptn << " "
1698  << thisLCT.getPattern();
1699  if (bend != thisLCT.getBend())
1700  LogTrace("CSCCathodeLCTProcessor")
1701  << "bend mismatch: " << bend << " " << thisLCT.getBend();
1702  if (cfeb != thisLCT.getCFEB())
1703  LogTrace("CSCCathodeLCTProcessor")
1704  << "cfeb mismatch: " << cfeb << " " << thisLCT.getCFEB();
1705  if (key_strip != thisLCT.getKeyStrip())
1706  LogTrace("CSCCathodeLCTProcessor")
1707  << "strip mismatch: " << key_strip << " "
1708  << thisLCT.getKeyStrip();
1709  if (bx != thisLCT.getBX())
1710  LogTrace("CSCCathodeLCTProcessor")
1711  << "bx mismatch: " << bx << " " << thisLCT.getBX();
1712  if (stripType != thisLCT.getStripType())
1713  LogTrace("CSCCathodeLCTProcessor")
1714  << "Strip Type mismatch: " << stripType << " "
1715  << thisLCT.getStripType();
1716  if (quality != thisLCT.getQuality())
1717  LogTrace("CSCCathodeLCTProcessor")
1718  << "quality mismatch: " << quality << " "
1719  << thisLCT.getQuality();
1720  }
1721  }
1722  }
1723  }
1724  }
1725  }
1726  }
1727 }
#define LogDebug(id)
int getQuality() const
return quality of a pattern (number of layers hit!)
Definition: CSCCLCTDigi.h:36
static const unsigned int def_drift_delay
T getParameter(std::string const &) const
CSCCLCTDigi bestCLCT[CSCConstants::MAX_CLCT_TBINS]
std::vector< CSCCLCTDigi > readoutCLCTs()
static const unsigned int def_fifo_tbins
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
bool ispretrig[CSCConstants::NUM_HALF_STRIPS_7CFEBS]
static const int cfeb_strips[2]
unsigned int clctHitPersist() const
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
int first_bx_corrected[CSCConstants::NUM_HALF_STRIPS_7CFEBS]
unsigned int clctNplanesHitPattern() const
static const int pattern2007_offset[CSCConstants::MAX_HALFSTRIPS_IN_PATTERN]
static const unsigned int def_min_separation
unsigned int clctMinSeparation() const
unsigned int clctNplanesHitPretrig() const
static const unsigned int def_nplanes_hit_pretrig
static int ringFromTriggerLabels(int station, int triggerCSCID)
bool preTrigger(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const int start_bx, int &first_bx)
int getStripType() const
return striptype
Definition: CSCCLCTDigi.h:48
unsigned int clctDriftDelay() const
int getBend() const
return bend
Definition: CSCCLCTDigi.h:54
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])
unsigned int clctPidThreshPretrig() const
void readComparatorDigis(std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
void dumpDigis(const std::vector< int > strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const int stripType, const int nStrips) const
int getCFEB() const
return Key CFEB ID
Definition: CSCCLCTDigi.h:66
static const int pattern2007[CSCConstants::NUM_CLCT_PATTERNS][CSCConstants::MAX_HALFSTRIPS_IN_PATTERN+2]
static const unsigned int def_tmb_l1a_window_size
int getBX() const
return BX
Definition: CSCCLCTDigi.h:72
bool getDigis(const CSCComparatorDigiCollection *compdc)
static const unsigned int def_nplanes_hit_pattern
unsigned int clctFifoPretrig() const
#define LogTrace(id)
std::vector< CSCCLCTPreTriggerDigi > thePreTriggerDigis
bool ptnFinding(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const int nStrips, const unsigned int bx_time)
std::string chamberName() const
Definition: CSCDetId.cc:71
double pulse(double x, double y, double z, double t)
static const unsigned int def_fifo_pretrig
int getPattern() const
return pattern
Definition: CSCCLCTDigi.h:42
std::vector< int > thePreTriggerBXs
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:133
static const unsigned int def_hit_persist
int stagger[CSCConstants::NUM_LAYERS]
std::vector< CSCComparatorDigi >::const_iterator const_iterator
void setFullBX(const uint16_t fullbx)
Set 12-bit full BX.
Definition: CSCCLCTDigi.h:101
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:58
std::vector< CSCComparatorDigi > digiV[CSCConstants::NUM_LAYERS]
std::pair< const_iterator, const_iterator > Range
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])
int getKeyStrip() const
Definition: CSCCLCTDigi.h:89
std::vector< CSCCLCTDigi > findLCTsSLHC(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
static int chamberFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station, int TriggerCSCID)
std::vector< CSCCLCTDigi > getCLCTs()
void setConfigParameters(const CSCDBL1TPParameters *conf)
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting CLCTs.
Definition: CSCCLCTDigi.h:95