CMS 3D CMS Logo

L1MuDTAssignmentUnit.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuDTAssignmentUnit
4 //
5 // Description: Assignment Unit
6 //
7 //
8 //
9 // Author :
10 // N. Neumeister CERN EP
11 // J. Troconiz UAM Madrid
12 //
13 //--------------------------------------------------
14 
15 //-----------------------
16 // This Class's Header --
17 //-----------------------
18 
20 
21 //---------------
22 // C++ Headers --
23 //---------------
24 
25 #include <iostream>
26 #include <cmath>
27 #include <cassert>
28 
29 //-------------------------------
30 // Collaborating Class Headers --
31 //-------------------------------
32 
46 
47 using namespace std;
48 
49 // --------------------------------
50 // class L1MuDTAssignmentUnit
51 //---------------------------------
52 
53 //----------------
54 // Constructors --
55 //----------------
56 
58  : m_sp(sp), m_id(id), m_addArray(), m_TSphi(), m_ptAssMethod(NODEF), nbit_phi(12), nbit_phib(10) {
59  m_TSphi.reserve(4); // a track candidate can consist of max 4 TS
60  reset();
61 
62  setPrecision();
63 }
64 
65 //--------------
66 // Destructor --
67 //--------------
68 
70 
71 //--------------
72 // Operations --
73 //--------------
74 
75 //
76 // run Assignment Unit
77 //
79  // enable track candidate
80  m_sp.track(m_id)->enable();
81  m_sp.tracK(m_id)->enable();
82 
83  // set track class
84  TrackClass tc = m_sp.TA()->trackClass(m_id);
85  m_sp.track(m_id)->setTC(tc);
86  m_sp.tracK(m_id)->setTC(tc);
87 
88  // get relative addresses of matching track segments
92 
93  // get track segments (track segment router)
94  TSR();
97 
98  // set bunch-crossing (use first track segment)
99  vector<const L1MuDTTrackSegPhi*>::const_iterator iter = m_TSphi.begin();
100  int bx = (*iter)->bx();
101  m_sp.track(m_id)->setBx(bx);
102  m_sp.tracK(m_id)->setBx(bx);
103 
104  // assign phi
105  PhiAU(c);
106 
107  // assign pt and charge
108  PtAU(c);
109 
110  // assign quality
111  QuaAU();
112 
113  // special hack for overlap region
114  // for ( iter = m_TSphi.begin(); iter != m_TSphi.end(); iter++ ) {
115  // int wheel = abs((*iter)->wheel());
116  // if ( wheel == 3 && (*iter)->etaFlag() ) m_sp.track(m_id)->disable();
117  // if ( wheel == 3 && (*iter)->etaFlag() ) m_sp.tracK(m_id)->disable();
118  // }
119 }
120 
121 //
122 // reset Assignment Unit
123 //
125  m_addArray.reset();
126  m_TSphi.clear();
128 }
129 
130 //
131 // assign phi with 8 bit precision
132 //
134  // calculate phi at station 2 using 8 bits (precision = 2.5 degrees)
135 
136  c.get<L1MuDTPhiLutRcd>().get(thePhiLUTs);
137 
138  int sh_phi = 12 - m_sp.tf().config()->getNbitsPhiPhi();
139  int sh_phib = 10 - m_sp.tf().config()->getNbitsPhiPhib();
140 
141  const L1MuDTTrackSegPhi* second = getTSphi(2); // track segment at station 2
142  const L1MuDTTrackSegPhi* first = getTSphi(1); // track segment at station 1
143  const L1MuDTTrackSegPhi* forth = getTSphi(4); // track segment at station 4
144 
145  int phi2 = 0; // phi-value at station 2
146  int sector = 0;
147 
148  if (second) {
149  phi2 = second->phi() >> sh_phi;
150  sector = second->sector();
151  } else if (second == nullptr && first) {
152  phi2 = first->phi() >> sh_phi;
153  sector = first->sector();
154  } else if (second == nullptr && forth) {
155  phi2 = forth->phi() >> sh_phi;
156  sector = forth->sector();
157  }
158 
159  int sector0 = m_sp.id().sector();
160 
161  // convert sector difference to values in the range -6 to +5
162 
163  int sectordiff = (sector - sector0) % 12;
164  if (sectordiff >= 6)
165  sectordiff -= 12;
166  if (sectordiff < -6)
167  sectordiff += 12;
168 
169  // assert( abs(sectordiff) <= 1 );
170 
171  // get sector center in 8 bit coding
172  int sector_8 = convertSector(sector0);
173 
174  // convert phi to 2.5 degree precision
175  int phi_precision = 4096 >> sh_phi;
176  const double k = 57.2958 / 2.5 / static_cast<float>(phi_precision);
177  double phi_f = static_cast<double>(phi2);
178  int phi_8 = static_cast<int>(floor(phi_f * k));
179 
180  if (second == nullptr && first) {
181  int bend_angle = (first->phib() >> sh_phib) << sh_phib;
182  phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(0, bend_angle);
183  } else if (second == nullptr && forth) {
184  int bend_angle = (forth->phib() >> sh_phib) << sh_phib;
185  phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(1, bend_angle);
186  }
187 
188  phi_8 += sectordiff * 12;
189 
190  if (phi_8 > 15)
191  phi_8 = 15;
192  if (phi_8 < -16)
193  phi_8 = -16;
194 
195  int phi = (sector_8 + phi_8 + 144) % 144;
196  phi_8 = (phi_8 + 32) % 32;
197 
198  m_sp.track(m_id)->setPhi(phi);
199  m_sp.tracK(m_id)->setPhi(phi_8);
200 }
201 
202 //
203 // assign pt with 5 bit precision
204 //
206  c.get<L1MuDTPtaLutRcd>().get(thePtaLUTs);
207 
208  // get pt-assignment method as function of track class and TS phib values
210 
211  // get input address for look-up table
212  int bend_angle = getPtAddress(m_ptAssMethod);
213  int bend_carga = getPtAddress(m_ptAssMethod, 1);
214 
215  // retrieve pt value from look-up table
216  int lut_idx = m_ptAssMethod;
217  int pt = thePtaLUTs->getPt(lut_idx, bend_angle);
218 
219  m_sp.track(m_id)->setPt(pt);
220  m_sp.tracK(m_id)->setPt(pt);
221 
222  // assign charge
223  int chsign = getCharge(m_ptAssMethod);
224  int charge = (bend_carga >= 0) ? chsign : -1 * chsign;
225  m_sp.track(m_id)->setCharge(charge);
226  m_sp.tracK(m_id)->setCharge(charge);
227 }
228 
229 //
230 // assign 3 bit quality code
231 //
233  unsigned int quality = 0;
234 
235  const TrackClass tc = m_sp.TA()->trackClass(m_id);
236 
237  switch (tc) {
238  case T1234: {
239  quality = 7;
240  break;
241  }
242  case T123: {
243  quality = 6;
244  break;
245  }
246  case T124: {
247  quality = 6;
248  break;
249  }
250  case T134: {
251  quality = 5;
252  break;
253  }
254  case T234: {
255  quality = 4;
256  break;
257  }
258  case T12: {
259  quality = 3;
260  break;
261  }
262  case T13: {
263  quality = 3;
264  break;
265  }
266  case T14: {
267  quality = 3;
268  break;
269  }
270  case T23: {
271  quality = 2;
272  break;
273  }
274  case T24: {
275  quality = 2;
276  break;
277  }
278  case T34: {
279  quality = 1;
280  break;
281  }
282  default: {
283  quality = 0;
284  break;
285  }
286  }
287 
288  m_sp.track(m_id)->setQuality(quality);
289  m_sp.tracK(m_id)->setQuality(quality);
290 }
291 
292 //
293 // Track Segment Router (TSR)
294 //
296  // get the track segments from the data buffer
297  const L1MuDTTrackSegPhi* ts = nullptr;
298  for (int stat = 1; stat <= 4; stat++) {
299  int adr = m_addArray.station(stat);
300  if (adr != 15) {
301  ts = m_sp.data()->getTSphi(stat, adr);
302  if (ts != nullptr)
303  m_TSphi.push_back(ts);
304  }
305  }
306 }
307 
308 //
309 // get track segment from a given station
310 //
312  vector<const L1MuDTTrackSegPhi*>::const_iterator iter;
313  for (iter = m_TSphi.begin(); iter != m_TSphi.end(); iter++) {
314  int stat = (*iter)->station();
315  if (station == stat) {
316  return (*iter);
317  break;
318  }
319  }
320 
321  return nullptr;
322 }
323 
324 //
325 // convert sector Id to a precision of 2.5 degrees using 8 bits (= sector center)
326 //
328  // assert( sector >=0 && sector < 12 );
329  const int sectorvalues[12] = {0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132};
330 
331  return sectorvalues[sector];
332 }
333 
334 //
335 // determine charge
336 //
338  int chargesign = 0;
339  switch (method) {
340  case PT12L: {
341  chargesign = -1;
342  break;
343  }
344  case PT12H: {
345  chargesign = -1;
346  break;
347  }
348  case PT13L: {
349  chargesign = -1;
350  break;
351  }
352  case PT13H: {
353  chargesign = -1;
354  break;
355  }
356  case PT14L: {
357  chargesign = -1;
358  break;
359  }
360  case PT14H: {
361  chargesign = -1;
362  break;
363  }
364  case PT23L: {
365  chargesign = -1;
366  break;
367  }
368  case PT23H: {
369  chargesign = -1;
370  break;
371  }
372  case PT24L: {
373  chargesign = -1;
374  break;
375  }
376  case PT24H: {
377  chargesign = -1;
378  break;
379  }
380  case PT34L: {
381  chargesign = 1;
382  break;
383  }
384  case PT34H: {
385  chargesign = 1;
386  break;
387  }
388  case PT12LO: {
389  chargesign = -1;
390  break;
391  }
392  case PT12HO: {
393  chargesign = -1;
394  break;
395  }
396  case PT13LO: {
397  chargesign = -1;
398  break;
399  }
400  case PT13HO: {
401  chargesign = -1;
402  break;
403  }
404  case PT14LO: {
405  chargesign = -1;
406  break;
407  }
408  case PT14HO: {
409  chargesign = -1;
410  break;
411  }
412  case PT23LO: {
413  chargesign = -1;
414  break;
415  }
416  case PT23HO: {
417  chargesign = -1;
418  break;
419  }
420  case PT24LO: {
421  chargesign = -1;
422  break;
423  }
424  case PT24HO: {
425  chargesign = -1;
426  break;
427  }
428  case PT34LO: {
429  chargesign = 1;
430  break;
431  }
432  case PT34HO: {
433  chargesign = 1;
434  break;
435  }
436  case PT15LO: {
437  chargesign = -1;
438  break;
439  }
440  case PT15HO: {
441  chargesign = -1;
442  break;
443  }
444  case PT25LO: {
445  chargesign = -1;
446  break;
447  }
448  case PT25HO: {
449  chargesign = -1;
450  break;
451  }
452  case NODEF: {
453  chargesign = 0;
454  // cerr << "AssignmentUnit::getCharge : undefined PtAssMethod!"
455  // << endl;
456  break;
457  }
458  }
459 
460  return chargesign;
461 }
462 
463 //
464 // determine pt-assignment method
465 //
467  // determine which pt-assignment method should be used as a function
468  // of the track class and
469  // of the phib values of the track segments making up this track candidate.
470 
471  // get bitmap of track candidate
472  const bitset<4> s = m_sp.TA()->trackBitMap(m_id);
473 
474  int method = -1;
475 
476  if (s.test(0) && s.test(3))
477  method = 2; // stations 1 and 4
478  if (s.test(0) && s.test(2))
479  method = 1; // stations 1 and 3
480  if (s.test(0) && s.test(1))
481  method = 0; // stations 1 and 2
482  if (!s.test(0) && s.test(1) && s.test(3))
483  method = 4; // stations 2 and 4
484  if (!s.test(0) && s.test(1) && s.test(2))
485  method = 3; // stations 2 and 3
486  if (!s.test(0) && !s.test(1) && s.test(2) && s.test(3))
487  method = 5; // stations 3 and 4
488 
489  if (m_sp.ovl()) {
490  int adr = m_addArray.station(3);
491  bool s5 = (adr == 15) ? false : ((adr / 2) % 2 == 1);
492  if (s.test(0) && s.test(3))
493  method = 8; // stations 1 and 4
494  if (s.test(0) && s.test(2) && s5)
495  method = 12; // stations 1 and 5
496  if (s.test(0) && s.test(2) && !s5)
497  method = 7; // stations 1 and 3
498  if (s.test(0) && s.test(1))
499  method = 6; // stations 1 and 2
500  if (!s.test(0) && s.test(1) && s.test(3))
501  method = 10; // stations 2 and 4
502  if (!s.test(0) && s.test(1) && s.test(2) && s5)
503  method = 13; // stations 2 and 5
504  if (!s.test(0) && s.test(1) && s.test(2) && !s5)
505  method = 9; // stations 2 and 3
506  if (!s.test(0) && !s.test(1) && s.test(2) && s.test(3))
507  method = 11; // stations 3 and 4
508  }
509 
510  int threshold = thePtaLUTs->getPtLutThreshold(method);
511 
512  // phib values of track segments from stations 1, 2 and 4
513  int phib1 = (getTSphi(1) != nullptr) ? getTSphi(1)->phib() : 0;
514  int phib2 = (getTSphi(2) != nullptr) ? getTSphi(2)->phib() : 0;
515  int phib4 = (getTSphi(4) != nullptr) ? getTSphi(4)->phib() : 0;
516 
517  PtAssMethod pam = NODEF;
518 
519  switch (method) {
520  case 0: {
521  pam = (abs(phib1) < threshold) ? PT12H : PT12L;
522  break;
523  }
524  case 1: {
525  pam = (abs(phib1) < threshold) ? PT13H : PT13L;
526  break;
527  }
528  case 2: {
529  pam = (abs(phib1) < threshold) ? PT14H : PT14L;
530  break;
531  }
532  case 3: {
533  pam = (abs(phib2) < threshold) ? PT23H : PT23L;
534  break;
535  }
536  case 4: {
537  pam = (abs(phib2) < threshold) ? PT24H : PT24L;
538  break;
539  }
540  case 5: {
541  pam = (abs(phib4) < threshold) ? PT34H : PT34L;
542  break;
543  }
544  case 6: {
545  pam = (abs(phib1) < threshold) ? PT12HO : PT12LO;
546  break;
547  }
548  case 7: {
549  pam = (abs(phib1) < threshold) ? PT13HO : PT13LO;
550  break;
551  }
552  case 8: {
553  pam = (abs(phib1) < threshold) ? PT14HO : PT14LO;
554  break;
555  }
556  case 9: {
557  pam = (abs(phib2) < threshold) ? PT23HO : PT23LO;
558  break;
559  }
560  case 10: {
561  pam = (abs(phib2) < threshold) ? PT24HO : PT24LO;
562  break;
563  }
564  case 11: {
565  pam = (abs(phib4) < threshold) ? PT34HO : PT34LO;
566  break;
567  }
568  case 12: {
569  pam = (abs(phib1) < threshold) ? PT15HO : PT15LO;
570  break;
571  }
572  case 13: {
573  pam = (abs(phib2) < threshold) ? PT25HO : PT25LO;
574  break;
575  }
576  default:;
577  //cout << "L1MuDTAssignmentUnit : Error in PT ass method evaluation" << endl;
578  }
579 
580  return pam;
581 }
582 
583 //
584 // calculate bend angle
585 //
587  // calculate bend angle as difference of two azimuthal positions
588 
589  int bendangle = 0;
590  switch (method) {
591  case PT12L: {
592  bendangle = phiDiff(1, 2);
593  break;
594  }
595  case PT12H: {
596  bendangle = phiDiff(1, 2);
597  break;
598  }
599  case PT13L: {
600  bendangle = phiDiff(1, 3);
601  break;
602  }
603  case PT13H: {
604  bendangle = phiDiff(1, 3);
605  break;
606  }
607  case PT14L: {
608  bendangle = phiDiff(1, 4);
609  break;
610  }
611  case PT14H: {
612  bendangle = phiDiff(1, 4);
613  break;
614  }
615  case PT23L: {
616  bendangle = phiDiff(2, 3);
617  break;
618  }
619  case PT23H: {
620  bendangle = phiDiff(2, 3);
621  break;
622  }
623  case PT24L: {
624  bendangle = phiDiff(2, 4);
625  break;
626  }
627  case PT24H: {
628  bendangle = phiDiff(2, 4);
629  break;
630  }
631  case PT34L: {
632  bendangle = phiDiff(4, 3);
633  break;
634  }
635  case PT34H: {
636  bendangle = phiDiff(4, 3);
637  break;
638  }
639  case PT12LO: {
640  bendangle = phiDiff(1, 2);
641  break;
642  }
643  case PT12HO: {
644  bendangle = phiDiff(1, 2);
645  break;
646  }
647  case PT13LO: {
648  bendangle = phiDiff(1, 3);
649  break;
650  }
651  case PT13HO: {
652  bendangle = phiDiff(1, 3);
653  break;
654  }
655  case PT14LO: {
656  bendangle = phiDiff(1, 4);
657  break;
658  }
659  case PT14HO: {
660  bendangle = phiDiff(1, 4);
661  break;
662  }
663  case PT23LO: {
664  bendangle = phiDiff(2, 3);
665  break;
666  }
667  case PT23HO: {
668  bendangle = phiDiff(2, 3);
669  break;
670  }
671  case PT24LO: {
672  bendangle = phiDiff(2, 4);
673  break;
674  }
675  case PT24HO: {
676  bendangle = phiDiff(2, 4);
677  break;
678  }
679  case PT34LO: {
680  bendangle = phiDiff(4, 3);
681  break;
682  }
683  case PT34HO: {
684  bendangle = phiDiff(4, 3);
685  break;
686  }
687  case PT15LO: {
688  bendangle = phiDiff(1, 3);
689  break;
690  }
691  case PT15HO: {
692  bendangle = phiDiff(1, 3);
693  break;
694  }
695  case PT25LO: {
696  bendangle = phiDiff(2, 3);
697  break;
698  }
699  case PT25HO: {
700  bendangle = phiDiff(2, 3);
701  break;
702  }
703  case NODEF: {
704  bendangle = 0;
705  // cerr << "AssignmentUnit::getPtAddress : undefined PtAssMethod" << endl;
706  break;
707  }
708  }
709 
710  int signo = 1;
711  bendangle = (bendangle + 8192) % 4096;
712  if (bendangle > 2047)
713  bendangle -= 4096;
714  if (bendangle < 0)
715  signo = -1;
716 
717  if (bendcharge)
718  return signo;
719 
720  bendangle = (bendangle + 2048) % 1024;
721  if (bendangle > 511)
722  bendangle -= 1024;
723 
724  return bendangle;
725 }
726 
727 //
728 // build difference of two phi values
729 //
730 int L1MuDTAssignmentUnit::phiDiff(int stat1, int stat2) const {
731  // calculate bit shift
732 
733  int sh_phi = 12 - nbit_phi;
734 
735  // get 2 phi values and add offset (30 degrees ) for adjacent sector
736  int sector1 = getTSphi(stat1)->sector();
737  int sector2 = getTSphi(stat2)->sector();
738  int phi1 = getTSphi(stat1)->phi() >> sh_phi;
739  int phi2 = getTSphi(stat2)->phi() >> sh_phi;
740 
741  // convert sector difference to values in the range -6 to +5
742 
743  int sectordiff = (sector2 - sector1) % 12;
744  if (sectordiff >= 6)
745  sectordiff -= 12;
746  if (sectordiff < -6)
747  sectordiff += 12;
748 
749  // assert( abs(sectordiff) <= 1 );
750 
751  int offset = (2144 >> sh_phi) * sectordiff;
752  int bendangle = (phi2 - phi1 + offset) << sh_phi;
753 
754  return bendangle;
755 }
756 
757 //
758 // set precision for pt-assignment of phi and phib
759 // default is 12 bits for phi and 10 bits for phib
760 //
764 }
765 
766 // static data members
void PtAU(const edm::EventSetup &c)
assign pt and charge
int getPt(int pta_ind, int address) const
get pt-value for a given address
void setPt(int pt)
set pt-code of muon candidate
Definition: L1MuDTTrack.h:146
L1MuDTTrack * tracK(int id) const
return pointer to muon candidate, index [0,1]
void QuaAU()
assign quality
unsigned short nbit_phib
of bits used for pt-assignment
void reset()
reset address array
int getNbitsPtaPhib() const
~L1MuDTAssignmentUnit() override
destructor
void setTSphi(const std::vector< const L1MuDTTrackSegPhi * > &tsList)
set phi track segments used to form the muon candidate
Definition: L1MuDTTrack.cc:145
int getCharge(PtAssMethod)
determine charge
int phi() const
return phi
void setTC(TrackClass tc)
set track-class of muon candidate
Definition: L1MuDTTrack.h:134
L1MuDTAddressArray m_addArray
void setAddresses(const L1MuDTAddressArray &addr)
set relative addresses of muon candidate
Definition: L1MuDTTrack.h:158
void enable()
enable muon candidate
Definition: L1MuDTTrack.h:122
int sector() const
return sector number
const L1MuDTDataBuffer * data() const
return pointer to Data Buffer
edm::ESHandle< L1MuDTPtaLut > thePtaLUTs
pt-assignment look-up tables
U second(std::pair< T, U > const &p)
L1MuDTSectorProcessor & m_sp
void setBx(int bx)
Set Bunch Crossing.
std::vector< const L1MuDTTrackSegPhi * > m_TSphi
unsigned short nbit_phi
of bits used for pt-assignment
int getDeltaPhi(int idx, int address) const
get delta-phi for a given address (bend-angle)
const L1MuDTTrackAssembler * TA() const
return pointer to Track Assembler
void TSR()
Track Segment Router.
const L1MuDTTrackSegPhi * getTSphi(int station) const
get track segment from a given station
virtual void run()
run processor logic
const std::bitset< 4 > & trackBitMap(int id) const
return bitmap of found track
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int phib() const
return phib
int phiDiff(int stat1, int stat2) const
build difference of two phi values
const L1MuDTSecProcId & id() const
return Sector Processor identifier
void setQuality(unsigned int quality)
set quality of muon candidate
Definition: L1MuDTTrack.h:155
int getNbitsPtaPhi() const
const TSPhivector & getTSphi() const
get all track segments from the buffer
void reset() override
reset Assignment Unit
int convertSector(int)
convert sector Id to 8 bit code (= sector center)
void PhiAU(const edm::EventSetup &c)
assign phi
void setPrecision()
set precision of phi and phib
static L1MuDTTFConfig * config()
return configuration
int getPtAddress(PtAssMethod, int bendcharge=0) const
calculate bend angle
T get() const
Definition: EventSetup.h:73
const L1MuDTTrackFinder & tf() const
return reference to barrel MTTF
int sector() const
return sector
edm::ESHandle< L1MuDTPhiLut > thePhiLUTs
phi-assignment look-up tables
int getPtLutThreshold(int pta_ind) const
get pt-assignment LUT threshold
TrackClass trackClass(int id) const
return Track Class of found track
PtAssMethod getPtMethod() const
determine pt assignment method
L1MuDTTrack * track(int id) const
return pointer to muon candidate, index [0,1]
int address(int id, int stat) const
get address of a single station of selected track candidate
unsigned short station(int stat) const
get address of a given station [1-4]
int getNbitsPhiPhi() const
L1MuDTAssignmentUnit(L1MuDTSectorProcessor &sp, int id)
constructor
void setPhi(int phi)
set phi-code of muon candidate
Definition: L1MuDTTrack.h:137
bool ovl() const
is it an overlap region Sector Processor?
int getNbitsPhiPhib() const
PtAssMethod
void setCharge(int charge)
set charge of muon candidate
Definition: L1MuDTTrack.h:149