test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuBMEtaProcessor.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuBMEtaProcessor
4 //
5 // Description: Eta Processor
6 //
7 // An Eta Processor consists of :
8 // a receiver unit,
9 // one Eta Track Finder (ETF) and
10 // one Eta Matching Unit (EMU)
11 //
12 //
13 // Author :
14 // N. Neumeister CERN EP
15 // J. Troconiz UAM Madrid
16 //
17 //--------------------------------------------------
18 
19 //-----------------------
20 // This Class's Header --
21 //-----------------------
22 
24 
25 //---------------
26 // C++ Headers --
27 //---------------
28 
29 #include <iostream>
30 #include <iomanip>
31 #include <bitset>
32 
33 //-------------------------------
34 // Collaborating Class Headers --
35 //-------------------------------
36 
50 
51 using namespace std;
52 
53 // --------------------------------
54 // class L1MuBMEtaProcessor
55 //---------------------------------
56 
57 //----------------
58 // Constructors --
59 //----------------
60 
62  m_tf(tf), m_epid(id), m_foundPattern(0), m_tseta(15), m_DTDigiToken(iC.consumes<L1MuDTChambThContainer>(L1MuBMTFConfig::getBMThetaDigiInputTag()))
63  {
64 
65  m_tseta.reserve(15);
66 
67 }
68 
69 
70 //--------------
71 // Destructor --
72 //--------------
73 
75 
76 
77 //--------------
78 // Operations --
79 //--------------
80 
81 //
82 // run Eta Processor
83 //
84 void L1MuBMEtaProcessor::run(int bx, const edm::Event& e, const edm::EventSetup& c) {
85 
86  if ( L1MuBMTFConfig::getEtaTF() ) {
87  receiveData(bx,e,c);
89  }
90 
93 
94  assign();
95 
96 }
97 
98 
99 //
100 // reset Eta Processor
101 //
103 
104  vector<const L1MuBMTrackSegEta*>::iterator iter = m_tseta.begin();
105  while ( iter != m_tseta.end() ) {
106  if ( *iter ) {
107  delete *iter;
108  *iter = 0;
109  }
110  iter++;
111  }
112 
113  m_tseta.clear();
114 
115  for ( int i = 0; i < 12; i++ ) {
116  m_eta[i] = 99;
117  m_fine[i] = false;
118  m_pattern[i] = 0;
119  m_address[i] = 0;
120  m_TrackCand[i] = 0;
121  m_TracKCand[i] = 0;
122  }
123 
124  m_foundPattern.clear();
125 
126  m_mask = true;
127 
128 }
129 
130 
131 //
132 // print track candidates found in Eta Processor
133 //
135 
136  bool empty1 = true;
137  for ( int i = 0; i < 15; i++ ) {
138  empty1 &= ( m_tseta[i] == 0 || m_tseta[i]->empty() );
139  }
140 
141  bool empty2 = true;
142  for ( int i = 0; i < 12; i++ ) {
143  empty2 &= ( m_address[i] == 0 );
144  }
145 
146  if ( !empty1 || !empty2 ) {
147  cout << "Eta processor " << m_epid << " : " << endl;
148 
149  // print local pattern
150  if ( !empty1 ) {
151  cout << "Local pattern : " << endl;
152  for ( int i = 0; i < 15; i++ ) {
153  if ( (i+5)%5 == 0 ) cout << "station " << m_tseta[i]->station() << " : ";
154  bitset<7> pos(m_tseta[i]->position());
155  bitset<7> qua(m_tseta[i]->quality());
156  for ( int j = 6; j >= 0; j-- ) {
157  cout << pos[j]+qua[j];
158  }
159  cout << " ";
160  if ( (i+1)%5 == 0 ) cout << endl;
161  }
162  cout << "Found patterns :" << endl;
163  vector<int>::const_iterator iter;
164  for ( iter = m_foundPattern.begin(); iter != m_foundPattern.end(); iter++ ) {
166  int qualitycode = p.quality();
167  cout << "ID = " << setw(4) << p.id() << " "
168  << "eta = " << setw(3) << p.eta() << " "
169  << "quality = " << setw(2) << qualitycode << " ("
170  << quality(qualitycode,1) << " "
171  << quality(qualitycode,2) << " "
172  << quality(qualitycode,3) << ")";
173  for ( int i = 0; i < 12; i++ ) {
174  if ( m_pattern[i] == p.id() ) cout << " <--";
175  }
176  cout << endl;
177  }
178  }
179 
180  cout << "Received addresses : " << endl;
181  for ( int i = 0; i < 12; i++ ) cout << setw(3) << m_address[i] << " ";
182  cout << endl;
183 
184  if ( !empty1 ) {
185  cout << "Matched patterns : " << endl;
186  for ( int i = 0; i < 12; i++ ) {
187  if ( m_fine[i] ) {
189  int fineeta = p.eta();
190  int coarseeta = theQualPatternLUT.getCoarseEta(i/2+1,m_address[i]);
191  cout << "Index = " << setw(2) << i << ", "
192  << "address = " << setw(2) << m_address[i] << " --> "
193  << "pattern = " << setw(4) << m_pattern[i] << " "
194  << "eta (coarse) = " << setw(3) << coarseeta << " "
195  << "eta (fine) = " << setw(3) << fineeta << " "
196  << "quality = " << setw(2) << p.quality() << endl;
197  }
198  }
199  }
200 
201  cout << "Eta values and fine bits : " << endl;
202  for ( int i = 0; i < 12; i++ ) cout << setw(3) << m_eta[i] << " ";
203  cout << endl;
204  for ( int i = 0; i < 12; i++ ) cout << setw(3) << m_fine[i] << " ";
205  cout << endl;
206  }
207 
208 }
209 
210 
211 //
212 // receive data ( 15*3 BBMX eta trigger primitives )
213 //
215 
216  //c.get< L1MuDTTFMasksRcd >().get( msks );
217  const L1TMuonBarrelParamsRcd& bmtfParamsRcd = c.get<L1TMuonBarrelParamsRcd>();
218  bmtfParamsRcd.get(bmtfParamsHandle);
219  const L1TMuonBarrelParams& bmtfParams = *bmtfParamsHandle.product();
220  msks = bmtfParams.l1mudttfmasks;
221  theEtaPatternLUT.m_lut = bmtfParams.lutparams_.eta_lut_; //l1mudttfetaplut; // ETF look-up table
222  theQualPatternLUT.m_lut = bmtfParams.lutparams_.qp_lut_; //l1mudttfqualplut; // EMU look-up tables
223 
225 // e.getByLabel(L1MuBMTFConfig::getBMThetaDigiInputTag(),dttrig);
226  e.getByToken(m_DTDigiToken,dttrig);
227 
228  // const int bx_offset = dttrig->correctBX();
229  int bx_offset=0;
230  bx = bx + bx_offset;
231 
232  //
233  // get 5*3 eta track segments
234  //
235  int sector = m_epid;
236  for ( int stat = 1; stat <= 3; stat++ ) {
237  for ( int wheel = -2; wheel <= 2; wheel++ ) {
238  L1MuDTChambThDigi const* tseta = dttrig->chThetaSegm(wheel,stat,sector,bx);
239  bitset<7> pos;
240  bitset<7> qual;
241 
242  int lwheel = wheel+1;
243  if ( wheel < 0 ) lwheel = wheel-1;
244 
245  bool masked = false;
246  if ( stat == 1 ) masked = msks.get_etsoc_chdis_st1(lwheel, sector);
247  if ( stat == 2 ) masked = msks.get_etsoc_chdis_st2(lwheel, sector);
248  if ( stat == 3 ) masked = msks.get_etsoc_chdis_st3(lwheel, sector);
249 
250  if ( !masked ) m_mask = false;
251 
252  if ( tseta && !masked ) {
253 
254  if ( wheel == -2 || wheel == -1 ||
255  ( wheel == 0 && (sector == 0 || sector == 3 || sector == 4 || sector == 7 || sector == 8 || sector == 11) ) ) {
256  for ( int i = 0; i < 7; i++ ) {
257  if ( tseta->position(i) ) pos.set(6-i);
258  if ( tseta->quality(i) ) qual.set(6-i);
259  }
260  } else {
261  for ( int i = 0; i < 7; i++ ) {
262  if ( tseta->position(i) ) pos.set(i);
263  if ( tseta->quality(i) ) qual.set(i);
264  }
265  }
266  }
267 
268  const L1MuBMTrackSegEta* tmpts = new L1MuBMTrackSegEta(wheel,sector,stat,pos.to_ulong(),qual.to_ulong(),bx-bx_offset);
269  m_tseta.push_back(tmpts);
270  }
271  }
272 
273 }
274 
275 
276 //
277 // receive track addresses from 6 Sector Processors
278 //
280 
281  // get track address code of all track segments
282  // 6*2 times 5 bits; valid range [1-22]
283 
284  int sector = m_epid;
285 
286  int i = 0;
287  for ( int wheel = -3; wheel <= 3; wheel++ ) {
288  if ( wheel == 0 ) continue;
289  L1MuBMSecProcId tmpspid(wheel,sector);
290  for ( int number = 0; number < 2; number++ ) {
291  const L1MuBMTrack* cand = m_tf.sp(tmpspid)->track(number);
292  const L1MuBMTrack* canD = m_tf.sp(tmpspid)->tracK(number);
293  if ( cand ) {
294  m_address[i] = cand->address().trackAddressCode();
295  if ( !cand->empty() ) {
296  m_TrackCand[i] = const_cast<L1MuBMTrack*>(cand);
297  m_TracKCand[i] = const_cast<L1MuBMTrack*>(canD);
298  }
299  i++;
300  }
301  }
302  }
303 
304 }
305 
306 
307 //
308 // run Eta Track Finder (ETF)
309 //
311 
312  //c.get< L1MuDTEtaPatternLutRcd >().get( theEtaPatternLUT );
313  const L1TMuonBarrelParamsRcd& bmtfParamsRcd = c.get<L1TMuonBarrelParamsRcd>();
314  bmtfParamsRcd.get(bmtfParamsHandle);
315  const L1TMuonBarrelParams& bmtfParams = *bmtfParamsHandle.product();
316  theEtaPatternLUT.m_lut = bmtfParams.lutparams_.eta_lut_; //l1mudttfetaplut; // ETF look-up table
317 
318  // check if there are any data
319  bool empty = true;
320  for ( int i = 0; i < 15; i++ ) {
321  empty &= m_tseta[i]->empty();
322  }
323  if ( empty ) return;
324 
325  // Pattern comparator:
326  // loop over all patterns and compare with local chamber pattern
327  // result : list of valid pattern IDs ( m_foundPattern )
329  while ( it != theEtaPatternLUT.end() ) {
330 
331  const L1MuDTEtaPattern pattern = (*it).second;
332  int qualitycode = pattern.quality();
333 
334  bool good = true;
335 
336  for ( int station = 0; station < 3; station++) {
337  int q = quality(qualitycode,station+1);
338  int wheel = pattern.wheel(station+1);
339  int bin = pattern.position(station+1);
340  if ( bin == 0 ) continue;
341  bitset<7> pos = m_tseta[wheel+2 + station*5]->position();
342  bitset<7> qual = m_tseta[wheel+2 + station*5]->quality();
343  // compare position
344  good &= pos.test(bin-1);
345  // compare quality
346  if ( q == 2 ) good &= qual.test(bin-1);
347  }
348 
349  if ( good ) m_foundPattern.push_back(pattern.id());
350 
351  it++;
352 
353  }
354 
355 }
356 
357 
358 //
359 // run Eta Matching Unit (EMU)
360 //
362 
363  //c.get< L1MuDTQualPatternLutRcd >().get( theQualPatternLUT );
364  const L1TMuonBarrelParamsRcd& bmtfParamsRcd = c.get<L1TMuonBarrelParamsRcd>();
365  bmtfParamsRcd.get(bmtfParamsHandle);
366  const L1TMuonBarrelParams& bmtfParams = *bmtfParamsHandle.product();
367  theQualPatternLUT.m_lut = bmtfParams.lutparams_.qp_lut_; //l1mudttfqualplut; // EMU look-up tables
368 
369  // loop over all addresses
370  for ( int i = 0; i < 12; i++ ) {
371 
372  int adr = m_address[i];
373  if ( adr == 0 ) continue;
374  int sp = i/2 + 1; //sector processor [1,6]
375 
376  // assign coarse eta value
377  if ( !m_mask ) m_eta[i] = theQualPatternLUT.getCoarseEta(sp,adr);
378  if ( m_eta[i] == 99 ) m_eta[i] = 32;
379  if ( m_eta[i] > 31 ) m_eta[i] -= 64;
380  //m_eta[i] += 32;
381 
382  if ( m_foundPattern.empty() ) continue;
383 
384  // get list of qualified patterns ordered by quality
385  // and compare with found patterns
386  const vector<short>& qualifiedPatterns = theQualPatternLUT.getQualifiedPatterns(sp,adr);
387  vector<short>::const_iterator iter;
388  vector<int>::const_iterator f_iter;
389  for ( iter = qualifiedPatterns.begin(); iter != qualifiedPatterns.end(); iter++ ) {
390  f_iter = find(m_foundPattern.begin(),m_foundPattern.end(),(*iter));
391  // found
392  if ( f_iter != m_foundPattern.end() ) {
394  // assign fine eta value
395  m_fine[i] = true;
396  m_eta[i] = p.eta(); // improved eta
397  if ( m_eta[i] == 99 ) m_eta[i] = 32;
398  if ( m_eta[i] > 31 ) m_eta[i] -= 64;
399  //m_eta[i] += 32;
400  m_pattern[i] = (*f_iter);
401  break;
402  }
403  }
404 
405  }
406 
407  // if both tracks from one sector processor deliver the same track address
408  // both tracks get only a coarse eta value!
409 
410  // loop over sector processors
411  for ( int i = 0; i < 6; i++ ) {
412  int idx1 = 2*i;
413  int idx2 = 2*i+1;
414  int adr1 = m_address[idx1];
415  int adr2 = m_address[idx2];
416  if ( adr1 == 0 || adr2 == 0 ) continue;
417  if ( adr1 == adr2 && !m_mask ) {
418  // both tracks get coarse (default) eta value
419  m_eta[idx1] = theQualPatternLUT.getCoarseEta(i+1,adr1);
420  if ( m_eta[idx1] == 99 ) m_eta[idx1] = 32;
421  if ( m_eta[idx1] > 31 ) m_eta[idx1] -= 64;
422  //m_eta[idx1] += 32;
423  m_pattern[idx1] = 0;
424  m_fine[idx1] = false;
425  m_eta[idx2] = theQualPatternLUT.getCoarseEta(i+1,adr2);
426  if ( m_eta[idx2] == 99 ) m_eta[idx2] = 32;
427  if ( m_eta[idx2] > 31 ) m_eta[idx2] -= 64;
428  //m_eta[idx2] += 32;
429  m_pattern[idx2] = 0;
430  m_fine[idx2] = false;
431  }
432  }
433 
434 }
435 
436 
437 //
438 // assign values to track candidates
439 //
441 
442  for ( int i = 0; i < 12; i++ ) {
443  if ( m_TrackCand[i] ) {
444  if ( m_eta[i] != 99 ) {
445  m_TrackCand[i]->setEta(m_eta[i]);
446  m_TracKCand[i]->setEta(m_eta[i]);
447  }
448  else {
449  // if ( i/2 != 2 ) cerr << "L1MuBMEtaProcessor: assign invalid eta" << " " << m_address[i] << endl;
450  }
451  if ( m_fine[i] ) {
454  // find all contributing track segments
456  vector<const L1MuBMTrackSegEta*> TSeta;
457  const L1MuBMTrackSegEta* ts = 0;
458  for ( int stat = 0; stat < 3; stat++ ) {
459  int wh = p.wheel(stat+1);
460  int pos = p.position(stat+1);
461  if ( pos == 0 ) continue;
462  ts = m_tseta[wh+2 + stat*5];
463  TSeta.push_back(ts);
464  }
465  m_TrackCand[i]->setTSeta(TSeta);
466  m_TracKCand[i]->setTSeta(TSeta);
467  }
468  }
469  }
470 
471 }
472 
473 
474 //
475 // get quality: id [0,26], stat [1,3]
476 //
477 int L1MuBMEtaProcessor::quality(int id, int stat) {
478 
479  // quality codes as defined in CMS Note 2001/027
480  // This QualityPatterns are used to have a defined Quality-Identifier for
481  // all possible found tracks.
482  // Therefore three integer numbers ( Station 1, 2, 3 from left to right )
483  // can have numbers like 0, 1 or 2
484  // 0 ... no hit is given
485  // 1 ... a LTRG is given
486  // 2 ... a HTRG is given
487 
488  const int qualcode[27][3] = { {0,0,0},{1,0,0},{0,1,0},{0,0,1},{2,0,0},
489  {0,2,0},{0,0,2},{1,1,0},{1,0,1},{0,1,1},
490  {2,1,0},{1,2,0},{2,0,1},{1,0,2},{0,2,1},
491  {0,1,2},{2,2,0},{2,0,2},{0,2,2},{1,1,1},
492  {2,1,1},{1,2,1},{1,1,2},{2,2,1},{2,1,2},
493  {1,2,2},{2,2,2} };
494 
495  return qualcode[id][stat-1];
496 
497 }
int i
Definition: DBlmapReader.cc:9
edm::ESHandle< L1TMuonBarrelParams > bmtfParamsHandle
LUT::const_iterator ETFLut_iter
const L1MuBMTrackFinder & m_tf
int trackAddressCode() const
get track address code (for eta track finder)
int quality() const
return quality
bool get_etsoc_chdis_st3(int wh, int sc) const
virtual void run(int bx, const edm::Event &e, const edm::EventSetup &c)
run the Eta Processor
L1MuDTQualPatternLut theQualPatternLUT
L1MuBMTrack * m_TrackCand[12]
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
void receiveData(int bx, const edm::Event &e, const edm::EventSetup &c)
receive data (eta trigger primitives)
L1MuBMTrack * m_TracKCand[12]
L1MuBMAddressArray address() const
get address-array for this muon candidate
Definition: L1MuBMTrack.h:103
int position(int station) const
return position in station [1,3]
virtual void reset()
reset the Eta Processor
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int quality(const int i) const
L1MuDTEtaPattern getPattern(int id) const
get pattern with a given ID
int id() const
return id
int position(const int i) const
L1MuBMTrack * tracK(int id) const
return pointer to muon candidate, index [0,1]
int eta() const
return eta
int getCoarseEta(int sp, int adr) const
get coarse eta value for a given sector processor [1-6] and address [1-22]
void setTSeta(const std::vector< const L1MuBMTrackSegEta * > &tsList)
set eta track segments used to form the muon candidate
Definition: L1MuBMTrack.cc:186
void runEtaMatchingUnit(const edm::EventSetup &c)
run Eta Matching Unit (EMU)
L1MuDTTFMasks l1mudttfmasks
void get(HolderT &iHolder) const
const L1MuBMSectorProcessor * sp(const L1MuBMSecProcId &) const
get a pointer to a Sector Processor
int j
Definition: DBlmapReader.cc:9
ETFLut_iter begin() const
return iterator which points to the first entry of the LUT
void print() const
print muon candidates found by the Eta Processor
std::vector< int > m_foundPattern
bool get_etsoc_chdis_st2(int wh, int sc) const
L1MuBMTrack * track(int id) const
return pointer to muon candidate, index [0,1]
L1MuDTEtaPatternLut theEtaPatternLUT
L1MuBMEtaProcessor(const L1MuBMTrackFinder &, int id, edm::ConsumesCollector &&iC)
constructor
int id() const
return Eta Processor identifier (0-11)
void setFineEtaBit()
set fine eta bit
Definition: L1MuBMTrack.h:154
edm::EDGetTokenT< L1MuDTChambThContainer > m_DTDigiToken
void assign()
assign eta and etaFineBit
void runEtaTrackFinder(const edm::EventSetup &c)
run Eta Track Finder (ETF)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
static int quality(int id, int stat)
get quality code; id [0,26], stat [1,3]
void receiveAddresses()
receive addresses (from 6 Sector Processors)
ETFLut_iter end() const
return iterator which points to the one-past-last entry of the LUT
void setEta(int eta)
set eta-code of muon candidate
Definition: L1MuBMTrack.cc:118
static int position[264][3]
Definition: ReadPGInfo.cc:509
int wheel(int station) const
return wheel number in station [1,3]
std::vector< const L1MuBMTrackSegEta * > m_tseta
virtual ~L1MuBMEtaProcessor()
destructor
tuple cout
Definition: gather_cfg.py:145
Definition: sp.h:21
bool get_etsoc_chdis_st1(int wh, int sc) const
bool empty() const
is it an empty muon candidate?
Definition: L1MuBMTrack.h:97
static bool getEtaTF()
const std::vector< short > & getQualifiedPatterns(int sp, int adr) const
get list of qualified patterns for a given sector processor [1-6] and address [1-22] ...