CMS 3D CMS Logo

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