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