CMS 3D CMS Logo

CSCUpgradeCathodeLCTProcessor.cc
Go to the documentation of this file.
2 
3 #include <iomanip>
4 
6  unsigned station,
7  unsigned sector,
8  unsigned subsector,
9  unsigned chamber,
11  : CSCCathodeLCTProcessor(endcap, station, sector, subsector, chamber, conf) {
12  if (!runPhase2_)
13  edm::LogError("CSCUpgradeCathodeLCTProcessor|ConfigError")
14  << "+++ Upgrade CSCUpgradeCathodeLCTProcessor constructed while runPhase2_ is not set! +++\n";
15 
16  // use of localized dead-time zones
17  use_dead_time_zoning_ = conf.clctParams().getParameter<bool>("useDeadTimeZoning");
18  clct_state_machine_zone_ = conf.clctParams().getParameter<unsigned int>("clctStateMachineZone");
19 
20  // how far away may trigger happen from pretrigger
21  pretrig_trig_zone_ = conf.clctParams().getParameter<unsigned int>("clctPretriggerTriggerZone");
22 }
23 
24 // --------------------------------------------------------------------------
25 // The code below is for Phase2 studies of the CLCT algorithm
26 // --------------------------------------------------------------------------
27 
28 // Phase2 version, add the feature of localized dead time zone for pretrigger
29 bool CSCUpgradeCathodeLCTProcessor::preTrigger(const int start_bx, int& first_bx) {
31  return CSCCathodeLCTProcessor::preTrigger(start_bx, first_bx);
32  }
33 
34  if (infoV > 1)
35  LogTrace("CSCUpgradeCathodeLCTProcessor")
36  << "....................PreTrigger, Phase2 version with localized dead time zone...........................";
37 
38  int nPreTriggers = 0;
39 
40  bool pre_trig = false;
41 
42  // Now do a loop over bx times to see (if/when) track goes over threshold
43  for (unsigned int bx_time = start_bx; bx_time < fifo_tbins; bx_time++) {
44  // For any given bunch-crossing, start at the lowest keystrip and look for
45  // the number of separate layers in the pattern for that keystrip that have
46  // pulses at that bunch-crossing time. Do the same for the next keystrip,
47  // etc. Then do the entire process again for the next bunch-crossing, etc
48  // until you find a pre-trigger.
49  std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer> > hits_in_patterns;
50  hits_in_patterns.clear();
51 
52  bool hits_in_time = patternFinding(bx_time, hits_in_patterns);
53  if (hits_in_time) {
54  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
55  if (infoV > 1) {
56  if (nhits[hstrip] > 0) {
57  LogTrace("CSCUpgradeCathodeLCTProcessor")
58  << " bx = " << std::setw(2) << bx_time << " --->"
59  << " halfstrip = " << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip]
60  << " nhits = " << nhits[hstrip];
61  }
62  }
63  // note that ispretrig_ is initialized in findLCT function
64  if (nhits[hstrip] >= nplanes_hit_pretrig && best_pid[hstrip] >= pid_thresh_pretrig &&
65  !busyMap_[hstrip][bx_time]) {
66  pre_trig = true;
67  ispretrig_[hstrip] = true;
68 
69  // write each pre-trigger to output
70  nPreTriggers++;
71  thePreTriggerDigis.push_back(constructPreCLCT(bx_time, hstrip, nPreTriggers));
72  }
73  // busy zone, keep pretriggering, ignore this
74  else if (nhits[hstrip] >= nplanes_hit_pretrig && best_pid[hstrip] >= pid_thresh_pretrig) {
75  ispretrig_[hstrip] = true;
76  if (infoV > 1)
77  LogTrace("CSCUpgradeCathodeLCTProcessor")
78  << " halfstrip " << std::setw(3) << hstrip << " in dead zone and is pretriggerred";
79  }
80  // no pretrigger on this halfstrip, release dead zone
81  else if (nhits[hstrip] < nplanes_hit_pretrig || best_pid[hstrip] < pid_thresh_pretrig) {
82  ispretrig_[hstrip] = false;
83  }
84  } // find all pretriggers
85 
86  // update dead zone
87  markBusyZone(bx_time);
88 
89  if (pre_trig) {
90  first_bx = bx_time; // bx at time of pretrigger
91  return true;
92  }
93  } else {
94  // no pattern found, remove all dead zone
96  }
97  } // end loop over bx times
98 
99  if (infoV > 1)
100  LogTrace("CSCUpgradeCathodeLCTProcessor") << "no pretrigger, returning \n";
101  first_bx = fifo_tbins;
102  return false;
103 } // preTrigger -- Phase2 version.
104 
105 // Phase2 version.
108  // run the original algorithm in case we do not use dead time zoning
110  return CSCCathodeLCTProcessor::findLCTs(halfstrip);
111  }
112 
113  std::vector<CSCCLCTDigi> lctList;
114 
115  // initialize the ispretrig_ before doing pretriggering
117 
118  if (infoV > 1)
119  dumpDigis(halfstrip);
120 
121  // keeps dead-time zones around key halfstrips of triggered CLCTs
123  for (int j = 0; j < CSCConstants::MAX_CLCT_TBINS; j++) {
124  busyMap_[i][j] = false;
125  }
126  }
127 
128  // Fire half-strip one-shots for hit_persist bx's (4 bx's by default).
129  pulseExtension(halfstrip);
130 
131  unsigned int start_bx = start_bx_shift;
132  // Stop drift_delay bx's short of fifo_tbins since at later bx's we will
133  // not have a full set of hits to start pattern search anyway.
134  unsigned int stop_bx = fifo_tbins - drift_delay;
135 
136  // Allow for more than one pass over the hits in the time window.
137  // Do search in every BX
138  while (start_bx < stop_bx) {
139  // temp CLCT objects
140  CSCCLCTDigi tempBestCLCT;
141  CSCCLCTDigi tempSecondCLCT;
142 
143  // All half-strip pattern envelopes are evaluated simultaneously, on every clock cycle.
144  int first_bx = 999;
145 
146  // Check for a pre-trigger. If so, find the first BX when the pre-trigger occurred
147  bool pre_trig = CSCUpgradeCathodeLCTProcessor::preTrigger(start_bx, first_bx);
148 
149  // If any of half-strip envelopes has enough layers hit in it, TMB
150  // will pre-trigger.
151  if (pre_trig) {
152  if (infoV > 1)
153  LogTrace("CSCUpgradeCathodeLCTProcessor")
154  << "..... pretrigger at bx = " << first_bx << "; waiting drift delay .....";
155 
156  // TMB latches LCTs drift_delay clocks after pretrigger.
157  int latch_bx = first_bx + drift_delay;
158 
159  // temporary container to keep track of the hits in the CLCT
160  std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer> > hits_in_patterns;
161  hits_in_patterns.clear();
162 
163  // We check if there is at least one key half strip for which at least
164  // one pattern id has at least the minimum number of hits
165  bool hits_in_time = patternFinding(latch_bx, hits_in_patterns);
166  if (infoV > 1) {
167  if (hits_in_time) {
168  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
169  if (nhits[hstrip] > 0) {
170  LogTrace("CSCUpgradeCathodeLCTProcessor")
171  << " bx = " << std::setw(2) << latch_bx << " --->"
172  << " halfstrip = " << std::setw(3) << hstrip << " best pid = " << std::setw(2) << best_pid[hstrip]
173  << " nhits = " << nhits[hstrip];
174  }
175  }
176  }
177  }
178 
179  // Quality for sorting.
182  for (int ilct = 0; ilct < CSCConstants::MAX_CLCTS_PER_PROCESSOR; ilct++) {
183  best_halfstrip[ilct] = -1;
184  best_quality[ilct] = 0;
185  }
186 
188 
189  // Calculate quality from pattern id and number of hits, and
190  // simultaneously select best-quality CLCT.
191  if (hits_in_time) {
192  // first, mark half-strip zones around pretriggers
193  // that happened at the current first_bx
194  markPreTriggerZone(pretrig_zone);
195 
196  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
197  /* The bend-direction bit pid[0] is ignored (left and right bends have equal quality).
198  This works both for the Run-2 patterns
199  - PID 2,3: 2 & 14 == 2, 3 & 14 == 2
200  - PID 4,5: 4 & 14 == 4, 3 & 14 == 4
201  - PID 6,7: 6 & 14 == 6, 3 & 14 == 6
202  - PID 8,9: 8 & 14 == 8, 3 & 14 == 8
203  - PID 10: 10 & 14 == 10
204  It also works for the Run-3 patterns:
205  - PID 0,1: 0 & 14 == 0, 1 & 14 == 0
206  - PID 2,3: 2 & 14 == 2, 3 & 14 == 2
207  - PID 4: 4 & 14 == 4
208  */
209  quality[hstrip] = (best_pid[hstrip] & 14) | (nhits[hstrip] << 5);
210  // do not consider halfstrips:
211  // - out of pretrigger-trigger zones
212  // - in busy zones from previous trigger
213  if (quality[hstrip] > best_quality[0] && pretrig_zone[hstrip] && !busyMap_[hstrip][first_bx]) {
214  best_halfstrip[0] = hstrip;
215  best_quality[0] = quality[hstrip];
216  // temporary alias
217  const int best_hs(best_halfstrip[0]);
218  const int best_pat(best_pid[best_hs]);
219  // construct a CLCT if the trigger condition has been met
220  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
221  // overwrite the current best CLCT
222  tempBestCLCT = constructCLCT(first_bx, best_hs, hits_in_patterns[best_hs][best_pat]);
223  }
224  }
225  }
226  }
227 
228  // If 1st best CLCT is found, look for the 2nd best.
229  if (best_halfstrip[0] >= 0) {
230  // Get the half-strip of the best CLCT in this BX that was put into the list.
231  // You do need to re-add the any stagger, because the busy keys are based on
232  // the pulse array which takes into account strip stagger!!!
233  const unsigned halfStripBestCLCT(tempBestCLCT.getKeyStrip() + stagger[CSCConstants::KEY_CLCT_LAYER - 1]);
234 
235  // Mark keys near best CLCT as busy by setting their quality to
236  // zero, and repeat the search.
237  //markBusyKeys(best_halfstrip[0], best_pid[best_halfstrip[0]], quality);
238  markBusyKeys(halfStripBestCLCT, best_pid[halfStripBestCLCT], quality);
239 
240  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
241  // we don't have to recalculate the quality for each half-strip
242  if (quality[hstrip] > best_quality[1] && pretrig_zone[hstrip] && !busyMap_[hstrip][first_bx]) {
243  best_halfstrip[1] = hstrip;
244  best_quality[1] = quality[hstrip];
245  // temporary alias
246  const int best_hs(best_halfstrip[1]);
247  const int best_pat(best_pid[best_hs]);
248  // construct a CLCT if the trigger condition has been met
249  if (best_hs >= 0 && nhits[best_hs] >= nplanes_hit_pattern) {
250  // overwrite the current second best CLCT
251  tempSecondCLCT = constructCLCT(first_bx, best_hs, hits_in_patterns[best_hs][best_pat]);
252  }
253  }
254  }
255 
256  // Sort bestCLCT and secondALCT by quality
257  // if qualities are the same, sort by run-2 or run-3 pattern
258  // if qualities and patterns are the same, sort by half strip number
259  bool changeOrder = false;
260 
261  unsigned qualityBest = 0, qualitySecond = 0;
262  unsigned patternBest = 0, patternSecond = 0;
263  unsigned halfStripBest = 0, halfStripSecond = 0;
264 
265  if (tempBestCLCT.isValid() and tempSecondCLCT.isValid()) {
266  qualityBest = tempBestCLCT.getQuality();
267  qualitySecond = tempSecondCLCT.getQuality();
268  if (!run3_) {
269  patternBest = tempBestCLCT.getPattern();
270  patternSecond = tempSecondCLCT.getPattern();
271  } else {
272  patternBest = tempBestCLCT.getRun3Pattern();
273  patternSecond = tempSecondCLCT.getRun3Pattern();
274  }
275  halfStripBest = tempBestCLCT.getKeyStrip();
276  halfStripSecond = tempSecondCLCT.getKeyStrip();
277 
278  if (qualitySecond > qualityBest)
279  changeOrder = true;
280  else if ((qualitySecond == qualityBest) and (int(patternSecond / 2) > int(patternBest / 2)))
281  changeOrder = true;
282  else if ((qualitySecond == qualityBest) and (int(patternSecond / 2) == int(patternBest / 2)) and
283  (halfStripSecond < halfStripBest))
284  changeOrder = true;
285  }
286 
287  CSCCLCTDigi tempCLCT;
288  if (changeOrder) {
289  tempCLCT = tempBestCLCT;
290  tempBestCLCT = tempSecondCLCT;
291  tempSecondCLCT = tempCLCT;
292  }
293 
294  // add the CLCTs to the collection
295  if (tempBestCLCT.isValid()) {
296  lctList.push_back(tempBestCLCT);
297  }
298  if (tempSecondCLCT.isValid()) {
299  lctList.push_back(tempSecondCLCT);
300  }
301  } //find CLCT, end of best_halfstrip[0] >= 0
302  } //pre_trig
303  // The pattern finder runs continuously, so another pre-trigger
304  // could occur already at the next bx.
305  start_bx = first_bx + 1;
306  }
307  return lctList;
308 } // findLCTs -- Phase2 version.
309 
311  bool pretrig_zone[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const {
312  // first reset the pretrigger zone (no pretriggers anywhere in this BX
313  for (int hstrip = 0; hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; hstrip++) {
314  pretrig_zone[hstrip] = false;
315  }
316  // then set the pretrigger zone according to the ispretrig_ array
317  for (int hstrip = 0; hstrip < CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER; hstrip++) {
318  if (ispretrig_[hstrip]) {
319  int min_hs = hstrip - pretrig_trig_zone_;
320  int max_hs = hstrip + pretrig_trig_zone_;
321  // set the minimum strip
322  if (min_hs < 0)
323  min_hs = 0;
324  // set the maximum strip
327  // mark the pre-trigger zone
328  for (int hs = min_hs; hs <= max_hs; hs++)
329  pretrig_zone[hs] = true;
330  if (infoV > 1)
331  LogTrace("CSCUpgradeCathodeLCTProcessor")
332  << " marked pretrigger halfstrip zone [" << min_hs << "," << max_hs << "]";
333  }
334  }
335 }
336 
338  for (int hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1]; hstrip < numHalfStrips_; hstrip++) {
339  // check if this halfstrip has a pretrigger
340  if (ispretrig_[hstrip]) {
341  // only fixed localized dead time zone is implemented in firmware
342  int min_hstrip = hstrip - clct_state_machine_zone_;
343  int max_hstrip = hstrip + clct_state_machine_zone_;
344  // set the minimum strip
345  if (min_hstrip < stagger[CSCConstants::KEY_CLCT_LAYER - 1])
346  min_hstrip = stagger[CSCConstants::KEY_CLCT_LAYER - 1];
347  // set the maximum strip
348  if (max_hstrip >= numHalfStrips_)
349  max_hstrip = numHalfStrips_ - 1;
350  // mask the busy half-strips for 1 BX after the pretrigger
351  for (int hs = min_hstrip; hs <= max_hstrip; hs++)
352  busyMap_[hs][bx + 1] = true;
353  if (infoV > 1)
354  LogTrace("CSCUpgradeCathodeLCTProcessor")
355  << " marked zone around pretriggerred halfstrip " << hstrip << " as dead zone for pretriggering at bx"
356  << bx + 1 << " halfstrip: [" << min_hstrip << "," << max_hstrip << "]";
357  }
358  }
359 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
uint16_t getQuality() const
return quality of a pattern (number of layers hit!)
Definition: CSCCLCTDigi.h:56
void pulseExtension(const std::vector< int > time[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
uint16_t getKeyStrip(const uint16_t n=2) const
Definition: CSCCLCTDigi.cc:107
bool patternFinding(const unsigned int bx_time, std::map< int, std::map< int, CSCCLCTDigi::ComparatorContainer > > &hits_in_patterns)
Log< level::Error, false > LogError
void markPreTriggerZone(bool pretrig_zone[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const
CSCUpgradeCathodeLCTProcessor(unsigned endcap, unsigned station, unsigned sector, unsigned subsector, unsigned chamber, CSCBaseboard::Parameters &conf)
#define LogTrace(id)
edm::ParameterSet const & clctParams() const
Definition: CSCBaseboard.h:24
std::vector< CSCCLCTDigi > findLCTs(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) override
string quality
unsigned int nhits[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
CSCCLCTPreTriggerDigi constructPreCLCT(const int bx, const unsigned halfstrip, const unsigned index) const
bool isValid() const
check CLCT validity (1 - valid CLCT)
Definition: CSCCLCTDigi.h:50
std::vector< CSCCLCTPreTriggerDigi > thePreTriggerDigis
virtual std::vector< CSCCLCTDigi > findLCTs(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
void markBusyKeys(const int best_hstrip, const int best_patid, int quality[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER])
bool busyMap_[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER][CSCConstants::MAX_CLCT_TBINS]
void dumpDigis(const std::vector< int > halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const
int stagger[CSCConstants::NUM_LAYERS]
uint16_t getPattern() const
return pattern
Definition: CSCCLCTDigi.h:62
virtual bool preTrigger(const int start_bx, int &first_bx)
uint16_t getRun3Pattern() const
return pattern
Definition: CSCCLCTDigi.h:68
bool preTrigger(const int start_bx, int &first_bx) override
CSCCLCTDigi constructCLCT(const int bx, const unsigned halfstrip_withstagger, const CSCCLCTDigi::ComparatorContainer &hits)
bool ispretrig_[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]
unsigned int best_pid[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]