test
CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCMotherboardME11GEM.cc
Go to the documentation of this file.
9 #include <cmath>
10 #include <tuple>
11 #include <set>
12 #include "boost/container/flat_set.hpp"
13 
14 // LUT for which ME1/1 wire group can cross which ME1/a halfstrip
15 // 1st index: WG number
16 // 2nd index: inclusive HS range
18 {0, 95},{0, 95},{0, 95},{0, 95},{0, 95},
19 {0, 95},{0, 95},{0, 95},{0, 95},{0, 95},
20 {0, 95},{0, 95},{0, 77},{0, 61},{0, 39},
21 {0, 22},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
22 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
23 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
24 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
25 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
26 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
27 {-1,-1},{-1,-1},{-1,-1} };
28 // a modified LUT for ganged ME1a
30 {0, 31},{0, 31},{0, 31},{0, 31},{0, 31},
31 {0, 31},{0, 31},{0, 31},{0, 31},{0, 31},
32 {0, 31},{0, 31},{0, 31},{0, 31},{0, 31},
33 {0, 22},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
34 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
35 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
36 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
37 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
38 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
39 {-1,-1},{-1,-1},{-1,-1} };
40 
41 // LUT for which ME1/1 wire group can cross which ME1/b halfstrip
42 // 1st index: WG number
43 // 2nd index: inclusive HS range
45 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
46 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
47 {100, 127},{73, 127},{47, 127},{22, 127},{0, 127},
48 {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
49 {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
50 {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
51 {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
52 {0, 127},{0, 127},{0, 127},{0, 127},{0, 127},
53 {0, 127},{0, 127},{0, 127},{0, 127},{0, 105},
54 {0, 93},{0, 78},{0, 63} };
55 
56 // LUT with bending angles of the GEM-CSC high efficiency patterns (98%)
57 // 1st index: pt value = {5,10,15,20,30,40}
58 // 2nd index: bending angle for odd numbered chambers
59 // 3rd index: bending angle for even numbered chambers
60 /*
61 const double CSCMotherboardME11GEM::lut_pt_vs_dphi_gemcsc[7][3] = {
62  {5., 0.02203511, 0.00930056},
63  {6 , 0.0182579 , 0.00790009},
64  {10., 0.01066000, 0.00483286},
65  {15., 0.00722795, 0.00363230},
66  {20., 0.00562598, 0.00304878},
67  {30., 0.00416544, 0.00253782},
68  {40., 0.00342827, 0.00230833} };
69 */
70 
72  {3, 0.03971647, 0.01710244},
73  {5, 0.02123785, 0.00928431},
74  {7, 0.01475524, 0.00650928},
75  {10, 0.01023299, 0.00458796},
76  {15, 0.00689220, 0.00331313},
77  {20, 0.00535176, 0.00276152},
78  {30, 0.00389050, 0.00224959},
79  {40, 0.00329539, 0.00204670}};
80 
82 {0, 2.44005, 2.44688},
83 {1, 2.38863, 2.45035},
84 {2, 2.32742, 2.43077},
85 {3, 2.30064, 2.40389},
86 {4, 2.2746, 2.37775},
87 {5, 2.24925, 2.35231},
88 {6, 2.22458, 2.32754},
89 {7, 2.20054, 2.30339},
90 {8, 2.1771, 2.27985},
91 {9, 2.15425, 2.25689},
92 {10, 2.13194, 2.23447},
93 {11, 2.11016, 2.21258},
94 {12, 2.08889, 2.19119},
95 {13, 2.06809, 2.17028},
96 {14, 2.04777, 2.14984},
97 {15, 2.02788, 2.12983},
98 {16, 2.00843, 2.11025},
99 {17, 1.98938, 2.09108},
100 {18, 1.97073, 2.0723},
101 {19, 1.95246, 2.0539},
102 {20, 1.93456, 2.03587},
103 {21, 1.91701, 2.01818},
104 {22, 1.8998, 2.00084},
105 {23, 1.88293, 1.98382},
106 {24, 1.86637, 1.96712},
107 {25, 1.85012, 1.95073},
108 {26, 1.83417, 1.93463},
109 {27, 1.8185, 1.91882},
110 {28, 1.80312, 1.90329},
111 {29, 1.788, 1.88803},
112 {30, 1.77315, 1.87302},
113 {31, 1.75855, 1.85827},
114 {32, 1.74421, 1.84377},
115 {33, 1.7301, 1.8295},
116 {34, 1.71622, 1.81547},
117 {35, 1.70257, 1.80166},
118 {36, 1.68914, 1.78807},
119 {37, 1.67592, 1.77469},
120 {38, 1.66292, 1.76151},
121 {39, 1.65011, 1.74854},
122 {40, 1.63751, 1.73577},
123 {41, 1.62509, 1.72319},
124 {42, 1.61287, 1.71079},
125 {43, 1.60082, 1.69857},
126 {44, 1.59924, 1.68654},
127 {45, 1.6006, 1.67467},
128 {46, 1.60151, 1.66297},
129 {47, 1.60198, 1.65144} };
130 
132 {0, 2.3917, 2.39853},
133 {1, 2.34037, 2.40199},
134 {2, 2.27928, 2.38244},
135 {3, 2.25254, 2.35561},
136 {4, 2.22655, 2.32951},
137 {5, 2.20127, 2.30412},
138 {6, 2.17665, 2.27939},
139 {7, 2.15267, 2.25529},
140 {8, 2.12929, 2.2318},
141 {9, 2.1065, 2.20889},
142 {10, 2.08425, 2.18652},
143 {11, 2.06253, 2.16468},
144 {12, 2.04132, 2.14334},
145 {13, 2.0206, 2.12249},
146 {14, 2.00033, 2.1021},
147 {15, 1.98052, 2.08215},
148 {16, 1.96113, 2.06262},
149 {17, 1.94215, 2.04351},
150 {18, 1.92357, 2.02479},
151 {19, 1.90538, 2.00645},
152 {20, 1.88755, 1.98847},
153 {21, 1.87007, 1.97085},
154 {22, 1.85294, 1.95357},
155 {23, 1.83614, 1.93662},
156 {24, 1.81965, 1.91998},
157 {25, 1.80348, 1.90365},
158 {26, 1.78761, 1.88762},
159 {27, 1.77202, 1.87187},
160 {28, 1.75672, 1.85641},
161 {29, 1.74168, 1.84121},
162 {30, 1.72691, 1.82628},
163 {31, 1.7124, 1.8116},
164 {32, 1.69813, 1.79716},
165 {33, 1.68411, 1.78297},
166 {34, 1.67032, 1.769},
167 {35, 1.65675, 1.75526},
168 {36, 1.64341, 1.74174},
169 {37, 1.63028, 1.72844},
170 {38, 1.61736, 1.71534},
171 {39, 1.60465, 1.70245},
172 {40, 1.59213, 1.68975},
173 {41, 1.57981, 1.67724},
174 {42, 1.56767, 1.66492},
175 {43, 1.55572, 1.65278},
176 {44, 1.55414, 1.64082},
177 {45, 1.55549, 1.62903},
178 {46, 1.5564, 1.61742},
179 {47, 1.55686, 1.60596} };
180 
182  unsigned sector, unsigned subsector,
183  unsigned chamber,
184  const edm::ParameterSet& conf) :
185  CSCMotherboard(endcap, station, sector, subsector, chamber, conf)
186 {
187  const edm::ParameterSet commonParams(conf.getParameter<edm::ParameterSet>("commonParam"));
188 
189  // special configuration parameters for ME11 treatment
190  smartME1aME1b = commonParams.getParameter<bool>("smartME1aME1b");
191  disableME1a = commonParams.getParameter<bool>("disableME1a");
192  gangedME1a = commonParams.getParameter<bool>("gangedME1a");
193  runME11ILT_ = commonParams.getParameter<bool>("runME11ILT");
194 
195  if (!isSLHC) edm::LogError("L1CSCTPEmulatorConfigError")
196  << "+++ Upgrade CSCMotherboardME11GEM constructed while isSLHC is not set! +++\n";
197  if (!smartME1aME1b) edm::LogError("L1CSCTPEmulatorConfigError")
198  << "+++ Upgrade CSCMotherboardME11GEM constructed while smartME1aME1b is not set! +++\n";
199 
200  const edm::ParameterSet alctParams(conf.getParameter<edm::ParameterSet>("alctSLHC"));
201  const edm::ParameterSet clctParams(conf.getParameter<edm::ParameterSet>("clctSLHC"));
202  const edm::ParameterSet me11tmbParams(conf.getParameter<edm::ParameterSet>("me11tmbSLHCGEM"));
203 
204  clct1a.reset( new CSCCathodeLCTProcessor(endcap, station, sector, subsector, chamber, clctParams, commonParams, me11tmbParams) );
205  clct1a->setRing(4);
206 
207  match_earliest_alct_me11_only = me11tmbParams.getParameter<bool>("matchEarliestAlctME11Only");
208  match_earliest_clct_me11_only = me11tmbParams.getParameter<bool>("matchEarliestClctME11Only");
209 
210  // if true: use regular CLCT-to-ALCT matching in TMB
211  // if false: do ALCT-to-CLCT matching
212  clct_to_alct = me11tmbParams.getParameter<bool>("clctToAlct");
213 
214  // whether to not reuse CLCTs that were used by previous matching ALCTs
215  // in ALCT-to-CLCT algorithm
216  drop_used_clcts = me11tmbParams.getParameter<bool>("tmbDropUsedClcts");
217 
218  tmb_cross_bx_algo = me11tmbParams.getParameter<unsigned int>("tmbCrossBxAlgorithm");
219 
220  // maximum lcts per BX in ME11: 2, 3, 4 or 999
221  max_me11_lcts = me11tmbParams.getParameter<unsigned int>("maxME11LCTs");
222 
224  for (unsigned int m=2; m<match_trig_window_size; m+=2)
225  {
226  pref[m-1] = pref[0] - m/2;
227  pref[m] = pref[0] + m/2;
228  }
229 
230  //----------------------------------------------------------------------------------------//
231 
232  // G E M - C S C I N T E G R A T E D L O C A L A L G O R I T H M
233 
234  //----------------------------------------------------------------------------------------//
235 
236  // debug gem matching
237  debug_gem_matching = me11tmbParams.getParameter<bool>("debugMatching");
238  debug_luts = me11tmbParams.getParameter<bool>("debugLUTs");
239  debug_gem_dphi = me11tmbParams.getParameter<bool>("debugGEMDphi");
240 
241  // deltas used to construct GEM coincidence pads
242  maxDeltaBXInCoPad_ = me11tmbParams.getParameter<int>("maxDeltaBXInCoPad");
243  maxDeltaPadInCoPad_ = me11tmbParams.getParameter<int>("maxDeltaPadInCoPad");
244 
245  // deltas used to match to GEM pads
246  maxDeltaBXPadEven_ = me11tmbParams.getParameter<int>("maxDeltaBXPadEven");
247  maxDeltaPadPadEven_ = me11tmbParams.getParameter<int>("maxDeltaPadPadEven");
248  maxDeltaBXPadOdd_ = me11tmbParams.getParameter<int>("maxDeltaBXPadOdd");
249  maxDeltaPadPadOdd_ = me11tmbParams.getParameter<int>("maxDeltaPadPadOdd");
250 
251  // deltas used to match to GEM coincidence pads
252  maxDeltaBXCoPadEven_ = me11tmbParams.getParameter<int>("maxDeltaBXCoPadEven");
253  maxDeltaPadCoPadEven_ = me11tmbParams.getParameter<int>("maxDeltaPadCoPadEven");
254  maxDeltaBXCoPadOdd_ = me11tmbParams.getParameter<int>("maxDeltaBXCoPadOdd");
255  maxDeltaPadCoPadOdd_ = me11tmbParams.getParameter<int>("maxDeltaPadCoPadOdd");
256 
257  // drop low quality stubs if they don't have GEMs
258  dropLowQualityCLCTsNoGEMs_ME1a_ = me11tmbParams.getParameter<bool>("dropLowQualityCLCTsNoGEMs_ME1a");
259  dropLowQualityCLCTsNoGEMs_ME1b_ = me11tmbParams.getParameter<bool>("dropLowQualityCLCTsNoGEMs_ME1b");
260  dropLowQualityALCTsNoGEMs_ME1a_ = me11tmbParams.getParameter<bool>("dropLowQualityALCTsNoGEMs_ME1a");
261  dropLowQualityALCTsNoGEMs_ME1b_ = me11tmbParams.getParameter<bool>("dropLowQualityALCTsNoGEMs_ME1b");
262 
263  // build LCT from ALCT and GEM
264  buildLCTfromALCTandGEM_ME1a_ = me11tmbParams.getParameter<bool>("buildLCTfromALCTandGEM_ME1a");
265  buildLCTfromALCTandGEM_ME1b_ = me11tmbParams.getParameter<bool>("buildLCTfromALCTandGEM_ME1b");
266  buildLCTfromCLCTandGEM_ME1a_ = me11tmbParams.getParameter<bool>("buildLCTfromCLCTandGEM_ME1a");
267  buildLCTfromCLCTandGEM_ME1b_ = me11tmbParams.getParameter<bool>("buildLCTfromCLCTandGEM_ME1b");
268 
269  // LCT ghostbusting
270  doLCTGhostBustingWithGEMs_ = me11tmbParams.getParameter<bool>("doLCTGhostBustingWithGEMs");
271 
272  // correct LCT timing with GEMs
273  correctLCTtimingWithGEM_ = me11tmbParams.getParameter<bool>("correctLCTtimingWithGEM");
274 
275  // use "old" or "new" dataformat for integrated LCTs?
276  useOldLCTDataFormat_ = me11tmbParams.getParameter<bool>("useOldLCTDataFormat");
277 
278  // promote ALCT-GEM pattern
279  promoteALCTGEMpattern_ = me11tmbParams.getParameter<bool>("promoteALCTGEMpattern");
280 
281  // promote ALCT-GEM quality
282  promoteALCTGEMquality_ = me11tmbParams.getParameter<bool>("promoteALCTGEMquality");
283  promoteCLCTGEMquality_ME1a_ = me11tmbParams.getParameter<bool>("promoteCLCTGEMquality_ME1a");
284  promoteCLCTGEMquality_ME1b_ = me11tmbParams.getParameter<bool>("promoteCLCTGEMquality_ME1b");
285 
286  // send first 2 LCTs
287  firstTwoLCTsInChamber_ = me11tmbParams.getParameter<bool>("firstTwoLCTsInChamber");
288 }
289 
290 
292 {
293  // Constructor used only for testing.
294 
295  clct1a.reset( new CSCCathodeLCTProcessor() );
296  clct1a->setRing(4);
297 
299  for (unsigned int m=2; m<match_trig_window_size; m+=2)
300  {
301  pref[m-1] = pref[0] - m/2;
302  pref[m] = pref[0] + m/2;
303  }
304 }
305 
306 
308 {
309 }
310 
311 
313 {
315  if (clct1a) clct1a->clear();
316  for (int bx = 0; bx < MAX_LCT_BINS; bx++)
317  {
318  //firstLCT1a[bx].clear();
319  //secondLCT1a[bx].clear();
320  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
321  for (int i=0;i<2;i++)
322  {
323  allLCTs1b[bx][mbx][i].clear();
324  allLCTs1a[bx][mbx][i].clear();
325  }
326  }
327  gemRollToEtaLimits_.clear();
328  cscWgToGemRoll_.clear();
329 
330  gemPadToCscHsME1a_.clear();
331  gemPadToCscHsME1b_.clear();
332 
333  cscHsToGemPadME1a_.clear();
334  cscHsToGemPadME1b_.clear();
335 
336  pads_.clear();
337  coPads_.clear();
338 }
339 
340 // Set configuration parameters obtained via EventSetup mechanism.
342 {
343  alct->setConfigParameters(conf);
344  clct->setConfigParameters(conf);
345  clct1a->setConfigParameters(conf);
346  // No config. parameters in DB for the TMB itself yet.
347 }
348 
349 
351  const CSCComparatorDigiCollection* compdc,
352  const GEMPadDigiCollection* gemPads)
353 {
354  clear();
355 
356  if (!( alct and clct and clct1a and smartME1aME1b))
357  {
358  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorSetupError")
359  << "+++ run() called for non-existing ALCT/CLCT processor! +++ \n";
360  return;
361  }
362 
363  alctV = alct->run(wiredc); // run anodeLCT
364  clctV1b = clct->run(compdc); // run cathodeLCT in ME1/b
365  clctV1a = clct1a->run(compdc); // run cathodeLCT in ME1/a
366 
367  bool gemGeometryAvailable(false);
368  if (gem_g != nullptr) {
369  if (infoV >= 0) edm::LogInfo("L1CSCTPEmulatorSetupInfo")
370  << "+++ run() called for GEM-CSC integrated trigger! +++ \n";
371  gemGeometryAvailable = true;
372  }
373 
374  int used_clct_mask[20], used_clct_mask_1a[20];
375  for (int b=0;b<20;b++)
376  used_clct_mask[b] = used_clct_mask_1a[b] = 0;
377 
378  // retrieve CSCChamber geometry
380  const CSCChamber* cscChamberME1b(geo_manager->chamber(theEndcap, theStation, theSector, theSubsector, theTrigChamber));
381  const CSCDetId me1bId(cscChamberME1b->id());
382  const CSCDetId me1aId(me1bId.endcap(), 1, 4, me1bId.chamber());
383  const CSCChamber* cscChamberME1a(csc_g->chamber(me1aId));
384 
385  if (runME11ILT_){
386 
387  // check for GEM geometry
388  if (not gemGeometryAvailable){
389  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorSetupError")
390  << "+++ run() called for GEM-CSC integrated trigger without valid GEM geometry! +++ \n";
391  return;
392  }
393 
394  // trigger geometry
395  const CSCLayer* keyLayerME1b(cscChamberME1b->layer(3));
396  const CSCLayerGeometry* keyLayerGeometryME1b(keyLayerME1b->geometry());
397  const CSCLayer* keyLayerME1a(cscChamberME1a->layer(3));
398  const CSCLayerGeometry* keyLayerGeometryME1a(keyLayerME1a->geometry());
399 
400  const bool isEven(me1bId.chamber()%2==0);
401  const int region((theEndcap == 1) ? 1: -1);
402  const GEMDetId gem_id(region, 1, theStation, 1, me1bId.chamber(), 0);
403  const GEMChamber* gemChamber(gem_g->chamber(gem_id));
404 
405  // initialize depending on whether even or odd
410 
411  // LUT<roll,<etaMin,etaMax> >
412  createGEMRollEtaLUT(isEven);
413  if (debug_luts){
414  LogDebug("CSCMotherboardME11GEM") << "me1b Det "<< me1bId<<" "<< me1bId.rawId() <<" "
415  << (isEven ? "Even":"odd") <<" chamber "<< me1bId.chamber()<<std::endl;
416  if (gemRollToEtaLimits_.size())
417  for(auto p : gemRollToEtaLimits_)
418  LogDebug("CSCMotherboardME11GEM") << "pad "<< p.first << " min eta " << (p.second).first << " max eta " << (p.second).second << std::endl;
419  }
420 
421  // loop on all wiregroups to create a LUT <WG,rollMin,rollMax>
422  const int numberOfWG(keyLayerGeometryME1b->numberOfWireGroups());
423  for (int i = 0; i< numberOfWG; ++i){
424  auto etaMin(isEven ? lut_wg_etaMin_etaMax_even[i][1] : lut_wg_etaMin_etaMax_odd[i][1]);
425  auto etaMax(isEven ? lut_wg_etaMin_etaMax_even[i][2] : lut_wg_etaMin_etaMax_odd[i][2]);
427  }
428  if (debug_luts){
429  for(auto p : cscWgToGemRoll_) {
430  LogDebug("CSCMotherboardME11GEM") << "WG "<< p.first << " GEM pads " << (p.second).first << " " << (p.second).second << std::endl;
431  }
432  }
433 
434  // pick any roll
435  auto randRoll(gemChamber->etaPartition(2));
436 
437  // ME1a
438  auto nStripsME1a(keyLayerGeometryME1a->numberOfStrips());
439  for (float i = 0; i< nStripsME1a; i = i+0.5){
440  const LocalPoint lpCSC(keyLayerGeometryME1a->topology()->localPosition(i));
441  const GlobalPoint gp(keyLayerME1a->toGlobal(lpCSC));
442  const LocalPoint lpGEM(randRoll->toLocal(gp));
443  const int HS(i/0.5);
444  const bool edge(HS < 4 or HS > 93);
445  const float pad(edge ? -99 : randRoll->pad(lpGEM));
446  // HS are wrapped-around
447  cscHsToGemPadME1a_[HS] = std::make_pair(std::floor(pad),std::ceil(pad));
448  }
449  // ME1b
450  auto nStripsME1b(keyLayerGeometryME1b->numberOfStrips());
451  for (float i = 0; i< nStripsME1b; i = i+0.5){
452  const LocalPoint lpCSC(keyLayerGeometryME1b->topology()->localPosition(i));
453  const GlobalPoint gp(keyLayerME1b->toGlobal(lpCSC));
454  const LocalPoint lpGEM(randRoll->toLocal(gp));
455  const int HS(i/0.5);
456  const bool edge(HS < 5 or HS > 124);
457  const float pad(edge ? -99 : randRoll->pad(lpGEM));
458  // HS are wrapped-around
459  cscHsToGemPadME1b_[HS] = std::make_pair(std::floor(pad),std::ceil(pad));
460  }
461  if (debug_luts){
462  LogDebug("CSCMotherboardME11GEM") << "detId " << me1bId;
463  LogDebug("CSCMotherboardME11GEM") << "CSCHSToGEMPad LUT in ME1a";
464  for(auto p : cscHsToGemPadME1a_) {
465  LogDebug("CSCMotherboardME11GEM") << "CSC HS "<< p.first << " GEM Pad low " << (p.second).first << " GEM Pad high " << (p.second).second;
466  }
467  LogDebug("CSCMotherboardME11GEM") << "CSCHSToGEMPad LUT in ME1b";
468  for(auto p : cscHsToGemPadME1b_) {
469  LogDebug("CSCMotherboardME11GEM") << "CSC HS "<< p.first << " GEM Pad low " << (p.second).first << " GEM Pad high " << (p.second).second;
470  }
471  }
472 
473  const int nGEMPads(randRoll->npads());
474  for (int i = 0; i< nGEMPads; ++i){
475  const LocalPoint lpGEM(randRoll->centreOfPad(i));
476  const GlobalPoint gp(randRoll->toGlobal(lpGEM));
477  const LocalPoint lpCSCME1a(keyLayerME1a->toLocal(gp));
478  const LocalPoint lpCSCME1b(keyLayerME1b->toLocal(gp));
479  const float stripME1a(keyLayerGeometryME1a->strip(lpCSCME1a));
480  const float stripME1b(keyLayerGeometryME1b->strip(lpCSCME1b));
481  // HS are wrapped-around
482  gemPadToCscHsME1a_[i] = (int) (stripME1a - 0.25)/0.5;
483  gemPadToCscHsME1b_[i] = (int) (stripME1b - 0.25)/0.5;
484  }
485  if (debug_luts){
486  LogDebug("CSCMotherboardME11GEM") << "detId " << me1bId;
487  LogDebug("CSCMotherboardME11GEM") << "GEMPadToCSCHs LUT in ME1a";
488  for(auto p : gemPadToCscHsME1a_) {
489  LogDebug("CSCMotherboardME11GEM") << "GEM Pad "<< p.first << " CSC HS: " << p.second;
490  }
491  LogDebug("CSCMotherboardME11GEM") << "GEMPadToCSCHs LUT in ME1b";
492  for(auto p : gemPadToCscHsME1b_) {
493  LogDebug("CSCMotherboardME11GEM") << "GEM Pad "<< p.first << " CSC HS: " << p.second;
494  }
495  }
496 
497  // build coincidence pads
498  std::unique_ptr<GEMCoPadDigiCollection> pCoPads(new GEMCoPadDigiCollection());
499  buildCoincidencePads(gemPads, *pCoPads, me1bId);
500 
501  // retrieve pads and copads in a certain BX window for this CSC
502  pads_.clear();
503  coPads_.clear();
504  retrieveGEMPads(gemPads, gem_id);
505  retrieveGEMCoPads(pCoPads.get(), gem_id);
506  }
507 
508  const bool hasPads(pads_.size()!=0);
509  const bool hasCoPads(hasPads and coPads_.size()!=0);
510  bool hasLCTs(false);
511 
512  // ALCT-centric matching
513  for (int bx_alct = 0; bx_alct < CSCAnodeLCTProcessor::MAX_ALCT_BINS; bx_alct++)
514  {
515  if (alct->bestALCT[bx_alct].isValid())
516  {
517  const int bx_clct_start(bx_alct - match_trig_window_size/2);
518  const int bx_clct_stop(bx_alct + match_trig_window_size/2);
519  const int bx_copad_start(bx_alct - maxDeltaBXCoPad_);
520  const int bx_copad_stop(bx_alct + maxDeltaBXCoPad_);
521 
522  if (debug_gem_matching){
523  std::cout << "========================================================================" << std::endl;
524  std::cout << "ALCT-CLCT matching in ME1/1 chamber: " << cscChamberME1b->id() << std::endl;
525  std::cout << "------------------------------------------------------------------------" << std::endl;
526  std::cout << "+++ Best ALCT Details: ";
527  alct->bestALCT[bx_alct].print();
528  std::cout << "+++ Second ALCT Details: ";
529  alct->secondALCT[bx_alct].print();
530 
531  printGEMTriggerPads(bx_clct_start, bx_clct_stop);
532  printGEMTriggerPads(bx_clct_start, bx_clct_stop, true);
533 
534  std::cout << "------------------------------------------------------------------------" << std::endl;
535  std::cout << "Attempt ALCT-CLCT matching in ME1/b in bx range: [" << bx_clct_start << "," << bx_clct_stop << "]" << std::endl;
536  }
537 
538  // ALCT-to-CLCT matching in ME1b
539  int nSuccesFulMatches = 0;
540  for (int bx_clct = bx_clct_start; bx_clct <= bx_clct_stop; bx_clct++)
541  {
542  if (bx_clct < 0 or bx_clct >= CSCCathodeLCTProcessor::MAX_CLCT_BINS) continue;
543  if (drop_used_clcts and used_clct_mask[bx_clct]) continue;
544  if (clct->bestCLCT[bx_clct].isValid())
545  {
546  const int quality(clct->bestCLCT[bx_clct].getQuality());
547  if (debug_gem_matching) std::cout << "++Valid ME1b CLCT: " << clct->bestCLCT[bx_clct] << std::endl;
548 
549  // pick the pad that corresponds
550  auto matchingPads(matchingGEMPads(clct->bestCLCT[bx_clct], alct->bestALCT[bx_alct], pads_[bx_clct], ME1B, false));
551  auto matchingCoPads(matchingGEMPads(clct->bestCLCT[bx_clct], alct->bestALCT[bx_alct], coPads_[bx_clct], ME1B, true));
552  if (runME11ILT_ and dropLowQualityCLCTsNoGEMs_ME1b_ and quality < 4 and hasPads){
553  int nFound(matchingPads.size());
554  const bool clctInEdge(clct->bestCLCT[bx_clct].getKeyStrip() < 5 or clct->bestCLCT[bx_clct].getKeyStrip() > 124);
555  if (clctInEdge){
556  if (debug_gem_matching) std::cout << "\tInfo: low quality CLCT in CSC chamber edge, don't care about GEM pads" << std::endl;
557  }
558  else {
559  if (nFound != 0){
560  if (debug_gem_matching) std::cout << "\tInfo: low quality CLCT with " << nFound << " matching GEM trigger pads" << std::endl;
561  }
562  else {
563  if (debug_gem_matching) std::cout << "\tWarning: low quality CLCT without matching GEM trigger pad" << std::endl;
564  continue;
565  }
566  }
567  }
568 
569  // check timing
571  int nFound(matchingCoPads.size());
572  if (nFound != 0 and bx_alct == 6 and bx_clct != 6){
573  if (debug_gem_matching) std::cout << "\tInfo: CLCT with incorrect timing" << std::endl;
574  continue;
575  }
576  }
577 
578  ++nSuccesFulMatches;
579 
580  hasLCTs = true;
581  // if (infoV > 1) LogTrace("CSCMotherboard")
582  int mbx = bx_clct-bx_clct_start;
583  correlateLCTsGEM(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
584  clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct],
585  allLCTs1b[bx_alct][mbx][0], allLCTs1b[bx_alct][mbx][1], ME1B, matchingPads, matchingCoPads);
586  if (debug_gem_matching) {
587  std::cout << "Successful ALCT-CLCT match in ME1b: bx_alct = " << bx_alct
588  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop
589  << "]; bx_clct = " << bx_clct << std::endl;
590  std::cout << "+++ Best CLCT Details: ";
591  clct->bestCLCT[bx_clct].print();
592  std::cout << "+++ Second CLCT Details: ";
593  clct->secondCLCT[bx_clct].print();
594  }
595 
596  if (allLCTs1b[bx_alct][mbx][0].isValid()) {
597  used_clct_mask[bx_clct] += 1;
599  }
600  }
601  }
602 
603  // ALCT-to-GEM matching in ME1b
604  int nSuccesFulGEMMatches = 0;
605  if (runME11ILT_ and nSuccesFulMatches==0 and buildLCTfromALCTandGEM_ME1b_){
606  if (debug_gem_matching) std::cout << "++No valid ALCT-CLCT matches in ME1b" << std::endl;
607  for (int bx_gem = bx_copad_start; bx_gem <= bx_copad_stop; bx_gem++) {
608  if (not hasCoPads) {
609  continue;
610  }
611 
612  // find the best matching copad - first one
613  auto copads(matchingGEMPads(alct->bestALCT[bx_alct], coPads_[bx_gem], ME1B, true));
614  if (debug_gem_matching) std::cout << "\t++Number of matching GEM CoPads in BX " << bx_alct << " : "<< copads.size() << std::endl;
615  if (copads.size()==0) {
616  continue;
617  }
618 
619  correlateLCTsGEM(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
620  copads.at(0).second, allLCTs1b[bx_alct][0][0], allLCTs1b[bx_alct][0][1], ME1B);
621  if (allLCTs1b[bx_alct][0][0].isValid()) {
622  ++nSuccesFulGEMMatches;
624  }
625  if (debug_gem_matching) {
626  std::cout << "Successful ALCT-GEM CoPad match in ME1b: bx_alct = " << bx_alct << std::endl << std::endl;
627  std::cout << "------------------------------------------------------------------------" << std::endl << std::endl;
628  }
629  }
630  }
631 
632  if (debug_gem_matching) {
633  std::cout << "========================================================================" << std::endl;
634  std::cout << "Summary: " << std::endl;
635  if (nSuccesFulMatches>1)
636  std::cout << "Too many successful ALCT-CLCT matches in ME1b: " << nSuccesFulMatches
637  << ", CSCDetId " << cscChamberME1b->id()
638  << ", bx_alct = " << bx_alct
639  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
640  else if (nSuccesFulMatches==1)
641  std::cout << "1 successful ALCT-CLCT match in ME1b: "
642  << " CSCDetId " << cscChamberME1b->id()
643  << ", bx_alct = " << bx_alct
644  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
645  else if (nSuccesFulGEMMatches==1)
646  std::cout << "1 successful ALCT-GEM match in ME1b: "
647  << " CSCDetId " << cscChamberME1b->id()
648  << ", bx_alct = " << bx_alct
649  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
650  else
651  std::cout << "Unsuccessful ALCT-CLCT match in ME1b: "
652  << "CSCDetId " << cscChamberME1b->id()
653  << ", bx_alct = " << bx_alct
654  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
655 
656  std::cout << "------------------------------------------------------------------------" << std::endl;
657  std::cout << "Attempt ALCT-CLCT matching in ME1/a in bx range: [" << bx_clct_start << "," << bx_clct_stop << "]" << std::endl;
658  }
659 
660  // ALCT-to-CLCT matching in ME1a
661  nSuccesFulMatches = 0;
662  for (int bx_clct = bx_clct_start; bx_clct <= bx_clct_stop; bx_clct++)
663  {
664  if (bx_clct < 0 or bx_clct >= CSCCathodeLCTProcessor::MAX_CLCT_BINS) continue;
665  if (drop_used_clcts and used_clct_mask_1a[bx_clct]) continue;
666  if (clct1a->bestCLCT[bx_clct].isValid())
667  {
668  const int quality(clct1a->bestCLCT[bx_clct].getQuality());
669  if (debug_gem_matching) std::cout << "++Valid ME1a CLCT: " << clct1a->bestCLCT[bx_clct] << std::endl;
670 
671  // pick the pad that corresponds
672  auto matchingPads(matchingGEMPads(clct1a->bestCLCT[bx_clct], alct->bestALCT[bx_alct], pads_[bx_clct], ME1A, false));
673  auto matchingCoPads(matchingGEMPads(clct1a->bestCLCT[bx_clct], alct->bestALCT[bx_alct], coPads_[bx_clct], ME1A, true));
674  if (runME11ILT_ and dropLowQualityCLCTsNoGEMs_ME1a_ and quality < 4 and hasPads){
675  int nFound(matchingPads.size());
676  const bool clctInEdge(clct1a->bestCLCT[bx_clct].getKeyStrip() < 4 or clct1a->bestCLCT[bx_clct].getKeyStrip() > 93);
677  if (clctInEdge){
678  if (debug_gem_matching) std::cout << "\tInfo: low quality CLCT in CSC chamber edge, don't care about GEM pads" << std::endl;
679  }
680  else {
681  if (nFound != 0){
682  if (debug_gem_matching) std::cout << "\tInfo: low quality CLCT with " << nFound << " matching GEM trigger pads" << std::endl;
683  }
684  else {
685  if (debug_gem_matching) std::cout << "\tWarning: low quality CLCT without matching GEM trigger pad" << std::endl;
686  continue;
687  }
688  }
689  }
690  ++nSuccesFulMatches;
691  int mbx = bx_clct-bx_clct_start;
692  correlateLCTsGEM(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
693  clct1a->bestCLCT[bx_clct], clct1a->secondCLCT[bx_clct],
694  allLCTs1a[bx_alct][mbx][0], allLCTs1a[bx_alct][mbx][1], ME1A, matchingPads, matchingCoPads);
695  if (debug_gem_matching) {
696  std::cout << "Successful ALCT-CLCT match in ME1a: bx_alct = " << bx_alct
697  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop
698  << "]; bx_clct = " << bx_clct << std::endl;
699  std::cout << "+++ Best CLCT Details: ";
700  clct1a->bestCLCT[bx_clct].print();
701  std::cout << "+++ Second CLCT Details: ";
702  clct1a->secondCLCT[bx_clct].print();
703  }
704  if (allLCTs1a[bx_alct][mbx][0].isValid()){
705  used_clct_mask_1a[bx_clct] += 1;
707  }
708  }
709  }
710 
711  // ALCT-to-GEM matching in ME1a
712  nSuccesFulGEMMatches = 0;
713  if (runME11ILT_ and nSuccesFulMatches==0 and buildLCTfromALCTandGEM_ME1a_){
714  if (debug_gem_matching) std::cout << "++No valid ALCT-CLCT matches in ME1a" << std::endl;
715  for (int bx_gem = bx_copad_start; bx_gem <= bx_copad_stop; bx_gem++) {
716  if (not hasCoPads) {
717  continue;
718  }
719 
720  // find the best matching copad - first one
721  auto copads(matchingGEMPads(alct->bestALCT[bx_alct], coPads_[bx_gem], ME1A, true));
722  if (debug_gem_matching) std::cout << "\t++Number of matching GEM CoPads in BX " << bx_alct << " : "<< copads.size() << std::endl;
723  if (copads.size()==0) {
724  continue;
725  }
726 
727  correlateLCTsGEM(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
728  copads.at(0).second, allLCTs1a[bx_alct][0][0], allLCTs1a[bx_alct][0][1], ME1A);
729  if (allLCTs1a[bx_alct][0][0].isValid()) {
730  ++nSuccesFulGEMMatches;
732  }
733  if (debug_gem_matching) {
734  std::cout << "Successful ALCT-GEM CoPad match in ME1a: bx_alct = " << bx_alct << std::endl << std::endl;
735  std::cout << "------------------------------------------------------------------------" << std::endl << std::endl;
736  }
737  }
738  }
739 
740  if (debug_gem_matching) {
741  std::cout << "========================================================================" << std::endl;
742  std::cout << "Summary: " << std::endl;
743  if (nSuccesFulMatches>1)
744  std::cout << "Too many successful ALCT-CLCT matches in ME1a: " << nSuccesFulMatches
745  << ", CSCDetId " << cscChamberME1a->id()
746  << ", bx_alct = " << bx_alct
747  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
748  else if (nSuccesFulMatches==1)
749  std::cout << "1 successful ALCT-CLCT match in ME1a: "
750  << " CSCDetId " << cscChamberME1a->id()
751  << ", bx_alct = " << bx_alct
752  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
753  else if (nSuccesFulGEMMatches==1)
754  std::cout << "1 successful ALCT-GEM match in ME1a: "
755  << " CSCDetId " << cscChamberME1a->id()
756  << ", bx_alct = " << bx_alct
757  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
758  else
759  std::cout << "Unsuccessful ALCT-CLCT match in ME1a: "
760  << "CSCDetId " << cscChamberME1a->id()
761  << ", bx_alct = " << bx_alct
762  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
763  }
764 
765  } // end of ALCT valid block
766  else {
767  auto coPads(coPads_[bx_alct]);
768  if (runME11ILT_ and coPads.size()!=0) {
769  // keep it simple for the time being, only consider the first copad
770  const int bx_clct_start(bx_alct - match_trig_window_size/2);
771  const int bx_clct_stop(bx_alct + match_trig_window_size/2);
772 
773  // matching in ME1b
775  for (int bx_clct = bx_clct_start; bx_clct <= bx_clct_stop; bx_clct++) {
776  if (bx_clct < 0 or bx_clct >= CSCCathodeLCTProcessor::MAX_CLCT_BINS) continue;
777  if (drop_used_clcts and used_clct_mask[bx_clct]) continue;
778  if (clct->bestCLCT[bx_clct].isValid()) {
779  const int quality(clct->bestCLCT[bx_clct].getQuality());
780  // only use high-Q stubs for the time being
781  if (quality < 4) continue;
782  int mbx = bx_clct-bx_clct_start;
783  correlateLCTsGEM(clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct], coPads[0].second, GEMDetId(coPads[0].first).roll(),
784  allLCTs1b[bx_alct][mbx][0], allLCTs1b[bx_alct][mbx][1], ME1B);
785  if (debug_gem_matching) {
786  // if (infoV > 1) LogTrace("CSCMotherboard")
787  std::cout << "Successful GEM-CLCT match in ME1b: bx_alct = " << bx_alct
788  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop
789  << "]; bx_clct = " << bx_clct << std::endl;
790  std::cout << "+++ Best CLCT Details: ";
791  clct->bestCLCT[bx_clct].print();
792  std::cout << "+++ Second CLCT Details: ";
793  clct->secondCLCT[bx_clct].print();
794  }
795  if (allLCTs1b[bx_alct][mbx][0].isValid()) {
796  used_clct_mask[bx_clct] += 1;
798  }
799  }
800  }
801  }
802 
803  // matching in ME1a
805  for (int bx_clct = bx_clct_start; bx_clct <= bx_clct_stop; bx_clct++) {
806  if (bx_clct < 0 || bx_clct >= CSCCathodeLCTProcessor::MAX_CLCT_BINS) continue;
807  if (drop_used_clcts && used_clct_mask_1a[bx_clct]) continue;
808  if (clct1a->bestCLCT[bx_clct].isValid()){
809  const int quality(clct1a->bestCLCT[bx_clct].getQuality());
810  // only use high-Q stubs for the time being
811  if (quality < 4) continue;
812  int mbx = bx_clct-bx_clct_start;
813  correlateLCTsGEM(clct1a->bestCLCT[bx_clct], clct1a->secondCLCT[bx_clct], coPads[0].second, GEMDetId(coPads[0].first).roll(),
814  allLCTs1a[bx_alct][mbx][0], allLCTs1a[bx_alct][mbx][1], ME1A);
815  if (debug_gem_matching) {
816  // if (infoV > 1) LogTrace("CSCMotherboard")
817  std::cout << "Successful GEM-CLCT match in ME1a: bx_alct = " << bx_alct
818  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop
819  << "]; bx_clct = " << bx_clct << std::endl;
820  std::cout << "+++ Best CLCT Details: ";
821  clct1a->bestCLCT[bx_clct].print();
822  std::cout << "+++ Second CLCT Details: ";
823  clct1a->secondCLCT[bx_clct].print();
824  }
825  if (allLCTs1a[bx_alct][mbx][0].isValid()){
826  used_clct_mask_1a[bx_clct] += 1;
828  }
829  }
830  }
831  }
832  }
833  }
834  } // end of ALCT-centric matching
835 
836  if (hasLCTs and debug_gem_matching){
837  std::cout << "========================================================================" << std::endl;
838  std::cout << "Counting the LCTs" << std::endl;
839  std::cout << "========================================================================" << std::endl;
840  }
841 
842  // reduction of nLCTs per each BX
843  for (int bx = 0; bx < MAX_LCT_BINS; bx++)
844  {
845  // counting
846  unsigned int n1a=0, n1b=0;
847  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
848  for (int i=0;i<2;i++)
849  {
850  int cbx = bx + mbx - match_trig_window_size/2;
851  if (allLCTs1b[bx][mbx][i].isValid())
852  {
853  n1b++;
854  if (infoV > 0) LogDebug("CSCMotherboard")
855  << "1b LCT"<<i+1<<" "<<bx<<"/"<<cbx<<": "<<allLCTs1b[bx][mbx][i]<<std::endl;
856  }
857  if (allLCTs1a[bx][mbx][i].isValid())
858  {
859  n1a++;
860  if (infoV > 0) LogDebug("CSCMotherboard")
861  << "1a LCT"<<i+1<<" "<<bx<<"/"<<cbx<<": "<<allLCTs1a[bx][mbx][i]<<std::endl;
862  }
863  }
864  if (infoV > 0 and n1a+n1b>0) LogDebug("CSCMotherboard")
865  <<"bx "<<bx<<" nLCT:"<<n1a<<" "<<n1b<<" "<<n1a+n1b<<std::endl;
866 
867  // some simple cross-bx sorting algorithms
868  if (tmb_cross_bx_algo == 1 and (n1a>2 or n1b>2) )
869  {
870  n1a=0, n1b=0;
871  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
872  for (int i=0;i<2;i++)
873  {
874  if (allLCTs1b[bx][pref[mbx]][i].isValid())
875  {
876  n1b++;
877  if (n1b>2) allLCTs1b[bx][pref[mbx]][i].clear();
878  }
879  if (allLCTs1a[bx][pref[mbx]][i].isValid())
880  {
881  n1a++;
882  if (n1a>2) allLCTs1a[bx][pref[mbx]][i].clear();
883  }
884  }
885 
886  n1a=0, n1b=0;
887  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
888  for (int i=0;i<2;i++)
889  {
890  int cbx = bx + mbx - match_trig_window_size/2;
891  if (allLCTs1b[bx][mbx][i].isValid())
892  {
893  n1b++;
894  if (infoV > 0) LogDebug("CSCMotherboard")
895  << "1b LCT"<<i+1<<" "<<bx<<"/"<<cbx<<": "<<allLCTs1b[bx][mbx][i]<<std::cout;
896  }
897  if (allLCTs1a[bx][mbx][i].isValid())
898  {
899  n1a++;
900  if (infoV > 0) LogDebug("CSCMotherboard")
901  << "1a LCT"<<i+1<<" "<<bx<<"/"<<cbx<<": "<<allLCTs1a[bx][mbx][i]<<std::cout;
902  }
903  }
904  if (infoV > 0 and n1a+n1b>0) LogDebug("CSCMotherboard")
905  <<"bx "<<bx<<" nnLCT:"<<n1a<<" "<<n1b<<" "<<n1a+n1b<<std::endl;
906  } // x-bx sorting
907 
908  // Maximum 2 per whole ME11 per BX case:
909  // (supposedly, now we should have max 2 per bx in each 1a and 1b)
910  if (n1a+n1b > max_me11_lcts and tmb_cross_bx_algo == 1)
911  {
912  // do it simple so far: take all low eta 1/b stubs
913  unsigned int nLCT=n1b;
914  n1a=0;
915  // right now nLCT<=2; cut 1a if necessary
916  for (unsigned int mbx=0; mbx<match_trig_window_size; mbx++)
917  for (int i=0;i<2;i++)
918  if (allLCTs1a[bx][mbx][i].isValid()) {
919  nLCT++;
920  if (nLCT>max_me11_lcts) allLCTs1a[bx][mbx][i].clear();
921  else n1a++;
922  }
923  // if (infoV > 0 and nLCT>0) LogDebug("CSCMotherboard")
924 // std::cout <<"bx "<<bx<<" nnnLCT: "<<n1a<<" "<<n1b<<" "<<n1a+n1b<<std::cout;
925  }
926  }// reduction per bx
927 
928  bool first = true;
929  unsigned int n1b=0, n1a=0;
930  for (auto p : readoutLCTs1b())
931  {
932  if (debug_gem_matching and first){
933  std::cout << "========================================================================" << std::endl;
934  std::cout << "Counting the final LCTs" << std::endl;
935  std::cout << "========================================================================" << std::endl;
936  first = false;
937  std::cout << "tmb_cross_bx_algo: " << tmb_cross_bx_algo << std::endl;
938 
939  }
940  n1b++;
941  if (debug_gem_matching)
942  std::cout << "1b LCT "<<n1b<<" " << p <<std::endl;
943  }
944 
945  for (auto p : readoutLCTs1a())
946  {
947  if (debug_gem_matching and first){
948  std::cout << "========================================================================" << std::endl;
949  std::cout << "Counting the final LCTs" << std::endl;
950  std::cout << "========================================================================" << std::endl;
951  first = false;
952  std::cout << "tmb_cross_bx_algo: " << tmb_cross_bx_algo << std::endl;
953  }
954  n1a++;
955  if (debug_gem_matching)
956  std::cout << "1a LCT "<<n1a<<" " << p <<std::endl;
957  }
958 
959  // if (infoV > 1) LogTrace("CSCMotherboardME11GEM")<<"clct_count E:"<<theEndcap<<"S:"<<theStation<<"R:"<<1<<"C:"
960  // <<CSCTriggerNumbering::chamberFromTriggerLabels(theSector,theSubsector, theStation, theTrigChamber)
961  // <<" a "<<n_clct_a<<" b "<<n_clct_b<<" ab "<<n_clct_a+n_clct_b;
962 }
963 
964 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::readoutLCTs1a()
965 {
966  return readoutLCTs(ME1A);
967 }
968 
969 
970 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::readoutLCTs1b()
971 {
972  return readoutLCTs(ME1B);
973 }
974 
975 
976 // Returns vector of read-out correlated LCTs, if any. Starts with
977 // the vector of all found LCTs and selects the ones in the read-out
978 // time window.
979 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::readoutLCTs(enum ME11Part me1ab)
980 {
981  std::vector<CSCCorrelatedLCTDigi> tmpV;
982 
983  // The start time of the L1A*LCT coincidence window should be related
984  // to the fifo_pretrig parameter, but I am not completely sure how.
985  // Just choose it such that the window is centered at bx=7. This may
986  // need further tweaking if the value of tmb_l1a_window_size changes.
987  //static int early_tbins = 4;
988  // The number of LCT bins in the read-out is given by the
989  // tmb_l1a_window_size parameter, forced to be odd
990  static int lct_bins =
992  static int late_tbins = early_tbins + lct_bins;
993 
994 
995  // Start from the vector of all found correlated LCTs and select
996  // those within the LCT*L1A coincidence window.
997  int bx_readout = -1;
998  std::vector<CSCCorrelatedLCTDigi> tmp_lcts;
999  std::vector<CSCCorrelatedLCTDigi> all_lcts;
1000  if (me1ab == ME1A) tmp_lcts = getLCTs1a();
1001  if (me1ab == ME1B) tmp_lcts = getLCTs1b();
1002  switch(tmb_cross_bx_algo){
1003  case 0: all_lcts = tmp_lcts;
1004  break;
1005  case 1: all_lcts = tmp_lcts;
1006  break;
1007  case 2: all_lcts = sortLCTsByQuality(me1ab);
1008  break;
1009  case 3: all_lcts = sortLCTsByGEMDPhi(me1ab);
1010  break;
1011  default: std::cout<<"tmb_cross_bx_algo error" <<std::endl;
1012  break;
1013  }
1014  std::vector <CSCCorrelatedLCTDigi>::const_iterator plct = all_lcts.begin();
1015  for (; plct != all_lcts.end(); plct++)
1016  {
1017  if (!plct->isValid()) continue;
1018 
1019  int bx = (*plct).getBX();
1020  // Skip LCTs found too early relative to L1Accept.
1021  if (bx <= early_tbins) continue;
1022 
1023  // Skip LCTs found too late relative to L1Accept.
1024  if (bx > late_tbins) continue;
1025 
1026  // If (readout_earliest_2) take only LCTs in the earliest bx in the read-out window:
1027  // in digi->raw step, LCTs have to be packed into the TMB header, and
1028  // currently there is room just for two.
1029  if (readout_earliest_2 and (bx_readout == -1 or bx == bx_readout) )
1030  {
1031  tmpV.push_back(*plct);
1032  if (bx_readout == -1) bx_readout = bx;
1033  }
1034  else tmpV.push_back(*plct);
1035  }
1036  return tmpV;
1037 }
1038 
1039 
1040 // Returns vector of found correlated LCTs, if any.
1041 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::getLCTs1b()
1042 {
1043  std::vector<CSCCorrelatedLCTDigi> tmpV;
1044 
1045  for (int bx = 0; bx < MAX_LCT_BINS; bx++)
1046  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
1047  for (int i=0;i<2;i++)
1048  if (allLCTs1b[bx][mbx][i].isValid()) tmpV.push_back(allLCTs1b[bx][mbx][i]);
1049  return tmpV;
1050 }
1051 
1052 
1053 // Returns vector of found correlated LCTs, if any.
1054 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::getLCTs1a()
1055 {
1056  std::vector<CSCCorrelatedLCTDigi> tmpV;
1057 
1058  // disabled ME1a
1059  if (mpc_block_me1a or disableME1a) return tmpV;
1060 
1061  // Report all LCTs found.
1062  for (int bx = 0; bx < MAX_LCT_BINS; bx++)
1063  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
1064  for (int i=0;i<2;i++)
1065  if (allLCTs1a[bx][mbx][i].isValid()) tmpV.push_back(allLCTs1a[bx][mbx][i]);
1066  return tmpV;
1067 }
1068 
1069 
1070 //sort LCTs by Quality in each BX
1071 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::sortLCTsByQuality(int bx, enum ME11Part me)
1072 {
1073  auto allLCTs(me==ME1A ? allLCTs1a : allLCTs1b);
1074  std::vector<CSCCorrelatedLCTDigi> LCTs;
1075  std::vector<CSCCorrelatedLCTDigi> tmpV;
1076  tmpV.clear();
1077  LCTs.clear();
1078  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
1079  for (int i=0;i<2;i++)
1080  if (allLCTs[bx][mbx][i].isValid())
1081  LCTs.push_back(allLCTs[bx][mbx][i]);
1082 
1083  std::sort(LCTs.begin(), LCTs.end(), CSCMotherboard::sortByQuality);
1084  tmpV = LCTs;
1085  if (tmpV.size()> max_me11_lcts) tmpV.erase(tmpV.begin()+max_me11_lcts, tmpV.end());
1086  return tmpV;
1087 }
1088 
1089 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::sortLCTsByQuality(std::vector<CSCCorrelatedLCTDigi> LCTs)
1090 {
1091  std::vector<CSCCorrelatedLCTDigi> tmpV;
1092  tmpV.clear();
1093  std::sort(LCTs.begin(), LCTs.end(), CSCMotherboard::sortByQuality);
1094  tmpV = LCTs;
1095  if (tmpV.size()> max_me11_lcts) tmpV.erase(tmpV.begin()+max_me11_lcts, tmpV.end());
1096  return tmpV;
1097 }
1098 
1099 
1100 //sort LCTs in whole LCTs BX window
1101 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::sortLCTsByQuality(enum ME11Part me)
1102 {
1103  std::vector<CSCCorrelatedLCTDigi> LCTs_final;
1104  LCTs_final.clear();
1105  for (int bx = 0; bx < MAX_LCT_BINS; bx++)
1106  {
1107  std::vector<CSCCorrelatedLCTDigi> LCTs1a;
1108  std::vector<CSCCorrelatedLCTDigi> LCTs1b;
1109  std::vector<CSCCorrelatedLCTDigi> LCTs_tmp;
1110  std::vector<CSCCorrelatedLCTDigi> LCTs_tmp1;
1111  LCTs1a = sortLCTsByQuality(bx, ME1A);
1112  LCTs1b = sortLCTsByQuality(bx, ME1B);
1113  std::vector<CSCCorrelatedLCTDigi>::iterator it1a = LCTs1a.begin();
1114  std::vector<CSCCorrelatedLCTDigi>::iterator it1b = LCTs1b.begin();
1115  LCTs_tmp.insert(LCTs_tmp.begin(), LCTs1b.begin(), LCTs1b.end());
1116  LCTs_tmp.insert(LCTs_tmp.end(), LCTs1a.begin(), LCTs1a.end());
1117  LCTs_tmp1 = sortLCTsByQuality(LCTs_tmp);//LCTs reduction per BX
1119  {
1120  std::vector<CSCCorrelatedLCTDigi>::iterator itp = LCTs_tmp1.begin();
1121  for ( ; itp != LCTs_tmp1.end(); itp++)
1122  {
1123  if (me==ME1A and it1a != LCTs1a.end() and *itp==*it1a )
1124  {
1125  LCTs_final.push_back(*it1a);
1126  it1a++;
1127  }
1128  if (me==ME1B and it1b != LCTs1b.end() and *itp==*it1b)
1129  {
1130  LCTs_final.push_back(*it1b);
1131  it1b++;
1132  }
1133  }
1134  }
1135  else {
1136  if (LCTs1a.size() and LCTs1b.size() and me==ME1A)
1137  LCTs_final.push_back(*LCTs1a.begin());
1138  else if (LCTs1a.size() and LCTs1b.size() and me==ME1B)
1139  LCTs_final.push_back(*LCTs1b.begin());
1140  else if (LCTs1a.size() and LCTs1b.size()==0 and me==ME1A)
1141  LCTs_final.insert(LCTs_final.end(), LCTs1a.begin(), LCTs1a.end());
1142  else if (LCTs1b.size() and LCTs1a.size()==0 and me==ME1B)
1143  LCTs_final.insert(LCTs_final.end(), LCTs1b.begin(), LCTs1b.end());
1144  }
1145  }
1146  return LCTs_final;
1147 }
1148 
1149 
1150 //sort LCTs by GEMDPhi in each BX
1151 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::sortLCTsByGEMDPhi(int bx, enum ME11Part me)
1152 {
1153 
1154  auto allLCTs(me==ME1A ? allLCTs1a : allLCTs1b);
1155  std::vector<CSCCorrelatedLCTDigi> LCTs;
1156  std::vector<CSCCorrelatedLCTDigi> tmpV;
1157  tmpV.clear();
1158  LCTs.clear();
1159  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
1160  for (int i=0;i<2;i++)
1161  if (allLCTs[bx][mbx][i].isValid())
1162  LCTs.push_back(allLCTs[bx][mbx][i]);
1163 
1164  std::sort(LCTs.begin(), LCTs.end(), CSCMotherboard::sortByGEMDphi);
1165  tmpV = LCTs;
1166  if (tmpV.size() > max_me11_lcts) tmpV.erase(tmpV.begin()+max_me11_lcts, tmpV.end());
1167  return tmpV;
1168 }
1169 
1170 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::sortLCTsByGEMDPhi(std::vector<CSCCorrelatedLCTDigi> LCTs)
1171 {
1172  std::vector<CSCCorrelatedLCTDigi> tmpV;
1173  tmpV.clear();
1174  std::sort(LCTs.begin(), LCTs.end(), CSCMotherboard::sortByGEMDphi);
1175  tmpV = LCTs;
1176  if (tmpV.size() > max_me11_lcts) tmpV.erase(tmpV.begin()+max_me11_lcts, tmpV.end());
1177  return tmpV;
1178 }
1179 
1180 
1181 //sort LCTs in whole LCTs BX window
1182 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME11GEM::sortLCTsByGEMDPhi(enum ME11Part me)
1183 {
1184  std::vector<CSCCorrelatedLCTDigi> LCTs_final;
1185  LCTs_final.clear();
1186  for (int bx = 0; bx < MAX_LCT_BINS; bx++)
1187  {
1188  std::vector<CSCCorrelatedLCTDigi> LCTs1a;
1189  std::vector<CSCCorrelatedLCTDigi> LCTs1b;
1190  std::vector<CSCCorrelatedLCTDigi> LCTs_tmp;
1191  std::vector<CSCCorrelatedLCTDigi> LCTs_tmp1;
1192  LCTs1a = sortLCTsByGEMDPhi(bx, ME1A);
1193  LCTs1b = sortLCTsByGEMDPhi(bx, ME1B);
1194  std::vector<CSCCorrelatedLCTDigi>::iterator it1a = LCTs1a.begin();
1195  std::vector<CSCCorrelatedLCTDigi>::iterator it1b = LCTs1b.begin();
1196  LCTs_tmp.insert(LCTs_tmp.begin(), LCTs1b.begin(), LCTs1b.end());
1197  LCTs_tmp.insert(LCTs_tmp.end(), LCTs1a.begin(), LCTs1a.end());
1198  LCTs_tmp1 = sortLCTsByGEMDPhi(LCTs_tmp);//LCTs reduction per BX
1200  {
1201  std::vector<CSCCorrelatedLCTDigi>::iterator itp = LCTs_tmp1.begin();
1202  while (itp != LCTs_tmp1.end())
1203  {
1204  if (me==ME1B and it1b != LCTs1b.end() and *itp==*it1b)
1205  {
1206  LCTs_final.push_back(*it1b);
1207  it1b++;
1208  }
1209  if (me==ME1A and it1a != LCTs1a.end() and *itp==*it1a)
1210  {
1211  LCTs_final.push_back(*it1a);
1212  it1a++;
1213  }
1214  itp++;
1215  }
1216  }
1217  else {
1218  if (LCTs1a.size() and LCTs1b.size() and me==ME1A)
1219  LCTs_final.push_back(*LCTs1a.begin());
1220  else if (LCTs1a.size() and LCTs1b.size() and me==ME1B)
1221  LCTs_final.push_back(*LCTs1b.begin());
1222  else if (LCTs1a.size() and LCTs1b.size()==0 and me==ME1A)
1223  LCTs_final.insert(LCTs_final.end(), LCTs1a.begin(), LCTs1a.end());
1224  else if (LCTs1b.size() and LCTs1a.size()==0 and me==ME1B)
1225  LCTs_final.insert(LCTs_final.end(), LCTs1b.begin(), LCTs1b.end());
1226  }
1227  }
1228  return LCTs_final;
1229 }
1230 
1231 
1233 {
1234  if ( !c.isValid() or !a.isValid() ) return false;
1235  int key_hs = c.getKeyStrip();
1236  int key_wg = a.getKeyWG();
1237  if ( me == ME1A )
1238  {
1239  if ( !gangedME1a )
1240  {
1241  // wrap around ME11 HS number for -z endcap
1242  if (theEndcap==2) key_hs = 95 - key_hs;
1243  if ( key_hs >= lut_wg_vs_hs_me1a[key_wg][0] and
1244  key_hs <= lut_wg_vs_hs_me1a[key_wg][1] ) return true;
1245  return false;
1246  }
1247  else
1248  {
1249  if (theEndcap==2) key_hs = 31 - key_hs;
1250  if ( key_hs >= lut_wg_vs_hs_me1ag[key_wg][0] and
1251  key_hs <= lut_wg_vs_hs_me1ag[key_wg][1] ) return true;
1252  return false;
1253  }
1254  }
1255  if ( me == ME1B)
1256  {
1257  if (theEndcap==2) key_hs = 127 - key_hs;
1258  if ( key_hs >= lut_wg_vs_hs_me1b[key_wg][0] and
1259  key_hs <= lut_wg_vs_hs_me1b[key_wg][1] ) return true;
1260  }
1261  return false;
1262 }
1263 
1265  CSCALCTDigi secondALCT,
1266  CSCCLCTDigi bestCLCT,
1267  CSCCLCTDigi secondCLCT,
1268  CSCCorrelatedLCTDigi& lct1,
1269  CSCCorrelatedLCTDigi& lct2)
1270 {
1271  bool anodeBestValid = bestALCT.isValid();
1272  bool anodeSecondValid = secondALCT.isValid();
1273  bool cathodeBestValid = bestCLCT.isValid();
1274  bool cathodeSecondValid = secondCLCT.isValid();
1275 
1276  if (anodeBestValid and !anodeSecondValid) secondALCT = bestALCT;
1277  if (!anodeBestValid and anodeSecondValid) bestALCT = secondALCT;
1278  if (cathodeBestValid and !cathodeSecondValid) secondCLCT = bestCLCT;
1279  if (!cathodeBestValid and cathodeSecondValid) bestCLCT = secondCLCT;
1280 
1281  // ALCT-CLCT matching conditions are defined by "trig_enable" configuration
1282  // parameters.
1283  if ((alct_trig_enable and bestALCT.isValid()) or
1284  (clct_trig_enable and bestCLCT.isValid()) or
1285  (match_trig_enable and bestALCT.isValid() and bestCLCT.isValid()))
1286  {
1287  lct1 = constructLCTs(bestALCT, bestCLCT);
1288  lct1.setTrknmb(1);
1289  }
1290 
1291  if (((secondALCT != bestALCT) or (secondCLCT != bestCLCT)) and
1292  ((alct_trig_enable and secondALCT.isValid()) or
1293  (clct_trig_enable and secondCLCT.isValid()) or
1294  (match_trig_enable and secondALCT.isValid() and secondCLCT.isValid())))
1295  {
1296  lct2 = constructLCTs(secondALCT, secondCLCT);
1297  lct2.setTrknmb(2);
1298  }
1299 }
1300 
1301 
1303  CSCALCTDigi secondALCT,
1304  GEMPadDigi gemPad,
1305  CSCCorrelatedLCTDigi& lct1,
1306  CSCCorrelatedLCTDigi& lct2, int ME)
1307 {
1308  bool anodeBestValid = bestALCT.isValid();
1309  bool anodeSecondValid = secondALCT.isValid();
1310 
1311  if (anodeBestValid and !anodeSecondValid) secondALCT = bestALCT;
1312  if (!anodeBestValid and anodeSecondValid) bestALCT = secondALCT;
1313 
1314  if ((alct_trig_enable and bestALCT.isValid()) or
1315  (match_trig_enable and bestALCT.isValid()))
1316  {
1317  lct1 = constructLCTsGEM(bestALCT, gemPad, ME, useOldLCTDataFormat_);
1318  lct1.setTrknmb(1);
1319  // lct1.setGEMDPhi(0.0);
1320  }
1321 
1322  if ((alct_trig_enable and secondALCT.isValid()) or
1323  (match_trig_enable and secondALCT.isValid() and secondALCT != bestALCT))
1324  {
1325  lct2 = constructLCTsGEM(secondALCT, gemPad, ME, useOldLCTDataFormat_);
1326  lct2.setTrknmb(2);
1327  // lct2.setGEMDPhi(0.0);
1328  }
1329 }
1330 
1331 
1333  CSCCLCTDigi secondCLCT,
1334  GEMPadDigi gemPad, int roll,
1335  CSCCorrelatedLCTDigi& lct1,
1336  CSCCorrelatedLCTDigi& lct2, int ME)
1337 {
1338  bool cathodeBestValid = bestCLCT.isValid();
1339  bool cathodeSecondValid = secondCLCT.isValid();
1340 
1341  if (cathodeBestValid and !cathodeSecondValid) secondCLCT = bestCLCT;
1342  if (!cathodeBestValid and cathodeSecondValid) bestCLCT = secondCLCT;
1343 
1344  if ((clct_trig_enable and bestCLCT.isValid()) or
1345  (match_trig_enable and bestCLCT.isValid()))
1346  {
1347  lct1 = constructLCTsGEM(bestCLCT, gemPad, roll, ME, useOldLCTDataFormat_);
1348  lct1.setTrknmb(1);
1349  }
1350 
1351  if ((clct_trig_enable and secondCLCT.isValid()) or
1352  (match_trig_enable and secondCLCT.isValid() and secondCLCT != bestCLCT))
1353  {
1354  lct2 = constructLCTsGEM(secondCLCT, gemPad, roll, ME, useOldLCTDataFormat_);
1355  lct2.setTrknmb(2);
1356  }
1357 }
1358 
1360  CSCALCTDigi secondALCT,
1361  CSCCLCTDigi bestCLCT,
1362  CSCCLCTDigi secondCLCT,
1363  CSCCorrelatedLCTDigi& lct1,
1364  CSCCorrelatedLCTDigi& lct2,
1365  int me,
1366  const GEMPadsBX& pads,
1367  const GEMPadsBX& copads)
1368 {
1369  // assume that always anodeBestValid and cathodeBestValid
1370 
1371  if (secondALCT == bestALCT) secondALCT.clear();
1372  if (secondCLCT == bestCLCT) secondCLCT.clear();
1373 
1374  int ok11 = doesALCTCrossCLCT( bestALCT, bestCLCT, me);
1375  int ok12 = doesALCTCrossCLCT( bestALCT, secondCLCT, me);
1376  int ok21 = doesALCTCrossCLCT( secondALCT, bestCLCT, me);
1377  int ok22 = doesALCTCrossCLCT( secondALCT, secondCLCT, me);
1378  int code = (ok11<<3) | (ok12<<2) | (ok21<<1) | (ok22);
1379 
1380  int dbg=0;
1381  int ring = me;
1383  CSCDetId did(theEndcap, theStation, ring, chamb, 0);
1384  if (dbg) LogTrace("CSCMotherboardME11GEM")<<"debug correlateLCTs in "<<did<<std::endl
1385  <<"ALCT1: "<<bestALCT<<std::endl
1386  <<"ALCT2: "<<secondALCT<<std::endl
1387  <<"CLCT1: "<<bestCLCT<<std::endl
1388  <<"CLCT2: "<<secondCLCT<<std::endl
1389  <<"ok 11 12 21 22 code = "<<ok11<<" "<<ok12<<" "<<ok21<<" "<<ok22<<" "<<code<<std::endl;
1390 
1391  if ( code==0 ) return;
1392 
1393  // LUT defines correspondence between possible ok## combinations
1394  // and resulting lct1 and lct2
1395  int lut[16][2] = {
1396  //ok: 11 12 21 22
1397  {0 ,0 }, // 0 0 0 0
1398  {22,0 }, // 0 0 0 1
1399  {21,0 }, // 0 0 1 0
1400  {21,22}, // 0 0 1 1
1401  {12,0 }, // 0 1 0 0
1402  {12,22}, // 0 1 0 1
1403  {12,21}, // 0 1 1 0
1404  {12,21}, // 0 1 1 1
1405  {11,0 }, // 1 0 0 0
1406  {11,22}, // 1 0 0 1
1407  {11,21}, // 1 0 1 0
1408  {11,22}, // 1 0 1 1
1409  {11,12}, // 1 1 0 0
1410  {11,22}, // 1 1 0 1
1411  {11,12}, // 1 1 1 0
1412  {11,22}, // 1 1 1 1
1413  };
1414 
1415  if (dbg) LogTrace("CSCMotherboardME11GEM")<<"lut 0 1 = "<<lut[code][0]<<" "<<lut[code][1]<<std::endl;
1416 
1417  // first check the special case (11,22) where we have an ambiguity
1418  const int nPads(pads.size());
1419  const int nCoPads(copads.size());
1420  const bool hasPads(nPads!=0);
1421  const bool hasCoPads(nCoPads!=0);
1422 
1423  if (doLCTGhostBustingWithGEMs_ and (lut[code][0] == 11) and (lut[code][0] == 22) and hasPads and (me==ME1B)){
1424 
1425  if (debug_gem_matching) std::cout << "++Info: 2 valid ALCTs-CLCTs pairs with trigger pads. Call the GHOSTBUSTERS!!!" << std::endl;
1426  // first check if there are any copads
1427  typedef std::pair<int,int> mypair;
1428  // for each trigger pad, store (deltaRoll,deltaHS) for 11,22,12 and 21.
1429  std::vector<std::tuple<mypair,mypair,mypair,mypair>> deltas;
1430  deltas.clear();
1431 
1432  if (hasCoPads){
1433  for (auto p : copads) {
1434  const GEMDetId detId(p.first);
1435  const int rollN(detId.roll());
1436  const int padN((p.second).pad());
1437 
1438  auto t11(std::make_pair(deltaRoll( bestALCT.getKeyWG(), rollN), deltaPad( bestCLCT.getKeyStrip(), padN)));
1439  auto t22(std::make_pair(deltaRoll(secondALCT.getKeyWG(), rollN), deltaPad(secondCLCT.getKeyStrip(), padN)));
1440  auto t12(std::make_pair(deltaRoll( bestALCT.getKeyWG(), rollN), deltaPad(secondCLCT.getKeyStrip(), padN)));
1441  auto t21(std::make_pair(deltaRoll(secondALCT.getKeyWG(), rollN), deltaPad( bestCLCT.getKeyStrip(), padN)));
1442 
1443  deltas.push_back(std::make_tuple(t11,t22,t12,t21));
1444  }
1445  if (debug_gem_matching){
1446  std::cout << "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " << std::endl;
1447  std::cout << "Printing (deltaRoll, deltaPad) for each (ALCT,CLCT) pair and for each trigger copad" << std::endl;
1448  for (unsigned i =0; i < deltas.size(); ++i){
1449  auto c(deltas.at(i));
1450  std::cout << "\tCoPad " << i << std::endl;
1451  std::cout << "\t11: " << "(" << std::get<0>(c).first << "," << std::get<0>(c).second << "); "
1452  << "22: " << "(" << std::get<1>(c).first << "," << std::get<1>(c).second << "); "
1453  << "12: " << "(" << std::get<2>(c).first << "," << std::get<2>(c).second << "); "
1454  << "21: " << "(" << std::get<3>(c).first << "," << std::get<3>(c).second << ")" << std::endl << std::endl;
1455  }
1456  std::cout << "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " << std::endl;
1457  }
1458 
1459 
1460 // lct1 = constructLCTs(bestALCT, bestCLCT);
1461 // lct1.setTrknmb(1);
1462 // lct2 = constructLCTs(secondALCT, secondCLCT);
1463 // lct2.setTrknmb(2);
1464 
1465 // lct1 = constructLCTs(bestALCT, secondCLCT);
1466 // lct1.setTrknmb(1);
1467 // lct2 = constructLCTs(secondLCT, bestCLCT);
1468 // lct2.setTrknmb(2);
1469  return;
1470  }
1471 
1472  // if no copads were found, do the same with pads...
1473  if (hasPads){
1474  for (auto p : pads) {
1475  const GEMDetId detId(p.first);
1476  const int rollN(detId.roll());
1477  const int padN((p.second).pad());
1478 
1479  auto t11(std::make_pair(deltaRoll( bestALCT.getKeyWG(), rollN), deltaPad( bestCLCT.getKeyStrip(), padN)));
1480  auto t22(std::make_pair(deltaRoll(secondALCT.getKeyWG(), rollN), deltaPad(secondCLCT.getKeyStrip(), padN)));
1481  auto t12(std::make_pair(deltaRoll( bestALCT.getKeyWG(), rollN), deltaPad(secondCLCT.getKeyStrip(), padN)));
1482  auto t21(std::make_pair(deltaRoll(secondALCT.getKeyWG(), rollN), deltaPad( bestCLCT.getKeyStrip(), padN)));
1483 
1484  deltas.push_back(std::make_tuple(t11,t22,t12,t21));
1485  }
1486  if (debug_gem_matching){
1487  std::cout << "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " << std::endl;
1488  std::cout << "Printing (deltaRoll, deltaPad) for each (ALCT,CLCT) pair and for each trigger pad" << std::endl;
1489  for (unsigned i =0; i < deltas.size(); ++i){
1490  auto c(deltas.at(i));
1491  std::cout << "\tPad " << i << std::endl;
1492  std::cout << "\t11: " << "(" << std::get<0>(c).first << "," << std::get<0>(c).second << "); "
1493  << "22: " << "(" << std::get<1>(c).first << "," << std::get<1>(c).second << "); "
1494  << "12: " << "(" << std::get<2>(c).first << "," << std::get<2>(c).second << "); "
1495  << "21: " << "(" << std::get<3>(c).first << "," << std::get<3>(c).second << ")" << std::endl << std::endl;
1496  }
1497  std::cout << "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " << std::endl;
1498  }
1499 
1500  return;
1501  }
1502  }
1503 
1504  switch (lut[code][0]) {
1505  case 11:
1506  lct1 = constructLCTsGEM(bestALCT, bestCLCT, hasPads, hasCoPads);
1507  break;
1508  case 12:
1509  lct1 = constructLCTsGEM(bestALCT, secondCLCT, hasPads, hasCoPads);
1510  break;
1511  case 21:
1512  lct1 = constructLCTsGEM(secondALCT, bestCLCT, hasPads, hasCoPads);
1513  break;
1514  case 22:
1515  lct1 = constructLCTsGEM(secondALCT, secondCLCT, hasPads, hasCoPads);
1516  break;
1517  default:
1518  return;
1519  }
1520  lct1.setTrknmb(1);
1521 
1522  if (dbg) LogTrace("CSCMotherboardME11GEM")<<"lct1: "<<lct1<<std::endl;
1523 
1524  switch (lut[code][1])
1525  {
1526  case 12:
1527  lct2 = constructLCTsGEM(bestALCT, secondCLCT, hasPads, hasCoPads);
1528  lct2.setTrknmb(2);
1529  if (dbg) LogTrace("CSCMotherboardME11GEM")<<"lct2: "<<lct2<<std::endl;
1530  return;
1531  case 21:
1532  lct2 = constructLCTsGEM(secondALCT, bestCLCT, hasPads, hasCoPads);
1533  lct2.setTrknmb(2);
1534  if (dbg) LogTrace("CSCMotherboardME11GEM")<<"lct2: "<<lct2<<std::endl;
1535  return;
1536  case 22:
1537  lct2 = constructLCTsGEM(secondALCT, secondCLCT, hasPads, hasCoPads);
1538  lct2.setTrknmb(2);
1539  if (dbg) LogTrace("CSCMotherboardME11GEM")<<"lct2: "<<lct2<<std::endl;
1540  return;
1541  default:
1542  return;
1543  }
1544  if (dbg) LogTrace("CSCMotherboardME11GEM")<<"out of correlateLCTs"<<std::endl;
1545 
1546  return;
1547 }
1548 
1550  GEMCoPadDigiCollection& out_co_pads,
1551  CSCDetId csc_id)
1552 {
1553  gemCoPadV.clear();
1554 
1555  // Build coincidences
1556  for (auto det_range = out_pads->begin(); det_range != out_pads->end(); ++det_range) {
1557  const GEMDetId& id = (*det_range).first;
1558  // same chamber
1559  if (id.region() != csc_id.zendcap() or id.station() != csc_id.station() or
1560  id.ring() != csc_id.ring() or id.chamber() != csc_id.chamber()) continue;
1561 
1562  // all coincidences detIDs will have layer=1
1563  if (id.layer() != 1) continue;
1564 
1565  // find the corresponding id with layer=2
1566  GEMDetId co_id(id.region(), id.ring(), id.station(), 2, id.chamber(), id.roll());
1567 
1568  auto co_pads_range = out_pads->get(co_id);
1569  // empty range = no possible coincidence pads
1570  if (co_pads_range.first == co_pads_range.second) continue;
1571 
1572  // now let's correlate the pads in two layers of this partition
1573  const auto& pads_range = (*det_range).second;
1574  for (auto p = pads_range.first; p != pads_range.second; ++p) {
1575  for (auto co_p = co_pads_range.first; co_p != co_pads_range.second; ++co_p) {
1576  // check the match in pad
1577  if (std::abs(p->pad() - co_p->pad()) > maxDeltaPadInCoPad_) continue;
1578  // check the match in BX
1579  if (std::abs(p->bx() - co_p->bx()) > maxDeltaBXInCoPad_ ) continue;
1580 
1581  // make a new coincidence pad digi
1582  gemCoPadV.push_back(GEMCoPadDigi(id.roll(),*p,*co_p));
1583  out_co_pads.insertDigi(id, GEMCoPadDigi(id.roll(),*p,*co_p));
1584  }
1585  }
1586  }
1587 }
1588 
1589 
1591 {
1592  int ch(isEven ? 2 : 1);
1593  auto chamber(gem_g->chamber(GEMDetId(1,1,1,1,ch,0)));
1594  if (chamber==nullptr) return;
1595 
1596  int n = 1;
1597  if (isEven) n = 2; // this only works for the 9-10 partition geometry!!! FIXME
1598  for(auto roll : chamber->etaPartitions()) {
1599  const float half_striplength(roll->specs()->specificTopology().stripLength()/2.);
1600  const LocalPoint lp_top(0., half_striplength, 0.);
1601  const LocalPoint lp_bottom(0., -half_striplength, 0.);
1602  const GlobalPoint gp_top(roll->toGlobal(lp_top));
1603  const GlobalPoint gp_bottom(roll->toGlobal(lp_bottom));
1604  gemRollToEtaLimits_[n] = std::make_pair(gp_top.eta(), gp_bottom.eta());
1605  ++n;
1606  }
1607 }
1608 
1609 
1611 {
1612  int result = -99;
1613  for(auto p : gemRollToEtaLimits_) {
1614  const float minEta((p.second).first);
1615  const float maxEta((p.second).second);
1616  if (minEta <= eta and eta <= maxEta) {
1617  result = p.first;
1618  break;
1619  }
1620  }
1621  return result;
1622 }
1623 
1624 
1626  const GEMPadDigi& gem,
1627  int ME, bool oldDataFormat)
1628 {
1629  auto mymap(ME==ME1A ? gemPadToCscHsME1a_ : gemPadToCscHsME1b_);
1630  auto wgvshs(ME==ME1A ? lut_wg_vs_hs_me1a : lut_wg_vs_hs_me1b);
1631  if (oldDataFormat){
1632  // CLCT pattern number - set it to a highest value
1633  // hack to get LCTs in the CSCTF
1634  unsigned int pattern = promoteALCTGEMpattern_ ? 10 : 0;
1635 
1636  // LCT quality number - set it to a very high value
1637  // hack to get LCTs in the CSCTF
1638  unsigned int quality = promoteALCTGEMquality_ ? 14 : 11;
1639 
1640  // Bunch crossing
1641  int bx = alct.getBX();
1642 
1643  // get keyStrip from LUT
1644  int keyStrip = mymap[gem.pad()];
1645 
1646  // get wiregroup from ALCT
1647  int wg = alct.getKeyWG();
1648 
1649  if (keyStrip>wgvshs[wg][0] && keyStrip<wgvshs[wg][1])
1650  { // construct correlated LCT; temporarily assign track number of 0.
1651  return CSCCorrelatedLCTDigi(0, 1, quality, wg, keyStrip, pattern, 0, bx, 0, 0, 0, theTrigChamber);
1652  }
1653  else return CSCCorrelatedLCTDigi(0,0,0,0,0,0,0,0,0,0,0,0);
1654  }
1655  else {
1656 
1657  // CLCT pattern number - no pattern
1658  unsigned int pattern = 0;
1659 
1660  // LCT quality number
1661  unsigned int quality = 1;
1662 
1663  // Bunch crossing
1664  int bx = gem.bx() + lct_central_bx;
1665 
1666  // get keyStrip from LUT
1667  int keyStrip = mymap[gem.pad()];
1668 
1669  // get wiregroup from ALCT
1670  int wg = alct.getKeyWG();
1671 
1672  if (keyStrip>wgvshs[wg][0] && keyStrip<wgvshs[wg][1])
1673  { // construct correlated LCT; temporarily assign track number of 0.
1674  return CSCCorrelatedLCTDigi(0, 1, quality, wg, keyStrip, pattern, 0, bx, 0, 0, 0, theTrigChamber);
1675  }
1676  else return CSCCorrelatedLCTDigi(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1677  }
1678 }
1679 
1681  const GEMPadDigi& gem, int roll,
1682  int ME, bool oldDataFormat)
1683 {
1684 // auto mymap(ME==ME1A ? gemPadToCscHsME1a_ : gemPadToCscHsME1b_);
1685  if (oldDataFormat){
1686  // CLCT pattern number - no pattern
1687  unsigned int pattern = encodePatternGEM(clct.getPattern(), clct.getStripType());
1688 
1689  // LCT quality number - dummy quality
1690  const bool promoteCLCTGEMquality(ME == ME1A ? promoteCLCTGEMquality_ME1a_:promoteCLCTGEMquality_ME1b_);
1691  unsigned int quality = promoteCLCTGEMquality ? 14 : 11;
1692 
1693  // Bunch crossing: get it from cathode LCT if anode LCT is not there.
1694  int bx = gem.bx() + lct_central_bx;;
1695 
1696  // pick a random WG in the roll range
1697  int wg(5);
1698 
1699  // construct correlated LCT; temporarily assign track number of 0.
1700  return CSCCorrelatedLCTDigi(0, 1, quality, wg, clct.getKeyStrip(), pattern, clct.getBend(), bx, 0, 0, 0, theTrigChamber);
1701  }
1702  else {
1703  // CLCT pattern number - no pattern
1704  unsigned int pattern = encodePatternGEM(clct.getPattern(), clct.getStripType());
1705 
1706  // LCT quality number - dummy quality
1707  unsigned int quality = 5;//findQualityGEM(alct, gem);
1708 
1709  // Bunch crossing: get it from cathode LCT if anode LCT is not there.
1710  int bx = gem.bx() + lct_central_bx;;
1711 
1712  // ALCT WG
1713  int wg();
1714 
1715  // construct correlated LCT; temporarily assign track number of 0.
1716  return CSCCorrelatedLCTDigi(0, 1, quality, 0, 0, pattern, 0, bx, 0, 0, 0, theTrigChamber);
1717  }
1718 }
1719 
1720 
1722  bool hasPad, bool hasCoPad)
1723 {
1724  // CLCT pattern number
1725  unsigned int pattern = encodePattern(cLCT.getPattern(), cLCT.getStripType());
1726 
1727  // LCT quality number
1728  unsigned int quality = findQualityGEM(aLCT, cLCT, hasPad, hasCoPad);
1729 
1730  // Bunch crossing: get it from cathode LCT if anode LCT is not there.
1731  int bx = aLCT.isValid() ? aLCT.getBX() : cLCT.getBX();
1732 
1733  // construct correlated LCT; temporarily assign track number of 0.
1734  int trknmb = 0;
1735  CSCCorrelatedLCTDigi thisLCT(trknmb, 1, quality, aLCT.getKeyWG(),
1736  cLCT.getKeyStrip(), pattern, cLCT.getBend(),
1737  bx, 0, 0, 0, theTrigChamber);
1738  return thisLCT;
1739 }
1740 
1741 
1742 unsigned int CSCMotherboardME11GEM::encodePatternGEM(const int ptn, const int highPt)
1743 {
1744  return 0;
1745 }
1746 
1747 
1748 unsigned int CSCMotherboardME11GEM::findQualityGEM(const CSCALCTDigi& aLCT, const CSCCLCTDigi& cLCT,
1749  bool hasPad, bool hasCoPad)
1750 {
1751 
1752  /*
1753  Same LCT quality definition as standard LCTs
1754  c4 takes GEMs into account!!!
1755  */
1756 
1757  unsigned int quality = 0;
1758 
1759  if (!isTMB07) {
1760  bool isDistrip = (cLCT.getStripType() == 0);
1761 
1762  if (aLCT.isValid() && !(cLCT.isValid())) { // no CLCT
1763  if (aLCT.getAccelerator()) {quality = 1;}
1764  else {quality = 3;}
1765  }
1766  else if (!(aLCT.isValid()) && cLCT.isValid()) { // no ALCT
1767  if (isDistrip) {quality = 4;}
1768  else {quality = 5;}
1769  }
1770  else if (aLCT.isValid() && cLCT.isValid()) { // both ALCT and CLCT
1771  if (aLCT.getAccelerator()) {quality = 2;} // accelerator muon
1772  else { // collision muon
1773  // CLCT quality is, in fact, the number of layers hit, so subtract 3
1774  // to get quality analogous to ALCT one.
1775  int sumQual = aLCT.getQuality() + (cLCT.getQuality()-3);
1776  if (sumQual < 1 || sumQual > 6) {
1777  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
1778  << "+++ findQuality: sumQual = " << sumQual << "+++ \n";
1779  }
1780  if (isDistrip) { // distrip pattern
1781  if (sumQual == 2) {quality = 6;}
1782  else if (sumQual == 3) {quality = 7;}
1783  else if (sumQual == 4) {quality = 8;}
1784  else if (sumQual == 5) {quality = 9;}
1785  else if (sumQual == 6) {quality = 10;}
1786  }
1787  else { // halfstrip pattern
1788  if (sumQual == 2) {quality = 11;}
1789  else if (sumQual == 3) {quality = 12;}
1790  else if (sumQual == 4) {quality = 13;}
1791  else if (sumQual == 5) {quality = 14;}
1792  else if (sumQual == 6) {quality = 15;}
1793  }
1794  }
1795  }
1796  }
1797 #ifdef OLD
1798  else {
1799  // Temporary definition, used until July 2008.
1800  // First if statement is fictitious, just to help the CSC TF emulator
1801  // handle such cases (one needs to make sure they will be accounted for
1802  // in the new quality definition.
1803  if (!(aLCT.isValid()) || !(cLCT.isValid())) {
1804  if (aLCT.isValid() && !(cLCT.isValid())) quality = 1; // no CLCT
1805  else if (!(aLCT.isValid()) && cLCT.isValid()) quality = 2; // no ALCT
1806  else quality = 0; // both absent; should never happen.
1807  }
1808  else {
1809  // Sum of ALCT and CLCT quality bits. CLCT quality is, in fact, the
1810  // number of layers hit, so subtract 3 to put it to the same footing as
1811  // the ALCT quality.
1812  int sumQual = aLCT.getQuality() + (cLCT.getQuality()-3);
1813  if (sumQual < 1 || sumQual > 6) {
1814  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
1815  << "+++ findQuality: Unexpected sumQual = " << sumQual << "+++\n";
1816  }
1817 
1818  // LCT quality is basically the sum of ALCT and CLCT qualities, but split
1819  // in two groups depending on the CLCT pattern id (higher quality for
1820  // straighter patterns).
1821  int offset = 0;
1822  if (cLCT.getPattern() <= 7) offset = 4;
1823  else offset = 9;
1824  quality = offset + sumQual;
1825  }
1826  }
1827 #endif
1828  else {
1829  // 2008 definition.
1830  if (!(aLCT.isValid()) || !(cLCT.isValid())) {
1831  if (aLCT.isValid() && !(cLCT.isValid())) quality = 1; // no CLCT
1832  else if (!(aLCT.isValid()) && cLCT.isValid()) quality = 2; // no ALCT
1833  else quality = 0; // both absent; should never happen.
1834  }
1835  else {
1836  int pattern = cLCT.getPattern();
1837  if (pattern == 1) quality = 3; // layer-trigger in CLCT
1838  else {
1839  // CLCT quality is the number of layers hit minus 3.
1840  // CLCT quality is the number of layers hit.
1841  // const int n_gem((pad!=NULL and 1) or (copad!=NULL and 2));
1842  int n_gem = 0;
1843  if (hasPad) n_gem = 1;
1844  if (hasCoPad) n_gem = 2;
1845  const bool a4(aLCT.getQuality() >= 1);
1846  const bool c4((cLCT.getQuality() >= 4) or (cLCT.getQuality() >= 3 and n_gem>=1));
1847  // quality = 4; "reserved for low-quality muons in future"
1848  if (!a4 && !c4) quality = 5; // marginal anode and cathode
1849  else if ( a4 && !c4) quality = 6; // HQ anode, but marginal cathode
1850  else if (!a4 && c4) quality = 7; // HQ cathode, but marginal anode
1851  else if ( a4 && c4) {
1852  if (aLCT.getAccelerator()) quality = 8; // HQ muon, but accel ALCT
1853  else {
1854  // quality = 9; "reserved for HQ muons with future patterns
1855  // quality = 10; "reserved for HQ muons with future patterns
1856  if (pattern == 2 || pattern == 3) quality = 11;
1857  else if (pattern == 4 || pattern == 5) quality = 12;
1858  else if (pattern == 6 || pattern == 7) quality = 13;
1859  else if (pattern == 8 || pattern == 9) quality = 14;
1860  else if (pattern == 10) quality = 15;
1861  else {
1862  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
1863  << "+++ findQuality: Unexpected CLCT pattern id = "
1864  << pattern << "+++\n";
1865  }
1866  }
1867  }
1868  }
1869  }
1870  }
1871  return quality;
1872 }
1873 
1874 
1875 unsigned int CSCMotherboardME11GEM::findQualityGEM(const CSCCLCTDigi& cLCT, const GEMPadDigi& gem)
1876 {
1877  return 0;
1878 }
1879 
1880 
1881 void CSCMotherboardME11GEM::printGEMTriggerPads(int bx_start, int bx_stop, bool iscopad)
1882 {
1883  // pads or copads?
1884  auto thePads(!iscopad ? pads_ : coPads_);
1885  const bool hasPads(thePads.size()!=0);
1886 
1887  std::cout << "------------------------------------------------------------------------" << std::endl;
1888  bool first = true;
1889  for (int bx = bx_start; bx <= bx_stop; bx++) {
1890  // print only the pads for the central BX
1891  if (bx!=lct_central_bx and iscopad) continue;
1892  std::vector<std::pair<unsigned int, const GEMPadDigi> > in_pads = thePads[bx];
1893  if (first) {
1894  if (!iscopad) std::cout << "* GEM trigger pads: " << std::endl;
1895  else std::cout << "* GEM trigger coincidence pads: " << std::endl;
1896  }
1897  first = false;
1898  if (!iscopad) std::cout << "N(pads) BX " << bx << " : " << in_pads.size() << std::endl;
1899  else std::cout << "N(copads) BX " << bx << " : " << in_pads.size() << std::endl;
1900  if (hasPads){
1901  for (auto pad : in_pads){
1902  auto roll_id(GEMDetId(pad.first));
1903  std::cout << "\tdetId " << pad.first << " " << roll_id << ", pad = " << pad.second.pad() << ", BX = " << pad.second.bx() + 6;
1904  if (isPadInOverlap(roll_id.roll())) std::cout << " (in overlap)" << std::endl;
1905  else std::cout << std::endl;
1906  }
1907  }
1908  else
1909  break;
1910  }
1911 }
1912 
1914 {
1915  auto superChamber(gem_g->superChamber(id));
1916  for (auto ch : superChamber->chambers()) {
1917  for (auto roll : ch->etaPartitions()) {
1918  GEMDetId roll_id(roll->id());
1919  auto pads_in_det = gemPads->get(roll_id);
1920  for (auto pad = pads_in_det.first; pad != pads_in_det.second; ++pad) {
1921  const int bx_shifted(lct_central_bx + pad->bx());
1922  for (int bx = bx_shifted - maxDeltaBXPad_;bx <= bx_shifted + maxDeltaBXPad_; ++bx) {
1923  pads_[bx].push_back(std::make_pair(roll_id, *pad));
1924  }
1925  }
1926  }
1927  }
1928 }
1929 
1931 {
1932  auto superChamber(gem_g->superChamber(id));
1933  for (auto ch : superChamber->chambers()) {
1934  for (auto roll : ch->etaPartitions()) {
1935  GEMDetId roll_id(roll->id());
1936  auto pads_in_det = gemPads->get(roll_id);
1937  for (auto pad = pads_in_det.first; pad != pads_in_det.second; ++pad) {
1938  const int bx_shifted(lct_central_bx + (pad->second()).bx());
1939  for (int bx = bx_shifted - maxDeltaBXPad_;bx <= bx_shifted + maxDeltaBXPad_; ++bx) {
1940  if(bx != lct_central_bx) continue;
1941  coPads_[bx].push_back(std::make_pair(roll_id, (*pad).second()));
1942  }
1943  }
1944  }
1945  }
1946 }
1947 
1949 {
1950  for (auto& p : cscWgToGemRoll_) {
1951  // overlap region are WGs 10-15
1952  if ((p.first < 10) or (p.first > 15)) continue;
1953  if (((p.second).first <= roll) and (roll <= (p.second).second)) return true;
1954  }
1955  return false;
1956 }
1957 
1958 
1960 {
1961  const auto p(cscWgToGemRoll_[wg]);
1962  return std::min(std::abs(p.first - pad), std::abs(p.second - pad));
1963 }
1964 
1965 
1967 {
1968  const auto p(cscHsToGemPadME1b_[hs]);
1969  return std::min(std::abs(p.first - pad), std::abs(p.second - pad));
1970 }
1971 
1972 
1974 CSCMotherboardME11GEM::matchingGEMPads(const CSCCLCTDigi& clct, const GEMPadsBX& pads, enum ME11Part part, bool isCoPad, bool first)
1975 {
1977 
1978  // fetch the low and high pad edges
1979  auto mymap(part==ME1A ? cscHsToGemPadME1a_ : cscHsToGemPadME1b_);
1980  int deltaPad(isCoPad ? maxDeltaPadCoPad_ : maxDeltaPadPad_);
1981  const int lowPad(mymap[clct.getKeyStrip()].first);
1982  const int highPad(mymap[clct.getKeyStrip()].second);
1983  const bool debug(false);
1984  if (debug) std::cout << "lowpad " << lowPad << " highpad " << highPad << " delta pad " << deltaPad <<std::endl;
1985  for (auto p: pads){
1986  auto padRoll((p.second).pad());
1987  if (debug) std::cout << "padRoll " << padRoll << std::endl;
1988  if (std::abs(lowPad - padRoll) <= deltaPad or std::abs(padRoll - highPad) <= deltaPad){
1989  if (debug) std::cout << "++Matches! " << std::endl;
1990  result.push_back(p);
1991  if (first) return result;
1992  }
1993  }
1994  return result;
1995 }
1996 
1997 
1999 CSCMotherboardME11GEM::matchingGEMPads(const CSCALCTDigi& alct, const GEMPadsBX& pads, enum ME11Part part, bool isCoPad, bool first)
2000 {
2002 
2003  auto alctRoll(cscWgToGemRoll_[alct.getKeyWG()]);
2004  const bool debug(false);
2005  if (debug) std::cout << "ALCT keyWG " << alct.getKeyWG() << ", rolls " << alctRoll.first << " " << alctRoll.second << std::endl;
2006  for (auto p: pads){
2007  auto padRoll(GEMDetId(p.first).roll());
2008  if (debug) std::cout << "Candidate ALCT: " << padRoll << std::endl;
2009  // only pads in overlap are good for ME1A
2010  if (part==ME1A and !isPadInOverlap(padRoll)) continue;
2011  if (alctRoll.first == -99 and alctRoll.second == -99) continue; //invalid region
2012  else if (alctRoll.first == -99 and !(padRoll <= alctRoll.second)) continue; // top of the chamber
2013  else if (alctRoll.second == -99 and !(padRoll >= alctRoll.first)) continue; // bottom of the chamber
2014  else if ((alctRoll.first != -99 and alctRoll.second != -99) and // center
2015  (alctRoll.first > padRoll or padRoll > alctRoll.second)) continue;
2016  if (debug) std::cout << "++Matches! " << std::endl;
2017  result.push_back(p);
2018  if (first) return result;
2019  }
2020  return result;
2021 }
2022 
2023 
2026  enum ME11Part part, bool isCoPad, bool first)
2027 {
2029 
2030  // Fetch all (!) pads matching to ALCTs and CLCTs
2031  auto padsClct(matchingGEMPads(clct, pads, part, isCoPad, false));
2032  auto padsAlct(matchingGEMPads(alct, pads, part, isCoPad, false));
2033 
2034  const bool debug(false);
2035  if (debug) std::cout << "-----------------------------------------------------------------------"<<std::endl;
2036  // Check if the pads overlap
2037  for (auto p : padsAlct){
2038  if (debug) std::cout<< "Candidate ALCT: " << p.first << " " << p.second << std::endl;
2039  for (auto q: padsClct){
2040  if (debug) std::cout<< "++Candidate CLCT: " << q.first << " " << q.second << std::endl;
2041  // look for exactly the same pads
2042  if ((p.first != q.first) or GEMPadDigi(p.second) != q.second) continue;
2043  if (debug) std::cout << "++Matches! " << std::endl;
2044  result.push_back(p);
2045  if (first) return result;
2046  }
2047  }
2048  if (debug) std::cout << "-----------------------------------------------------------------------"<<std::endl;
2049  return result;
2050 }
2051 
2052 
2053 std::vector<GEMCoPadDigi> CSCMotherboardME11GEM::readoutCoPads()
2054 {
2055  return gemCoPadV;
2056 }
2057 
#define LogDebug(id)
int getQuality() const
return quality of a pattern (number of layers hit!)
Definition: CSCCLCTDigi.h:33
void retrieveGEMCoPads(const GEMCoPadDigiCollection *pads, unsigned id)
int chamber() const
Definition: CSCDetId.h:68
const unsigned theSector
T getParameter(std::string const &) const
std::map< int, std::pair< int, int > > cscHsToGemPadME1a_
int i
Definition: DBlmapReader.cc:9
CSCCorrelatedLCTDigi constructLCTs(const CSCALCTDigi &aLCT, const CSCCLCTDigi &cLCT)
std::vector< CSCCorrelatedLCTDigi > sortLCTsByQuality(int bx, enum ME11Part=ME1B)
unsigned int clct_trig_enable
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 lut_wg_vs_hs_me1ag[48][2]
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
static bool sortByGEMDphi(const CSCCorrelatedLCTDigi &, const CSCCorrelatedLCTDigi &)
std::vector< CSCCorrelatedLCTDigi > readoutLCTs1a()
std::vector< CSCCorrelatedLCTDigi > readoutLCTs()
unsigned int match_trig_window_size
const unsigned theTrigChamber
bool isValid() const
check ALCT validity (1 - valid ALCT)
Definition: CSCALCTDigi.h:30
void buildCoincidencePads(const GEMPadDigiCollection *out_pads, GEMCoPadDigiCollection &out_co_pads, CSCDetId csc_id)
unsigned int encodePatternGEM(const int ptn, const int highPt)
static const double lut_pt_vs_dphi_gemcsc[8][3]
int roll() const
Definition: GEMDetId.h:80
bool runME11ILT_
GEM-CSC integrated local algorithm.
const unsigned theEndcap
std::map< int, std::pair< int, int > > cscHsToGemPadME1b_
void clear()
clear this ALCT
Definition: CSCALCTDigi.cc:35
Definition: deltas.h:18
double maxEta
int deltaPad(int hs, int pad)
int getStripType() const
return striptype
Definition: CSCCLCTDigi.h:39
tuple result
Definition: mps_fire.py:84
int getBend() const
return bend
Definition: CSCCLCTDigi.h:42
unsigned int mpc_block_me1a
static const int lut_wg_vs_hs_me1b[48][2]
Definition: ME.h:11
GEMPadsBX matchingGEMPads(const CSCCLCTDigi &cLCT, const GEMPadsBX &pads=GEMPadsBX(), enum ME11Part=ME1B, bool isCopad=false, bool first=true)
CSCCorrelatedLCTDigi allLCTs1a[MAX_LCT_BINS][15][2]
const unsigned theStation
static CSCTriggerGeomManager * get()
void correlateLCTsGEM(CSCALCTDigi bestALCT, CSCALCTDigi secondALCT, CSCCLCTDigi bestCLCT, CSCCLCTDigi secondCLCT, CSCCorrelatedLCTDigi &lct1, CSCCorrelatedLCTDigi &lct2, int me, const GEMPadsBX &pads=GEMPadsBX(), const GEMPadsBX &copads=GEMPadsBX())
int pad() const
Definition: GEMPadDigi.h:26
const unsigned theSubsector
int getBX() const
return BX
Definition: CSCCLCTDigi.h:51
std::map< int, std::pair< double, double > > gemRollToEtaLimits_
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
bool isValid() const
check CLCT validity (1 - valid CLCT)
Definition: CSCCLCTDigi.h:30
unsigned int match_trig_enable
CSCCorrelatedLCTDigi constructLCTsGEM(const CSCALCTDigi &alct, const GEMPadDigi &gem, int me, bool oldDataFormat=false)
tuple lut
Definition: lumiPlot.py:244
T min(T a, T b)
Definition: MathUtil.h:58
void correlateLCTs(CSCALCTDigi bestALCT, CSCALCTDigi secondALCT, CSCCLCTDigi bestCLCT, CSCCLCTDigi secondCLCT, CSCCorrelatedLCTDigi &lct1, CSCCorrelatedLCTDigi &lct2)
std::vector< CSCCorrelatedLCTDigi > getLCTs1b()
int deltaRoll(int wg, int roll)
MuonDigiCollection< GEMDetId, GEMCoPadDigi > GEMCoPadDigiCollection
#define LogTrace(id)
const GEMSuperChamber * superChamber(GEMDetId id) const
Definition: GEMGeometry.cc:91
void printGEMTriggerPads(int minBX, int maxBx, bool iscopad=false)
int getBX() const
return BX - five low bits of BXN counter tagged by the ALCT
Definition: CSCALCTDigi.h:48
std::vector< CSCCorrelatedLCTDigi > getLCTs1a()
static const int lut_wg_vs_hs_me1a[48][2]
int ring() const
Definition: CSCDetId.h:75
short int zendcap() const
Definition: CSCDetId.h:100
int getQuality() const
return quality of a pattern
Definition: CSCALCTDigi.h:33
#define debug
Definition: HDRShower.cc:19
int getAccelerator() const
Definition: CSCALCTDigi.h:37
int bx() const
Definition: GEMPadDigi.h:27
std::vector< CSCALCTDigi > alctV
int getPattern() const
return pattern
Definition: CSCCLCTDigi.h:36
part
Definition: HCALResponse.h:20
void retrieveGEMPads(const GEMPadDigiCollection *pads, unsigned id)
const GEMGeometry * gem_g
const GEMChamber * chamber(GEMDetId id) const
Definition: GEMGeometry.cc:95
unsigned int findQualityGEM(const CSCALCTDigi &aLCT, const GEMPadDigi &gem)
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:118
double b
Definition: hdecay.h:120
std::vector< GEMCoPadDigi > gemCoPadV
bool doesALCTCrossCLCT(CSCALCTDigi &a, CSCCLCTDigi &c, int me)
std::map< int, int > gemPadToCscHsME1a_
std::map< int, std::pair< int, int > > cscWgToGemRoll_
unsigned int alct_trig_enable
std::vector< CSCCorrelatedLCTDigi > readoutLCTs1b()
void createGEMRollEtaLUT(bool isEven)
std::unique_ptr< CSCAnodeLCTProcessor > alct
double a
Definition: hdecay.h:121
std::vector< CSCCLCTDigi > clctV1b
std::vector< CSCCLCTDigi > clctV1a
std::unique_ptr< CSCCathodeLCTProcessor > clct
void run(const CSCWireDigiCollection *wiredc, const CSCComparatorDigiCollection *compdc, const GEMPadDigiCollection *gemPads)
void clear()
clear this CLCT
Definition: CSCCLCTDigi.cc:58
CSCCorrelatedLCTDigi allLCTs1b[MAX_LCT_BINS][15][2]
std::map< int, int > gemPadToCscHsME1b_
int station() const
Definition: CSCDetId.h:86
tuple cout
Definition: gather_cfg.py:145
int getKeyStrip() const
Definition: CSCCLCTDigi.h:65
std::unique_ptr< CSCCathodeLCTProcessor > clct1a
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting LCTs.
const CSCGeometry * csc_g
std::vector< GEMCoPadDigi > readoutCoPads()
int getKeyWG() const
return key wire group
Definition: CSCALCTDigi.h:45
static int chamberFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station, int TriggerCSCID)
static const double lut_wg_etaMin_etaMax_even[48][3]
static const double lut_wg_etaMin_etaMax_odd[48][3]
std::vector< GEMPadBX > GEMPadsBX
static bool sortByQuality(const CSCCorrelatedLCTDigi &, const CSCCorrelatedLCTDigi &)
void setConfigParameters(const CSCDBL1TPParameters *conf)
std::vector< CSCCorrelatedLCTDigi > sortLCTsByGEMDPhi(int bx, enum ME11Part=ME1B)