CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuBMTrackFinder.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuBMTrackFinder
4 //
5 // Description: L1 barrel Muon Trigger Track Finder
6 //
7 //
8 //
9 // Author :
10 // N. Neumeister CERN EP
11 // J. Troconiz UAM Madrid
12 // Modifications:
13 // G. Flouris U.Ioannina
14 //--------------------------------------------------
15 
16 //-----------------------
17 // This Class's Header --
18 //-----------------------
19 
21 
22 //---------------
23 // C++ Headers --
24 //---------------
25 
26 #include <iostream>
27 #include <string>
28 
29 //-------------------------------
30 // Collaborating Class Headers --
31 //-------------------------------
32 
35 
44 
46 
47 using namespace std;
48 
49 //---------------------------------
50 // class L1MuBMTrackFinder
51 //---------------------------------
52 
53 
54 //----------------
55 // Constructors --
56 //----------------
57 //:
59 _cache0(144,-9,8),_cache(36, -9, 8) {
60  // set configuration parameters
61  if ( m_config == 0 ) m_config = new L1MuBMTFConfig(ps);
62 
63  if ( L1MuBMTFConfig::Debug(1) ) cout << endl;
64  if ( L1MuBMTFConfig::Debug(1) ) cout << "**** entering L1MuBMTrackFinder ****" << endl;
65  if ( L1MuBMTFConfig::Debug(1) ) cout << endl;
66 
67  m_spmap = new L1MuBMSecProcMap();
68  m_epvec.reserve(12);
69  m_wsvec.reserve(12);
70  m_ms = 0;
71 
73 }
74 
75 
76 //--------------
77 // Destructor --
78 //--------------
79 
81 
82  delete m_spmap;
83 
84  vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
85  while ( it_ep != m_epvec.end() ) {
86  delete (*it_ep);
87  it_ep++;
88  }
89  m_epvec.clear();
90 
91  vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
92  while ( it_ws != m_wsvec.end() ) {
93  delete (*it_ws);
94  it_ws++;
95  }
96  m_wsvec.clear();
97 
98  delete m_ms;
99 
100  if ( m_config ) delete m_config;
101  m_config = 0;
102 
103 }
104 
105 
106 //--------------
107 // Operations --
108 //--------------
109 
110 //
111 // setup MTTF configuration
112 //
114 
115  // build the barrel Muon Trigger Track Finder
116 
117  if ( L1MuBMTFConfig::Debug(1) ) cout << endl;
118  if ( L1MuBMTFConfig::Debug(1) ) cout << "**** L1MuBMTrackFinder building ****" << endl;
119  if ( L1MuBMTFConfig::Debug(1) ) cout << endl;
120 
121  // create new sector processors
122  for ( int wh = -3; wh <= 3; wh++ ) {
123  if ( wh == 0 ) continue;
124  for ( int sc = 0; sc < 12; sc++ ) {
125  L1MuBMSecProcId tmpspid(wh,sc);
126  L1MuBMSectorProcessor* sp = new L1MuBMSectorProcessor(*this,tmpspid,std::move(iC));
127  if ( L1MuBMTFConfig::Debug(2) ) cout << "creating " << tmpspid << endl;
128  m_spmap->insert(tmpspid,sp);
129  }
130  }
131 
132  // create new eta processors and wedge sorters
133  for ( int sc = 0; sc < 12; sc++ ) {
135  if ( L1MuBMTFConfig::Debug(2) ) cout << "creating Eta Processor " << sc << endl;
136  m_epvec.push_back(ep);
138  if ( L1MuBMTFConfig::Debug(2) ) cout << "creating Wedge Sorter " << sc << endl;
139  m_wsvec.push_back(ws);
140  }
141 
142  // create new muon sorter
143  if ( L1MuBMTFConfig::Debug(2) ) cout << "creating BM Muon Sorter " << endl;
144  m_ms = new L1MuBMMuonSorter(*this);
145 
146 }
147 
148 
149 //
150 // run MTTF
151 //
153 
155  int bx_min = L1MuBMTFConfig::getBxMin();
156  int bx_max = L1MuBMTFConfig::getBxMax();
157 
158  //Resize the bx range according to the config file
159  _cache0.setBXRange(bx_min,bx_max);
160  _cache.setBXRange(bx_min,bx_max);
161 
162 
163 
164 // run the barrel Muon Trigger Track Finder
166  e.getByToken(m_DTDigiToken,dttrig);
167  if ( dttrig->getContainer()->size() == 0 ) return;
168 
169  if ( L1MuBMTFConfig::Debug(2) ) cout << endl;
170  if ( L1MuBMTFConfig::Debug(2) ) cout << "**** L1MuBMTrackFinder processing ------****" << endl;
171  if ( L1MuBMTFConfig::Debug(2) ) cout << endl;
172 
173  for ( int bx = bx_min; bx <= bx_max; bx++ ) {
174  if ( dttrig->bxEmpty(bx) ) continue;
175 
176  if ( L1MuBMTFConfig::Debug(2) ) cout << "L1MuBMTrackFinder processing bunch-crossing : " << bx << endl;
177 
178  // reset MTTF
179  reset();
180 
181  // run sector processors
183  while ( it_sp != m_spmap->end() ) {
184  if ( L1MuBMTFConfig::Debug(2) ) cout << "running "
185  << (*it_sp).second->id() << endl;
186  if ( (*it_sp).second ) (*it_sp).second->run(bx,e,c);
187  if ( L1MuBMTFConfig::Debug(2) && (*it_sp).second ) (*it_sp).second->print();
188  it_sp++;
189  }
190 
191  // run eta processors
192  vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
193  while ( it_ep != m_epvec.end() ) {
194  if ( L1MuBMTFConfig::Debug(2) ) cout << "running Eta Processor "
195  << (*it_ep)->id() << endl;
196  if ( *it_ep ) (*it_ep)->run(bx,e,c);
197  if ( L1MuBMTFConfig::Debug(2) && *it_ep ) (*it_ep)->print();
198  it_ep++;
199  }
200 
201  // read sector processors
202  it_sp = m_spmap->begin();
203  while ( it_sp != m_spmap->end() ) {
204  if ( L1MuBMTFConfig::Debug(2) ) cout << "reading "
205  << (*it_sp).second->id() << endl;
206  for ( int number = 0; number < 2; number++ ) {
207  const L1MuBMTrack* cand = (*it_sp).second->tracK(number);
208 
209  if ( cand && !cand->empty() ) {
210 
212 
213  if(cand->hwEta()>-33 || cand->hwEta()<32 )
214  rmc.setHwEta(eta_map[cand->hwEta()]);
215  else
216  rmc.setHwEta(-1000);
217 
218  rmc.setHwPt(cand->pt());
219  int abs_add_1 = setAdd(1,cand->address(1));
220  int abs_add_2 = setAdd(2,cand->address(2));
221  int abs_add_3 = setAdd(3,cand->address(3));
222  int abs_add_4 = setAdd(4,cand->address(4));
223 
224  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelSide, cand->spid().wheel() < 0); // this has to be set!
225  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelNum, abs(cand->spid().wheel()) - 1); // this has to be set!
234  rmc.setHwHF(cand->hwHF());
235 
236  rmc.setHwPhi(cand->hwPhi());
237  rmc.setHwSign(cand->hwSign() == 1 ? 0 : 1 );
238  rmc.setHwSignValid(cand->hwSignValid());
239  rmc.setHwQual(cand->hwQual());
241 
242  _cache0.push_back(cand->bx(), rmc);
243 
244  }
245  }
246  it_sp++;
247  }
248 
249  // run wedge sorters
250  vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
251  while ( it_ws != m_wsvec.end() ) {
252  if ( L1MuBMTFConfig::Debug(2) ) cout << "running Wedge Sorter "
253  << (*it_ws)->id() << endl;
254  if ( *it_ws ) (*it_ws)->run();
255  if ( L1MuBMTFConfig::Debug(2) && *it_ws ) (*it_ws)->print();
256 
257  // store found track candidates in container (cache)
258  if ( (*it_ws)->anyMuonCands() ) {
259  const vector<const L1MuBMTrack*>& mttf_cont = (*it_ws)->tracks();
260 
261  vector<const L1MuBMTrack*>::const_iterator iter;
262  for ( iter = mttf_cont.begin(); iter != mttf_cont.end(); iter++ ) {
263  if(!*iter) continue;
265  rmc.setHwPt((*iter)->hwPt());
266  int abs_add_1 = setAdd(1,(*iter)->address(1));
267  int abs_add_2 = setAdd(2,(*iter)->address(2));
268  int abs_add_3 = setAdd(3,(*iter)->address(3));
269  int abs_add_4 = setAdd(4,(*iter)->address(4));
270 
271  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelSide, (*iter)->spid().wheel() < 0); // this has to be set!
272  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelNum, abs((*iter)->spid().wheel()) - 1); // this has to be set!
281  rmc.setHwHF((*iter)->hwHF());
282 
283  rmc.setHwPhi((*iter)->hwPhi());
284  if((*iter)->hwEta()>-33 || (*iter)->hwEta()<32 )
285  rmc.setHwEta(eta_map[(*iter)->hwEta()]);
286  else
287  rmc.setHwEta(-1000);
288  rmc.setHwSign((*iter)->hwSign() == 1 ? 0 : 1);
289  rmc.setHwSignValid((*iter)->hwSignValid());
290  rmc.setHwQual((*iter)->hwQual());
291  rmc.setTFIdentifiers((*iter)->spid().sector(),l1t::tftype::bmtf);
292 
293  if ( *iter ){ _cache.push_back((*iter)->bx(), rmc);}
294  }
295  }
296 
297  it_ws++;
298 
299  }//end wedge sorting
300 
301  /* // run muon sorter
302  if ( L1MuBMTFConfig::Debug(2) ) cout << "running BM Muon Sorter" << endl;
303  if ( m_ms ) m_ms->run();
304  if ( L1MuBMTFConfig::Debug(2) && m_ms ) m_ms->print();
305 
306 
307  // store found track candidates in container (cache)
308  if ( m_ms->numberOfTracks() > 0 ) {
309  const vector<const L1MuBMTrack*>& mttf_cont = m_ms->tracks();
310  vector<const L1MuBMTrack*>::const_iterator iter;
311  for ( iter = mttf_cont.begin(); iter != mttf_cont.end(); iter++ ) {
312 
313  l1t::RegionalMuonCand rmc;
314  rmc.setHwPt((*iter)->hwPt());
315  int abs_add_1 = setAdd(1,(*iter)->address(1));
316  int abs_add_2 = setAdd(2,(*iter)->address(2));
317  int abs_add_3 = setAdd(3,(*iter)->address(3));
318  int abs_add_4 = setAdd(4,(*iter)->address(4));
319 
320  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelSide, (*iter)->spid().wheel() < 0); // this has to be set!
321  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelNum, abs((*iter)->spid().wheel()) - 1); // this has to be set!
322  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat1, abs_add_1);
323  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat2, abs_add_2);
324  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat3, abs_add_3);
325  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat4, abs_add_4);
326  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat1, 0);
327  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat2, 0);
328  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat3, 0);
329  rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat4, 0);
330 
331 
332  rmc.setHwPhi((*iter)->hwPhi());
333  if((*iter)->hwEta()>-33 || (*iter)->hwEta()<32 )
334  rmc.setHwEta(eta_map[(*iter)->hwEta()]);
335  else
336  rmc.setHwEta(-1000);
337  rmc.setHwSign((*iter)->hwSign() == 1 ? 0 : 1);
338  rmc.setHwSignValid((*iter)->hwSignValid());
339  rmc.setHwQual((*iter)->hwQual());
340  rmc.setTFIdentifiers((*iter)->spid().sector(),l1t::tftype::bmtf);
341 
342  if ( *iter ){ _cache.push_back((*iter)->bx(), rmc);}
343  }
344  }
345  */
346 
347  }//end of bx loop
348 }
349 
350 
351 //
352 // reset MTTF
353 //
355 
357  while ( it_sp != m_spmap->end() ) {
358  if ( (*it_sp).second ) (*it_sp).second->reset();
359  it_sp++;
360  }
361 
362  vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
363  while ( it_ep != m_epvec.end() ) {
364  if ( *it_ep ) (*it_ep)->reset();
365  it_ep++;
366  }
367 
368  vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
369  while ( it_ws != m_wsvec.end() ) {
370  if ( *it_ws ) (*it_ws)->reset();
371  it_ws++;
372  }
373 
374  if ( m_ms ) m_ms->reset();
375 
376 }
377 
378 
379 //
380 // return Sector Processor container
381 //
383 
384  return m_spmap->sp(id);
385 
386 }
387 
388 
389 //
390 // return number of muon candidates found by the barrel MTTF
391 //
393  int num = 0;
394  for (int bx = _cache.getFirstBX(); bx < _cache.getLastBX(); ++bx) {
395  num += _cache.size(bx);
396  }
397  return num;
398 }
399 
400 
402 
403  return _cache.begin(bx);
404 
405 }
406 
407 
409 
410  return _cache.end(bx);
411 
412 }
413 
414 
416 
417  _cache.clear();
418  _cache0.clear();
419 
420 }
421 
422 
423 //
424 // return number of muon candidates found by the barrel MTTF at a given bx
425 //
427  return _cache.size(0);
428 }
429 
430 
431 //
432 // Convert Relative to Absolute Track Addresses
433 //
434 
435 int L1MuBMTrackFinder::setAdd(int ust, int rel_add) {
436  unsigned int uadd = rel_add;
437 
438  switch (uadd) {
439  case 0: { rel_add = 8; break; }
440  case 1: { rel_add = 9; break; }
441  case 2: { rel_add = 0; break; }
442  case 3: { rel_add = 1; break; }
443  case 8: { rel_add = 10; break; }
444  case 9: { rel_add = 11; break; }
445  case 10: { rel_add = 2; break; }
446  case 11: { rel_add = 3; break; }
447  case 4: { rel_add = 12; break; }
448  case 5: { rel_add = 13; break; }
449  case 6: { rel_add = 4; break; }
450  case 7: { rel_add = 5; break; }
451  case 15: { rel_add = 15; break; }
452  default: { rel_add = 15; break; }
453  }
454 
455  if (ust!=1) return rel_add;
456 
457  switch (uadd) {
458  case 0: { rel_add = 2; break; }
459  case 1: { rel_add = 1; break; }
460  case 15: { rel_add = 3; break; }
461  default: { rel_add = 3; break; }
462  }
463  return rel_add;
464 }
465 
466 
467 // static data members
468 
static int getBxMax()
const_iterator end(int bx) const
L1MuBMSectorProcessor * sp(const L1MuBMSecProcId &) const
return pointer to Sector Processor
edm::EDGetTokenT< L1MuDTChambPhContainer > m_DTDigiToken
unsigned int pt() const
get pt-code (5 bits)
Definition: L1MuBMTrack.h:76
void setHwPhi(int bits)
Set compressed relative phi as transmitted by hardware LSB = 2*pi/576 (8 bits)
int numberOfTracks()
get number of muon candidates found by the barrel MTTF
unsigned size(int bx) const
const int hwSignValid() const
Get charge sign valid bit (0 - not valid (high pT muon); 1 - valid)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
L1MuBMMuonSorter * m_ms
BM Muon Sorter.
L1MuBMAddressArray address() const
get address-array for this muon candidate
Definition: L1MuBMTrack.h:103
const L1MuBMSecProcId & spid() const
return Sector Processor in which the muon candidate was found
Definition: L1MuBMTrack.h:100
SPmap::iterator SPmap_iter
const L1MuBMWedgeSorter * ws(int id) const
get a pointer to a Wedge Sorter, index [0-11]
int sector() const
return sector number
const int hwQual() const
Get quality code.
std::map< int, int > eta_map
L1MuBMTrackFinder(const edm::ParameterSet &ps, edm::ConsumesCollector &&iC)
constructor
virtual void reset()
reset Muon Sorter
void setTFIdentifiers(int processor, tftype trackFinder)
Set the processor ID, track-finder type. From these two, the link is set.
def move
Definition: eostools.py:510
TFtracks_const_iter begin(int bx)
static int getBxMin()
static edm::InputTag getBMDigiInputTag()
std::vector< L1MuBMWedgeSorter * > m_wsvec
Wedge Sorters.
void setTrackSubAddress(bmtfAddress subAddress, int value)
Set a part of the muon candidates track address; specialised for BMTF.
const L1MuBMSectorProcessor * sp(const L1MuBMSecProcId &) const
get a pointer to a Sector Processor
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const int hwHF() const
Get HF (halo / fine eta) bit (EMTF: halo -&gt; 1; BMTF: fine eta -&gt; 1)
void setHwHF(bool bit)
Set HF (halo / fine eta) bit (EMTF: halo -&gt; 1; BMTF: fine eta -&gt; 1)
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
SPmap_iter begin()
return iterator which points to the first entry of the container
void insert(const L1MuBMSecProcId &, L1MuBMSectorProcessor *sp)
insert a Sector Processor into the container
const int hwPhi() const
Get compressed local phi (returned int * 2*pi/576 = local phi in rad)
int bx() const
get the bunch crossing for this muon candidate
Definition: L1MuBMTrack.h:109
void run(const edm::Event &e, const edm::EventSetup &c)
run the barrel MTTF
static L1MuBMTFConfig * m_config
Track Finder configuration.
void setHwQual(int bits)
Set compressed quality code as transmitted by hardware (4 bits)
void setHwPt(int bits)
Set compressed pT as transmitted by hardware LSB = 0.5 (9 bits)
l1t::RegionalMuonCandBxCollection _cache0
void setHwEta(int bits)
Set compressed eta as transmitted by hardware LSB = 0.010875 (9 bits)
int getFirstBX() const
TFtracks_const_iter end(int bx)
std::vector< L1MuBMEtaProcessor * > m_epvec
Eta Processors.
void clear()
void setDefaultsES(const edm::EventSetup &c)
void setBXRange(int bxFirst, int bxLast)
static bool Debug()
l1t::RegionalMuonCandBxCollection _cache
l1t::RegionalMuonCandBxCollection::const_iterator TFtracks_const_iter
container for muon candidates
int setAdd(int ust, int rel_add)
int getLastBX() const
const int hwSign() const
Get charge sign bit (charge = (-1)^(sign))
void setHwSignValid(int bits)
Set whether charge measurement is valid (0 for high pT muons)
void setup(edm::ConsumesCollector &&)
build the structure of the barrel MTTF
tuple cout
Definition: gather_cfg.py:145
Definition: sp.h:21
SPmap_iter end()
return iterator which points to the one-past-last entry of the container
const_iterator begin(int bx) const
bool empty() const
is it an empty muon candidate?
Definition: L1MuBMTrack.h:97
const L1MuBMEtaProcessor * ep(int id) const
get a pointer to an Eta Processor, index [0-11]
L1MuBMSecProcMap * m_spmap
Sector Processors.
void push_back(int bx, T object)
void setHwSign(int bits)
Set charge sign bit (charge = (-1)^(sign))
virtual ~L1MuBMTrackFinder()
destructor
void reset()
reset the barrel MTTF
int wheel() const
return wheel number