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 par) 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  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  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  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  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  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>&) 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>&) 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>&) 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,
136  CSCCorrelatedLCTDigi& lct1, CSCCorrelatedLCTDigi& lct2) const;
137 
138  // correlate ALCTs/CLCTs with their best matching GEM copads
139  // the template is ALCT or CLCT
140  template <class T>
141  void correlateLCTsGEM(const T& best, const T& second,
142  const GEMCoPadDigi&, const GEMCoPadDigi&,
143  CSCCorrelatedLCTDigi& lct1, CSCCorrelatedLCTDigi& lct2) const;
144 
145  // construct LCT from ALCT and GEM copad
146  // fourth argument is the LCT number (1 or 2)
148  const GEMCoPadDigi& gem, int i) const;
149 
150  // construct LCT from CLCT and GEM copad
151  // fourth argument is the LCT number (1 or 2)
153  const GEMCoPadDigi& gem,
154  int i) const;
155 
156  // construct LCT from ALCT,CLCT and GEM copad
157  // last argument is the LCT number (1 or 2)
159  const CSCCLCTDigi& clct,
160  const GEMCoPadDigi& gem,
161  int i) const;
162 
163  // construct LCT from ALCT,CLCT and a single GEM pad
164  // last argument is the LCT number (1 or 2)
166  const CSCCLCTDigi& clct,
167  const GEMPadDigi& gem,
168  int i) const;
169  /*
170  * General function to construct integrated stubs from CSC and GEM information.
171  * Options are:
172  * 1. ALCT-CLCT-GEMPad
173  * 2. ALCT-CLCT-GEMCoPad
174  * 3. ALCT-GEMCoPad
175  * 4. CLCT-GEMCoPad
176  */
177  // last argument is the LCT number (1 or 2)
179  const CSCCLCTDigi& clct,
180  const GEMPadDigi& gem1,
181  const GEMCoPadDigi& gem2,
182  int i) const;
183 
184  // get the pads/copads from the digi collection and store in handy containers
185  void retrieveGEMPads(const GEMPadDigiCollection* pads, unsigned id);
186  void retrieveGEMCoPads();
187 
188  // quality of the LCT when you take into account max 2 GEM layers
189  unsigned int findQualityGEM(const CSCALCTDigi&,
190  const CSCCLCTDigi&,
191  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 
233  template <class T>
234  const matchesBX<T>& getPads() const;
235 
236  template <class T>
237  int getMaxDeltaBX() const;
238 
239  template <class T>
240  int getLctTrigEnable() const;
241 };
242 
243 
244 template<class T>
246  matches<T>& result) const
247 {
248  result.clear();
249  // Invalid ALCTs have no matching pads
250  if (not alct.isValid()) return;
251 
252  // Get the corresponding roll numbers for a given ALCT
253  std::pair<int,int> alctRoll =
255 
256  // Get the pads in the ALCT bx
257  const matchesBX<T>& lut = getPads<T>();
258 
259  // If no pads in that bx...
260  if (lut.count(alct.getBX())==0) return;
261 
262  for (const auto& p: lut.at(alct.getBX())){
263  auto padRoll(getRoll(p));
264 
265  // pad bx needs to match to ALCT bx
266  int pad_bx = getBX(p.second)+CSCConstants::LCT_CENTRAL_BX;
267  if (std::abs(alct.getBX()-pad_bx)>getMaxDeltaBX<T>()) continue;
268 
269  // gem roll number if invalid
270  if (alctRoll.first == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
271  alctRoll.second == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE) continue;
272  // ALCTs at the top of the chamber
273  else if (alctRoll.first == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
274  padRoll > alctRoll.second) continue;
275  // ALCTs at the bottom of the chamber
276  else if (alctRoll.second == CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
277  padRoll < alctRoll.first) continue;
278  // ignore pads that are too far away in roll number
279  else if ((alctRoll.first != CSCGEMMotherboard::DEFAULT_MATCHING_VALUE and
280  alctRoll.second != CSCGEMMotherboard::DEFAULT_MATCHING_VALUE) and
281  (alctRoll.first > padRoll or padRoll > alctRoll.second)) continue;
282  result.push_back(p);
283  }
284 }
285 
286 template<class T>
288  matches<T>& result) const
289 {
290  result.clear();
291  // Invalid ALCTs have no matching pads
292  if (not clct.isValid()) return;
293 
294  auto part(getCSCPart(clct.getKeyStrip()));
295  // Get the corresponding pad numbers for a given CLCT
296  const auto& mymap = (getLUT()->get_csc_hs_to_gem_pad(par, part));
297  const int lowPad(mymap[clct.getKeyStrip()].first);
298  const int highPad(mymap[clct.getKeyStrip()].second);
299 
300  // Get the pads in the CLCT bx
301  const matchesBX<T>& lut = getPads<T>();
302 
303  // If no pads in that bx...
304  if (lut.count(clct.getBX())==0) return;
305 
306  for (const auto& p: lut.at(clct.getBX())){
307 
308  // pad bx needs to match to CLCT bx
309  int pad_bx = getBX(p.second)+CSCConstants::LCT_CENTRAL_BX;
310  if (std::abs(clct.getBX()-pad_bx)>getMaxDeltaBX<T>()) continue;
311 
312  // pad number must match
313  int padNumber(getPad(p.second));
314  if (std::abs(lowPad - padNumber) <= maxDeltaPadL1_ or
315  std::abs(padNumber - highPad) <= maxDeltaPadL1_){
316  result.push_back(p);
317  }
318  }
319 }
320 
321 
322 template <class S, class T>
323 void CSCGEMMotherboard::matchingPads(const S& d1, const S& d2,
324  matches<T>& result) const
325 {
326  matches<T> p1, p2;
327 
328  // pads matching to the CLCT/ALCT
329  matchingPads<T>(d1, p1);
330 
331  // pads matching to the CLCT/ALCT
332  matchingPads<T>(d2, p2);
333 
334  // collect *all* matching pads
335  result.reserve(p1.size() + p2.size());
336  result.insert(std::end(result), std::begin(p1), std::end(p1));
337  result.insert(std::end(result), std::begin(p2), std::end(p2));
338 }
339 
340 template <class T>
342  const CSCALCTDigi& alct1,
343  matches<T>& result) const
344 {
345  matches<T> padsClct, padsAlct;
346 
347  // pads matching to the CLCT
348  matchingPads<T>(clct1, padsClct);
349 
350  // pads matching to the ALCT
351  matchingPads<T>(alct1, padsAlct);
352 
353  // collect all *common* pads
354  intersection(padsClct, padsAlct, result);
355 }
356 
357 template <class T>
359  const CSCCLCTDigi& clct2,
360  const CSCALCTDigi& alct1,
361  const CSCALCTDigi& alct2,
362  matches<T>& result) const
363 {
364  matches<T> padsClct, padsAlct;
365 
366  // pads matching to CLCTs
367  matchingPads<CSCCLCTDigi, T>(clct1, clct2, padsClct);
368 
369  // pads matching to ALCTs
370  matchingPads<CSCALCTDigi, T>(alct1, alct2, padsAlct);
371 
372  // collect *all* matching pads
373  result.reserve(padsClct.size() + padsAlct.size());
374  result.insert(std::end(result), std::begin(padsClct), std::end(padsClct));
375  result.insert(std::end(result), std::begin(padsAlct), std::end(padsAlct));
376 }
377 
378 
379 template <class S>
381  const matches<S>& pads) const
382 {
383  S result;
384  // no matching pads for invalid stub
385  if (not alct1.isValid()) return result;
386 
387  // return the first one with the same roll number
388  for (const auto& p: pads){
389 
390  // protection against corrupted DetIds
391  if (not isGEMDetId(p.first)) continue;
392 
393  // roll number of pad and ALCT must match
394  if (getRoll(p) == getRoll(alct1)){
395  return p.second;
396  }
397  }
398  return result;
399 }
400 
401 template <class S>
403  const matches<S>& pads) const
404 {
405  S result;
406  // no matching pads for invalid stub
407  if (not clct.isValid()) return result;
408 
409  auto part(getCSCPart(clct.getKeyStrip()));
410 
411  // return the pad with the smallest bending angle
412  float averagePadNumberCSC = getPad(clct, part);
413  float minDeltaPad = 999;
414  for (const auto& p: pads){
415 
416  // protection against corrupted DetIds
417  if (not isGEMDetId(p.first)) continue;
418 
419  // best pad is closest to CLCT in number of halfstrips
420  float averagePadNumberGEM = getPad(p.second);
421  if (std::abs(averagePadNumberCSC - averagePadNumberGEM) < minDeltaPad){
422  minDeltaPad = std::abs(averagePadNumberCSC - averagePadNumberGEM);
423  result = p.second;
424  }
425  }
426  return result;
427 }
428 
429 template <class S>
431  const CSCCLCTDigi& clct1,
432  const matches<S>& pads) const
433 {
434  S result;
435  // no matching pads for invalid stub
436  if (not alct1.isValid() or not clct1.isValid()) return result;
437 
438  auto part(getCSCPart(clct1.getKeyStrip()));
439 
440  // return the pad with the smallest bending angle
441  float averagePadNumberCSC = getPad(clct1, part);
442  float minDeltaPad = 999;
443  for (const auto& p: pads){
444 
445  // protection against corrupted DetIds
446  if (not isGEMDetId(p.first)) continue;
447 
448  float averagePadNumberGEM = getPad(p.second);
449  // add another safety to make sure that the deltaPad is not larger than max value!!!
450  if (std::abs(averagePadNumberCSC - averagePadNumberGEM) < minDeltaPad and
451  getRoll(p) == getRoll(alct1)){
452  minDeltaPad = std::abs(averagePadNumberCSC - averagePadNumberGEM);
453  result = p.second;
454  }
455  }
456  return result;
457 }
458 
459 template <class T>
461  T& secondLCT,
462  const GEMCoPadDigiIds& coPads,
463  CSCCorrelatedLCTDigi& lct1,
464  CSCCorrelatedLCTDigi& lct2) const
465 {
466  // Check which LCTs are valid
467  bool bestValid = bestLCT.isValid();
468  bool secondValid = secondLCT.isValid();
469 
470  // At this point, set both LCTs valid if they are invalid
471  // Duplicate LCTs are taken into account later
472  if (bestValid and !secondValid) secondLCT = bestLCT;
473  if (!bestValid and secondValid) bestLCT = secondLCT;
474 
475  // get best matching copad1
476  const GEMCoPadDigi& bestCoPad = bestMatchingPad<GEMCoPadDigi>(bestLCT, coPads);
477  const GEMCoPadDigi& secondCoPad = bestMatchingPad<GEMCoPadDigi>(secondLCT, coPads);
478 
479  correlateLCTsGEM(bestLCT, secondLCT, bestCoPad, secondCoPad, lct1, lct2);
480 }
481 
482 
483 template<class T>
485  const T& secondLCT,
486  const GEMCoPadDigi& bestCoPad,
487  const GEMCoPadDigi& secondCoPad,
488  CSCCorrelatedLCTDigi& lct1,
489  CSCCorrelatedLCTDigi& lct2) const
490 {
491  // construct the first LCT from ALCT(CLCT) and a GEM Copad
492  if ((getLctTrigEnable<T>() and bestLCT.isValid()) or
493  (match_trig_enable and bestLCT.isValid()))
494  {
495  lct1 = constructLCTsGEM(bestLCT, bestCoPad, 1);
496  }
497 
498  // construct the second LCT from ALCT(CLCT) and a GEM Copad
499  if ((getLctTrigEnable<T>() and secondLCT.isValid()) or
500  (match_trig_enable and secondLCT.isValid() and secondLCT != bestLCT))
501  {
502  lct2 = constructLCTsGEM(secondLCT, secondCoPad, 2);
503  }
504 }
505 
506 #endif
void retrieveGEMPads(const GEMPadDigiCollection *pads, unsigned id)
match< GEMCoPadDigi > GEMCoPadDigiId
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_
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
A class for AMC data.
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:72
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:63
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
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:89
const GEMGeometry * gem_g
long double T
int getMaxDeltaBX() const
int getKeyWG() const
return key wire group
Definition: CSCALCTDigi.h:57
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