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 #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 sl = 1;
0390 n = 999;
0391 return bti;
0392 }
0393
0394
0395 DTChamberId sid = geom()->statId();
0396 DTBtiId _id = DTBtiId(sid, sl, n);
0397
0398
0399 int _debug_bti = config_bti(_id)->debug();
0400
0401 if (_debug_bti == 3) {
0402 std::cout << "DTBtiCard::activeGetBTI :";
0403 std::cout << " bti number: " << n << std::endl;
0404 }
0405
0406 if (sl < 1 || sl > 3) {
0407 if (_debug_bti > 1) {
0408 std::cout << "DTBtiCard::activeGetBTI :";
0409 std::cout << " invalid superlayer number: " << sl;
0410 std::cout << " dummy BTI returned!" << std::endl;
0411 }
0412 sl = 1;
0413 n = 999;
0414 return bti;
0415 }
0416
0417 BTI_iter pbti = _btimap[sl - 1].find(n);
0418 if (pbti != _btimap[sl - 1].end()) {
0419 bti = (*pbti).second;
0420 } else {
0421 bti = new DTBtiChip(this, geom(), sl, n, config_bti(_id));
0422 _btimap[sl - 1][n] = bti;
0423 }
0424 return bti;
0425 }
0426
0427 DTBtiChip* DTBtiCard::getBTI(int sl, int n) const {
0428 if (sl < 1 || sl > 3 || n == 999) {
0429 std::cout << "DTBtiCard::getBTI :";
0430 std::cout << " invalid superlayer number: " << sl;
0431 std::cout << " 0 returned!" << std::endl;
0432 return nullptr;
0433 }
0434 BTI_const_iter pbti = _btimap[sl - 1].find(n);
0435 if (pbti == _btimap[sl - 1].end()) {
0436 return nullptr;
0437 }
0438 return (*pbti).second;
0439 }
0440
0441 std::vector<DTBtiChip*> DTBtiCard::btiList(int sl) {
0442 std::vector<DTBtiChip*> blist;
0443
0444 if (size() < 1)
0445 return blist;
0446
0447 if (sl < 1 || sl > 3) {
0448 std::cout << "DTBtiCard::btiList :";
0449 std::cout << " invalid superlayer number: " << sl;
0450 std::cout << " empty list returned" << std::endl;
0451 return blist;
0452 }
0453
0454 for (BTI_const_iter p = _btimap[sl - 1].begin(); p != _btimap[sl - 1].end(); p++) {
0455 blist.push_back((*p).second);
0456 }
0457 return blist;
0458 }
0459
0460 DTBtiTrig* DTBtiCard::storeTrigger(DTBtiTrigData td) {
0461 DTBtiId btiid = td.parentId();
0462 if (!(btiid.wheel() == wheel() && btiid.sector() == sector() && btiid.station() == station()))
0463 return nullptr;
0464 std::cout << "DTBtiCard::trigger: trigger not belonging to this card! ";
0465 std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
0466 std::cout << "trig=(" << btiid.wheel() << "," << btiid.station() << "," << btiid.sector() << ")";
0467
0468 DTBtiChip* bti = activeGetBTI(btiid.superlayer(), btiid.bti());
0469
0470 auto trig = std::make_unique<DTBtiTrig>(bti, td);
0471 auto pTrig = trig.get();
0472
0473 bti->addTrig(td.step(), std::move(trig));
0474
0475 return pTrig;
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
0516
0517
0518
0519 LocalPoint DTBtiCard::localPosition(const DTTrigData* tr) const {
0520
0521 const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0522 if (!trig) {
0523 std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
0524 return LocalPoint(0, 0, 0);
0525 }
0526
0527
0528 float x = geom()->localPosition(trig->parentId()).x();
0529 float y = geom()->localPosition(trig->parentId()).y();
0530 float z = geom()->localPosition(trig->parentId()).z();
0531
0532
0533
0534
0535
0536 float xt = 0;
0537 float yt = 0;
0538
0539 DTBtiId _btiid = trig->parentId();
0540 float xtrig = (float)trig->X() * geom()->cellPitch() / (config_bti(_btiid)->ST());
0541 if (trig->btiSL() == 2)
0542 yt = -xtrig;
0543 else
0544 xt = +xtrig;
0545
0546
0547
0548
0549
0550
0551
0552 if (debug()) {
0553 std::cout << "DTBtiCard::localPosition of BTI in (" << x << "," << y << "," << z << ")" << std::endl;
0554 std::cout << " called for trig ";
0555 trig->print();
0556 std::cout << "in Local Point (" << x + xt << "," << y + yt << "," << z << ")" << std::endl;
0557 }
0558
0559 return LocalPoint(x + xt, y + yt, z);
0560 }
0561
0562 LocalVector DTBtiCard::localDirection(const DTTrigData* tr) const {
0563
0564 const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
0565
0566 if (!trig) {
0567 std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
0568 return LocalVector(0, 0, 0);
0569 }
0570
0571
0572
0573
0574
0575 DTBtiId _btiid = trig->parentId();
0576 float psi = atan((float)(trig->K() - config_bti(_btiid)->ST()) * geom()->cellPitch() /
0577 (2 * geom()->cellH() * config_bti(_btiid)->ST()));
0578
0579 float xd = 0;
0580 float yd = 0;
0581 float zd = -cos(psi);
0582 if (trig->btiSL() == 2)
0583 yd = sin(psi);
0584 else
0585 xd = -sin(psi);
0586
0587
0588
0589
0590
0591
0592
0593 if (debug()) {
0594
0595 float xb = geom()->localPosition(trig->parentId()).x();
0596 float yb = geom()->localPosition(trig->parentId()).y();
0597 float zb = geom()->localPosition(trig->parentId()).z();
0598
0599 std::cout << "DTBtiCard::localDirection of BTI in (" << xb << "," << yb << "," << zb << ")" << std::endl;
0600 std::cout << " called for trig ";
0601 trig->print();
0602 std::cout << "in Local Direction (" << xd << "," << yd << "," << zd << ")" << std::endl;
0603 }
0604
0605 return LocalVector(xd, yd, zd);
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
0634
0635
0636
0637 DTConfigBti* DTBtiCard::config_bti(DTBtiId& btiid) const {
0638
0639 ConfBtiMap::const_iterator biter = _conf_bti_map.find(btiid);
0640 if (biter == _conf_bti_map.end()) {
0641 std::cout << "DTBtiCard::config_bti : BTI (" << btiid.wheel() << "," << btiid.sector() << "," << btiid.station()
0642 << "," << btiid.superlayer() << "," << btiid.bti() << ") not found, return 0" << std::endl;
0643 return nullptr;
0644 }
0645
0646 return const_cast<DTConfigBti*>(&(*biter).second);
0647 }