00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
00022
00023
00024
00025
00026 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00027 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00028 #include "L1Trigger/DTBti/interface/DTBtiChip.h"
00029 #include "L1Trigger/DTBti/interface/DTBtiTrig.h"
00030
00031 #include "FWCore/Framework/interface/Event.h"
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 #include "DataFormats/Common/interface/Handle.h"
00034
00035 #include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h"
00036 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00037 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00038 #include "Geometry/DTGeometry/interface/DTLayer.h"
00039 #include "Geometry/DTGeometry/interface/DTChamber.h"
00040
00041 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00042 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
00043 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
00044 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00045 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
00046
00047
00048
00049
00050 #include <iostream>
00051 #include <cmath>
00052 #include <utility>
00053 #include <vector>
00054
00055 using namespace edm;
00056
00057
00058
00059
00060
00061 DTBtiCard::DTBtiCard(DTTrigGeom *geom, DTTTrigBaseSync *sync) :
00062 DTGeomSupplier(geom), _digi_sync(sync) {
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 }
00075
00076
00077
00078
00079
00080 DTBtiCard::~DTBtiCard(){
00081
00082 localClear();
00083
00084
00085 }
00086
00087
00088
00089
00090
00091 void
00092 DTBtiCard::clearCache(){
00093
00094 BTICache::clearCache();
00095 localClear();
00096
00097 }
00098
00099 void
00100 DTBtiCard::setConfig(const DTConfigManager *conf){
00101
00102 DTChamberId sid = ChamberId();
00103 _conf_bti_map = conf->getDTConfigBtiMap(sid);
00104 _debug = conf->getDTTPGDebug();
00105 _finedelay = conf->getDTConfigTrigUnit(sid)->MCSetupTime();
00106
00107 }
00108
00109
00110 void
00111 DTBtiCard::localClear(){
00112
00113 for(int i=0; i<3; i++){
00114 for(BTI_iter p=_btimap[i].begin();p!=_btimap[i].end();p++){
00115 delete (*p).second;
00116 }
00117 _btimap[i].clear();
00118 }
00119
00120
00121 std::vector<DTDigi*>::const_iterator p;
00122 for(p=_digis.begin();p<_digis.end();p++)
00123 delete (*p);
00124 _digis.clear();
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 void
00252 DTBtiCard::loadBTI(const DTDigiCollection dtDigis) {
00253
00254 localClear();
00255
00256 if(debug()){
00257 std::cout << "DTBtiCard::loadBTI called for wheel=" << wheel() ;
00258 std::cout << ", station=" << station();
00259 std::cout << ", sector=" << sector() << std::endl;
00260 }
00261
00262 DTDigiCollection::DigiRangeIterator detUnitIt;
00263 for (detUnitIt=dtDigis.begin();
00264 detUnitIt!=dtDigis.end();
00265 ++detUnitIt){
00266
00267 const DTLayerId& id = (*detUnitIt).first;
00268 const DTDigiCollection::Range& range = (*detUnitIt).second;
00269
00270
00271 if(debug()){
00272 std::cout<<"--------------"<<std::endl;
00273 std::cout<<"id: "<<id;
00274 }
00275
00276
00277 for (DTDigiCollection::const_iterator digiIt = range.first;
00278 digiIt!=range.second;
00279 ++digiIt){
00280
00281 int tube = (*digiIt).wire();
00282 const DTWireId tubeid(id,tube);
00283 float tdrift = (*digiIt).time() - _digi_sync->offset(tubeid);
00284 if (debug()){
00285 std::cout << "digi time: " << (*digiIt).time();
00286 std::cout << " sync offset: " << _digi_sync->offset(tubeid) << std::endl;
00287 }
00288
00289 if(tdrift<500 && tdrift>-500){
00290 if(debug())
00291 (*digiIt).print();
00292
00293
00294
00295 DTSuperLayerId slnum = id.superlayerId();
00296
00297 int sln = slnum.superlayer();
00298 int layn = id.layer();
00299
00300
00301
00302
00303
00304
00305
00306 int nch = geom()->mapTubeInFEch(sln,layn,tube);
00307 int nbti = nch ;
00308
00309 if(debug()){
00310 std::cout << "FE ch " << nch;
00311 std::cout << " of bti " << nbti;
00312
00313 std::cout << " now nbti is " << nch << std::endl;
00314
00315 }
00316
00317
00318
00319
00320
00321 tdrift = tdrift + _finedelay;
00322
00323
00324
00325 DTDigi* pdigi = new DTDigi((*digiIt).wire(),tdrift);
00326 _digis.push_back(const_cast<DTDigi*>(pdigi) );
00327
00328
00329 switch(layn) {
00330 case 1:
00331 if(activeGetBTI(sln, nbti )) activeGetBTI(sln, nbti )->add_digi(4, pdigi);
00332 if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(8, pdigi);
00333 break;
00334 case 2:
00335 if(activeGetBTI(sln, nbti )) activeGetBTI(sln, nbti )->add_digi(2, pdigi);
00336 if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(6, pdigi);
00337 break;
00338 case 3:
00339 if(activeGetBTI(sln, nbti )) activeGetBTI(sln, nbti )->add_digi(3, pdigi);
00340 if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(7, pdigi);
00341 break;
00342 case 4:
00343 if(activeGetBTI(sln, nbti )) activeGetBTI(sln, nbti )->add_digi(1, pdigi);
00344 if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(5, pdigi);
00345 if(activeGetBTI(sln, nbti-2)) activeGetBTI(sln, nbti-2)->add_digi(9, pdigi);
00346 break;
00347 }
00348 }
00349
00350
00351 }
00352 }
00353 }
00354
00355 void
00356 DTBtiCard::runBTI() {
00357
00358 int nbtisig = _btimap[0].size()+_btimap[1].size()+_btimap[2].size();
00359
00360 if(debug()){
00361 std::cout << "DTBtiCard::runBTI called for wheel=" << wheel() ;
00362 std::cout << ", station=" << station();
00363 std::cout << ", sector=" << sector();
00364 std::cout << ", " << nbtisig
00365 << " BTIs with signal" << std::endl;
00366 }
00367
00368 if( nbtisig){
00369
00370 if(debug()){
00371 std::cout << "====================================================" << std::endl;
00372 std::cout << " BTI triggers " << std::endl;
00373 }
00374
00375
00376
00377 for(int sl=1;sl<=3;sl++){
00378 if(_btimap[sl-1].size()>0){
00379 BTI_iter pbti;
00380 for(pbti=_btimap[sl-1].begin(); pbti!=_btimap[sl-1].end(); pbti++) {
00381 DTBtiChip* bti = (*pbti).second;
00382 if(bti->number()<200)
00383 bti->run();
00384 for(int step=DTConfig::NSTEPF; step<=DTConfig::NSTEPL; step++){
00385 if(bti->nTrig(step)>0) {
00386 _cache.push_back( bti->triggerData(step,1) );
00387
00388
00389 }
00390 }
00391 }
00392 }
00393 }
00394
00395 if(debug())
00396 std::cout << "====================================================" << std::endl;
00397 }
00398 }
00399
00400 DTBtiChip*
00401 DTBtiCard::activeGetBTI(int sl, int n){
00402
00403 DTBtiChip* bti=0;
00404
00405 if( n<1 || n>geom()->nCell(sl) ){
00406 if(debug()){
00407 std::cout << "DTBtiCard::activeGetBTI :";
00408 std::cout << " invalid bti number: " << n;
00409 std::cout << " not in range [1," << geom()->nCell(sl) << "]";
00410 std::cout << " dummy BTI returned!" << std::endl;
00411 }
00412 sl = 1;
00413 n = 999;
00414 return bti;
00415 }
00416
00417
00418 DTChamberId sid = geom()->statId();
00419 DTBtiId _id = DTBtiId(sid, sl, n);
00420
00421
00422 int _debug_bti = config_bti(_id)->debug();
00423
00424 if(_debug_bti==3){
00425 std::cout << "DTBtiCard::activeGetBTI :";
00426 std::cout << " bti number: " << n << std::endl;
00427 }
00428
00429 if( sl<1 || sl>3){
00430 if(_debug_bti>1){
00431 std::cout << "DTBtiCard::activeGetBTI :";
00432 std::cout << " invalid superlayer number: " << sl;
00433 std::cout << " dummy BTI returned!" << std::endl;
00434 }
00435 sl = 1;
00436 n = 999;
00437 return bti;
00438 }
00439
00440 BTI_iter pbti = _btimap[sl-1].find(n);
00441 if( pbti!=_btimap[sl-1].end() ) {
00442 bti = (*pbti).second;
00443 } else {
00444 bti = new DTBtiChip(geom(),sl,n, config_bti(_id));
00445 _btimap[sl-1][n]=bti;
00446 }
00447 return bti;
00448 }
00449
00450 DTBtiChip*
00451 DTBtiCard::getBTI(int sl, int n) const {
00452 if(sl<1||sl>3||n==999){
00453 std::cout << "DTBtiCard::getBTI :";
00454 std::cout << " invalid superlayer number: " << sl;
00455 std::cout << " 0 returned!" << std::endl;
00456 return 0;
00457 }
00458 BTI_const_iter pbti = _btimap[sl-1].find(n);
00459 if( pbti==_btimap[sl-1].end() ){
00460 return 0;
00461 }
00462 return (*pbti).second;
00463 }
00464
00465 std::vector<DTBtiChip*>
00466 DTBtiCard::btiList(int sl) {
00467
00468 std::vector<DTBtiChip*> blist;
00469
00470 if(size()<1)return blist;
00471
00472 if(sl<1||sl>3){
00473 std::cout << "DTBtiCard::btiList :";
00474 std::cout << " invalid superlayer number: " << sl;
00475 std::cout << " empty list returned" << std::endl;
00476 return blist;
00477 }
00478
00479 for(BTI_const_iter p=_btimap[sl-1].begin();p!=_btimap[sl-1].end();p++){
00480 blist.push_back((*p).second);
00481 }
00482 return blist;
00483
00484 }
00485
00486 DTBtiTrig*
00487 DTBtiCard::storeTrigger(DTBtiTrigData td) {
00488 DTBtiId btiid = td.parentId();
00489 if(!(btiid.wheel()==wheel() &&
00490 btiid.sector()==sector() &&
00491 btiid.station()==station()) ) return 0;
00492 std::cout << "DTBtiCard::trigger: trigger not belonging to this card! ";
00493 std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
00494 std::cout << "trig=(" << btiid.wheel() << "," << btiid.station() << ","
00495 << btiid.sector() << ")";
00496
00497 DTBtiChip* bti = activeGetBTI(btiid.superlayer(), btiid.bti());
00498
00499 DTBtiTrig* trig = new DTBtiTrig(bti,td);
00500
00501 bti->addTrig(td.step(),trig);
00502
00503 return trig;
00504 }
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 LocalPoint
00548 DTBtiCard::localPosition(const DTTrigData* tr) const {
00549
00550 DTBtiTrigData* trig = dynamic_cast<DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
00551 if(!trig) {
00552 std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
00553 return LocalPoint(0,0,0);
00554 }
00555
00556
00557 float x = geom()->localPosition(trig->parentId()).x();
00558 float y = geom()->localPosition(trig->parentId()).y();
00559 float z = geom()->localPosition(trig->parentId()).z();
00560
00561
00562 int FE = geom()->posFE(trig->parentId().superlayer());
00563
00564
00565 float xt = 0;
00566 float yt = 0;
00567
00568 DTBtiId _btiid = trig->parentId();
00569 float xtrig = (float)trig->X() * geom()->cellPitch() / (config_bti(_btiid)->ST());
00570 if(trig->btiSL()==2)
00571 yt = - xtrig;
00572 else
00573 xt = + xtrig;
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583 if(debug()){
00584 std::cout << "DTBtiCard::localPosition of BTI in ("<<x<<","<<y<<","<<z<<")"<<std::endl;
00585 std::cout << " called for trig ";
00586 trig->print();
00587 std::cout << "in Local Point ("<<x+xt<<","<<y+yt<<","<<z<<")"<<std::endl;
00588 }
00589
00590 return LocalPoint(x+xt,y+yt,z);
00591 }
00592
00593
00594 LocalVector
00595 DTBtiCard::localDirection(const DTTrigData* tr) const {
00596
00597 DTBtiTrigData* trig = dynamic_cast<DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
00598
00599 if(!trig) {
00600 std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
00601 return LocalVector(0,0,0);
00602 }
00603
00604
00605
00606
00607
00608 DTBtiId _btiid = trig->parentId();
00609 float psi = atan((float)(trig->K() - config_bti(_btiid)->ST())*geom()->cellPitch()
00610 /(2*geom()->cellH() * config_bti(_btiid)->ST()));
00611
00612 float xd=0;
00613 float yd=0;
00614 float zd=-cos(psi);
00615 if(trig->btiSL()==2)
00616 yd = sin(psi);
00617 else
00618 xd = -sin(psi);
00619
00620
00621
00622
00623
00624
00625
00626 if(debug()){
00627
00628 float xb = geom()->localPosition(trig->parentId()).x();
00629 float yb = geom()->localPosition(trig->parentId()).y();
00630 float zb = geom()->localPosition(trig->parentId()).z();
00631
00632 std::cout << "DTBtiCard::localDirection of BTI in ("<<xb<<","<<yb<<","<<zb<<")"<<std::endl;
00633 std::cout << " called for trig ";
00634 trig->print();
00635 std::cout << "in Local Direction ("<<xd<<","<<yd<<","<<zd<<")"<<std::endl;
00636 }
00637
00638 return LocalVector(xd,yd,zd);
00639 }
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670 DTConfigBti*
00671 DTBtiCard::config_bti(DTBtiId& btiid) const
00672 {
00673
00674 ConfBtiMap::const_iterator biter = _conf_bti_map.find(btiid);
00675 if (biter == _conf_bti_map.end()){
00676 std::cout << "DTBtiCard::config_bti : BTI (" << btiid.wheel()
00677 << "," << btiid.sector()
00678 << "," << btiid.station()
00679 << "," << btiid.superlayer()
00680 << "," << btiid.bti()
00681 << ") not found, return 0" << std::endl;
00682 return 0;
00683 }
00684
00685 return const_cast<DTConfigBti*>(&(*biter).second);
00686
00687 }