CMS 3D CMS Logo

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