CMS 3D CMS Logo

CSCGEMMotherboard.h
Go to the documentation of this file.
1 #ifndef L1Trigger_CSCTriggerPrimitives_CSCGEMMotherboard_h
2 #define L1Trigger_CSCTriggerPrimitives_CSCGEMMotherboard_h
3 
20 
21 typedef match<GEMPadDigi> GEMPadDigiId;
22 typedef matches<GEMPadDigi> GEMPadDigiIds;
23 typedef matchesBX<GEMPadDigi> GEMPadDigiIdsBX;
24 
25 typedef match<GEMCoPadDigi> GEMCoPadDigiId;
26 typedef matches<GEMCoPadDigi> GEMCoPadDigiIds;
27 typedef matchesBX<GEMCoPadDigi> GEMCoPadDigiIdsBX;
28 
30 public:
32 
33  // standard constructor
34  CSCGEMMotherboard(unsigned endcap,
35  unsigned station,
36  unsigned sector,
37  unsigned subsector,
38  unsigned chamber,
39  const edm::ParameterSet& conf);
40 
41  //Default constructor for testing
43 
44  ~CSCGEMMotherboard() override;
45 
46  // clear stored pads and copads
47  void clear();
48 
50 
51  // run TMB with GEM pads as input
53  virtual void run(const CSCWireDigiCollection* wiredc,
54  const CSCComparatorDigiCollection* compdc,
55  const GEMPadDigiCollection* gemPads) = 0;
56 
57  // run TMB with GEM pad clusters as input
58  void run(const CSCWireDigiCollection* wiredc,
59  const CSCComparatorDigiCollection* compdc,
60  const GEMPadDigiClusterCollection* gemPads);
61 
63  std::unique_ptr<GEMCoPadProcessor> coPadProcessor;
64 
66  void setGEMGeometry(const GEMGeometry* g) { gem_g = g; }
67 
68 protected:
69  virtual const CSCGEMMotherboardLUT* getLUT() const = 0;
70  // check wether wiregroup corss strip or not. ME11 case would redefine this function
71  virtual bool doesWiregroupCrossStrip(int key_wg, int key_strip) const { return true; }
72 
73  // check if a GEMDetId is valid
74  bool isGEMDetId(unsigned int) const;
75 
76  // aux functions to get BX and position of a digi
77  int getBX(const GEMPadDigi& p) const;
78  int getBX(const GEMCoPadDigi& p) const;
79 
80  int getRoll(const GEMPadDigiId& p) const;
81  int getRoll(const GEMCoPadDigiId& p) const;
82  std::pair<int, int> getRolls(const CSCALCTDigi&) const;
83 
84  float getPad(const GEMPadDigi&) const;
85  float getPad(const GEMCoPadDigi&) const;
86  float getPad(const CSCCLCTDigi&, enum CSCPart par) const;
87 
88  // match ALCT to GEM Pad/CoPad
89  // the template is GEMPadDigi or GEMCoPadDigi
90  template <class T>
91  void matchingPads(const CSCALCTDigi& alct, matches<T>&) const;
92 
93  // match CLCT to GEM Pad/CoPad
94  // the template is GEMPadDigi or GEMCoPadDigi
95  template <class T>
96  void matchingPads(const CSCCLCTDigi& alct, matches<T>&) const;
97 
98  // find the matching pads to a pair of ALCT/CLCT
99  // the first template is ALCT or CLCT
100  // the second template is GEMPadDigi or GEMCoPadDigi
101  template <class S, class T>
102  void matchingPads(const S& d1, const S& d2, matches<T>&) const;
103 
104  // find common matches between an ALCT and CLCT
105  // the template is GEMPadDigi or GEMCoPadDigi
106  template <class T>
107  void matchingPads(const CSCCLCTDigi& clct1, const CSCALCTDigi& alct1, matches<T>&) const;
108 
109  // find all matching pads to a pair of ALCT and a pair of CLCT
110  // the template is GEMPadDigi or GEMCoPadDigi
111  template <class T>
112  void matchingPads(const CSCCLCTDigi& clct1,
113  const CSCCLCTDigi& clct2,
114  const CSCALCTDigi& alct1,
115  const CSCALCTDigi& alct2,
116  matches<T>&) const;
117 
118  // find the best matching pad to an ALCT
119  // the template is GEMPadDigi or GEMCoPadDigi
120  template <class T>
121  T bestMatchingPad(const CSCALCTDigi&, const matches<T>&) const;
122 
123  // find the best matching pad to an ALCT
124  // the template is GEMPadDigi or GEMCoPadDigi
125  template <class T>
126  T bestMatchingPad(const CSCCLCTDigi&, const matches<T>&) const;
127 
128  // find the best matching pad to an ALCT and CLCT
129  // the template is GEMPadDigi or GEMCoPadDigi
130  template <class T>
131  T bestMatchingPad(const CSCALCTDigi&, const CSCCLCTDigi&, const matches<T>&) const;
132 
133  // correlate ALCTs/CLCTs with a set of matching GEM copads
134  // use this function when the best matching copads are not clear yet
135  // the template is ALCT or CLCT
136  template <class T>
137  void correlateLCTsGEM(const T& best,
138  const T& second,
139  const GEMCoPadDigiIds& coPads,
140  CSCCorrelatedLCTDigi& lct1,
141  CSCCorrelatedLCTDigi& lct2) const;
142 
143  // correlate ALCTs/CLCTs with their best matching GEM copads
144  // the template is ALCT or CLCT
145  template <class T>
146  void correlateLCTsGEM(const T& best,
147  const T& second,
148  const GEMCoPadDigi&,
149  const GEMCoPadDigi&,
150  CSCCorrelatedLCTDigi& lct1,
151  CSCCorrelatedLCTDigi& lct2) const;
152 
153  // construct LCT from ALCT and GEM copad
154  // fourth argument is the LCT number (1 or 2)
155  CSCCorrelatedLCTDigi constructLCTsGEM(const CSCALCTDigi& alct, const GEMCoPadDigi& gem, int i) const;
156 
157  // construct LCT from CLCT and GEM copad
158  // fourth argument is the LCT number (1 or 2)
159  CSCCorrelatedLCTDigi constructLCTsGEM(const CSCCLCTDigi& clct, const GEMCoPadDigi& gem, int i) const;
160 
161  // construct LCT from ALCT,CLCT and GEM copad
162  // last argument is the LCT number (1 or 2)
164  const CSCCLCTDigi& clct,
165  const GEMCoPadDigi& gem,
166  int i) const;
167 
168  // construct LCT from ALCT,CLCT and a single GEM pad
169  // last argument is the LCT number (1 or 2)
171  const CSCCLCTDigi& clct,
172  const GEMPadDigi& gem,
173  int i) const;
174  /*
175  * General function to construct integrated stubs from CSC and GEM information.
176  * Options are:
177  * 1. ALCT-CLCT-GEMPad
178  * 2. ALCT-CLCT-GEMCoPad
179  * 3. ALCT-GEMCoPad
180  * 4. CLCT-GEMCoPad
181  */
182  // last argument is the LCT number (1 or 2)
184  const CSCALCTDigi& alct, const CSCCLCTDigi& clct, const GEMPadDigi& gem1, const GEMCoPadDigi& gem2, int i) const;
185 
186  // get the pads/copads from the digi collection and store in handy containers
187  void retrieveGEMPads(const GEMPadDigiCollection* pads, unsigned id);
188  void retrieveGEMCoPads();
189 
190  // quality of the LCT when you take into account max 2 GEM layers
191  unsigned int findQualityGEM(const CSCALCTDigi&, const CSCCLCTDigi&, int gemlayer) const;
192 
193  // print available trigger pads
194  void printGEMTriggerPads(int bx_start, int bx_stop, enum CSCPart);
195  void printGEMTriggerCoPads(int bx_start, int bx_stop, enum CSCPart);
196 
197  bool isPadInOverlap(int roll) const;
198 
199  void setupGeometry();
200 
202  unsigned gemId;
203 
206 
207  std::vector<GEMCoPadDigi> gemCoPadV;
208 
209  // map< bx , vector<gemid, pad> >
212 
213  // deltas used to match to GEM pads
218 
219  // send LCT old dataformat
221 
222  // promote ALCT-GEM pattern
224 
227 
228  // LCT ghostbusting
230 
231 private:
232  template <class T>
233  const matchesBX<T>& getPads() const;
234 
235  template <class T>
236  int getMaxDeltaBX() const;
237 
238  template <class T>
239  int getLctTrigEnable() const;
240 };
241 
242 template <class T>
243 void CSCGEMMotherboard::matchingPads(const CSCALCTDigi& alct, matches<T>& result) const {
244  result.clear();
245  // Invalid ALCTs have no matching pads
246  if (not alct.isValid())
247  return;
248 
249  // Get the corresponding roll numbers for a given ALCT
250  std::pair<int, int> alctRoll = (getLUT()->get_csc_wg_to_gem_roll(theParity))[alct.getKeyWG()];
251 
252  // Get the pads in the ALCT bx
253  const matchesBX<T>& lut = getPads<T>();
254 
255  // If no pads in that bx...
256  if (lut.count(alct.getBX()) == 0)
257  return;
258 
259  for (const auto& p : lut.at(alct.getBX())) {
260  auto padRoll(getRoll(p));
261 
262  int delta;
263  if (GEMDetId(p.first).station() == 2)
264  delta = 1;
265 
266  // pad bx needs to match to ALCT bx
267  int pad_bx = getBX(p.second) + CSCConstants::LCT_CENTRAL_BX;
268 
269  if (std::abs(alct.getBX() - pad_bx) > getMaxDeltaBX<T>())
270  continue;
271 
272  // gem roll number if invalid
273  if (alctRoll.first == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
275  continue;
276  // ALCTs at the top of the chamber
277  else if (alctRoll.first == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and padRoll > alctRoll.second)
278  continue;
279  // ALCTs at the bottom of the chamber
280  else if (alctRoll.second == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and padRoll < alctRoll.first)
281  continue;
282  // ignore pads that are too far away in roll number
283  else if ((alctRoll.first != CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
284  alctRoll.second != CSCGEMMotherboard::DEFAULT_MATCHING_VALUE) and
285  (alctRoll.first - delta > padRoll or padRoll > alctRoll.second))
286  continue;
287  result.push_back(p);
288  }
289 }
290 
291 template <class T>
292 void CSCGEMMotherboard::matchingPads(const CSCCLCTDigi& clct, matches<T>& result) const {
293  result.clear();
294  // Invalid ALCTs have no matching pads
295  if (not clct.isValid())
296  return;
297 
298  auto part(getCSCPart(clct.getKeyStrip()));
299  // Get the corresponding pad numbers for a given CLCT
300  const auto& mymap = (getLUT()->get_csc_hs_to_gem_pad(theParity, part));
301  int keyStrip = clct.getKeyStrip();
302  //ME1A part, convert halfstrip from 128-223 to 0-95
304  keyStrip = keyStrip - CSCConstants::MAX_HALF_STRIP_ME1B - 1;
305  const int lowPad(mymap[keyStrip].first);
306  const int highPad(mymap[keyStrip].second);
307 
308  // Get the pads in the CLCT bx
309  const matchesBX<T>& lut = getPads<T>();
310 
311  // If no pads in that bx...
312  if (lut.count(clct.getBX()) == 0)
313  return;
314 
315  for (const auto& p : lut.at(clct.getBX())) {
316  // pad bx needs to match to CLCT bx
317  int pad_bx = getBX(p.second) + CSCConstants::LCT_CENTRAL_BX;
318  if (std::abs(clct.getBX() - pad_bx) > getMaxDeltaBX<T>())
319  continue;
320 
321  // pad number must match
322  int padNumber(getPad(p.second));
323  if (std::abs(lowPad - padNumber) <= maxDeltaPadL1_ or std::abs(padNumber - highPad) <= maxDeltaPadL1_) {
324  result.push_back(p);
325  }
326  }
327 }
328 
329 template <class S, class T>
330 void CSCGEMMotherboard::matchingPads(const S& d1, const S& d2, matches<T>& result) const {
331  matches<T> p1, p2;
332 
333  // pads matching to the CLCT/ALCT
334  matchingPads<T>(d1, p1);
335 
336  // pads matching to the CLCT/ALCT
337  matchingPads<T>(d2, p2);
338 
339  // collect *all* matching pads
340  result.reserve(p1.size() + p2.size());
341  result.insert(std::end(result), std::begin(p1), std::end(p1));
342  result.insert(std::end(result), std::begin(p2), std::end(p2));
343 }
344 
345 template <class T>
346 void CSCGEMMotherboard::matchingPads(const CSCCLCTDigi& clct1, const CSCALCTDigi& alct1, matches<T>& result) const {
347  matches<T> padsClct, padsAlct;
348 
349  // pads matching to the CLCT
350  matchingPads<T>(clct1, padsClct);
351 
352  // pads matching to the ALCT
353  matchingPads<T>(alct1, padsAlct);
354 
355  // collect all *common* pads
356  intersection(padsClct, padsAlct, result);
357 }
358 
359 template <class T>
361  const CSCCLCTDigi& clct2,
362  const CSCALCTDigi& alct1,
363  const CSCALCTDigi& alct2,
364  matches<T>& result) const {
365  matches<T> padsClct, padsAlct;
366 
367  // pads matching to CLCTs
368  matchingPads<CSCCLCTDigi, T>(clct1, clct2, padsClct);
369 
370  // pads matching to ALCTs
371  matchingPads<CSCALCTDigi, T>(alct1, alct2, padsAlct);
372 
373  // collect *all* matching pads
374  result.reserve(padsClct.size() + padsAlct.size());
375  result.insert(std::end(result), std::begin(padsClct), std::end(padsClct));
376  result.insert(std::end(result), std::begin(padsAlct), std::end(padsAlct));
377 }
378 
379 template <class S>
380 S CSCGEMMotherboard::bestMatchingPad(const CSCALCTDigi& alct1, const matches<S>& pads) const {
381  S result;
382  // no matching pads for invalid stub
383  if (not alct1.isValid()) {
384  return result;
385  }
386  // return the first one with the same roll number
387  for (const auto& p : pads) {
388  // protection against corrupted DetIds
389  if (not isGEMDetId(p.first))
390  continue;
391 
392  // roll number of pad and ALCT must match
393  if (getRolls(alct1).first <= getRoll(p) and getRoll(p) <= getRolls(alct1).second) {
394  return p.second;
395  }
396  }
397  return result;
398 }
399 
400 template <class S>
401 S CSCGEMMotherboard::bestMatchingPad(const CSCCLCTDigi& clct, const matches<S>& pads) const {
402  S result;
403  // no matching pads for invalid stub
404  if (not clct.isValid())
405  return result;
406 
407  auto part(getCSCPart(clct.getKeyStrip()));
408 
409  // return the pad with the smallest bending angle
410  float averagePadNumberCSC = getPad(clct, part);
411  float minDeltaPad = 999;
412  for (const auto& p : pads) {
413  // protection against corrupted DetIds
414  if (not isGEMDetId(p.first))
415  continue;
416 
417  // best pad is closest to CLCT in number of halfstrips
418  float averagePadNumberGEM = getPad(p.second);
419  if (std::abs(averagePadNumberCSC - averagePadNumberGEM) < minDeltaPad) {
420  minDeltaPad = std::abs(averagePadNumberCSC - averagePadNumberGEM);
421  result = p.second;
422  }
423  }
424  return result;
425 }
426 
427 template <class S>
428 S CSCGEMMotherboard::bestMatchingPad(const CSCALCTDigi& alct1, const CSCCLCTDigi& clct1, const matches<S>& pads) const {
429  S result;
430  // no matching pads for invalid stub
431  if (not alct1.isValid() or not clct1.isValid()) {
432  return result;
433  }
434 
435  auto part(getCSCPart(clct1.getKeyStrip()));
436 
437  // return the pad with the smallest bending angle
438  float averagePadNumberCSC = getPad(clct1, part);
439  float minDeltaPad = 999;
440  for (const auto& p : pads) {
441  // protection against corrupted DetIds
442  if (not isGEMDetId(p.first))
443  continue;
444 
445  float averagePadNumberGEM = getPad(p.second);
446 
447  int delta;
448  if (GEMDetId(p.first).station() == 2)
449  delta = 1;
450 
451  // add another safety to make sure that the deltaPad is not larger than max value!!!
452  if (std::abs(averagePadNumberCSC - averagePadNumberGEM) < minDeltaPad and
453  getRolls(alct1).first - delta <= getRoll(p) and getRoll(p) <= getRolls(alct1).second) {
454  minDeltaPad = std::abs(averagePadNumberCSC - averagePadNumberGEM);
455  result = p.second;
456  }
457  }
458  return result;
459 }
460 
461 template <class T>
463  const T& sLCT,
464  const GEMCoPadDigiIds& coPads,
465  CSCCorrelatedLCTDigi& lct1,
466  CSCCorrelatedLCTDigi& lct2) const {
467  T bestLCT = bLCT;
468  T secondLCT = sLCT;
469 
470  // Check which LCTs are valid
471  bool bestValid = bestLCT.isValid();
472  bool secondValid = secondLCT.isValid();
473 
474  // At this point, set both LCTs valid if they are invalid
475  // Duplicate LCTs are taken into account later
476  if (bestValid and !secondValid)
477  secondLCT = bestLCT;
478  if (!bestValid and secondValid)
479  bestLCT = secondLCT;
480 
481  // get best matching copad1
482  const GEMCoPadDigi& bestCoPad = bestMatchingPad<GEMCoPadDigi>(bestLCT, coPads);
483  const GEMCoPadDigi& secondCoPad = bestMatchingPad<GEMCoPadDigi>(secondLCT, coPads);
484 
485  correlateLCTsGEM(bestLCT, secondLCT, bestCoPad, secondCoPad, lct1, lct2);
486 }
487 
488 template <class T>
490  const T& secondLCT,
491  const GEMCoPadDigi& bestCoPad,
492  const GEMCoPadDigi& secondCoPad,
493  CSCCorrelatedLCTDigi& lct1,
494  CSCCorrelatedLCTDigi& lct2) const {
495  // construct the first LCT from ALCT(CLCT) and a GEM Copad
496  if ((getLctTrigEnable<T>() and bestLCT.isValid()) or (match_trig_enable and bestLCT.isValid())) {
497  lct1 = constructLCTsGEM(bestLCT, bestCoPad, 1);
498  }
499 
500  // construct the second LCT from ALCT(CLCT) and a GEM Copad
501  if ((getLctTrigEnable<T>() and secondLCT.isValid()) or
502  (match_trig_enable and secondLCT.isValid() and secondLCT != bestLCT)) {
503  lct2 = constructLCTsGEM(secondLCT, secondCoPad, 2);
504  }
505 }
506 
507 #endif
void retrieveGEMPads(const GEMPadDigiCollection *pads, unsigned id)
match< GEMCoPadDigi > GEMCoPadDigiId
void correlateLCTsGEM(const T &best, const T &second, const GEMCoPadDigiIds &coPads, CSCCorrelatedLCTDigi &lct1, CSCCorrelatedLCTDigi &lct2) const
bool isValid() const
check ALCT validity (1 - valid ALCT)
Definition: CSCALCTDigi.h:32
void setGEMGeometry(const GEMGeometry *g)
set CSC and GEM geometries for the matching needs
GEMCoPadDigiIdsBX coPads_
T bestMatchingPad(const CSCALCTDigi &, const matches< T > &) const
CSCCorrelatedLCTDigi secondLCT[CSCConstants::MAX_LCT_TBINS]
int getBX(const GEMPadDigi &p) const
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 g
Definition: Activities.doc:4
matches< GEMCoPadDigi > GEMCoPadDigiIds
virtual bool doesWiregroupCrossStrip(int key_wg, int key_strip) const
Definition: AMC13Event.h:6
std::vector< GEMCoPadDigi > gemCoPadV
U second(std::pair< T, U > const &p)
matchesBX< GEMPadDigi > GEMPadDigiIdsBX
match< GEMPadDigi > GEMPadDigiId
std::unique_ptr< GEMCoPadProcessor > coPadProcessor
virtual void run(const CSCWireDigiCollection *wiredc, const CSCComparatorDigiCollection *compdc, const GEMPadDigiCollection *gemPads)=0
unsigned int findQualityGEM(const CSCALCTDigi &, const CSCCLCTDigi &, int gemlayer) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
int getBX() const
return BX
Definition: CSCCLCTDigi.h:77
int station() const
Definition: GEMDetId.h:173
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void printGEMTriggerCoPads(int bx_start, int bx_stop, enum CSCPart)
bool isValid() const
check CLCT validity (1 - valid CLCT)
Definition: CSCCLCTDigi.h:35
int getRoll(const GEMPadDigiId &p) const
unsigned int match_trig_enable
#define end
Definition: vmac.h:39
int getLctTrigEnable() const
std::pair< int, int > getRolls(const CSCALCTDigi &) const
bool isGEMDetId(unsigned int) const
double p2[4]
Definition: TauolaWrapper.h:90
int getBX() const
return BX - five low bits of BXN counter tagged by the ALCT
Definition: CSCALCTDigi.h:65
bool isPadInOverlap(int roll) const
float getPad(const GEMPadDigi &) const
CSCCorrelatedLCTDigi constructLCTsGEM(const CSCALCTDigi &alct, const GEMCoPadDigi &gem, int i) const
matchesBX< GEMCoPadDigi > GEMCoPadDigiIdsBX
part
Definition: HCALResponse.h:20
bool isValid() const
return valid pattern bit
virtual const CSCGEMMotherboardLUT * getLUT() const =0
std::vector< CSCCorrelatedLCTDigi > readoutLCTs() const override
GEMPadDigiIdsBX pads_
#define begin
Definition: vmac.h:32
double p1[4]
Definition: TauolaWrapper.h:89
void intersection(const S &d1, const S &d2, S &result) const
virtual std::vector< std::pair< int, int > > get_csc_hs_to_gem_pad(Parity par, enum CSCPart) const =0
const matchesBX< T > & getPads() const
matches< GEMPadDigi > GEMPadDigiIds
void matchingPads(const CSCALCTDigi &alct, matches< T > &) const
~CSCGEMMotherboard() override
int getKeyStrip() const
Definition: CSCCLCTDigi.h:94
void run(const CSCWireDigiCollection *wiredc, const CSCComparatorDigiCollection *compdc) override
const GEMGeometry * gem_g
long double T
int getMaxDeltaBX() const
int getKeyWG() const
return key wire group
Definition: CSCALCTDigi.h:59
void printGEMTriggerPads(int bx_start, int bx_stop, enum CSCPart)
std::vector< std::pair< int, int > > get_csc_wg_to_gem_roll(Parity par, int layer=1) const
enum CSCPart getCSCPart(int keystrip) const