File indexing completed on 2024-04-06 12:19:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include "L1Trigger/DTBti/interface/DTBtiChip.h"
0023
0024
0025
0026
0027 #include "L1Trigger/DTBti/interface/DTBtiHit.h"
0028 #include "L1Trigger/DTBti/interface/DTBtiTrig.h"
0029
0030 #include <DataFormats/MuonDetId/interface/DTChamberId.h>
0031 #include <DataFormats/MuonDetId/interface/DTLayerId.h>
0032 #include <DataFormats/MuonDetId/interface/DTSuperLayerId.h>
0033 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0034
0035 #include <DataFormats/DTDigi/interface/DTDigiCollection.h>
0036
0037
0038
0039 #include <iostream>
0040 #include <cmath>
0041
0042 using namespace std;
0043
0044
0045
0046
0047
0048 DTBtiChip::DTBtiChip(DTBtiCard* card, DTTrigGeom* geom, int supl, int n, DTConfigBti* conf)
0049 : _card(card), _geom(geom), _config(conf) {
0050
0051 setSnap();
0052 reSumSet();
0053
0054
0055 if (config()->debug() > 2) {
0056 cout << "DTBtiChip constructor called for BTI number " << n;
0057 cout << " in superlayer " << supl << endl;
0058 }
0059
0060
0061 for (auto& t : _trigs) {
0062 t.reserve(2);
0063 }
0064
0065 for (auto& d : _digis) {
0066 d.reserve(10);
0067 }
0068 for (auto& h : _hits) {
0069 h.reserve(10);
0070 }
0071
0072
0073 int DEAD = config()->DEADpar();
0074 for (auto& c : _busyStart_clock) {
0075 c = -DEAD - 1;
0076 }
0077
0078
0079 DTChamberId sid = _geom->statId();
0080 _id = DTBtiId(sid, supl, n);
0081
0082
0083
0084 _MinKAcc = 0;
0085 _MaxKAcc = 63;
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150 if (_id.superlayer() == 2) {
0151
0152
0153
0154
0155
0156
0157 if (_card->useAcceptParamFlag() == 0) {
0158
0159 float distp2 = 2 * _geom->cellH() * config()->ST() / _geom->cellPitch();
0160 float K0 = config()->ST();
0161
0162
0163 DTBtiId _id1 = DTBtiId(sid, supl, 1);
0164 GlobalPoint gp1 = _geom->CMSPosition(_id1);
0165 GlobalPoint gp = CMSPosition();
0166 if (config()->debug() > 3) {
0167 cout << "Position: R=" << gp.perp() << "cm, Phi=" << gp.phi() * 180 / 3.14159;
0168 cout << " deg, Z=" << gp.z() << " cm" << endl;
0169 }
0170
0171 float theta;
0172 if (gp1.z() < 0.0)
0173 theta = atan(-(gp.z()) / gp.perp());
0174 else
0175 theta = atan((gp.z()) / gp.perp());
0176
0177
0178 float fktmin = tan(theta) * distp2 + K0;
0179 int ktmin = static_cast<int>(fktmin) - config()->KAccTheta();
0180 float fktmax = tan(theta) * distp2 + K0 + 1;
0181 int ktmax = static_cast<int>(fktmax) + config()->KAccTheta();
0182 if (ktmin > _MinKAcc)
0183 _MinKAcc = ktmin;
0184 if (ktmax < _MaxKAcc)
0185 _MaxKAcc = ktmax;
0186 }
0187
0188 else {
0189 _MinKAcc = config()->CL();
0190 _MaxKAcc = config()->CH();
0191 }
0192
0193
0194 if (config()->debug() > 2) {
0195 cout << "CMS position:" << CMSPosition() << endl;
0196 cout << "K acceptance (theta view):" << _MinKAcc << "," << _MaxKAcc << endl;
0197 }
0198
0199 }
0200
0201
0202
0203
0204 init_done = 0;
0205 }
0206
0207
0208
0209
0210 DTBtiChip::~DTBtiChip() { clear(); }
0211
0212 void DTBtiChip::add_digi(int cell, const DTDigi* digi) {
0213 if (_id.bti() < 1 || _id.bti() > _geom->nCell(superlayer()))
0214 return;
0215 if (cell < 1 || cell > 9) {
0216 cout << "DTBtiChip::add_digi : wrong cell number: " << cell;
0217 cout << ". Digi not added!" << endl;
0218 return;
0219 }
0220
0221 int DEAD = config()->DEADpar();
0222 float stepTimeTdc = DTBtiHit::_stepTimeTdc;
0223
0224 if (int(digi->countsTDC() / stepTimeTdc) - _busyStart_clock[cell - 1] > DEAD) {
0225 _busyStart_clock[cell - 1] = int(digi->countsTDC() / stepTimeTdc);
0226 _digis[cell - 1].push_back(digi);
0227
0228
0229 if (config()->debug() > 1) {
0230 cout << "DTBtiChip::add_digi: DTBtiChip # " << _id.bti() << " cell " << cell
0231 << " --> drift time (tdc units)= " << digi->countsTDC() << endl;
0232 digi->print();
0233 }
0234 } else {
0235
0236 if (config()->debug() > 1)
0237 cout << "DTBtiChip::add_digi: DTBtiChip # " << _id.bti() << " cell " << cell
0238 << " in dead time -> digi not added! " << endl;
0239 }
0240 }
0241
0242 void DTBtiChip::add_digi_clock(int cell, int digi) {
0243 if (cell < 1 || cell > 9) {
0244 cout << "DTBtiChip::add_digi_clock : wrong cell number: " << cell;
0245 cout << ". Digi not added!" << endl;
0246 return;
0247 }
0248
0249 int DEAD = config()->DEADpar();
0250
0251 if (digi - _busyStart_clock[cell - 1] > DEAD) {
0252 _busyStart_clock[cell - 1] = digi;
0253 _digis_clock[cell - 1].push_back(digi);
0254
0255 if (config()->debug() > 1)
0256 cout << "DTBtiChip::add_digi_clock: DTBtiChip # " << number() << " cell " << cell << " --> clock time = " << digi
0257 << endl;
0258 } else {
0259
0260 if (config()->debug() > 1)
0261 cout << "DTBtiChip::add_digi_clock: DTBtiChip # " << number() << " cell " << cell
0262 << " in dead time -> digi not added! " << endl;
0263 }
0264 }
0265
0266 int DTBtiChip::nCellHit() const {
0267 int n = 0;
0268 int i = 0;
0269 for (auto const& d : _digis) {
0270 if (!d.empty())
0271 n++;
0272 }
0273 if (config()->debug() > 2) {
0274 cout << n << " cells with hits found:" << endl;
0275 }
0276 if (config()->debug() > 2) {
0277 for (i = 0; i < 9; i++) {
0278 for (auto const& d : _digis[i]) {
0279 cout << "DTBtiChip # " << _id.bti() << " cell " << i + 1;
0280 cout << " --> drift time (tdc units): " << d->countsTDC() << endl;
0281 d->print();
0282 }
0283 }
0284 }
0285 return n;
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312 }
0313
0314 void DTBtiChip::addTrig(int step, std::unique_ptr<DTBtiTrig> btitrig) {
0315 if (step >= DTConfig::NSTEPF && step <= DTConfig::NSTEPL) {
0316 if (config()->debug() > 3)
0317 cout << "DTBtiChip: adding trigger..." << endl;
0318 _trigs[step - DTConfig::NSTEPF].emplace_back(std::move(btitrig));
0319 } else {
0320 if (config()->debug() > 3) {
0321 cout << "DTBtiChip::addTrig: step " << step;
0322 cout << " outside range. Trigger not added" << endl;
0323 }
0324 }
0325 }
0326
0327 int DTBtiChip::nTrig(int step) const {
0328 if (step < DTConfig::NSTEPF || step > DTConfig::NSTEPL) {
0329 cout << "DTBtiChip::nTrig: step out of range: " << step;
0330 cout << " 0 returned" << endl;
0331 return 0;
0332 }
0333 return _trigs[step - DTConfig::NSTEPF].size();
0334 }
0335
0336 vector<std::unique_ptr<DTBtiTrig>> const& DTBtiChip::trigList(int step) const {
0337 if (step < DTConfig::NSTEPF || step > DTConfig::NSTEPL) {
0338 cout << "DTBtiChip::trigList: step out of range: " << step;
0339 cout << " empty pointer returned" << endl;
0340
0341 }
0342 return _trigs[step - DTConfig::NSTEPF];
0343 }
0344
0345 DTBtiTrig const* DTBtiChip::trigger(int step, unsigned n) const {
0346 if (step < DTConfig::NSTEPF || step > DTConfig::NSTEPL) {
0347 cout << "DTBtiChip::trigger: step out of range: " << step;
0348 cout << " empty pointer returned" << endl;
0349 return nullptr;
0350 }
0351 if (n < 1 || n > _trigs[step - DTConfig::NSTEPF].size()) {
0352 cout << "DTBtiChip::trigger: requested trigger does not exist: " << n;
0353 cout << " empty pointer returned!" << endl;
0354 return nullptr;
0355 }
0356 auto p = _trigs[step - DTConfig::NSTEPF].begin();
0357 return (*(p + n - 1)).get();
0358 }
0359
0360 DTBtiTrigData DTBtiChip::triggerData(int step, unsigned n) const {
0361 if (step < DTConfig::NSTEPF || step > DTConfig::NSTEPL) {
0362 cout << "DTBtiChip::triggerData: step out of range: " << step;
0363 cout << " dummy trigger returned" << endl;
0364 return DTBtiTrigData();
0365 }
0366 if (n < 1 || n > _trigs[step - DTConfig::NSTEPF].size()) {
0367 cout << "DTBtiChip::triggerData: requested trig. doesn't exist: " << n;
0368 cout << " dummy trigger returned!" << endl;
0369 return DTBtiTrigData();
0370 }
0371 auto p = _trigs[step - DTConfig::NSTEPF].begin();
0372 return (*(p + n - 1))->data();
0373 }
0374
0375 void DTBtiChip::eraseTrigger(int step, unsigned n) {
0376 if (step < DTConfig::NSTEPF || step > DTConfig::NSTEPL) {
0377 cout << "DTBtiChip::eraseTrigger: step out of range: " << step;
0378 cout << " trigger not deleted!" << endl;
0379 }
0380 if (n < 1 || n > _trigs[step - DTConfig::NSTEPF].size()) {
0381 cout << "DTBtiChip::trigger: requested trigger does not exist: " << n;
0382 cout << " trigger not deleted!" << endl;
0383 }
0384 auto p = _trigs[step - DTConfig::NSTEPF].begin() + n - 1;
0385 _trigs[step - DTConfig::NSTEPF].erase(p);
0386 }
0387
0388 void DTBtiChip::clear() {
0389 if (config()->debug() > 3)
0390 cout << "DTBtiChip::clear()" << endl;
0391
0392 for (auto& d : _digis) {
0393 d.clear();
0394 }
0395 for (auto& c : _digis_clock) {
0396 c.clear();
0397 }
0398 for (auto& h : _hits) {
0399 h.clear();
0400 }
0401
0402 for (auto& t : _trigs) {
0403 t.clear();
0404 }
0405 }
0406
0407 void DTBtiChip::init() {
0408 if (config()->debug() > 3)
0409 cout << "DTBtiChip::init() -> initializing bti chip" << endl;
0410
0411 _curStep = 0;
0412 for (int i = 0; i < 25; i++) {
0413 _sums[i] = 1000;
0414 _difs[i] = 1000;
0415 }
0416
0417 for (int cell = 0; cell < 9; cell++) {
0418 int WEN = config()->WENflag(cell + 1);
0419 if (WEN == 1) {
0420 _thisStepUsedHit[cell] = nullptr;
0421 vector<const DTDigi*>::const_iterator p;
0422 for (p = _digis[cell].begin(); p < _digis[cell].end(); p++) {
0423 DTBtiHit* hit = new DTBtiHit(*p, config());
0424
0425
0426 _hits[cell].push_back(hit);
0427 }
0428
0429
0430 if (config()->debug() > 2) {
0431 vector<DTBtiHit*>::const_iterator p1;
0432 for (p1 = _hits[cell].begin(); p1 < _hits[cell].end(); p1++) {
0433 cout << " Filling hit in cell " << cell + 1;
0434 if ((*p1)->curTime() != 4000)
0435 cout << " raw time in trigger: " << (*p1)->curTime() << endl;
0436 cout << " time (clock units): " << (*p1)->clockTime() << endl;
0437 }
0438 }
0439
0440 }
0441 }
0442 }
0443
0444 void DTBtiChip::init_clock() {
0445 if (config()->debug() > 3)
0446 cout << "DTBtiChip::init_clock() -> initializing bti chip" << endl;
0447
0448 init_done = 1;
0449 _curStep = 0;
0450
0451 for (int i = 0; i < 25; i++) {
0452 _sums[i] = 1000;
0453 _difs[i] = 1000;
0454 }
0455
0456 for (int cell = 0; cell < 9; cell++) {
0457 int WEN = config()->WENflag(cell + 1);
0458 if (WEN == 1) {
0459 _thisStepUsedHit[cell] = nullptr;
0460 for (unsigned int i = 0; i < _digis_clock[cell].size(); i++) {
0461 const int clockTime = (_digis_clock[cell])[i];
0462 DTBtiHit* hit = new DTBtiHit(clockTime, config());
0463 _hits[cell].push_back(hit);
0464 }
0465
0466
0467 if (config()->debug() > 2) {
0468 vector<DTBtiHit*>::const_iterator p1;
0469 for (p1 = _hits[cell].begin(); p1 < _hits[cell].end(); p1++) {
0470 cout << " Filling hit in cell " << cell + 1;
0471 if ((*p1)->curTime() != 4000)
0472 cout << " time: " << (*p1)->curTime() << endl;
0473 else
0474 cout << " time (clock units): " << (*p1)->clockTime() << endl;
0475 }
0476 }
0477
0478 }
0479 }
0480 }
0481
0482 void DTBtiChip::run() {
0483
0484 if (config()->debug() > 2) {
0485 cout << "DTBtiChip::run: Processing BTI " << _id.bti() << endl;
0486 cout << " in SL " << _id.superlayer() << endl;
0487 }
0488
0489
0490 if (_id.bti() < 1 || _id.bti() > _geom->nCell(superlayer())) {
0491 if (config()->debug() > 1)
0492 cout << "DTBtiChip::run : wrong BTI number: " << _id.bti() << endl;
0493 return;
0494 }
0495
0496
0497 if (!init_done)
0498 init();
0499 if (nCellHit() < 3)
0500 return;
0501
0502 for (int ints = 0; ints < 2 * DTConfig::NSTEPL; ints++) {
0503 tick();
0504
0505
0506
0507
0508 if ((currentIntStep() / 2) * 2 != currentIntStep())
0509 continue;
0510
0511
0512 if (config()->debug() > 2) {
0513 cout << "DTBtiChip::run : internal step " << currentIntStep();
0514 cout << " number of JTRIG hits is " << _nStepUsedHits << endl;
0515 }
0516 if (currentStep() >= DTConfig::NSTEPF && _nStepUsedHits > 2) {
0517
0518 computeSums();
0519 computeEqs();
0520 findTrig();
0521 }
0522 }
0523 if (config()->LTS() > 0)
0524 doLTS();
0525 }
0526
0527 void DTBtiChip::tick() {
0528
0529
0530
0531
0532
0533 _curStep++;
0534
0535
0536 if (config()->debug() > 2) {
0537 cout << "DTBtiChip::tick: internal step is now " << currentIntStep() << endl;
0538 }
0539
0540
0541
0542 _nStepUsedHits = 0;
0543 for (int cell = 0; cell < 9; cell++) {
0544
0545 for (auto& h : _hits[cell]) {
0546 h->stepDownTime();
0547 }
0548
0549
0550 _thisStepUsedHit[cell] = nullptr;
0551 for (auto& h : _hits[cell]) {
0552 if (h->isDrifting()) {
0553 break;
0554 } else if (h->isInsideReg()) {
0555 _thisStepUsedHit[cell] = h;
0556 _nStepUsedHits++;
0557
0558 if (config()->debug() > 2) {
0559 if (h->curTime() != 4000)
0560 cout << "DTBtiChip::tick: hit in register: time=" << h->curTime();
0561 else
0562 cout << "DTBtiChip::tick: hit in register! " << endl;
0563 cout << " jtrig=" << h->jtrig() << endl;
0564 }
0565
0566 break;
0567 }
0568
0569
0570 }
0571
0572
0573 if (config()->debug() > 2) {
0574 if (_thisStepUsedHit[cell] != nullptr) {
0575 cout << "int. step=" << currentIntStep() << " cell=" << cell + 1;
0576 cout << " jtrig=" << _thisStepUsedHit[cell]->jtrig();
0577 if (_thisStepUsedHit[cell]->curTime() != 4000)
0578 cout << " (time=" << _thisStepUsedHit[cell]->curTime() << ")" << endl;
0579 else
0580 cout << endl;
0581 }
0582 }
0583
0584
0585 }
0586 }
0587
0588 void DTBtiChip::doLTS() {
0589 if (config()->debug() > 2)
0590 cout << "Do LTS" << endl;
0591 int lts = config()->LTS();
0592 int nbxlts = config()->SET();
0593
0594
0595
0596
0597
0598 if (lts == 0)
0599 return;
0600
0601
0602 for (int is = DTConfig::NSTEPF; is <= DTConfig::NSTEPL; is++) {
0603 if (nTrig(is) > 0) {
0604 if (trigger(is, 1)->code() == 8) {
0605
0606 for (int js = is + 1; (js <= is + nbxlts && js <= DTConfig::NSTEPL); js++) {
0607 if (nTrig(js) > 0) {
0608 DTBtiTrig const* tr = trigger(js, 1);
0609 if (tr->code() < 8 && (lts == 1 || lts == 3)) {
0610 if (config()->debug() > 3)
0611 cout << "LTS: erasing trigger!" << endl;
0612 eraseTrigger(js, 1);
0613 }
0614 }
0615 }
0616
0617 if (is > DTConfig::NSTEPF && nTrig(is - 1) > 0) {
0618 DTBtiTrig const* tr = trigger(is - 1, 1);
0619 if (tr->code() < 8 && (lts == 2 || lts == 3)) {
0620 if (config()->debug() > 3)
0621 cout << "LTS: erasing trigger!" << endl;
0622 eraseTrigger(is - 1, 1);
0623 }
0624 }
0625 }
0626 }
0627 }
0628 }
0629
0630 int DTBtiChip::store(const int eq,
0631 const int code,
0632 const int K,
0633 const int X,
0634 float KeqAB,
0635 float KeqBC,
0636 float KeqCD,
0637 float KeqAC,
0638 float KeqBD,
0639 float KeqAD) {
0640
0641 if (X < 0)
0642 return 0;
0643
0644
0645 if (K >= _MinKAcc && K <= _MaxKAcc) {
0646 int trig_step = currentStep();
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662 int strobe = -1;
0663
0664
0665 float Keq[6] = {KeqAB, KeqBC, KeqCD, KeqAC, KeqBD, KeqAD};
0666
0667 auto trg = std::make_unique<DTBtiTrig>(this, code, K, X, trig_step, eq, strobe, Keq);
0668
0669
0670 for (auto& h : _thisStepUsedHit) {
0671 if (h) {
0672 const DTDigi* digi = h->hitDigi();
0673 if (digi)
0674 trg->addDigi(digi);
0675 }
0676 }
0677
0678
0679 if (config()->debug() > 1)
0680 trg->print();
0681
0682
0683
0684 addTrig(trig_step, std::move(trg));
0685
0686 return 1;
0687 } else {
0688
0689 if (config()->debug() > 2) {
0690 cout << "DTBtiChip::store, REJECTED TRIGGER at step " << currentStep();
0691 cout << " allowed K range in theta view is: [";
0692 cout << _MinKAcc << "," << _MaxKAcc << "]";
0693 cout << "K value is " << K << endl;
0694 }
0695 return 0;
0696 }
0697 }
0698
0699 void DTBtiChip::setSnap() {
0700
0701 ST43 = config()->ST43();
0702 RE43 = config()->RE43();
0703 ST23 = int(double(ST43) / 2.);
0704 RE23 = (RE43 == 1) ? 2 : int(double(RE43) / 2.);
0705
0706 ST = int(double(ST43) * 3. / 4. + double(RE43) * 1. / 4.);
0707 ST2 = int((double(ST43) * 3. / 4. + double(RE43) * 1. / 4.) * 2.);
0708 ST3 = int((double(ST43) * 3. / 4. + double(RE43) * 1. / 4.) * 3.);
0709 ST4 = int((double(ST43) * 3. / 4. + double(RE43) * 1. / 4.) * 4.);
0710 ST5 = int((double(ST43) * 3. / 4. + double(RE43) * 1. / 4.) * 5.);
0711 ST7 = int((double(ST43) * 3. / 4. + double(RE43) * 1. / 4.) * 7.);
0712
0713 if (config()->debug() > 3) {
0714 cout << "Snap register dump: " << endl;
0715 cout << "ST43 = " << ST43 << endl;
0716 cout << "RE43 = " << RE43 << endl;
0717 cout << "ST23 = " << ST23 << endl;
0718 cout << "RE23 = " << RE23 << endl;
0719 cout << "ST = " << ST << endl;
0720 cout << "ST2 = " << ST2 << endl;
0721 cout << "ST3 = " << ST3 << endl;
0722 cout << "ST4 = " << ST4 << endl;
0723 cout << "ST5 = " << ST5 << endl;
0724 cout << "ST7 = " << ST7 << endl;
0725 }
0726 }