CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // and distrip 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 
30 
32 #include <algorithm>
33 #include <iomanip>
34 #include <iostream>
35 #include <set>
36 
37 //-----------------
38 // Static variables
39 //-----------------
40 
41 // This is the strip pattern that we use for pretrigger.
42 // pre_hit_pattern[0][i] = layer. pre_hit_pattern[1][i] = key_strip offset.
43 const int CSCCathodeLCTProcessor::pre_hit_pattern[2][NUM_PATTERN_STRIPS] = {
44  { 999, 0, 0, 0, 999,
45  999, 1, 1, 1, 999,
46  999, 2, 2, 2, 999,
47  3, // layer
48  999, 4, 4, 4, 999,
49  999, 5, 5, 5, 999},
50  //-------------------------------------------
51  { 999, -1, 0, 1, 999,
52  999, -1, 0, 1, 999,
53  999, -1, 0, 1, 999,
54  0, // offset
55  999, -1, 0, 1, 999,
56  999, -1, 0, 1, 999}
57 };
58 
59 // The old set of half-strip/di-strip patterns used prior to 2007.
60 // For the given pattern, set the unused parts of the pattern to 999.
61 // Pattern[i][NUM_PATTERN_STRIPS] contains pt bend value. JM
62 // bend of 0 is left/straight and bend of 1 is right bht 21 June 2001
63 // note that the left/right-ness of this is exactly opposite of what one would
64 // expect naively (at least it was for me). The only way to make sure you've
65 // got the patterns you want is to use the printPatterns() method to dump
66 // them. BHT 21 June 2001
68  { 999, 999, 999, 999, 999,
69  999, 999, 999, 999, 999,
70  999, 999, 999, 999, 999,
71  999, // dummy (reserved)
72  999, 999, 999, 999, 999,
73  999, 999, 999, 999, 999, 0},
74  //-------------------------------------------------------------
75  { 999, 999, 999, 0, 999,
76  999, 999, 999, 1, 999,
77  999, 999, 2, 2, 999,
78  3, // right bending pattern (large)
79  999, 4, 4, 999, 999,
80  999, 5, 999, 999, 999, 1},
81  //-------------------------------------------------------------
82  { 999, 0, 999, 999, 999,
83  999, 1, 999, 999, 999,
84  999, 2, 2, 999, 999,
85  3, // left bending pattern (large)
86  999, 999, 4, 4, 999,
87  999, 999, 999, 5, 999, 0},
88  //-------------------------------------------------------------
89  { 999, 999, 0, 999, 999,
90  999, 999, 1, 999, 999,
91  999, 999, 2, 999, 999,
92  3, // right bending pattern (medium)
93  999, 4, 999, 999, 999,
94  999, 5, 999, 999, 999, 1},
95  //-------------------------------------------------------------
96  { 999, 999, 0, 999, 999,
97  999, 999, 1, 999, 999,
98  999, 999, 2, 999, 999,
99  3, // left bending pattern (medium)
100  999, 999, 999, 4, 999,
101  999, 999, 999, 5, 999, 0},
102  //-------------------------------------------------------------
103  { 999, 999, 999, 0, 999,
104  999, 999, 999, 1, 999,
105  999, 999, 2, 2, 999,
106  3, // right bending pattern (small)
107  999, 999, 4, 999, 999,
108  999, 999, 5, 999, 999, 1},
109  //-------------------------------------------------------------
110  { 999, 0, 999, 999, 999,
111  999, 1, 999, 999, 999,
112  999, 2, 2, 999, 999,
113  3, // left bending pattern (small)
114  999, 999, 4, 999, 999,
115  999, 999, 5, 999, 999, 0},
116  //-------------------------------------------------------------
117  { 999, 999, 0, 999, 999,
118  999, 999, 1, 999, 999,
119  999, 999, 2, 999, 999,
120  3, // straight through pattern
121  999, 999, 4, 999, 999,
122  999, 999, 5, 999, 999, 1}
123 };
124 
125 // New set of halfstrip patterns for 2007 version of the algorithm.
126 // For the given pattern, set the unused parts of the pattern to 999.
127 // Pattern[i][NUM_PATTERN_HALFSTRIPS] contains bend direction.
128 // Bend of 0 is right/straight and bend of 1 is left.
129 // Pattern[i][NUM_PATTERN_HALFSTRIPS+1] contains pattern maximum width
130 const int CSCCathodeLCTProcessor::pattern2007_offset[NUM_PATTERN_HALFSTRIPS] =
131  { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5,
132  -2, -1, 0, 1, 2,
133  0,
134  -2, -1, 0, 1, 2,
135  -4, -3, -2, -1, 0, 1, 2, 3, 4,
136  -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 };
137 
138 const int CSCCathodeLCTProcessor::pattern2007[CSCConstants::NUM_CLCT_PATTERNS][NUM_PATTERN_HALFSTRIPS+2] = {
139  { 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999,
140  999, 999, 999, 999, 999,
141  999, // pid=0: no pattern found
142  999, 999, 999, 999, 999,
143  999, 999, 999, 999, 999, 999, 999, 999, 999,
144  999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, -1, 0},
145  //-------------------------------------------------------------
146  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
147  1, 1, 1, 1, 1,
148  2, // pid=1: layer-OR trigger
149  3, 3, 3, 3, 3,
150  4, 4, 4, 4, 4, 4, 4, 4, 4,
151  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, -1, 11},
152  //-------------------------------------------------------------
153  { 999, 999, 999, 999, 999, 999, 999, 999, 0, 0, 0,
154  999, 999, 999, 1, 1,
155  2, // pid=2: right-bending (large)
156  3, 3, 3, 999, 999,
157  4, 4, 4, 999, 999, 999, 999, 999, 999,
158  5, 5, 5, 999, 999, 999, 999, 999, 999, 999, 999, 0, 11},
159  //-------------------------------------------------------------
160  { 0, 0, 0, 999, 999, 999, 999, 999, 999, 999, 999,
161  1, 1, 999, 999, 999,
162  2, // pid=3: left-bending (large)
163  999, 999, 3, 3, 3,
164  999, 999, 999, 999, 999, 999, 4, 4, 4,
165  999, 999, 999, 999, 999, 999, 999, 999, 5, 5, 5, 1, 11},
166  //-------------------------------------------------------------
167  { 999, 999, 999, 999, 999, 999, 999, 0, 0, 0, 999,
168  999, 999, 999, 1, 1,
169  2, // pid=4: right-bending (medium)
170  3, 3, 999, 999, 999,
171  4, 4, 4, 999, 999, 999, 999, 999, 999,
172  999, 5, 5, 5, 999, 999, 999, 999, 999, 999, 999, 0, 9},
173  //-------------------------------------------------------------
174  { 999, 0, 0, 0, 999, 999, 999, 999, 999, 999, 999,
175  1, 1, 999, 999, 999,
176  2, // pid=5: left-bending (medium)
177  999, 999, 999, 3, 3,
178  999, 999, 999, 999, 999, 999, 4, 4, 4,
179  999, 999, 999, 999, 999, 999, 999, 5, 5, 5, 999, 1, 9},
180  //-------------------------------------------------------------
181  { 999, 999, 999, 999, 999, 999, 0, 0, 0, 999, 999,
182  999, 999, 1, 1, 999,
183  2, // pid=6: right-bending (medium)
184  999, 3, 3, 999, 999,
185  999, 999, 4, 4, 999, 999, 999, 999, 999,
186  999, 999, 5, 5, 5, 999, 999, 999, 999, 999, 999, 0, 7},
187  //-------------------------------------------------------------
188  { 999, 999, 0, 0, 0, 999, 999, 999, 999, 999, 999,
189  999, 1, 1, 999, 999,
190  2, // pid=7: left-bending (medium)
191  999, 999, 3, 3, 999,
192  999, 999, 999, 999, 999, 4, 4, 999, 999,
193  999, 999, 999, 999, 999, 999, 5, 5, 5, 999, 999, 1, 7},
194  //-------------------------------------------------------------
195  { 999, 999, 999, 999, 999, 0, 0, 0, 999, 999, 999,
196  999, 999, 1, 1, 999,
197  2, // pid=8: right-bending (small)
198  999, 3, 3, 999, 999,
199  999, 999, 4, 4, 4, 999, 999, 999, 999,
200  999, 999, 999, 5, 5, 5, 999, 999, 999, 999, 999, 0, 5},
201  //-------------------------------------------------------------
202  { 999, 999, 999, 0, 0, 0, 999, 999, 999, 999, 999,
203  999, 1, 1, 999, 999,
204  2, // pid=9: left-bending (small)
205  999, 999, 3, 3, 999,
206  999, 999, 999, 999, 4, 4, 4, 999, 999,
207  999, 999, 999, 999, 999, 5, 5, 5, 999, 999, 999, 1, 5},
208  //-------------------------------------------------------------
209  { 999, 999, 999, 999, 0, 0, 0, 999, 999, 999, 999,
210  999, 999, 1, 999, 999,
211  2, // pid=A: straight-through
212  999, 999, 3, 999, 999,
213  999, 999, 999, 4, 4, 4, 999, 999, 999,
214  999, 999, 999, 999, 5, 5, 5, 999, 999, 999, 999, 0, 3}
215  // pid's=B-F are not yet defined
216 };
217 
218 // Default values of configuration parameters.
219 const unsigned int CSCCathodeLCTProcessor::def_fifo_tbins = 12;
220 const unsigned int CSCCathodeLCTProcessor::def_fifo_pretrig = 7;
221 const unsigned int CSCCathodeLCTProcessor::def_hit_persist = 6;
222 const unsigned int CSCCathodeLCTProcessor::def_drift_delay = 2;
226 const unsigned int CSCCathodeLCTProcessor::def_min_separation = 10;
228 
229 // Number of di-strips/half-strips per CFEB.
230 const int CSCCathodeLCTProcessor::cfeb_strips[2] = { 8, 32};
231 
232 //----------------
233 // Constructors --
234 //----------------
235 
237  unsigned station,
238  unsigned sector,
239  unsigned subsector,
240  unsigned chamber,
241  const edm::ParameterSet& conf,
242  const edm::ParameterSet& comm,
243  const edm::ParameterSet& ctmb) :
244  theEndcap(endcap), theStation(station), theSector(sector),
245  theSubsector(subsector), theTrigChamber(chamber) {
246  static std::atomic<bool> config_dumped{false};
247 
248  // CLCT configuration parameters.
249  fifo_tbins = conf.getParameter<unsigned int>("clctFifoTbins");
250  hit_persist = conf.getParameter<unsigned int>("clctHitPersist");
251  drift_delay = conf.getParameter<unsigned int>("clctDriftDelay");
253  conf.getParameter<unsigned int>("clctNplanesHitPretrig");
255  conf.getParameter<unsigned int>("clctNplanesHitPattern");
256 
257  // Not used yet.
258  fifo_pretrig = conf.getParameter<unsigned int>("clctFifoPretrig");
259 
260  // Defines pre-2007 version of the CLCT algorithm used in test beams and
261  // MTCC.
262  isMTCC = comm.getParameter<bool>("isMTCC");
263 
264  // TMB07 firmware used since 2007: switch and config. parameters.
265  isTMB07 = comm.getParameter<bool>("isTMB07");
266 
267  // Flag for SLHC studies
268  isSLHC = comm.getUntrackedParameter<bool>("isSLHC",false);
269 
270  // special configuration parameters for ME11 treatment
271  smartME1aME1b = comm.getUntrackedParameter<bool>("smartME1aME1b",false);
272  disableME1a = comm.getUntrackedParameter<bool>("disableME1a",false);
273  gangedME1a = comm.getUntrackedParameter<bool>("gangedME1a",true);
274 
275  if (isSLHC && !smartME1aME1b) edm::LogError("L1CSCTPEmulatorConfigError")
276  << "+++ SLHC upgrade configuration is used (isSLHC=True) but smartME1aME1b=False!\n"
277  << "Only smartME1aME1b algorithm is so far supported for upgrade! +++\n";
278 
279  if (isTMB07) {
281  conf.getParameter<unsigned int>("clctPidThreshPretrig");
283  conf.getParameter<unsigned int>("clctMinSeparation");
284 
285  start_bx_shift = conf.getUntrackedParameter<int>("clctStartBxShift",0);
286  }
287 
288  if (smartME1aME1b) {
289  // use of localized dead-time zones
291  conf.getUntrackedParameter<bool>("useDeadTimeZoning",true);
293  conf.getUntrackedParameter<unsigned int>("clctStateMachineZone",8);
295  conf.getUntrackedParameter<bool>("useDynamicStateMachineZone",true);
296 
297  // how far away may trigger happen from pretrigger
299  conf.getUntrackedParameter<unsigned int>("clctPretriggerTriggerZone",5);
300 
301  // whether to calculate bx as corrected_bx instead of pretrigger one
302  use_corrected_bx = conf.getUntrackedParameter<bool>("clctUseCorrectedBx",false);
303  }
304 
305  // Motherboard parameters: common for all configurations.
306  tmb_l1a_window_size = // Common to CLCT and TMB
307  ctmb.getParameter<unsigned int>("tmbL1aWindowSize");
308 
309  // separate handle for early time bins
310  early_tbins = ctmb.getUntrackedParameter<int>("tmbEarlyTbins",-1);
311  static int fpga_latency = 3;
312  if (early_tbins<0) early_tbins = fifo_pretrig - fpga_latency;
313 
314  // wether to readout only the earliest two LCTs in readout window
315  readout_earliest_2 = ctmb.getUntrackedParameter<bool>("tmbReadoutEarliest2",0);
316 
317  // Verbosity level, set to 0 (no print) by default.
318  infoV = conf.getUntrackedParameter<int>("verbosity", 0);
319 
320  // Check and print configuration parameters.
322  if ((infoV > 0 || isSLHC) && !config_dumped) {
323  //std::cerr<<"**** CLCT constructor parameters dump ****"<<std::endl;
325  config_dumped = true;
326  }
327 
328  numStrips = 0; // Will be set later.
329  // Provisional, but should be OK for all stations except ME1.
330  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
331  if ((i_layer+1)%2 == 0) stagger[i_layer] = 0;
332  else stagger[i_layer] = 1;
333  }
334 
336 
339 
340  // trigger numbering doesn't distinguish between ME1a and ME1b chambers:
341  isME11 = (theStation == 1 && theRing == 1);
342 
343  //if (theStation==1 && theRing==2) infoV = 3;
344 
346  //if (theStation == 2 && theSector == 1 &&
347  // theRing == 1 &&
348  // theChamber == 1) {
350  // testPatterns();
352  // testLCTs();
354  // printPatterns();
355  //}
356 }
357 
359  theEndcap(1), theStation(1), theSector(1),
360  theSubsector(1), theTrigChamber(1) {
361  // constructor for debugging.
362  static std::atomic<bool> config_dumped{false};
363 
364  // CLCT configuration parameters.
366  infoV = 2;
367  isMTCC = false;
368  isTMB07 = true;
369 
370  smartME1aME1b = false;
371  disableME1a = false;
372  gangedME1a = true;
373 
374  early_tbins = 4;
375 
376  start_bx_shift = 0;
379 
380  // Check and print configuration parameters.
382  if (!config_dumped) {
383  //std::cerr<<"**** CLCT default constructor parameters dump ****"<<std::endl;
385  config_dumped = true;
386  }
387 
389  // Should be OK for all stations except ME1.
390  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
391  if ((i_layer+1)%2 == 0) stagger[i_layer] = 0;
392  else stagger[i_layer] = 1;
393  }
394 
396  isME11 = (theStation == 1 && theRing == 1);
397 }
398 
400  // Set default values for configuration parameters.
407 
408  isMTCC = false;
409 
410  // New TMB07 parameters.
411  isTMB07 = true;
412  if (isTMB07) {
415  }
416 
418 }
419 
420 // Set configuration parameters obtained via EventSetup mechanism.
422  static std::atomic<bool> config_dumped{false};
423 
424  fifo_tbins = conf->clctFifoTbins();
425  fifo_pretrig = conf->clctFifoPretrig();
426  hit_persist = conf->clctHitPersist();
427  drift_delay = conf->clctDriftDelay();
430 
431  // TMB07 parameters.
432  if (isTMB07) {
435  }
436 
437  // Check and print configuration parameters.
439  if (!config_dumped) {
440  //std::cerr<<"**** CLCT setConfigParams parameters dump ****"<<std::endl;
442  config_dumped = true;
443  }
444 }
445 
447  // Make sure that the parameter values are within the allowed range.
448 
449  // Max expected values.
450  static const unsigned int max_fifo_tbins = 1 << 5;
451  static const unsigned int max_fifo_pretrig = 1 << 5;
452  static const unsigned int max_hit_persist = 1 << 4;
453  static const unsigned int max_drift_delay = 1 << 2;
454  static const unsigned int max_nplanes_hit_pretrig = 1 << 3;
455  static const unsigned int max_nplanes_hit_pattern = 1 << 3;
456  static const unsigned int max_pid_thresh_pretrig = 1 << 4;
457  static const unsigned int max_min_separation = CSCConstants::NUM_HALF_STRIPS;
458  static const unsigned int max_tmb_l1a_window_size = 1 << 4;
459 
460  // Checks.
461  if (fifo_tbins >= max_fifo_tbins) {
462  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
463  << "+++ Value of fifo_tbins, " << fifo_tbins
464  << ", exceeds max allowed, " << max_fifo_tbins-1 << " +++\n"
465  << "+++ Try to proceed with the default value, fifo_tbins="
466  << def_fifo_tbins << " +++\n";
468  }
469  if (fifo_pretrig >= max_fifo_pretrig) {
470  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
471  << "+++ Value of fifo_pretrig, " << fifo_pretrig
472  << ", exceeds max allowed, " << max_fifo_pretrig-1 << " +++\n"
473  << "+++ Try to proceed with the default value, fifo_pretrig="
474  << def_fifo_pretrig << " +++\n";
476  }
477  if (hit_persist >= max_hit_persist) {
478  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
479  << "+++ Value of hit_persist, " << hit_persist
480  << ", exceeds max allowed, " << max_hit_persist-1 << " +++\n"
481  << "+++ Try to proceed with the default value, hit_persist="
482  << def_hit_persist << " +++\n";
484  }
485  if (drift_delay >= max_drift_delay) {
486  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
487  << "+++ Value of drift_delay, " << drift_delay
488  << ", exceeds max allowed, " << max_drift_delay-1 << " +++\n"
489  << "+++ Try to proceed with the default value, drift_delay="
490  << def_drift_delay << " +++\n";
492  }
493  if (nplanes_hit_pretrig >= max_nplanes_hit_pretrig) {
494  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
495  << "+++ Value of nplanes_hit_pretrig, " << nplanes_hit_pretrig
496  << ", exceeds max allowed, " << max_nplanes_hit_pretrig-1 << " +++\n"
497  << "+++ Try to proceed with the default value, nplanes_hit_pretrig="
498  << def_nplanes_hit_pretrig << " +++\n";
500  }
501  if (nplanes_hit_pattern >= max_nplanes_hit_pattern) {
502  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
503  << "+++ Value of nplanes_hit_pattern, " << nplanes_hit_pattern
504  << ", exceeds max allowed, " << max_nplanes_hit_pattern-1 << " +++\n"
505  << "+++ Try to proceed with the default value, nplanes_hit_pattern="
506  << def_nplanes_hit_pattern << " +++\n";
508  }
509 
510  if (isTMB07) {
511  if (pid_thresh_pretrig >= max_pid_thresh_pretrig) {
512  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
513  << "+++ Value of pid_thresh_pretrig, " << pid_thresh_pretrig
514  << ", exceeds max allowed, " << max_pid_thresh_pretrig-1 << " +++\n"
515  << "+++ Try to proceed with the default value, pid_thresh_pretrig="
516  << def_pid_thresh_pretrig << " +++\n";
518  }
519  if (min_separation >= max_min_separation) {
520  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
521  << "+++ Value of min_separation, " << min_separation
522  << ", exceeds max allowed, " << max_min_separation-1 << " +++\n"
523  << "+++ Try to proceed with the default value, min_separation="
524  << def_min_separation << " +++\n";
526  }
527  }
528 
529  if (tmb_l1a_window_size >= max_tmb_l1a_window_size) {
530  if (infoV > 0) edm::LogError("L1CSCTPEmulatorConfigError")
531  << "+++ Value of tmb_l1a_window_size, " << tmb_l1a_window_size
532  << ", exceeds max allowed, " << max_tmb_l1a_window_size-1 << " +++\n"
533  << "+++ Try to proceed with the default value, tmb_l1a_window_size="
534  << def_tmb_l1a_window_size << " +++\n";
536  }
537 }
538 
540  thePreTriggerBXs.clear();
541  for (int bx = 0; bx < MAX_CLCT_BINS; bx++) {
542  bestCLCT[bx].clear();
543  secondCLCT[bx].clear();
544  }
545 }
546 
547 std::vector<CSCCLCTDigi>
549  // This is the version of the run() function that is called when running
550  // over the entire detector. It gets the comparator & timing info from the
551  // comparator digis and then passes them on to another run() function.
552 
553  // clear(); // redundant; called by L1MuCSCMotherboard.
554 
555  static std::atomic<bool> config_dumped{false};
556  if ((infoV > 0 || isSLHC) && !config_dumped) {
557  //std::cerr<<"**** CLCT run parameters dump ****"<<std::endl;
559  config_dumped = true;
560  }
561 
562  // Get the number of strips and stagger of layers for the given chamber.
563  // Do it only once per chamber.
564  if (numStrips == 0) {
566  CSCChamber* chamber = theGeom->chamber(theEndcap, theStation, theSector,
568  if (chamber) {
569  numStrips = chamber->layer(1)->geometry()->numberOfStrips();
570  // ME1/a is known to the readout hardware as strips 65-80 of ME1/1.
571  // Still need to decide whether we do any special adjustments to
572  // reconstruct LCTs in this region (3:1 ganged strips); for now, we
573  // simply allow for hits in ME1/a and apply standard reconstruction
574  // to them.
575  // For SLHC ME1/1 is set to have 4 CFEBs in ME1/b and 3 CFEBs in ME1/a
576  if (isME11) {
577  if (!smartME1aME1b && !disableME1a && theRing == 1 ) numStrips = 80;
578  if (!smartME1aME1b && disableME1a && theRing == 1 ) numStrips = 64;
579  if ( smartME1aME1b && !disableME1a && theRing == 1 ) numStrips = 64;
580  if ( smartME1aME1b && !disableME1a && theRing == 4 ) {
581  if (gangedME1a) numStrips = 16;
582  else numStrips = 48;
583  }
584  }
585 
587  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorSetupError")
588  << "+++ Number of strips, " << numStrips
589  << " found in ME" << ((theEndcap == 1) ? "+" : "-")
590  << theStation << "/" << theRing << "/" << theChamber
591  << " (sector " << theSector << " subsector " << theSubsector
592  << " trig id. " << theTrigChamber << ")"
593  << " exceeds max expected, " << CSCConstants::MAX_NUM_STRIPS
594  << " +++\n"
595  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
596  numStrips = -1;
597  }
598  // The strips for a given layer may be offset from the adjacent layers.
599  // This was done in order to improve resolution. We need to find the
600  // 'staggering' for each layer and make necessary conversions in our
601  // arrays. -JM
602  // In the TMB-07 firmware, half-strips in odd layers (layers are
603  // counted as ly0-ly5) are shifted by -1 half-strip, whereas in
604  // the previous firmware versions half-strips in even layers
605  // were shifted by +1 half-strip. This difference is due to a
606  // change from ly3 to ly2 in the choice of the key layer, and
607  // the intention to keep half-strips in the key layer unchanged.
608  // In the emulator, we use the old way for both cases, to avoid
609  // negative half-strip numbers. This will necessitate a
610  // subtraction of 1 half-strip for TMB-07 later on. -SV.
611  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
612  stagger[i_layer] =
613  (chamber->layer(i_layer+1)->geometry()->stagger() + 1) / 2;
614  }
615  }
616  else {
617  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
618  << " ME" << ((theEndcap == 1) ? "+" : "-")
619  << theStation << "/" << theRing << "/" << theChamber
620  << " (sector " << theSector << " subsector " << theSubsector
621  << " trig id. " << theTrigChamber << ")"
622  << " is not defined in current geometry! +++\n"
623  << "+++ CSC geometry looks garbled; no emulation possible +++\n";
624  numStrips = -1;
625  }
626  }
627 
628  if (numStrips < 0) {
629  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
630  << " ME" << ((theEndcap == 1) ? "+" : "-")
631  << theStation << "/" << theRing << "/" << theChamber
632  << " (sector " << theSector << " subsector " << theSubsector
633  << " trig id. " << theTrigChamber << "):"
634  << " numStrips = " << numStrips << "; CLCT emulation skipped! +++";
635  std::vector<CSCCLCTDigi> emptyV;
636  return emptyV;
637  }
638 
639  // Get comparator digis in this chamber.
640  bool noDigis = getDigis(compdc);
641 
642  if (!noDigis) {
643  // Get halfstrip (and possibly distrip) times from comparator digis.
644  std::vector<int>
646  std::vector<int>
648  if (isTMB07) { // TMB07 (latest) version: halfstrips only.
649  readComparatorDigis(halfstrip);
650  }
651  else { // Earlier versions: halfstrips and distrips.
652  readComparatorDigis(halfstrip, distrip);
653  }
654 
655  // Pass arrays of halfstrips and distrips on to another run() doing the
656  // LCT search.
657  // If the number of layers containing digis is smaller than that
658  // required to trigger, quit right away. (If LCT-based digi suppression
659  // is implemented one day, this condition will have to be changed
660  // to the number of planes required to pre-trigger.)
661  unsigned int layersHit = 0;
662  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
663  for (int i_hstrip = 0; i_hstrip < CSCConstants::NUM_HALF_STRIPS;
664  i_hstrip++) {
665  if (!halfstrip[i_layer][i_hstrip].empty()) {layersHit++; break;}
666  }
667  }
668  // Run the algorithm only if the probability for the pre-trigger
669  // to fire is not null. (Pre-trigger decisions are used for the
670  // strip read-out conditions in DigiToRaw.)
671  if (layersHit >= nplanes_hit_pretrig) run(halfstrip, distrip);
672  }
673 
674  // Return vector of CLCTs.
675  std::vector<CSCCLCTDigi> tmpV = getCLCTs();
676  return tmpV;
677 }
678 
680  const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
681  const std::vector<int> distrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]) {
682  // This version of the run() function can either be called in a standalone
683  // test, being passed the halfstrip and distrip times, or called by the
684  // run() function above. It uses the findLCTs() method to find vectors
685  // of LCT candidates. These candidates are sorted and the best two per bx
686  // are returned.
687  std::vector<CSCCLCTDigi> LCTlist;
688 
689  if (isTMB07) {
690  // Upgrade version for ME11 with better dead-time handling
691  if (isSLHC && smartME1aME1b && isME11 && use_dead_time_zoning) LCTlist = findLCTsSLHC(halfstrip);
692  // TMB07 version of the CLCT algorithm.
693  else LCTlist = findLCTs(halfstrip);
694  }
695  else if (isMTCC) { // MTCC version.
696  LCTlist = findLCTs(halfstrip, distrip);
697  }
698  else { // Idealized algorithm of many years ago.
699  std::vector<CSCCLCTDigi> halfStripLCTs = findLCTs(halfstrip, 1);
700  std::vector<CSCCLCTDigi> diStripLCTs = findLCTs(distrip, 0);
701  // Put all the candidates into a single vector and sort them.
702  for (unsigned int i = 0; i < halfStripLCTs.size(); i++)
703  LCTlist.push_back(halfStripLCTs[i]);
704  for (unsigned int i = 0; i < diStripLCTs.size(); i++)
705  LCTlist.push_back(diStripLCTs[i]);
706  }
707 
708  // LCT sorting.
709  if (LCTlist.size() > 1)
710  sort(LCTlist.begin(), LCTlist.end(), std::greater<CSCCLCTDigi>());
711 
712  // Take the best two candidates per bx.
713  for (std::vector<CSCCLCTDigi>::const_iterator plct = LCTlist.begin();
714  plct != LCTlist.end(); plct++) {
715  int bx = plct->getBX();
716  if (bx >= MAX_CLCT_BINS) {
717  if (infoV > 0) edm::LogWarning("L1CSCTPEmulatorOutOfTimeCLCT")
718  << "+++ Bx of CLCT candidate, " << bx << ", exceeds max allowed, "
719  << MAX_CLCT_BINS-1 << "; skipping it... +++\n";
720  continue;
721  }
722 
723  if (!bestCLCT[bx].isValid()) bestCLCT[bx] = *plct;
724  else if (!secondCLCT[bx].isValid()) {
725  // Ignore CLCT if it is the same as the best (i.e. if the same
726  // CLCT was found in both half- and di-strip pattern search).
727  // This can never happen in the test beam and MTCC
728  // implementations.
729  if (!isMTCC && !isTMB07 && *plct == bestCLCT[bx]) continue;
730  secondCLCT[bx] = *plct;
731  }
732  }
733 
734  for (int bx = 0; bx < MAX_CLCT_BINS; bx++) {
735  if (bestCLCT[bx].isValid()) {
736  bestCLCT[bx].setTrknmb(1);
737  if (infoV > 0) LogDebug("CSCCathodeLCTProcessor")
738  << bestCLCT[bx] << " found in ME" << ((theEndcap == 1) ? "+" : "-")
739  << theStation << "/" << theRing << "/" << theChamber
740  << " (sector " << theSector << " subsector " << theSubsector
741  << " trig id. " << theTrigChamber << ")" << "\n";
742  }
743  if (secondCLCT[bx].isValid()) {
744  secondCLCT[bx].setTrknmb(2);
745  if (infoV > 0) LogDebug("CSCCathodeLCTProcessor")
746  << secondCLCT[bx] << " found in ME" << ((theEndcap == 1) ? "+" : "-")
747  << theStation << "/" << theRing << "/" << theChamber
748  << " (sector " << theSector << " subsector " << theSubsector
749  << " trig id. " << theTrigChamber << ")" << "\n";
750  }
751  }
752  // Now that we have our best CLCTs, they get correlated with the best
753  // ALCTs and then get sent to the MotherBoard. -JM
754 }
755 
757  bool noDigis = true;
758 
759  // Loop over layers and save comparator digis on each one into digiV[layer].
760  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
761  digiV[i_layer].clear();
762 
764  getDigis(compdc, detid);
765 
766  // If this is ME1/1, fetch digis in corresponding ME1/A (ring=4) as well.
767  if (theStation == 1 && theRing == 1 && !disableME1a && !smartME1aME1b) {
768  CSCDetId detid_me1a(theEndcap, theStation, 4, theChamber, i_layer+1);
769  getDigis(compdc, detid_me1a);
770  }
771 
772  if (!digiV[i_layer].empty()) {
773  noDigis = false;
774  if (infoV > 1) {
775  LogTrace("CSCCathodeLCTProcessor")
776  << "found " << digiV[i_layer].size()
777  << " comparator digi(s) in layer " << i_layer << " of ME"
778  << ((theEndcap == 1) ? "+" : "-") << theStation << "/" << theRing
779  << "/" << theChamber << " (trig. sector " << theSector
780  << " subsector " << theSubsector << " id " << theTrigChamber << ")";
781  }
782  }
783  }
784 
785  return noDigis;
786 }
787 
789  const CSCDetId& id) {
790  bool me1a = (id.station() == 1) && (id.ring() == 4);
791  const CSCComparatorDigiCollection::Range rcompd = compdc->get(id);
792  for (CSCComparatorDigiCollection::const_iterator digiIt = rcompd.first;
793  digiIt != rcompd.second; ++digiIt) {
794  if (me1a && digiIt->getStrip() <= 16 && !disableME1a && !smartME1aME1b) {
795  // Move ME1/A comparators from CFEB=0 to CFEB=4 if this has not
796  // been done already.
797  CSCComparatorDigi digi_corr(digiIt->getStrip()+64,
798  digiIt->getComparator(),
799  digiIt->getTimeBinWord());
800  digiV[id.layer()-1].push_back(digi_corr);
801  }
802  else {
803  digiV[id.layer()-1].push_back(*digiIt);
804  }
805  }
806 }
807 
809  std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]) {
810  // Single-argument version for TMB07 (halfstrip-only) firmware.
811  // Takes the comparator & time info and stuffs it into halfstrip vector.
812  // Multiple hits on the same strip are allowed.
813 
814  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
815  int i_digi = 0; // digi counter, for dumps.
816  for (std::vector<CSCComparatorDigi>::iterator pld = digiV[i_layer].begin();
817  pld != digiV[i_layer].end(); pld++, i_digi++) {
818  // Dump raw digi info.
819  if (infoV > 1) {
820  std::ostringstream strstrm;
821  strstrm << "Comparator digi: comparator = " << pld->getComparator()
822  << " strip #" << pld->getStrip()
823  << " time bins on:";
824  std::vector<int> bx_times = pld->getTimeBinsOn();
825  for (unsigned int tbin = 0; tbin < bx_times.size(); tbin++)
826  strstrm << " " << bx_times[tbin];
827  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
828  }
829 
830  // Get comparator: 0/1 for left/right halfstrip for each comparator
831  // that fired.
832  int thisComparator = pld->getComparator();
833  if (thisComparator != 0 && thisComparator != 1) {
834  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
835  << "+++ Found comparator digi with wrong comparator value = "
836  << thisComparator << "; skipping it... +++\n";
837  continue;
838  }
839 
840  // Get strip number.
841  int thisStrip = pld->getStrip() - 1; // count from 0
842  if (thisStrip < 0 || thisStrip >= numStrips) {
843  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
844  << "+++ Found comparator digi with wrong strip number = "
845  << thisStrip
846  << " (max strips = " << numStrips << "); skipping it... +++\n";
847  continue;
848  }
849  // 2*strip: convert strip to 1/2 strip
850  // comp : comparator output
851  // stagger: stagger for this layer
852  int thisHalfstrip = 2*thisStrip + thisComparator + stagger[i_layer];
853  if (thisHalfstrip >= 2*numStrips + 1) {
854  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
855  << "+++ Found wrong halfstrip number = " << thisHalfstrip
856  << "; skipping this digi... +++\n";
857  continue;
858  }
859 
860  // Get bx times on this digi and check that they are within the bounds.
861  std::vector<int> bx_times = pld->getTimeBinsOn();
862  for (unsigned int i = 0; i < bx_times.size(); i++) {
863  // Total number of time bins in DAQ readout is given by fifo_tbins,
864  // which thus determines the maximum length of time interval.
865  //
866  // In TMB07 version, better data-emulator agreement is
867  // achieved when hits in the first 2 time bins are excluded.
868  // As of May 2009, the reasons for this are not fully
869  // understood yet (the work is on-going).
870  if (bx_times[i] > 1 && bx_times[i] < static_cast<int>(fifo_tbins)) {
871 
872  if (i == 0 || (i > 0 && bx_times[i]-bx_times[i-1] >=
873  static_cast<int>(hit_persist))) {
874  // A later hit on the same strip is ignored during the
875  // number of clocks defined by the "hit_persist" parameter
876  // (i.e., 6 bx's by default).
877  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
878  << "Comp digi: layer " << i_layer+1
879  << " digi #" << i_digi+1
880  << " strip " << thisStrip
881  << " halfstrip " << thisHalfstrip
882  << " distrip " << thisStrip/2 + // [0-39]
883  ((thisStrip%2 == 1 && thisComparator == 1 && stagger[i_layer] == 1) ? 1 : 0)
884  << " time " << bx_times[i]
885  << " comparator " << thisComparator
886  << " stagger " << stagger[i_layer];
887  halfstrip[i_layer][thisHalfstrip].push_back(bx_times[i]);
888  }
889  else if (i > 0) {
890  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
891  << " Skipping comparator digi: strip = " << thisStrip
892  << ", layer = " << i_layer+1 << ", bx = " << bx_times[i]
893  << ", bx of previous hit = " << bx_times[i-1];
894  }
895  }
896  else {
897  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
898  << "+++ Skipping comparator digi: strip = " << thisStrip
899  << ", layer = " << i_layer+1 << ", bx = " << bx_times[i] << " +++";
900  }
901  }
902  }
903  }
904 }
905 
907  std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
908  std::vector<int> distrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]) {
909  // Two-argument version for pre-TMB07 (halfstrip and distrips) firmware.
910  // Takes the comparator & time info and stuffs it into halfstrip and (and
911  // possibly distrip) vector.
912 
916  for (int i = 0; i < CSCConstants::NUM_LAYERS; i++){
917  for (int j = 0; j < CSCConstants::MAX_NUM_STRIPS; j++) {
918  time[i][j] = -999;
919  comp[i][j] = 0;
920  digiNum[i][j] = -999;
921  }
922  }
923 
924  for (int i = 0; i < CSCConstants::NUM_LAYERS; i++) {
925  std::vector <CSCComparatorDigi> layerDigiV = digiV[i];
926  for (unsigned int j = 0; j < layerDigiV.size(); j++) {
927  // Get one digi at a time for the layer. -Jm
928  CSCComparatorDigi thisDigi = layerDigiV[j];
929 
930  // Dump raw digi info
931  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
932  << "Comparator digi: comparator = " << thisDigi.getComparator()
933  << " strip #" << thisDigi.getStrip()
934  << " time bin = " << thisDigi.getTimeBin();
935 
936  // Get comparator: 0/1 for left/right halfstrip for each comparator
937  // that fired.
938  int thisComparator = thisDigi.getComparator();
939  if (thisComparator != 0 && thisComparator != 1) {
940  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
941  << "+++ Comparator digi with wrong comparator value: digi #" << j
942  << ", comparator = " << thisComparator << "; skipping it... +++\n";
943  continue;
944  }
945 
946  // Get strip number.
947  int thisStrip = thisDigi.getStrip() - 1; // count from 0
948  if (thisStrip < 0 || thisStrip >= numStrips) {
949  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
950  << "+++ Comparator digi with wrong strip number: digi #" << j
951  << ", strip = " << thisStrip
952  << ", max strips = " << numStrips << "; skipping it... +++\n";
953  continue;
954  }
955 
956  // Get Bx of this Digi and check that it is within the bounds
957  int thisDigiBx = thisDigi.getTimeBin();
958 
959  // Total number of time bins in DAQ readout is given by fifo_tbins,
960  // which thus determines the maximum length of time interval.
961  if (thisDigiBx >= 0 && thisDigiBx < static_cast<int>(fifo_tbins)) {
962 
963  // If there is more than one hit in the same strip, pick one
964  // which occurred earlier.
965  // In reality, the second hit on the same distrip is ignored only
966  // during the number of clocks defined by the "hit_persist"
967  // parameter (i.e., 6 bx's by default). So if one simulates
968  // a large number of bx's in a crowded environment, this
969  // approximation here may not be sufficiently good.
970  if (time[i][thisStrip] == -999 || time[i][thisStrip] > thisDigiBx) {
971  digiNum[i][thisStrip] = j;
972  time[i][thisStrip] = thisDigiBx;
973  comp[i][thisStrip] = thisComparator;
974  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
975  << "Comp digi: layer " << i+1
976  << " digi #" << j+1
977  << " strip " << thisStrip
978  << " halfstrip " << 2*thisStrip + comp[i][thisStrip] + stagger[i]
979  << " distrip " << thisStrip/2 + // [0-39]
980  ((thisStrip%2 == 1 && comp[i][thisStrip] == 1 && stagger[i] == 1) ? 1 : 0)
981  << " time " << time[i][thisStrip]
982  << " comparator " << comp[i][thisStrip]
983  << " stagger " << stagger[i];
984  }
985  }
986  else {
987  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
988  << "+++ Skipping comparator digi: strip = " << thisStrip
989  << ", layer = " << i+1 << ", bx = " << thisDigiBx << " +++";
990  }
991  }
992  }
993 
994  // Take the comparator & time info and stuff it into half- and di-strip
995  // arrays.
996  for (int i = 0; i < CSCConstants::NUM_LAYERS; i++) {
997  // Use the comparator info to setup the halfstrips and distrips. -BT
998  // This loop is only for halfstrips.
999  for (int j = 0; j < CSCConstants::MAX_NUM_STRIPS; j++) {
1000  if (time[i][j] >= 0) {
1001  int i_halfstrip = 2*j + comp[i][j] + stagger[i];
1002  // 2*j : convert strip to 1/2 strip
1003  // comp : comparator output
1004  // stagger: stagger for this layer
1005  if (i_halfstrip >= 2*numStrips + 1) {
1006  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
1007  << "+++ Found wrong halfstrip number = " << i_halfstrip
1008  << "; skipping this digi... +++\n";
1009  continue;
1010  }
1011  halfstrip[i][i_halfstrip].push_back(time[i][j]);
1012  }
1013  }
1014 
1015  // There are no di-strips in the 2007 version of the TMB firmware.
1016  if (!isTMB07) {
1017  // This loop is only for distrips. We have to separate the routines
1018  // because triad and time arrays can be changed by the distripStagger
1019  // routine which could mess up the halfstrips.
1020  static std::atomic<int> test_iteration{0};
1021  for (int j = 0; j < CSCConstants::MAX_NUM_STRIPS; j++){
1022  if (time[i][j] >= 0) {
1023  int i_distrip = j/2;
1024  if (j%2 == 1 && comp[i][j] == 1 && stagger[i] == 1) {
1025  // @@ Needs to be checked.
1026  bool stagger_debug = (infoV > 2);
1027  distripStagger(comp[i], time[i], digiNum[i], j, stagger_debug);
1028  }
1029  // comp[i][j] == 1 : hit on right half-strip.
1030  // stagger[i] == 1 : half-strips are shifted by 1.
1031  // if these conditions are met add 1; otherwise add 0.
1032  // So if there is a hit on the far right half-strip, and the
1033  // half-strips have been staggered to the right, then the di-strip
1034  // would actually correspond to the next highest di-strip. -JM
1035  if (infoV > 2 && test_iteration == 1) {
1037  test_iteration++;
1038  }
1039  if (i_distrip >= numStrips/2 + 1) {
1040  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
1041  << "+++ Found wrong distrip number = " << i_distrip
1042  << "; skipping this digi... +++\n";
1043  continue;
1044  }
1045  distrip[i][i_distrip].push_back(time[i][j]);
1046  }
1047  }
1048  }
1049  }
1050 }
1051 
1053  int stag_time[CSCConstants::MAX_NUM_STRIPS],
1054  int stag_digi[CSCConstants::MAX_NUM_STRIPS],
1055  int i_strip, bool debug) {
1056  // Author: Jason Mumford (mumford@physics.ucla.edu)
1057  // This routine takes care of the stagger situation where there is a hit
1058  // on the right half-strip of a di-strip. If there is a stagger, then
1059  // we must associate that distrip with the next distrip. The situation
1060  // gets more complicated if the next distrip also has a hit on its right
1061  // half-strip. One could imagine a whole chain of these in which case
1062  // we need to go into this routine recursively. The formula is that
1063  // while this condition is satisfied, we enquire the next distrip,
1064  // until we have a hit on any other halfstrip (or triad!=3). Then we
1065  // must compare the 2 different bx times and take the smallest one.
1066  // Afterwards, we must cycle out of the routine assigning the bx times
1067  // to the one strip over.
1068 
1069  // Used only for pre-TMB07 firmware.
1070 
1071  if (i_strip >= CSCConstants::MAX_NUM_STRIPS) {
1072  if (debug) edm::LogWarning("L1CSCTPEmulatorWrongInput")
1073  << "+++ Found wrong strip number = " << i_strip
1074  << "; cannot apply distrip staggering... +++\n";
1075  return;
1076  }
1077 
1078  if (debug)
1079  LogDebug("CSCCathodeLCTProcessor")
1080  << " Enter distripStagger: i_strip = " << i_strip
1081  << " stag_triad[i_strip] = " << stag_triad[i_strip]
1082  << " stag_time[i_strip] = " << stag_time[i_strip]
1083  << " stag_triad[i_strip+2] = " << stag_triad[i_strip+2]
1084  << " stag_time[i_strip+2] = " << stag_time[i_strip+2];
1085 
1086  // So if the next distrip has a stagger hit, go into the routine again
1087  // for the next distrip.
1088  if (i_strip+2 < CSCConstants::MAX_NUM_STRIPS && stag_triad[i_strip+2] == 1)
1089  distripStagger(stag_triad, stag_time, stag_digi, i_strip+2);
1090 
1091  // When we have reached a distrip that does not have a staggered hit,
1092  // if it has a hit, we compare the bx times of the
1093  // staggered distrip with the non-staggered distrip and we take the
1094  // smallest of the two and assign it to the shifted distrip time.
1095  if (stag_time[i_strip+2] >= 0) {
1096  if (stag_time[i_strip] < stag_time[i_strip+2]) {
1097  stag_time[i_strip+2] = stag_time[i_strip];
1098  stag_digi[i_strip+2] = stag_digi[i_strip];
1099  }
1100  }
1101  // If the next distrip did not have a hit, then we merely assign the
1102  // shifted time to the time associated with the staggered distrip.
1103  else {
1104  stag_time[i_strip+2] = stag_time[i_strip];
1105  stag_digi[i_strip+2] = stag_digi[i_strip];
1106  }
1107 
1108  // Then to prevent previous staggers from being overwritten, we assign
1109  // the unshifted time to -999, and then mark the triads that were shifted
1110  // so that we don't go into the routine ever again (such as when making
1111  // the next loop over strips).
1112  stag_time[i_strip] = -999;
1113  stag_triad[i_strip] = 4;
1114  stag_digi[i_strip] = -999;
1115 
1116  if (debug)
1117  LogDebug("CSCCathodeLCTProcessor")
1118  << " Exit distripStagger: i_strip = " << i_strip
1119  << " stag_triad[i_strip] = " << stag_triad[i_strip]
1120  << " stag_time[i_strip] = " << stag_time[i_strip]
1121  << " stag_triad[i_strip+2] = " << stag_triad[i_strip+2]
1122  << " stag_time[i_strip+2] = " << stag_time[i_strip+2];
1123 }
1124 
1125 // --------------------------------------------------------------------------
1126 // The code below is a description of the idealized CLCT algorithm which
1127 // was used in Monte Carlo studies since early ORCA days and until
1128 // CMSSW_2_0_0 (March 2008) but was never realized in the firmware.
1129 //
1130 // Starting with CMSSW_3_1_0, it may no longer give the same results as
1131 // before since old versions of overloaded < > == operators in CLCTDigi
1132 // class were discarded.
1133 // --------------------------------------------------------------------------
1134 // Idealized version for MC studies.
1135 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::findLCTs(const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], int stripType)
1136 {
1137  int j;
1138  int best_strip = 0;
1139  int first_bx = 999;
1140  const int max_lct_num = 2;
1141  const int adjacent_strips = 2;
1142  // Distrip, halfstrip pattern threshold.
1143  const unsigned int ptrn_thrsh[2] = {nplanes_hit_pattern, nplanes_hit_pattern};
1144  int highest_quality = 0;
1145 
1146  int keystrip_data[CSCConstants::NUM_HALF_STRIPS][7];
1147  int final_lcts[max_lct_num];
1148 
1149  std::vector <CSCCLCTDigi> lctList;
1150 
1151  int nStrips = 0;
1152  if (stripType == 1) nStrips = 2*numStrips + 1;
1153  else if (stripType == 0) nStrips = numStrips/2 + 1;
1154 
1155  if (infoV > 1) dumpDigis(strip, stripType, nStrips);
1156 
1157  // Send data to a pretrigger so that we don't excessively look at data
1158  // that won't give an LCT. If there is a pretrigger, then get all quality
1159  // and bend for all keystrips.
1160  if (preTrigger(strip, stripType, nStrips, first_bx)){
1161  getKeyStripData(strip, keystrip_data, nStrips, first_bx, best_strip, stripType);
1162 
1163  /* Set all final_lcts to impossible key_strip numbers */
1164  for (j = 0; j < max_lct_num; j++)
1165  final_lcts[j] = -999;
1166 
1167  // Now take the keystrip with the best quality, and do a search over the
1168  // rest of the strips for the next highest quality. Do the search over a
1169  // range excluding a certain number of keystrips adjacent to the original
1170  // best key_strip.
1171  final_lcts[0] = best_strip;
1172 
1173  for (int key_strip = 0; key_strip < (nStrips-stripType); key_strip++){
1174  // If indexed strip does not fall within excluded range, then continue
1175  if (abs(best_strip - key_strip) > adjacent_strips){
1176  // Match with highest quality
1177  if (keystrip_data[key_strip][CLCT_QUALITY] > highest_quality){
1178  highest_quality = keystrip_data[key_strip][CLCT_QUALITY];
1179  final_lcts[1] = key_strip;
1180  }
1181  }
1182  }
1183 
1184  for (j = 0; j < max_lct_num; j++){
1185  // Only report LCTs if the number of layers hit is greater than or
1186  // equal to the (variable) valid pattern threshold ptrn_thrsh.
1187  int keystrip = final_lcts[j];
1188  if (keystrip >= 0 &&
1189  keystrip_data[keystrip][CLCT_QUALITY] >= static_cast<int>(ptrn_thrsh[stripType])) {
1190  // assign the stripType here. 1 = halfstrip, 0 = distrip.
1191  keystrip_data[keystrip][CLCT_STRIP_TYPE] = stripType;
1192  // Now make the LCT words for the 2 highest, and store them in a list
1193  int theHalfStrip = (keystrip_data[keystrip][CLCT_STRIP_TYPE] ?
1194  keystrip_data[keystrip][CLCT_STRIP] :
1195  4*keystrip_data[keystrip][CLCT_STRIP]);
1196  keystrip_data[keystrip][CLCT_CFEB] = theHalfStrip/32;
1197  int halfstrip_in_cfeb =
1198  theHalfStrip - 32*keystrip_data[keystrip][CLCT_CFEB];
1199 
1200  CSCCLCTDigi thisLCT(1, keystrip_data[keystrip][CLCT_QUALITY],
1201  keystrip_data[keystrip][CLCT_PATTERN],
1202  keystrip_data[keystrip][CLCT_STRIP_TYPE],
1203  keystrip_data[keystrip][CLCT_BEND],
1204  halfstrip_in_cfeb,
1205  keystrip_data[keystrip][CLCT_CFEB],
1206  keystrip_data[keystrip][CLCT_BX]);
1207  if (infoV > 2) {
1208  char stripType =
1209  (keystrip_data[keystrip][CLCT_STRIP_TYPE] == 0) ? 'D' : 'H';
1210  char bend =
1211  (keystrip_data[keystrip][CLCT_BEND] == 0) ? 'L' : 'R';
1212  LogTrace("CSCCathodeLCTProcessor")
1213  << " Raw Find: "
1214  << "Key Strip: " << std::setw(3)
1215  << keystrip_data[keystrip][CLCT_STRIP]
1216  << " Pattern: " << std::setw(2)
1217  << keystrip_data[keystrip][CLCT_PATTERN]
1218  << " Bend: " << std::setw(1) << bend
1219  << " Quality: " << std::setw(1)
1220  << keystrip_data[keystrip][CLCT_QUALITY]
1221  << " stripType: " << std::setw(1) << stripType
1222  << " BX: " << std::setw(1)
1223  << keystrip_data[keystrip][CLCT_BX];
1224  }
1225  lctList.push_back(thisLCT);
1226  }
1227  }
1228  }
1229 
1230  return lctList;
1231 } // findLCTs -- idealized version for MC studies.
1232 
1233 
1234 // Idealized version for MC studies.
1236  const int stripType, const int nStrips,
1237  int& first_bx)
1238 {
1239  static const int hs_thresh = nplanes_hit_pretrig;
1240  static const int ds_thresh = nplanes_hit_pretrig;
1241 
1243  int i_layer, i_strip, this_layer, this_strip;
1244  int hits, layers_hit;
1245  bool hit_layer[CSCConstants::NUM_LAYERS];
1246 
1247  const int pre_trigger_layer_min = (stripType == 1) ? hs_thresh : ds_thresh;
1248 
1249  // Fire half-strip/di-strip one-shots for hit_persist bx's (6 bx's by
1250  // default).
1251  pulseExtension(strip, nStrips, pulse);
1252 
1253  // Now do a loop over different bunch-crossing times.
1254  for (unsigned int bx_time = 0; bx_time < fifo_tbins; bx_time++) {
1255  // For any given bunch-crossing, start at the lowest keystrip and look for
1256  // the number of separate layers in the pattern for that keystrip that have
1257  // pulses at that bunch-crossing time. Do the same for the next keystrip,
1258  // etc. Then do the entire process again for the next bunch-crossing, etc
1259  // until you find a pre-trigger.
1260  for (int key_strip = 0; key_strip < nStrips; key_strip++){
1261  // Clear variables
1262  hits = 0;
1263  layers_hit = 0;
1264  for (i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
1265  hit_layer[i_layer] = false;
1266  // Loop over pattern strips and look for hits.
1267  for (i_strip = 0; i_strip < NUM_PATTERN_STRIPS; i_strip++){
1268  this_layer = pre_hit_pattern[0][i_strip];
1269  this_strip = pre_hit_pattern[1][i_strip]+key_strip;
1270  if (this_strip >= 0 && this_strip < nStrips) {
1271  // Perform bit operation to see if pulse is 1 at a certain bx_time.
1272  if (((pulse[this_layer][this_strip] >> bx_time) & 1) == 1) {
1273  hits++;
1274  // Store number of layers hit.
1275  if (hit_layer[this_layer] == false) {
1276  hit_layer[this_layer] = true;
1277  layers_hit++;
1278 
1279  // Look if number of layers hit is greater or equal than some
1280  // pre-defined threshold.
1281  if (layers_hit >= pre_trigger_layer_min) {
1282  first_bx = bx_time;
1283  return true;
1284  }
1285  }
1286  }
1287  }
1288  }
1289  }
1290  }
1291  // If the pretrigger was never satisfied, then return false.
1292  return false;
1293 } // preTrigger -- idealized version for MC studies.
1294 
1295 
1296 // Idealized version for MC studies.
1298  int keystrip_data[CSCConstants::NUM_HALF_STRIPS][7],
1299  int nStrips, int first_bx, int& best_strip, int stripType) {
1300  int lct_pattern[NUM_PATTERN_STRIPS];
1301  int key_strip, this_layer, this_strip;
1302  int quality, best_quality;
1303  int bend = 0;
1304  int highest_quality = 0;
1305  bool nullPattern;
1306 
1307  for (key_strip = 0; key_strip < nStrips; key_strip++)
1308  for (int i = 0; i < 7; i++)
1309  keystrip_data[key_strip][i] = 0;
1310 
1311  // Now we need to look at all the keystrips and take the best pattern
1312  // for each. There are multiple patterns available for each keystrip.
1313 
1314  for (key_strip = 0; key_strip < (nStrips-stripType); key_strip++){
1315  nullPattern = true;
1316  for (int pattern_strip = 0; pattern_strip < NUM_PATTERN_STRIPS; pattern_strip++){
1317  this_layer = pre_hit_pattern[0][pattern_strip];
1318  this_strip = pre_hit_pattern[1][pattern_strip] + key_strip;
1319  // This conditional statement prevents us from looking at strips
1320  // that don't exist along the chamber boundaries.
1321  if ((this_strip >= 0 && this_strip < nStrips) &&
1322  !strip[this_layer][this_strip].empty()) {
1323  if (nullPattern) nullPattern = false;
1324  std::vector<int> bx_times = strip[this_layer][this_strip];
1325  lct_pattern[pattern_strip] = bx_times[0];
1326  }
1327  else
1328  lct_pattern[pattern_strip] = -999;
1329  }
1330  // do the rest only if there is at least one DIGI in the pattern for
1331  // this keystrip
1332  if (nullPattern) continue;
1333 
1334  // Initialize best_quality to zero so that we can look for best pattern
1335  // within a keystrip.
1336  best_quality = 0;
1337 
1338  // Loop over all possible patterns.
1339  // Loop in reverse order, in order to give priority to a straighter
1340  // pattern (larger pattern_num) in case of equal qualities.
1341  // Exclude pattern 0 since it is not defined.
1342  for (int pattern_num = CSCConstants::NUM_CLCT_PATTERNS_PRE_TMB07-1; pattern_num > 0; pattern_num--) {
1343  // Get the pattern quality from lct_pattern.
1344  // TMB latches LCTs drift_delay clocks after pretrigger.
1345  int latch_bx = first_bx + drift_delay;
1346  getPattern(pattern_num, lct_pattern, latch_bx, quality, bend);
1347  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1348  << "Key_strip " << key_strip << " quality of pattern_num "
1349  << pattern_num << ": " << quality;
1350  if (quality > best_quality){
1351  // Store the best pattern, quality, etc., for each key_strip.
1352  keystrip_data[key_strip][CLCT_PATTERN] = pattern_num;
1353  keystrip_data[key_strip][CLCT_BEND] = bend;
1354  keystrip_data[key_strip][CLCT_STRIP] = key_strip;
1355  keystrip_data[key_strip][CLCT_BX] = first_bx;
1356  // keystrip_data[key_strip][CLCT_STRIP_TYPE] = stripType; //assign the stripType elsewhere
1357  keystrip_data[key_strip][CLCT_QUALITY] = quality;
1358  if (quality > highest_quality){
1359  // Keep track of which strip had the highest quality.
1360  // highest_quality refers to the overall highest quality for all
1361  // key strips. This is different than best_quality which refers
1362  // to the best quality in a keystrip from different patterns.
1363  best_strip = key_strip;
1364  highest_quality = quality;
1365  }
1366  best_quality = quality;
1367  }
1368  }
1369  }
1370 } // getKeyStripData -- idealized version for MC studies.
1371 
1372 
1373 // Idealized version for MC studies.
1375  int strip_value[NUM_PATTERN_STRIPS], int bx_time,
1376  int& quality, int& bend){
1377  // This function takes strip values and bx_time to find out which hits fall
1378  // within a certain pattern. Quality, and bend are then calculated based on
1379  // which strip pattern and how many layers were hit within the pattern.
1380  int layers_hit = 0;
1381  bool hit_layer[CSCConstants::NUM_LAYERS];
1382 
1383  // Clear hit_layer array to keep track of number of layers hit.
1384  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
1385  hit_layer[i_layer] = false;
1386 
1387  // Loop over all designated patterns.
1388  for (int strip_num = 0; strip_num < NUM_PATTERN_STRIPS; strip_num++){
1389  if (hitIsGood(strip_value[strip_num], bx_time)){
1390  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++){
1391  // Loop over layer and see if corresponding strip is on same layer
1392  // If so then increment number of hits.
1393  if (i_layer == pattern[pattern_num][strip_num]){
1394  // If layer has no hits, then increment number of layers hit.
1395  if (hit_layer[i_layer] == false){
1396  layers_hit++;
1397  hit_layer[i_layer] = true;
1398  }
1399  }
1400  }
1401  }
1402  }
1403  // Get bend value from pattern.
1404  bend = pattern[pattern_num][NUM_PATTERN_STRIPS];
1405  quality = layers_hit;
1406 } // getPattern -- idealized version for MC studies.
1407 
1408 
1409 // Idealized version for MC studies.
1410 bool CSCCathodeLCTProcessor::hitIsGood(int hitTime, int BX) {
1411  // Find out if hit time is good. Hit should have occurred no more than
1412  // hit_persist clocks before the latching time.
1413  int dt = BX - hitTime;
1414  if (dt >= 0 && dt <= static_cast<int>(hit_persist)) {return true;}
1415  else {return false;}
1416 } // hitIsGood -- idealized version for MC studies.
1417 
1418 
1419 // --------------------------------------------------------------------------
1420 // The code below is a description of the pre-2007 version of the CLCT
1421 // algorithm. It was used in numerous CSC test beams and MTCC for
1422 // firmware-emulator comparisons, but due to a number of known limitations
1423 // it was never used in Monte Carlo studies.
1424 //
1425 // Starting with CMSSW_3_1_0, it may no longer give the same results as
1426 // before since old versions of overloaded < > == operators in CLCTDigi
1427 // class were discarded.
1428 // --------------------------------------------------------------------------
1429 // Pre-2007 version.
1430 std::vector <CSCCLCTDigi> CSCCathodeLCTProcessor::findLCTs(
1431  const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
1432  const std::vector<int> distrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]) {
1433  std::vector <CSCCLCTDigi> lctList;
1434  int _bx[2] = {999, 999};
1435  int first_bx = 999;
1436 
1437  const int nhStrips = 2*numStrips + 1;
1438  const int ndStrips = numStrips/2 + 1;
1439 
1440  if (infoV > 1) {
1441  dumpDigis(halfstrip, 1, nhStrips);
1442  dumpDigis(distrip, 0, ndStrips);
1443  }
1444 
1445  // Test beam version of TMB pretrigger and LCT sorting
1446  int h_keyStrip[MAX_CFEBS]; // one key per CFEB
1447  unsigned int h_nhits[MAX_CFEBS]; // number of hits in envelope for each key
1448  int d_keyStrip[MAX_CFEBS]; // one key per CFEB
1449  unsigned int d_nhits[MAX_CFEBS]; // number of hits in envelope for each key
1450  int keystrip_data[2][7]; // 2 possible LCTs per CSC x 7 LCT quantities
1451  unsigned int h_pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]; // simulate digital one-shot
1452  unsigned int d_pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]; // simulate digital one-shot
1453  bool pre_trig[2] = {false, false};
1454 
1455  // All half-strip and di-strip pattern envelopes are evaluated
1456  // simultaneously, on every clock cycle.
1457  pre_trig[0] = preTrigger(halfstrip, h_pulse, 1, nhStrips, 0, _bx[0]);
1458  pre_trig[1] = preTrigger( distrip, d_pulse, 0, ndStrips, 0, _bx[1]);
1459 
1460  // If any of 200 half-strip and di-strip envelopes has enough layers hit in
1461  // it, TMB will pre-trigger.
1462  if (pre_trig[0] || pre_trig[1]) {
1463  first_bx = (_bx[0] < _bx[1]) ? _bx[0] : _bx[1];
1464  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1465  << "half bx " << _bx[0] << " di bx " << _bx[1] << " first " << first_bx
1466  << "\n ..... waiting drift delay ..... ";
1467 
1468  // Empirically-found trick allowing to dramatically improve agreement
1469  // with MTCC-II data.
1470  // The trick is to ignore hits in a few first time bins when latching
1471  // hits for priority encode envelopes. For MTCC-II, we need to ignore
1472  // hits in time bins 0-3 inclusively.
1473  //
1474  // Firmware configuration has been fixed for most of 2007 runs, so
1475  // this trick should NOT be used when emulating 2007 trigger.
1476  /*
1477  int max_bx = 4;
1478  for (int ilayer = 0; ilayer < CSCConstants::NUM_LAYERS; ilayer++) {
1479  for (int istrip = 0; istrip < CSCConstants::NUM_HALF_STRIPS; istrip++) {
1480  for (int bx = 0; bx < max_bx; bx++) {
1481  if (((h_pulse[ilayer][istrip] >> bx) & 1) == 1) {
1482  h_pulse[ilayer][istrip] = 0;
1483  }
1484  }
1485  }
1486  for (int istrip = 0; istrip < CSCConstants::NUM_DI_STRIPS; istrip++) {
1487  for (int bx = 0; bx < max_bx; bx++) {
1488  if (((d_pulse[ilayer][istrip] >> bx) & 1) == 1) {
1489  d_pulse[ilayer][istrip] = 0;
1490  }
1491  }
1492  }
1493  }
1494  */
1495 
1496  // TMB latches LCTs drift_delay clocks after pretrigger.
1497  int latch_bx = first_bx + drift_delay;
1498  latchLCTs(h_pulse, h_keyStrip, h_nhits, 1, CSCConstants::NUM_HALF_STRIPS,
1499  latch_bx);
1500  latchLCTs(d_pulse, d_keyStrip, d_nhits, 0, CSCConstants::NUM_DI_STRIPS,
1501  latch_bx);
1502 
1503  if (infoV > 1) {
1504  LogTrace("CSCCathodeLCTProcessor")
1505  << "...............................\n"
1506  << "Final halfstrip hits and keys (after drift delay) ...";
1507  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1508  LogTrace("CSCCathodeLCTProcessor")
1509  << "cfeb " << icfeb << " key: " << h_keyStrip[icfeb]
1510  << " hits " << h_nhits[icfeb];
1511  }
1512  LogTrace("CSCCathodeLCTProcessor")
1513  << "Final distrip hits and keys (after drift delay) ...";
1514  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1515  LogTrace("CSCCathodeLCTProcessor")
1516  << "cfeb " << icfeb << " key: " << d_keyStrip[icfeb]
1517  << " hits " << d_nhits[icfeb];
1518  }
1519  }
1520  priorityEncode(h_keyStrip, h_nhits, d_keyStrip, d_nhits, keystrip_data);
1521  getKeyStripData(h_pulse, d_pulse, keystrip_data, first_bx);
1522 
1523  for (int ilct = 0; ilct < 2; ilct++) {
1524  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1525  << "found lcts: ilct " << ilct
1526  << " key strip " << keystrip_data[ilct][CLCT_STRIP];
1527  if (keystrip_data[ilct][CLCT_STRIP] != -1) {
1528  int halfstrip_in_cfeb = 0;
1529  if (keystrip_data[ilct][CLCT_STRIP_TYPE] == 0)
1530  halfstrip_in_cfeb = 4*keystrip_data[ilct][CLCT_STRIP] -
1531  32*keystrip_data[ilct][CLCT_CFEB];
1532  else
1533  halfstrip_in_cfeb = keystrip_data[ilct][CLCT_STRIP] -
1534  32*keystrip_data[ilct][CLCT_CFEB];
1535 
1536  CSCCLCTDigi thisLCT(1, keystrip_data[ilct][CLCT_QUALITY],
1537  keystrip_data[ilct][CLCT_PATTERN],
1538  keystrip_data[ilct][CLCT_STRIP_TYPE],
1539  keystrip_data[ilct][CLCT_BEND],
1540  halfstrip_in_cfeb,
1541  keystrip_data[ilct][CLCT_CFEB],
1542  keystrip_data[ilct][CLCT_BX]);
1543  lctList.push_back(thisLCT);
1544  }
1545  }
1546  }
1547 
1548  return lctList;
1549 
1550 } // findLCTs -- pre-2007 version.
1551 
1552 
1553 // Pre-2007 version.
1555  const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
1556  unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
1557  const int stripType, const int nStrips,
1558  const int start_bx, int& first_bx) {
1559  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1560  << "....................PreTrigger...........................";
1561 
1562  if (start_bx == 0) {
1563  // Fire one-shots for hit_persist bx's (6 bx's by default).
1564  pulseExtension(strip, nStrips, pulse);
1565  }
1566 
1567  bool pre_trig = false;
1568  // Now do a loop over bx times to see (if/when) track goes over threshold
1569  for (unsigned int bx_time = start_bx; bx_time < fifo_tbins; bx_time++) {
1570  // For any given bunch-crossing, start at the lowest keystrip and look for
1571  // the number of separate layers in the pattern for that keystrip that have
1572  // pulses at that bunch-crossing time. Do the same for the next keystrip,
1573  // etc. Then do the entire process again for the next bunch-crossing, etc
1574  // until you find a pre-trigger.
1575  pre_trig = preTrigLookUp(pulse, stripType, nStrips, bx_time);
1576  if (pre_trig) {
1577  first_bx = bx_time; // bx at time of pretrigger
1578  return true;
1579  }
1580  } // end loop over bx times
1581 
1582  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1583  << "no pretrigger for strip type " << stripType << ", returning \n";
1584  first_bx = fifo_tbins;
1585  return false;
1586 } // preTrigger -- pre-2007 version.
1587 
1588 
1589 // Pre-2007 version.
1591  const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
1592  const int stripType, const int nStrips,
1593  const unsigned int bx_time) {
1594  static const int hs_thresh = nplanes_hit_pretrig;
1595  static const int ds_thresh = nplanes_hit_pretrig;
1596 
1597  bool hit_layer[CSCConstants::NUM_LAYERS];
1598  int key_strip, this_layer, this_strip, layers_hit;
1599 
1600  // Layers hit threshold for pretrigger
1601  const int pre_trigger_layer_min = (stripType == 1) ? hs_thresh : ds_thresh;
1602 
1603  if (stripType != 0 && stripType != 1) {
1604  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
1605  << "+++ preTrigLookUp: stripType = " << stripType
1606  << " does not correspond to half-strip/di-strip patterns! +++\n";
1607  return false;
1608  }
1609 
1610  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) { // loop over cfebs
1611  // Loop over (di-/half-)strips in CFEB.
1612  for (int istrip = 0; istrip < cfeb_strips[stripType]; istrip++) {
1613  // Calculate candidate key.
1614  key_strip = icfeb*cfeb_strips[stripType] + istrip;
1615  layers_hit = 0;
1616  for (int ilayer = 0; ilayer < CSCConstants::NUM_LAYERS; ilayer++)
1617  hit_layer[ilayer] = false;
1618 
1619  // Loop over strips in pretrigger pattern mask and look for hits.
1620  for (int pstrip = 0; pstrip < NUM_PATTERN_STRIPS; pstrip++) {
1621  this_layer = pre_hit_pattern[0][pstrip];
1622  this_strip = pre_hit_pattern[1][pstrip]+key_strip;
1623 
1624  if (this_strip >= 0 && this_strip < nStrips) {
1625  // Determine if "one shot" is high at this bx_time
1626  if (((pulse[this_layer][this_strip] >> bx_time) & 1) == 1) {
1627  if (hit_layer[this_layer] == false) {
1628  hit_layer[this_layer] = true;
1629  layers_hit++; // determines number of layers hit
1630  if (layers_hit >= pre_trigger_layer_min) {
1631  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1632  << "pretrigger at bx: " << bx_time
1633  << ", cfeb " << icfeb << ", returning";
1634  return true;
1635  }
1636  }
1637  }
1638  }
1639  } // end loop over strips in pretrigger pattern
1640  } // end loop over candidate key strips in cfeb
1641  } // end loop over cfebs, if pretrigger is found, stop looking and return
1642 
1643  return false;
1644 
1645 } // preTrigLookUp -- pre-2007 version.
1646 
1647 
1648 // Pre-2007 version.
1650  const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
1651  int keyStrip[MAX_CFEBS], unsigned int n_hits[MAX_CFEBS],
1652  const int stripType, const int nStrips, const int bx_time) {
1653 
1654  bool hit_layer[CSCConstants::NUM_LAYERS];
1655  int key_strip, this_layer, this_strip;
1656  int layers_hit, prev_hits;
1657 
1658  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1659  keyStrip[icfeb] = -1;
1660  n_hits[icfeb] = 0;
1661  }
1662 
1663  if (stripType != 0 && stripType != 1) {
1664  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongInput")
1665  << "+++ latchLCTs: stripType = " << stripType
1666  << " does not correspond to half-strip/di-strip patterns! +++\n";
1667  return;
1668  }
1669 
1670  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) { // loop over CFEBs
1671  prev_hits = 0;
1672  // Loop over (di-/half-)strips in CFEB.
1673  for (int istrip = 0; istrip < cfeb_strips[stripType]; istrip++) {
1674  // Calculate candidate key.
1675  key_strip = icfeb*cfeb_strips[stripType] + istrip;
1676  layers_hit = 0;
1677  for (int ilayer = 0; ilayer < CSCConstants::NUM_LAYERS; ilayer++)
1678  hit_layer[ilayer] = false;
1679 
1680  // Loop over strips in pretrigger pattern mask and look for hits.
1681  for (int pstrip = 0; pstrip < NUM_PATTERN_STRIPS; pstrip++) {
1682  this_layer = pre_hit_pattern[0][pstrip];
1683  this_strip = pre_hit_pattern[1][pstrip]+key_strip;
1684 
1685  if (this_strip >= 0 && this_strip < nStrips) {
1686  // Determine if "one shot" is high at this bx_time
1687  if (((pulse[this_layer][this_strip] >> bx_time) & 1) == 1) {
1688  if (hit_layer[this_layer] == false) {
1689  hit_layer[this_layer] = true;
1690  layers_hit++; // number of layers hit
1691  }
1692  }
1693  }
1694  } // end loop over strips in pretrigger pattern
1695  if (infoV > 1) {
1696  if (layers_hit > 0) LogTrace("CSCCathodeLCTProcessor")
1697  << "cfeb: " << icfeb << " key_strip: " << key_strip
1698  << " n_hits: " << layers_hit;
1699  }
1700  // If two or more keys have an equal number of hits, the lower number
1701  // key is taken. Hence, replace the previous key only if this key has
1702  // more hits.
1703  if (layers_hit > prev_hits) {
1704  prev_hits = layers_hit;
1705  keyStrip[icfeb] = key_strip; // key with highest hits is LCT key strip
1706  n_hits[icfeb] = layers_hit; // corresponding hits in envelope
1707  }
1708  } // end loop over candidate key strips in cfeb
1709  } // end loop over cfebs
1710 } // latchLCTs -- pre-2007 version.
1711 
1712 
1713 // Pre-2007 version.
1715  const int h_keyStrip[MAX_CFEBS], const unsigned int h_nhits[MAX_CFEBS],
1716  const int d_keyStrip[MAX_CFEBS], const unsigned int d_nhits[MAX_CFEBS],
1717  int keystrip_data[2][7]) {
1718  static const unsigned int hs_thresh = nplanes_hit_pretrig;
1719  //static const unsigned int ds_thresh = nplanes_hit_pretrig;
1720 
1721  int ihits[2]; // hold hits for sorting
1722  int cfebs[2]; // holds CFEB numbers corresponding to highest hits
1723  const int nlcts = 2;
1724  int key_strip[MAX_CFEBS], key_phits[MAX_CFEBS], strip_type[MAX_CFEBS];
1725 
1726  // initialize arrays
1727  for (int ilct = 0; ilct < nlcts; ilct++) {
1728  for (int j = 0; j < 7; j++) keystrip_data[ilct][j] = -1;
1729  ihits[ilct] = 0;
1730  cfebs[ilct] = -1;
1731  }
1732  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1733  key_strip[icfeb] = -1;
1734  key_phits[icfeb] = -1;
1735  strip_type[icfeb] = -1;
1736  }
1737 
1738  if (infoV > 1) {
1739  LogTrace("CSCCathodeLCTProcessor")
1740  << ".....................PriorityEncode.......................";
1741  std::ostringstream strstrm;
1742  strstrm << "hkeys:";
1743  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1744  strstrm << std::setw(4) << h_keyStrip[icfeb];
1745  }
1746  strstrm << "\ndkeys:";
1747  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1748  strstrm << std::setw(4) << d_keyStrip[icfeb];
1749  }
1750  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
1751  }
1752 
1753  // Loop over CFEBs and determine better of half- or di- strip pattern.
1754  // If select halfstrip, promote it by adding an extra bit to its hits.
1755  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1756  if (h_keyStrip[icfeb] != -1 && d_keyStrip[icfeb] != -1) {
1757  if (h_nhits[icfeb] >= hs_thresh) {
1758  key_strip[icfeb] = h_keyStrip[icfeb];
1759  key_phits[icfeb] = h_nhits[icfeb] + 8; // halfstrip promotion
1760  strip_type[icfeb]= 1;
1761  }
1762  // For di-strip envelope there is no requirement that the number of
1763  // layers hit is >= ds_thresh!!!
1764  // else if (d_nhits[icfeb] >= ds_thresh) {
1765  else {
1766  key_strip[icfeb] = d_keyStrip[icfeb];
1767  key_phits[icfeb] = d_nhits[icfeb];
1768  strip_type[icfeb]= 0;
1769  }
1770  }
1771  else if (h_keyStrip[icfeb] != -1) {
1772  if (h_nhits[icfeb] >= hs_thresh) {
1773  key_strip[icfeb] = h_keyStrip[icfeb];
1774  key_phits[icfeb] = h_nhits[icfeb] + 8; // halfstrip promotion
1775  strip_type[icfeb]= 1;
1776  }
1777  }
1778  else if (d_keyStrip[icfeb] != -1) {
1779  // if (d_nhits[icfeb] >= ds_thresh) {
1780  key_strip[icfeb] = d_keyStrip[icfeb];
1781  key_phits[icfeb] = d_nhits[icfeb];
1782  strip_type[icfeb]= 0;
1783  // }
1784  }
1785  if (infoV > 1 && strip_type[icfeb] != -1) {
1786  if (strip_type[icfeb] == 0)
1787  LogTrace("CSCCathodeLCTProcessor")
1788  << " taking distrip pattern on cfeb " << icfeb;
1789  else if (strip_type[icfeb] == 1)
1790  LogTrace("CSCCathodeLCTProcessor")
1791  << " taking halfstrip pattern on cfeb " << icfeb;
1792  LogTrace("CSCCathodeLCTProcessor")
1793  << " cfeb " << icfeb << " key " << key_strip[icfeb]
1794  << " hits " << key_phits[icfeb] << " type " << strip_type[icfeb];
1795  }
1796  }
1797 
1798  // Remove duplicate LCTs at boundaries -- it is possilbe to have key[0]
1799  // be the higher of the two key strips, take this into account, but
1800  // preserve rank of lcts.
1801  int key[MAX_CFEBS];
1802  int loedge, hiedge;
1803 
1804  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1805  << "...... Remove Duplicates ......";
1806  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1807  if(strip_type[icfeb] == 0) key[icfeb] = key_strip[icfeb]*4;
1808  else key[icfeb] = key_strip[icfeb];
1809  }
1810  for (int icfeb = 0; icfeb < MAX_CFEBS-1; icfeb++) {
1811  if (key[icfeb] >= 0 && key[icfeb+1] >= 0) {
1812  loedge = cfeb_strips[1]*(icfeb*8+7)/8;
1813  hiedge = cfeb_strips[1]*(icfeb*8+9)/8 - 1;
1814  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1815  << " key 1: " << key[icfeb] << " key 2: " << key[icfeb+1]
1816  << " low edge: " << loedge << " high edge: " << hiedge;
1817  if (key[icfeb] >= loedge && key[icfeb+1] <= hiedge) {
1818  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1819  << "Duplicate LCTs found at boundary of CFEB " << icfeb << " ...";
1820  if (key_phits[icfeb+1] > key_phits[icfeb]) {
1821  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1822  << " deleting LCT on CFEB " << icfeb;
1823  key_strip[icfeb] = -1;
1824  key_phits[icfeb] = -1;
1825  }
1826  else {
1827  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1828  << " deleting LCT on CFEB " << icfeb+1;
1829  key_strip[icfeb+1] = -1;
1830  key_phits[icfeb+1] = -1;
1831  }
1832  }
1833  }
1834  }
1835 
1836  // Now loop over CFEBs and pick best two lcts based on no. hits in envelope.
1837  // In case of equal quality, select the one on lower-numbered CFEBs.
1838  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1839  << "\n...... Select best LCTs ......";
1840  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1841  if (key_phits[icfeb] > ihits[0]) {
1842  ihits[1] = ihits[0];
1843  cfebs[1] = cfebs[0];
1844  ihits[0] = key_phits[icfeb];
1845  cfebs[0] = icfeb;
1846  if (infoV > 1) {
1847  std::ostringstream strstrm;
1848  for (int icfeb = 0; icfeb < MAX_CFEBS; icfeb++) {
1849  strstrm << std::setw(4) << strip_type[icfeb];
1850  }
1851  LogTrace("CSCCathodeLCTProcessor")
1852  << "strip_type" << strstrm.str()
1853  << "\n best: ihits " << ihits[0] << " cfeb " << cfebs[0]
1854  << " strip_type " << ((cfebs[0] >= 0) ? strip_type[cfebs[0]] : -1)
1855  << "\n next: ihits " << ihits[1] << " cfeb " << cfebs[1]
1856  << " strip_type " << ((cfebs[1] >= 0) ? strip_type[cfebs[1]] : -1);
1857  }
1858  }
1859  else if (key_phits[icfeb] > ihits[1]) {
1860  ihits[1] = key_phits[icfeb];
1861  cfebs[1] = icfeb;
1862  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1863  << "\n next: ihits " << ihits[1] << " cfeb " << cfebs[1]
1864  << " strip_type " << ((cfebs[1] >= 0) ? strip_type[cfebs[1]] : -1);
1865  }
1866  }
1867 
1868  // fill lct data array key strip with 2 highest hit lcts (if they exist)
1869  int jlct = 0;
1870  for (int ilct = 0; ilct < nlcts; ilct++) {
1871  if (cfebs[ilct] != -1) {
1872  keystrip_data[jlct][CLCT_CFEB] = cfebs[ilct];
1873  keystrip_data[jlct][CLCT_STRIP] = key_strip[cfebs[ilct]];
1874  keystrip_data[jlct][CLCT_STRIP_TYPE] = strip_type[cfebs[ilct]];
1875  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1876  << "filling key: " << key_strip[cfebs[ilct]]
1877  << " type: " << strip_type[cfebs[ilct]];
1878  jlct++;
1879  }
1880  }
1881 } // priorityEncode -- pre-2007 version.
1882 
1883 
1884 // Pre-2007 version.
1886  const unsigned int h_pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
1887  const unsigned int d_pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
1888  int keystrip_data[2][7], const int first_bx) {
1889 
1890  int lct_pattern[NUM_PATTERN_STRIPS];
1891  int this_layer, this_strip;
1892  unsigned int quality = 0, bend = 0;
1893  unsigned int best_quality, best_pattern;
1894  bool valid[2] = {false,false};
1895 
1896  // Time at which TMB latches LCTs.
1897  int latch_bx = first_bx + drift_delay;
1898 
1899  // Look at keystrips determined from priorityEncode and find their best
1900  // pattern based on number of hits matching that pattern (quality). Also
1901  // find bend angle. There are multiple patterns available for each keystrip.
1902 
1903  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1904  << "...............getKeyStripData....................";
1905 
1906  for (int ilct = 0; ilct < 2; ilct++) {
1907  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1908  << "lct " << ilct << " keystrip " << keystrip_data[ilct][CLCT_STRIP]
1909  << " type " << keystrip_data[ilct][CLCT_STRIP_TYPE];
1910  if (keystrip_data[ilct][CLCT_STRIP] == -1) {// flag set in priorityEncode()
1911  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1912  << "no lct at ilct " << ilct;
1913  continue;
1914  }
1915  for (int pattern_strip = 0; pattern_strip < NUM_PATTERN_STRIPS;
1916  pattern_strip++) {
1917  lct_pattern[pattern_strip] = -999;
1918  this_layer = pre_hit_pattern[0][pattern_strip];
1919  this_strip = pre_hit_pattern[1][pattern_strip] +
1920  keystrip_data[ilct][CLCT_STRIP];
1921  // This conditional statement prevents us from looking at strips
1922  // that don't exist along the chamber boundaries.
1923  if (keystrip_data[ilct][CLCT_STRIP_TYPE] == 1) {
1924  if (this_strip >= 0 && this_strip < CSCConstants::NUM_HALF_STRIPS) {
1925  // Now look at one-shots in bx where TMB latches the LCTs
1926  if (((h_pulse[this_layer][this_strip] >> latch_bx) & 1) == 1)
1927  lct_pattern[pattern_strip] = 1;
1928  }
1929  }
1930  else {
1931  if (this_strip >= 0 && this_strip < CSCConstants::NUM_DI_STRIPS) {
1932  // Now look at one-shots in bx where TMB latches the LCTs
1933  if (((d_pulse[this_layer][this_strip] >> latch_bx) & 1) == 1)
1934  lct_pattern[pattern_strip] = 1;
1935  }
1936  }
1937  }
1938 
1939  // Find best pattern and quality associated with key by looping over all
1940  // possible patterns
1941  best_quality = 0;
1942  best_pattern = 0;
1943 
1944  for (unsigned int pattern_num = 0;
1945  pattern_num < CSCConstants::NUM_CLCT_PATTERNS_PRE_TMB07; pattern_num++) {
1946  getPattern(pattern_num, lct_pattern, quality, bend);
1947  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1948  << "pattern " << pattern_num << " quality " << quality
1949  << " bend " << bend;
1950  // Number of layers hit matching a pattern template is compared
1951  // to nplanes_hit_pattern. The threshold is the same for both half- and
1952  // di-strip patterns.
1953  if (quality >= nplanes_hit_pattern) {
1954  // If the number of matches is the same for two pattern templates,
1955  // the higher pattern-template number is selected.
1956  if ((quality == best_quality && pattern_num > best_pattern) ||
1957  (quality > best_quality)) {
1958  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1959  << "valid = true at quality " << quality
1960  << " thresh " << nplanes_hit_pattern;
1961  valid[ilct] = true;
1962  keystrip_data[ilct][CLCT_PATTERN] = pattern_num;
1963  keystrip_data[ilct][CLCT_BEND] = bend;
1964  keystrip_data[ilct][CLCT_BX] = first_bx;
1965  //keystrip_data[ilct][CLCT_STRIP_TYPE] = stripType;
1966  keystrip_data[ilct][CLCT_QUALITY] = quality;
1967  best_quality = quality;
1968  best_pattern = pattern_num;
1969  }
1970  }
1971  }
1972 
1973  if (!valid[ilct]) {
1974  keystrip_data[ilct][CLCT_STRIP] = -1; // delete lct
1975  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1976  << "lct " << ilct << " not over threshold: deleting";
1977  }
1978  else {
1979  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
1980  << "\n" << "--------- final LCT: " << ilct << " -------------\n"
1981  << " key strip " << keystrip_data[ilct][CLCT_STRIP]
1982  << " pattern_num " << keystrip_data[ilct][CLCT_PATTERN]
1983  << " quality " << keystrip_data[ilct][CLCT_QUALITY]
1984  << " bend " << keystrip_data[ilct][CLCT_BEND]
1985  << " bx " << keystrip_data[ilct][CLCT_BX]
1986  << " type " << keystrip_data[ilct][CLCT_STRIP_TYPE] << "\n";
1987  }
1988  } // end loop over lcts
1989 } // getKeyStripData -- pre-2007 version.
1990 
1991 
1992 // Pre-2007 version.
1993 void CSCCathodeLCTProcessor::getPattern(unsigned int pattern_num,
1994  const int strip_value[NUM_PATTERN_STRIPS],
1995  unsigned int& quality, unsigned int& bend) {
1996 
1997  // This function takes strip "one-shots" at the correct bx to find out
1998  // which hits fall within a certain pattern. Quality and bend are then
1999  // calculated based on which strip pattern and how many layers were hit
2000  // within the pattern.
2001 
2002  unsigned int layers_hit = 0;
2003  bool hit_layer[CSCConstants::NUM_LAYERS];
2004 
2005  // Clear hit_layer array to keep track of number of layers hit.
2006  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
2007  hit_layer[i_layer] = false;
2008 
2009  // Loop over all designated patterns.
2010  for (int strip_num = 0; strip_num < NUM_PATTERN_STRIPS; strip_num++){
2011  if (strip_value[strip_num] == 1){
2012  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++){
2013  // Loop over layer and see if corresponding strip is on same layer
2014  // If so then increment number of hits.
2015  if (i_layer == pattern[pattern_num][strip_num]){
2016  // If layer has no hits, then increment number of layers hit.
2017  if (hit_layer[i_layer] == false){
2018  layers_hit++;
2019  hit_layer[i_layer] = true;
2020  }
2021  }
2022  }
2023  }
2024  }
2025  // Get bend value from pattern.
2026  bend = pattern[pattern_num][NUM_PATTERN_STRIPS];
2027  quality = layers_hit;
2028 
2029 } // getPattern -- pre-2007 version.
2030 
2031 
2032 // --------------------------------------------------------------------------
2033 // The code below is a description of the 2007 version of the CLCT
2034 // algorithm (half-strips only). It was first used in 2008 CRUZET runs,
2035 // and later in CRAFT. The algorithm became the default version for
2036 // Monte Carlo studies in March 2008 (CMSSW_2_0_0).
2037 // --------------------------------------------------------------------------
2038 // TMB-07 version.
2039 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::findLCTs(const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]) {
2040  std::vector<CSCCLCTDigi> lctList;
2041 
2042  // Max. number of half-strips for this chamber.
2043  const int maxHalfStrips = 2*numStrips + 1;
2044 
2045  if (infoV > 1) dumpDigis(halfstrip, 1, maxHalfStrips);
2046 
2047  // Test beam version of TMB pretrigger and LCT sorting
2048  enum {max_lcts = 2};
2049  // 2 possible LCTs per CSC x 7 LCT quantities
2050  int keystrip_data[max_lcts][7] = {{0}};
2052 
2053  // Fire half-strip one-shots for hit_persist bx's (4 bx's by default).
2054  pulseExtension(halfstrip, maxHalfStrips, pulse);
2055 
2056  unsigned int start_bx = start_bx_shift;
2057  // Stop drift_delay bx's short of fifo_tbins since at later bx's we will
2058  // not have a full set of hits to start pattern search anyway.
2059  unsigned int stop_bx = fifo_tbins - drift_delay;
2060  // Allow for more than one pass over the hits in the time window.
2061  while (start_bx < stop_bx) {
2062  // All half-strip pattern envelopes are evaluated simultaneously, on every
2063  // clock cycle.
2064  int first_bx = 999;
2065  bool pre_trig = preTrigger(pulse, start_bx, first_bx);
2066 
2067  // If any of half-strip envelopes has enough layers hit in it, TMB
2068  // will pre-trigger.
2069  if (pre_trig) {
2070  thePreTriggerBXs.push_back(first_bx);
2071  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
2072  << "..... pretrigger at bx = " << first_bx
2073  << "; waiting drift delay .....";
2074 
2075  // TMB latches LCTs drift_delay clocks after pretrigger.
2076  int latch_bx = first_bx + drift_delay;
2077  bool hits_in_time = ptnFinding(pulse, maxHalfStrips, latch_bx);
2078  if (infoV > 1) {
2079  if (hits_in_time) {
2080  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
2081  hstrip < maxHalfStrips; hstrip++) {
2082  if (nhits[hstrip] > 0) {
2083  LogTrace("CSCCathodeLCTProcessor")
2084  << " bx = " << std::setw(2) << latch_bx << " --->"
2085  << " halfstrip = " << std::setw(3) << hstrip
2086  << " best pid = " << std::setw(2) << best_pid[hstrip]
2087  << " nhits = " << nhits[hstrip];
2088  }
2089  }
2090  }
2091  }
2092  // The pattern finder runs continuously, so another pre-trigger
2093  // could occur already at the next bx.
2094  start_bx = first_bx + 1;
2095 
2096  // Quality for sorting.
2097  int quality[CSCConstants::NUM_HALF_STRIPS];
2098  int best_halfstrip[max_lcts], best_quality[max_lcts];
2099  for (int ilct = 0; ilct < max_lcts; ilct++) {
2100  best_halfstrip[ilct] = -1;
2101  best_quality[ilct] = 0;
2102  }
2103 
2104  // Calculate quality from pattern id and number of hits, and
2105  // simultaneously select best-quality LCT.
2106  if (hits_in_time) {
2107  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
2108  hstrip < maxHalfStrips; hstrip++) {
2109  // The bend-direction bit pid[0] is ignored (left and right
2110  // bends have equal quality).
2111  quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
2112  if (quality[hstrip] > best_quality[0]) {
2113  best_halfstrip[0] = hstrip;
2114  best_quality[0] = quality[hstrip];
2115  }
2116  if (infoV > 1 && quality[hstrip] > 0) {
2117  LogTrace("CSCCathodeLCTProcessor")
2118  << " 1st CLCT: halfstrip = " << std::setw(3) << hstrip
2119  << " quality = " << std::setw(3) << quality[hstrip]
2120  << " best halfstrip = " << std::setw(3) << best_halfstrip[0]
2121  << " best quality = " << std::setw(3) << best_quality[0];
2122  }
2123  }
2124  }
2125 
2126  // If 1st best CLCT is found, look for the 2nd best.
2127  if (best_halfstrip[0] >= 0) {
2128  // Mark keys near best CLCT as busy by setting their quality to
2129  // zero, and repeat the search.
2130  markBusyKeys(best_halfstrip[0], best_pid[best_halfstrip[0]], quality);
2131 
2132  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
2133  hstrip < maxHalfStrips; hstrip++) {
2134  if (quality[hstrip] > best_quality[1]) {
2135  best_halfstrip[1] = hstrip;
2136  best_quality[1] = quality[hstrip];
2137  }
2138  if (infoV > 1 && quality[hstrip] > 0) {
2139  LogTrace("CSCCathodeLCTProcessor")
2140  << " 2nd CLCT: halfstrip = " << std::setw(3) << hstrip
2141  << " quality = " << std::setw(3) << quality[hstrip]
2142  << " best halfstrip = " << std::setw(3) << best_halfstrip[1]
2143  << " best quality = " << std::setw(3) << best_quality[1];
2144  }
2145  }
2146 
2147  // Pattern finder.
2148  bool ptn_trig = false;
2149  for (int ilct = 0; ilct < max_lcts; ilct++) {
2150  int best_hs = best_halfstrip[ilct];
2151  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
2152  ptn_trig = true;
2153  keystrip_data[ilct][CLCT_PATTERN] = best_pid[best_hs];
2154  keystrip_data[ilct][CLCT_BEND] =
2156  // Remove stagger if any.
2157  keystrip_data[ilct][CLCT_STRIP] =
2159  keystrip_data[ilct][CLCT_BX] = first_bx;
2160  keystrip_data[ilct][CLCT_STRIP_TYPE] = 1; // obsolete
2161  keystrip_data[ilct][CLCT_QUALITY] = nhits[best_hs];
2162  keystrip_data[ilct][CLCT_CFEB] =
2163  keystrip_data[ilct][CLCT_STRIP]/cfeb_strips[1];
2164  int halfstrip_in_cfeb = keystrip_data[ilct][CLCT_STRIP] -
2165  cfeb_strips[1]*keystrip_data[ilct][CLCT_CFEB];
2166 
2167  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
2168  << " Final selection: ilct " << ilct
2169  << " key halfstrip " << keystrip_data[ilct][CLCT_STRIP]
2170  << " quality " << keystrip_data[ilct][CLCT_QUALITY]
2171  << " pattern " << keystrip_data[ilct][CLCT_PATTERN]
2172  << " bx " << keystrip_data[ilct][CLCT_BX];
2173 
2174  CSCCLCTDigi thisLCT(1, keystrip_data[ilct][CLCT_QUALITY],
2175  keystrip_data[ilct][CLCT_PATTERN],
2176  keystrip_data[ilct][CLCT_STRIP_TYPE],
2177  keystrip_data[ilct][CLCT_BEND],
2178  halfstrip_in_cfeb,
2179  keystrip_data[ilct][CLCT_CFEB],
2180  keystrip_data[ilct][CLCT_BX]);
2181  lctList.push_back(thisLCT);
2182  }
2183  }
2184 
2185  if (ptn_trig) {
2186  // Once there was a trigger, CLCT pre-trigger state machine
2187  // checks the number of hits that lie on a pattern template
2188  // at every bx, and waits for it to drop below threshold.
2189  // The search for CLCTs resumes only when the number of hits
2190  // drops below threshold.
2191  start_bx = fifo_tbins;
2192  // Stop checking drift_delay bx's short of fifo_tbins since
2193  // at later bx's we won't have a full set of hits for a
2194  // pattern search anyway.
2195  unsigned int stop_time = fifo_tbins - drift_delay;
2196  for (unsigned int bx = latch_bx + 1; bx < stop_time; bx++) {
2197  bool return_to_idle = true;
2198  bool hits_in_time = ptnFinding(pulse, maxHalfStrips, bx);
2199  if (hits_in_time) {
2200  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
2201  hstrip < maxHalfStrips; hstrip++) {
2202  if (nhits[hstrip] >= nplanes_hit_pattern) {
2203  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
2204  << " State machine busy at bx = " << bx;
2205  return_to_idle = false;
2206  break;
2207  }
2208  }
2209  }
2210  if (return_to_idle) {
2211  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
2212  << " State machine returns to idle state at bx = " << bx;
2213  start_bx = bx;
2214  break;
2215  }
2216  }
2217  }
2218  }
2219  }
2220  else {
2221  start_bx = first_bx + 1; // no dead time
2222  }
2223  }
2224 
2225  return lctList;
2226 } // findLCTs -- TMB-07 version.
2227 
2228 
2229 // Common to all versions.
2232  const int nStrips,
2233  unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]) {
2234 
2235  static const unsigned int bits_in_pulse = 8*sizeof(pulse[0][0]);
2236 
2237  // Clear pulse array. This array will be used as a bit representation of
2238  // hit times. For example: if strip[1][2] has a value of 3, then 1 shifted
2239  // left 3 will be bit pattern of pulse[1][2]. This would make the pattern
2240  // look like 0000000000001000. Then add on additional bits to signify
2241  // the duration of a signal (hit_persist, formerly bx_width) to simulate
2242  // the TMB's drift delay. So for the same pulse[1][2] with a hit_persist
2243  // of 3 would look like 0000000000111000. This is similating the digital
2244  // one-shot in the TMB.
2245  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
2246  for (int i_strip = 0; i_strip < nStrips; i_strip++)
2247  pulse[i_layer][i_strip] = 0;
2248 
2249  // Loop over all layers and halfstrips.
2250  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
2251  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
2252  // If there is a hit, simulate digital one-shot persistence starting
2253  // in the bx of the initial hit. Fill this into pulse[][].
2254  if (time[i_layer][i_strip].size() > 0) {
2255  std::vector<int> bx_times = time[i_layer][i_strip];
2256  for (unsigned int i = 0; i < bx_times.size(); i++) {
2257  // Check that min and max times are within the allowed range.
2258  if (bx_times[i] < 0 || bx_times[i] + hit_persist >= bits_in_pulse) {
2259  if (infoV > 0) edm::LogWarning("L1CSCTPEmulatorOutOfTimeDigi")
2260  << "+++ BX time of comparator digi (halfstrip = " << i_strip
2261  << " layer = " << i_layer << ") bx = " << bx_times[i]
2262  << " is not within the range (0-" << bits_in_pulse
2263  << "] allowed for pulse extension. Skip this digi! +++\n";
2264  continue;
2265  }
2266  if (bx_times[i] >= start_bx_shift) {
2267  for (unsigned int bx = bx_times[i]; bx < bx_times[i] + hit_persist; ++bx)
2268  pulse[i_layer][i_strip] = pulse[i_layer][i_strip] | (1 << bx);
2269  }
2270  }
2271  }
2272  }
2273  }
2274 } // pulseExtension.
2275 
2276 
2277 // TMB-07 version.
2279  const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
2280  const int start_bx, int& first_bx) {
2281  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor")
2282  << "....................PreTrigger...........................";
2283 
2284  // Max. number of half-strips for this chamber.
2285  const int nStrips = 2*numStrips + 1;
2286 
2287  bool pre_trig = false;
2288  // Now do a loop over bx times to see (if/when) track goes over threshold
2289  for (unsigned int bx_time = start_bx; bx_time < fifo_tbins; bx_time++) {
2290  // For any given bunch-crossing, start at the lowest keystrip and look for
2291  // the number of separate layers in the pattern for that keystrip that have
2292  // pulses at that bunch-crossing time. Do the same for the next keystrip,
2293  // etc. Then do the entire process again for the next bunch-crossing, etc
2294  // until you find a pre-trigger.
2295  bool hits_in_time = ptnFinding(pulse, nStrips, bx_time);
2296  if (hits_in_time) {
2297  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER-1];
2298  hstrip < nStrips; hstrip++) {
2299  if (infoV > 1) {
2300  if (nhits[hstrip] > 0) {
2301  LogTrace("CSCCathodeLCTProcessor")
2302  << " bx = " << std::setw(2) << bx_time << " --->"
2303  << " halfstrip = " << std::setw(3) << hstrip
2304  << " best pid = " << std::setw(2) << best_pid[hstrip]
2305  << " nhits = " << nhits[hstrip];
2306  }
2307  }
2308  ispretrig[hstrip] = 0;
2309  if (nhits[hstrip] >= nplanes_hit_pretrig &&
2310  best_pid[hstrip] >= pid_thresh_pretrig) {
2311  pre_trig = true;
2312  ispretrig[hstrip] = 1;
2313  }
2314  }
2315 
2316  if (pre_trig) {
2317  first_bx = bx_time; // bx at time of pretrigger
2318  return true;
2319  }
2320  }
2321  } // end loop over bx times
2322 
2323  if (infoV > 1) LogTrace("CSCCathodeLCTProcessor") <<
2324  "no pretrigger, returning \n";
2325  first_bx = fifo_tbins;
2326  return false;
2327 } // preTrigger -- TMB-07 version.
2328 
2329 
2330 // TMB-07 version.
2332  const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
2333  const int nStrips, const unsigned int bx_time)
2334 {
2335  if (bx_time >= fifo_tbins) return false;
2336 
2337  // This loop is a quick check of a number of layers hit at bx_time: since
2338  // most of the time it is 0, this check helps to speed-up the execution
2339  // substantially.
2340  unsigned int layers_hit = 0;
2341  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++)
2342  {
2343  for (int i_hstrip = 0; i_hstrip < nStrips; i_hstrip++)
2344  {
2345  if (((pulse[i_layer][i_hstrip] >> bx_time) & 1) == 1)
2346  {
2347  layers_hit++;
2348  break;
2349  }
2350  }
2351  }
2352  if (layers_hit < nplanes_hit_pretrig) return false;
2353 
2354  for (int key_hstrip = 0; key_hstrip < nStrips; key_hstrip++)
2355  {
2356  best_pid[key_hstrip] = 0;
2357  nhits[key_hstrip] = 0;
2358  first_bx_corrected[key_hstrip] = -999;
2359  }
2360 
2361  // Loop over candidate key strips.
2362  bool hit_layer[CSCConstants::NUM_LAYERS];
2363  for (int key_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; key_hstrip < nStrips; key_hstrip++)
2364  {
2365  // Loop over patterns and look for hits matching each pattern.
2366  for (unsigned int pid = CSCConstants::NUM_CLCT_PATTERNS - 1; pid >= pid_thresh_pretrig; pid--)
2367  {
2368  layers_hit = 0;
2369  for (int ilayer = 0; ilayer < CSCConstants::NUM_LAYERS; ilayer++)
2370  hit_layer[ilayer] = false;
2371 
2372  double num_pattern_hits=0., times_sum=0.;
2373  std::multiset<int> mset_for_median;
2374  mset_for_median.clear();
2375 
2376  // Loop over halfstrips in trigger pattern mask and calculate the
2377  // "absolute" halfstrip number for each.
2378  for (int strip_num = 0; strip_num < NUM_PATTERN_HALFSTRIPS; strip_num++)
2379  {
2380  int this_layer = pattern2007[pid][strip_num];
2381  if (this_layer >= 0 && this_layer < CSCConstants::NUM_LAYERS)
2382  {
2383  int this_strip = pattern2007_offset[strip_num] + key_hstrip;
2384  if (this_strip >= 0 && this_strip < nStrips) {
2385  if (infoV > 3) LogTrace("CSCCathodeLCTProcessor")
2386  << " In ptnFinding: key_strip = " << key_hstrip
2387  << " pid = " << pid << " strip_num = " << strip_num
2388  << " layer = " << this_layer << " strip = " << this_strip;
2389  // Determine if "one shot" is high at this bx_time
2390  if (((pulse[this_layer][this_strip] >> bx_time) & 1) == 1)
2391  {
2392  if (hit_layer[this_layer] == false)
2393  {
2394  hit_layer[this_layer] = true;
2395  layers_hit++; // determines number of layers hit
2396  }
2397 
2398  // find at what bx did pulse on this halsfstrip&layer have started
2399  // use hit_pesrist constraint on how far back we can go
2400  int first_bx_layer = bx_time;
2401  for (unsigned int dbx = 0; dbx < hit_persist; dbx++)
2402  {
2403  if (((pulse[this_layer][this_strip] >> (first_bx_layer - 1)) & 1) == 1)
2404  first_bx_layer--;
2405  else
2406  break;
2407  }
2408  times_sum += (double) first_bx_layer;
2409  num_pattern_hits += 1.;
2410  mset_for_median.insert(first_bx_layer);
2411  if (infoV > 2)
2412  LogTrace("CSCCathodeLCTProcessor") << " 1st bx in layer: " << first_bx_layer << " sum bx: " << times_sum
2413  << " #pat. hits: " << num_pattern_hits;
2414  }
2415  }
2416  }
2417  } // end loop over strips in pretrigger pattern
2418 
2419  if (layers_hit > nhits[key_hstrip])
2420  {
2421  best_pid[key_hstrip] = pid;
2422  nhits[key_hstrip] = layers_hit;
2423 
2424  // calculate median
2425  const int sz = mset_for_median.size();
2426  if (sz>0){
2427  std::multiset<int>::iterator im = mset_for_median.begin();
2428  if (sz>1) std::advance(im,sz/2-1);
2429  if (sz==1) first_bx_corrected[key_hstrip] = *im;
2430  else if ((sz % 2) == 1) first_bx_corrected[key_hstrip] = *(++im);
2431  else first_bx_corrected[key_hstrip] = ((*im) + (*(++im)))/2;
2432 
2433  if (infoV > 1) {
2434  char bxs[300]="";
2435  for (im = mset_for_median.begin(); im != mset_for_median.end(); im++)
2436  sprintf(bxs,"%s %d", bxs, *im);
2437  LogTrace("CSCCathodeLCTProcessor")
2438  <<"bx="<<bx_time<<" bx_cor="<< first_bx_corrected[key_hstrip]<<" bxset="<<bxs;
2439  }
2440  }
2441 
2442  // Do not loop over the other (worse) patterns if max. numbers of
2443  // hits is found.
2444  if (nhits[key_hstrip] == CSCConstants::NUM_LAYERS) break;
2445  }
2446  } // end loop over pid
2447  } // end loop over candidate key strips
2448  return true;
2449 } // ptnFinding -- TMB-07 version.
2450 
2451 
2452 // TMB-07 version.
2453 void CSCCathodeLCTProcessor::markBusyKeys(const int best_hstrip,
2454  const int best_patid,
2455  int quality[CSCConstants::NUM_HALF_STRIPS]) {
2456  int nspan = min_separation;
2457  int pspan = min_separation;
2458 
2459  // if dynamic spacing is enabled, separation is defined by pattern width
2460  //if (dynamic_spacing)
2461  // nspan = pspan = pattern2007[best_patid][NUM_PATTERN_HALFSTRIPS+1]-1;
2462 
2463  for (int hstrip = best_hstrip-nspan; hstrip <= best_hstrip+pspan; hstrip++) {
2464  if (hstrip >= 0 && hstrip < CSCConstants::NUM_HALF_STRIPS) {
2465  quality[hstrip] = 0;
2466  }
2467  }
2468 } // markBusyKeys -- TMB-07 version.
2469 
2470 
2471 
2472 // --------------------------------------------------------------------------
2473 // The code below is for SLHC studies of the CLCT algorithm (half-strips only).
2474 // --------------------------------------------------------------------------
2475 // SLHC version.
2476 std::vector<CSCCLCTDigi>
2478 {
2479  std::vector<CSCCLCTDigi> lctList;
2480 
2481  // Max. number of half-strips for this chamber.
2482  const int maxHalfStrips = 2 * numStrips + 1;
2483 
2484  if (infoV > 1) dumpDigis(halfstrip, 1, maxHalfStrips);
2485 
2486  enum { max_lcts = 2 };
2487 
2488  // keeps dead-time zones around key halfstrips of triggered CLCTs
2490  for (int i = 0; i < CSCConstants::NUM_HALF_STRIPS; i++)
2491  for (int j = 0; j < MAX_CLCT_BINS; j++)
2492  busyMap[i][j] = false;
2493 
2494  std::vector<CSCCLCTDigi> lctListBX;
2495 
2497 
2498  // Fire half-strip one-shots for hit_persist bx's (4 bx's by default).
2499  pulseExtension(halfstrip, maxHalfStrips, pulse);
2500 
2501  unsigned int start_bx = start_bx_shift;
2502  // Stop drift_delay bx's short of fifo_tbins since at later bx's we will
2503  // not have a full set of hits to start pattern search anyway.
2504  unsigned int stop_bx = fifo_tbins - drift_delay;
2505 
2506  // Allow for more than one pass over the hits in the time window.
2507  // Do search in every BX
2508  while (start_bx < stop_bx)
2509  {
2510  lctListBX.clear();
2511 
2512  // All half-strip pattern envelopes are evaluated simultaneously, on every clock cycle.
2513  int first_bx = 999;
2514  bool pre_trig = preTrigger(pulse, start_bx, first_bx);
2515 
2516  // If any of half-strip envelopes has enough layers hit in it, TMB
2517  // will pre-trigger.
2518  if (pre_trig)
2519  {
2520  if (infoV > 1)
2521  LogTrace("CSCCathodeLCTProcessor") << "..... pretrigger at bx = " << first_bx << "; waiting drift delay .....";
2522 
2523  // TMB latches LCTs drift_delay clocks after pretrigger.
2524  int latch_bx = first_bx + drift_delay;
2525  bool hits_in_time = ptnFinding(pulse, maxHalfStrips, latch_bx);
2526  if (infoV > 1)
2527  {
2528  if (hits_in_time)
2529  {
2530  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < maxHalfStrips; hstrip++)
2531  {
2532  if (nhits[hstrip] > 0)
2533  {
2534  LogTrace("CSCCathodeLCTProcessor") << " bx = " << std::setw(2) << latch_bx << " --->" << " halfstrip = "
2535  << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip] << " nhits = " << nhits[hstrip];
2536  }
2537  }
2538  }
2539  }
2540  // The pattern finder runs continuously, so another pre-trigger
2541  // could occur already at the next bx.
2542  start_bx = first_bx + 1;
2543 
2544  // 2 possible LCTs per CSC x 7 LCT quantities per BX
2545  int keystrip_data[max_lcts][7] = {{0}};
2546 
2547  // Quality for sorting.
2548  int quality[CSCConstants::NUM_HALF_STRIPS];
2549  int best_halfstrip[max_lcts], best_quality[max_lcts];
2550  for (int ilct = 0; ilct < max_lcts; ilct++)
2551  {
2552  best_halfstrip[ilct] = -1;
2553  best_quality[ilct] = 0;
2554  }
2555 
2556  bool pretrig_zone[CSCConstants::NUM_HALF_STRIPS];
2557 
2558  // Calculate quality from pattern id and number of hits, and
2559  // simultaneously select best-quality LCT.
2560  if (hits_in_time)
2561  {
2562  // first, mark half-strip zones around pretriggers
2563  // that happened at the current first_bx
2564  for (int hstrip = 0; hstrip < CSCConstants::NUM_HALF_STRIPS; hstrip++)
2565  pretrig_zone[hstrip] = 0;
2566  for (int hstrip = 0; hstrip < CSCConstants::NUM_HALF_STRIPS; hstrip++)
2567  {
2568  if (ispretrig[hstrip])
2569  {
2570  int min_hs = hstrip - pretrig_trig_zone;
2571  int max_hs = hstrip + pretrig_trig_zone;
2572  if (min_hs < 0)
2573  min_hs = 0;
2574  if (max_hs > CSCConstants::NUM_HALF_STRIPS - 1)
2575  max_hs = CSCConstants::NUM_HALF_STRIPS - 1;
2576  for (int hs = min_hs; hs <= max_hs; hs++)
2577  pretrig_zone[hs] = 1;
2578  if (infoV > 1)
2579  LogTrace("CSCCathodeLCTProcessor") << " marked pretrigger halfstrip zone [" << min_hs << "," << max_hs << "]";
2580  }
2581  }
2582 
2583  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < maxHalfStrips; hstrip++)
2584  {
2585  // The bend-direction bit pid[0] is ignored (left and right bends have equal quality).
2586  quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
2587  // do not consider halfstrips:
2588  // - out of pretrigger-trigger zones
2589  // - in busy zones from previous trigger
2590  if (quality[hstrip] > best_quality[0] &&
2591  pretrig_zone[hstrip] &&
2592  !busyMap[hstrip][first_bx] )
2593  {
2594  best_halfstrip[0] = hstrip;
2595  best_quality[0] = quality[hstrip];
2596  if (infoV > 1)
2597  {
2598  LogTrace("CSCCathodeLCTProcessor") << " 1st CLCT: halfstrip = " << std::setw(3) << hstrip << " quality = "
2599  << std::setw(3) << quality[hstrip] << " best halfstrip = " << std::setw(3) << best_halfstrip[0]
2600  << " best quality = " << std::setw(3) << best_quality[0];
2601  }
2602  }
2603  }
2604  }
2605 
2606  // If 1st best CLCT is found, look for the 2nd best.
2607  if (best_halfstrip[0] >= 0)
2608  {
2609  // Mark keys near best CLCT as busy by setting their quality to zero, and repeat the search.
2610  markBusyKeys(best_halfstrip[0], best_pid[best_halfstrip[0]], quality);
2611 
2612  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < maxHalfStrips; hstrip++)
2613  {
2614  if (quality[hstrip] > best_quality[1] &&
2615  pretrig_zone[hstrip] &&
2616  !busyMap[hstrip][first_bx] )
2617  {
2618  best_halfstrip[1] = hstrip;
2619  best_quality[1] = quality[hstrip];
2620  if (infoV > 1)
2621  {
2622  LogTrace("CSCCathodeLCTProcessor") << " 2nd CLCT: halfstrip = " << std::setw(3) << hstrip << " quality = "
2623  << std::setw(3) << quality[hstrip] << " best halfstrip = " << std::setw(3) << best_halfstrip[1]
2624  << " best quality = " << std::setw(3) << best_quality[1];
2625  }
2626  }
2627  }
2628 
2629  // Pattern finder.
2630  bool ptn_trig = false;
2631  for (int ilct = 0; ilct < max_lcts; ilct++)
2632  {
2633  int best_hs = best_halfstrip[ilct];
2634  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern)
2635  {
2636  int bx = first_bx;
2637  int fbx = first_bx_corrected[best_hs];
2638  if (use_corrected_bx) {
2639  bx = fbx;
2640  fbx = first_bx;
2641  }
2642  ptn_trig = true;
2643  keystrip_data[ilct][CLCT_PATTERN] = best_pid[best_hs];
2644  keystrip_data[ilct][CLCT_BEND] = pattern2007[best_pid[best_hs]][NUM_PATTERN_HALFSTRIPS];
2645  // Remove stagger if any.
2646  keystrip_data[ilct][CLCT_STRIP] = best_hs - stagger[CSCConstants::KEY_CLCT_LAYER - 1];
2647  keystrip_data[ilct][CLCT_BX] = bx;
2648  keystrip_data[ilct][CLCT_STRIP_TYPE] = 1; // obsolete
2649  keystrip_data[ilct][CLCT_QUALITY] = nhits[best_hs];
2650  keystrip_data[ilct][CLCT_CFEB] = keystrip_data[ilct][CLCT_STRIP] / cfeb_strips[1];
2651  int halfstrip_in_cfeb = keystrip_data[ilct][CLCT_STRIP] - cfeb_strips[1] * keystrip_data[ilct][CLCT_CFEB];
2652 
2653  if (infoV > 1)
2654  LogTrace("CSCCathodeLCTProcessor") << " Final selection: ilct " << ilct << " key halfstrip "
2655  << keystrip_data[ilct][CLCT_STRIP] << " quality " << keystrip_data[ilct][CLCT_QUALITY] << " pattern "
2656  << keystrip_data[ilct][CLCT_PATTERN] << " bx " << keystrip_data[ilct][CLCT_BX];
2657 
2658  CSCCLCTDigi thisLCT(1, keystrip_data[ilct][CLCT_QUALITY], keystrip_data[ilct][CLCT_PATTERN],
2659  keystrip_data[ilct][CLCT_STRIP_TYPE], keystrip_data[ilct][CLCT_BEND], halfstrip_in_cfeb,
2660  keystrip_data[ilct][CLCT_CFEB], keystrip_data[ilct][CLCT_BX]);
2661  thisLCT.setFullBX(fbx);
2662  lctList.push_back(thisLCT);
2663  lctListBX.push_back(thisLCT);
2664  }
2665  }
2666 
2667  // state-machine
2668  if (ptn_trig)
2669  {
2670  // Once there was a trigger, CLCT pre-trigger state machine checks the number of hits
2671  // that lie on a key halfstrip pattern template at every bx, and waits for it to drop below threshold.
2672  // During that time no CLCTs could be found with its key halfstrip in the area of
2673  // [clct_key-clct_state_machine_zone, clct_key+clct_state_machine_zone]
2674  // starting from first_bx+1.
2675  // The search for CLCTs resumes only when the number of hits on key halfstrip drops below threshold.
2676  for (unsigned int ilct = 0; ilct < lctListBX.size(); ilct++)
2677  {
2678  int key_hstrip = lctListBX[ilct].getKeyStrip() + stagger[CSCConstants::KEY_CLCT_LAYER - 1];
2679 
2680  int delta_hs = clct_state_machine_zone;
2682  delta_hs = pattern2007[lctListBX[ilct].getPattern()][NUM_PATTERN_HALFSTRIPS + 1] - 1;
2683 
2684  int min_hstrip = key_hstrip - delta_hs;
2685  int max_hstrip = key_hstrip + delta_hs;
2686 
2687  if (min_hstrip < stagger[CSCConstants::KEY_CLCT_LAYER - 1])
2688  min_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1];
2689  if (max_hstrip > maxHalfStrips)
2690  max_hstrip = maxHalfStrips;
2691 
2692  if (infoV > 2)
2693  LogTrace("CSCCathodeLCTProcessor") << " marking post-trigger zone after bx=" << lctListBX[ilct].getBX() << " ["
2694  << min_hstrip << "," << max_hstrip << "]";
2695 
2696  // Stop checking drift_delay bx's short of fifo_tbins since
2697  // at later bx's we won't have a full set of hits for a
2698  // pattern search anyway.
2699  //int stop_time = fifo_tbins - drift_delay;
2700  // -- no, need to extend busyMap over fifo_tbins - drift_delay
2701  for (size_t bx = first_bx + 1; bx < fifo_tbins; bx++)
2702  {
2703  bool busy_bx = false;
2704  if (bx <= (size_t)latch_bx)
2705  busy_bx = true; // always busy before drift time
2706  if (!busy_bx)
2707  {
2708  bool hits_in_time = ptnFinding(pulse, maxHalfStrips, bx);
2709  if (hits_in_time && nhits[key_hstrip] >= nplanes_hit_pattern)
2710  busy_bx = true;
2711  if (infoV > 2)
2712  LogTrace("CSCCathodeLCTProcessor") << " at bx=" << bx << " hits_in_time=" << hits_in_time << " nhits="
2713  << nhits[key_hstrip];
2714  }
2715  if (infoV > 2)
2716  LogTrace("CSCCathodeLCTProcessor") << " at bx=" << bx << " busy=" << busy_bx;
2717  if (busy_bx)
2718  for (int hstrip = min_hstrip; hstrip <= max_hstrip; hstrip++)
2719  busyMap[hstrip][bx] = true;
2720  else
2721  break;
2722  }
2723  }
2724  } // if (ptn_trig)
2725  }
2726  }
2727  else
2728  {
2729  start_bx = first_bx + 1; // no dead time
2730  }
2731  }
2732 
2733  return lctList;
2734 } // findLCTs -- SLHC version.
2735 
2736 
2737 // --------------------------------------------------------------------------
2738 // Auxiliary code.
2739 // --------------------------------------------------------------------------
2740 // Dump of configuration parameters.
2742  std::ostringstream strm;
2743  strm << "\n";
2744  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
2745  strm << "+ CLCT configuration parameters: +\n";
2746  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
2747  strm << " fifo_tbins [total number of time bins in DAQ readout] = "
2748  << fifo_tbins << "\n";
2749  strm << " fifo_pretrig [start time of cathode raw hits in DAQ readout] = "
2750  << fifo_pretrig << "\n";
2751  strm << " hit_persist [duration of signal pulse, in 25 ns bins] = "
2752  << hit_persist << "\n";
2753  strm << " drift_delay [time after pre-trigger before TMB latches LCTs] = "
2754  << drift_delay << "\n";
2755  strm << " nplanes_hit_pretrig [min. number of layers hit for pre-trigger] = "
2756  << nplanes_hit_pretrig << "\n";
2757  strm << " nplanes_hit_pattern [min. number of layers hit for trigger] = "
2758  << nplanes_hit_pattern << "\n";
2759  if (isTMB07) {
2760  strm << " pid_thresh_pretrig [lower threshold on pattern id] = "
2761  << pid_thresh_pretrig << "\n";
2762  strm << " min_separation [region of busy key strips] = "
2763  << min_separation << "\n";
2764  }
2765  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
2766  LogDebug("CSCCathodeLCTProcessor") << strm.str();
2767  //std::cerr<<strm.str()<<std::endl;
2768 }
2769 
2770 // Reasonably nice dump of digis on half-strips and di-strips.
2771 void CSCCathodeLCTProcessor::dumpDigis(const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], const int stripType, const int nStrips) const
2772 {
2773  LogDebug("CSCCathodeLCTProcessor")
2774  << "ME" << ((theEndcap == 1) ? "+" : "-")
2775  << theStation << "/" << theRing << "/" << theChamber
2776  << " strip type " << stripType << " nStrips " << nStrips;
2777 
2778  std::ostringstream strstrm;
2779  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
2780  if (i_strip%10 == 0) {
2781  if (i_strip < 100) strstrm << i_strip/10;
2782  else strstrm << (i_strip-100)/10;
2783  }
2784  else strstrm << " ";
2785  if ((i_strip+1)%cfeb_strips[stripType] == 0) strstrm << " ";
2786  }
2787  strstrm << "\n";
2788  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
2789  strstrm << i_strip%10;
2790  if ((i_strip+1)%cfeb_strips[stripType] == 0) strstrm << " ";
2791  }
2792  for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
2793  strstrm << "\n";
2794  for (int i_strip = 0; i_strip < nStrips; i_strip++) {
2795  if (!strip[i_layer][i_strip].empty()) {
2796  std::vector<int> bx_times = strip[i_layer][i_strip];
2797  // Dump only the first in time.
2798  strstrm << std::hex << bx_times[0] << std::dec;
2799  }
2800  else {
2801  strstrm << "-";
2802  }
2803  if ((i_strip+1)%cfeb_strips[stripType] == 0) strstrm << " ";
2804  }
2805  }
2806  LogTrace("CSCCathodeLCTProcessor") << strstrm.str();
2807 }
2808 
2809 // Returns vector of read-out CLCTs, if any. Starts with the vector
2810 // of all found CLCTs and selects the ones in the read-out time window.
2811 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::readoutCLCTs() {
2812  std::vector<CSCCLCTDigi> tmpV;
2813 
2814  // The start time of the L1A*CLCT coincidence window should be
2815  // related to the fifo_pretrig parameter, but I am not completely
2816  // sure how. For now, just choose it such that the window is
2817  // centered at bx=7. This may need further tweaking if the value of
2818  // tmb_l1a_window_size changes.
2819  // static int fpga_latency = 3;
2820  // static int early_tbins = fifo_pretrig - fpga_latency;
2821  // static int early_tbins = 4;
2822 
2823  // The number of CLCT bins in the read-out is given by the
2824  // tmb_l1a_window_size parameter, but made even by setting the LSB
2825  // of tmb_l1a_window_size to 0.
2826  //
2827  static std::atomic<int> lct_bins;
2829  static std::atomic<int> late_tbins;
2830  late_tbins = early_tbins + lct_bins;
2831 
2832  static std::atomic<int> ifois{0};
2833  if (ifois == 0) {
2834  if (infoV >= 0 && early_tbins < 0) {
2835  edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
2836  << "+++ early_tbins = " << early_tbins
2837  << "; in-time CLCTs are not getting read-out!!! +++" << "\n";
2838  }
2839 
2840  if (late_tbins > MAX_CLCT_BINS-1) {
2841  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
2842  << "+++ Allowed range of time bins, [0-" << late_tbins
2843  << "] exceeds max allowed, " << MAX_CLCT_BINS-1 << " +++\n"
2844  << "+++ Set late_tbins to max allowed +++\n";
2845  late_tbins = MAX_CLCT_BINS-1;
2846  }
2847  ifois = 1;
2848  }
2849 
2850  // Start from the vector of all found CLCTs and select those within
2851  // the CLCT*L1A coincidence window.
2852  int bx_readout = -1;
2853  std::vector<CSCCLCTDigi> all_lcts = getCLCTs();
2854  for (std::vector <CSCCLCTDigi>::const_iterator plct = all_lcts.begin();
2855  plct != all_lcts.end(); plct++) {
2856  if (!plct->isValid()) continue;
2857 
2858  int bx = (*plct).getBX();
2859  // Skip CLCTs found too early relative to L1Accept.
2860  if (bx <= early_tbins) {
2861  if (infoV > 1) LogDebug("CSCCathodeLCTProcessor")
2862  << " Do not report CLCT on key halfstrip " << plct->getKeyStrip()
2863  << ": found at bx " << bx << ", whereas the earliest allowed bx is "
2864  << early_tbins+1;
2865  continue;
2866  }
2867 
2868  // Skip CLCTs found too late relative to L1Accept.
2869  if (bx > late_tbins) {
2870  if (infoV > 1) LogDebug("CSCCathodeLCTProcessor")
2871  << " Do not report CLCT on key halfstrip " << plct->getKeyStrip()
2872  << ": found at bx " << bx << ", whereas the latest allowed bx is "
2873  << late_tbins;
2874  continue;
2875  }
2876 
2877  // If (readout_earliest_2) take only CLCTs in the earliest bx in the read-out window:
2878  // in digi->raw step, LCTs have to be packed into the TMB header, and
2879  // currently there is room just for two.
2880  if (readout_earliest_2) {
2881  if (bx_readout == -1 || bx == bx_readout) {
2882  tmpV.push_back(*plct);
2883  if (bx_readout == -1) bx_readout = bx;
2884  }
2885  }
2886  else tmpV.push_back(*plct);
2887  }
2888  return tmpV;
2889 }
2890 
2891 // Returns vector of all found CLCTs, if any. Used for ALCT-CLCT matching.
2892 std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::getCLCTs() {
2893  std::vector<CSCCLCTDigi> tmpV;
2894  for (int bx = 0; bx < MAX_CLCT_BINS; bx++) {
2895  if (bestCLCT[bx].isValid()) tmpV.push_back(bestCLCT[bx]);
2896  if (secondCLCT[bx].isValid()) tmpV.push_back(secondCLCT[bx]);
2897  }
2898  return tmpV;
2899 }
2900 
2901 
2902 // --------------------------------------------------------------------------
2903 // Test routines. Mostly for older versions of the algorithm and outdated.
2904 // --------------------------------------------------------------------------
2906  // Author: Jason Mumford (mumford@physics.ucla.edu)
2907  // This routine tests the distripStagger routine.
2908  // @@
2909  bool debug = true;
2910  int test_triad[CSCConstants::NUM_DI_STRIPS], test_time[CSCConstants::NUM_DI_STRIPS];
2911  int test_digi[CSCConstants::NUM_DI_STRIPS];
2912  int distrip = 0;
2913  test_triad[distrip] = 3; //After routine, I expect 4
2914  test_triad[distrip+1] = 3; // 4
2915  test_triad[distrip+2] = 3; // 4
2916  test_triad[distrip+3] = 3; // 4
2917  test_triad[distrip+4] = 3; // 4
2918  test_triad[distrip+5] = 3; // 4
2919  test_triad[distrip+6] = 3; // 4
2920  test_triad[distrip+7] = 3; // 4
2921  test_triad[distrip+8] = 3; // 4
2922  test_triad[distrip+9] = 3; // 4
2923  test_triad[distrip+10] = 2; // 2
2924 
2925  test_time[distrip] = 4; // "" "" 0
2926  test_time[distrip+1] = 10; // 4
2927  test_time[distrip+2] = 2; // 10
2928  test_time[distrip+3] = 0; // 2
2929  test_time[distrip+4] = 6; // 2
2930  test_time[distrip+5] = 8; // 2
2931  test_time[distrip+6] = 10; // 2
2932  test_time[distrip+7] = 1; // 2
2933  test_time[distrip+8] = 8; // 2
2934  test_time[distrip+9] = 5; // 2
2935  test_time[distrip+10] = 6; // 2
2936 
2937  std::cout << "\n ------------------------------------------------- \n";
2938  std::cout << "!!!!!!Testing distripStagger routine!!!!!!" << std::endl;
2939  std::cout << "Values before distripStagger routine:" << std::endl;
2940  for (int i=distrip; i<distrip+11; i++){
2941  test_digi[i] = 999;
2942  std::cout << "test_triad[" << i << "] = " << test_triad[i];
2943  std::cout << " test_time[" << i << "] = " << test_time[i] << std::endl;
2944  }
2945  distripStagger(test_triad, test_time, test_digi, distrip, debug);
2946  std::cout << "Values after distripStagger routine:" << std::endl;
2947  for (int i=distrip; i<distrip+11; i++){
2948  std::cout << "test_triad[" << i << "] = " << test_triad[i];
2949  std::cout << " test_time[" << i << "] = " << test_time[i] << std::endl;
2950  }
2951  std::cout << "\n ------------------------------------------------- \n \n";
2952 }
2953 
2955  // test to make sure what goes into an LCT is what comes out.
2956  for (int ptn = 0; ptn < 8; ptn++) {
2957  for (int bend = 0; bend < 2; bend++) {
2958  for (int cfeb = 0; cfeb < MAX_CFEBS; cfeb++) {
2959  for (int key_strip = 0; key_strip < 32; key_strip++) {
2960  for (int bx = 0; bx < 7; bx++) {
2961  for (int stripType = 0; stripType < 2; stripType++) {
2962  for (int quality = 3; quality < 6; quality++) {
2963  CSCCLCTDigi thisLCT(1, quality, ptn, stripType, bend,
2964  key_strip, cfeb, bx);
2965  if (ptn != thisLCT.getPattern())
2966  LogTrace("CSCCathodeLCTProcessor")
2967  << "pattern mismatch: " << ptn << " "
2968  << thisLCT.getPattern();
2969  if (bend != thisLCT.getBend())
2970  LogTrace("CSCCathodeLCTProcessor")
2971  << "bend mismatch: " << bend << " " << thisLCT.getBend();
2972  if (cfeb != thisLCT.getCFEB())
2973  LogTrace("CSCCathodeLCTProcessor")
2974  << "cfeb mismatch: " << cfeb << " " << thisLCT.getCFEB();
2975  if (key_strip != thisLCT.getKeyStrip())
2976  LogTrace("CSCCathodeLCTProcessor")
2977  << "strip mismatch: " << key_strip << " "
2978  << thisLCT.getKeyStrip();
2979  if (bx != thisLCT.getBX())
2980  LogTrace("CSCCathodeLCTProcessor")
2981  << "bx mismatch: " << bx << " " << thisLCT.getBX();
2982  if (stripType != thisLCT.getStripType())
2983  LogTrace("CSCCathodeLCTProcessor")
2984  << "Strip Type mismatch: " << stripType << " "
2985  << thisLCT.getStripType();
2986  if (quality != thisLCT.getQuality())
2987  LogTrace("CSCCathodeLCTProcessor")
2988  << "quality mismatch: " << quality << " "
2989  << thisLCT.getQuality();
2990  }
2991  }
2992  }
2993  }
2994  }
2995  }
2996  }
2997 }
2998 
3000  // @@
3001  std::cout<<" Printing patterns for Cathode LCT"<<std::endl;
3002  std::cout<<" ";
3003  for (int patternNum = 0; patternNum < CSCConstants::NUM_CLCT_PATTERNS_PRE_TMB07; patternNum++) {
3004  std::cout<<" Pattern "<<patternNum<<" ";
3005  }
3006  std::cout<<std::endl;
3007  std::cout<<" Layer ";
3008  for (int patternNum = 0; patternNum < CSCConstants::NUM_CLCT_PATTERNS_PRE_TMB07; patternNum++) {
3009  std::cout<<" Bend "<<(pattern[patternNum][NUM_PATTERN_STRIPS]==0 ? "L": "R")<<" ";
3010  }
3011  std::cout<<std::endl;
3012  for (int layer = 0; layer < CSCConstants::NUM_LAYERS; layer++) {
3013  for (int patternNum = 0; patternNum < CSCConstants::NUM_CLCT_PATTERNS_PRE_TMB07; patternNum++) {
3014  if (patternNum == 0) std::cout<<" "<<layer<<" ";
3015  if ((isTMB07 && layer != CSCConstants::KEY_CLCT_LAYER-1) ||
3016  (!isTMB07 && layer != CSCConstants::KEY_CLCT_LAYER_PRE_TMB07-1)) {//that old counting from 1 vs 0 thing.
3017  int minStrip =0;
3018  if ((isTMB07 && layer < CSCConstants::KEY_CLCT_LAYER-1) ||
3020  minStrip = 3*layer;
3021  } else {
3022  minStrip = 3*layer - 2;// since on the key layer we only have 1 strip
3023  }
3024  for (int strip = minStrip; strip < minStrip + 3; strip++) {
3025  if (layer == pattern[patternNum][strip]) {
3026  std::cout<<"X";
3027  } else {
3028  std::cout<<"_";
3029  }
3030  }
3031  } else {// on the key layer we always have a hit, right?
3032  std::cout<<" X ";
3033  }
3034  std::cout<<" ";
3035  }
3036  std::cout<<std::endl;
3037  }
3038 }
3039 
3041 //generate all possible combinations of hits in a given area and see what we find.
3042 // Benn Tannenbaum 21 June 2001
3043 
3044  //there are 16 strips in our uber-pattern, each of which can be on or off.
3045  // 2^16 = 65536
3046  for (int possibleHits = 0; possibleHits < 65536; possibleHits++) {
3047  std::vector<int> stripsHit[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS];
3048  //assign one bit to each strip in an array. I'll start centered around strip 10.
3049  stripsHit[0][ 9].push_back(( possibleHits & 1 ) != 0); // 2^0
3050  stripsHit[0][10].push_back(( possibleHits & 2 ) != 0); // 2^1
3051  stripsHit[0][11].push_back(( possibleHits & 4 ) != 0); // 2^2
3052  stripsHit[1][ 9].push_back(( possibleHits & 8 ) != 0); // 2^3
3053  stripsHit[1][10].push_back(( possibleHits & 16 ) != 0); // 2^4
3054  stripsHit[1][11].push_back(( possibleHits & 32 ) != 0); // 2^5
3055  stripsHit[2][ 9].push_back(( possibleHits & 64 ) != 0); // 2^6
3056  stripsHit[2][10].push_back(( possibleHits & 128 ) != 0); // 2^7
3057  stripsHit[2][11].push_back(( possibleHits & 256 ) != 0); // 2^8
3058  stripsHit[3][10].push_back(( possibleHits & 512 ) != 0); // 2^9
3059  stripsHit[4][ 9].push_back(( possibleHits & 1024 ) != 0); // 2^10
3060  stripsHit[4][10].push_back(( possibleHits & 2048 ) != 0); // 2^11
3061  stripsHit[4][11].push_back(( possibleHits & 4096 ) != 0); // 2^12
3062  stripsHit[5][ 9].push_back(( possibleHits & 8192 ) != 0); // 2^13
3063  stripsHit[5][10].push_back(( possibleHits & 16384 ) != 0); // 2^14
3064  stripsHit[5][11].push_back(( possibleHits & 32768 ) != 0); // 2^15
3065  int numLayersHit = findNumLayersHit(stripsHit);
3066  std::vector <CSCCLCTDigi> results = findLCTs(stripsHit, 1);
3067 // print out whatever we find-- but only ones where 4 or more layers are hit
3068 // OR ones where we find something
3069 // key: X a hit there and was used to find pattern
3070 // x a hit not involved in pattern
3071 // _ empty strip
3072 // o a hit was there, but no pattern was found
3073  if (numLayersHit > 3 || results.size() > 0) {
3074  std::cout<<"Input "<<possibleHits<<"/"<< 65536 <<" # Found Patterns "<<results.size()<<std::endl<<" ";
3075  for (int layer = 0; layer < CSCConstants::NUM_LAYERS; layer++) {
3076  if ((isTMB07 && layer != CSCConstants::KEY_CLCT_LAYER - 1) ||
3077  (!isTMB07 && layer != CSCConstants::KEY_CLCT_LAYER_PRE_TMB07 - 1)) {
3078  for (int strip = 9; strip < 12; strip++) {
3079  if (!stripsHit[layer][strip].empty()) {
3080  if (results.size() > 0) {
3081  int thePatternStrip = strip - (results[0].getKeyStrip() - 2) + 3*layer;
3082  if ((isTMB07 && layer>=CSCConstants::KEY_CLCT_LAYER) ||
3084  thePatternStrip -= 2;
3085 
3086  if (pattern[results[0].getPattern()][thePatternStrip] == layer)
3087  {
3088  std::cout<<"X";
3089  } else {
3090  std::cout<<"x";
3091  }
3092  } else {
3093  std::cout<<"o";
3094  }
3095  } else {
3096  std::cout<<"_";
3097  }
3098  }
3099  std::cout<<" ";
3100  for (unsigned int output = 0; output < results.size(); output++) {
3101  int minStrip;
3102  if ((isTMB07 && layer < CSCConstants::KEY_CLCT_LAYER-1) ||
3104  minStrip = 3*layer;
3105  } else {
3106  minStrip = 3*layer - 2;// since on the key layer we only have 1 strip
3107  }
3108  for (int strip = minStrip; strip < minStrip + 3; strip++) {
3109  if (layer == pattern[results[output].getPattern()][strip]) {
3110  std::cout<<"X";
3111  } else {
3112  std::cout<<"_";
3113  }
3114  }
3115  std::cout<<" ";
3116  }
3117  } else {
3118  if (!stripsHit[layer][10].empty()) {
3119  std::cout<<" X ";
3120  } else {
3121  std::cout<<" _ ";
3122  }
3123  for (unsigned int output = 0; output < results.size(); output++)
3124  std::cout<<" X ";
3125  }
3126  if (layer < static_cast<int>(results.size()) ) {
3127  std::cout<<results[layer];
3128  std::cout<<" ";
3129  } else {
3130  std::cout<<" "<<std::endl<<" ";
3131  }
3132  }
3133  }
3134  }
3135 }
3136 
3139  int number = 0;
3140  for (int layer = 0; layer < CSCConstants::NUM_LAYERS; layer++) {
3141  if ((!stripsHit[layer][ 9].empty()) ||
3142  (!stripsHit[layer][10].empty()) ||
3143  (!stripsHit[layer][11].empty()) ) number++;
3144  }
3145  return number;
3146 }
#define LogDebug(id)
int getQuality() const
return quality of a pattern (number of layers hit!)
Definition: CSCCLCTDigi.h:33
void getPattern(int pattern_num, int strip_value[NUM_PATTERN_STRIPS], int bx_time, int &quality, int &bend)
static const unsigned int def_drift_delay
CSCCLCTDigi secondCLCT[MAX_CLCT_BINS]
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
float dt
Definition: AMPTWrapper.h:126
int i
Definition: DBlmapReader.cc:9
std::vector< CSCCLCTDigi > readoutCLCTs()
static const unsigned int def_fifo_tbins
int getStrip() const
Get the strip number.
std::vector< CSCCLCTDigi > findLCTs(const std::vector< int > strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], int stripType)
CSCChamber * chamber(unsigned endcap, unsigned station, unsigned sector, unsigned subsector, unsigned tcscid) const
Return the CSCChamber for a corresponding endcap/station/sector/subsector/trigger cscid...
static const int cfeb_strips[2]
unsigned int clctHitPersist() const
int first_bx_corrected[CSCConstants::NUM_HALF_STRIPS]
void getKeyStripData(const std::vector< int > strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], int keystrip_data[CSCConstants::NUM_HALF_STRIPS][7], int nStrips, int first_bx, int &best_strip, int stripType)
void markBusyKeys(const int best_hstrip, const int best_patid, int quality[CSCConstants::NUM_HALF_STRIPS])
void readComparatorDigis(std::vector< int >halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], std::vector< int > distrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS])
unsigned int clctNplanesHitPattern() const
int findNumLayersHit(std::vector< int > stripsHit[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS])
void latchLCTs(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], int keyStrip[MAX_CFEBS], unsigned int nhits[MAX_CFEBS], const int stripType, const int nStrips, const int bx_time)
static const unsigned int def_min_separation
int numberOfStrips() const
std::vector< CSCCLCTDigi > findLCTsSLHC(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS])
CSCCLCTDigi bestCLCT[MAX_CLCT_BINS]
unsigned int clctMinSeparation() const
int getComparator() const
Get Comparator readings.
unsigned int clctNplanesHitPretrig() const
static const unsigned int def_nplanes_hit_pretrig
int getTimeBin() const
Return bin number of first time bin which is ON. Counts from 0.
static int ringFromTriggerLabels(int station, int triggerCSCID)
int getStripType() const
return striptype
Definition: CSCCLCTDigi.h:39
unsigned int clctDriftDelay() const
int getBend() const
return bend
Definition: CSCCLCTDigi.h:42
static const unsigned int def_pid_thresh_pretrig
static void distripStagger(int stag_triad[CSCConstants::MAX_NUM_STRIPS], int stag_time[CSCConstants::MAX_NUM_STRIPS], int stag_digi[CSCConstants::MAX_NUM_STRIPS], int i_distrip, bool debug=false)
static CSCTriggerGeomManager * get()
unsigned int clctPidThreshPretrig() const
int getCFEB() const
return Key CFEB ID
Definition: CSCCLCTDigi.h:48
static const int pattern2007[CSCConstants::NUM_CLCT_PATTERNS][NUM_PATTERN_HALFSTRIPS+2]
static const unsigned int def_tmb_l1a_window_size
int getBX() const
return BX
Definition: CSCCLCTDigi.h:51
static const int pattern[CSCConstants::NUM_CLCT_PATTERNS_PRE_TMB07][NUM_PATTERN_STRIPS+1]
bool getDigis(const CSCComparatorDigiCollection *compdc)
static const unsigned int def_nplanes_hit_pattern
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:39
unsigned int clctFifoPretrig() const
#define LogTrace(id)
tuple conf
Definition: dbtoconf.py:185
void dumpDigis(const std::vector< int > strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], const int stripType, const int nStrips) const
void priorityEncode(const int h_keyStrip[MAX_CFEBS], const unsigned int h_nhits[MAX_CFEBS], const int d_keyStrip[MAX_CFEBS], const unsigned int d_nhits[MAX_CFEBS], int keystrip_data[2][7])
void pulseExtension(const std::vector< int > time[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], const int nStrips, unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS])
int stagger() const
#define debug
Definition: HDRShower.cc:19
static const unsigned int def_fifo_pretrig
int getPattern() const
return pattern
Definition: CSCCLCTDigi.h:36
std::vector< int > thePreTriggerBXs
tuple pid
Definition: sysUtil.py:22
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:77
unsigned int best_pid[CSCConstants::NUM_HALF_STRIPS]
std::vector< CSCCLCTDigi > run(const CSCComparatorDigiCollection *compdc)
unsigned int clctFifoTbins() const
#define begin
Definition: vmac.h:30
static const int pattern2007_offset[NUM_PATTERN_HALFSTRIPS]
list key
Definition: combine.py:13
bool hitIsGood(int hitTime, int BX)
unsigned int nhits[CSCConstants::NUM_HALF_STRIPS]
void clear()
clear this CLCT
Definition: CSCCLCTDigi.cc:58
std::vector< CSCComparatorDigi > digiV[CSCConstants::NUM_LAYERS]
tuple cout
Definition: gather_cfg.py:121
std::pair< const_iterator, const_iterator > Range
static const int pre_hit_pattern[2][NUM_PATTERN_STRIPS]
int getKeyStrip() const
Definition: CSCCLCTDigi.h:65
bool ptnFinding(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], const int nStrips, const unsigned int bx_time)
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:47
tuple size
Write out results.
static int chamberFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station, int TriggerCSCID)
std::vector< CSCCLCTDigi > getCLCTs()
void setConfigParameters(const CSCDBL1TPParameters *conf)
bool ispretrig[CSCConstants::NUM_HALF_STRIPS]
bool preTrigger(const std::vector< int > strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], const int stripType, const int nStrips, int &first_bx)
bool preTrigLookUp(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS], const int stripType, const int nStrips, const unsigned int bx_time)
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting CLCTs.
Definition: CSCCLCTDigi.h:71