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 {
31 public:
32 
34 
35  // standard constructor
36  CSCGEMMotherboard(unsigned endcap, unsigned station, unsigned sector,
37  unsigned subsector, unsigned chamber,
38  const edm::ParameterSet& conf);
39 
40  //Default constructor for testing
42 
43  ~CSCGEMMotherboard() override;
44 
45  // clear stored pads and copads
46  void clear();
47 
49 
50  // run TMB with GEM pads as input
52  virtual void run(const CSCWireDigiCollection* wiredc,
53  const CSCComparatorDigiCollection* compdc,
54  const GEMPadDigiCollection* gemPads)=0;
55 
56  // run TMB with GEM pad clusters as input
57  void run(const CSCWireDigiCollection* wiredc,
58  const CSCComparatorDigiCollection* compdc,
59  const GEMPadDigiClusterCollection* gemPads);
60 
62  std::unique_ptr<GEMCoPadProcessor> coPadProcessor;
63 
65  void setGEMGeometry(const GEMGeometry *g) { gem_g = g; }
66 
67 protected:
68 
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  int getRoll(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,
92  matches<T>&) const;
93 
94  // match CLCT to GEM Pad/CoPad
95  // the template is GEMPadDigi or GEMCoPadDigi
96  template <class T>
97  void matchingPads(const CSCCLCTDigi& alct,
98  matches<T>&) const;
99 
100  // find the matching pads to a pair of ALCT/CLCT
101  // the first template is ALCT or CLCT
102  // the second template is GEMPadDigi or GEMCoPadDigi
103  template <class S, class T>
104  void matchingPads(const S& d1, const S& d2,
105  matches<T>&) const;
106 
107  // find common matches between an ALCT and CLCT
108  // the template is GEMPadDigi or GEMCoPadDigi
109  template <class T>
110  void matchingPads(const CSCCLCTDigi& clct1, const CSCALCTDigi& alct1,
111  matches<T>&) const;
112 
113  // find all matching pads to a pair of ALCT and a pair of CLCT
114  // the template is GEMPadDigi or GEMCoPadDigi
115  template <class T>
116  void matchingPads(const CSCCLCTDigi& clct1, const CSCCLCTDigi& clct2,
117  const CSCALCTDigi& alct1, const CSCALCTDigi& alct2,
118  matches<T>&) const;
119 
120  // find the best matching pad to an ALCT
121  // the template is GEMPadDigi or GEMCoPadDigi
122  template <class T>
123  T bestMatchingPad(const CSCALCTDigi&, const matches<T>&) const;
124 
125  // find the best matching pad to an ALCT
126  // the template is GEMPadDigi or GEMCoPadDigi
127  template <class T>
128  T bestMatchingPad(const CSCCLCTDigi&, const matches<T>&) const;
129 
130  // find the best matching pad to an ALCT and CLCT
131  // the template is GEMPadDigi or GEMCoPadDigi
132  template <class T>
133  T bestMatchingPad(const CSCALCTDigi&, const CSCCLCTDigi&,
134  const matches<T>&) const;
135 
136  // correlate ALCTs/CLCTs with a set of matching GEM copads
137  // use this function when the best matching copads are not clear yet
138  // the template is ALCT or CLCT
139  template <class T>
140  void correlateLCTsGEM(T& best, T& second, const GEMCoPadDigiIds& coPads,
141  CSCCorrelatedLCTDigi& lct1, 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, const T& second,
147  const GEMCoPadDigi&, const GEMCoPadDigi&,
148  CSCCorrelatedLCTDigi& lct1, CSCCorrelatedLCTDigi& lct2) const;
149 
150  // construct LCT from ALCT and GEM copad
151  // fourth argument is the LCT number (1 or 2)
153  const GEMCoPadDigi& gem, int i) const;
154 
155  // construct LCT from CLCT and GEM copad
156  // fourth argument is the LCT number (1 or 2)
158  const GEMCoPadDigi& gem,
159  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 CSCCLCTDigi& clct,
185  const GEMPadDigi& gem1,
186  const GEMCoPadDigi& gem2,
187  int i) const;
188 
189  // get the pads/copads from the digi collection and store in handy containers
190  void retrieveGEMPads(const GEMPadDigiCollection* pads, unsigned id);
191  void retrieveGEMCoPads();
192 
193  // quality of the LCT when you take into account max 2 GEM layers
194  unsigned int findQualityGEM(const CSCALCTDigi&,
195  const CSCCLCTDigi&,
196  int gemlayer) const;
197 
198  // print available trigger pads
199  void printGEMTriggerPads(int bx_start, int bx_stop, enum CSCPart);
200  void printGEMTriggerCoPads(int bx_start, int bx_stop, enum CSCPart);
201 
202  bool isPadInOverlap(int roll) const;
203 
204  void setupGeometry();
205 
207  unsigned gemId;
208 
211 
212  std::vector<GEMCoPadDigi> gemCoPadV;
213 
214  // map< bx , vector<gemid, pad> >
217 
218  // deltas used to match to GEM pads
223 
224  // send LCT old dataformat
226 
227  // promote ALCT-GEM pattern
229 
232 
233  // LCT ghostbusting
235 
236  private:
237 
238  template <class T>
239  const matchesBX<T>& getPads() const;
240 
241  template <class T>
242  int getMaxDeltaBX() const;
243 
244  template <class T>
245  int getLctTrigEnable() const;
246 };
247 
248 
249 template<class T>
251  matches<T>& result) const
252 {
253  result.clear();
254  // Invalid ALCTs have no matching pads
255  if (not alct.isValid()) return;
256 
257  // Get the corresponding roll numbers for a given ALCT
258  std::pair<int,int> alctRoll =
260 
261  // Get the pads in the ALCT bx
262  const matchesBX<T>& lut = getPads<T>();
263 
264  // If no pads in that bx...
265  if (lut.count(alct.getBX())==0) return;
266 
267  for (const auto& p: lut.at(alct.getBX())){
268  auto padRoll(getRoll(p));
269 
270  // pad bx needs to match to ALCT bx
271  int pad_bx = getBX(p.second)+CSCConstants::LCT_CENTRAL_BX;
272  if (std::abs(alct.getBX()-pad_bx)>getMaxDeltaBX<T>()) continue;
273 
274  // gem roll number if invalid
275  if (alctRoll.first == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
276  alctRoll.second == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE) continue;
277  // ALCTs at the top of the chamber
278  else if (alctRoll.first == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
279  padRoll > alctRoll.second) continue;
280  // ALCTs at the bottom of the chamber
281  else if (alctRoll.second == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
282  padRoll < alctRoll.first) continue;
283  // ignore pads that are too far away in roll number
284  else if ((alctRoll.first != CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
285  alctRoll.second != CSCGEMMotherboard::DEFAULT_MATCHING_VALUE) and
286  (alctRoll.first > padRoll or padRoll > alctRoll.second)) continue;
287  result.push_back(p);
288  }
289 }
290 
291 template<class T>
293  matches<T>& result) const
294 {
295  result.clear();
296  // Invalid ALCTs have no matching pads
297  if (not clct.isValid()) return;
298 
299  auto part(getCSCPart(clct.getKeyStrip()));
300  // Get the corresponding pad numbers for a given CLCT
301  const auto& mymap = (getLUT()->get_csc_hs_to_gem_pad(theParity, part));
302  int keyStrip = clct.getKeyStrip();
303  //ME1A part, convert halfstrip from 128-223 to 0-95
305  keyStrip = keyStrip - CSCConstants::MAX_HALF_STRIP_ME1B -1;
306  const int lowPad(mymap[keyStrip].first);
307  const int highPad(mymap[keyStrip].second);
308 
309  // Get the pads in the CLCT bx
310  const matchesBX<T>& lut = getPads<T>();
311 
312  // If no pads in that bx...
313  if (lut.count(clct.getBX())==0) return;
314 
315  for (const auto& p: lut.at(clct.getBX())){
316 
317  // pad bx needs to match to CLCT bx
318  int pad_bx = getBX(p.second)+CSCConstants::LCT_CENTRAL_BX;
319  if (std::abs(clct.getBX()-pad_bx)>getMaxDeltaBX<T>()) continue;
320 
321  // pad number must match
322  int padNumber(getPad(p.second));
323  if (std::abs(lowPad - padNumber) <= maxDeltaPadL1_ or
324  std::abs(padNumber - highPad) <= maxDeltaPadL1_){
325  result.push_back(p);
326  }
327  }
328 }
329 
330 
331 template <class S, class T>
332 void CSCGEMMotherboard::matchingPads(const S& d1, const S& d2,
333  matches<T>& result) const
334 {
335  matches<T> p1, p2;
336 
337  // pads matching to the CLCT/ALCT
338  matchingPads<T>(d1, p1);
339 
340  // pads matching to the CLCT/ALCT
341  matchingPads<T>(d2, p2);
342 
343  // collect *all* matching pads
344  result.reserve(p1.size() + p2.size());
345  result.insert(std::end(result), std::begin(p1), std::end(p1));
346  result.insert(std::end(result), std::begin(p2), std::end(p2));
347 }
348 
349 template <class T>
351  const CSCALCTDigi& alct1,
352  matches<T>& result) const
353 {
354  matches<T> padsClct, padsAlct;
355 
356  // pads matching to the CLCT
357  matchingPads<T>(clct1, padsClct);
358 
359  // pads matching to the ALCT
360  matchingPads<T>(alct1, padsAlct);
361 
362  // collect all *common* pads
363  intersection(padsClct, padsAlct, result);
364 }
365 
366 template <class T>
368  const CSCCLCTDigi& clct2,
369  const CSCALCTDigi& alct1,
370  const CSCALCTDigi& alct2,
371  matches<T>& result) const
372 {
373  matches<T> padsClct, padsAlct;
374 
375  // pads matching to CLCTs
376  matchingPads<CSCCLCTDigi, T>(clct1, clct2, padsClct);
377 
378  // pads matching to ALCTs
379  matchingPads<CSCALCTDigi, T>(alct1, alct2, padsAlct);
380 
381  // collect *all* matching pads
382  result.reserve(padsClct.size() + padsAlct.size());
383  result.insert(std::end(result), std::begin(padsClct), std::end(padsClct));
384  result.insert(std::end(result), std::begin(padsAlct), std::end(padsAlct));
385 }
386 
387 
388 template <class S>
390  const matches<S>& pads) const
391 {
392  S result;
393  // no matching pads for invalid stub
394  if (not alct1.isValid()) return result;
395 
396  // return the first one with the same roll number
397  for (const auto& p: pads){
398 
399  // protection against corrupted DetIds
400  if (not isGEMDetId(p.first)) continue;
401 
402  // roll number of pad and ALCT must match
403  if (getRoll(p) == getRoll(alct1)){
404  return p.second;
405  }
406  }
407  return result;
408 }
409 
410 template <class S>
412  const matches<S>& pads) const
413 {
414  S result;
415  // no matching pads for invalid stub
416  if (not clct.isValid()) return result;
417 
418  auto part(getCSCPart(clct.getKeyStrip()));
419 
420  // return the pad with the smallest bending angle
421  float averagePadNumberCSC = getPad(clct, part);
422  float minDeltaPad = 999;
423  for (const auto& p: pads){
424 
425  // protection against corrupted DetIds
426  if (not isGEMDetId(p.first)) continue;
427 
428  // best pad is closest to CLCT in number of halfstrips
429  float averagePadNumberGEM = getPad(p.second);
430  if (std::abs(averagePadNumberCSC - averagePadNumberGEM) < minDeltaPad){
431  minDeltaPad = std::abs(averagePadNumberCSC - averagePadNumberGEM);
432  result = p.second;
433  }
434  }
435  return result;
436 }
437 
438 template <class S>
440  const CSCCLCTDigi& clct1,
441  const matches<S>& pads) const
442 {
443  S result;
444  // no matching pads for invalid stub
445  if (not alct1.isValid() or not clct1.isValid()) return result;
446 
447  auto part(getCSCPart(clct1.getKeyStrip()));
448 
449  // return the pad with the smallest bending angle
450  float averagePadNumberCSC = getPad(clct1, part);
451  float minDeltaPad = 999;
452  for (const auto& p: pads){
453 
454  // protection against corrupted DetIds
455  if (not isGEMDetId(p.first)) continue;
456 
457  float averagePadNumberGEM = getPad(p.second);
458  // add another safety to make sure that the deltaPad is not larger than max value!!!
459  if (std::abs(averagePadNumberCSC - averagePadNumberGEM) < minDeltaPad and
460  getRoll(p) == getRoll(alct1)){
461  minDeltaPad = std::abs(averagePadNumberCSC - averagePadNumberGEM);
462  result = p.second;
463  }
464  }
465  return result;
466 }
467 
468 template <class T>
470  T& secondLCT,
471  const GEMCoPadDigiIds& coPads,
472  CSCCorrelatedLCTDigi& lct1,
473  CSCCorrelatedLCTDigi& lct2) const
474 {
475  // Check which LCTs are valid
476  bool bestValid = bestLCT.isValid();
477  bool secondValid = secondLCT.isValid();
478 
479  // At this point, set both LCTs valid if they are invalid
480  // Duplicate LCTs are taken into account later
481  if (bestValid and !secondValid) secondLCT = bestLCT;
482  if (!bestValid and secondValid) bestLCT = secondLCT;
483 
484  // get best matching copad1
485  const GEMCoPadDigi& bestCoPad = bestMatchingPad<GEMCoPadDigi>(bestLCT, coPads);
486  const GEMCoPadDigi& secondCoPad = bestMatchingPad<GEMCoPadDigi>(secondLCT, coPads);
487 
488  correlateLCTsGEM(bestLCT, secondLCT, bestCoPad, secondCoPad, lct1, lct2);
489 }
490 
491 
492 template<class T>
494  const T& secondLCT,
495  const GEMCoPadDigi& bestCoPad,
496  const GEMCoPadDigi& secondCoPad,
497  CSCCorrelatedLCTDigi& lct1,
498  CSCCorrelatedLCTDigi& lct2) const
499 {
500  // construct the first LCT from ALCT(CLCT) and a GEM Copad
501  if ((getLctTrigEnable<T>() and bestLCT.isValid()) or
502  (match_trig_enable and bestLCT.isValid()))
503  {
504  lct1 = constructLCTsGEM(bestLCT, bestCoPad, 1);
505  }
506 
507  // construct the second LCT from ALCT(CLCT) and a GEM Copad
508  if ((getLctTrigEnable<T>() and secondLCT.isValid()) or
509  (match_trig_enable and secondLCT.isValid() and secondLCT != bestLCT))
510  {
511  lct2 = constructLCTsGEM(secondLCT, secondCoPad, 2);
512  }
513 }
514 
515 #endif
void retrieveGEMPads(const GEMPadDigiCollection *pads, unsigned id)
match< GEMCoPadDigi > GEMCoPadDigiId
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
void correlateLCTsGEM(T &best, T &second, const GEMCoPadDigiIds &coPads, CSCCorrelatedLCTDigi &lct1, CSCCorrelatedLCTDigi &lct2) const
unsigned int findQualityGEM(const CSCALCTDigi &, const CSCCLCTDigi &, int gemlayer) const
virtual std::vector< std::pair< int, int > > get_csc_hs_to_gem_pad(Parity par, enum CSCPart) const =0
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
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
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
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
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