CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCMotherboardME21GEM.cc
Go to the documentation of this file.
8 #include <iomanip>
9 #include "boost/container/flat_set.hpp"
10 
11 const double CSCMotherboardME21GEM::lut_wg_eta_odd[112][2] = {
12 { 0,2.441},{ 1,2.435},{ 2,2.425},{ 3,2.414},{ 4,2.404},{ 5,2.394},{ 6,2.384},{ 7,2.374},
13 { 8,2.365},{ 9,2.355},{10,2.346},{11,2.336},{12,2.327},{13,2.317},{14,2.308},{15,2.299},
14 {16,2.290},{17,2.281},{18,2.273},{19,2.264},{20,2.255},{21,2.247},{22,2.238},{23,2.230},
15 {24,2.221},{25,2.213},{26,2.205},{27,2.197},{28,2.189},{29,2.181},{30,2.173},{31,2.165},
16 {32,2.157},{33,2.149},{34,2.142},{35,2.134},{36,2.127},{37,2.119},{38,2.112},{39,2.104},
17 {40,2.097},{41,2.090},{42,2.083},{43,2.075},{44,2.070},{45,2.059},{46,2.054},{47,2.047},
18 {48,2.041},{49,2.034},{50,2.027},{51,2.020},{52,2.014},{53,2.007},{54,2.000},{55,1.994},
19 {56,1.988},{57,1.981},{58,1.975},{59,1.968},{60,1.962},{61,1.956},{62,1.950},{63,1.944},
20 {64,1.937},{65,1.931},{66,1.924},{67,1.916},{68,1.909},{69,1.902},{70,1.895},{71,1.888},
21 {72,1.881},{73,1.875},{74,1.868},{75,1.861},{76,1.854},{77,1.848},{78,1.841},{79,1.835},
22 {80,1.830},{81,1.820},{82,1.815},{83,1.809},{84,1.803},{85,1.796},{86,1.790},{87,1.784},
23 {88,1.778},{89,1.772},{90,1.766},{91,1.760},{92,1.754},{93,1.748},{94,1.742},{95,1.736},
24 {96,1.731},{97,1.725},{98,1.719},{99,1.714},{100,1.708},{101,1.702},{102,1.697},{103,1.691},
25 {104,1.686},{105,1.680},{106,1.675},{107,1.670},{108,1.664},{109,1.659},{110,1.654},{111,1.648},
26 };
27 
28 const double CSCMotherboardME21GEM::lut_wg_eta_even[112][2] = {
29 { 0,2.412},{ 1,2.405},{ 2,2.395},{ 3,2.385},{ 4,2.375},{ 5,2.365},{ 6,2.355},{ 7,2.345},
30 { 8,2.335},{ 9,2.325},{10,2.316},{11,2.306},{12,2.297},{13,2.288},{14,2.279},{15,2.270},
31 {16,2.261},{17,2.252},{18,2.243},{19,2.234},{20,2.226},{21,2.217},{22,2.209},{23,2.200},
32 {24,2.192},{25,2.184},{26,2.175},{27,2.167},{28,2.159},{29,2.151},{30,2.143},{31,2.135},
33 {32,2.128},{33,2.120},{34,2.112},{35,2.105},{36,2.097},{37,2.090},{38,2.082},{39,2.075},
34 {40,2.068},{41,2.060},{42,2.053},{43,2.046},{44,2.041},{45,2.030},{46,2.025},{47,2.018},
35 {48,2.011},{49,2.005},{50,1.998},{51,1.991},{52,1.985},{53,1.978},{54,1.971},{55,1.965},
36 {56,1.958},{57,1.952},{58,1.946},{59,1.939},{60,1.933},{61,1.927},{62,1.921},{63,1.915},
37 {64,1.909},{65,1.902},{66,1.895},{67,1.887},{68,1.880},{69,1.873},{70,1.866},{71,1.859},
38 {72,1.853},{73,1.846},{74,1.839},{75,1.832},{76,1.826},{77,1.819},{78,1.812},{79,1.806},
39 {80,1.801},{81,1.792},{82,1.787},{83,1.780},{84,1.774},{85,1.768},{86,1.762},{87,1.756},
40 {88,1.750},{89,1.744},{90,1.738},{91,1.732},{92,1.726},{93,1.720},{94,1.714},{95,1.708},
41 {96,1.702},{97,1.697},{98,1.691},{99,1.685},{100,1.680},{101,1.674},{102,1.669},{103,1.663},
42 {104,1.658},{105,1.652},{106,1.647},{107,1.642},{108,1.636},{109,1.631},{110,1.626},{111,1.621},
43 };
44 
45 // LUT with bending angles of the GEM-CSC high efficiency patterns (98%)
46 // 1st index: pt value = {5,10,15,20,30,40}
47 // 2nd index: bending angle for odd numbered chambers
48 // 3rd index: bending angle for even numbered chambers
50  {3, 0.01832829, 0.01003643 },
51  {5, 0.01095490, 0.00631625 },
52  {7, 0.00786026, 0.00501017 },
53  {10, 0.00596349, 0.00414560 },
54  {15, 0.00462411, 0.00365550 },
55  {20, 0.00435298, 0.00361550 },
56  {30, 0.00465160, 0.00335700 },
57  {40, 0.00372145, 0.00366262 }
58 };
59 
61  unsigned sector, unsigned subsector,
62  unsigned chamber,
63  const edm::ParameterSet& conf) :
64  CSCMotherboard(endcap, station, sector, subsector, chamber, conf)
65 {
66  const edm::ParameterSet commonParams(conf.getParameter<edm::ParameterSet>("commonParam"));
67  runME21ILT_ = commonParams.getParameter<bool>("runME21ILT");
68 
69  if (!isSLHC) edm::LogError("L1CSCTPEmulatorConfigError")
70  << "+++ Upgrade CSCMotherboardME21GEM constructed while isSLHC is not set! +++\n";
71 
72  const edm::ParameterSet me21tmbParams(conf.getParameter<edm::ParameterSet>("me21tmbSLHCGEM"));
73 
74  // whether to not reuse CLCTs that were used by previous matching ALCTs
75  // in ALCT-to-CLCT algorithm
76  drop_used_clcts = me21tmbParams.getParameter<bool>("tmbDropUsedClcts");
77 
78  match_earliest_clct_me21_only = me21tmbParams.getParameter<bool>("matchEarliestClctME21Only");
79 
80  tmb_cross_bx_algo = me21tmbParams.getParameter<unsigned int>("tmbCrossBxAlgorithm");
81 
82  // maximum lcts per BX in ME2
83  max_me21_lcts = me21tmbParams.getParameter<unsigned int>("maxME21LCTs");
84 
86  for (unsigned int m=2; m<match_trig_window_size; m+=2)
87  {
88  pref[m-1] = pref[0] - m/2;
89  pref[m] = pref[0] + m/2;
90  }
91 
92  //----------------------------------------------------------------------------------------//
93 
94  // 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
95 
96  //----------------------------------------------------------------------------------------//
97 
98  // debug gem matching
99  debug_gem_matching = me21tmbParams.getParameter<bool>("debugMatching");
100  debug_luts = me21tmbParams.getParameter<bool>("debugLUTs");
101  debug_gem_dphi = me21tmbParams.getParameter<bool>("debugGEMDphi");
102 
103  // deltas used to construct GEM coincidence pads
104  maxDeltaBXInCoPad_ = me21tmbParams.getParameter<int>("maxDeltaBXInCoPad");
105  maxDeltaPadInCoPad_ = me21tmbParams.getParameter<int>("maxDeltaPadInCoPad");
106 
107  // deltas used to match to GEM pads
108  maxDeltaBXPad_ = me21tmbParams.getParameter<int>("maxDeltaBXPad");
109  maxDeltaPadPadOdd_ = me21tmbParams.getParameter<int>("maxDeltaPadPadOdd");
110  maxDeltaPadPadEven_ = me21tmbParams.getParameter<int>("maxDeltaPadPadEven");
111  maxDeltaWg_ = me21tmbParams.getParameter<int>("maxDeltaWg");
112 
113  // deltas used to match to GEM coincidence pads
114  maxDeltaBXCoPad_ = me21tmbParams.getParameter<int>("maxDeltaBXCoPad");
115  maxDeltaPadCoPad_ = me21tmbParams.getParameter<int>("maxDeltaPadCoPad");
116 
117  // drop low quality stubs if they don't have GEMs
118  dropLowQualityCLCTsNoGEMs_ = me21tmbParams.getParameter<bool>("dropLowQualityCLCTsNoGEMs");
119  dropLowQualityALCTsNoGEMs_ = me21tmbParams.getParameter<bool>("dropLowQualityALCTsNoGEMs");
120 
121  // correct LCT timing with GEMs
122  correctLCTtimingWithGEM_ = me21tmbParams.getParameter<bool>("correctLCTtimingWithGEM");
123 
124  // build LCT from ALCT and GEM
125  buildLCTfromALCTandGEM_ = me21tmbParams.getParameter<bool>("buildLCTfromALCTandGEM");
126  buildLCTfromCLCTandGEM_ = me21tmbParams.getParameter<bool>("buildLCTfromCLCTandGEM");
127 
128  // LCT ghostbusting
129  doLCTGhostBustingWithGEMs_ = me21tmbParams.getParameter<bool>("doLCTGhostBustingWithGEMs");
130 
131  // use "old" or "new" dataformat for integrated LCTs?
132  useOldLCTDataFormat_ = me21tmbParams.getParameter<bool>("useOldLCTDataFormat");
133 
134  // promote ALCT-GEM pattern
135  promoteALCTGEMpattern_ = me21tmbParams.getParameter<bool>("promoteALCTGEMpattern");
136 
137  // promote ALCT-GEM quality
138  promoteALCTGEMquality_ = me21tmbParams.getParameter<bool>("promoteALCTGEMquality");
139  promoteCLCTGEMquality_ = me21tmbParams.getParameter<bool>("promoteCLCTGEMquality");
140 }
141 
143 {
144 }
145 
147 {
149 
150  for (int bx = 0; bx < MAX_LCT_BINS; bx++)
151  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
152  for (int i=0;i<2;i++)
153  allLCTs[bx][mbx][i].clear();
154 
155  gemRollToEtaLimits_.clear();
156  cscWgToGemRoll_.clear();
157  gemPadToCscHs_.clear();
158  cscHsToGemPad_.clear();
159  pads_.clear();
160  coPads_.clear();
161 }
162 
163 void
165  const CSCComparatorDigiCollection* compdc,
166  const GEMPadDigiCollection* gemPads)
167 {
168  clear();
169 
170  if (!( alct and clct and runME21ILT_))
171  {
172  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorSetupError")
173  << "+++ run() called for non-existing ALCT/CLCT processor! +++ \n";
174  return;
175  }
176 
177  alct->run(wiredc); // run anodeLCT
178  clct->run(compdc); // run cathodeLCT
179 
180  bool gemGeometryAvailable(false);
181  if (gem_g != nullptr) {
182  if (infoV >= 0) edm::LogInfo("L1CSCTPEmulatorSetupInfo")
183  << "+++ run() called for GEM-CSC integrated trigger! +++ \n";
184  gemGeometryAvailable = true;
185  }
186 
187  // retrieve CSCChamber geometry
189  const CSCChamber* cscChamber(geo_manager->chamber(theEndcap, theStation, theSector, theSubsector, theTrigChamber));
190  const CSCDetId csc_id(cscChamber->id());
191 
192  if (runME21ILT_){
193 
194  // check for GE2/1 geometry
195  if ((not gemGeometryAvailable) or (gemGeometryAvailable and (gem_g->stations()).size()==2)) {
196  if (infoV >= 0) edm::LogError("L1CSCTPEmulatorSetupError")
197  << "+++ run() called for GEM-CSC integrated trigger without valid GE21 geometry! +++ \n";
198  return;
199  }
200 
201  // trigger geometry
202  const CSCLayer* keyLayer(cscChamber->layer(3));
203  const CSCLayerGeometry* keyLayerGeometry(keyLayer->geometry());
204 
205  // const bool isEven(csc_id%2==0);
206  const int region((theEndcap == 1) ? 1: -1);
207  const bool isEven(csc_id.chamber()%2==0);
208  const GEMDetId gem_id_long(region, 1, 2, 1, csc_id.chamber(), 0);
209  const GEMChamber* gemChamberLong(gem_g->chamber(gem_id_long));
210 
211  // LUT<roll,<etaMin,etaMax> >
213 
214  if (debug_luts){
215  std::cout<<"csc id "<< csc_id <<" "<< csc_id.rawId() << (isEven ? " even" : " odd") << " chamber" << csc_id.chamber()<<std::endl;
216  if (gemRollToEtaLimits_.size())
217  for(auto p : gemRollToEtaLimits_) {
218  std::cout << "pad "<< p.first << " min eta " << (p.second).first << " max eta " << (p.second).second << std::endl;
219  }
220  }
221 
222  // loop on all wiregroups to create a LUT <WG,rollMin,rollMax>
223  const int numberOfWG(keyLayerGeometry->numberOfWireGroups());
224  for (int i = 0; i< numberOfWG; ++i){
225  auto eta(isEven ? lut_wg_eta_even[i][1] : lut_wg_eta_odd[i][1]);
227  }
228  if (debug_luts){
229  for(auto p : cscWgToGemRoll_) {
230  std::cout << "WG "<< p.first << " GEM roll " << p.second << std::endl;
231  }
232  }
233 
234  auto randRoll(gemChamberLong->etaPartition(2));
235  auto nStrips(keyLayerGeometry->numberOfStrips());
236  for (float i = 0; i< nStrips; i = i+0.5){
237  const LocalPoint lpCSC(keyLayerGeometry->topology()->localPosition(i));
238  const GlobalPoint gp(keyLayer->toGlobal(lpCSC));
239  const LocalPoint lpGEM(randRoll->toLocal(gp));
240  const int HS(i/0.5);
241  const bool edge(HS < 5 or HS > 155);
242  const float pad(edge ? -99 : randRoll->pad(lpGEM));
243  // HS are wrapped-around
244  cscHsToGemPad_[HS] = std::make_pair(std::floor(pad),std::ceil(pad));
245  }
246  if (debug_luts){
247  std::cout << "detId " << csc_id << std::endl;
248  for(auto p : cscHsToGemPad_) {
249  std::cout << "CSC HS "<< p.first << " GEM Pad low " << (p.second).first << " GEM Pad high " << (p.second).second << std::endl;
250  }
251  }
252 
253  // pick any roll
254  const int nGEMPads(randRoll->npads());
255  for (int i = 0; i< nGEMPads; ++i){
256  const LocalPoint lpGEM(randRoll->centreOfPad(i));
257  const GlobalPoint gp(randRoll->toGlobal(lpGEM));
258  const LocalPoint lpCSC(keyLayer->toLocal(gp));
259  const float strip(keyLayerGeometry->strip(lpCSC));
260  // HS are wrapped-around
261  gemPadToCscHs_[i] = (int) (strip - 0.25)/0.5;
262  }
263  if (debug_luts){
264  std::cout << "detId " << csc_id << std::endl;
265  for(auto p : gemPadToCscHs_) {
266  std::cout << "GEM Pad "<< p.first << " CSC HS : " << p.second << std::endl;
267  }
268  }
269 
270  //select correct scenario, even or odd
272  // build coincidence pads
273  std::unique_ptr<GEMCoPadDigiCollection> pCoPads(new GEMCoPadDigiCollection());
274  buildCoincidencePads(gemPads, *pCoPads, csc_id);
275 
276  // retrieve pads and copads in a certain BX window for this CSC
277  pads_.clear();
278  coPads_.clear();
279  retrieveGEMPads(gemPads, gem_id_long);
280  retrieveGEMCoPads(pCoPads.get(), gem_id_long);
281  }
282 
283  int used_clct_mask[20];
284  for (int c=0;c<20;++c) used_clct_mask[c]=0;
285 
286  const bool hasPads(pads_.size()!=0);
287  const bool hasCoPads(hasPads and coPads_.size()!=0);
288 
289  // ALCT centric matching
290  for (int bx_alct = 0; bx_alct < CSCAnodeLCTProcessor::MAX_ALCT_BINS; bx_alct++)
291  {
292  if (alct->bestALCT[bx_alct].isValid())
293  {
294  const int bx_clct_start(bx_alct - match_trig_window_size/2);
295  const int bx_clct_stop(bx_alct + match_trig_window_size/2);
296  const int bx_copad_start(bx_alct - maxDeltaBXCoPad_);
297  const int bx_copad_stop(bx_alct + maxDeltaBXCoPad_);
298 
299  if (debug_gem_matching){
300  std::cout << "========================================================================" << std::endl;
301  std::cout << "ALCT-CLCT matching in ME2/1 chamber: " << cscChamber->id() << std::endl;
302  std::cout << "------------------------------------------------------------------------" << std::endl;
303  std::cout << "+++ Best ALCT Details: ";
304  alct->bestALCT[bx_alct].print();
305  std::cout << "+++ Second ALCT Details: ";
306  alct->secondALCT[bx_alct].print();
307 
308  printGEMTriggerPads(bx_clct_start, bx_clct_stop);
309 
310  std::cout << "------------------------------------------------------------------------" << std::endl;
311  std::cout << "Attempt ALCT-CLCT matching in ME2/1 in bx range: [" << bx_clct_start << "," << bx_clct_stop << "]" << std::endl;
312  }
313 
314  // ALCT-to-CLCT
315  int nSuccesFulMatches = 0;
316  for (int bx_clct = bx_clct_start; bx_clct <= bx_clct_stop; bx_clct++)
317  {
318  if (bx_clct < 0 or bx_clct >= CSCCathodeLCTProcessor::MAX_CLCT_BINS) continue;
319  if (drop_used_clcts and used_clct_mask[bx_clct]) continue;
320  if (clct->bestCLCT[bx_clct].isValid())
321  {
322  // clct quality
323  const int quality(clct->bestCLCT[bx_clct].getQuality());
324  // low quality ALCT
325  const bool lowQualityALCT(alct->bestALCT[bx_alct].getQuality() == 0);
326  // low quality ALCT or CLCT
327  const bool lowQuality(quality<4 or lowQualityALCT);
328  if (debug_gem_matching) std::cout << "++Valid ME21 CLCT: " << clct->bestCLCT[bx_clct] << std::endl;
329 
330  // pick the pad that corresponds
331  auto matchingPads(matchingGEMPads(clct->bestCLCT[bx_clct], alct->bestALCT[bx_alct], pads_[bx_clct], false));
332  auto matchingCoPads(matchingGEMPads(clct->bestCLCT[bx_clct], alct->bestALCT[bx_alct], coPads_[bx_clct], true));
333  if (runME21ILT_ and dropLowQualityCLCTsNoGEMs_ and lowQuality and hasPads){
334  int nFound(matchingPads.size());
335  const bool clctInEdge(clct->bestCLCT[bx_clct].getKeyStrip() < 5 or clct->bestCLCT[bx_clct].getKeyStrip() > 155);
336  if (clctInEdge){
337  if (debug_gem_matching) std::cout << "\tInfo: low quality CLCT in CSC chamber edge, don't care about GEM pads" << std::endl;
338  }
339  else {
340  if (nFound != 0){
341  if (debug_gem_matching) std::cout << "\tInfo: low quality CLCT with " << nFound << " matching GEM trigger pads" << std::endl;
342  }
343  else {
344  if (debug_gem_matching) std::cout << "\tWarning: low quality CLCT without matching GEM trigger pad" << std::endl;
345  continue;
346  }
347  }
348  }
349 
350  // check timing
351  if (runME21ILT_ and correctLCTtimingWithGEM_){
352  int nFound(matchingCoPads.size());
353  if (nFound != 0 and bx_alct == 6 and bx_clct != 6){
354  if (debug_gem_matching) std::cout << "\tInfo: CLCT with incorrect timing" << std::endl;
355  continue;
356  }
357  }
358 
359  ++nSuccesFulMatches;
360 
361  int mbx = bx_clct-bx_clct_start;
362 
363  correlateLCTsGEM(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
364  clct->bestCLCT[bx_clct], clct->secondCLCT[bx_clct],
365  allLCTs[bx_alct][mbx][0], allLCTs[bx_alct][mbx][1], matchingPads, matchingCoPads);
366  if (debug_gem_matching) {
367  // if (infoV > 1) LogTrace("CSCMotherboard")
368  std::cout << "Successful ALCT-CLCT match in ME21: bx_alct = " << bx_alct
369  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop
370  << "]; bx_clct = " << bx_clct << std::endl;
371  std::cout << "+++ Best CLCT Details: ";
372  clct->bestCLCT[bx_clct].print();
373  std::cout << "+++ Second CLCT Details: ";
374  clct->secondCLCT[bx_clct].print();
375  }
376  if (allLCTs[bx_alct][mbx][0].isValid()) {
377  used_clct_mask[bx_clct] += 1;
379  }
380  }
381  }
382 
383  // ALCT-to-GEM matching
384  int nSuccesFulGEMMatches = 0;
385  if (runME21ILT_ and nSuccesFulMatches==0 and buildLCTfromALCTandGEM_){
386  if (debug_gem_matching) std::cout << "++No valid ALCT-CLCT matches in ME21" << std::endl;
387  for (int bx_gem = bx_copad_start; bx_gem <= bx_copad_stop; bx_gem++) {
388  if (not hasCoPads) {
389  continue;
390  }
391 
392  // find the best matching copad - first one
393  auto copads(matchingGEMPads(alct->bestALCT[bx_alct], coPads_[bx_gem], true));
394  if (debug_gem_matching) std::cout << "\t++Number of matching GEM CoPads in BX " << bx_alct << " : "<< copads.size() << std::endl;
395  if (copads.size()==0) {
396  continue;
397  }
398 
399  correlateLCTsGEM(alct->bestALCT[bx_alct], alct->secondALCT[bx_alct],
400  *(copads.at(0)).second, allLCTs[bx_alct][0][0], allLCTs[bx_alct][0][1]);
401  if (allLCTs[bx_alct][0][0].isValid()) {
402  ++nSuccesFulGEMMatches;
404  }
405  if (debug_gem_matching) {
406  std::cout << "Successful ALCT-GEM CoPad match in ME21: bx_alct = " << bx_alct << std::endl << std::endl;
407  std::cout << "------------------------------------------------------------------------" << std::endl << std::endl;
408  }
409  }
410  }
411 
412  if (debug_gem_matching) {
413  std::cout << "========================================================================" << std::endl;
414  std::cout << "Summary: " << std::endl;
415  if (nSuccesFulMatches>1)
416  std::cout << "Too many successful ALCT-CLCT matches in ME21: " << nSuccesFulMatches
417  << ", CSCDetId " << cscChamber->id()
418  << ", bx_alct = " << bx_alct
419  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
420  else if (nSuccesFulMatches==1)
421  std::cout << "1 successful ALCT-CLCT match in ME21: "
422  << " CSCDetId " << cscChamber->id()
423  << ", bx_alct = " << bx_alct
424  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
425  else if (nSuccesFulGEMMatches==1)
426  std::cout << "1 successful ALCT-GEM match in ME21: "
427  << " CSCDetId " << cscChamber->id()
428  << ", bx_alct = " << bx_alct
429  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
430  else
431  std::cout << "Unsuccessful ALCT-CLCT match in ME21: "
432  << "CSCDetId " << cscChamber->id()
433  << ", bx_alct = " << bx_alct
434  << "; match window: [" << bx_clct_start << "; " << bx_clct_stop << "]" << std::endl;
435  }
436  }
437  // at this point we have invalid ALCTs --> try GEM pad matching
438  else{
439  auto coPads(coPads_[bx_alct]);
440  if (runME21ILT_ and coPads.size() and buildLCTfromCLCTandGEM_) {
441  //const int bx_clct_start(bx_alct - match_trig_window_size/2);
442  //const int bx_clct_stop(bx_alct + match_trig_window_size/2);
443 
444  if (debug_gem_matching){
445  std::cout << "========================================================================" << std::endl;
446  // std::cout << "GEM-CLCT matching in ME2/1 chamber: " << cscChamber->id() << " in bx range: [" << bx_clct_start << "," << bx_clct_stop << "]" << std::endl;
447  std::cout <<"GEM-CLCT matching in ME2/1 chamber: "<< cscChamber->id()<< "in bx:"<<bx_alct<<std::endl;
448  std::cout << "------------------------------------------------------------------------" << std::endl;
449  }
450  // GEM-to-CLCT
451  int nSuccesFulMatches = 0;
452  //for (int bx_clct = bx_clct_start; bx_clct <= bx_clct_stop; bx_clct++)
453  // {
454  // if (bx_clct < 0 or bx_clct >= CSCCathodeLCTProcessor::MAX_CLCT_BINS) continue;
455  if (drop_used_clcts and used_clct_mask[bx_alct]) continue;
456  if (clct->bestCLCT[bx_alct].isValid())
457  {
458  const int quality(clct->bestCLCT[bx_alct].getQuality());
459  // only use high-Q stubs for the time being
460  if (quality < 4) continue;
461 
462  ++nSuccesFulMatches;
463 
464  int mbx = std::abs(clct->bestCLCT[bx_alct].getBX()-bx_alct);
465  int bx_gem = (coPads[0].second)->bx()+lct_central_bx;
466  correlateLCTsGEM(clct->bestCLCT[bx_alct], clct->secondCLCT[bx_alct], *(coPads[0].second), GEMDetId(coPads[0].first).roll(),
467  allLCTs[bx_gem][mbx][0], allLCTs[bx_gem][mbx][1]);
468  if (debug_gem_matching) {
469  // if (infoV > 1) LogTrace("CSCMotherboard")
470  std::cout << "Successful GEM-CLCT match in ME21: bx_alct = " << bx_alct <<std::endl;
471  //<< "; match window: [" << bx_clct_start << "; " << bx_clct_stop
472  //<< "]; bx_clct = " << bx_clct << std::endl;
473  std::cout << "+++ Best CLCT Details: ";
474  clct->bestCLCT[bx_alct].print();
475  std::cout << "+++ Second CLCT Details: ";
476  clct->secondCLCT[bx_alct].print();
477  }
478  if (allLCTs[bx_gem][mbx][0].isValid()) {
479  used_clct_mask[bx_alct] += 1;
481  }
482  }
483  }
484  }
485  }
486 
487  // reduction of nLCTs per each BX
488  for (int bx = 0; bx < MAX_LCT_BINS; bx++)
489  {
490  // counting
491  unsigned int n=0;
492  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
493  for (int i=0;i<2;i++)
494  {
495  int cbx = bx + mbx - match_trig_window_size/2;
496  if (allLCTs[bx][mbx][i].isValid())
497  {
498  ++n;
499  if (infoV > 0) LogDebug("CSCMotherboard")
500  << "LCT"<<i+1<<" "<<bx<<"/"<<cbx<<": "<<allLCTs[bx][mbx][i]<<std::endl;
501  }
502  }
503 
504  // some simple cross-bx sorting algorithms
505  if (tmb_cross_bx_algo == 1 and (n>2))
506  {
507  n=0;
508  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
509  for (int i=0;i<2;i++)
510  {
511  if (allLCTs[bx][pref[mbx]][i].isValid())
512  {
513  n++;
514  if (n>2) allLCTs[bx][pref[mbx]][i].clear();
515  }
516  }
517 
518  n=0;
519  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
520  for (int i=0;i<2;i++)
521  {
522  int cbx = bx + mbx - match_trig_window_size/2;
523  if (allLCTs[bx][mbx][i].isValid())
524  {
525  n++;
526  if (infoV > 0) LogDebug("CSCMotherboard")
527  << "LCT"<<i+1<<" "<<bx<<"/"<<cbx<<": "<<allLCTs[bx][mbx][i]<<std::cout;
528  }
529  }
530  if (infoV > 0 and n>0) LogDebug("CSCMotherboard")
531  <<"bx "<<bx<<" nnLCT:"<<n<<" "<<n<<std::endl;
532  } // x-bx sorting
533  }
534 
535  bool first = true;
536  unsigned int n=0;
537  for (auto p : readoutLCTs()) {
538  if (debug_gem_matching and first){
539  std::cout << "========================================================================" << std::endl;
540  std::cout << "Counting the final LCTs" << std::endl;
541  std::cout << "========================================================================" << std::endl;
542  first = false;
543  std::cout << "tmb_cross_bx_algo: " << tmb_cross_bx_algo << std::endl;
544  }
545  n++;
546  if (debug_gem_matching)
547  std::cout << "LCT "<<n<<" " << p <<std::endl;
548  }
549 }
550 
551 
552 //readout LCTs
553 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME21GEM::readoutLCTs()
554 {
555  return getLCTs();
556 }
557 
558 //getLCTs when we use different sort algorithm
559 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME21GEM::getLCTs()
560 {
561  std::vector<CSCCorrelatedLCTDigi> result;
562  for (int bx = 0; bx < MAX_LCT_BINS; bx++) {
563  std::vector<CSCCorrelatedLCTDigi> tmpV;
564  if (tmb_cross_bx_algo == 2) {
565  tmpV = sortLCTsByQuality(bx);
566  result.insert(result.end(), tmpV.begin(), tmpV.end());
567  }
568  else if (tmb_cross_bx_algo == 3) {
569  tmpV = sortLCTsByGEMDPhi(bx);
570  result.insert(result.end(), tmpV.begin(), tmpV.end());
571  }
572  else {
573  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++) {
574  for (int i=0;i<2;i++) {
575  if (allLCTs[bx][mbx][i].isValid()) {
576  result.push_back(allLCTs[bx][mbx][i]);
577  }
578  }
579  }
580  }
581  }
582  return result;
583 }
584 
585 //sort LCTs by Quality in each BX
586 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME21GEM::sortLCTsByQuality(int bx)
587 {
588  std::vector<CSCCorrelatedLCTDigi> LCTs;
589  LCTs.clear();
590  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
591  for (int i=0;i<2;i++)
592  if (allLCTs[bx][mbx][i].isValid())
593  LCTs.push_back(allLCTs[bx][mbx][i]);
594 
595  //std::cout<<"LCT before sorting in Bx:"<<bx<<std::endl;
596  //for (auto p : LCTs)
597  // std::cout<< p <<std::endl;
598  // return sorted vector with 2 highest quality LCTs
599  std::sort(LCTs.begin(), LCTs.end(), CSCMotherboard::sortByQuality);
600  if (LCTs.size()> max_me21_lcts) LCTs.erase(LCTs.begin()+max_me21_lcts, LCTs.end());
601  //std::cout<<"LCT after sorting by quality in BX:"<<bx<<std::endl;
602  //for (auto p : LCTs)
603  // std::cout<< p <<std::endl;
604  return LCTs;
605 }
606 
607 //sort LCTs by dphi in each BX
608 std::vector<CSCCorrelatedLCTDigi> CSCMotherboardME21GEM::sortLCTsByGEMDPhi(int bx)
609 {
610  std::vector<CSCCorrelatedLCTDigi> LCTs;
611  LCTs.clear();
612  for (unsigned int mbx = 0; mbx < match_trig_window_size; mbx++)
613  for (int i=0;i<2;i++)
614  if (allLCTs[bx][mbx][i].isValid())
615  LCTs.push_back(allLCTs[bx][mbx][i]);
616 
617  // return sorted vector with 2 highest quality LCTs
618  std::sort(LCTs.begin(), LCTs.end(), CSCMotherboard::sortByGEMDphi);
619  if (LCTs.size()> max_me21_lcts) LCTs.erase(LCTs.begin()+max_me21_lcts, LCTs.end());
620  return LCTs;
621 }
622 
623 
625  CSCALCTDigi secondALCT,
626  CSCCLCTDigi bestCLCT,
627  CSCCLCTDigi secondCLCT,
628  CSCCorrelatedLCTDigi& lct1,
629  CSCCorrelatedLCTDigi& lct2,
630  const GEMPadsBX& pads,
631  const GEMPadsBX& copads)
632 {
633  // check for pads
634  const int nPads(pads.size());
635  const int nCoPads(copads.size());
636  const bool hasPads(nPads!=0);
637  const bool hasCoPads(nCoPads!=0);
638 
639  bool anodeBestValid = bestALCT.isValid();
640  bool anodeSecondValid = secondALCT.isValid();
641  bool cathodeBestValid = bestCLCT.isValid();
642  bool cathodeSecondValid = secondCLCT.isValid();
643 
644  if (anodeBestValid and !anodeSecondValid) secondALCT = bestALCT;
645  if (!anodeBestValid and anodeSecondValid) bestALCT = secondALCT;
646  if (cathodeBestValid and !cathodeSecondValid) secondCLCT = bestCLCT;
647  if (!cathodeBestValid and cathodeSecondValid) bestCLCT = secondCLCT;
648 
649  // ALCT-CLCT matching conditions are defined by "trig_enable" configuration
650  // parameters.
651  if ((alct_trig_enable and bestALCT.isValid()) or
652  (clct_trig_enable and bestCLCT.isValid()) or
653  (match_trig_enable and bestALCT.isValid() and bestCLCT.isValid()))
654  {
655  lct1 = constructLCTsGEM(bestALCT, bestCLCT, hasPads, hasCoPads);
656  lct1.setTrknmb(1);
657  }
658 
659  if (((secondALCT != bestALCT) or (secondCLCT != bestCLCT)) and
660  ((alct_trig_enable and secondALCT.isValid()) or
661  (clct_trig_enable and secondCLCT.isValid()) or
662  (match_trig_enable and secondALCT.isValid() and secondCLCT.isValid())))
663  {
664  lct2 = constructLCTsGEM(secondALCT, secondCLCT, hasPads, hasCoPads);
665  lct2.setTrknmb(2);
666  }
667 }
668 
669 
671  CSCALCTDigi secondALCT,
672  GEMPadDigi gemPad,
673  CSCCorrelatedLCTDigi& lct1,
674  CSCCorrelatedLCTDigi& lct2)
675 {
676  bool anodeBestValid = bestALCT.isValid();
677  bool anodeSecondValid = secondALCT.isValid();
678 
679  if (anodeBestValid and !anodeSecondValid) secondALCT = bestALCT;
680  if (!anodeBestValid and anodeSecondValid) bestALCT = secondALCT;
681 
682  if ((alct_trig_enable and bestALCT.isValid()) or
683  (match_trig_enable and bestALCT.isValid()))
684  {
685  lct1 = constructLCTsGEM(bestALCT, gemPad, useOldLCTDataFormat_);
686  lct1.setTrknmb(1);
687  // lct1.setGEMDPhi(0.0);
688  }
689 
690  if ((alct_trig_enable and secondALCT.isValid()) or
691  (match_trig_enable and secondALCT.isValid() and secondALCT != bestALCT))
692  {
693  lct2 = constructLCTsGEM(secondALCT, gemPad, useOldLCTDataFormat_);
694  lct2.setTrknmb(2);
695  // lct2.setGEMDPhi(0.0);
696  }
697 }
698 
699 
701  CSCCLCTDigi secondCLCT,
702  GEMPadDigi gemPad, int roll,
703  CSCCorrelatedLCTDigi& lct1,
704  CSCCorrelatedLCTDigi& lct2)
705 {
706  bool cathodeBestValid = bestCLCT.isValid();
707  bool cathodeSecondValid = secondCLCT.isValid();
708 
709  if (cathodeBestValid and !cathodeSecondValid) secondCLCT = bestCLCT;
710  if (!cathodeBestValid and cathodeSecondValid) bestCLCT = secondCLCT;
711 
712  if ((clct_trig_enable and bestCLCT.isValid()) or
713  (match_trig_enable and bestCLCT.isValid()))
714  {
715  lct1 = constructLCTsGEM(bestCLCT, gemPad, roll, useOldLCTDataFormat_);
716  lct1.setTrknmb(1);
717  }
718 
719  if ((clct_trig_enable and secondCLCT.isValid()) or
720  (match_trig_enable and secondCLCT.isValid() and secondCLCT != bestCLCT))
721  {
722  lct2 = constructLCTsGEM(secondCLCT, gemPad, roll, useOldLCTDataFormat_);
723  lct2.setTrknmb(2);
724  }
725 }
726 
727 
729  const GEMPadDigi& gem,
730  bool oldDataFormat)
731 {
732  if (oldDataFormat){
733  // CLCT pattern number - set it to a highest value
734  // hack to get LCTs in the CSCTF
735  unsigned int pattern = promoteALCTGEMpattern_ ? 10 : 0;
736 
737  // LCT quality number - set it to a very high value
738  // hack to get LCTs in the CSCTF
739  unsigned int quality = promoteALCTGEMquality_ ? 14 : 11;
740 
741  // Bunch crossing
742  int bx = alct.getBX();
743 
744  // get keyStrip from LUT
745  int keyStrip = gemPadToCscHs_[gem.pad()];
746 
747  // get wiregroup from ALCT
748  int wg = alct.getKeyWG();
749 
750  // construct correlated LCT; temporarily assign track number of 0.
751  return CSCCorrelatedLCTDigi(0, 1, quality, wg, keyStrip, pattern, 0, bx, 0, 0, 0, theTrigChamber);
752  }
753  else {
754  // CLCT pattern number - no pattern
755  unsigned int pattern = 0;
756 
757  // LCT quality number
758  unsigned int quality = 1;
759 
760  // Bunch crossing
761  int bx = gem.bx() + lct_central_bx;
762 
763  // get keyStrip from LUT
764  int keyStrip = gemPadToCscHs_[gem.pad()];
765  // get wiregroup from ALCT
766  int wg = alct.getKeyWG();
767 
768  // construct correlated LCT; temporarily assign track number of 0.
769  return CSCCorrelatedLCTDigi(0, 1, quality, wg, keyStrip, pattern, 0, bx, 0, 0, 0, theTrigChamber);
770  }
771 }
772 
774  const GEMPadDigi& gem, int roll,
775  bool oldDataFormat)
776 {
777  if (oldDataFormat){
778  // CLCT pattern number - for the time being, do not include GEMs in the pattern
779  unsigned int pattern = encodePattern(clct.getPattern(), clct.getStripType());
780 
781  // LCT quality number - dummy quality
782  unsigned int quality = promoteCLCTGEMquality_ ? 14 : 11;
783 
784  // Bunch crossing: pick GEM bx
785  int bx = gem.bx() + lct_central_bx;
786 
787  // pick a random WG in the roll range
788  int wg(20);
789 
790  // construct correlated LCT; temporarily assign track number of 0.
791  return CSCCorrelatedLCTDigi(0, 1, quality, wg, clct.getKeyStrip(), pattern, clct.getBend(), bx, 0, 0, 0, theTrigChamber);
792  }
793  else {
794  // CLCT pattern number - no pattern
795  unsigned int pattern = 0;//encodePatternGEM(clct.getPattern(), clct.getStripType());
796 
797  // LCT quality number - dummy quality
798  unsigned int quality = 5;//findQualityGEM(alct, gem);
799 
800  // Bunch crossing: get it from cathode LCT if anode LCT is not there.
801  int bx = gem.bx() + lct_central_bx;;
802 
803  // ALCT WG
804  int wg(0);
805 
806  // construct correlated LCT; temporarily assign track number of 0.
807  return CSCCorrelatedLCTDigi(0, 1, quality, wg, 0, pattern, 0, bx, 0, 0, 0, theTrigChamber);
808  }
809 }
810 
811 
813  bool hasPad, bool hasCoPad)
814 {
815  // CLCT pattern number
816  unsigned int pattern = encodePattern(cLCT.getPattern(), cLCT.getStripType());
817 
818  // LCT quality number
819  unsigned int quality = findQualityGEM(aLCT, cLCT, hasPad, hasCoPad);
820 
821  // Bunch crossing: get it from cathode LCT if anode LCT is not there.
822  int bx = aLCT.isValid() ? aLCT.getBX() : cLCT.getBX();
823 
824  // construct correlated LCT; temporarily assign track number of 0.
825  int trknmb = 0;
826  CSCCorrelatedLCTDigi thisLCT(trknmb, 1, quality, aLCT.getKeyWG(),
827  cLCT.getKeyStrip(), pattern, cLCT.getBend(),
828  bx, 0, 0, 0, theTrigChamber);
829  return thisLCT;
830 }
831 
832 
833 unsigned int CSCMotherboardME21GEM::findQualityGEM(const CSCALCTDigi& aLCT, const CSCCLCTDigi& cLCT,
834  bool hasPad, bool hasCoPad)
835 {
836 
837  /*
838  Same LCT quality definition as standard LCTs
839  c4 takes GEMs into account!!!
840  */
841 
842  unsigned int quality = 0;
843 
844  if (!isTMB07) {
845  bool isDistrip = (cLCT.getStripType() == 0);
846 
847  if (aLCT.isValid() && !(cLCT.isValid())) { // no CLCT
848  if (aLCT.getAccelerator()) {quality = 1;}
849  else {quality = 3;}
850  }
851  else if (!(aLCT.isValid()) && cLCT.isValid()) { // no ALCT
852  if (isDistrip) {quality = 4;}
853  else {quality = 5;}
854  }
855  else if (aLCT.isValid() && cLCT.isValid()) { // both ALCT and CLCT
856  if (aLCT.getAccelerator()) {quality = 2;} // accelerator muon
857  else { // collision muon
858  // CLCT quality is, in fact, the number of layers hit, so subtract 3
859  // to get quality analogous to ALCT one.
860  int sumQual = aLCT.getQuality() + (cLCT.getQuality()-3);
861  if (sumQual < 1 || sumQual > 6) {
862  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
863  << "+++ findQuality: sumQual = " << sumQual << "+++ \n";
864  }
865  if (isDistrip) { // distrip pattern
866  if (sumQual == 2) {quality = 6;}
867  else if (sumQual == 3) {quality = 7;}
868  else if (sumQual == 4) {quality = 8;}
869  else if (sumQual == 5) {quality = 9;}
870  else if (sumQual == 6) {quality = 10;}
871  }
872  else { // halfstrip pattern
873  if (sumQual == 2) {quality = 11;}
874  else if (sumQual == 3) {quality = 12;}
875  else if (sumQual == 4) {quality = 13;}
876  else if (sumQual == 5) {quality = 14;}
877  else if (sumQual == 6) {quality = 15;}
878  }
879  }
880  }
881  }
882 #ifdef OLD
883  else {
884  // Temporary definition, used until July 2008.
885  // First if statement is fictitious, just to help the CSC TF emulator
886  // handle such cases (one needs to make sure they will be accounted for
887  // in the new quality definition.
888  if (!(aLCT.isValid()) || !(cLCT.isValid())) {
889  if (aLCT.isValid() && !(cLCT.isValid())) quality = 1; // no CLCT
890  else if (!(aLCT.isValid()) && cLCT.isValid()) quality = 2; // no ALCT
891  else quality = 0; // both absent; should never happen.
892  }
893  else {
894  // Sum of ALCT and CLCT quality bits. CLCT quality is, in fact, the
895  // number of layers hit, so subtract 3 to put it to the same footing as
896  // the ALCT quality.
897  int sumQual = aLCT.getQuality() + (cLCT.getQuality()-3);
898  if (sumQual < 1 || sumQual > 6) {
899  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
900  << "+++ findQuality: Unexpected sumQual = " << sumQual << "+++\n";
901  }
902 
903  // LCT quality is basically the sum of ALCT and CLCT qualities, but split
904  // in two groups depending on the CLCT pattern id (higher quality for
905  // straighter patterns).
906  int offset = 0;
907  if (cLCT.getPattern() <= 7) offset = 4;
908  else offset = 9;
909  quality = offset + sumQual;
910  }
911  }
912 #endif
913  else {
914  // 2008 definition.
915  if (!(aLCT.isValid()) || !(cLCT.isValid())) {
916  if (aLCT.isValid() && !(cLCT.isValid())) quality = 1; // no CLCT
917  else if (!(aLCT.isValid()) && cLCT.isValid()) quality = 2; // no ALCT
918  else quality = 0; // both absent; should never happen.
919  }
920  else {
921  const int pattern(cLCT.getPattern());
922  if (pattern == 1) quality = 3; // layer-trigger in CLCT
923  else {
924  // ALCT quality is the number of layers hit minus 3.
925  // CLCT quality is the number of layers hit.
926  int n_gem = 0;
927  if (hasPad) n_gem = 1;
928  if (hasCoPad) n_gem = 2;
929  const bool a4((aLCT.getQuality() >= 1) or (aLCT.getQuality() >= 0 and n_gem >=1));
930  const bool c4((cLCT.getQuality() >= 4) or (cLCT.getQuality() >= 3 and n_gem>=1));
931  // quality = 4; "reserved for low-quality muons in future"
932  if (!a4 && !c4) quality = 5; // marginal anode and cathode
933  else if ( a4 && !c4) quality = 6; // HQ anode, but marginal cathode
934  else if (!a4 && c4) quality = 7; // HQ cathode, but marginal anode
935  else if ( a4 && c4) {
936  if (aLCT.getAccelerator()) quality = 8; // HQ muon, but accel ALCT
937  else {
938  // quality = 9; "reserved for HQ muons with future patterns
939  // quality = 10; "reserved for HQ muons with future patterns
940  if (pattern == 2 || pattern == 3) quality = 11;
941  else if (pattern == 4 || pattern == 5) quality = 12;
942  else if (pattern == 6 || pattern == 7) quality = 13;
943  else if (pattern == 8 || pattern == 9) quality = 14;
944  else if (pattern == 10) quality = 15;
945  else {
946  if (infoV >= 0) edm::LogWarning("L1CSCTPEmulatorWrongValues")
947  << "+++ findQuality: Unexpected CLCT pattern id = "
948  << pattern << "+++\n";
949  }
950  }
951  }
952  }
953  }
954  }
955  return quality;
956 }
957 
958 
960  GEMCoPadDigiCollection& out_co_pads,
961  CSCDetId csc_id)
962 {
963  gemCoPadV.clear();
964 
965  // build coincidences
966  for (auto det_range = out_pads->begin(); det_range != out_pads->end(); ++det_range) {
967  const GEMDetId& id = (*det_range).first;
968 
969  // same chamber
970  if (id.region() != csc_id.zendcap() or
971  id.ring() != csc_id.ring() or id.chamber() != csc_id.chamber()) continue;
972 
973  // build coincidences only for long superchamber pads
974  if (id.station() != 2) continue;
975 
976  // all coincidences detIDs will have layer=1
977  if (id.layer() != 1) continue;
978 
979  // find the corresponding id with layer=2
980  GEMDetId co_id(id.region(), id.ring(), id.station(), 2, id.chamber(), id.roll());
981 
982  auto co_pads_range = out_pads->get(co_id);
983  // empty range = no possible coincidence pads
984  if (co_pads_range.first == co_pads_range.second) continue;
985 
986  // now let's correlate the pads in two layers of this partition
987  const auto& pads_range = (*det_range).second;
988  for (auto p = pads_range.first; p != pads_range.second; ++p) {
989  for (auto co_p = co_pads_range.first; co_p != co_pads_range.second; ++co_p) {
990  // check the match in pad
991  if (std::abs(p->pad() - co_p->pad()) > maxDeltaPadInCoPad_) continue;
992  // check the match in BX
993  if (std::abs(p->bx() - co_p->bx()) > maxDeltaBXInCoPad_ ) continue;
994 
995  // make a new coincidence pad digi
996  gemCoPadV.push_back(GEMCoPadDigi(id.roll(),*p,*co_p));
997  out_co_pads.insertDigi(id, GEMCoPadDigi(id.roll(),*p,*co_p));
998  }
999  }
1000  }
1001 }
1002 
1003 
1004 std::map<int,std::pair<double,double> >
1006 {
1007  std::map<int,std::pair<double,double> > result;
1008 
1009  auto chamber(gem_g->chamber(GEMDetId(1,1,2,1,1,0)));
1010  if (chamber==nullptr) return result;
1011 
1012  for(int i = 1; i<= chamber->nEtaPartitions(); ++i){
1013  auto roll(chamber->etaPartition(i));
1014  if (roll==nullptr) continue;
1015  const float half_striplength(roll->specs()->specificTopology().stripLength()/2.);
1016  const LocalPoint lp_top(0., half_striplength, 0.);
1017  const LocalPoint lp_bottom(0., -half_striplength, 0.);
1018  const GlobalPoint gp_top(roll->toGlobal(lp_top));
1019  const GlobalPoint gp_bottom(roll->toGlobal(lp_bottom));
1020  //result[i] = std::make_pair(floorf(gp_top.eta() * 100) / 100, ceilf(gp_bottom.eta() * 100) / 100);
1021  result[i] = std::make_pair(gp_top.eta(), gp_bottom.eta());
1022  }
1023  return result;
1024 }
1025 
1027 {
1028  auto superChamber(gem_g->superChamber(id));
1029  for (auto ch : superChamber->chambers()) {
1030  for (auto roll : ch->etaPartitions()) {
1031  GEMDetId roll_id(roll->id());
1032  auto pads_in_det = gemPads->get(roll_id);
1033  for (auto pad = pads_in_det.first; pad != pads_in_det.second; ++pad) {
1034  auto id_pad = std::make_pair(roll_id, &(*pad));
1035  const int bx_shifted(lct_central_bx + pad->bx());
1036  for (int bx = bx_shifted - maxDeltaBXPad_;bx <= bx_shifted + maxDeltaBXPad_; ++bx) {
1037  pads_[bx].push_back(id_pad);
1038  }
1039  }
1040  }
1041  }
1042 }
1043 
1045 {
1046  auto superChamber(gem_g->superChamber(id));
1047  for (auto ch : superChamber->chambers()) {
1048  for (auto roll : ch->etaPartitions()) {
1049  GEMDetId roll_id(roll->id());
1050  auto pads_in_det = gemPads->get(roll_id);
1051  for (auto pad = pads_in_det.first; pad != pads_in_det.second; ++pad) {
1052  GEMPadDigi gfirst((*pad).first());
1053  auto id_pad = std::make_pair(roll_id, &gfirst);
1054  const int bx_shifted(lct_central_bx + (pad->first()).bx());
1055  for (int bx = bx_shifted - maxDeltaBXPad_;bx <= bx_shifted + maxDeltaBXPad_; ++bx) {
1056  if(bx != lct_central_bx) continue;
1057  coPads_[bx].push_back(id_pad);
1058  }
1059  }
1060  }
1061  }
1062 }
1063 
1064 void CSCMotherboardME21GEM::printGEMTriggerPads(int bx_start, int bx_stop, bool iscopad)
1065 {
1066  // pads or copads?
1067  auto thePads(!iscopad ? pads_ : coPads_ );
1068  const bool hasPads(thePads.size()!=0);
1069 
1070  std::cout << "------------------------------------------------------------------------" << std::endl;
1071  bool first = true;
1072  for (int bx = bx_start; bx <= bx_stop; bx++) {
1073  // print only the pads for the central BX
1074  //if (bx!=lct_central_bx and iscopad) continue;
1075  std::vector<std::pair<unsigned int, const GEMPadDigi*> > in_pads = thePads[bx];
1076  if (first) {
1077  if (!iscopad) std::cout << "* GEM trigger pads: " << std::endl;
1078  else std::cout << "* GEM trigger coincidence pads: " << std::endl;
1079  }
1080  first = false;
1081  if (!iscopad) std::cout << "N(pads) BX " << bx << " : " << in_pads.size() << std::endl;
1082  else std::cout << "N(copads) BX " << bx << " : " << in_pads.size() << std::endl;
1083  if (hasPads){
1084  for (auto pad : in_pads){
1085  auto roll_id(GEMDetId(pad.first));
1086  std::cout << "\tdetId " << pad.first << " " << roll_id << ", pad = " << pad.second->pad() << ", BX = " << pad.second->bx() + 6 << std::endl;
1087  }
1088  }
1089  else
1090  break;
1091  }
1092 }
1093 
1094 
1096 CSCMotherboardME21GEM::matchingGEMPads(const CSCCLCTDigi& clct, const GEMPadsBX& pads, bool isCoPad, bool first)
1097 {
1099 
1100  // fetch the low and high pad edges for the long superchambers
1101  int deltaPad(isCoPad ? maxDeltaPadCoPad_ : maxDeltaPadPad_);
1102  int deltaBX(isCoPad ? maxDeltaBXCoPad_ : maxDeltaBXPad_);
1103  int clct_bx = clct.getBX();
1104  const int lowPad(cscHsToGemPad_[clct.getKeyStrip()].first);
1105  const int highPad(cscHsToGemPad_[clct.getKeyStrip()].second);
1106  const bool debug(false);
1107  if (debug) std::cout << "lowpad " << lowPad << " highpad " << highPad << " delta pad " << deltaPad <<std::endl;
1108  for (auto p: pads){
1109  if (debug) std::cout<<"DetId"<<GEMDetId(p.first)<<" "<< *(p.second)<<std::endl;
1110  auto padRoll((p.second)->pad());
1111  int pad_bx = (p.second)->bx()+lct_central_bx;
1112  if (debug) std::cout << "padRoll " << padRoll << std::endl;
1113  if (std::abs(clct_bx-pad_bx)>deltaBX) continue;
1114  if (std::abs(lowPad - padRoll) <= deltaPad or std::abs(padRoll - highPad) <= deltaPad){
1115  if (debug) std::cout << "++Matches! " << std::endl;
1116  result.push_back(p);
1117  if (first) return result;
1118  }
1119  }
1120  return result;
1121 }
1122 
1123 
1125 CSCMotherboardME21GEM::matchingGEMPads(const CSCALCTDigi& alct, const GEMPadsBX& pads, bool isCoPad, bool first)
1126 {
1128  int deltaBX(isCoPad ? maxDeltaBXCoPad_ : maxDeltaBXPad_);
1129  int alct_bx = alct.getBX();
1130  int Wg = alct.getKeyWG();
1131  std::vector<int> Rolls;
1132  Rolls.push_back(cscWgToGemRoll_[Wg]);
1133  if (Wg>=maxDeltaWg_ && cscWgToGemRoll_[Wg] != cscWgToGemRoll_[Wg-maxDeltaWg_])
1134  Rolls.push_back(cscWgToGemRoll_[Wg-maxDeltaWg_]);
1135  if ((unsigned int)(Wg+maxDeltaWg_)<cscWgToGemRoll_.size() && cscWgToGemRoll_[Wg] != cscWgToGemRoll_[Wg+maxDeltaWg_])
1136  Rolls.push_back(cscWgToGemRoll_[Wg+maxDeltaWg_]);
1137 
1138  const bool debug(false);
1139  if (debug) std::cout << "ALCT keyWG " << alct.getKeyWG() << std::endl;
1140  for (auto alctRoll : Rolls)
1141  {
1142  if (debug) std::cout <<"roll " << alctRoll << std::endl;
1143  for (auto p: pads){
1144  auto padRoll(GEMDetId(p.first).roll());
1145  int pad_bx = (p.second)->bx()+lct_central_bx;
1146  if (debug) std::cout<<"Detid "<< GEMDetId(p.first) <<" "<< *(p.second)<<std::endl;
1147  if (debug) std::cout << "Candidate ALCT: " << padRoll << std::endl;
1148  if (std::abs(alct_bx-pad_bx)>deltaBX) continue;
1149  if (alctRoll != padRoll) continue;
1150  if (debug) std::cout << "++Matches! " << std::endl;
1151  result.push_back(p);
1152  if (first) return result;
1153  }
1154  }
1155  return result;
1156 }
1157 
1158 
1161  bool isCoPad, bool first)
1162 {
1164 
1165  // Fetch all (!) pads matching to ALCTs and CLCTs
1166  auto padsClct(matchingGEMPads(clct, pads, isCoPad, false));
1167  auto padsAlct(matchingGEMPads(alct, pads, isCoPad, false));
1168 
1169  const bool debug(false);
1170  if (debug) std::cout << "-----------------------------------------------------------------------"<<std::endl;
1171  // Check if the pads overlap
1172  for (auto p : padsAlct){
1173  if (debug) std::cout<< "Candidate ALCT: " << p.first << " " << *(p.second) << std::endl;
1174  for (auto q: padsClct){
1175  if (debug) std::cout<< "++Candidate CLCT: " << q.first << " " << *(q.second) << std::endl;
1176  // look for exactly the same pads
1177  if ((p.first != q.first) or GEMPadDigi(*(p.second)) != *(q.second)) continue;
1178  if (debug) std::cout << "++Matches! " << std::endl;
1179  result.push_back(p);
1180  if (first) return result;
1181  }
1182  }
1183  if (debug) std::cout << "-----------------------------------------------------------------------"<<std::endl;
1184  return result;
1185 }
1186 
1187 
1189 {
1190  int result = -99;
1191  for(auto p : gemRollToEtaLimits_) {
1192  const float minEta((p.second).first);
1193  const float maxEta((p.second).second);
1194  if (minEta <= eta and eta <= maxEta) {
1195  result = p.first;
1196  break;
1197  }
1198  }
1199  return result;
1200 }
1201 
1202 
1203 std::vector<GEMCoPadDigi> CSCMotherboardME21GEM::readoutCoPads()
1204 {
1205  return gemCoPadV;
1206 }
#define LogDebug(id)
int getQuality() const
return quality of a pattern (number of layers hit!)
Definition: CSCCLCTDigi.h:33
std::vector< GEMCoPadDigi > readoutCoPads()
int chamber() const
Definition: CSCDetId.h:68
const unsigned theSector
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< CSCCorrelatedLCTDigi > getLCTs()
GEMPadsBX matchingGEMPads(const CSCCLCTDigi &cLCT, const GEMPadsBX &pads=GEMPadsBX(), bool isCopad=false, bool first=true)
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...
unsigned int findQualityGEM(const CSCALCTDigi &aLCT, const CSCCLCTDigi &cLCT, bool hasPad, bool hasCoPad)
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 &)
unsigned int match_trig_window_size
const unsigned theTrigChamber
bool isValid() const
check ALCT validity (1 - valid ALCT)
Definition: CSCALCTDigi.h:30
std::map< int, std::pair< double, double > > gemRollToEtaLimits_
int roll() const
Definition: GEMDetId.h:80
const unsigned theEndcap
double maxEta
std::vector< CSCCorrelatedLCTDigi > sortLCTsByQuality(int bx)
int getStripType() const
return striptype
Definition: CSCCLCTDigi.h:39
tuple result
Definition: mps_fire.py:84
int deltaPad(int hs, int pad)
int getBend() const
return bend
Definition: CSCCLCTDigi.h:42
U second(std::pair< T, U > const &p)
const unsigned theStation
void retrieveGEMPads(const GEMPadDigiCollection *pads, unsigned id)
static CSCTriggerGeomManager * get()
static const double lut_wg_eta_odd[112][2]
tuple quality
[pTError/pT]*max(1,normChi2) &lt;= ptErrorCut
int pad() const
Definition: GEMPadDigi.h:26
const unsigned theSubsector
int getBX() const
return BX
Definition: CSCCLCTDigi.h:51
unsigned int encodePattern(const int ptn, const int highPt)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< GEMPadBX > GEMPadsBX
bool isValid() const
check CLCT validity (1 - valid CLCT)
Definition: CSCCLCTDigi.h:30
unsigned int match_trig_enable
MuonDigiCollection< GEMDetId, GEMCoPadDigi > GEMCoPadDigiCollection
std::map< int, std::pair< double, double > > createGEMRollEtaLUT()
const GEMSuperChamber * superChamber(GEMDetId id) const
Definition: GEMGeometry.cc:91
int getBX() const
return BX - five low bits of BXN counter tagged by the ALCT
Definition: CSCALCTDigi.h:48
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
static const double lut_pt_vs_dphi_gemcsc[8][3]
int getAccelerator() const
Definition: CSCALCTDigi.h:37
void run(const CSCWireDigiCollection *wiredc, const CSCComparatorDigiCollection *compdc, const GEMPadDigiCollection *gemPads)
std::map< int, std::pair< int, int > > cscHsToGemPad_
int bx() const
Definition: GEMPadDigi.h:27
int getPattern() const
return pattern
Definition: CSCCLCTDigi.h:36
const GEMChamber * chamber(GEMDetId id) const
Definition: GEMGeometry.cc:95
std::map< int, int > gemPadToCscHs_
CSCCorrelatedLCTDigi allLCTs[MAX_LCT_BINS][15][2]
const GEMGeometry * gem_g
unsigned int alct_trig_enable
std::vector< GEMCoPadDigi > gemCoPadV
std::unique_ptr< CSCAnodeLCTProcessor > alct
void buildCoincidencePads(const GEMPadDigiCollection *out_pads, GEMCoPadDigiCollection &out_co_pads, CSCDetId csc_id)
void printGEMTriggerPads(int minBX, int maxBx, bool iscopad=false)
CSCCorrelatedLCTDigi constructLCTsGEM(const CSCALCTDigi &alct, const GEMPadDigi &gem, bool oldDataFormat=false)
std::vector< CSCCorrelatedLCTDigi > sortLCTsByGEMDPhi(int bx)
std::unique_ptr< CSCCathodeLCTProcessor > clct
std::vector< CSCCorrelatedLCTDigi > readoutLCTs()
const std::vector< const GEMStation * > & stations() const
Return a vector of all GEM stations.
Definition: GEMGeometry.cc:47
tuple cout
Definition: gather_cfg.py:145
CSCMotherboardME21GEM(unsigned endcap, unsigned station, unsigned sector, unsigned subsector, unsigned chamber, const edm::ParameterSet &conf)
void retrieveGEMCoPads(const GEMCoPadDigiCollection *pads, unsigned id)
int getKeyStrip() const
Definition: CSCCLCTDigi.h:65
void setTrknmb(const uint16_t number)
Set track number (1,2) after sorting LCTs.
void correlateLCTsGEM(CSCALCTDigi bestALCT, CSCALCTDigi secondALCT, GEMPadDigi gemPad, CSCCorrelatedLCTDigi &lct1, CSCCorrelatedLCTDigi &lct2)
std::map< int, int > cscWgToGemRoll_
int getKeyWG() const
return key wire group
Definition: CSCALCTDigi.h:45
tuple size
Write out results.
static bool sortByQuality(const CSCCorrelatedLCTDigi &, const CSCCorrelatedLCTDigi &)
static const double lut_wg_eta_even[112][2]