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 
48  // run TMB with GEM pads as input
49  virtual void run(const CSCWireDigiCollection* wiredc,
50  const CSCComparatorDigiCollection* compdc,
51  const GEMPadDigiCollection* gemPads)=0;
52 
53  // run TMB with GEM pad clusters as input
54  void run(const CSCWireDigiCollection* wiredc,
55  const CSCComparatorDigiCollection* compdc,
56  const GEMPadDigiClusterCollection* gemPads);
57 
59  std::unique_ptr<GEMCoPadProcessor> coPadProcessor;
60 
62  void setGEMGeometry(const GEMGeometry *g) { gem_g = g; }
63 
64 protected:
65 
66  virtual const CSCGEMMotherboardLUT* getLUT() const=0;
67 
68  // check if a GEMDetId is valid
69  bool isGEMDetId(unsigned int) const;
70 
71  // aux functions to get BX and position of a digi
72  int getBX(const GEMPadDigi& p) const;
73  int getBX(const GEMCoPadDigi& p) const;
74 
75  int getRoll(const GEMPadDigiId& p) const;
76  int getRoll(const GEMCoPadDigiId& p) const;
77  int getRoll(const CSCALCTDigi&) const;
78 
79  float getPad(const GEMPadDigi&) const;
80  float getPad(const GEMCoPadDigi&) const;
81  float getPad(const CSCCLCTDigi&, enum CSCPart part) const;
82 
83  // match ALCT to GEM Pad/CoPad
84  // the template is GEMPadDigi or GEMCoPadDigi
85  template <class T>
86  void matchingPads(const CSCALCTDigi& alct,
87  enum CSCPart part, matches<T>&) const;
88 
89  // match CLCT to GEM Pad/CoPad
90  // the template is GEMPadDigi or GEMCoPadDigi
91  template <class T>
92  void matchingPads(const CSCCLCTDigi& alct,
93  enum CSCPart part, matches<T>&) const;
94 
95  // find the matching pads to a pair of ALCT/CLCT
96  // the first template is ALCT or CLCT
97  // the second template is GEMPadDigi or GEMCoPadDigi
98  template <class S, class T>
99  void matchingPads(const S& d1, const S& d2,
100  enum CSCPart part, matches<T>&) const;
101 
102  // find common matches between an ALCT and CLCT
103  // the template is GEMPadDigi or GEMCoPadDigi
104  template <class T>
105  void matchingPads(const CSCCLCTDigi& clct1, const CSCALCTDigi& alct1,
106  enum CSCPart part, matches<T>&) const;
107 
108  // find all matching pads to a pair of ALCT and a pair of CLCT
109  // the template is GEMPadDigi or GEMCoPadDigi
110  template <class T>
111  void matchingPads(const CSCCLCTDigi& clct1, const CSCCLCTDigi& clct2,
112  const CSCALCTDigi& alct1, const CSCALCTDigi& alct2,
113  enum CSCPart part, matches<T>&) const;
114 
115  // find the best matching pad to an ALCT
116  // the template is GEMPadDigi or GEMCoPadDigi
117  template <class T>
118  T bestMatchingPad(const CSCALCTDigi&, const matches<T>&, enum CSCPart) 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 CSCCLCTDigi&, const matches<T>&, enum CSCPart) const;
124 
125  // find the best matching pad to an ALCT and CLCT
126  // the template is GEMPadDigi or GEMCoPadDigi
127  template <class T>
128  T bestMatchingPad(const CSCALCTDigi&, const CSCCLCTDigi&,
129  const matches<T>&, enum CSCPart) const;
130 
131  // correlate ALCTs/CLCTs with a set of matching GEM copads
132  // use this function when the best matching copads are not clear yet
133  // the template is ALCT or CLCT
134  template <class T>
135  void correlateLCTsGEM(T& best, T& second, const GEMCoPadDigiIds& coPads,
137  enum CSCPart) const;
138 
139  // correlate ALCTs/CLCTs with their best matching GEM copads
140  // the template is ALCT or CLCT
141  template <class T>
142  void correlateLCTsGEM(const T& best, const T& second,
143  const GEMCoPadDigi&, const GEMCoPadDigi&,
145  enum CSCPart) const;
146 
147  // construct LCT from ALCT and GEM copad
148  // third argument is the CSC 'partition'
149  // fourth argument is the LCT number (1 or 2)
151  const GEMCoPadDigi& gem,
152  enum CSCPart, int i) const;
153 
154  // construct LCT from CLCT and GEM copad
155  // third argument is the CSC 'partition'
156  // fourth argument is the LCT number (1 or 2)
158  const GEMCoPadDigi& gem,
159  enum CSCPart, int i) const;
160 
161  // construct LCT from ALCT,CLCT and GEM copad
162  // fourth argument is the CSC 'partition'
163  // fifth argument is the LCT number (1 or 2)
165  const CSCCLCTDigi& clct,
166  const GEMCoPadDigi& gem,
167  enum CSCPart p, int i) const;
168 
169  // construct LCT from ALCT,CLCT and a single GEM pad
170  // fourth argument is the CSC 'partition'
171  // fifth argument is the LCT number (1 or 2)
173  const CSCCLCTDigi& clct,
174  const GEMPadDigi& gem,
175  enum CSCPart p, int i) const;
176  /*
177  * General function to construct integrated stubs from CSC and GEM information.
178  * Options are:
179  * 1. ALCT-CLCT-GEMPad
180  * 2. ALCT-CLCT-GEMCoPad
181  * 3. ALCT-GEMCoPad
182  * 4. CLCT-GEMCoPad
183  */
184  // fifth argument is the CSC 'partition'
185  // sixth argument is the LCT number (1 or 2)
187  const CSCCLCTDigi& clct,
188  const GEMPadDigi& gem1,
189  const GEMCoPadDigi& gem2,
190  enum CSCPart p, int i) const;
191 
192  // get the pads/copads from the digi collection and store in handy containers
193  void retrieveGEMPads(const GEMPadDigiCollection* pads, unsigned id);
194  void retrieveGEMCoPads();
195 
196  // quality of the LCT when you take into account max 2 GEM layers
197  unsigned int findQualityGEM(const CSCALCTDigi&,
198  const CSCCLCTDigi&,
199  int gemlayer) const;
200 
201  // print available trigger pads
202  void printGEMTriggerPads(int bx_start, int bx_stop, enum CSCPart);
203  void printGEMTriggerCoPads(int bx_start, int bx_stop, enum CSCPart);
204 
205  bool isPadInOverlap(int roll) const;
206 
207  void setupGeometry();
208 
210  unsigned gemId;
211 
214 
215  std::vector<GEMCoPadDigi> gemCoPadV;
216 
217  // map< bx , vector<gemid, pad> >
220 
221  // deltas used to match to GEM pads
226 
227  // send LCT old dataformat
229 
230  // promote ALCT-GEM pattern
232 
235 
236  // LCT ghostbusting
238 
239  private:
240 
241  template <class T>
242  const matchesBX<T>& getPads() const;
243 
244  template <class T>
245  int getMaxDeltaBX() const;
246 
247  template <class T>
248  int getLctTrigEnable() const;
249 };
250 
251 
252 template<class T>
254  enum CSCPart part,
255  matches<T>& result) const
256 {
257  result.clear();
258  // Invalid ALCTs have no matching pads
259  if (not alct.isValid()) return;
260 
261  // Get the corresponding roll numbers for a given ALCT
262  std::pair<int,int> alctRoll =
264 
265  // Get the pads in the ALCT bx
266  const matchesBX<T>& lut = getPads<T>();
267 
268  // If no pads in that bx...
269  if (lut.count(alct.getBX())==0) return;
270 
271  for (const auto& p: lut.at(alct.getBX())){
272  auto padRoll(getRoll(p));
273 
274  // only pads in overlap are good for ME1A
275  if (part==CSCPart::ME1A and !isPadInOverlap(padRoll)) continue;
276 
277  // pad bx needs to match to ALCT bx
278  int pad_bx = getBX(p.second)+lct_central_bx;
279  if (std::abs(alct.getBX()-pad_bx)>getMaxDeltaBX<T>()) continue;
280 
281  // gem roll number if invalid
282  if (alctRoll.first == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
283  alctRoll.second == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE) continue;
284  // ALCTs at the top of the chamber
285  else if (alctRoll.first == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
286  padRoll > alctRoll.second) continue;
287  // ALCTs at the bottom of the chamber
288  else if (alctRoll.second == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
289  padRoll < alctRoll.first) continue;
290  // ignore pads that are too far away in roll number
291  else if ((alctRoll.first != CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
292  alctRoll.second != CSCGEMMotherboard::DEFAULT_MATCHING_VALUE) and
293  (alctRoll.first > padRoll or padRoll > alctRoll.second)) continue;
294  result.push_back(p);
295  }
296 }
297 
298 template<class T>
300  enum CSCPart part,
301  matches<T>& result) const
302 {
303  result.clear();
304  // Invalid ALCTs have no matching pads
305  if (not clct.isValid()) return;
306 
307  // Get the corresponding pad numbers for a given CLCT
308  const auto& mymap = (getLUT()->get_csc_hs_to_gem_pad(par, part));
309  const int lowPad(mymap[clct.getKeyStrip()].first);
310  const int highPad(mymap[clct.getKeyStrip()].second);
311 
312  // Get the pads in the CLCT bx
313  const matchesBX<T>& lut = getPads<T>();
314 
315  // If no pads in that bx...
316  if (lut.count(clct.getBX())==0) return;
317 
318  for (const auto& p: lut.at(clct.getBX())){
319 
320  // pad bx needs to match to CLCT bx
321  int pad_bx = getBX(p.second)+lct_central_bx;
322  if (std::abs(clct.getBX()-pad_bx)>getMaxDeltaBX<T>()) continue;
323 
324  // pad number must match
325  int padNumber(getPad(p.second));
326  if (std::abs(lowPad - padNumber) <= maxDeltaPadL1_ or
327  std::abs(padNumber - highPad) <= maxDeltaPadL1_){
328  result.push_back(p);
329  }
330  }
331 }
332 
333 
334 template <class S, class T>
335 void CSCGEMMotherboard::matchingPads(const S& d1, const S& d2,
336  enum CSCPart part,
337  matches<T>& result) const
338 {
339  matches<T> p1, p2;
340 
341  // pads matching to the CLCT/ALCT
342  matchingPads<T>(d1, part, p1);
343 
344  // pads matching to the CLCT/ALCT
345  matchingPads<T>(d2, part, p2);
346 
347  // collect *all* matching pads
348  result.reserve(p1.size() + p2.size());
349  result.insert(std::end(result), std::begin(p1), std::end(p1));
350  result.insert(std::end(result), std::begin(p2), std::end(p2));
351 }
352 
353 template <class T>
355  const CSCALCTDigi& alct1,
356  enum CSCPart part,
357  matches<T>& result) const
358 {
359  matches<T> padsClct, padsAlct;
360 
361  // pads matching to the CLCT
362  matchingPads<T>(clct1, part, padsClct);
363 
364  // pads matching to the ALCT
365  matchingPads<T>(alct1, part, padsAlct);
366 
367  // collect all *common* pads
368  intersection(padsClct, padsAlct, result);
369 }
370 
371 template <class T>
373  const CSCCLCTDigi& clct2,
374  const CSCALCTDigi& alct1,
375  const CSCALCTDigi& alct2,
376  enum CSCPart part,
377  matches<T>& result) const
378 {
379  matches<T> padsClct, padsAlct;
380 
381  // pads matching to CLCTs
382  matchingPads<CSCCLCTDigi, T>(clct1, clct2, part, padsClct);
383 
384  // pads matching to ALCTs
385  matchingPads<CSCALCTDigi, T>(alct1, alct2, part, padsAlct);
386 
387  // collect *all* matching pads
388  result.reserve(padsClct.size() + padsAlct.size());
389  result.insert(std::end(result), std::begin(padsClct), std::end(padsClct));
390  result.insert(std::end(result), std::begin(padsAlct), std::end(padsAlct));
391 }
392 
393 
394 template <class S>
396  const matches<S>& pads,
397  enum CSCPart) const
398 {
399  S result;
400  // no matching pads for invalid stub
401  if (not alct1.isValid()) return result;
402 
403  // return the first one with the same roll number
404  for (const auto& p: pads){
405 
406  // protection against corrupted DetIds
407  if (not isGEMDetId(p.first)) continue;
408 
409  // roll number of pad and ALCT must match
410  if (getRoll(p) == getRoll(alct1)){
411  return p.second;
412  }
413  }
414  return result;
415 }
416 
417 template <class S>
419  const matches<S>& pads,
420  enum CSCPart part) const
421 {
422  S result;
423  // no matching pads for invalid stub
424  if (not clct.isValid()) return result;
425 
426  // return the pad with the smallest bending angle
427  float averagePadNumberCSC = getPad(clct, part);
428  float minDeltaPad = 999;
429  for (const auto& p: pads){
430 
431  // protection against corrupted DetIds
432  if (not isGEMDetId(p.first)) continue;
433 
434  // best pad is closest to CLCT in number of halfstrips
435  float averagePadNumberGEM = getPad(p.second);
436  if (std::abs(averagePadNumberCSC - averagePadNumberGEM) < minDeltaPad){
437  minDeltaPad = std::abs(averagePadNumberCSC - averagePadNumberGEM);
438  result = p.second;
439  }
440  }
441  return result;
442 }
443 
444 template <class S>
446  const CSCCLCTDigi& clct1,
447  const matches<S>& pads,
448  enum CSCPart part) const
449 {
450  S result;
451  // no matching pads for invalid stub
452  if (not alct1.isValid() or not clct1.isValid()) return result;
453 
454  // return the pad with the smallest bending angle
455  float averagePadNumberCSC = getPad(clct1, part);
456  float minDeltaPad = 999;
457  for (const auto& p: pads){
458 
459  // protection against corrupted DetIds
460  if (not isGEMDetId(p.first)) continue;
461 
462  float averagePadNumberGEM = getPad(p.second);
463  // add another safety to make sure that the deltaPad is not larger than max value!!!
464  if (std::abs(averagePadNumberCSC - averagePadNumberGEM) < minDeltaPad and
465  getRoll(p) == getRoll(alct1)){
466  minDeltaPad = std::abs(averagePadNumberCSC - averagePadNumberGEM);
467  result = p.second;
468  }
469  }
470  return result;
471 }
472 
473 template <class T>
475  T& secondLCT,
476  const GEMCoPadDigiIds& coPads,
477  CSCCorrelatedLCTDigi& lct1,
478  CSCCorrelatedLCTDigi& lct2,
479  enum CSCPart p) const
480 {
481  // Check which LCTs are valid
482  bool bestValid = bestLCT.isValid();
483  bool secondValid = secondLCT.isValid();
484 
485  // At this point, set both LCTs valid if they are invalid
486  // Duplicate LCTs are taken into account later
487  if (bestValid and !secondValid) secondLCT = bestLCT;
488  if (!bestValid and secondValid) bestLCT = secondLCT;
489 
490  // get best matching copad1
491  const GEMCoPadDigi& bestCoPad = bestMatchingPad<GEMCoPadDigi>(bestLCT, coPads, p);
492  const GEMCoPadDigi& secondCoPad = bestMatchingPad<GEMCoPadDigi>(secondLCT, coPads, p);
493 
494  correlateLCTsGEM(bestLCT, secondLCT, bestCoPad, secondCoPad, lct1, lct2, p);
495 }
496 
497 
498 template<class T>
500  const T& secondLCT,
501  const GEMCoPadDigi& bestCoPad,
502  const GEMCoPadDigi& secondCoPad,
503  CSCCorrelatedLCTDigi& lct1,
504  CSCCorrelatedLCTDigi& lct2,
505  enum CSCPart p) const
506 {
507  // construct the first LCT from ALCT(CLCT) and a GEM Copad
508  if ((getLctTrigEnable<T>() and bestLCT.isValid()) or
509  (match_trig_enable and bestLCT.isValid()))
510  {
511  lct1 = constructLCTsGEM(bestLCT, bestCoPad, p, 1);
512  }
513 
514  // construct the second LCT from ALCT(CLCT) and a GEM Copad
515  if ((getLctTrigEnable<T>() and secondLCT.isValid()) or
516  (match_trig_enable and secondLCT.isValid() and secondLCT != bestLCT))
517  {
518  lct2 = constructLCTsGEM(secondLCT, secondCoPad, p, 2);
519  }
520 }
521 
522 #endif
void retrieveGEMPads(const GEMPadDigiCollection *pads, unsigned id)
match< GEMCoPadDigi > GEMCoPadDigiId
void matchingPads(const CSCALCTDigi &alct, enum CSCPart part, matches< T > &) const
bool isValid() const
check ALCT validity (1 - valid ALCT)
Definition: CSCALCTDigi.h:30
void setGEMGeometry(const GEMGeometry *g)
set CSC and GEM geometries for the matching needs
GEMCoPadDigiIdsBX coPads_
CSCCorrelatedLCTDigi constructLCTsGEM(const CSCALCTDigi &alct, const GEMCoPadDigi &gem, enum CSCPart, int i) 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
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
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
void correlateLCTsGEM(T &best, T &second, const GEMCoPadDigiIds &coPads, CSCCorrelatedLCTDigi &lct1, CSCCorrelatedLCTDigi &lct2, enum CSCPart) const
int getBX() const
return BX
Definition: CSCCLCTDigi.h:51
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:30
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:48
bool isPadInOverlap(int roll) const
float getPad(const GEMPadDigi &) const
matchesBX< GEMCoPadDigi > GEMCoPadDigiIdsBX
part
Definition: HCALResponse.h:20
virtual const CSCGEMMotherboardLUT * getLUT() const =0
GEMPadDigiIdsBX pads_
std::unique_ptr< CSCAnodeLCTProcessor > alct
#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
std::unique_ptr< CSCCathodeLCTProcessor > clct
T bestMatchingPad(const CSCALCTDigi &, const matches< T > &, enum CSCPart) const
matches< GEMPadDigi > GEMPadDigiIds
~CSCGEMMotherboard() override
int getKeyStrip() const
Definition: CSCCLCTDigi.h:65
const GEMGeometry * gem_g
long double T
int getMaxDeltaBX() const
int getKeyWG() const
return key wire group
Definition: CSCALCTDigi.h:45
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