CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/L1Trigger/DTBti/src/DTBtiCard.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTBtiCard
00004 //
00005 //   Description: Contains active DTBtiChips
00006 //
00007 //
00008 //   Author List:
00009 //   C. Grandi
00010 //   Modifications: 
00011 //   S. Vanini
00012 //   22/VI/04 SV: last trigger code update - digi offset subtracted from digi time
00013 //   III/05 SV  : NEWGEO : trigger in new geometry ! 
00014 //   05/II/07 SV : new DTConfig update 
00015 //   30/III/07 SV : config with DTConfigManager every single chip
00016 //----------------------------------------------------------------
00017 
00018 //-----------------------
00019 // This Class's Header --
00020 //-----------------------
00021 #include "L1Trigger/DTBti/interface/DTBtiCard.h"
00022 
00023 //-------------------------------
00024 // Collaborating Class Headers --
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 // C++ Headers --
00049 //---------------
00050 #include <iostream>
00051 #include <cmath>
00052 #include <utility>  
00053 #include <vector>
00054 
00055 using namespace edm;                            
00056 
00057 //----------------
00058 // Constructors --
00059 //----------------
00060 
00061 DTBtiCard::DTBtiCard(DTTrigGeom *geom, DTTTrigBaseSync *sync) : 
00062   DTGeomSupplier(geom), _digi_sync(sync) {
00063 
00064         //_configBti = new DTConfigBti(bti_pset);
00065         //_configBti->print();
00066 
00067         //DTChamberId sid = ChamberId();
00068         //_conf_bti_map = conf_manager->getDTConfigBtiMap(sid); 
00069         //_debug = conf_manager->getDTTPGDebug();
00070 
00071         //_finedelay   = conf_manager->getDTConfigTrigUnit(sid)->MCSetupTime();
00072         //_MCdelay     = conf_manager->getDTConfigTrigUnit(sid)->MCDigiOffset();
00073 
00074 }
00075 
00076 //--------------
00077 // Destructor --
00078 //--------------
00079 
00080 DTBtiCard::~DTBtiCard(){
00081 
00082   localClear();
00083   //delete _conf_Bti;
00084   
00085 }
00086 
00087 //--------------
00088 // Operations --
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   // get bti acceptance flag
00108   _flag_acc = conf->useAcceptParam();
00109 
00110 }
00111 
00112 
00113 void
00114 DTBtiCard::localClear(){
00115 // Clear the maps
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   //clear digis
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 // void 
00131 // //DTBtiCard::loadBTI() {
00132 // DTBtiCard::loadBTI(const DTDigiCollection dtDigis) {
00133 
00134 //   localClear();
00135  
00136 //    int ndigis = stat()->ndigis();
00137 
00138 
00139 // // /*
00140 // //   //SV version for tb2003 data
00141 // //   // loop over chambers, superlayers and layers
00142 // //   DTBXSetUp* setup = Singleton<DTBXSetUp>::instance();
00143 // //   DTDetectorMap* detMap = setup->chamberMap();
00144 // //   std::vector<DTChamber*> chambers = detMap->chambers();
00145 // //   DTDetectorMap::ChamIter stat;
00146 // //   for ( stat = chambers.begin(); stat != chambers.end(); stat++ ) {
00147 // // */
00148 
00149 // //   // Get DTDigi's from DTChamber  (stat is DTChamber*) 
00150 // //   // Loop over all Digis and make a local copy
00151 // //   // Store a pointer to them in the relevant DTBtiChip's
00152 
00153 //   if(ndigis){
00154 
00155 //     if(debug()){
00156 //       std::cout << "====================================================" << std::endl;
00157 //       std::cout <<  ndigis << " DIGIS in  wheel " << wheel() << 
00158 //               " station " << station() <<
00159 //               " sector "  << sector() << std::endl; 
00160 //     }
00161 
00162 
00163 //     std::vector<DTDigi> digi_container = stat()->digis();
00164 //     std::vector<DTDigi>::const_iterator       digi_iter;
00165 
00166 //     for(digi_iter=digi_container.begin(); digi_iter<digi_container.end(); digi_iter++){
00167 
00168 //     /*Testbeam 2004 specific code
00169 //     //digi.time in ns; digi.countsTDC in tdcunits
00170 //     //float tdrift = (*digi_iter).time()-1.0*DTDigiParameters::offset;
00171 //     //TB2004 version: no offset subtraction because digi are already t0 off!!!!
00172 //     //tdrift must be float, otherwise DTDigi constructor assumes tdcunits!
00173 //     //add chamber specific delay
00174 //     int tdctime = (*digi_iter).countsTDC();
00175 //     int mcdelay = (stat()->id().station()==1) ? config()->SetupTimeMB1() : config()->SetupTimeMB
00176 // 3();
00177 //     tdctime += mcdelay;
00178 //     */
00179 //       float tdrift = (*digi_iter).time()-1.0*DTDigiParameters::offset;
00180 //       DTWireId idwire( wheel(), station(), sector(), (*digi_iter).slayer(), 
00181 //                         (*digi_iter).layer(), (*digi_iter).wire() );
00182 
00183 
00184 // /*
00185 //   //NEWGEO TEST: sw testpulse for testing new geometry in wire 1 of each sl
00186 //   for(int l=0;l<12;l++){
00187 //     int sl = int(l/4.) + 1;
00188 //     if(station()!=4 || sl!=2){
00189 //     int lay = int(fmod(l,4.)) + 1;
00190 //     int wire = 2*sector();
00191 //     if(geom()->posFE(sl)==0 || station()==1 || sl==2)
00192 //       wire += lay==4? 1:2;
00193 //     else if(geom()->posFE(sl)==1) 
00194 //       wire += lay==3? 3:2;
00195 
00196 //     //int wire = 1;
00197 //     //tmax=400ns, straight tracks in middle : 200ns (float for ns, int for tdc_counts)
00198 //     //float tdrift = 187.5;
00199 //     float tdrift = 200.0;
00200 //     DTWireId idwire( wheel(), station(), sector(), sl, lay, wire);
00201 // */
00202 
00203 //       DTDigi* pdigi = new DTDigi(idwire,tdrift);
00204 //       _digis.push_back(const_cast<DTDigi*>(pdigi));
00205 
00206 //       if(debug())
00207 //         pdigi->print();
00208 
00209 //       int sln = pdigi->slayer();
00210 //       int layn = pdigi->layer();
00211 //       int tube = pdigi->wire();
00212 
00213 //       // map in FE channel number:
00214 //       int nch = geom()->mapTubeInFEch(sln,layn,tube);
00215 
00216 //       // assign ch numbers to btis: depends on layer staggering!
00217 //       int nbti = nch + geom()->layerFEStaggering(sln,layn);
00218 
00219 //       if(debug()){
00220 //         std::cout << "FE ch " << nch;
00221 //         std::cout << " of bti " << nbti;
00222 //         std::cout << " staggering " <<  geom()->layerFEStaggering(sln,layn);
00223 //         std::cout << " now nbti is " << nch;
00224 //         std::cout << " SL phi offset " << geom()->phiSLOffset() << std::endl; 
00225 //       }  
00226 
00227 //       switch(layn) {
00228 //       case 1:
00229 //         if(activeGetBTI(sln, nbti  )) activeGetBTI(sln, nbti  )->add_digi(4, pdigi);
00230 //         if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(8, pdigi);
00231 //       break;
00232 //       case 2:
00233 //         if(activeGetBTI(sln, nbti  )) activeGetBTI(sln, nbti  )->add_digi(2, pdigi);
00234 //         if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(6, pdigi);
00235 //       break;
00236 //       case 3:
00237 //         if(activeGetBTI(sln, nbti  )) activeGetBTI(sln, nbti  )->add_digi(3, pdigi);
00238 //         if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(7, pdigi);
00239 //       break;
00240 //       case 4:
00241 //         if(activeGetBTI(sln, nbti  )) activeGetBTI(sln, nbti  )->add_digi(1, pdigi);
00242 //         if(activeGetBTI(sln, nbti-1)) activeGetBTI(sln, nbti-1)->add_digi(5, pdigi);
00243 //         if(activeGetBTI(sln, nbti-2)) activeGetBTI(sln, nbti-2)->add_digi(9, pdigi);
00244 //       break;
00245 //       }
00246 //     }//end loop on digi
00247 
00248 //     if(debug())
00249 //       std::cout << "====================================================" << std::endl;
00250 
00251 //   }//end if(ndigis)
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     // DTLayerId print-out
00274     if(debug()){
00275       std::cout<<"--------------"<<std::endl;
00276       std::cout<<"id: "<<id;
00277     }
00278     
00279     // Loop over the digis of this DetUnit
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         // get bti number for access to the configuration for this bti chip : SV
00297         // FIX: for the moment take first bti configuration!!!!! ok fixed
00298         DTSuperLayerId slnum = id.superlayerId();
00299         //DTChamberId dtcham =id.chamberId();
00300         int sln = slnum.superlayer();
00301         int layn = id.layer();
00302         //int tube = (*digiIt).wire();
00303 
00304         // map in FE channel number: SL theta tubes are numbered inversely w.r.t. hardware setup in new geometry 19/06/06
00305         // assign ch numbers to btis: in new geometry does not depend on layer staggering anymore! Same staggering anywhere.
00306         //int nch = geom()->mapTubeInFEch(sln,layn,tube);
00307         //      int nbti = nch + geom()->layerFEStaggering(sln,layn);
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 //        std::cout << " staggering " <<  geom()->layerFEStaggering(sln,layn);
00316           std::cout << " now nbti is " << nch <<  std::endl;
00317 //        std::cout << " SL phi offset " << geom()->phiSLOffset() << std::endl; 
00318         }
00319         
00320         // FIXED get configuration for the nbti chip Identifier, and from it MCdelay + finedelay
00321         //DTChamberId sid = geom()->statId();
00322         //DTBtiId _id = DTBtiId(sid, sln, nbti);
00323  
00324         tdrift = tdrift + _finedelay; 
00325 //      float tdrift = (*digiIt).time() - _MCdelay + _finedelay; 
00326 //      std::cout<<"tdrift "<< tdrift << " (*digiIt).wire() " << (*digiIt).wire() << std::endl;
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       }//end loop on digi
00352       //    }//end loop on lay
00353       //  }//end loop on sl
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     // run DTBtiChip algorithm on all non-empty BTI
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               //localPosition(&(bti->triggerData(step,1))); 
00391               //localDirection(&(bti->triggerData(step,1))); 
00392              }
00393             }
00394         }
00395       }
00396     }
00397 
00398     if(debug())
00399       std::cout << "====================================================" << std::endl;
00400   }//end if(nbtisig)
00401 }
00402 
00403 DTBtiChip* 
00404 DTBtiCard::activeGetBTI(int sl, int n){
00405 
00406   DTBtiChip* bti=0;
00407   //check if BTi is out of range before all
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   // get configuration for this chip Identifier
00421   DTChamberId sid = geom()->statId();
00422   DTBtiId _id = DTBtiId(sid, sl, n); 
00423 
00424   //debug this chip
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   // get the appropriate BTI
00500   DTBtiChip* bti = activeGetBTI(btiid.superlayer(), btiid.bti());
00501   // create a new trigger in the BTI
00502   DTBtiTrig* trig = new DTBtiTrig(bti,td);
00503   // add the trigger to the BTI
00504   bti->addTrig(td.step(),trig);
00505   // return the trigger
00506   return trig;
00507 }
00508 
00509 /*
00510 LocalPoint 
00511 DTBtiCard::localPosition(const DTTrigData* tr) const {
00512 //OBSOLETE!!!!!
00513   //@@ patch for Sun 4.2 compiler
00514   DTBtiTrigData* trig = dynamic_cast<DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
00515   //  const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
00516   if(!trig) {
00517     std::cout << "DTBtiCard::localPosition called with wrong argument!" << std::endl;
00518     return LocalPoint(0,0,0);
00519   }
00520   float x = geom()->localPosition(trig->parentId()).x();
00521   float y = geom()->localPosition(trig->parentId()).y();
00522   float z = geom()->localPosition(trig->parentId()).z();
00523   
00524   //FE position
00525   int FE = geom()->posFE(trig->parentId().superlayer());
00526 
00527   //trigger position in the BTI frame
00528   float xt = 0;
00529   float yt = 0;
00530   float xtrig = (float)trig->X() * geom()->cellPitch() / (config()->ST());
00531   if(trig->btiSL()==2) 
00532     yt = - xtrig;
00533   else
00534     xt = + xtrig;
00535 
00536   if(FE==1){//FE in negative y
00537       xt = - xt;
00538       yt = - yt;
00539   }
00540 
00541   std::cout << "DTBtiCard::localPosition of BTI in ("<<x<<","<<y<<","<<z<<")"<<std::endl;
00542   std::cout << " called for trig "; 
00543   trig->print(); 
00544   std::cout << "in Local Point ("<<x+xt<<","<<y+yt<<","<<z<<")"<<std::endl;
00545 
00546   return LocalPoint(x+xt,y+yt,z);
00547 }
00548 */
00549 
00550 LocalPoint 
00551 DTBtiCard::localPosition(const DTTrigData* tr) const {
00552 //NEWGEO!!!
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   //BTI position in chamber frame
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   //FE position
00565   //int FE = geom()->posFE(trig->parentId().superlayer());
00566 
00567   //trigger position in the BTI frame
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 //   17/07/06 Should be obsolete in CMSSW
00579 //   if(FE==1){//FE in negative y
00580 //       xt = - xt;
00581 //       yt = - yt;
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 //NEWGEO
00600  DTBtiTrigData* trig = dynamic_cast<DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
00601  //this method is only for check purpose
00602   if(!trig) {
00603     std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
00604     return LocalVector(0,0,0);
00605   }
00606 
00607   //FE position
00608   //int FE = geom()->posFE(trig->parentId().superlayer());
00609 
00610   // psi in BTI frame
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   // (xd,yd,zd) in chamber frame
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 // 17/07/06 Ths should be obsolete in CMSSW
00624 //   if(FE==1){//FE in negative y
00625 //       xd = - xd;
00626 //       yd = - yd;
00627 //  }
00628 
00629   if(debug()){
00630     //BTI position in chamber frame
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 LocalVector
00647 DTBtiCard::localDirection(const DTTrigData* tr) const {
00648 //OBSOLETE!!!!
00649   //@@ patch for Sun 4.2 compiler
00650   const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(const_cast<DTTrigData*>(tr));
00651   //  const DTBtiTrigData* trig = dynamic_cast<const DTBtiTrigData*>(tr);
00652   if(!trig) {
00653     std::cout << "DTBtiCard::localDirection called with wrong argument!" << std::endl;
00654     return LocalVector(0,0,0);
00655   }
00656   float x1,r,x,y,z;
00657   x1 = -(float)trig->K() * geom()->cellPitch() /
00658                       (float)(config()->ST());
00659   z = - 2 * geom()->cellH();
00660   r = sqrt(x1*x1+z*z);
00661   if(trig->btiSL()!=2) {
00662     x = x1/r;
00663     y = 0;
00664   } else {
00665     x = 0;
00666     y = x1/r;
00667   }
00668   z /= r;
00669   return LocalVector(x,y,z);
00670 }
00671 */
00672 
00673 DTConfigBti* 
00674 DTBtiCard::config_bti(DTBtiId& btiid) const 
00675 {
00676   //loop on map to find bti
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 }