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 _flag_acc = conf->useAcceptParam();
00109
00110 }
00111
00112
00113 void
00114 DTBtiCard::localClear(){
00115
00116 for(int i=0; i<3; i++){
00117 for(BTI_iter p=_btimap[i].begin();p!=_btimap[i].end();p++){
00118 delete (*p).second;
00119 }
00120 _btimap[i].clear();
00121 }
00122
00123
00124 std::vector<DTDigi*>::const_iterator p;
00125 for(p=_digis.begin();p<_digis.end();p++)
00126 delete (*p);
00127 _digis.clear();
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
00252
00253
00254 void
00255 DTBtiCard::loadBTI(const DTDigiCollection dtDigis) {
00256
00257 localClear();
00258
00259 if(debug()){
00260 std::cout << "DTBtiCard::loadBTI called for wheel=" << wheel() ;
00261 std::cout << ", station=" << station();
00262 std::cout << ", sector=" << sector() << std::endl;
00263 }
00264
00265 DTDigiCollection::DigiRangeIterator detUnitIt;
00266 for (detUnitIt=dtDigis.begin();
00267 detUnitIt!=dtDigis.end();
00268 ++detUnitIt){
00269
00270 const DTLayerId& id = (*detUnitIt).first;
00271 const DTDigiCollection::Range& range = (*detUnitIt).second;
00272
00273
00274 if(debug()){
00275 std::cout<<"--------------"<<std::endl;
00276 std::cout<<"id: "<<id;
00277 }
00278
00279
00280 for (DTDigiCollection::const_iterator digiIt = range.first;
00281 digiIt!=range.second;
00282 ++digiIt){
00283
00284 int tube = (*digiIt).wire();
00285 const DTWireId tubeid(id,tube);
00286 float tdrift = (*digiIt).time() - _digi_sync->offset(tubeid);
00287 if (debug()){
00288 std::cout << "digi time: " << (*digiIt).time();
00289 std::cout << " sync offset: " << _digi_sync->offset(tubeid) << std::endl;
00290 }
00291
00292 if(tdrift<500 && tdrift>-500){
00293 if(debug())
00294 (*digiIt).print();
00295
00296
00297
00298 DTSuperLayerId slnum = id.superlayerId();
00299
00300 int sln = slnum.superlayer();
00301 int layn = id.layer();
00302
00303
00304
00305
00306
00307
00308
00309 int nch = geom()->mapTubeInFEch(sln,layn,tube);
00310 int nbti = nch ;
00311
00312 if(debug()){
00313 std::cout << "FE ch " << nch;
00314 std::cout << " of bti " << nbti;
00315
00316 std::cout << " now nbti is " << nch << std::endl;
00317
00318 }
00319
00320
00321
00322
00323
00324 tdrift = tdrift + _finedelay;
00325
00326
00327
00328 DTDigi* pdigi = new DTDigi((*digiIt).wire(),tdrift);
00329 _digis.push_back(const_cast<DTDigi*>(pdigi) );
00330
00331
00332 switch(layn) {
00333 case 1:
00334 if(activeGetBTI(sln, nbti )) activeGetBTI(sln, nbti )->add_digi(4, pdigi);
00335 if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(8, pdigi);
00336 break;
00337 case 2:
00338 if(activeGetBTI(sln, nbti )) activeGetBTI(sln, nbti )->add_digi(2, pdigi);
00339 if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(6, pdigi);
00340 break;
00341 case 3:
00342 if(activeGetBTI(sln, nbti )) activeGetBTI(sln, nbti )->add_digi(3, pdigi);
00343 if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(7, pdigi);
00344 break;
00345 case 4:
00346 if(activeGetBTI(sln, nbti )) activeGetBTI(sln, nbti )->add_digi(1, pdigi);
00347 if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(5, pdigi);
00348 if(activeGetBTI(sln, nbti-2)) activeGetBTI(sln, nbti-2)->add_digi(9, pdigi);
00349 break;
00350 }
00351 }
00352
00353
00354 }
00355 }
00356 }
00357
00358 void
00359 DTBtiCard::runBTI() {
00360
00361 int nbtisig = _btimap[0].size()+_btimap[1].size()+_btimap[2].size();
00362
00363 if(debug()){
00364 std::cout << "DTBtiCard::runBTI called for wheel=" << wheel() ;
00365 std::cout << ", station=" << station();
00366 std::cout << ", sector=" << sector();
00367 std::cout << ", " << nbtisig
00368 << " BTIs with signal" << std::endl;
00369 }
00370
00371 if( nbtisig){
00372
00373 if(debug()){
00374 std::cout << "====================================================" << std::endl;
00375 std::cout << " BTI triggers " << std::endl;
00376 }
00377
00378
00379
00380 for(int sl=1;sl<=3;sl++){
00381 if(_btimap[sl-1].size()>0){
00382 BTI_iter pbti;
00383 for(pbti=_btimap[sl-1].begin(); pbti!=_btimap[sl-1].end(); pbti++) {
00384 DTBtiChip* bti = (*pbti).second;
00385 if(bti->number()<200)
00386 bti->run();
00387 for(int step=DTConfig::NSTEPF; step<=DTConfig::NSTEPL; step++){
00388 if(bti->nTrig(step)>0) {
00389 _cache.push_back( bti->triggerData(step,1) );
00390
00391
00392 }
00393 }
00394 }
00395 }
00396 }
00397
00398 if(debug())
00399 std::cout << "====================================================" << std::endl;
00400 }
00401 }
00402
00403 DTBtiChip*
00404 DTBtiCard::activeGetBTI(int sl, int n){
00405
00406 DTBtiChip* bti=0;
00407
00408 if( n<1 || n>geom()->nCell(sl) ){
00409 if(debug()){
00410 std::cout << "DTBtiCard::activeGetBTI :";
00411 std::cout << " invalid bti number: " << n;
00412 std::cout << " not in range [1," << geom()->nCell(sl) << "]";
00413 std::cout << " dummy BTI returned!" << std::endl;
00414 }
00415 sl = 1;
00416 n = 999;
00417 return bti;
00418 }
00419
00420
00421 DTChamberId sid = geom()->statId();
00422 DTBtiId _id = DTBtiId(sid, sl, n);
00423
00424
00425 int _debug_bti = config_bti(_id)->debug();
00426
00427 if(_debug_bti==3){
00428 std::cout << "DTBtiCard::activeGetBTI :";
00429 std::cout << " bti number: " << n << std::endl;
00430 }
00431
00432 if( sl<1 || sl>3){
00433 if(_debug_bti>1){
00434 std::cout << "DTBtiCard::activeGetBTI :";
00435 std::cout << " invalid superlayer number: " << sl;
00436 std::cout << " dummy BTI returned!" << std::endl;
00437 }
00438 sl = 1;
00439 n = 999;
00440 return bti;
00441 }
00442
00443 BTI_iter pbti = _btimap[sl-1].find(n);
00444 if( pbti!=_btimap[sl-1].end() ) {
00445 bti = (*pbti).second;
00446 } else {
00447 bti = new DTBtiChip(this, geom(),sl,n, config_bti(_id));
00448 _btimap[sl-1][n]=bti;
00449 }
00450 return bti;
00451 }
00452
00453 DTBtiChip*
00454 DTBtiCard::getBTI(int sl, int n) const {
00455 if(sl<1||sl>3||n==999){
00456 std::cout << "DTBtiCard::getBTI :";
00457 std::cout << " invalid superlayer number: " << sl;
00458 std::cout << " 0 returned!" << std::endl;
00459 return 0;
00460 }
00461 BTI_const_iter pbti = _btimap[sl-1].find(n);
00462 if( pbti==_btimap[sl-1].end() ){
00463 return 0;
00464 }
00465 return (*pbti).second;
00466 }
00467
00468 std::vector<DTBtiChip*>
00469 DTBtiCard::btiList(int sl) {
00470
00471 std::vector<DTBtiChip*> blist;
00472
00473 if(size()<1)return blist;
00474
00475 if(sl<1||sl>3){
00476 std::cout << "DTBtiCard::btiList :";
00477 std::cout << " invalid superlayer number: " << sl;
00478 std::cout << " empty list returned" << std::endl;
00479 return blist;
00480 }
00481
00482 for(BTI_const_iter p=_btimap[sl-1].begin();p!=_btimap[sl-1].end();p++){
00483 blist.push_back((*p).second);
00484 }
00485 return blist;
00486
00487 }
00488
00489 DTBtiTrig*
00490 DTBtiCard::storeTrigger(DTBtiTrigData td) {
00491 DTBtiId btiid = td.parentId();
00492 if(!(btiid.wheel()==wheel() &&
00493 btiid.sector()==sector() &&
00494 btiid.station()==station()) ) return 0;
00495 std::cout << "DTBtiCard::trigger: trigger not belonging to this card! ";
00496 std::cout << "card=(" << wheel() << "," << station() << "," << sector() << ") ";
00497 std::cout << "trig=(" << btiid.wheel() << "," << btiid.station() << ","
00498 << btiid.sector() << ")";
00499
00500 DTBtiChip* bti = activeGetBTI(btiid.superlayer(), btiid.bti());
00501
00502 DTBtiTrig* trig = new DTBtiTrig(bti,td);
00503
00504 bti->addTrig(td.step(),trig);
00505
00506 return trig;
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
00548
00549
00550 LocalPoint
00551 DTBtiCard::localPosition(const DTTrigData* tr) const {
00552
00553 DTBtiTrigData* trig = dynamic_cast<DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
00554 if(!trig) {
00555 std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
00556 return LocalPoint(0,0,0);
00557 }
00558
00559
00560 float x = geom()->localPosition(trig->parentId()).x();
00561 float y = geom()->localPosition(trig->parentId()).y();
00562 float z = geom()->localPosition(trig->parentId()).z();
00563
00564
00565
00566
00567
00568 float xt = 0;
00569 float yt = 0;
00570
00571 DTBtiId _btiid = trig->parentId();
00572 float xtrig = (float)trig->X() * geom()->cellPitch() / (config_bti(_btiid)->ST());
00573 if(trig->btiSL()==2)
00574 yt = - xtrig;
00575 else
00576 xt = + xtrig;
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 if(debug()){
00587 std::cout << "DTBtiCard::localPosition of BTI in ("<<x<<","<<y<<","<<z<<")"<<std::endl;
00588 std::cout << " called for trig ";
00589 trig->print();
00590 std::cout << "in Local Point ("<<x+xt<<","<<y+yt<<","<<z<<")"<<std::endl;
00591 }
00592
00593 return LocalPoint(x+xt,y+yt,z);
00594 }
00595
00596
00597 LocalVector
00598 DTBtiCard::localDirection(const DTTrigData* tr) const {
00599
00600 DTBtiTrigData* trig = dynamic_cast<DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
00601
00602 if(!trig) {
00603 std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
00604 return LocalVector(0,0,0);
00605 }
00606
00607
00608
00609
00610
00611 DTBtiId _btiid = trig->parentId();
00612 float psi = atan((float)(trig->K() - config_bti(_btiid)->ST())*geom()->cellPitch()
00613 /(2*geom()->cellH() * config_bti(_btiid)->ST()));
00614
00615 float xd=0;
00616 float yd=0;
00617 float zd=-cos(psi);
00618 if(trig->btiSL()==2)
00619 yd = sin(psi);
00620 else
00621 xd = -sin(psi);
00622
00623
00624
00625
00626
00627
00628
00629 if(debug()){
00630
00631 float xb = geom()->localPosition(trig->parentId()).x();
00632 float yb = geom()->localPosition(trig->parentId()).y();
00633 float zb = geom()->localPosition(trig->parentId()).z();
00634
00635 std::cout << "DTBtiCard::localDirection of BTI in ("<<xb<<","<<yb<<","<<zb<<")"<<std::endl;
00636 std::cout << " called for trig ";
00637 trig->print();
00638 std::cout << "in Local Direction ("<<xd<<","<<yd<<","<<zd<<")"<<std::endl;
00639 }
00640
00641 return LocalVector(xd,yd,zd);
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
00671
00672
00673 DTConfigBti*
00674 DTBtiCard::config_bti(DTBtiId& btiid) const
00675 {
00676
00677 ConfBtiMap::const_iterator biter = _conf_bti_map.find(btiid);
00678 if (biter == _conf_bti_map.end()){
00679 std::cout << "DTBtiCard::config_bti : BTI (" << btiid.wheel()
00680 << "," << btiid.sector()
00681 << "," << btiid.station()
00682 << "," << btiid.superlayer()
00683 << "," << btiid.bti()
00684 << ") not found, return 0" << std::endl;
00685 return 0;
00686 }
00687
00688 return const_cast<DTConfigBti*>(&(*biter).second);
00689
00690 }