File indexing completed on 2025-04-11 03:31:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
0022
0023
0024
0025
0026 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0027 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0028 #include "L1Trigger/DTBti/interface/DTBtiChip.h"
0029 #include "L1Trigger/DTBti/interface/DTBtiTrig.h"
0030
0031 #include "FWCore/Framework/interface/Event.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "DataFormats/Common/interface/Handle.h"
0034
0035 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0036 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0037 #include "Geometry/DTGeometry/interface/DTLayer.h"
0038 #include "Geometry/DTGeometry/interface/DTChamber.h"
0039
0040 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0041 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
0042 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
0043 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0044 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
0045
0046
0047
0048
0049 #include <iostream>
0050 #include <cmath>
0051 #include <utility>
0052 #include <vector>
0053
0054 using namespace edm;
0055
0056
0057
0058
0059
0060 DTBtiCard::DTBtiCard(DTTrigGeom* geom) : DTGeomSupplier(geom) {
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 }
0071
0072
0073
0074
0075
0076 DTBtiCard::~DTBtiCard() {
0077 localClear();
0078
0079 }
0080
0081
0082
0083
0084
0085 void DTBtiCard::clearCache() {
0086 BTICache::clearCache();
0087 localClear();
0088 }
0089
0090 void DTBtiCard::setConfig(const DTConfigManager* conf) {
0091 DTChamberId sid = ChamberId();
0092 _conf_bti_map = conf->getDTConfigBtiMap(sid);
0093 _debug = conf->getDTTPGDebug();
0094 _pedestals = conf->getDTConfigPedestals();
0095
0096
0097 _flag_acc = conf->useAcceptParam();
0098 }
0099
0100 void DTBtiCard::localClear() {
0101
0102 for (int i = 0; i < 3; i++) {
0103 for (BTI_iter p = _btimap[i].begin(); p != _btimap[i].end(); p++) {
0104 delete (*p).second;
0105 }
0106 _btimap[i].clear();
0107 }
0108
0109
0110 std::vector<DTDigi*>::const_iterator p;
0111 for (p = _digis.begin(); p < _digis.end(); p++)
0112 delete (*p);
0113 _digis.clear();
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
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237 void DTBtiCard::loadBTI(const DTDigiCollection dtDigis) {
0238 localClear();
0239
0240 if (debug()) {
0241 std::cout << "DTBtiCard::loadBTI called for wheel=" << wheel();
0242 std::cout << ", station=" << station();
0243 std::cout << ", sector=" << sector() << std::endl;
0244 }
0245
0246 DTDigiCollection::DigiRangeIterator detUnitIt;
0247 for (detUnitIt = dtDigis.begin(); detUnitIt != dtDigis.end(); ++detUnitIt) {
0248 const DTLayerId& id = (*detUnitIt).first;
0249 const DTDigiCollection::Range& range = (*detUnitIt).second;
0250
0251
0252 if (debug()) {
0253 std::cout << "--------------" << std::endl;
0254 std::cout << "id: " << id;
0255 }
0256
0257
0258 for (DTDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
0259 int tube = (*digiIt).wire();
0260 const DTWireId tubeid(id, tube);
0261 float tdrift = (*digiIt).time() - _pedestals->getOffset(tubeid);
0262
0263 if (debug()) {
0264 std::cout << " digi time : " << (*digiIt).time();
0265 std::cout << " pedestal offset : " << _pedestals->getOffset(tubeid) << std::endl;
0266 std::cout << " drift time after subtraction : " << tdrift << std::endl;
0267 }
0268
0269 if (tdrift < 500 && tdrift > -500) {
0270 if (debug())
0271 (*digiIt).print();
0272
0273
0274
0275 DTSuperLayerId slnum = id.superlayerId();
0276
0277 int sln = slnum.superlayer();
0278 int layn = id.layer();
0279
0280
0281
0282
0283
0284
0285
0286 int nch = geom()->mapTubeInFEch(sln, layn, tube);
0287 int nbti = nch;
0288
0289 if (debug()) {
0290 std::cout << "FE ch " << nch;
0291 std::cout << " of bti " << nbti;
0292
0293 std::cout << " now nbti is " << nch << std::endl;
0294
0295 }
0296
0297
0298
0299
0300
0301 DTDigi* pdigi = new DTDigi((*digiIt).wire(), tdrift);
0302 _digis.push_back(pdigi);
0303
0304 switch (layn) {
0305 case 1:
0306 if (activeGetBTI(sln, nbti))
0307 activeGetBTI(sln, nbti)->add_digi(4, pdigi);
0308 if (activeGetBTI(sln, nbti - 1))
0309 activeGetBTI(sln, nbti - 1)->add_digi(8, pdigi);
0310 break;
0311 case 2:
0312 if (activeGetBTI(sln, nbti))
0313 activeGetBTI(sln, nbti)->add_digi(2, pdigi);
0314 if (activeGetBTI(sln, nbti - 1))
0315 activeGetBTI(sln, nbti - 1)->add_digi(6, pdigi);
0316 break;
0317 case 3:
0318 if (activeGetBTI(sln, nbti))
0319 activeGetBTI(sln, nbti)->add_digi(3, pdigi);
0320 if (activeGetBTI(sln, nbti - 1))
0321 activeGetBTI(sln, nbti - 1)->add_digi(7, pdigi);
0322 break;
0323 case 4:
0324 if (activeGetBTI(sln, nbti))
0325 activeGetBTI(sln, nbti)->add_digi(1, pdigi);
0326 if (activeGetBTI(sln, nbti - 1))
0327 activeGetBTI(sln, nbti - 1)->add_digi(5, pdigi);
0328 if (activeGetBTI(sln, nbti - 2))
0329 activeGetBTI(sln, nbti - 2)->add_digi(9, pdigi);
0330 break;
0331 }
0332 }
0333
0334
0335 }
0336 }
0337 }
0338
0339 void DTBtiCard::runBTI() {
0340 int nbtisig = _btimap[0].size() + _btimap[1].size() + _btimap[2].size();
0341
0342 if (debug()) {
0343 std::cout << "DTBtiCard::runBTI called for wheel=" << wheel();
0344 std::cout << ", station=" << station();
0345 std::cout << ", sector=" << sector();
0346 std::cout << ", " << nbtisig << " BTIs with signal" << std::endl;
0347 }
0348
0349 if (nbtisig) {
0350 if (debug()) {
0351 std::cout << "====================================================" << std::endl;
0352 std::cout << " BTI triggers " << std::endl;
0353 }
0354
0355
0356 for (int sl = 1; sl <= 3; sl++) {
0357 if (!_btimap[sl - 1].empty()) {
0358 BTI_iter pbti;
0359 for (pbti = _btimap[sl - 1].begin(); pbti != _btimap[sl - 1].end(); pbti++) {
0360 DTBtiChip* bti = (*pbti).second;
0361 if (bti->number() < 200)
0362 bti->run();
0363 for (int step = DTConfig::NSTEPF; step <= DTConfig::NSTEPL; step++) {
0364 if (bti->nTrig(step) > 0) {
0365 _cache.push_back(bti->triggerData(step, 1));
0366
0367
0368 }
0369 }
0370 }
0371 }
0372 }
0373
0374 if (debug())
0375 std::cout << "====================================================" << std::endl;
0376 }
0377 }
0378
0379 DTBtiChip* DTBtiCard::activeGetBTI(int sl, int n) {
0380 DTBtiChip* bti = nullptr;
0381
0382 if (n < 1 || n > geom()->nCell(sl)) {
0383 if (debug()) {
0384 std::cout << "DTBtiCard::activeGetBTI :";
0385 std::cout << " invalid bti number: " << n;
0386 std::cout << " not in range [1," << geom()->nCell(sl) << "]";
0387 std::cout << " dummy BTI returned!" << std::endl;
0388 }
0389 return bti;
0390 }
0391
0392
0393 DTChamberId sid = geom()->statId();
0394 DTBtiId _id = DTBtiId(sid, sl, n);
0395
0396
0397 int _debug_bti = config_bti(_id)->debug();
0398
0399 if (_debug_bti == 3) {
0400 std::cout << "DTBtiCard::activeGetBTI :";
0401 std::cout << " bti number: " << n << std::endl;
0402 }
0403
0404 if (sl < 1 || sl > 3) {
0405 if (_debug_bti > 1) {
0406 std::cout << "DTBtiCard::activeGetBTI :";
0407 std::cout << " invalid superlayer number: " << sl;
0408 std::cout << " dummy BTI returned!" << std::endl;
0409 }
0410 return bti;
0411 }
0412
0413 BTI_iter pbti = _btimap[sl - 1].find(n);
0414 if (pbti != _btimap[sl - 1].end()) {
0415 bti = (*pbti).second;
0416 } else {
0417 bti = new DTBtiChip(this, geom(), sl, n, config_bti(_id));
0418 _btimap[sl - 1][n] = bti;
0419 }
0420 return bti;
0421 }
0422
0423 DTBtiChip* DTBtiCard::getBTI(int sl, int n) const {
0424 if (sl < 1 || sl > 3 || n == 999) {
0425 std::cout << "DTBtiCard::getBTI :";
0426 std::cout << " invalid superlayer number: " << sl;
0427 std::cout << " 0 returned!" << std::endl;
0428 return nullptr;
0429 }
0430 BTI_const_iter pbti = _btimap[sl - 1].find(n);
0431 if (pbti == _btimap[sl - 1].end()) {
0432 return nullptr;
0433 }
0434 return (*pbti).second;
0435 }
0436
0437 std::vector<DTBtiChip*> DTBtiCard::btiList(int sl) {
0438 std::vector<DTBtiChip*> blist;
0439
0440 if (size() < 1)
0441 return blist;
0442
0443 if (sl < 1 || sl > 3) {
0444 std::cout << "DTBtiCard::btiList :";
0445 std::cout << " invalid superlayer number: " << sl;
0446 std::cout << " empty list returned" << std::endl;
0447 return blist;
0448 }
0449
0450 for (BTI_const_iter p = _btimap[sl - 1].begin(); p != _btimap[sl - 1].end(); p++) {
0451 blist.push_back((*p).second);
0452 }
0453 return blist;
0454 }
0455
0456 DTBtiTrig* DTBtiCard::storeTrigger(DTBtiTrigData td) {
0457 DTBtiId btiid = td.parentId();
0458 if (!(btiid.wheel() == wheel() && btiid.sector() == sector() && btiid.station() == station()))
0459 return nullptr;
0460 std::cout << "DTBtiCard::trigger: trigger not belonging to this card! ";
0461 std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
0462 std::cout << "trig=(" << btiid.wheel() << "," << btiid.station() << "," << btiid.sector() << ")";
0463
0464 DTBtiChip* bti = activeGetBTI(btiid.superlayer(), btiid.bti());
0465
0466 auto trig = std::make_unique<DTBtiTrig>(bti, td);
0467 auto pTrig = trig.get();
0468
0469 bti->addTrig(td.step(), std::move(trig));
0470
0471 return pTrig;
0472 }
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515 LocalPoint DTBtiCard::localPosition(const DTTrigData* tr) const {
0516
0517 const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0518 if (!trig) {
0519 std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
0520 return LocalPoint(0, 0, 0);
0521 }
0522
0523
0524 float x = geom()->localPosition(trig->parentId()).x();
0525 float y = geom()->localPosition(trig->parentId()).y();
0526 float z = geom()->localPosition(trig->parentId()).z();
0527
0528
0529
0530
0531
0532 float xt = 0;
0533 float yt = 0;
0534
0535 DTBtiId _btiid = trig->parentId();
0536 float xtrig = (float)trig->X() * geom()->cellPitch() / (config_bti(_btiid)->ST());
0537 if (trig->btiSL() == 2)
0538 yt = -xtrig;
0539 else
0540 xt = +xtrig;
0541
0542
0543
0544
0545
0546
0547
0548 if (debug()) {
0549 std::cout << "DTBtiCard::localPosition of BTI in (" << x << "," << y << "," << z << ")" << std::endl;
0550 std::cout << " called for trig ";
0551 trig->print();
0552 std::cout << "in Local Point (" << x + xt << "," << y + yt << "," << z << ")" << std::endl;
0553 }
0554
0555 return LocalPoint(x + xt, y + yt, z);
0556 }
0557
0558 LocalVector DTBtiCard::localDirection(const DTTrigData* tr) const {
0559
0560 const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0561
0562 if (!trig) {
0563 std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
0564 return LocalVector(0, 0, 0);
0565 }
0566
0567
0568
0569
0570
0571 DTBtiId _btiid = trig->parentId();
0572 float psi = atan((float)(trig->K() - config_bti(_btiid)->ST()) * geom()->cellPitch() /
0573 (2 * geom()->cellH() * config_bti(_btiid)->ST()));
0574
0575 float xd = 0;
0576 float yd = 0;
0577 float zd = -cos(psi);
0578 if (trig->btiSL() == 2)
0579 yd = sin(psi);
0580 else
0581 xd = -sin(psi);
0582
0583
0584
0585
0586
0587
0588
0589 if (debug()) {
0590
0591 float xb = geom()->localPosition(trig->parentId()).x();
0592 float yb = geom()->localPosition(trig->parentId()).y();
0593 float zb = geom()->localPosition(trig->parentId()).z();
0594
0595 std::cout << "DTBtiCard::localDirection of BTI in (" << xb << "," << yb << "," << zb << ")" << std::endl;
0596 std::cout << " called for trig ";
0597 trig->print();
0598 std::cout << "in Local Direction (" << xd << "," << yd << "," << zd << ")" << std::endl;
0599 }
0600
0601 return LocalVector(xd, yd, zd);
0602 }
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633 DTConfigBti* DTBtiCard::config_bti(DTBtiId& btiid) const {
0634
0635 ConfBtiMap::const_iterator biter = _conf_bti_map.find(btiid);
0636 if (biter == _conf_bti_map.end()) {
0637 std::cout << "DTBtiCard::config_bti : BTI (" << btiid.wheel() << "," << btiid.sector() << "," << btiid.station()
0638 << "," << btiid.superlayer() << "," << btiid.bti() << ") not found, return 0" << std::endl;
0639 return nullptr;
0640 }
0641
0642 return const_cast<DTConfigBti*>(&(*biter).second);
0643 }