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