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 
42 
43 #include <iostream>
44 #include <iomanip>
45 
46 using namespace std;
47 // --------------------------------
48 // class L1MuBMAssignmentUnit
49 //---------------------------------
50 
51 //----------------
52 // Constructors --
53 //----------------
54 
56  : m_sp(sp), m_id(id), m_addArray(), m_TSphi(), m_ptAssMethod(L1MuBMLUTHandler::NODEF) {
57  m_TSphi.reserve(4); // a track candidate can consist of max 4 TS
58  reset();
59  setPrecision();
60 }
61 
62 //--------------
63 // Destructor --
64 //--------------
65 
67 
68 //--------------
69 // Operations --
70 //--------------
71 
72 //
73 // run Assignment Unit
74 //
76  // enable track candidate
77  m_sp.track(m_id)->enable();
78  m_sp.tracK(m_id)->enable();
79 
80  // set track class
81  TrackClass tc = m_sp.TA()->trackClass(m_id);
82  m_sp.track(m_id)->setTC(tc);
83  m_sp.tracK(m_id)->setTC(tc);
84 
85  // get relative addresses of matching track segments
89 
90  // get track segments (track segment router)
91  TSR();
94 
95  // set bunch-crossing (use first track segment)
96  vector<const L1MuBMTrackSegPhi*>::const_iterator iter = m_TSphi.begin();
97  int bx = (*iter)->bx();
98  m_sp.track(m_id)->setBx(bx);
99  m_sp.tracK(m_id)->setBx(bx);
100 
101  // assign phi
102  PhiAU(bmtfParams);
103 
104  // assign pt and charge
105  PtAU(bmtfParams);
106 
107  // assign quality
108  QuaAU();
109 }
110 
111 //
112 // reset Assignment Unit
113 //
115  m_addArray.reset();
116  m_TSphi.clear();
118 }
119 
120 //
121 // assign phi with 8 bit precision
122 //
124  thePhiLUTs = new L1MuBMLUTHandler(bmtfParams);
125  //thePhiLUTs->print();
126  // calculate phi at station 2 using 8 bits (precision = 0.625 degrees)
127  int sh_phi = 12 - L1MuBMTFConfig::getNbitsPhiPhi();
128  int sh_phib = 10 - L1MuBMTFConfig::getNbitsPhiPhib();
129 
130  const L1MuBMTrackSegPhi* second = getTSphi(2); // track segment at station 2
131  const L1MuBMTrackSegPhi* first = getTSphi(1); // track segment at station 1
132  const L1MuBMTrackSegPhi* forth = getTSphi(4); // track segment at station 4
133 
134  int phi2 = 0; // phi-value at station 2
135  int sector = 0;
136  if (second) {
137  phi2 = second->phi() >> sh_phi;
138  sector = second->sector();
139  } else if (second == nullptr && first) {
140  phi2 = first->phi() >> sh_phi;
141  sector = first->sector();
142  } else if (second == nullptr && forth) {
143  phi2 = forth->phi() >> sh_phi;
144  sector = forth->sector();
145  }
146 
147  int sector0 = m_sp.id().sector();
148 
149  // convert sector difference to values in the range -6 to +5
150 
151  int sectordiff = (sector - sector0) % 12;
152  if (sectordiff >= 6)
153  sectordiff -= 12;
154  if (sectordiff < -6)
155  sectordiff += 12;
156 
157  // convert phi to 0.625 degree precision
158  int phi_precision = 4096 >> sh_phi;
159  const double k = 57.2958 / 0.625 / static_cast<float>(phi_precision);
160  double phi_f = static_cast<double>(phi2);
161  int bit_div_phi = static_cast<int>(phi2) % 4;
162  if (bit_div_phi < 0)
163  bit_div_phi += 4;
164  phi_f = phi_f - std::abs(bit_div_phi);
165  int phi_8 = static_cast<int>(floor(phi_f * k));
166 
167  if (second == nullptr && first) {
168  int bend_angle = (first->phib() >> sh_phib) << sh_phib;
169  phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(0, bend_angle);
170  //phi_8 = phi_8 + getDeltaPhi(0, bend_angle, bmtfParams->phi_lut());
171  } else if (second == nullptr && forth) {
172  int bend_angle = (forth->phib() >> sh_phib) << sh_phib;
173  phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(1, bend_angle);
174  //phi_8 = phi_8 + getDeltaPhi(1, bend_angle, bmtfParams->phi_lut());
175  }
176 
177  //If muon is found at the neighbour sector - second station
178  //a shift is needed by 48
179  phi_8 += sectordiff * 48;
180 
181  int phi = phi_8 + 24;
182  // 78 phi bins (-8 to 69) correspond 30 degree sector plus
183  // additional lower and higher bins for neighboring sectors.
184  if (phi > 69)
185  phi = 69;
186  if (phi < -8)
187  phi = -8;
188 
189  m_sp.track(m_id)->setPhi(phi); // Regional
190  m_sp.tracK(m_id)->setPhi(phi);
191 
192  delete thePhiLUTs;
193 }
194 
195 //
196 // assign pt with 5 bit precision
197 //
199  const L1TMuonBarrelParamsAllPublic bmtfParams(bmtfParams1);
200  thePtaLUTs = new L1MuBMLUTHandler(bmtfParams);
201  //thePtaLUTs->print();
202  // get pt-assignment method as function of track class and TS phib values
203  //m_ptAssMethod = getPtMethod(bmtfParams);
205  // get input address for look-up table
206  int bend_angle = getPtAddress(m_ptAssMethod);
207  int bend_carga = getPtAddress(m_ptAssMethod, 1);
208 
209  // retrieve pt value from look-up table
210  int lut_idx = m_ptAssMethod;
211  int pt = thePtaLUTs->getPt(lut_idx, bend_angle);
212  //int pt = getPt(lut_idx, bend_angle, bmtfParams->pta_lut());
213 
214  if (!bmtfParams.get_DisableNewAlgo()) {
215  if (Quality() < 4) {
216  int ptj = pt;
219  if (jj1 != L1MuBMLUTHandler::NODEF) {
220  lut_idx = jj1;
221  bend_angle = getPt1Address(m_ptAssMethod);
222  if (abs(bend_angle) < 512)
223  ptj = thePtaLUTs->getPt(lut_idx, bend_angle);
224  } else if (jj2 != L1MuBMLUTHandler::NODEF) {
225  lut_idx = jj2;
226  bend_angle = getPt2Address(m_ptAssMethod);
227  if (abs(bend_angle) < 512)
228  ptj = thePtaLUTs->getPt(lut_idx, bend_angle);
229  }
230  if (ptj < pt)
231  pt = ptj;
232  }
233  }
234 
235  m_sp.track(m_id)->setPt(pt);
236  m_sp.tracK(m_id)->setPt(pt);
237 
238  // assign charge
239  int chsign = getCharge(m_ptAssMethod);
240  int charge = (bend_carga >= 0) ? chsign : -1 * chsign;
243  delete thePtaLUTs;
244 }
245 
246 //
247 // assign 4 bit quality code
248 //
250  unsigned int quality = 0;
251 
252  const TrackClass tc = m_sp.TA()->trackClass(m_id);
253 
255  switch (tc) {
256  case T1234: {
257  quality = 3;
258  break;
259  }
260  case T123: {
261  quality = 2;
262  break;
263  }
264  case T124: {
265  quality = 2;
266  break;
267  }
268  case T134: {
269  quality = 2;
270  break;
271  }
272  case T234: {
273  quality = 2;
274  break;
275  }
276  case T12: {
277  quality = 1;
278  break;
279  }
280  case T13: {
281  quality = 1;
282  break;
283  }
284  case T14: {
285  quality = 1;
286  break;
287  }
288  case T23: {
289  quality = 0;
290  break;
291  }
292  case T24: {
293  quality = 0;
294  break;
295  }
296  case T34: {
297  quality = 0;
298  break;
299  }
300  default: {
301  quality = 0;
302  break;
303  }
304  }
305 
307  quality += 12;
308 
311 }
312 
313 //
314 // assign 3 bit quality code
315 //
317  unsigned int quality = 0;
318 
319  const TrackClass tc = m_sp.TA()->trackClass(m_id);
320 
321  switch (tc) {
322  case T1234: {
323  quality = 7;
324  break;
325  }
326  case T123: {
327  quality = 6;
328  break;
329  }
330  case T124: {
331  quality = 6;
332  break;
333  }
334  case T134: {
335  quality = 5;
336  break;
337  }
338  case T234: {
339  quality = 4;
340  break;
341  }
342  case T12: {
343  quality = 3;
344  break;
345  }
346  case T13: {
347  quality = 3;
348  break;
349  }
350  case T14: {
351  quality = 3;
352  break;
353  }
354  case T23: {
355  quality = 2;
356  break;
357  }
358  case T24: {
359  quality = 2;
360  break;
361  }
362  case T34: {
363  quality = 1;
364  break;
365  }
366  default: {
367  quality = 0;
368  }
369  }
370 
371  return quality;
372 }
373 
374 //
375 // Track Segment Router (TSR)
376 //
378  // get the track segments from the data buffer
379  const L1MuBMTrackSegPhi* ts = nullptr;
380  for (int stat = 1; stat <= 4; stat++) {
381  int adr = m_addArray.station(stat);
382  if (adr != 15) {
383  ts = m_sp.data()->getTSphi(stat, adr);
384  if (ts != nullptr)
385  m_TSphi.push_back(ts);
386  }
387  }
388 }
389 
390 //
391 // get track segment from a given station
392 //
394  vector<const L1MuBMTrackSegPhi*>::const_iterator iter;
395  for (iter = m_TSphi.begin(); iter != m_TSphi.end(); iter++) {
396  int stat = (*iter)->station();
397  if (station == stat) {
398  return (*iter);
399  break;
400  }
401  }
402 
403  return nullptr;
404 }
405 
406 //
407 // convert sector Id to a precision of 2.5 degrees using 8 bits (= sector center)
408 //
410  // assert( sector >=0 && sector < 12 );
411  const int sectorvalues[12] = {0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132};
412 
413  return sectorvalues[sector];
414 }
415 
416 //
417 // determine charge
418 //
420  int chargesign = 0;
421  switch (method) {
423  chargesign = -1;
424  break;
425  }
427  chargesign = -1;
428  break;
429  }
431  chargesign = -1;
432  break;
433  }
435  chargesign = -1;
436  break;
437  }
439  chargesign = -1;
440  break;
441  }
443  chargesign = -1;
444  break;
445  }
447  chargesign = -1;
448  break;
449  }
451  chargesign = -1;
452  break;
453  }
455  chargesign = -1;
456  break;
457  }
459  chargesign = -1;
460  break;
461  }
463  chargesign = 1;
464  break;
465  }
467  chargesign = 1;
468  break;
469  }
470 
472  chargesign = 0;
473  // cerr << "AssignmentUnit::getCharge : undefined PtAssMethod!"
474  // << endl;
475  break;
476  }
477  default: {
478  chargesign = 0;
479  }
480  }
481 
482  return chargesign;
483 }
484 
485 //
486 // determine pt-assignment method
487 //
488 //PtAssMethod L1MuBMAssignmentUnit::getPtMethod(L1TMuonBarrelParams *l1tbmparams) const {
490  // determine which pt-assignment method should be used as a function
491  // of the track class and
492  // of the phib values of the track segments making up this track candidate.
493 
494  // get bitmap of track candidate
495  const bitset<4> s = m_sp.TA()->trackBitMap(m_id);
496 
497  int method = -1;
498 
499  if (s.test(0) && s.test(3))
500  method = 2; // stations 1 and 4
501  if (s.test(0) && s.test(2))
502  method = 1; // stations 1 and 3
503  if (s.test(0) && s.test(1))
504  method = 0; // stations 1 and 2
505  if (!s.test(0) && s.test(1) && s.test(3))
506  method = 4; // stations 2 and 4
507  if (!s.test(0) && s.test(1) && s.test(2))
508  method = 3; // stations 2 and 3
509  if (!s.test(0) && !s.test(1) && s.test(2) && s.test(3))
510  method = 5; // stations 3 and 4
512 
513  // phib values of track segments from stations 1, 2 and 4
514  int phib1 = (getTSphi(1) != nullptr) ? getTSphi(1)->phib() : 0;
515  int phib2 = (getTSphi(2) != nullptr) ? getTSphi(2)->phib() : 0;
516  int phib4 = (getTSphi(4) != nullptr) ? getTSphi(4)->phib() : 0;
517 
519 
520  switch (method) {
521  case 0: {
523  break;
524  }
525  case 1: {
527  break;
528  }
529  case 2: {
531  break;
532  }
533  case 3: {
535  break;
536  }
537  case 4: {
539  break;
540  }
541  case 5: {
543  break;
544  }
545  default:;
546  //cout << "L1MuBMAssignmentUnit : Error in PT ass method evaluation" << endl;
547  }
548 
549  return pam;
550 }
551 
552 //
553 // calculate bend angle
554 //
556  // calculate bend angle as difference of two azimuthal positions
557 
558  int bendangle = 0;
559  switch (method) {
561  bendangle = phiDiff(1, 2);
562  break;
563  }
565  bendangle = phiDiff(1, 2);
566  break;
567  }
569  bendangle = phiDiff(1, 3);
570  break;
571  }
573  bendangle = phiDiff(1, 3);
574  break;
575  }
577  bendangle = phiDiff(1, 4);
578  break;
579  }
581  bendangle = phiDiff(1, 4);
582  break;
583  }
585  bendangle = phiDiff(2, 3);
586  break;
587  }
589  bendangle = phiDiff(2, 3);
590  break;
591  }
593  bendangle = phiDiff(2, 4);
594  break;
595  }
597  bendangle = phiDiff(2, 4);
598  break;
599  }
601  bendangle = phiDiff(4, 3);
602  break;
603  }
605  bendangle = phiDiff(4, 3);
606  break;
607  }
609  bendangle = 0;
610  // cerr << "AssignmentUnit::getPtAddress : undefined PtAssMethod" << endl;
611  break;
612  }
613  default: {
614  bendangle = 0;
615  }
616  }
617 
618  int signo = 1;
619  bendangle = (bendangle + 8192) % 4096;
620  if (bendangle > 2047)
621  bendangle -= 4096;
622  if (bendangle < 0)
623  signo = -1;
624 
625  if (bendcharge)
626  return signo;
627 
628  bendangle = (bendangle + 2048) % 1024;
629  if (bendangle > 511)
630  bendangle -= 1024;
631 
632  return bendangle;
633 }
634 
635 //
636 // build difference of two phi values
637 //
638 int L1MuBMAssignmentUnit::phiDiff(int stat1, int stat2) const {
639  // calculate bit shift
640 
641  int sh_phi = 12 - nbit_phi;
642 
643  // get 2 phi values and add offset (30 degrees ) for adjacent sector
644  int sector1 = getTSphi(stat1)->sector();
645  int sector2 = getTSphi(stat2)->sector();
646  int phi1 = getTSphi(stat1)->phi() >> sh_phi;
647  int phi2 = getTSphi(stat2)->phi() >> sh_phi;
648 
649  // convert sector difference to values in the range -6 to +5
650 
651  int sectordiff = (sector2 - sector1) % 12;
652  if (sectordiff >= 6)
653  sectordiff -= 12;
654  if (sectordiff < -6)
655  sectordiff += 12;
656 
657  // assert( abs(sectordiff) <= 1 );
658 
659  int offset = (2144 >> sh_phi) * sectordiff;
660  int bendangle = (phi2 - phi1 + offset) << sh_phi;
661 
662  return bendangle;
663 }
664 
665 //
666 // determine pt-assignment method
667 //
669  // quality values of track segments from stations 1, 2 and 4
670  int qual1 = (getTSphi(1) != nullptr) ? getTSphi(1)->quality() : 0;
671  int qual2 = (getTSphi(2) != nullptr) ? getTSphi(2)->quality() : 0;
672  int qual4 = (getTSphi(4) != nullptr) ? getTSphi(4)->quality() : 0;
673 
675 
676  switch (method) {
678  if (qual1 > 3)
680  break;
681  }
683  if (qual1 > 3)
685  break;
686  }
688  if (qual1 > 3)
690  break;
691  }
693  if (qual2 > 3)
695  break;
696  }
698  if (qual2 > 3)
700  break;
701  }
703  if (qual4 > 3)
705  break;
706  }
709  break;
710  }
711  default: {
713  }
714  }
715 
716  return pam;
717 }
718 
719 //
720 // determine pt-assignment method
721 //
723  // quality values of track segments from stations 2 and 4
724  int qual2 = (getTSphi(2) != nullptr) ? getTSphi(2)->quality() : 0;
725  // int qual4 = ( getTSphi(4) != 0 ) ? getTSphi(4)->quality() : 0;
726 
728 
729  switch (method) {
731  if (qual2 > 3)
733  break;
734  }
735  // case PT14H : { if (qual4 > 3) pam = PB34H; break; }
736  // case PT24H : { if (qual4 > 3) pam = PB34H; break; }
737  //case PT12HO : { if (qual2 > 3) pam = PB21HO; break; }
738  // case PT14HO : { if (qual4 > 3) pam = PB34HO; break; }
739  // case PT24HO : { if (qual4 > 3) pam = PB34HO; break; }
742  break;
743  }
744  default: {
746  }
747  }
748 
749  return pam;
750 }
751 
752 //
753 // calculate bend angle
754 //
756  // phib values of track segments from stations 1, 2 and 4
757  int phib1 = (getTSphi(1) != nullptr) ? getTSphi(1)->phib() : -999;
758  int phib2 = (getTSphi(2) != nullptr) ? getTSphi(2)->phib() : -999;
759  int phib4 = (getTSphi(4) != nullptr) ? getTSphi(4)->phib() : -999;
760 
761  int bendangle = -999;
762  switch (method) {
764  bendangle = phib1;
765  break;
766  }
768  bendangle = phib1;
769  break;
770  }
772  bendangle = phib1;
773  break;
774  }
776  bendangle = phib2;
777  break;
778  }
780  bendangle = phib2;
781  break;
782  }
784  bendangle = phib4;
785  break;
786  }
788  bendangle = -999;
789  break;
790  }
791  default: {
792  bendangle = -999;
793  }
794  }
795 
796  return bendangle;
797 }
798 
799 //
800 // calculate bend angle
801 //
803  // phib values of track segments from stations 1, 2 and 4
804  int phib2 = (getTSphi(2) != nullptr) ? getTSphi(2)->phib() : -999;
805  int phib4 = (getTSphi(4) != nullptr) ? getTSphi(4)->phib() : -999;
806 
807  int bendangle = -999;
808  switch (method) {
810  bendangle = phib2;
811  break;
812  }
814  bendangle = phib4;
815  break;
816  }
818  bendangle = phib4;
819  break;
820  }
821  //case L1MuBMLUTHandler::PT12HO : { bendangle = phib2; break; }
822  //case L1MuBMLUTHandler::PT14HO : { bendangle = phib4; break; }
823  //case L1MuBMLUTHandler::PT24HO : { bendangle = phib4; break; }
825  bendangle = -999;
826  break;
827  }
828  default: {
829  bendangle = -999;
830  }
831  }
832 
833  return bendangle;
834 }
835 
836 //
837 // set precision for pt-assignment of phi and phib
838 // default is 12 bits for phi and 10 bits for phib
839 //
843 }
844 
845 // static data members
846 
847 unsigned short int L1MuBMAssignmentUnit::nbit_phi = 12;
848 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)
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
string quality
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