File indexing completed on 2024-04-06 12:20:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "L1Trigger/L1TMuonBarrel/interface/L1MuBMTrackFinder.h"
0022
0023
0024
0025
0026
0027 #include <iostream>
0028 #include <string>
0029
0030
0031
0032
0033
0034 #include <DataFormats/Common/interface/Handle.h>
0035 #include <FWCore/Framework/interface/Event.h>
0036
0037 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMTFConfig.h"
0038 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMSecProcMap.h"
0039 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMSectorProcessor.h"
0040 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMEtaProcessor.h"
0041 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMWedgeSorter.h"
0042 #include "L1Trigger/L1TMuonBarrel/src/L1MuBMMuonSorter.h"
0043
0044 #include "DataFormats/L1TMuon/interface/BMTF/L1MuBMSecProcId.h"
0045 #include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
0046 #include "DataFormats/L1TMuon/interface/L1MuBMTrack.h"
0047 #include "DataFormats/L1TMuon/interface/L1MuBMTrackSegPhi.h"
0048 #include "DataFormats/L1TMuon/interface/L1MuBMTrackSegEta.h"
0049
0050 using namespace std;
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 L1MuBMTrackFinder::L1MuBMTrackFinder(const edm::ParameterSet& ps, edm::ConsumesCollector&& iC)
0061 : _cache0(144, -9, 8), _cache(36, -9, 8) {
0062
0063 if (not m_config) {
0064 auto temp = std::make_shared<L1MuBMTFConfig>(ps);
0065 std::shared_ptr<L1MuBMTFConfig> empty;
0066 std::atomic_compare_exchange_strong(&m_config, &empty, temp);
0067 }
0068
0069 if (L1MuBMTFConfig::Debug(1))
0070 cout << endl;
0071 if (L1MuBMTFConfig::Debug(1))
0072 cout << "**** entering L1MuBMTrackFinder ****" << endl;
0073 if (L1MuBMTFConfig::Debug(1))
0074 cout << endl;
0075
0076 m_spmap = new L1MuBMSecProcMap();
0077 m_epvec.reserve(12);
0078 m_wsvec.reserve(12);
0079 m_ms = nullptr;
0080
0081 m_DTDigiToken = iC.consumes<L1MuDTChambPhContainer>(L1MuBMTFConfig::getBMDigiInputTag());
0082 m_mbParamsToken = iC.esConsumes();
0083 }
0084
0085
0086
0087
0088
0089 L1MuBMTrackFinder::~L1MuBMTrackFinder() {
0090 delete m_spmap;
0091
0092 vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
0093 while (it_ep != m_epvec.end()) {
0094 delete (*it_ep);
0095 it_ep++;
0096 }
0097 m_epvec.clear();
0098
0099 vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
0100 while (it_ws != m_wsvec.end()) {
0101 delete (*it_ws);
0102 it_ws++;
0103 }
0104 m_wsvec.clear();
0105
0106 delete m_ms;
0107 }
0108
0109
0110
0111
0112
0113
0114
0115
0116 void L1MuBMTrackFinder::setup(edm::ConsumesCollector&& iC) {
0117
0118
0119 if (L1MuBMTFConfig::Debug(1))
0120 cout << endl;
0121 if (L1MuBMTFConfig::Debug(1))
0122 cout << "**** L1MuBMTrackFinder building ****" << endl;
0123 if (L1MuBMTFConfig::Debug(1))
0124 cout << endl;
0125
0126
0127 for (int wh = -3; wh <= 3; wh++) {
0128 if (wh == 0)
0129 continue;
0130 for (int sc = 0; sc < 12; sc++) {
0131 L1MuBMSecProcId tmpspid(wh, sc);
0132 L1MuBMSectorProcessor* sp = new L1MuBMSectorProcessor(*this, tmpspid, std::move(iC));
0133 if (L1MuBMTFConfig::Debug(2))
0134 cout << "creating " << tmpspid << endl;
0135 m_spmap->insert(tmpspid, sp);
0136 }
0137 }
0138
0139
0140 for (int sc = 0; sc < 12; sc++) {
0141 L1MuBMEtaProcessor* ep = new L1MuBMEtaProcessor(*this, sc, std::move(iC));
0142 if (L1MuBMTFConfig::Debug(2))
0143 cout << "creating Eta Processor " << sc << endl;
0144 m_epvec.push_back(ep);
0145 L1MuBMWedgeSorter* ws = new L1MuBMWedgeSorter(*this, sc);
0146 if (L1MuBMTFConfig::Debug(2))
0147 cout << "creating Wedge Sorter " << sc << endl;
0148 m_wsvec.push_back(ws);
0149 }
0150
0151
0152 if (L1MuBMTFConfig::Debug(2))
0153 cout << "creating BM Muon Sorter " << endl;
0154 m_ms = new L1MuBMMuonSorter(*this);
0155 }
0156
0157
0158
0159
0160 void L1MuBMTrackFinder::run(const edm::Event& e, const edm::EventSetup& c) {
0161 m_config->setDefaultsES(c.getData(m_mbParamsToken));
0162 int bx_min = L1MuBMTFConfig::getBxMin();
0163 int bx_max = L1MuBMTFConfig::getBxMax();
0164
0165
0166 _cache0.setBXRange(bx_min, bx_max);
0167 _cache.setBXRange(bx_min, bx_max);
0168
0169
0170 edm::Handle<L1MuDTChambPhContainer> dttrig;
0171 e.getByToken(m_DTDigiToken, dttrig);
0172 if (dttrig->getContainer()->empty())
0173 return;
0174
0175 if (L1MuBMTFConfig::Debug(2))
0176 cout << endl;
0177 if (L1MuBMTFConfig::Debug(2))
0178 cout << "**** L1MuBMTrackFinder processing ------****" << endl;
0179 if (L1MuBMTFConfig::Debug(2))
0180 cout << endl;
0181
0182 for (int bx = bx_min; bx <= bx_max; bx++) {
0183 if (dttrig->bxEmpty(bx))
0184 continue;
0185
0186 if (L1MuBMTFConfig::Debug(2))
0187 cout << "L1MuBMTrackFinder processing bunch-crossing : " << bx << endl;
0188
0189
0190 reset();
0191
0192
0193 L1MuBMSecProcMap::SPmap_iter it_sp = m_spmap->begin();
0194 while (it_sp != m_spmap->end()) {
0195 if (L1MuBMTFConfig::Debug(2))
0196 cout << "running " << (*it_sp).second->id() << endl;
0197 if ((*it_sp).second)
0198 (*it_sp).second->run(bx, e, c);
0199 if (L1MuBMTFConfig::Debug(2) && (*it_sp).second)
0200 (*it_sp).second->print();
0201 it_sp++;
0202 }
0203
0204
0205 vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
0206 while (it_ep != m_epvec.end()) {
0207 if (L1MuBMTFConfig::Debug(2))
0208 cout << "running Eta Processor " << (*it_ep)->id() << endl;
0209 if (*it_ep)
0210 (*it_ep)->run(bx, e, c);
0211 if (L1MuBMTFConfig::Debug(2) && *it_ep)
0212 (*it_ep)->print();
0213 it_ep++;
0214 }
0215
0216
0217 it_sp = m_spmap->begin();
0218 while (it_sp != m_spmap->end()) {
0219 if (L1MuBMTFConfig::Debug(2))
0220 cout << "reading " << (*it_sp).second->id() << endl;
0221 for (int number = 0; number < 2; number++) {
0222 const L1MuBMTrack* cand = (*it_sp).second->tracK(number);
0223
0224 if (cand && !cand->empty()) {
0225 l1t::RegionalMuonCand rmc;
0226
0227
0228 if (cand->hwEta() > -117 || cand->hwEta() < 117)
0229 rmc.setHwEta(cand->hwEta());
0230 else
0231 rmc.setHwEta(-1000);
0232
0233 rmc.setHwPt(cand->pt());
0234 int abs_add_1 = setAdd(1, cand->address(1));
0235 int abs_add_2 = setAdd(2, cand->address(2));
0236 int abs_add_3 = setAdd(3, cand->address(3));
0237 int abs_add_4 = setAdd(4, cand->address(4));
0238
0239 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelSide, cand->spid().wheel() < 0);
0240 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelNum,
0241 abs(cand->spid().wheel()) - 1);
0242 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat1, abs_add_1);
0243 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat2, abs_add_2);
0244 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat3, abs_add_3);
0245 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat4, abs_add_4);
0246 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat1, 0);
0247 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat2, 0);
0248 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat3, 0);
0249 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat4, 0);
0250 rmc.setHwHF(cand->hwHF());
0251
0252 rmc.setHwPhi(cand->hwPhi());
0253 rmc.setHwSign(cand->hwSign() == 1 ? 0 : 1);
0254 rmc.setHwSignValid(cand->hwSignValid());
0255 rmc.setHwQual(cand->hwQual());
0256 rmc.setTFIdentifiers(cand->spid().sector(), l1t::tftype::bmtf);
0257
0258 _cache0.push_back(cand->bx(), rmc);
0259 _cache2.insert(std::end(_cache2), std::begin(cand->getTSphi()), std::end(cand->getTSphi()));
0260 _cache3.insert(std::end(_cache3), std::begin(cand->getTSeta()), std::end(cand->getTSeta()));
0261 }
0262 }
0263 it_sp++;
0264 }
0265
0266
0267 vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
0268 while (it_ws != m_wsvec.end()) {
0269 if (L1MuBMTFConfig::Debug(2))
0270 cout << "running Wedge Sorter " << (*it_ws)->id() << endl;
0271 if (*it_ws)
0272 (*it_ws)->run();
0273 if (L1MuBMTFConfig::Debug(2) && *it_ws)
0274 (*it_ws)->print();
0275
0276
0277 if ((*it_ws)->anyMuonCands()) {
0278 const vector<const L1MuBMTrack*>& mttf_cont = (*it_ws)->tracks();
0279
0280 vector<const L1MuBMTrack*>::const_iterator iter;
0281 for (iter = mttf_cont.begin(); iter != mttf_cont.end(); iter++) {
0282 if (!*iter)
0283 continue;
0284 l1t::RegionalMuonCand rmc;
0285 rmc.setHwPt((*iter)->hwPt());
0286 int abs_add_1 = setAdd(1, (*iter)->address(1));
0287 int abs_add_2 = setAdd(2, (*iter)->address(2));
0288 int abs_add_3 = setAdd(3, (*iter)->address(3));
0289 int abs_add_4 = setAdd(4, (*iter)->address(4));
0290
0291 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelSide,
0292 (*iter)->spid().wheel() < 0);
0293 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kWheelNum,
0294 abs((*iter)->spid().wheel()) - 1);
0295 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat1, abs_add_1);
0296 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat2, abs_add_2);
0297 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat3, abs_add_3);
0298 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kStat4, abs_add_4);
0299 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat1, 0);
0300 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat2, 0);
0301 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat3, 0);
0302 rmc.setTrackSubAddress(l1t::RegionalMuonCand::kSegSelStat4, 0);
0303 rmc.setHwHF((*iter)->hwHF());
0304
0305 rmc.setHwPhi((*iter)->hwPhi());
0306 if ((*iter)->hwEta() > -117 || (*iter)->hwEta() < 117)
0307
0308 rmc.setHwEta((*iter)->hwEta());
0309 else
0310 rmc.setHwEta(-1000);
0311 rmc.setHwSign((*iter)->hwSign() == 1 ? 0 : 1);
0312 rmc.setHwSignValid((*iter)->hwSignValid());
0313 rmc.setHwQual((*iter)->hwQual());
0314 rmc.setTFIdentifiers((*iter)->spid().sector(), l1t::tftype::bmtf);
0315
0316 if (*iter) {
0317 _cache.push_back((*iter)->bx(), rmc);
0318 _cache1.push_back(**iter);
0319 }
0320 }
0321 }
0322
0323 it_ws++;
0324
0325 }
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373 }
0374 }
0375
0376
0377
0378
0379 void L1MuBMTrackFinder::reset() {
0380 L1MuBMSecProcMap::SPmap_iter it_sp = m_spmap->begin();
0381 while (it_sp != m_spmap->end()) {
0382 if ((*it_sp).second)
0383 (*it_sp).second->reset();
0384 it_sp++;
0385 }
0386
0387 vector<L1MuBMEtaProcessor*>::iterator it_ep = m_epvec.begin();
0388 while (it_ep != m_epvec.end()) {
0389 if (*it_ep)
0390 (*it_ep)->reset();
0391 it_ep++;
0392 }
0393
0394 vector<L1MuBMWedgeSorter*>::iterator it_ws = m_wsvec.begin();
0395 while (it_ws != m_wsvec.end()) {
0396 if (*it_ws)
0397 (*it_ws)->reset();
0398 it_ws++;
0399 }
0400
0401 if (m_ms)
0402 m_ms->reset();
0403 }
0404
0405
0406
0407
0408 const L1MuBMSectorProcessor* L1MuBMTrackFinder::sp(const L1MuBMSecProcId& id) const { return m_spmap->sp(id); }
0409
0410
0411
0412
0413 int L1MuBMTrackFinder::numberOfTracks() {
0414 int num = 0;
0415 for (int bx = _cache.getFirstBX(); bx < _cache.getLastBX(); ++bx) {
0416 num += _cache.size(bx);
0417 }
0418 return num;
0419 }
0420
0421 L1MuBMTrackFinder::TFtracks_const_iter L1MuBMTrackFinder::begin(int bx) { return _cache.begin(bx); }
0422
0423 L1MuBMTrackFinder::TFtracks_const_iter L1MuBMTrackFinder::end(int bx) { return _cache.end(bx); }
0424
0425 void L1MuBMTrackFinder::clear() {
0426 _cache.clear();
0427 _cache0.clear();
0428 _cache1.clear();
0429 _cache2.clear();
0430 _cache3.clear();
0431 }
0432
0433
0434
0435
0436 int L1MuBMTrackFinder::numberOfTracks(int bx) { return _cache.size(0); }
0437
0438
0439
0440
0441
0442 int L1MuBMTrackFinder::setAdd(int ust, int rel_add) {
0443 unsigned int uadd = rel_add;
0444
0445 switch (uadd) {
0446 case 0: {
0447 rel_add = 8;
0448 break;
0449 }
0450 case 1: {
0451 rel_add = 9;
0452 break;
0453 }
0454 case 2: {
0455 rel_add = 0;
0456 break;
0457 }
0458 case 3: {
0459 rel_add = 1;
0460 break;
0461 }
0462 case 8: {
0463 rel_add = 10;
0464 break;
0465 }
0466 case 9: {
0467 rel_add = 11;
0468 break;
0469 }
0470 case 10: {
0471 rel_add = 2;
0472 break;
0473 }
0474 case 11: {
0475 rel_add = 3;
0476 break;
0477 }
0478 case 4: {
0479 rel_add = 12;
0480 break;
0481 }
0482 case 5: {
0483 rel_add = 13;
0484 break;
0485 }
0486 case 6: {
0487 rel_add = 4;
0488 break;
0489 }
0490 case 7: {
0491 rel_add = 5;
0492 break;
0493 }
0494 case 15: {
0495 rel_add = 15;
0496 break;
0497 }
0498 default: {
0499 rel_add = 15;
0500 break;
0501 }
0502 }
0503
0504 if (ust != 1)
0505 return rel_add;
0506
0507 switch (uadd) {
0508 case 0: {
0509 rel_add = 2;
0510 break;
0511 }
0512 case 1: {
0513 rel_add = 1;
0514 break;
0515 }
0516 case 15: {
0517 rel_add = 3;
0518 break;
0519 }
0520 default: {
0521 rel_add = 3;
0522 break;
0523 }
0524 }
0525 return rel_add;
0526 }
0527
0528
0529
0530 std::shared_ptr<L1MuBMTFConfig> L1MuBMTrackFinder::m_config;