CMS 3D CMS Logo

CSCMotherboard.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Class: CSCMotherboard
4 //
5 // Description:
6 // When the Trigger MotherBoard is instantiated it instantiates an ALCT
7 // and CLCT board. The Motherboard takes up to two LCTs from each anode
8 // and cathode LCT card and combines them into a single Correlated LCT.
9 // The output is up to two Correlated LCTs.
10 //
11 // It can be run in either a test mode, where the arguments are a collection
12 // of wire times and arrays of halfstrip and distrip times, or
13 // for general use, with with wire digi and comparator digi collections as
14 // arguments. In the latter mode, the wire & strip info is passed on the
15 // LCTProcessors, where it is decoded and converted into a convenient form.
16 // After running the anode and cathode LCTProcessors, TMB correlates the
17 // anode and cathode LCTs. At present, it simply matches the best CLCT
18 // with the best ALCT; perhaps a better algorithm will be determined in
19 // the future. The MotherBoard then determines a few more numbers (such as
20 // quality and pattern) from the ALCT and CLCT information, and constructs
21 // two correlated LCTs.
22 //
23 // correlateLCTs() may need to be modified to take into account a
24 // possibility of ALCTs and CLCTs arriving at different bx times.
25 //
26 // Author List: Benn Tannenbaum 28 August 1999 benn@physics.ucla.edu
27 // Based on code by Nick Wisniewski (nw@its.caltech.edu)
28 // and a framework by Darin Acosta (acosta@phys.ufl.edu).
29 //
30 //
31 // Modifications: Numerous later improvements by Jason Mumford and
32 // Slava Valuev (see cvs in ORCA).
33 // Porting from ORCA by S. Valuev (Slava.Valuev@cern.ch), May 2006.
34 //
35 //-----------------------------------------------------------------------------
36 
40 #include <iostream>
41 
42 // Default values of configuration parameters.
43 const unsigned int CSCMotherboard::def_mpc_block_me1a = 1;
44 const unsigned int CSCMotherboard::def_alct_trig_enable = 0;
45 const unsigned int CSCMotherboard::def_clct_trig_enable = 0;
46 const unsigned int CSCMotherboard::def_match_trig_enable = 1;
47 const unsigned int CSCMotherboard::def_match_trig_window_size = 7;
48 const unsigned int CSCMotherboard::def_tmb_l1a_window_size = 7;
49 
51  unsigned sector, unsigned subsector,
52  unsigned chamber,
53  const edm::ParameterSet& conf) :
54  theEndcap(endcap), theStation(station), theSector(sector),
55  theSubsector(subsector), theTrigChamber(chamber) {
56 
58 
59  // Normal constructor. -JM
60  // Pass ALCT, CLCT, and common parameters on to ALCT and CLCT processors.
61  static std::atomic<bool> config_dumped{false};
62 
63  // Some configuration parameters and some details of the emulator
64  // algorithms depend on whether we want to emulate the trigger logic
65  // used in TB/MTCC or its idealized version (the latter was used in MC
66  // studies since early ORCA days until (and including) CMSSW_2_1_X).
67  edm::ParameterSet commonParams =
68  conf.getParameter<edm::ParameterSet>("commonParam");
69  isMTCC = commonParams.getParameter<bool>("isMTCC");
70 
71  // Switch for a new (2007) version of the TMB firmware.
72  isTMB07 = commonParams.getParameter<bool>("isTMB07");
73 
74  // is it (non-upgrade algorithm) run along with upgrade one?
75  isSLHC = commonParams.getParameter<bool>("isSLHC");
76 
77  // Choose the appropriate set of configuration parameters depending on
78  // isTMB07 and isMTCC flags.
79  // Starting with CMSSW_3_1_X, these settings are overwritten by the
80  // ones delivered by the EventSetup mechanism.
81  edm::ParameterSet alctParams, clctParams;
82  if (isTMB07) {
83  alctParams = conf.getParameter<edm::ParameterSet>("alctParam07");
84  clctParams = conf.getParameter<edm::ParameterSet>("clctParam07");
85  }
86  else if (isMTCC) {
87  alctParams = conf.getParameter<edm::ParameterSet>("alctParamMTCC");
88  clctParams = conf.getParameter<edm::ParameterSet>("clctParamMTCC");
89  }
90  else {
91  alctParams = conf.getParameter<edm::ParameterSet>("alctParamOldMC");
92  clctParams = conf.getParameter<edm::ParameterSet>("clctParamOldMC");
93  }
94 
95  // Motherboard parameters:
96  edm::ParameterSet tmbParams = conf.getParameter<edm::ParameterSet>("tmbParam");
97  const edm::ParameterSet me11tmbGemParams(conf.existsAs<edm::ParameterSet>("me11tmbSLHCGEM")?
98  conf.getParameter<edm::ParameterSet>("me11tmbSLHCGEM"):edm::ParameterSet());
99  const edm::ParameterSet me21tmbGemParams(conf.existsAs<edm::ParameterSet>("me21tmbSLHCGEM")?
100  conf.getParameter<edm::ParameterSet>("me21tmbSLHCGEM"):edm::ParameterSet());
101  const edm::ParameterSet me3141tmbRpcParams(conf.existsAs<edm::ParameterSet>("me3141tmbSLHCRPC")?
102  conf.getParameter<edm::ParameterSet>("me3141tmbSLHCRPC"):edm::ParameterSet());
103 
104  const bool runME11ILT(commonParams.existsAs<bool>("runME11ILT")?commonParams.getParameter<bool>("runME11ILT"):false);
105  const bool runME21ILT(commonParams.existsAs<bool>("runME21ILT")?commonParams.getParameter<bool>("runME21ILT"):false);
106  const bool runME3141ILT(commonParams.existsAs<bool>("runME3141ILT")?commonParams.getParameter<bool>("runME3141ILT"):false);
107 
108  // run upgrade TMBs for all MEX/1 stations
109  if (isSLHC and theRing == 1){
110  if (theStation == 1) {
111  tmbParams = conf.getParameter<edm::ParameterSet>("tmbSLHC");
112  alctParams = conf.getParameter<edm::ParameterSet>("alctSLHC");
113  clctParams = conf.getParameter<edm::ParameterSet>("clctSLHC");
114  if (runME11ILT) {
115  tmbParams = me11tmbGemParams;
116  }
117  }
118  else if (theStation == 2 and runME21ILT) {
119  tmbParams = me21tmbGemParams;
120  alctParams = conf.getParameter<edm::ParameterSet>("alctSLHCME21");
121  clctParams = conf.getParameter<edm::ParameterSet>("clctSLHCME21");
122  }
123  else if ((theStation == 3 or theStation == 4) and runME3141ILT) {
124  tmbParams = me3141tmbRpcParams;
125  alctParams = conf.getParameter<edm::ParameterSet>("alctSLHCME3141");
126  clctParams = conf.getParameter<edm::ParameterSet>("clctSLHCME3141");
127  }
128  }
129 
130  mpc_block_me1a = tmbParams.getParameter<unsigned int>("mpcBlockMe1a");
131  alct_trig_enable = tmbParams.getParameter<unsigned int>("alctTrigEnable");
132  clct_trig_enable = tmbParams.getParameter<unsigned int>("clctTrigEnable");
133  match_trig_enable = tmbParams.getParameter<unsigned int>("matchTrigEnable");
135  tmbParams.getParameter<unsigned int>("matchTrigWindowSize");
136  tmb_l1a_window_size = // Common to CLCT and TMB
137  tmbParams.getParameter<unsigned int>("tmbL1aWindowSize");
138 
139  lct_central_bx = 6;
140 
141  // configuration handle for number of early time bins
142  early_tbins = tmbParams.getParameter<int>("tmbEarlyTbins");
143 
144  // whether to not reuse ALCTs that were used by previous matching CLCTs
145  drop_used_alcts = tmbParams.getParameter<bool>("tmbDropUsedAlcts");
146 
147  // whether to readout only the earliest two LCTs in readout window
148  readout_earliest_2 = tmbParams.getParameter<bool>("tmbReadoutEarliest2");
149 
150  infoV = tmbParams.getParameter<int>("verbosity");
151 
152  alct.reset( new CSCAnodeLCTProcessor(endcap, station, sector, subsector, chamber, alctParams, commonParams) );
153  clct.reset( new CSCCathodeLCTProcessor(endcap, station, sector, subsector, chamber, clctParams, commonParams, tmbParams) );
154 
155  //if (theStation==1 && CSCTriggerNumbering::ringFromTriggerLabels(theStation, theTrigChamber)==2) infoV = 3;
156 
157  // Check and print configuration parameters.
159  if (infoV > 0 && !config_dumped) {
161  config_dumped = true;
162  }
163 
164  // test to make sure that what goes into a correlated LCT is also what
165  // comes back out.
166  // testLCT();
167 }
168 
170  theEndcap(1), theStation(1), theSector(1),
172  // Constructor used only for testing. -JM
173  static std::atomic<bool> config_dumped{false};
174 
175  isMTCC = false;
176  isTMB07 = true;
177 
178  early_tbins = 4;
179 
180  alct.reset( new CSCAnodeLCTProcessor() );
181  clct.reset( new CSCCathodeLCTProcessor() );
188 
189  infoV = 2;
190 
191  // Check and print configuration parameters.
193  if (infoV > 0 && !config_dumped) {
195  config_dumped = true;
196  }
197 }
198 
200  if (alct) alct->clear();
201  if (clct) clct->clear();
202  for (int bx = 0; bx < MAX_LCT_BINS; bx++) {
203  firstLCT[bx].clear();
204  secondLCT[bx].clear();
205  }
206 }
207 
208 // Set configuration parameters obtained via EventSetup mechanism.
210  static std::atomic<bool> config_dumped{false};
211 
212  // Config. parameters for the TMB itself.
219 
220  // Config. paramteres for ALCT and CLCT processors.
221  alct->setConfigParameters(conf);
222  clct->setConfigParameters(conf);
223 
224  // Check and print configuration parameters.
226  if (!config_dumped) {
228  config_dumped = true;
229  }
230 }
231 
233  // Make sure that the parameter values are within the allowed range.
234 
235  // Max expected values.
236  static const unsigned int max_mpc_block_me1a = 1 << 1;
237  static const unsigned int max_alct_trig_enable = 1 << 1;
238  static const unsigned int max_clct_trig_enable = 1 << 1;
239  static const unsigned int max_match_trig_enable = 1 << 1;
240  static const unsigned int max_match_trig_window_size = 1 << 4;
241  static const unsigned int max_tmb_l1a_window_size = 1 << 4;
242 
243  // Checks.
244  if (mpc_block_me1a >= max_mpc_block_me1a) {
245  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
246  << "+++ Value of mpc_block_me1a, " << mpc_block_me1a
247  << ", exceeds max allowed, " << max_mpc_block_me1a-1 << " +++\n"
248  << "+++ Try to proceed with the default value, mpc_block_me1a="
249  << def_mpc_block_me1a << " +++\n";
251  }
252  if (alct_trig_enable >= max_alct_trig_enable) {
253  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
254  << "+++ Value of alct_trig_enable, " << alct_trig_enable
255  << ", exceeds max allowed, " << max_alct_trig_enable-1 << " +++\n"
256  << "+++ Try to proceed with the default value, alct_trig_enable="
257  << def_alct_trig_enable << " +++\n";
259  }
260  if (clct_trig_enable >= max_clct_trig_enable) {
261  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
262  << "+++ Value of clct_trig_enable, " << clct_trig_enable
263  << ", exceeds max allowed, " << max_clct_trig_enable-1 << " +++\n"
264  << "+++ Try to proceed with the default value, clct_trig_enable="
265  << def_clct_trig_enable << " +++\n";
267  }
268  if (match_trig_enable >= max_match_trig_enable) {
269  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
270  << "+++ Value of match_trig_enable, " << match_trig_enable
271  << ", exceeds max allowed, " << max_match_trig_enable-1 << " +++\n"
272  << "+++ Try to proceed with the default value, match_trig_enable="
273  << def_match_trig_enable << " +++\n";
275  }
276  if (match_trig_window_size >= max_match_trig_window_size) {
277  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
278  << "+++ Value of match_trig_window_size, " << match_trig_window_size
279  << ", exceeds max allowed, " << max_match_trig_window_size-1 << " +++\n"
280  << "+++ Try to proceed with the default value, match_trig_window_size="
281  << def_match_trig_window_size << " +++\n";
283  }
284  if (tmb_l1a_window_size >= max_tmb_l1a_window_size) {
285  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorConfigError")
286  << "+++ Value of tmb_l1a_window_size, " << tmb_l1a_window_size
287  << ", exceeds max allowed, " << max_tmb_l1a_window_size-1 << " +++\n"
288  << "+++ Try to proceed with the default value, tmb_l1a_window_size="
289  << def_tmb_l1a_window_size << " +++\n";
291  }
292 }
293 
295  const std::vector<int> w_times[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_WIRES],
296  const std::vector<int> hs_times[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS],
297  const std::vector<int> ds_times[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS]) {
298  // Debug version. -JM
299  clear();
300  alct->run(w_times); // run anode LCT
301  clct->run(hs_times, ds_times); // run cathodeLCT
302 
303  int bx_alct_matched = 0;
304  for (int bx_clct = 0; bx_clct < CSCCathodeLCTProcessor::MAX_CLCT_BINS;
305  bx_clct++) {
306  if (clct->bestCLCT[bx_clct].isValid()) {
307  bool is_matched = false;
308  int bx_alct_start = bx_clct - match_trig_window_size/2;
309  int bx_alct_stop = bx_clct + match_trig_window_size/2;
310  // Empirical correction to match 2009 collision data (firmware change?)
311  if (!isSLHC) bx_alct_stop += match_trig_window_size%2;
312 
313  for (int bx_alct = bx_alct_start; bx_alct <= bx_alct_stop; bx_alct++) {
314  if (bx_alct < 0 || bx_alct >= CSCAnodeLCTProcessor::MAX_ALCT_BINS)
315  continue;
316  if (alct->bestALCT[bx_alct].isValid()) {
317  correlateLCTs(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
318  clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct]);
319  is_matched = true;
320  bx_alct_matched = bx_alct;
321  break;
322  }
323  }
324  // No ALCT within the match time interval found: report CLCT-only LCT
325  // (use dummy ALCTs).
326  if (!is_matched) {
327  correlateLCTs(alct->bestALCT[bx_clct], alct->secondALCT[bx_clct],
328  clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct]);
329  }
330  }
331  // No valid CLCTs; attempt to make ALCT-only LCT (use dummy CLCTs).
332  else {
333  int bx_alct = bx_clct - match_trig_window_size/2;
334  if (bx_alct >= 0 && bx_alct > bx_alct_matched) {
335  if (alct->bestALCT[bx_alct].isValid()) {
336  correlateLCTs(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
337  clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct]);
338  }
339  }
340  }
341  }
342 }
343 
344 void
346  const CSCComparatorDigiCollection* compdc) {
347  clear();
348  if (alct && clct) {
349  {
350  std::vector<CSCALCTDigi> alctV = alct->run(wiredc); // run anodeLCT
351  }
352  {
353  std::vector<CSCCLCTDigi> clctV = clct->run(compdc); // run cathodeLCT
354  }
355 
356  int used_alct_mask[20];
357  for (int a=0;a<20;++a) used_alct_mask[a]=0;
358 
359  int bx_alct_matched = 0; // bx of last matched ALCT
360  for (int bx_clct = 0; bx_clct < CSCCathodeLCTProcessor::MAX_CLCT_BINS;
361  bx_clct++) {
362  // There should be at least one valid ALCT or CLCT for a
363  // correlated LCT to be formed. Decision on whether to reject
364  // non-complete LCTs (and if yes of which type) is made further
365  // upstream.
366  if (clct->bestCLCT[bx_clct].isValid()) {
367  // Look for ALCTs within the match-time window. The window is
368  // centered at the CLCT bx; therefore, we make an assumption
369  // that anode and cathode hits are perfectly synchronized. This
370  // is always true for MC, but only an approximation when the
371  // data is analyzed (which works fairly good as long as wide
372  // windows are used). To get rid of this assumption, one would
373  // need to access "full BX" words, which are not readily
374  // available.
375  bool is_matched = false;
376  int bx_alct_start = bx_clct - match_trig_window_size/2;
377  int bx_alct_stop = bx_clct + match_trig_window_size/2;
378  // Empirical correction to match 2009 collision data (firmware change?)
379  // (but don't do it for SLHC case, assume it would not be there)
380  if (!isSLHC) bx_alct_stop += match_trig_window_size%2;
381 
382  for (int bx_alct = bx_alct_start; bx_alct <= bx_alct_stop; bx_alct++) {
383  if (bx_alct < 0 || bx_alct >= CSCAnodeLCTProcessor::MAX_ALCT_BINS)
384  continue;
385  // default: do not reuse ALCTs that were used with previous CLCTs
386  if (drop_used_alcts && used_alct_mask[bx_alct]) continue;
387  if (alct->bestALCT[bx_alct].isValid()) {
388  if (infoV > 1) LogTrace("CSCMotherboard")
389  << "Successful ALCT-CLCT match: bx_clct = " << bx_clct
390  << "; match window: [" << bx_alct_start << "; " << bx_alct_stop
391  << "]; bx_alct = " << bx_alct;
392  correlateLCTs(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
393  clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct]);
394  used_alct_mask[bx_alct] += 1;
395  is_matched = true;
396  bx_alct_matched = bx_alct;
397  break;
398  }
399  }
400  // No ALCT within the match time interval found: report CLCT-only LCT
401  // (use dummy ALCTs).
402  if (!is_matched) {
403  if (infoV > 1) LogTrace("CSCMotherboard")
404  << "Unsuccessful ALCT-CLCT match (CLCT only): bx_clct = "
405  << bx_clct << "; match window: [" << bx_alct_start
406  << "; " << bx_alct_stop << "]";
407  correlateLCTs(alct->bestALCT[bx_clct], alct->secondALCT[bx_clct],
408  clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct]);
409  }
410  }
411  // No valid CLCTs; attempt to make ALCT-only LCT. Use only ALCTs
412  // which have zeroth chance to be matched at later cathode times.
413  // (I am not entirely sure this perfectly matches the firmware logic.)
414  // Use dummy CLCTs.
415  else {
416  int bx_alct = bx_clct - match_trig_window_size/2;
417  if (bx_alct >= 0 && bx_alct > bx_alct_matched) {
418  if (alct->bestALCT[bx_alct].isValid()) {
419  if (infoV > 1) LogTrace("CSCMotherboard")
420  << "Unsuccessful ALCT-CLCT match (ALCT only): bx_alct = "
421  << bx_alct;
422  correlateLCTs(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
423  clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct]);
424  }
425  }
426  }
427  }
428 
429  if (infoV > 0) {
430  for (int bx = 0; bx < MAX_LCT_BINS; bx++) {
431  if (firstLCT[bx].isValid())
432  LogDebug("CSCMotherboard") << firstLCT[bx];
433  if (secondLCT[bx].isValid())
434  LogDebug("CSCMotherboard") << secondLCT[bx];
435  }
436  }
437  }
438  else {
439  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorSetupError")
440  << "+++ run() called for non-existing ALCT/CLCT processor! +++ \n";
441  }
442 }
443 
444 // Returns vector of read-out correlated LCTs, if any. Starts with
445 // the vector of all found LCTs and selects the ones in the read-out
446 // time window.
447 std::vector<CSCCorrelatedLCTDigi> CSCMotherboard::readoutLCTs() {
448  std::vector<CSCCorrelatedLCTDigi> tmpV;
449 
450  // The start time of the L1A*LCT coincidence window should be related
451  // to the fifo_pretrig parameter, but I am not completely sure how.
452  // Just choose it such that the window is centered at bx=7. This may
453  // need further tweaking if the value of tmb_l1a_window_size changes.
454  //static int early_tbins = 4;
455 
456  // Empirical correction to match 2009 collision data (firmware change?)
457  int lct_bins = tmb_l1a_window_size;
458  int late_tbins = early_tbins + lct_bins;
459 
460  int ifois = 0;
461  if (ifois == 0) {
462  if (infoV >= 0 && early_tbins < 0) {
463  edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
464  << "+++ early_tbins = " << early_tbins
465  << "; in-time LCTs are not getting read-out!!! +++" << "\n";
466  }
467 
468  if (late_tbins > MAX_LCT_BINS-1) {
469  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
470  << "+++ Allowed range of time bins, [0-" << late_tbins
471  << "] exceeds max allowed, " << MAX_LCT_BINS-1 << " +++\n"
472  << "+++ Set late_tbins to max allowed +++\n";
473  late_tbins = MAX_LCT_BINS-1;
474  }
475  ifois = 1;
476  }
477 
478  // Start from the vector of all found correlated LCTs and select
479  // those within the LCT*L1A coincidence window.
480  int bx_readout = -1;
481  std::vector<CSCCorrelatedLCTDigi> all_lcts = getLCTs();
482  for (std::vector <CSCCorrelatedLCTDigi>::const_iterator plct =
483  all_lcts.begin(); plct != all_lcts.end(); plct++) {
484  if (!plct->isValid()) continue;
485 
486  int bx = (*plct).getBX();
487  // Skip LCTs found too early relative to L1Accept.
488  if (bx <= early_tbins) {
489  if (infoV > 1) LogDebug("CSCMotherboard")
490  << " Do not report correlated LCT on key halfstrip "
491  << plct->getStrip() << " and key wire " << plct->getKeyWG()
492  << ": found at bx " << bx << ", whereas the earliest allowed bx is "
493  << early_tbins+1;
494  continue;
495  }
496 
497  // Skip LCTs found too late relative to L1Accept.
498  if (bx > late_tbins) {
499  if (infoV > 1) LogDebug("CSCMotherboard")
500  << " Do not report correlated LCT on key halfstrip "
501  << plct->getStrip() << " and key wire " << plct->getKeyWG()
502  << ": found at bx " << bx << ", whereas the latest allowed bx is "
503  << late_tbins;
504  continue;
505  }
506 
507  // If (readout_earliest_2) take only LCTs in the earliest bx in the read-out window:
508  // in digi->raw step, LCTs have to be packed into the TMB header, and
509  // currently there is room just for two.
510  if (readout_earliest_2) {
511  if (bx_readout == -1 || bx == bx_readout) {
512  tmpV.push_back(*plct);
513  if (bx_readout == -1) bx_readout = bx;
514  }
515  }
516  // if readout_earliest_2 == false, save all LCTs
517  else tmpV.push_back(*plct);
518  }
519  return tmpV;
520 }
521 
522 // Returns vector of all found correlated LCTs, if any.
523 std::vector<CSCCorrelatedLCTDigi> CSCMotherboard::getLCTs() {
524  std::vector<CSCCorrelatedLCTDigi> tmpV;
525 
526  bool me11 = (theStation == 1 &&
528  theTrigChamber)==1);
529 
530  // Do not report LCTs found in ME1/A if mpc_block_me1/a is set.
531  for (int bx = 0; bx < MAX_LCT_BINS; bx++) {
532  if (firstLCT[bx].isValid())
533  if (!mpc_block_me1a || (!me11 || firstLCT[bx].getStrip() <= 127))
534  tmpV.push_back(firstLCT[bx]);
535  if (secondLCT[bx].isValid())
536  if (!mpc_block_me1a || (!me11 || secondLCT[bx].getStrip() <= 127))
537  tmpV.push_back(secondLCT[bx]);
538  }
539  return tmpV;
540 }
541 
543  CSCALCTDigi secondALCT,
544  CSCCLCTDigi bestCLCT,
545  CSCCLCTDigi secondCLCT) {
546 
547  bool anodeBestValid = bestALCT.isValid();
548  bool anodeSecondValid = secondALCT.isValid();
549  bool cathodeBestValid = bestCLCT.isValid();
550  bool cathodeSecondValid = secondCLCT.isValid();
551 
552  if (anodeBestValid && !anodeSecondValid) secondALCT = bestALCT;
553  if (!anodeBestValid && anodeSecondValid) bestALCT = secondALCT;
554  if (cathodeBestValid && !cathodeSecondValid) secondCLCT = bestCLCT;
555  if (!cathodeBestValid && cathodeSecondValid) bestCLCT = secondCLCT;
556 
557  // ALCT-CLCT matching conditions are defined by "trig_enable" configuration
558  // parameters.
559  if ((alct_trig_enable && bestALCT.isValid()) ||
560  (clct_trig_enable && bestCLCT.isValid()) ||
561  (match_trig_enable && bestALCT.isValid() && bestCLCT.isValid())) {
563  int bx = lct.getBX();
564  if (bx >= 0 && bx < MAX_LCT_BINS) {
565  firstLCT[bx] = lct;
566  firstLCT[bx].setTrknmb(1);
567  }
568  else {
569  if (infoV > 0) edm::LogWarning("L1CSCTPEmulatorOutOfTimeLCT")
570  << "+++ Bx of first LCT candidate, " << bx
571  << ", is not within the allowed range, [0-" << MAX_LCT_BINS-1
572  << "); skipping it... +++\n";
573  }
574  }
575 
576  if (((secondALCT != bestALCT) || (secondCLCT != bestCLCT)) &&
577  ((alct_trig_enable && secondALCT.isValid()) ||
578  (clct_trig_enable && secondCLCT.isValid()) ||
579  (match_trig_enable && secondALCT.isValid() && secondCLCT.isValid()))) {
581  int bx = lct.getBX();
582  if (bx >= 0 && bx < MAX_LCT_BINS) {
583  secondLCT[bx] = lct;
584  secondLCT[bx].setTrknmb(2);
585  }
586  else {
587  if (infoV > 0) edm::LogWarning("L1CSCTPEmulatorOutOfTimeLCT")
588  << "+++ Bx of second LCT candidate, " << bx
589  << ", is not within the allowed range, [0-" << MAX_LCT_BINS-1
590  << "); skipping it... +++\n";
591  }
592  }
593 }
594 
595 // This method calculates all the TMB words and then passes them to the
596 // constructor of correlated LCTs.
598  const CSCCLCTDigi& cLCT,
599  int type) {
600  // CLCT pattern number
601  unsigned int pattern = encodePattern(cLCT.getPattern(), cLCT.getStripType());
602 
603  // LCT quality number
604  unsigned int quality = findQuality(aLCT, cLCT);
605 
606  // Bunch crossing: get it from cathode LCT if anode LCT is not there.
607  int bx = aLCT.isValid() ? aLCT.getBX() : cLCT.getBX();
608 
609  // construct correlated LCT; temporarily assign track number of 0.
610  int trknmb = 0;
611  CSCCorrelatedLCTDigi thisLCT(trknmb, 1, quality, aLCT.getKeyWG(),
612  cLCT.getKeyStrip(), pattern, cLCT.getBend(),
613  bx, 0, 0, 0, theTrigChamber);
614  thisLCT.setType(type);
615  thisLCT.setALCT(aLCT);
616  thisLCT.setCLCT(cLCT);
617  return thisLCT;
618 }
619 
620 // CLCT pattern number: encodes the pattern number itself and
621 // whether the pattern consists of half-strips or di-strips.
622 unsigned int CSCMotherboard::encodePattern(const int ptn,
623  const int stripType) {
624  const int kPatternBitWidth = 4;
625  unsigned int pattern;
626 
627  if (!isTMB07) {
628  // Cathode pattern number is a kPatternBitWidth-1 bit word.
629  pattern = (abs(ptn) & ((1<<(kPatternBitWidth-1))-1));
630 
631  // The pattern has the MSB (4th bit in the default version) set if it
632  // consists of half-strips.
633  if (stripType) {
634  pattern = pattern | (1<<(kPatternBitWidth-1));
635  }
636  }
637  else {
638  // In the TMB07 firmware, LCT pattern is just a 4-bit CLCT pattern.
639  pattern = (abs(ptn) & ((1<<kPatternBitWidth)-1));
640  }
641 
642  return pattern;
643 }
644 
645 // 4-bit LCT quality number. Definition can be found in
646 // http://www.phys.ufl.edu/~acosta/tb/tmb_quality.txt. Made by TMB lookup
647 // tables and used for MPC sorting.
648 unsigned int CSCMotherboard::findQuality(const CSCALCTDigi& aLCT,
649  const CSCCLCTDigi& cLCT) {
650  unsigned int quality = 0;
651 
652  if (!isTMB07) {
653  bool isDistrip = (cLCT.getStripType() == 0);
654 
655  if (aLCT.isValid() && !(cLCT.isValid())) { // no CLCT
656  if (aLCT.getAccelerator()) {quality = 1;}
657  else {quality = 3;}
658  }
659  else if (!(aLCT.isValid()) && cLCT.isValid()) { // no ALCT
660  if (isDistrip) {quality = 4;}
661  else {quality = 5;}
662  }
663  else if (aLCT.isValid() && cLCT.isValid()) { // both ALCT and CLCT
664  if (aLCT.getAccelerator()) {quality = 2;} // accelerator muon
665  else { // collision muon
666  // CLCT quality is, in fact, the number of layers hit, so subtract 3
667  // to get quality analogous to ALCT one.
668  int sumQual = aLCT.getQuality() + (cLCT.getQuality()-3);
669  if (sumQual < 1 || sumQual > 6) {
670  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
671  << "+++ findQuality: sumQual = " << sumQual << "+++ \n";
672  }
673  if (isDistrip) { // distrip pattern
674  if (sumQual == 2) {quality = 6;}
675  else if (sumQual == 3) {quality = 7;}
676  else if (sumQual == 4) {quality = 8;}
677  else if (sumQual == 5) {quality = 9;}
678  else if (sumQual == 6) {quality = 10;}
679  }
680  else { // halfstrip pattern
681  if (sumQual == 2) {quality = 11;}
682  else if (sumQual == 3) {quality = 12;}
683  else if (sumQual == 4) {quality = 13;}
684  else if (sumQual == 5) {quality = 14;}
685  else if (sumQual == 6) {quality = 15;}
686  }
687  }
688  }
689  }
690 #ifdef OLD
691  else {
692  // Temporary definition, used until July 2008.
693  // First if statement is fictitious, just to help the CSC TF emulator
694  // handle such cases (one needs to make sure they will be accounted for
695  // in the new quality definition.
696  if (!(aLCT.isValid()) || !(cLCT.isValid())) {
697  if (aLCT.isValid() && !(cLCT.isValid())) quality = 1; // no CLCT
698  else if (!(aLCT.isValid()) && cLCT.isValid()) quality = 2; // no ALCT
699  else quality = 0; // both absent; should never happen.
700  }
701  else {
702  // Sum of ALCT and CLCT quality bits. CLCT quality is, in fact, the
703  // number of layers hit, so subtract 3 to put it to the same footing as
704  // the ALCT quality.
705  int sumQual = aLCT.getQuality() + (cLCT.getQuality()-3);
706  if (sumQual < 1 || sumQual > 6) {
707  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
708  << "+++ findQuality: Unexpected sumQual = " << sumQual << "+++\n";
709  }
710 
711  // LCT quality is basically the sum of ALCT and CLCT qualities, but split
712  // in two groups depending on the CLCT pattern id (higher quality for
713  // straighter patterns).
714  int offset = 0;
715  if (cLCT.getPattern() <= 7) offset = 4;
716  else offset = 9;
717  quality = offset + sumQual;
718  }
719  }
720 #endif
721  else {
722  // 2008 definition.
723  if (!(aLCT.isValid()) || !(cLCT.isValid())) {
724  if (aLCT.isValid() && !(cLCT.isValid())) quality = 1; // no CLCT
725  else if (!(aLCT.isValid()) && cLCT.isValid()) quality = 2; // no ALCT
726  else quality = 0; // both absent; should never happen.
727  }
728  else {
729  int pattern = cLCT.getPattern();
730  if (pattern == 1) quality = 3; // layer-trigger in CLCT
731  else {
732  // CLCT quality is the number of layers hit minus 3.
733  // CLCT quality is the number of layers hit.
734  bool a4 = (aLCT.getQuality() >= 1);
735  bool c4 = (cLCT.getQuality() >= 4);
736  // quality = 4; "reserved for low-quality muons in future"
737  if (!a4 && !c4) quality = 5; // marginal anode and cathode
738  else if ( a4 && !c4) quality = 6; // HQ anode, but marginal cathode
739  else if (!a4 && c4) quality = 7; // HQ cathode, but marginal anode
740  else if ( a4 && c4) {
741  if (aLCT.getAccelerator()) quality = 8; // HQ muon, but accel ALCT
742  else {
743  // quality = 9; "reserved for HQ muons with future patterns
744  // quality = 10; "reserved for HQ muons with future patterns
745  if (pattern == 2 || pattern == 3) quality = 11;
746  else if (pattern == 4 || pattern == 5) quality = 12;
747  else if (pattern == 6 || pattern == 7) quality = 13;
748  else if (pattern == 8 || pattern == 9) quality = 14;
749  else if (pattern == 10) quality = 15;
750  else {
751  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
752  << "+++ findQuality: Unexpected CLCT pattern id = "
753  << pattern << "+++\n";
754  }
755  }
756  }
757  }
758  }
759  }
760  return quality;
761 }
762 
764  unsigned int lctPattern, lctQuality;
765  for (int pattern = 0; pattern < 8; pattern++) {
766  for (int bend = 0; bend < 2; bend++) {
767  for (int cfeb = 0; cfeb < 5; cfeb++) {
768  for (int strip = 0; strip < 32; strip++) {
769  for (int bx = 0; bx < 7; bx++) {
770  for (int stripType = 0; stripType < 2; stripType++) {
771  for (int quality = 3; quality < 7; quality++) {
772  CSCCLCTDigi cLCT(1, quality, pattern, stripType, bend,
773  strip, cfeb, bx);
774  lctPattern = encodePattern(cLCT.getPattern(),
775  cLCT.getStripType());
776  for (int aQuality = 0; aQuality < 4; aQuality++) {
777  for (int wireGroup = 0; wireGroup < 120; wireGroup++) {
778  for (int abx = 0; abx < 7; abx++) {
779  CSCALCTDigi aLCT(1, aQuality, 0, 1, wireGroup, abx);
780  lctQuality = findQuality(aLCT, cLCT);
782  thisLCT(0, 1, lctQuality, aLCT.getKeyWG(),
783  cLCT.getKeyStrip(), lctPattern, cLCT.getBend(),
784  aLCT.getBX());
785  if (lctPattern != static_cast<unsigned int>(thisLCT.getPattern()) )
786  LogTrace("CSCMotherboard")
787  << "pattern mismatch: " << lctPattern
788  << " " << thisLCT.getPattern();
789  if (bend != thisLCT.getBend())
790  LogTrace("CSCMotherboard")
791  << "bend mismatch: " << bend
792  << " " << thisLCT.getBend();
793  int key_strip = 32*cfeb + strip;
794  if (key_strip != thisLCT.getStrip())
795  LogTrace("CSCMotherboard")
796  << "strip mismatch: " << key_strip
797  << " " << thisLCT.getStrip();
798  if (wireGroup != thisLCT.getKeyWG())
799  LogTrace("CSCMotherboard")
800  << "wire group mismatch: " << wireGroup
801  << " " << thisLCT.getKeyWG();
802  if (abx != thisLCT.getBX())
803  LogTrace("CSCMotherboard")
804  << "bx mismatch: " << abx << " " << thisLCT.getBX();
805  if (lctQuality != static_cast<unsigned int>(thisLCT.getQuality()))
806  LogTrace("CSCMotherboard")
807  << "quality mismatch: " << lctQuality
808  << " " << thisLCT.getQuality();
809  }
810  }
811  }
812  }
813  }
814  }
815  }
816  }
817  }
818  }
819 }
820 
822  std::ostringstream strm;
823  strm << "\n";
824  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
825  strm << "+ TMB configuration parameters: +\n";
826  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
827  strm << " mpc_block_me1a [block/not block triggers which come from ME1/A] = "
828  << mpc_block_me1a << "\n";
829  strm << " alct_trig_enable [allow ALCT-only triggers] = "
830  << alct_trig_enable << "\n";
831  strm << " clct_trig_enable [allow CLCT-only triggers] = "
832  << clct_trig_enable << "\n";
833  strm << " match_trig_enable [allow matched ALCT-CLCT triggers] = "
834  << match_trig_enable << "\n";
835  strm << " match_trig_window_size [ALCT-CLCT match window width, in 25 ns] = "
836  << match_trig_window_size << "\n";
837  strm << " tmb_l1a_window_size [L1Accept window width, in 25 ns bins] = "
838  << tmb_l1a_window_size << "\n";
839  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
840  LogDebug("CSCMotherboard") << strm.str();
841 }
842 
843 
844 // compare LCTs by quality
846 {
847  return lct1.getQuality() > lct2.getQuality();
848 }
849 
850 // compare LCTs by GEM bending angle
852 {
853  // return lct1.getGEMDPhi() < lct2.getGEMDPhi();
854  return true;
855 }
#define LogDebug(id)
int getQuality() const
return quality of a pattern (number of layers hit!)
Definition: CSCCLCTDigi.h:33
type
Definition: HCALResponse.h:21
const unsigned theSector
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
unsigned int clct_trig_enable
std::vector< CSCCorrelatedLCTDigi > getLCTs()
static bool sortByGEMDphi(const CSCCorrelatedLCTDigi &, const CSCCorrelatedLCTDigi &)
std::vector< CSCCorrelatedLCTDigi > readoutLCTs()
unsigned int match_trig_window_size
const unsigned theTrigChamber
static const unsigned int def_alct_trig_enable
bool isValid() const
check ALCT validity (1 - valid ALCT)
Definition: CSCALCTDigi.h:30
int getQuality() const
return the 4 bit Correlated LCT Quality
const unsigned theEndcap
static const unsigned int def_mpc_block_me1a
unsigned int tmbClctTrigEnable() const
unsigned int findQuality(const CSCALCTDigi &aLCT, const CSCCLCTDigi &cLCT)
static const unsigned int def_clct_trig_enable
static int ringFromTriggerLabels(int station, int triggerCSCID)
int getStripType() const
return striptype
Definition: CSCCLCTDigi.h:39
int getBend() const
return bend
Definition: CSCCLCTDigi.h:42
unsigned int mpc_block_me1a
unsigned int tmbTmbL1aWindowSize() const
void correlateLCTs(CSCALCTDigi bestALCT, CSCALCTDigi secondALCT, CSCCLCTDigi bestCLCT, CSCCLCTDigi secondCLCT)
const unsigned theStation
unsigned int tmbMatchTrigWindowSize() const
CSCCorrelatedLCTDigi secondLCT[MAX_LCT_BINS]
static const unsigned int def_tmb_l1a_window_size
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
CSCCorrelatedLCTDigi constructLCTs(const CSCALCTDigi &aLCT, const CSCCLCTDigi &cLCT, int)
const unsigned theSubsector
void run(const std::vector< int > w_time[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_WIRES], const std::vector< int > hs_times[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS], const std::vector< int > ds_times[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS_7CFEBS])
int getBX() const
return BX
Definition: CSCCLCTDigi.h:51
unsigned int tmbAlctTrigEnable() const
unsigned int encodePattern(const int ptn, const int highPt)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int tmb_l1a_window_size
void checkConfigParameters()
bool isValid() const
check CLCT validity (1 - valid CLCT)
Definition: CSCCLCTDigi.h:30
unsigned int match_trig_enable
#define LogTrace(id)
int getBX() const
return BX
int getBX() const
return BX - five low bits of BXN counter tagged by the ALCT
Definition: CSCALCTDigi.h:48
CSCCorrelatedLCTDigi firstLCT[MAX_LCT_BINS]
unsigned int tmbMpcBlockMe1a() const
int getQuality() const
return quality of a pattern
Definition: CSCALCTDigi.h:33
int getAccelerator() const
Definition: CSCALCTDigi.h:37
int getPattern() const
return pattern
Definition: CSCCLCTDigi.h:36
static const unsigned int def_match_trig_window_size
unsigned int alct_trig_enable
std::unique_ptr< CSCAnodeLCTProcessor > alct
double a
Definition: hdecay.h:121
void dumpConfigParams() const
std::unique_ptr< CSCCathodeLCTProcessor > clct
int getKeyStrip() const
Definition: CSCCLCTDigi.h:65
void setConfigParameters(const CSCDBL1TPParameters *conf)
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting LCTs.
int getKeyWG() const
return key wire group
Definition: CSCALCTDigi.h:45
static const unsigned int def_match_trig_enable
static bool sortByQuality(const CSCCorrelatedLCTDigi &, const CSCCorrelatedLCTDigi &)
unsigned int tmbMatchTrigEnable() const
unsigned theRing