CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
45 
46 using namespace std;
47 
48 // --------------------------------
49 // class L1MuDTAssignmentUnit
50 //---------------------------------
51 
52 //----------------
53 // Constructors --
54 //----------------
55 
57  m_sp(sp), m_id(id),
58  m_addArray(), m_TSphi(), m_ptAssMethod(NODEF) {
59 
60  m_TSphi.reserve(4); // a track candidate can consist of max 4 TS
61  reset();
62 
63  setPrecision();
64 
65 }
66 
67 
68 //--------------
69 // Destructor --
70 //--------------
71 
73 
74 
75 //--------------
76 // Operations --
77 //--------------
78 
79 //
80 // run Assignment Unit
81 //
83 
84  // enable track candidate
85  m_sp.track(m_id)->enable();
86  m_sp.tracK(m_id)->enable();
87 
88  // set track class
89  TrackClass tc = m_sp.TA()->trackClass(m_id);
90  m_sp.track(m_id)->setTC(tc);
91  m_sp.tracK(m_id)->setTC(tc);
92 
93  // get relative addresses of matching track segments
97 
98  // get track segments (track segment router)
99  TSR();
102 
103  // set bunch-crossing (use first track segment)
104  vector<const L1MuDTTrackSegPhi*>::const_iterator iter = m_TSphi.begin();
105  int bx = (*iter)->bx();
106  m_sp.track(m_id)->setBx(bx);
107  m_sp.tracK(m_id)->setBx(bx);
108 
109  // assign phi
110  PhiAU(c);
111 
112  // assign pt and charge
113  PtAU(c);
114 
115  // assign quality
116  QuaAU();
117 
118  // special hack for overlap region
119  // for ( iter = m_TSphi.begin(); iter != m_TSphi.end(); iter++ ) {
120  // int wheel = abs((*iter)->wheel());
121  // if ( wheel == 3 && (*iter)->etaFlag() ) m_sp.track(m_id)->disable();
122  // if ( wheel == 3 && (*iter)->etaFlag() ) m_sp.tracK(m_id)->disable();
123  // }
124 
125 }
126 
127 
128 //
129 // reset Assignment Unit
130 //
132 
133  m_addArray.reset();
134  m_TSphi.clear();
136 
137 }
138 
139 
140 //
141 // assign phi with 8 bit precision
142 //
144 
145  // calculate phi at station 2 using 8 bits (precision = 2.5 degrees)
146 
147  c.get< L1MuDTPhiLutRcd >().get( thePhiLUTs );
148 
149  int sh_phi = 12 - L1MuDTTFConfig::getNbitsPhiPhi();
150  int sh_phib = 10 - L1MuDTTFConfig::getNbitsPhiPhib();
151 
152  const L1MuDTTrackSegPhi* second = getTSphi(2); // track segment at station 2
153  const L1MuDTTrackSegPhi* first = getTSphi(1); // track segment at station 1
154  const L1MuDTTrackSegPhi* forth = getTSphi(4); // track segment at station 4
155 
156  int phi2 = 0; // phi-value at station 2
157  int sector = 0;
158 
159  if ( second ) {
160  phi2 = second->phi() >> sh_phi;
161  sector = second->sector();
162  }
163  else if ( second == 0 && first ) {
164  phi2 = first->phi() >> sh_phi;
165  sector = first->sector();
166  }
167  else if ( second == 0 && forth ) {
168  phi2 = forth->phi() >> sh_phi;
169  sector = forth->sector();
170  }
171 
172  int sector0 = m_sp.id().sector();
173 
174  // convert sector difference to values in the range -6 to +5
175 
176  int sectordiff = (sector - sector0)%12;
177  if ( sectordiff >= 6 ) sectordiff -= 12;
178  if ( sectordiff < -6 ) sectordiff += 12;
179 
180  // assert( abs(sectordiff) <= 1 );
181 
182  // get sector center in 8 bit coding
183  int sector_8 = convertSector(sector0);
184 
185  // convert phi to 2.5 degree precision
186  int phi_precision = 4096 >> sh_phi;
187  const double k = 57.2958/2.5/static_cast<float>(phi_precision);
188  double phi_f = static_cast<double>(phi2);
189  int phi_8 = static_cast<int>(floor(phi_f*k));
190 
191  if ( second == 0 && first ) {
192  int bend_angle = (first->phib() >> sh_phib) << sh_phib;
193  phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(0,bend_angle);
194  }
195  else if ( second == 0 && forth ) {
196  int bend_angle = (forth->phib() >> sh_phib) << sh_phib;
197  phi_8 = phi_8 + thePhiLUTs->getDeltaPhi(1,bend_angle);
198  }
199 
200  phi_8 += sectordiff*12;
201 
202  if (phi_8 > 15) phi_8 = 15;
203  if (phi_8 < -16) phi_8 = -16;
204 
205  int phi = (sector_8 + phi_8 + 144)%144;
206  phi_8 = (phi_8 + 32)%32;
207 
208  m_sp.track(m_id)->setPhi(phi);
209  m_sp.tracK(m_id)->setPhi(phi_8);
210 
211 }
212 
213 
214 //
215 // assign pt with 5 bit precision
216 //
218 
219  c.get< L1MuDTPtaLutRcd >().get( thePtaLUTs );
220 
221  // get pt-assignment method as function of track class and TS phib values
223 
224  // get input address for look-up table
225  int bend_angle = getPtAddress(m_ptAssMethod);
226  int bend_carga = getPtAddress(m_ptAssMethod, 1);
227 
228  // retrieve pt value from look-up table
229  int lut_idx = m_ptAssMethod;
230  int pt = thePtaLUTs->getPt(lut_idx,bend_angle );
231 
232  m_sp.track(m_id)->setPt(pt);
233  m_sp.tracK(m_id)->setPt(pt);
234 
235  // assign charge
236  int chsign = getCharge(m_ptAssMethod);
237  int charge = ( bend_carga >= 0 ) ? chsign : -1 * chsign;
238  m_sp.track(m_id)->setCharge(charge);
239  m_sp.tracK(m_id)->setCharge(charge);
240 
241 }
242 
243 
244 //
245 // assign 3 bit quality code
246 //
248 
249  unsigned int quality = 0;
250 
251  const TrackClass tc = m_sp.TA()->trackClass(m_id);
252 
253  switch ( tc ) {
254  case T1234 : { quality = 7; break; }
255  case T123 : { quality = 6; break; }
256  case T124 : { quality = 6; break; }
257  case T134 : { quality = 5; break; }
258  case T234 : { quality = 4; break; }
259  case T12 : { quality = 3; break; }
260  case T13 : { quality = 3; break; }
261  case T14 : { quality = 3; break; }
262  case T23 : { quality = 2; break; }
263  case T24 : { quality = 2; break; }
264  case T34 : { quality = 1; break; }
265  default : { quality = 0; break; }
266  }
267 
268  m_sp.track(m_id)->setQuality(quality);
269  m_sp.tracK(m_id)->setQuality(quality);
270 
271 }
272 
273 
274 //
275 // Track Segment Router (TSR)
276 //
278 
279  // get the track segments from the data buffer
280  const L1MuDTTrackSegPhi* ts = 0;
281  for ( int stat = 1; stat <= 4; stat++ ) {
282  int adr = m_addArray.station(stat);
283  if ( adr != 15 ) {
284  ts = m_sp.data()->getTSphi(stat,adr);
285  if ( ts != 0 ) m_TSphi.push_back( ts );
286  }
287  }
288 
289 }
290 
291 
292 //
293 // get track segment from a given station
294 //
296 
297  vector<const L1MuDTTrackSegPhi*>::const_iterator iter;
298  for ( iter = m_TSphi.begin(); iter != m_TSphi.end(); iter++ ) {
299  int stat = (*iter)->station();
300  if ( station == stat ) {
301  return (*iter);
302  break;
303  }
304  }
305 
306  return 0;
307 
308 }
309 
310 
311 //
312 // convert sector Id to a precision of 2.5 degrees using 8 bits (= sector center)
313 //
315 
316  // assert( sector >=0 && sector < 12 );
317  const int sectorvalues[12] = { 0, 12, 24, 36, 48, 60, 72, 84,
318  96, 108, 120, 132 };
319 
320  return sectorvalues[sector];
321 
322 }
323 
324 
325 //
326 // determine charge
327 //
329 
330  int chargesign = 0;
331  switch ( method ) {
332  case PT12L : { chargesign = -1; break; }
333  case PT12H : { chargesign = -1; break; }
334  case PT13L : { chargesign = -1; break; }
335  case PT13H : { chargesign = -1; break; }
336  case PT14L : { chargesign = -1; break; }
337  case PT14H : { chargesign = -1; break; }
338  case PT23L : { chargesign = -1; break; }
339  case PT23H : { chargesign = -1; break; }
340  case PT24L : { chargesign = -1; break; }
341  case PT24H : { chargesign = -1; break; }
342  case PT34L : { chargesign = 1; break; }
343  case PT34H : { chargesign = 1; break; }
344  case PT12LO : { chargesign = -1; break; }
345  case PT12HO : { chargesign = -1; break; }
346  case PT13LO : { chargesign = -1; break; }
347  case PT13HO : { chargesign = -1; break; }
348  case PT14LO : { chargesign = -1; break; }
349  case PT14HO : { chargesign = -1; break; }
350  case PT23LO : { chargesign = -1; break; }
351  case PT23HO : { chargesign = -1; break; }
352  case PT24LO : { chargesign = -1; break; }
353  case PT24HO : { chargesign = -1; break; }
354  case PT34LO : { chargesign = 1; break; }
355  case PT34HO : { chargesign = 1; break; }
356  case PT15LO : { chargesign = -1; break; }
357  case PT15HO : { chargesign = -1; break; }
358  case PT25LO : { chargesign = -1; break; }
359  case PT25HO : { chargesign = -1; break; }
360  case NODEF : { chargesign = 0;
361  // cerr << "AssignmentUnit::getCharge : undefined PtAssMethod!"
362  // << endl;
363  break;
364  }
365  }
366 
367  return chargesign;
368 
369 }
370 
371 
372 //
373 // determine pt-assignment method
374 //
376 
377  // determine which pt-assignment method should be used as a function
378  // of the track class and
379  // of the phib values of the track segments making up this track candidate.
380 
381  // get bitmap of track candidate
382  const bitset<4> s = m_sp.TA()->trackBitMap(m_id);
383 
384  int method = -1;
385 
386  if ( s.test(0) && s.test(3) ) method = 2; // stations 1 and 4
387  if ( s.test(0) && s.test(2) ) method = 1; // stations 1 and 3
388  if ( s.test(0) && s.test(1) ) method = 0; // stations 1 and 2
389  if ( !s.test(0) && s.test(1) && s.test(3) ) method = 4; // stations 2 and 4
390  if ( !s.test(0) && s.test(1) && s.test(2) ) method = 3; // stations 2 and 3
391  if ( !s.test(0) && !s.test(1) && s.test(2) && s.test(3) ) method = 5; // stations 3 and 4
392 
393  if ( m_sp.ovl() ) {
394  int adr = m_addArray.station(3);
395  bool s5 = (adr == 15) ? false : ((adr/2)%2 == 1);
396  if ( s.test(0) && s.test(3) ) method = 8; // stations 1 and 4
397  if ( s.test(0) && s.test(2) && s5 ) method = 12; // stations 1 and 5
398  if ( s.test(0) && s.test(2) && !s5 ) method = 7; // stations 1 and 3
399  if ( s.test(0) && s.test(1) ) method = 6; // stations 1 and 2
400  if ( !s.test(0) && s.test(1) && s.test(3) ) method = 10; // stations 2 and 4
401  if ( !s.test(0) && s.test(1) && s.test(2) && s5 ) method = 13; // stations 2 and 5
402  if ( !s.test(0) && s.test(1) && s.test(2) && !s5 ) method = 9; // stations 2 and 3
403  if ( !s.test(0) && !s.test(1) && s.test(2) && s.test(3) ) method = 11; // stations 3 and 4
404  }
405 
406  int threshold = thePtaLUTs->getPtLutThreshold(method);
407 
408  // phib values of track segments from stations 1, 2 and 4
409  int phib1 = ( getTSphi(1) != 0 ) ? getTSphi(1)->phib() : 0;
410  int phib2 = ( getTSphi(2) != 0 ) ? getTSphi(2)->phib() : 0;
411  int phib4 = ( getTSphi(4) != 0 ) ? getTSphi(4)->phib() : 0;
412 
413  PtAssMethod pam = NODEF;
414 
415  switch ( method ) {
416  case 0 : { pam = ( abs(phib1) < threshold ) ? PT12H : PT12L; break; }
417  case 1 : { pam = ( abs(phib1) < threshold ) ? PT13H : PT13L; break; }
418  case 2 : { pam = ( abs(phib1) < threshold ) ? PT14H : PT14L; break; }
419  case 3 : { pam = ( abs(phib2) < threshold ) ? PT23H : PT23L; break; }
420  case 4 : { pam = ( abs(phib2) < threshold ) ? PT24H : PT24L; break; }
421  case 5 : { pam = ( abs(phib4) < threshold ) ? PT34H : PT34L; break; }
422  case 6 : { pam = ( abs(phib1) < threshold ) ? PT12HO : PT12LO; break; }
423  case 7 : { pam = ( abs(phib1) < threshold ) ? PT13HO : PT13LO; break; }
424  case 8 : { pam = ( abs(phib1) < threshold ) ? PT14HO : PT14LO; break; }
425  case 9 : { pam = ( abs(phib2) < threshold ) ? PT23HO : PT23LO; break; }
426  case 10 : { pam = ( abs(phib2) < threshold ) ? PT24HO : PT24LO; break; }
427  case 11 : { pam = ( abs(phib4) < threshold ) ? PT34HO : PT34LO; break; }
428  case 12 : { pam = ( abs(phib1) < threshold ) ? PT15HO : PT15LO; break; }
429  case 13 : { pam = ( abs(phib2) < threshold ) ? PT25HO : PT25LO; break; }
430  default : ;
431  //cout << "L1MuDTAssignmentUnit : Error in PT ass method evaluation" << endl;
432  }
433 
434  return pam;
435 
436 }
437 
438 
439 //
440 // calculate bend angle
441 //
443 
444  // calculate bend angle as difference of two azimuthal positions
445 
446  int bendangle = 0;
447  switch (method) {
448  case PT12L : { bendangle = phiDiff(1,2); break; }
449  case PT12H : { bendangle = phiDiff(1,2); break; }
450  case PT13L : { bendangle = phiDiff(1,3); break; }
451  case PT13H : { bendangle = phiDiff(1,3); break; }
452  case PT14L : { bendangle = phiDiff(1,4); break; }
453  case PT14H : { bendangle = phiDiff(1,4); break; }
454  case PT23L : { bendangle = phiDiff(2,3); break; }
455  case PT23H : { bendangle = phiDiff(2,3); break; }
456  case PT24L : { bendangle = phiDiff(2,4); break; }
457  case PT24H : { bendangle = phiDiff(2,4); break; }
458  case PT34L : { bendangle = phiDiff(4,3); break; }
459  case PT34H : { bendangle = phiDiff(4,3); break; }
460  case PT12LO : { bendangle = phiDiff(1,2); break; }
461  case PT12HO : { bendangle = phiDiff(1,2); break; }
462  case PT13LO : { bendangle = phiDiff(1,3); break; }
463  case PT13HO : { bendangle = phiDiff(1,3); break; }
464  case PT14LO : { bendangle = phiDiff(1,4); break; }
465  case PT14HO : { bendangle = phiDiff(1,4); break; }
466  case PT23LO : { bendangle = phiDiff(2,3); break; }
467  case PT23HO : { bendangle = phiDiff(2,3); break; }
468  case PT24LO : { bendangle = phiDiff(2,4); break; }
469  case PT24HO : { bendangle = phiDiff(2,4); break; }
470  case PT34LO : { bendangle = phiDiff(4,3); break; }
471  case PT34HO : { bendangle = phiDiff(4,3); break; }
472  case PT15LO : { bendangle = phiDiff(1,3); break; }
473  case PT15HO : { bendangle = phiDiff(1,3); break; }
474  case PT25LO : { bendangle = phiDiff(2,3); break; }
475  case PT25HO : { bendangle = phiDiff(2,3); break; }
476  case NODEF : { bendangle = 0;
477  // cerr << "AssignmentUnit::getPtAddress : undefined PtAssMethod" << endl;
478  break;
479  }
480  }
481 
482  int signo = 1;
483  bendangle = (bendangle+8192)%4096;
484  if ( bendangle > 2047 ) bendangle -= 4096;
485  if ( bendangle < 0 ) signo = -1;
486 
487  if (bendcharge) return signo;
488 
489  bendangle = (bendangle+2048)%1024;
490  if ( bendangle > 511 ) bendangle -= 1024;
491 
492  return bendangle;
493 
494 }
495 
496 
497 //
498 // build difference of two phi values
499 //
500 int L1MuDTAssignmentUnit::phiDiff(int stat1, int stat2) const {
501 
502  // calculate bit shift
503 
504  int sh_phi = 12 - nbit_phi;
505 
506  // get 2 phi values and add offset (30 degrees ) for adjacent sector
507  int sector1 = getTSphi(stat1)->sector();
508  int sector2 = getTSphi(stat2)->sector();
509  int phi1 = getTSphi(stat1)->phi() >> sh_phi;
510  int phi2 = getTSphi(stat2)->phi() >> sh_phi;
511 
512  // convert sector difference to values in the range -6 to +5
513 
514  int sectordiff = (sector2 - sector1)%12;
515  if ( sectordiff >= 6 ) sectordiff -= 12;
516  if ( sectordiff < -6 ) sectordiff += 12;
517 
518  // assert( abs(sectordiff) <= 1 );
519 
520  int offset = (2144 >> sh_phi) * sectordiff;
521  int bendangle = (phi2 - phi1 + offset) << sh_phi;
522 
523  return bendangle;
524 
525 }
526 
527 
528 //
529 // set precision for pt-assignment of phi and phib
530 // default is 12 bits for phi and 10 bits for phib
531 //
533 
536 
537 }
538 
539 
540 // static data members
541 
542 unsigned short int L1MuDTAssignmentUnit::nbit_phi = 12;
543 unsigned short int L1MuDTAssignmentUnit::nbit_phib = 10;
void PtAU(const edm::EventSetup &c)
assign pt and charge
void setPt(int pt)
set pt-code of muon candidate
Definition: L1MuDTTrack.h:147
L1MuDTTrack * tracK(int id) const
return pointer to muon candidate, index [0,1]
edm::ESHandle< L1MuDTPhiLut > thePhiLUTs
phi-assignment look-up tables
void QuaAU()
assign quality
void reset()
reset address array
edm::ESHandle< L1MuDTPtaLut > thePtaLUTs
pt-assignment look-up tables
void setTSphi(const std::vector< const L1MuDTTrackSegPhi * > &tsList)
set phi track segments used to form the muon candidate
Definition: L1MuDTTrack.cc:168
static int getCharge(PtAssMethod)
determine charge
int phi() const
return phi
void setTC(TrackClass tc)
set track-class of muon candidate
Definition: L1MuDTTrack.h:135
L1MuDTAddressArray m_addArray
double charge(const std::vector< uint8_t > &Ampls)
static int getNbitsPhiPhi()
void setAddresses(const L1MuDTAddressArray &addr)
set relative addresses of muon candidate
Definition: L1MuDTTrack.h:156
static int getNbitsPtaPhi()
void enable()
enable muon candidate
Definition: L1MuDTTrack.h:126
int sector() const
return sector number
const L1MuDTDataBuffer * data() const
return pointer to Data Buffer
U second(std::pair< T, U > const &p)
L1MuDTSectorProcessor & m_sp
void setBx(int bx)
Set Bunch Crossing.
std::vector< const L1MuDTTrackSegPhi * > m_TSphi
static unsigned short nbit_phib
of bits used for pt-assignment
virtual void reset()
reset Assignment Unit
virtual ~L1MuDTAssignmentUnit()
destructor
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:153
unsigned int offset(bool)
bool first
Definition: L1TdeRCT.cc:75
int k[5][pyjets_maxn]
static int getNbitsPhiPhib()
const TSPhivector & getTSphi() const
get all track segments from the buffer
static int convertSector(int)
convert sector Id to 8 bit code (= sector center)
void PhiAU(const edm::EventSetup &c)
assign phi
static void setPrecision()
set precision of phi and phib
const T & get() const
Definition: EventSetup.h:55
int getPtAddress(PtAssMethod, int bendcharge=0) const
calculate bend angle
int sector() const
return sector
static int getNbitsPtaPhib()
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]
L1MuDTAssignmentUnit(L1MuDTSectorProcessor &sp, int id)
constructor
void setPhi(int phi)
set phi-code of muon candidate
Definition: L1MuDTTrack.h:138
bool ovl() const
is it an overlap region Sector Processor?
static unsigned short nbit_phi
of bits used for pt-assignment
PtAssMethod
void setCharge(int charge)
set charge of muon candidate
Definition: L1MuDTTrack.h:150
Definition: DDAxes.h:10