CMS 3D CMS Logo

L1MuBMAssignmentUnit.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuBMAssignmentUnit
4 //
5 // Description: Assignment Unit
6 //
7 //
8 //
9 // Author :
10 // N. Neumeister CERN EP
11 // J. Troconiz UAM Madrid
12 // Modifications:
13 // G. Flouris U. Ioannina
14 // G Karathanasis U. Athens
15 //--------------------------------------------------
16 
17 //-----------------------
18 // This Class's Header --
19 //-----------------------
20 
22 
23 //---------------
24 // C++ Headers --
25 //---------------
26 
27 #include <iostream>
28 #include <cmath>
29 #include <cassert>
30 
31 //-------------------------------
32 // Collaborating Class Headers --
33 //-------------------------------
34 
43 
44 #include <iostream>
45 #include <iomanip>
46 
47 using namespace std;
48 // --------------------------------
49 // class L1MuBMAssignmentUnit
50 //---------------------------------
51 
52 //----------------
53 // Constructors --
54 //----------------
55 
57  : m_sp(sp), m_id(id), m_addArray(), m_TSphi(), m_ptAssMethod(L1MuBMLUTHandler::NODEF) {
58  m_TSphi.reserve(4); // a track candidate can consist of max 4 TS
59  reset();
60  setPrecision();
61 }
62 
63 //--------------
64 // Destructor --
65 //--------------
66 
68 
69 //--------------
70 // Operations --
71 //--------------
72 
73 //
74 // run Assignment Unit
75 //
77  // enable track candidate
78  m_sp.track(m_id)->enable();
79  m_sp.tracK(m_id)->enable();
80 
81  // set track class
82  TrackClass tc = m_sp.TA()->trackClass(m_id);
83  m_sp.track(m_id)->setTC(tc);
84  m_sp.tracK(m_id)->setTC(tc);
85 
86  // get relative addresses of matching track segments
90 
91  // get track segments (track segment router)
92  TSR();
95 
96  // set bunch-crossing (use first track segment)
97  vector<const L1MuBMTrackSegPhi*>::const_iterator iter = m_TSphi.begin();
98  int bx = (*iter)->bx();
99  m_sp.track(m_id)->setBx(bx);
100  m_sp.tracK(m_id)->setBx(bx);
101 
102  // assign phi
103  PhiAU(bmtfParams);
104 
105  // assign pt and charge
106  PtAU(bmtfParams);
107 
108  // assign quality
109  QuaAU();
110 }
111 
112 //
113 // reset Assignment Unit
114 //
116  m_addArray.reset();
117  m_TSphi.clear();
119 }
120 
121 //
122 // assign phi with 8 bit precision
123 //
125  thePhiLUTs = new L1MuBMLUTHandler(bmtfParams);
126  //thePhiLUTs->print();
127  // calculate phi at station 2 using 8 bits (precision = 0.625 degrees)
128  int sh_phi = 12 - L1MuBMTFConfig::getNbitsPhiPhi();
129  int sh_phib = 10 - L1MuBMTFConfig::getNbitsPhiPhib();
130 
131  const L1MuBMTrackSegPhi* second = getTSphi(2); // track segment at station 2
132  const L1MuBMTrackSegPhi* first = getTSphi(1); // track segment at station 1
133  const L1MuBMTrackSegPhi* forth = getTSphi(4); // track segment at station 4
134 
135  int phi2 = 0; // phi-value at station 2
136  int sector = 0;
137  if (second) {
138  phi2 = second->phi() >> sh_phi;
139  sector = second->sector();
140  } else if (second == nullptr && first) {
141  phi2 = first->phi() >> sh_phi;
142  sector = first->sector();
143  } else if (second == nullptr && forth) {
144  phi2 = forth->phi() >> sh_phi;
145  sector = forth->sector();
146  }
147 
148  int sector0 = m_sp.id().sector();
149 
150  // convert sector difference to values in the range -6 to +5
151 
152  int sectordiff = (sector - sector0) % 12;
153  if (sectordiff >= 6)
154  sectordiff -= 12;
155  if (sectordiff < -6)
156  sectordiff += 12;
157 
158  // convert phi to 0.625 degree precision
159  int phi_precision = 4096 >> sh_phi;
160  const double k = 57.2958 / 0.625 / static_cast<float>(phi_precision);
161  double phi_f = static_cast<double>(phi2);
162  int bit_div_phi = static_cast<int>(phi2) % 4;
163  if (bit_div_phi < 0)
164  bit_div_phi += 4;
165  phi_f = phi_f - std::abs(bit_div_phi);
166  int phi_8 = static_cast<int>(floor(phi_f * k));
167 
168  if (second == nullptr && first) {
169  int bend_angle = l1t::bitShift((first->phib() >> sh_phib), sh_phib);
170  phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(0, bend_angle);
171  //phi_8 = phi_8 + getDeltaPhi(0, bend_angle, bmtfParams->phi_lut());
172  } else if (second == nullptr && forth) {
173  int bend_angle = l1t::bitShift((forth->phib() >> sh_phib), sh_phib);
174  phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(1, bend_angle);
175  //phi_8 = phi_8 + getDeltaPhi(1, bend_angle, bmtfParams->phi_lut());
176  }
177 
178  //If muon is found at the neighbour sector - second station
179  //a shift is needed by 48
180  phi_8 += sectordiff * 48;
181 
182  int phi = phi_8 + 24;
183  // 78 phi bins (-8 to 69) correspond 30 degree sector plus
184  // additional lower and higher bins for neighboring sectors.
185  if (phi > 69)
186  phi = 69;
187  if (phi < -8)
188  phi = -8;
189 
190  m_sp.track(m_id)->setPhi(phi); // Regional
191  m_sp.tracK(m_id)->setPhi(phi);
192 
193  delete thePhiLUTs;
194 }
195 
196 //
197 // assign pt with 5 bit precision
198 //
200  const L1TMuonBarrelParamsAllPublic bmtfParams(bmtfParams1);
201  thePtaLUTs = new L1MuBMLUTHandler(bmtfParams);
202  //thePtaLUTs->print();
203  // get pt-assignment method as function of track class and TS phib values
204  //m_ptAssMethod = getPtMethod(bmtfParams);
206  // get input address for look-up table
207  int bend_angle = getPtAddress(m_ptAssMethod);
208  int bend_carga = getPtAddress(m_ptAssMethod, 1);
209 
210  // retrieve pt value from look-up table
211  int lut_idx = m_ptAssMethod;
212  int pt = thePtaLUTs->getPt(lut_idx, bend_angle);
213  //int pt = getPt(lut_idx, bend_angle, bmtfParams->pta_lut());
214 
215  if (!bmtfParams.get_DisableNewAlgo()) {
216  if (Quality() < 4) {
217  int ptj = pt;
220  if (jj1 != L1MuBMLUTHandler::NODEF) {
221  lut_idx = jj1;
222  bend_angle = getPt1Address(m_ptAssMethod);
223  if (abs(bend_angle) < 512)
224  ptj = thePtaLUTs->getPt(lut_idx, bend_angle);
225  } else if (jj2 != L1MuBMLUTHandler::NODEF) {
226  lut_idx = jj2;
227  bend_angle = getPt2Address(m_ptAssMethod);
228  if (abs(bend_angle) < 512)
229  ptj = thePtaLUTs->getPt(lut_idx, bend_angle);
230  }
231  if (ptj < pt)
232  pt = ptj;
233  }
234  }
235 
236  m_sp.track(m_id)->setPt(pt);
237  m_sp.tracK(m_id)->setPt(pt);
238 
239  // assign charge
240  int chsign = getCharge(m_ptAssMethod);
241  int charge = (bend_carga >= 0) ? chsign : -1 * chsign;
244  delete thePtaLUTs;
245 }
246 
247 //
248 // assign 4 bit quality code
249 //
251  unsigned int quality = 0;
252 
253  const TrackClass tc = m_sp.TA()->trackClass(m_id);
254 
256  switch (tc) {
257  case T1234: {
258  quality = 3;
259  break;
260  }
261  case T123: {
262  quality = 2;
263  break;
264  }
265  case T124: {
266  quality = 2;
267  break;
268  }
269  case T134: {
270  quality = 2;
271  break;
272  }
273  case T234: {
274  quality = 2;
275  break;
276  }
277  case T12: {
278  quality = 1;
279  break;
280  }
281  case T13: {
282  quality = 1;
283  break;
284  }
285  case T14: {
286  quality = 1;
287  break;
288  }
289  case T23: {
290  quality = 0;
291  break;
292  }
293  case T24: {
294  quality = 0;
295  break;
296  }
297  case T34: {
298  quality = 0;
299  break;
300  }
301  default: {
302  quality = 0;
303  break;
304  }
305  }
306 
308  quality += 12;
309 
312 }
313 
314 //
315 // assign 3 bit quality code
316 //
318  unsigned int quality = 0;
319 
320  const TrackClass tc = m_sp.TA()->trackClass(m_id);
321 
322  switch (tc) {
323  case T1234: {
324  quality = 7;
325  break;
326  }
327  case T123: {
328  quality = 6;
329  break;
330  }
331  case T124: {
332  quality = 6;
333  break;
334  }
335  case T134: {
336  quality = 5;
337  break;
338  }
339  case T234: {
340  quality = 4;
341  break;
342  }
343  case T12: {
344  quality = 3;
345  break;
346  }
347  case T13: {
348  quality = 3;
349  break;
350  }
351  case T14: {
352  quality = 3;
353  break;
354  }
355  case T23: {
356  quality = 2;
357  break;
358  }
359  case T24: {
360  quality = 2;
361  break;
362  }
363  case T34: {
364  quality = 1;
365  break;
366  }
367  default: {
368  quality = 0;
369  }
370  }
371 
372  return quality;
373 }
374 
375 //
376 // Track Segment Router (TSR)
377 //
379  // get the track segments from the data buffer
380  const L1MuBMTrackSegPhi* ts = nullptr;
381  for (int stat = 1; stat <= 4; stat++) {
382  int adr = m_addArray.station(stat);
383  if (adr != 15) {
384  ts = m_sp.data()->getTSphi(stat, adr);
385  if (ts != nullptr)
386  m_TSphi.push_back(ts);
387  }
388  }
389 }
390 
391 //
392 // get track segment from a given station
393 //
395  vector<const L1MuBMTrackSegPhi*>::const_iterator iter;
396  for (iter = m_TSphi.begin(); iter != m_TSphi.end(); iter++) {
397  int stat = (*iter)->station();
398  if (station == stat) {
399  return (*iter);
400  break;
401  }
402  }
403 
404  return nullptr;
405 }
406 
407 //
408 // convert sector Id to a precision of 2.5 degrees using 8 bits (= sector center)
409 //
411  // assert( sector >=0 && sector < 12 );
412  const int sectorvalues[12] = {0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132};
413 
414  return sectorvalues[sector];
415 }
416 
417 //
418 // determine charge
419 //
421  int chargesign = 0;
422  switch (method) {
424  chargesign = -1;
425  break;
426  }
428  chargesign = -1;
429  break;
430  }
432  chargesign = -1;
433  break;
434  }
436  chargesign = -1;
437  break;
438  }
440  chargesign = -1;
441  break;
442  }
444  chargesign = -1;
445  break;
446  }
448  chargesign = -1;
449  break;
450  }
452  chargesign = -1;
453  break;
454  }
456  chargesign = -1;
457  break;
458  }
460  chargesign = -1;
461  break;
462  }
464  chargesign = 1;
465  break;
466  }
468  chargesign = 1;
469  break;
470  }
471 
473  chargesign = 0;
474  // cerr << "AssignmentUnit::getCharge : undefined PtAssMethod!"
475  // << endl;
476  break;
477  }
478  default: {
479  chargesign = 0;
480  }
481  }
482 
483  return chargesign;
484 }
485 
486 //
487 // determine pt-assignment method
488 //
489 //PtAssMethod L1MuBMAssignmentUnit::getPtMethod(L1TMuonBarrelParams *l1tbmparams) const {
491  // determine which pt-assignment method should be used as a function
492  // of the track class and
493  // of the phib values of the track segments making up this track candidate.
494 
495  // get bitmap of track candidate
496  const bitset<4> s = m_sp.TA()->trackBitMap(m_id);
497 
498  int method = -1;
499 
500  if (s.test(0) && s.test(3))
501  method = 2; // stations 1 and 4
502  if (s.test(0) && s.test(2))
503  method = 1; // stations 1 and 3
504  if (s.test(0) && s.test(1))
505  method = 0; // stations 1 and 2
506  if (!s.test(0) && s.test(1) && s.test(3))
507  method = 4; // stations 2 and 4
508  if (!s.test(0) && s.test(1) && s.test(2))
509  method = 3; // stations 2 and 3
510  if (!s.test(0) && !s.test(1) && s.test(2) && s.test(3))
511  method = 5; // stations 3 and 4
513 
514  // phib values of track segments from stations 1, 2 and 4
515  int phib1 = (getTSphi(1) != nullptr) ? getTSphi(1)->phib() : 0;
516  int phib2 = (getTSphi(2) != nullptr) ? getTSphi(2)->phib() : 0;
517  int phib4 = (getTSphi(4) != nullptr) ? getTSphi(4)->phib() : 0;
518 
520 
521  switch (method) {
522  case 0: {
524  break;
525  }
526  case 1: {
528  break;
529  }
530  case 2: {
532  break;
533  }
534  case 3: {
536  break;
537  }
538  case 4: {
540  break;
541  }
542  case 5: {
544  break;
545  }
546  default:;
547  //cout << "L1MuBMAssignmentUnit : Error in PT ass method evaluation" << endl;
548  }
549 
550  return pam;
551 }
552 
553 //
554 // calculate bend angle
555 //
557  // calculate bend angle as difference of two azimuthal positions
558 
559  int bendangle = 0;
560  switch (method) {
562  bendangle = phiDiff(1, 2);
563  break;
564  }
566  bendangle = phiDiff(1, 2);
567  break;
568  }
570  bendangle = phiDiff(1, 3);
571  break;
572  }
574  bendangle = phiDiff(1, 3);
575  break;
576  }
578  bendangle = phiDiff(1, 4);
579  break;
580  }
582  bendangle = phiDiff(1, 4);
583  break;
584  }
586  bendangle = phiDiff(2, 3);
587  break;
588  }
590  bendangle = phiDiff(2, 3);
591  break;
592  }
594  bendangle = phiDiff(2, 4);
595  break;
596  }
598  bendangle = phiDiff(2, 4);
599  break;
600  }
602  bendangle = phiDiff(4, 3);
603  break;
604  }
606  bendangle = phiDiff(4, 3);
607  break;
608  }
610  bendangle = 0;
611  // cerr << "AssignmentUnit::getPtAddress : undefined PtAssMethod" << endl;
612  break;
613  }
614  default: {
615  bendangle = 0;
616  }
617  }
618 
619  int signo = 1;
620  bendangle = (bendangle + 8192) % 4096;
621  if (bendangle > 2047)
622  bendangle -= 4096;
623  if (bendangle < 0)
624  signo = -1;
625 
626  if (bendcharge)
627  return signo;
628 
629  bendangle = (bendangle + 2048) % 1024;
630  if (bendangle > 511)
631  bendangle -= 1024;
632 
633  return bendangle;
634 }
635 
636 //
637 // build difference of two phi values
638 //
639 int L1MuBMAssignmentUnit::phiDiff(int stat1, int stat2) const {
640  // calculate bit shift
641 
642  int sh_phi = 12 - nbit_phi;
643 
644  // get 2 phi values and add offset (30 degrees ) for adjacent sector
645  int sector1 = getTSphi(stat1)->sector();
646  int sector2 = getTSphi(stat2)->sector();
647  int phi1 = getTSphi(stat1)->phi() >> sh_phi;
648  int phi2 = getTSphi(stat2)->phi() >> sh_phi;
649 
650  // convert sector difference to values in the range -6 to +5
651 
652  int sectordiff = (sector2 - sector1) % 12;
653  if (sectordiff >= 6)
654  sectordiff -= 12;
655  if (sectordiff < -6)
656  sectordiff += 12;
657 
658  // assert( abs(sectordiff) <= 1 );
659 
660  int offset = (2144 >> sh_phi) * sectordiff;
661  int bendangle = l1t::bitShift((phi2 - phi1 + offset), sh_phi);
662 
663  return bendangle;
664 }
665 
666 //
667 // determine pt-assignment method
668 //
670  // quality values of track segments from stations 1, 2 and 4
671  int qual1 = (getTSphi(1) != nullptr) ? getTSphi(1)->quality() : 0;
672  int qual2 = (getTSphi(2) != nullptr) ? getTSphi(2)->quality() : 0;
673  int qual4 = (getTSphi(4) != nullptr) ? getTSphi(4)->quality() : 0;
674 
676 
677  switch (method) {
679  if (qual1 > 3)
681  break;
682  }
684  if (qual1 > 3)
686  break;
687  }
689  if (qual1 > 3)
691  break;
692  }
694  if (qual2 > 3)
696  break;
697  }
699  if (qual2 > 3)
701  break;
702  }
704  if (qual4 > 3)
706  break;
707  }
710  break;
711  }
712  default: {
714  }
715  }
716 
717  return pam;
718 }
719 
720 //
721 // determine pt-assignment method
722 //
724  // quality values of track segments from stations 2 and 4
725  int qual2 = (getTSphi(2) != nullptr) ? getTSphi(2)->quality() : 0;
726  // int qual4 = ( getTSphi(4) != 0 ) ? getTSphi(4)->quality() : 0;
727 
729 
730  switch (method) {
732  if (qual2 > 3)
734  break;
735  }
736  // case PT14H : { if (qual4 > 3) pam = PB34H; break; }
737  // case PT24H : { if (qual4 > 3) pam = PB34H; break; }
738  //case PT12HO : { if (qual2 > 3) pam = PB21HO; break; }
739  // case PT14HO : { if (qual4 > 3) pam = PB34HO; break; }
740  // case PT24HO : { if (qual4 > 3) pam = PB34HO; break; }
743  break;
744  }
745  default: {
747  }
748  }
749 
750  return pam;
751 }
752 
753 //
754 // calculate bend angle
755 //
757  // phib values of track segments from stations 1, 2 and 4
758  int phib1 = (getTSphi(1) != nullptr) ? getTSphi(1)->phib() : -999;
759  int phib2 = (getTSphi(2) != nullptr) ? getTSphi(2)->phib() : -999;
760  int phib4 = (getTSphi(4) != nullptr) ? getTSphi(4)->phib() : -999;
761 
762  int bendangle = -999;
763  switch (method) {
765  bendangle = phib1;
766  break;
767  }
769  bendangle = phib1;
770  break;
771  }
773  bendangle = phib1;
774  break;
775  }
777  bendangle = phib2;
778  break;
779  }
781  bendangle = phib2;
782  break;
783  }
785  bendangle = phib4;
786  break;
787  }
789  bendangle = -999;
790  break;
791  }
792  default: {
793  bendangle = -999;
794  }
795  }
796 
797  return bendangle;
798 }
799 
800 //
801 // calculate bend angle
802 //
804  // phib values of track segments from stations 1, 2 and 4
805  int phib2 = (getTSphi(2) != nullptr) ? getTSphi(2)->phib() : -999;
806  int phib4 = (getTSphi(4) != nullptr) ? getTSphi(4)->phib() : -999;
807 
808  int bendangle = -999;
809  switch (method) {
811  bendangle = phib2;
812  break;
813  }
815  bendangle = phib4;
816  break;
817  }
819  bendangle = phib4;
820  break;
821  }
822  //case L1MuBMLUTHandler::PT12HO : { bendangle = phib2; break; }
823  //case L1MuBMLUTHandler::PT14HO : { bendangle = phib4; break; }
824  //case L1MuBMLUTHandler::PT24HO : { bendangle = phib4; break; }
826  bendangle = -999;
827  break;
828  }
829  default: {
830  bendangle = -999;
831  }
832  }
833 
834  return bendangle;
835 }
836 
837 //
838 // set precision for pt-assignment of phi and phib
839 // default is 12 bits for phi and 10 bits for phib
840 //
844 }
845 
846 // static data members
847 
848 unsigned short int L1MuBMAssignmentUnit::nbit_phi = 12;
849 unsigned short int L1MuBMAssignmentUnit::nbit_phib = 10;
const L1MuBMSecProcId & id() const
return Sector Processor identifier
void setTC(TrackClass tc)
set track-class of muon candidate
Definition: L1MuBMTrack.h:142
static int getNbitsPhiPhi()
void setPt(int pt)
set pt-code of muon candidate
Definition: L1MuBMTrack.h:154
static int getNbitsPhiPhib()
L1MuBMAssignmentUnit(L1MuBMSectorProcessor &sp, int id)
constructor
L1MuBMTrack * track(int id) const
return pointer to muon candidate, index [0,1]
void QuaAU()
assign quality
int address(int id, int stat) const
get address of a single station of selected track candidate
void setQuality(unsigned int quality)
set quality of muon candidate
Definition: L1MuBMTrack.h:163
void setPhi(int phi)
set phi-code of muon candidate
Definition: L1MuBMTrack.h:145
void setAddresses(const L1MuBMAddressArray &addr)
set relative addresses of muon candidate
Definition: L1MuBMTrack.h:166
const L1MuBMTrackSegPhi * getTSphi(int station) const
get track segment from a given station
static int getNbitsPtaPhi()
void setCharge(int charge)
set charge of muon candidate
Definition: L1MuBMTrack.h:157
L1MuBMLUTHandler * thePtaLUTs
pt-assignment look-up tables
void TSR()
Track Segment Router.
void enable()
enable muon candidate
Definition: L1MuBMTrack.h:130
std::vector< const L1MuBMTrackSegPhi * > m_TSphi
U second(std::pair< T, U > const &p)
string quality
static int getNbitsPtaPhib()
int getPt2Address(L1MuBMLUTHandler::PtAssMethod) const
static int convertSector(int)
convert sector Id to 8 bit code (= sector center)
L1MuBMLUTHandler * thePhiLUTs
phi-assignment look-up tables
const L1MuBMDataBuffer * data() const
return pointer to Data Buffer
static unsigned short nbit_phib
of bits used for pt-assignment
static void setPrecision()
set precision of phi and phib
int quality() const
return quality code
L1MuBMLUTHandler::PtAssMethod getPtMethod() const
determine pt assignment method
~L1MuBMAssignmentUnit()
destructor
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1MuBMLUTHandler::PtAssMethod getPt2Method(L1MuBMLUTHandler::PtAssMethod) const
const L1MuBMTrackAssembler * TA() const
return pointer to Track Assembler
void setTSphi(const std::vector< const L1MuBMTrackSegPhi *> &tsList)
set phi track segments used to form the muon candidate
Definition: L1MuBMTrack.cc:147
void setBx(int bx)
set charge of muon candidate
Definition: L1MuBMTrack.h:160
int phib() const
return phib
const std::bitset< 4 > & trackBitMap(int id) const
return bitmap of found track
unsigned short station(int stat) const
get address of a given station [1-4]
int getPt(int pta_ind, int address) const
get pt-value for a given address
int getPt1Address(L1MuBMLUTHandler::PtAssMethod) const
const TSPhivector & getTSphi() const
get all track segments from the buffer
int phiDiff(int stat1, int stat2) const
build difference of two phi values
void PtAU(const L1TMuonBarrelParams &)
assign pt and charge
void PhiAU(const L1TMuonBarrelParams &)
assign phi
int sector() const
return sector number
int getPtLutThreshold(int pta_ind) const
get pt-assignment LUT threshold
void run(const L1TMuonBarrelParams &mbtfParams)
run Assignment Unit
L1MuBMTrack * tracK(int id) const
return pointer to muon candidate, index [0,1]
L1MuBMLUTHandler::PtAssMethod getPt1Method(L1MuBMLUTHandler::PtAssMethod) const
L1MuBMAddressArray m_addArray
int getDeltaPhi(int idx, int address) const
get delta-phi for a given address (bend-angle)
void reset()
reset Assignment Unit
static int getCharge(L1MuBMLUTHandler::PtAssMethod)
determine charge
void reset()
reset address array
int sector() const
return sector
int phi() const
return phi
int getPtAddress(L1MuBMLUTHandler::PtAssMethod, int bendcharge=0) const
calculate bend angle
L1MuBMSectorProcessor & m_sp
TrackClass trackClass(int id) const
return Track Class of found track
static unsigned short nbit_phi
of bits used for pt-assignment
L1MuBMLUTHandler::PtAssMethod m_ptAssMethod
int bitShift(int num, int bits)
Definition: BitShift.h:6