CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 //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 
49 
53 
54 using namespace std;
55 
56 // --------------------------------
57 // class L1MuBMEtaProcessor
58 //---------------------------------
59 
60 //----------------
61 // Constructors --
62 //----------------
63 
65  : m_tf(tf),
66  m_epid(id),
67  m_foundPattern(0),
68  m_tseta(15),
69  m_bmtfParamsToken(iC.esConsumes()),
70  m_DTDigiToken(iC.consumes<L1MuDTChambThContainer>(L1MuBMTFConfig::getBMThetaDigiInputTag())) {
71  m_tseta.reserve(15);
72 }
73 
74 //--------------
75 // Destructor --
76 //--------------
77 
79 
80 //--------------
81 // Operations --
82 //--------------
83 
84 //
85 // run Eta Processor
86 //
88  auto const& params = c.getData(m_bmtfParamsToken);
90  receiveData(bx, e, params);
92  }
93 
96 
97  assign();
98 }
99 
100 //
101 // reset Eta Processor
102 //
104  vector<const L1MuBMTrackSegEta*>::iterator iter = m_tseta.begin();
105  while (iter != m_tseta.end()) {
106  if (*iter) {
107  delete *iter;
108  *iter = nullptr;
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] = nullptr;
121  m_TracKCand[i] = nullptr;
122  }
123 
124  m_foundPattern.clear();
125 
126  m_mask = true;
127 }
128 
129 //
130 // print track candidates found in Eta Processor
131 //
133  bool empty1 = true;
134  for (int i = 0; i < 15; i++) {
135  empty1 &= (m_tseta[i] == nullptr || m_tseta[i]->empty());
136  }
137 
138  bool empty2 = true;
139  for (int i = 0; i < 12; i++) {
140  empty2 &= (m_address[i] == 0);
141  }
142 
143  if (!empty1 || !empty2) {
144  cout << "Eta processor " << m_epid << " : " << endl;
145 
146  // print local pattern
147  if (!empty1) {
148  cout << "Local pattern : " << endl;
149  for (int i = 0; i < 15; i++) {
150  if ((i + 5) % 5 == 0)
151  cout << "station " << m_tseta[i]->station() << " : ";
152  bitset<7> pos(m_tseta[i]->position());
153  bitset<7> qua(m_tseta[i]->quality());
154  for (int j = 6; j >= 0; j--) {
155  cout << pos[j] + qua[j];
156  }
157  cout << " ";
158  if ((i + 1) % 5 == 0)
159  cout << endl;
160  }
161  cout << "Found patterns :" << endl;
162  vector<int>::const_iterator iter;
163  for (iter = m_foundPattern.begin(); iter != m_foundPattern.end(); iter++) {
165  int qualitycode = p.quality();
166  cout << "ID = " << setw(4) << p.id() << " "
167  << "eta = " << setw(3) << p.eta() << " "
168  << "quality = " << setw(2) << qualitycode << " (" << quality(qualitycode, 1) << " "
169  << quality(qualitycode, 2) << " " << quality(qualitycode, 3) << ")";
170  for (int i = 0; i < 12; i++) {
171  if (m_pattern[i] == p.id())
172  cout << " <--";
173  }
174  cout << endl;
175  }
176  }
177 
178  cout << "Received addresses : " << endl;
179  for (int i = 0; i < 12; i++)
180  cout << setw(3) << m_address[i] << " ";
181  cout << endl;
182 
183  if (!empty1) {
184  cout << "Matched patterns : " << endl;
185  for (int i = 0; i < 12; i++) {
186  if (m_fine[i]) {
188  int fineeta = p.eta();
189  int coarseeta = theQualPatternLUT.getCoarseEta(i / 2 + 1, m_address[i]);
190  cout << "Index = " << setw(2) << i << ", "
191  << "address = " << setw(2) << m_address[i] << " --> "
192  << "pattern = " << setw(4) << m_pattern[i] << " "
193  << "eta (coarse) = " << setw(3) << coarseeta << " "
194  << "eta (fine) = " << setw(3) << fineeta << " "
195  << "quality = " << setw(2) << p.quality() << endl;
196  }
197  }
198  }
199 
200  cout << "Eta values and fine bits : " << endl;
201  for (int i = 0; i < 12; i++)
202  cout << setw(3) << m_eta[i] << " ";
203  cout << endl;
204  for (int i = 0; i < 12; i++)
205  cout << setw(3) << m_fine[i] << " ";
206  cout << endl;
207  }
208 }
209 
210 //
211 // receive data ( 15*3 BBMX eta trigger primitives )
212 //
213 void L1MuBMEtaProcessor::receiveData(int bx, const edm::Event& e, const L1TMuonBarrelParams& bmtfParams) {
214  msks = bmtfParams.l1mudttfmasks;
215  theEtaPatternLUT.m_lut = bmtfParams.lutparams_.eta_lut_; //l1mudttfetaplut; // ETF look-up table
216  theQualPatternLUT.m_lut = bmtfParams.lutparams_.qp_lut_; //l1mudttfqualplut; // EMU look-up tables
217 
219  e.getByToken(m_DTDigiToken, dttrig);
220 
221  // const int bx_offset = dttrig->correctBX();
222  int bx_offset = 0;
223  bx = bx + bx_offset;
224 
225  //
226  // get 5*3 eta track segments
227  //
228  int sector = m_epid;
229  for (int stat = 1; stat <= 3; stat++) {
230  for (int wheel = -2; wheel <= 2; wheel++) {
231  L1MuDTChambThDigi const* tseta = dttrig->chThetaSegm(wheel, stat, sector, bx);
232  bitset<7> pos;
233  bitset<7> qual;
234 
235  int lwheel = wheel + 1;
236  if (wheel < 0)
237  lwheel = wheel - 1;
238 
239  bool masked = false;
240  if (stat == 1)
241  masked = msks.get_etsoc_chdis_st1(lwheel, sector);
242  if (stat == 2)
243  masked = msks.get_etsoc_chdis_st2(lwheel, sector);
244  if (stat == 3)
245  masked = msks.get_etsoc_chdis_st3(lwheel, sector);
246 
247  if (!masked)
248  m_mask = false;
249 
250  if (tseta && !masked) {
251  if (wheel == -2 || wheel == -1 ||
252  (wheel == 0 && (sector == 0 || sector == 3 || sector == 4 || sector == 7 || sector == 8 || sector == 11))) {
253  for (int i = 0; i < 7; i++) {
254  if (tseta->position(i))
255  pos.set(6 - i);
256  if (tseta->quality(i))
257  qual.set(6 - i);
258  }
259  } else {
260  for (int i = 0; i < 7; i++) {
261  if (tseta->position(i))
262  pos.set(i);
263  if (tseta->quality(i))
264  qual.set(i);
265  }
266  }
267  }
268 
269  const L1MuBMTrackSegEta* tmpts =
270  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 // receive track addresses from 6 Sector Processors
278 //
280  // get track address code of all track segments
281  // 6*2 times 5 bits; valid range [1-22]
282 
283  int sector = m_epid;
284 
285  int i = 0;
286  for (int wheel = -3; wheel <= 3; wheel++) {
287  if (wheel == 0)
288  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 // run Eta Track Finder (ETF)
307 //
309  theEtaPatternLUT.m_lut = bmtfParams.lutparams_.eta_lut_; //l1mudttfetaplut; // ETF look-up table
310 
311  // check if there are any data
312  bool empty = true;
313  for (int i = 0; i < 15; i++) {
314  empty &= m_tseta[i]->empty();
315  }
316  if (empty)
317  return;
318 
319  // Pattern comparator:
320  // loop over all patterns and compare with local chamber pattern
321  // result : list of valid pattern IDs ( m_foundPattern )
323  while (it != theEtaPatternLUT.end()) {
324  const L1MuDTEtaPattern pattern = (*it).second;
325  int qualitycode = pattern.quality();
326 
327  bool good = true;
328 
329  for (int station = 0; station < 3; station++) {
330  int q = quality(qualitycode, station + 1);
331  int wheel = pattern.wheel(station + 1);
332  int bin = pattern.position(station + 1);
333  if (bin == 0)
334  continue;
335  bitset<7> pos = m_tseta[wheel + 2 + station * 5]->position();
336  bitset<7> qual = m_tseta[wheel + 2 + station * 5]->quality();
337  // compare position
338  good &= pos.test(bin - 1);
339  // compare quality
340  if (q == 2)
341  good &= qual.test(bin - 1);
342  }
343 
344  if (good)
345  m_foundPattern.push_back(pattern.id());
346 
347  it++;
348  }
349 }
350 
351 //
352 // run Eta Matching Unit (EMU)
353 //
355  theQualPatternLUT.m_lut = bmtfParams.lutparams_.qp_lut_; //l1mudttfqualplut; // EMU look-up tables
356 
357  // loop over all addresses
358  for (int i = 0; i < 12; i++) {
359  int adr = m_address[i];
360  if (adr == 0)
361  continue;
362  int sp = i / 2 + 1; //sector processor [1,6]
363 
364  // assign coarse eta value
365  if (!m_mask)
367 
368  if (m_foundPattern.empty())
369  continue;
370 
371  // get list of qualified patterns ordered by quality
372  // and compare with found patterns
373  const vector<short>& qualifiedPatterns = theQualPatternLUT.getQualifiedPatterns(sp, adr);
374  vector<short>::const_iterator iter;
375  vector<int>::const_iterator f_iter;
376  for (iter = qualifiedPatterns.begin(); iter != qualifiedPatterns.end(); iter++) {
377  f_iter = find(m_foundPattern.begin(), m_foundPattern.end(), (*iter));
378  // found
379  if (f_iter != m_foundPattern.end()) {
381  // assign fine eta value
382  m_fine[i] = true;
383  m_eta[i] = p.eta(); // improved eta
384  ;
385  m_pattern[i] = (*f_iter);
386  break;
387  }
388  }
389  }
390 
391  // if both tracks from one sector processor deliver the same track address
392  // both tracks get only a coarse eta value!
393 
394  // loop over sector processors
395  for (int i = 0; i < 6; i++) {
396  int idx1 = 2 * i;
397  int idx2 = 2 * i + 1;
398  int adr1 = m_address[idx1];
399  int adr2 = m_address[idx2];
400  if (adr1 == 0 || adr2 == 0)
401  continue;
402  if (adr1 == adr2 && !m_mask) {
403  // both tracks get coarse (default) eta value
404  m_eta[idx1] = theQualPatternLUT.getCoarseEta(i + 1, adr1);
405  m_pattern[idx1] = 0;
406  m_fine[idx1] = false;
407  m_eta[idx2] = theQualPatternLUT.getCoarseEta(i + 1, adr2);
408 
409  m_pattern[idx2] = 0;
410  m_fine[idx2] = false;
411  }
412  }
413 }
414 
415 //
416 // assign values to track candidates
417 //
419  for (int i = 0; i < 12; i++) {
420  if (m_TrackCand[i]) {
421  if (m_eta[i] != 99) {
422  m_TrackCand[i]->setEta(m_eta[i]);
423  m_TracKCand[i]->setEta(m_eta[i]);
424  } else {
425  // if ( i/2 != 2 ) cerr << "L1MuBMEtaProcessor: assign invalid eta" << " " << m_address[i] << endl;
426  }
427  if (m_fine[i]) {
430  // find all contributing track segments
432  vector<const L1MuBMTrackSegEta*> TSeta;
433  const L1MuBMTrackSegEta* ts = nullptr;
434  for (int stat = 0; stat < 3; stat++) {
435  int wh = p.wheel(stat + 1);
436  int pos = p.position(stat + 1);
437  if (pos == 0)
438  continue;
439  ts = m_tseta[wh + 2 + stat * 5];
440  TSeta.push_back(ts);
441  }
442  m_TrackCand[i]->setTSeta(TSeta);
443  m_TracKCand[i]->setTSeta(TSeta);
444  }
445  }
446  }
447 }
448 
449 //
450 // get quality: id [0,26], stat [1,3]
451 //
453  // quality codes as defined in CMS Note 2001/027
454  // This QualityPatterns are used to have a defined Quality-Identifier for
455  // all possible found tracks.
456  // Therefore three integer numbers ( Station 1, 2, 3 from left to right )
457  // can have numbers like 0, 1 or 2
458  // 0 ... no hit is given
459  // 1 ... a LTRG is given
460  // 2 ... a HTRG is given
461 
462  const int qualcode[27][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {2, 0, 0}, {0, 2, 0}, {0, 0, 2},
463  {1, 1, 0}, {1, 0, 1}, {0, 1, 1}, {2, 1, 0}, {1, 2, 0}, {2, 0, 1}, {1, 0, 2},
464  {0, 2, 1}, {0, 1, 2}, {2, 2, 0}, {2, 0, 2}, {0, 2, 2}, {1, 1, 1}, {2, 1, 1},
465  {1, 2, 1}, {1, 1, 2}, {2, 2, 1}, {2, 1, 2}, {1, 2, 2}, {2, 2, 2}};
466 
467  return qualcode[id][stat - 1];
468 }
edm::ESGetToken< L1TMuonBarrelParams, L1TMuonBarrelParamsRcd > m_bmtfParamsToken
const edm::EventSetup & c
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:539
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:97
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:19
int quality(const int i) const
L1MuBMTEtaPatternLut theEtaPatternLUT
int id() const
return id
int position(const int i) const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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:160
L1MuDTTFMasks l1mudttfmasks
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
void receiveData(int bx, const edm::Event &e, const L1TMuonBarrelParams &params)
receive data (eta trigger primitives)
bool get_etsoc_chdis_st2(int wh, int sc) const
L1MuBMTrack * track(int id) const
return pointer to muon candidate, index [0,1]
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:151
edm::EDGetTokenT< L1MuDTChambThContainer > m_DTDigiToken
void assign()
assign eta and etaFineBit
void runEtaMatchingUnit(const L1TMuonBarrelParams &params)
run Eta Matching Unit (EMU)
auto const good
min quality of good
void runEtaTrackFinder(const L1TMuonBarrelParams &params)
run Eta Track Finder (ETF)
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:289
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:144
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:91
static bool getEtaTF()
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
L1MuBMTQualPatternLut theQualPatternLUT
ETFLut_iter end() const
return iterator which points to the one-past-last entry of the LUT