CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/CalibTracker/SiStripCommon/src/TkDetMap.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripCommon/interface/TkDetMap.h"
00002 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00003 #include "DataFormats/SiStripDetId/interface/SiStripSubStructure.h"
00004 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00005 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00006 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00007 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include <iostream>
00012 #include <cstring>
00013 
00014 TkLayerMap::TkLayerMap(int in):layerEnumNb_(in){
00015 
00016   LogTrace("TkLayerMap") <<" TkLayerMap::constructor for layer " << in;
00017 
00018   initialize(layerEnumNb_);
00019 
00020  if(!edm::Service<SiStripDetInfoFileReader>().isAvailable()){
00021     edm::LogError("TkLayerMap") << 
00022       "\n------------------------------------------"
00023       "\nUnAvailable Service SiStripDetInfoFileReader: please insert in the configuration file an instance like"
00024       "\n\tprocess.SiStripDetInfoFileReader = cms.Service(\"SiStripDetInfoFileReader\")"
00025       "\n------------------------------------------";
00026   }
00027  
00028   SiStripDetInfoFileReader * fr=edm::Service<SiStripDetInfoFileReader>().operator->();
00029 
00030   std::vector<uint32_t> TkDetIdList=fr->getAllDetIds();
00031   
00032   switch (layerEnumNb_)
00033     {
00034     case TkLayerMap::TIB_L1:
00035     case TkLayerMap::TIB_L2:
00036     case TkLayerMap::TIB_L3:
00037     case TkLayerMap::TIB_L4:         
00038       createTIB(TkDetIdList,layerEnumNb_);
00039       break;
00040     case TkLayerMap::TIDP_D1:
00041     case TkLayerMap::TIDP_D2:
00042     case TkLayerMap::TIDP_D3:
00043     case TkLayerMap::TIDM_D1:
00044     case TkLayerMap::TIDM_D2:
00045     case TkLayerMap::TIDM_D3:
00046       createTID(TkDetIdList,layerEnumNb_); 
00047       break;
00048     case TkLayerMap::TOB_L1:
00049     case TkLayerMap::TOB_L2:
00050     case TkLayerMap::TOB_L3:
00051     case TkLayerMap::TOB_L4:
00052     case TkLayerMap::TOB_L5:
00053     case TkLayerMap::TOB_L6:
00054       createTOB(TkDetIdList,layerEnumNb_); 
00055     break;
00056     case TkLayerMap::TECP_W1:
00057     case TkLayerMap::TECP_W2:
00058     case TkLayerMap::TECP_W3:
00059     case TkLayerMap::TECP_W4:
00060     case TkLayerMap::TECP_W5: 
00061     case TkLayerMap::TECP_W6:
00062     case TkLayerMap::TECP_W7:
00063     case TkLayerMap::TECP_W8:
00064     case TkLayerMap::TECP_W9:
00065     case TkLayerMap::TECM_W1:
00066     case TkLayerMap::TECM_W2:
00067     case TkLayerMap::TECM_W3:
00068     case TkLayerMap::TECM_W4:
00069     case TkLayerMap::TECM_W5: 
00070     case TkLayerMap::TECM_W6:
00071     case TkLayerMap::TECM_W7:
00072     case TkLayerMap::TECM_W8:
00073     case TkLayerMap::TECM_W9:
00074       createTEC(TkDetIdList,layerEnumNb_); 
00075       break;
00076     default:
00077       edm::LogError("TkLayerMap") <<" TkLayerMap::requested creation of a wrong layer Nb "<< layerEnumNb_; 
00078     }
00079 }
00080 
00081 uint32_t TkLayerMap::getDetFromBin(int ix, int iy){
00082   
00083   int val=(ix-1)+nchX*(iy-1);
00084   if(val>-1 && val < nchX*nchY)
00085     return binToDet[val];
00086   return 0;
00087 }
00088 
00089 const int16_t TkLayerMap::layerSearch(uint32_t detid){
00090   
00091     //  switch((detid>>25)&0x7){
00092   if(SiStripDetId(detid).subDetector()==SiStripDetId::TIB){
00093     TIBDetId D(detid);
00094     return TkLayerMap::TIB_L1  -1 +D.layerNumber();
00095   } else if (SiStripDetId(detid).subDetector()==SiStripDetId::TID){
00096     TIDDetId D(detid);
00097     return TkLayerMap::TIDM_D1 -1 + (D.side() -1)*3 + D.wheel();
00098   } else if (SiStripDetId(detid).subDetector()==SiStripDetId::TOB){
00099     TOBDetId D(detid);
00100     return TkLayerMap::TOB_L1  -1 +D.layerNumber();
00101   } else if (SiStripDetId(detid).subDetector()==SiStripDetId::TEC){
00102     TECDetId D(detid);
00103     return TkLayerMap::TECM_W1 -1 + (D.side() -1)*9 + D.wheel();
00104   }
00105   return 0;
00106 }
00107 
00108 void TkLayerMap::initialize(int layer){
00109 
00110   switch (layer){
00111   case TkLayerMap::TIB_L1: //TIBL1
00112     
00113     Nstring_ext=30;
00114     SingleExtString.insert(SingleExtString.begin(),8,0);
00115     SingleExtString.insert(SingleExtString.begin()+8,7,1);
00116     SingleExtString.insert(SingleExtString.begin()+15,8,2);
00117     SingleExtString.insert(SingleExtString.begin()+23,7,3);
00118     nchX=12;
00119     lowX=-6;
00120     highX=6;
00121     nchY=2*(Nstring_ext+1);
00122     lowY=-1.*(Nstring_ext+1.);
00123     highY=(Nstring_ext+1);
00124     
00125     break;
00126     case TkLayerMap::TIB_L2:
00127     
00128     Nstring_ext=38;
00129     SingleExtString.insert(SingleExtString.begin(),10,0);
00130     SingleExtString.insert(SingleExtString.begin()+10,9,1);
00131     SingleExtString.insert(SingleExtString.begin()+19,10,2);
00132     SingleExtString.insert(SingleExtString.begin()+29,9,3);
00133     nchX=12;
00134     lowX=-6;
00135     highX=6;
00136     nchY=2*(Nstring_ext+1);
00137     lowY=-1.*(Nstring_ext+1.);
00138     highY=(Nstring_ext+1);
00139 
00140     break;
00141   case TkLayerMap::TIB_L3:
00142 
00143     Nstring_ext=46; 
00144     SingleExtString.insert(SingleExtString.begin(),23,0);
00145     SingleExtString.insert(SingleExtString.begin()+23,23,1);
00146     nchX=12;
00147     lowX=-6;
00148     highX=6;
00149     nchY=Nstring_ext;
00150     lowY=0;
00151     highY=nchY;
00152 
00153     break;
00154   case TkLayerMap::TIB_L4:
00155 
00156     Nstring_ext=56;
00157     SingleExtString.insert(SingleExtString.begin(),14,0);
00158     SingleExtString.insert(SingleExtString.begin()+14,14,1);
00159     SingleExtString.insert(SingleExtString.begin()+28,14,2);
00160     SingleExtString.insert(SingleExtString.begin()+42,14,3);
00161     nchX=12;
00162     lowX=-6.;
00163     highX=6.;
00164     nchY=Nstring_ext;
00165     lowY=0.;
00166     highY=nchY;
00167 
00168     break;
00169   case TkLayerMap::TIDM_D1:  //TID
00170   case TkLayerMap::TIDM_D2:  //TID
00171   case TkLayerMap::TIDM_D3:  //TID
00172 
00173     nchX=7;
00174     lowX=-7.;
00175     highX=0.;
00176     nchY=40;
00177     lowY=0.0;
00178     highY=1.*nchY;
00179 
00180     break;
00181   case TkLayerMap::TIDP_D1:  //TID
00182   case TkLayerMap::TIDP_D2:  //TID
00183   case TkLayerMap::TIDP_D3:  //TID
00184     
00185     nchX=7;
00186     lowX=0.;
00187     highX=7.;
00188     nchY=40;
00189     lowY=0.0;
00190     highY=1.*nchY;
00191 
00192     break;
00193   case TkLayerMap::TOB_L1:  //TOBL1
00194 
00195     Nrod=42;
00196     nchX=12;
00197     lowX=-6.;
00198     highX=6.;
00199     nchY=2*(Nrod+1);
00200     lowY=-1.*(Nrod+1.);
00201     highY=(Nrod+1.);
00202 
00203     break;
00204   case TkLayerMap::TOB_L2:
00205     
00206     Nrod=48;
00207     nchX=12;
00208     lowX=-6.;
00209     highX=6.;
00210     nchY=int(2.*(Nrod+1.));
00211     lowY=-1.*(Nrod+1.);
00212     highY=(Nrod+1.);
00213     
00214     break;
00215   case TkLayerMap::TOB_L3: //TOBL3
00216    
00217     Nrod=54;
00218     nchX=12;
00219     lowX=-6.;
00220     highX=6.;
00221     nchY=Nrod;
00222     lowY=0.;
00223     highY=1.*Nrod;
00224     
00225     break;
00226   case TkLayerMap::TOB_L4:
00227     
00228     Nrod=60;
00229     nchX=12;
00230     lowX=-6.;
00231     highX=6.;
00232     nchY=Nrod;
00233     lowY=0.;
00234     highY=1.*Nrod;
00235 
00236     break;
00237   case TkLayerMap::TOB_L5:
00238     
00239     Nrod=66;
00240     nchX=12;
00241     lowX=-6.;
00242     highX=6.;
00243     nchY=Nrod;
00244     lowY=0.;
00245     highY=1.*Nrod;
00246 
00247     break;
00248   case TkLayerMap::TOB_L6:
00249     
00250     Nrod=74;
00251     nchX=12;
00252     lowX=-6.;
00253     highX=6.;
00254     nchY=Nrod;
00255     lowY=0.;
00256     highY=1.*Nrod;
00257 
00258     break;
00259   default: //TEC
00260     switch (layer){
00261     case TkLayerMap::TECM_W1:
00262     case TkLayerMap::TECM_W2:
00263     case TkLayerMap::TECM_W3:
00264       nchX=16;
00265       lowX=-16.;
00266       highX=0.;
00267       nchY=80;
00268       lowY=0.;
00269       highY=1.*nchY;
00270 
00271       BinForRing.push_back(0); //null value for component 0
00272       BinForRing.push_back(1);
00273       BinForRing.push_back(4);
00274       BinForRing.push_back(7);
00275       BinForRing.push_back(9);
00276       BinForRing.push_back(11);
00277       BinForRing.push_back(14);
00278       BinForRing.push_back(16);
00279       break;
00280     case TkLayerMap::TECM_W4:
00281     case TkLayerMap::TECM_W5: 
00282     case TkLayerMap::TECM_W6:
00283       nchX=13;
00284       lowX=-16.;
00285       highX=-3.;
00286       nchY=80;
00287       lowY=0.;
00288       highY=1.*nchY;
00289 
00290       BinForRing.push_back(0); //null value for component 0
00291       BinForRing.push_back(0);
00292       BinForRing.push_back(1);
00293       BinForRing.push_back(4);
00294       BinForRing.push_back(6);
00295       BinForRing.push_back(8);
00296       BinForRing.push_back(11);
00297       BinForRing.push_back(13);
00298       break;
00299     case TkLayerMap::TECM_W7:
00300     case TkLayerMap::TECM_W8:
00301       nchX=10;
00302       lowX=-16.;
00303       highX=-6.;
00304       nchY=80;
00305       lowY=0.;
00306       highY=1.*nchY;
00307 
00308       BinForRing.push_back(0); //null value for component 0
00309       BinForRing.push_back(0);
00310       BinForRing.push_back(0);
00311       BinForRing.push_back(1);
00312       BinForRing.push_back(3);
00313       BinForRing.push_back(5);
00314       BinForRing.push_back(8);
00315       BinForRing.push_back(10);
00316       break;
00317     case TkLayerMap::TECM_W9:
00318       nchX=8;
00319       lowX=-16.;
00320       highX=-8.;
00321       nchY=80;
00322       lowY=0.;
00323       highY=1.*nchY;
00324 
00325       BinForRing.push_back(0); //null value for component 0
00326       BinForRing.push_back(0);
00327       BinForRing.push_back(0);
00328       BinForRing.push_back(0);
00329       BinForRing.push_back(1);
00330       BinForRing.push_back(3);
00331       BinForRing.push_back(6);
00332       BinForRing.push_back(8);
00333       break;
00334     case TkLayerMap::TECP_W1:
00335     case TkLayerMap::TECP_W2:
00336     case TkLayerMap::TECP_W3:
00337       nchX=16;
00338       lowX=0.;
00339       highX=16.;
00340       nchY=80;
00341       lowY=0.;
00342       highY=1.*nchY;
00343 
00344       BinForRing.push_back(0); //null value for component 0
00345       BinForRing.push_back(1);
00346       BinForRing.push_back(4);
00347       BinForRing.push_back(7);
00348       BinForRing.push_back(9);
00349       BinForRing.push_back(11);
00350       BinForRing.push_back(14);
00351       BinForRing.push_back(16);
00352       break;
00353     case TkLayerMap::TECP_W4:
00354     case TkLayerMap::TECP_W5: 
00355     case TkLayerMap::TECP_W6:
00356       nchX=13;
00357       lowX=3.;
00358       highX=16.;
00359       nchY=80;
00360       lowY=0.;
00361       highY=1.*nchY;
00362 
00363       BinForRing.push_back(0); //null value for component 0
00364       BinForRing.push_back(0);
00365       BinForRing.push_back(1);
00366       BinForRing.push_back(4);
00367       BinForRing.push_back(6);
00368       BinForRing.push_back(8);
00369       BinForRing.push_back(11);
00370       BinForRing.push_back(13);
00371       break;
00372     case TkLayerMap::TECP_W7:
00373     case TkLayerMap::TECP_W8:
00374       nchX=10;
00375       lowX=6.;
00376       highX=16.;
00377       nchY=80;
00378       lowY=0.;
00379       highY=1.*nchY;
00380 
00381       BinForRing.push_back(0); //null value for component 0
00382       BinForRing.push_back(0);
00383       BinForRing.push_back(0);
00384       BinForRing.push_back(1);
00385       BinForRing.push_back(3);
00386       BinForRing.push_back(5);
00387       BinForRing.push_back(8);
00388       BinForRing.push_back(10);
00389       break;
00390     case TkLayerMap::TECP_W9:
00391       nchX=8;
00392       lowX=8.;
00393       highX=16.;
00394       nchY=80;
00395       lowY=0.;
00396       highY=1.*nchY;
00397 
00398       BinForRing.push_back(0); //null value for component 0
00399       BinForRing.push_back(0);
00400       BinForRing.push_back(0);
00401       BinForRing.push_back(0);
00402       BinForRing.push_back(1);
00403       BinForRing.push_back(3);
00404       BinForRing.push_back(6);
00405       BinForRing.push_back(8);
00406     }
00407 
00408 
00409     ModulesInRingFront.push_back(0); //null value for component 0
00410     ModulesInRingFront.push_back(2);
00411     ModulesInRingFront.push_back(2);
00412     ModulesInRingFront.push_back(3);
00413     ModulesInRingFront.push_back(4);
00414     ModulesInRingFront.push_back(2);
00415     ModulesInRingFront.push_back(4);
00416     ModulesInRingFront.push_back(5);
00417 
00418     ModulesInRingBack.push_back(0); //null value for component 0
00419     ModulesInRingBack.push_back(1);    
00420     ModulesInRingBack.push_back(1);    
00421     ModulesInRingBack.push_back(2);    
00422     ModulesInRingBack.push_back(3);    
00423     ModulesInRingBack.push_back(3);    
00424     ModulesInRingBack.push_back(3);    
00425     ModulesInRingBack.push_back(5);
00426   }
00427   
00428   for (size_t i=0;i<SingleExtString.size();i++)
00429     LogTrace("TkLayerMap") << "[initialize SingleExtString["<<i<<"] " << SingleExtString[i];
00430 
00431   binToDet= new uint32_t[nchX*nchY];
00432   for(size_t i=0;i<(size_t) nchX*nchY;++i)
00433     binToDet[i]=0;
00434 }
00435  
00436 void TkLayerMap::createTIB(std::vector<uint32_t>& TkDetIdList,int layerEnumNb){
00437   
00438   std::vector<uint32_t> LayerDetIdList;
00439   SiStripSubStructure siStripSubStructure;
00440   
00441   //extract  vector of module in the layer
00442   siStripSubStructure.getTIBDetectors(TkDetIdList,LayerDetIdList,layerEnumNb,0,0,0);
00443 
00444   LogTrace("TkLayerMap") << "[TkLayerMap::createTIB12] layer " << layerEnumNb  << " number of dets " << LayerDetIdList.size() << " lowY " << lowY << " high " << highY << " Nstring " << Nstring_ext;
00445 
00446   for(size_t j=0;j<LayerDetIdList.size();++j){
00447     xybin=getXY_TIB(LayerDetIdList[j],layerEnumNb);
00448     binToDet[(xybin.ix-1)+nchX*(xybin.iy-1)]=LayerDetIdList[j];
00449     LogTrace("TkLayerMap") << "[TkLayerMap::createTIB] " << LayerDetIdList[j]<< " " << xybin.ix << " " << xybin.iy  << " " << xybin.x << " " << xybin.y ;
00450   }
00451 }
00452 
00453 void TkLayerMap::createTOB(std::vector<uint32_t>& TkDetIdList,int layerEnumNb){
00454   
00455   std::vector<uint32_t> LayerDetIdList;
00456   SiStripSubStructure siStripSubStructure;
00457   
00458   //extract  vector of module in the layer
00459   siStripSubStructure.getTOBDetectors(TkDetIdList,LayerDetIdList,layerEnumNb-10,0,0);
00460 
00461   LogTrace("TkLayerMap") << "[TkLayerMap::createTOB] layer " << layerEnumNb-10  << " number of dets " << LayerDetIdList.size() << " lowY " << lowY << " high " << highY << " Nstring " << Nstring_ext;
00462 
00463   for(size_t j=0;j<LayerDetIdList.size();++j){
00464     xybin=getXY_TOB(LayerDetIdList[j],layerEnumNb);
00465     binToDet[(xybin.ix-1)+nchX*(xybin.iy-1)]=LayerDetIdList[j];
00466     LogTrace("TkLayerMap") << "[TkLayerMap::createTOB] " << LayerDetIdList[j]<< " " << xybin.ix << " " << xybin.iy  << " " << xybin.x << " " << xybin.y ;
00467   }
00468 }
00469 
00470 void TkLayerMap::createTID(std::vector<uint32_t>& TkDetIdList,int layerEnumNb){
00471   
00472   std::vector<uint32_t> LayerDetIdList;
00473   SiStripSubStructure siStripSubStructure;
00474   
00475   //extract  vector of module in the layer
00476   siStripSubStructure.getTIDDetectors(TkDetIdList,LayerDetIdList,(layerEnumNb-TkLayerMap::TIDM_D1)/3+1,(layerEnumNb-TkLayerMap::TIDM_D1)%3+1,0,0);
00477 
00478   LogTrace("TkLayerMap") << "[TkLayerMap::createTID] layer side " << (layerEnumNb-TkLayerMap::TIDM_D1)/3+1 << " nb " << (layerEnumNb-TkLayerMap::TIDM_D1)%3+1  << " number of dets " << LayerDetIdList.size() << " lowY " << lowY << " high " << highY << " Nstring " << Nstring_ext;
00479   
00480   for(size_t j=0;j<LayerDetIdList.size();++j){
00481     xybin=getXY_TID(LayerDetIdList[j],layerEnumNb);
00482     binToDet[(xybin.ix-1)+nchX*(xybin.iy-1)]=LayerDetIdList[j];
00483     LogTrace("TkLayerMap") << "[TkLayerMap::createTID] " << LayerDetIdList[j]<< " " << xybin.ix << " " << xybin.iy  << " " << xybin.x << " " << xybin.y ;
00484   }
00485 }
00486 
00487 void TkLayerMap::createTEC(std::vector<uint32_t>& TkDetIdList,int layerEnumNb){
00488   
00489   std::vector<uint32_t> LayerDetIdList;
00490   SiStripSubStructure siStripSubStructure;
00491   
00492   //extract  vector of module in the layer
00493   siStripSubStructure.getTECDetectors(TkDetIdList,LayerDetIdList,(layerEnumNb-TkLayerMap::TECM_W1)/9+1,(layerEnumNb-TkLayerMap::TECM_W1)%9+1,0,0);
00494   
00495   LogTrace("TkLayerMap") << "[TkLayerMap::createTEC] layer side " << (layerEnumNb-TkLayerMap::TECM_W1)/9+1 << " " << (layerEnumNb-TkLayerMap::TECM_W1)%9+1  << " number of dets " << LayerDetIdList.size() << " lowY " << lowY << " high " << highY << " Nstring " << Nstring_ext;
00496 
00497   for(size_t j=0;j<LayerDetIdList.size();++j){
00498     xybin=getXY_TEC(LayerDetIdList[j],layerEnumNb);
00499     binToDet[(xybin.ix-1)+nchX*(xybin.iy-1)]=LayerDetIdList[j];
00500     LogTrace("TkLayerMap") << "[TkLayerMap::createTEC] " << LayerDetIdList[j]<< " " << xybin.ix << " " << xybin.iy  << " " << xybin.x << " " << xybin.y ;
00501     
00502   }
00503 }
00504 
00505 
00506 const TkLayerMap::XYbin TkLayerMap::getXY(uint32_t& detid, int layerEnumNb){
00507   LogTrace("TkLayerMap") << "[TkLayerMap::getXY] " << detid << " layer " << layerEnumNb; 
00508 
00509   if(!layerEnumNb)
00510     layerEnumNb=layerSearch(detid);
00511 
00512   if(layerEnumNb!=layerEnumNb_)
00513     throw cms::Exception("CorruptedData")
00514       << "[TkLayerMap::getXY] Fill of DetId " << detid << " layerEnumNb " << layerEnumNb << " are requested to wrong TkLayerMap " << layerEnumNb_ << " \nPlease check the TkDetMap code"; 
00515  
00516 
00517   if(layerEnumNb>=TkLayerMap::TIB_L1 && layerEnumNb<=TkLayerMap::TIB_L4)  
00518     return getXY_TIB(detid,layerEnumNb);
00519   else if(layerEnumNb>=TkLayerMap::TIDM_D1 && layerEnumNb<=TkLayerMap::TIDP_D3)  
00520     return getXY_TID(detid,layerEnumNb); 
00521   else if(layerEnumNb>=TkLayerMap::TOB_L1 && layerEnumNb<=TkLayerMap::TOB_L6)  
00522     return getXY_TOB(detid,layerEnumNb); 
00523   else 
00524     return getXY_TEC(detid,layerEnumNb); 
00525 }
00526 
00527 TkLayerMap::XYbin TkLayerMap::getXY_TIB(uint32_t& detid, int layerEnumNb){  
00528   if(!layerEnumNb)
00529     layerEnumNb=layerSearch(detid);
00530 
00531   TIBDetId D(detid);
00532   if(D.layerNumber()%2){
00533     Offset=D.isInternalString()?2:1;
00534   }else{
00535     Offset=D.isInternalString()?1:2;
00536   }
00537   xybin.ix=2*(D.isZMinusSide()?-1*D.moduleNumber()+3:D.moduleNumber()+2)+Offset;
00538   xybin.iy=D.isInternalString()?D.stringNumber()+SingleExtString[D.stringNumber()]:D.stringNumber();
00539   if(D.layerNumber()<3 && !D.isStereo())
00540     xybin.iy+=Nstring_ext+2;
00541   
00542   xybin.x=lowX+xybin.ix-0.5;
00543   xybin.y=lowY+xybin.iy-0.5;
00544   return xybin;
00545 }
00546 
00547 TkLayerMap::XYbin TkLayerMap::getXY_TOB(uint32_t& detid, int layerEnumNb){  
00548   if(!layerEnumNb)
00549     layerEnumNb=layerSearch(detid);
00550 
00551   TOBDetId D(detid);
00552   xybin.ix=D.isZMinusSide()?-1*D.moduleNumber()+7:D.moduleNumber()+6;
00553   xybin.iy=D.rodNumber();  
00554   if(D.layerNumber()<3 && !D.isStereo())
00555     xybin.iy+=Nrod+2;
00556 
00557   xybin.x=lowX+xybin.ix-0.5;
00558   xybin.y=lowY+xybin.iy-0.5;
00559   return xybin;
00560 }
00561 
00562 TkLayerMap::XYbin TkLayerMap::getXY_TID(uint32_t& detid, int layerEnumNb){  
00563   if(!layerEnumNb)
00564     layerEnumNb=layerSearch(detid);
00565 
00566   TIDDetId D(detid);
00567   xybin.ix=D.isZMinusSide()?-3*D.ring()+10:3*D.ring()-2;
00568   if(D.isStereo())
00569     xybin.ix+=(D.isZMinusSide()?-1:1);
00570   xybin.iy= int(2. * D.moduleNumber() - (D.isBackRing()?0.:1.));
00571 
00572   xybin.x=lowX+xybin.ix-0.5;
00573   xybin.y=lowY+xybin.iy-0.5;
00574   return xybin;
00575 }
00576 
00577 TkLayerMap::XYbin TkLayerMap::getXY_TEC(uint32_t& detid, int layerEnumNb){  
00578   if(!layerEnumNb)
00579     layerEnumNb=layerSearch(detid);
00580 
00581   TECDetId D(detid);
00582   xybin.ix=D.isZMinusSide()?BinForRing[7]-BinForRing[D.ring()]+1:BinForRing[D.ring()]; //after the introduction of plus and minus histos, the BinForRing should have been changed. on the contrary we hack this part of the code 
00583   if(D.isStereo())
00584     xybin.ix+=(D.isZMinusSide()?-1:1);
00585 
00586   if(D.isZMinusSide()){
00587     xybin.iy= (D.petalNumber()-1)*(ModulesInRingFront[D.ring()]+ModulesInRingBack[D.ring()]) + ModulesInRingFront[D.ring()] - D.moduleNumber() +1;
00588     if(D.isBackPetal())
00589       xybin.iy+=ModulesInRingBack[D.ring()];
00590   }else{ 
00591     xybin.iy= (D.petalNumber()-1)*(ModulesInRingFront[D.ring()]+ModulesInRingBack[D.ring()])+D.moduleNumber();
00592     if(D.isBackPetal())
00593       xybin.iy+=ModulesInRingFront[D.ring()];
00594   }
00595 
00596   xybin.x=lowX+xybin.ix-0.5;
00597   xybin.y=lowY+xybin.iy-0.5;
00598   return xybin;
00599 }
00600 
00601 //--------------------------------------
00602 
00603 TkDetMap::TkDetMap(const edm::ParameterSet& p,const edm::ActivityRegistry& a)
00604   :cached_detid(0),
00605    cached_layer(TkLayerMap::INVALID){
00606   doMe();
00607 }
00608 
00609 TkDetMap::TkDetMap()
00610 :cached_detid(0),
00611  cached_layer(TkLayerMap::INVALID){
00612   doMe();
00613 }
00614 
00615 void TkDetMap::doMe(){
00616   LogTrace("TkDetMap") <<"TkDetMap::constructor ";
00617 
00618   TkMap.resize(35);
00619   //Create TkLayerMap for each layer declared in the TkLayerEnum
00620   for(int layer=1;layer<35;++layer){
00621     TkMap[layer]=new TkLayerMap(layer);
00622   }
00623 }
00624 
00625 TkDetMap::~TkDetMap(){
00626   detmapType::iterator iter=TkMap.begin();
00627   detmapType::iterator iterE=TkMap.end();
00628  
00629   for(;iter!=iterE;++iter)
00630     delete (*iter);  
00631 }
00632 
00633 const TkLayerMap::XYbin& TkDetMap::getXY(uint32_t& detid){
00634 
00635   LogTrace("TkDetMap") <<"[getXY] detid "<< detid << " cache " << cached_detid << " layer " << cached_layer << " XY " << cached_XYbin.ix << " " << cached_XYbin.iy  << " " << cached_XYbin.x << " " << cached_XYbin.y ;    
00636   if(detid==cached_detid)
00637     return cached_XYbin;
00638 
00639   /*FIXME*/
00640   //if (layer!=INVALID)
00641   FindLayer(detid);
00642   LogTrace("TkDetMap") <<"[getXY] detid "<< detid << " cache " << cached_detid << " layer " << cached_layer << " XY " << cached_XYbin.ix << " " << cached_XYbin.iy  << " " << cached_XYbin.x << " " << cached_XYbin.y ;    
00643   return cached_XYbin;
00644 }
00645 
00646 int16_t TkDetMap::FindLayer(uint32_t& detid){ 
00647 
00648   if(detid==cached_detid)
00649     return cached_layer;
00650 
00651   cached_detid=detid;
00652 
00653   int16_t layer=TkLayerMap::layerSearch(detid);
00654   LogTrace("TkDetMap") <<"[FindLayer] detid "<< detid << " layer " << layer;
00655   if(layer!=cached_layer){
00656     cached_layer=layer;  
00657   }
00658   cached_XYbin=TkMap[cached_layer]->getXY(detid,layer);
00659   LogTrace("TkDetMap") <<"[FindLayer] detid "<< detid << " cached_XYbin " << cached_XYbin.ix << " "<< cached_XYbin.iy;
00660 
00661   return cached_layer;
00662 }
00663 
00664 
00665 
00666 void TkDetMap::getComponents(int& layer,
00667                              int& nchX,double& lowX,double& highX,
00668                              int& nchY,double& lowY,double& highY){
00669   nchX=TkMap[layer]->get_nchX();
00670   lowX=TkMap[layer]->get_lowX();
00671   highX=TkMap[layer]->get_highX();
00672   nchY=TkMap[layer]->get_nchY();
00673   lowY=TkMap[layer]->get_lowY();
00674   highY=TkMap[layer]->get_highY();
00675 }
00676 
00677 void TkDetMap::getDetsForLayer(int layer,std::vector<uint32_t>& output){
00678   output.clear();
00679   size_t size_=TkMap[layer]->get_nchX()*TkMap[layer]->get_nchY();
00680   output.resize(size_);
00681   memcpy((void*)&output[0],(void*)TkMap[layer]->getBinToDet(),size_*sizeof(uint32_t));
00682 }
00683 
00684 std::string TkDetMap::getLayerName(int& in){
00685   switch (in)
00686     {
00687     case TkLayerMap::TIB_L1:
00688       return "TIB_L1";
00689     case TkLayerMap::TIB_L2:
00690       return "TIB_L2";
00691     case TkLayerMap::TIB_L3:
00692       return "TIB_L3";
00693     case TkLayerMap::TIB_L4:         
00694       return "TIB_L4";         
00695     case TkLayerMap::TIDP_D1:
00696       return "TIDP_D1";
00697     case TkLayerMap::TIDP_D2:
00698       return "TIDP_D2";
00699     case TkLayerMap::TIDP_D3:
00700       return "TIDP_D3";
00701     case TkLayerMap::TIDM_D1:
00702       return "TIDM_D1";
00703     case TkLayerMap::TIDM_D2:
00704       return "TIDM_D2";
00705     case TkLayerMap::TIDM_D3:
00706       return "TIDM_D3";
00707     case TkLayerMap::TOB_L1:
00708       return "TOB_L1";
00709     case TkLayerMap::TOB_L2:
00710       return "TOB_L2";
00711     case TkLayerMap::TOB_L3:
00712       return "TOB_L3";
00713     case TkLayerMap::TOB_L4:
00714       return "TOB_L4";
00715     case TkLayerMap::TOB_L5:
00716       return "TOB_L5";
00717     case TkLayerMap::TOB_L6:
00718       return "TOB_L6";
00719     case TkLayerMap::TECP_W1:
00720       return "TECP_W1";
00721     case TkLayerMap::TECP_W2:
00722       return "TECP_W2";
00723     case TkLayerMap::TECP_W3:
00724       return "TECP_W3";
00725     case TkLayerMap::TECP_W4:
00726       return "TECP_W4";
00727     case TkLayerMap::TECP_W5: 
00728       return "TECP_W5";
00729     case TkLayerMap::TECP_W6:
00730       return "TECP_W6";
00731     case TkLayerMap::TECP_W7:
00732       return "TECP_W7";
00733     case TkLayerMap::TECP_W8:
00734       return "TECP_W8";
00735     case TkLayerMap::TECP_W9:
00736       return "TECP_W9";
00737     case TkLayerMap::TECM_W1:
00738       return "TECM_W1";
00739     case TkLayerMap::TECM_W2:
00740       return "TECM_W2";
00741     case TkLayerMap::TECM_W3:
00742       return "TECM_W3";
00743     case TkLayerMap::TECM_W4:
00744       return "TECM_W4";
00745     case TkLayerMap::TECM_W5: 
00746       return "TECM_W5";
00747     case TkLayerMap::TECM_W6:
00748       return "TECM_W6";
00749     case TkLayerMap::TECM_W7:
00750       return "TECM_W7";
00751     case TkLayerMap::TECM_W8:
00752       return "TECM_W8";
00753     case TkLayerMap::TECM_W9:
00754       return "TECM_W9";
00755     }
00756   return "Invalid";
00757 }
00758 
00759 int TkDetMap::getLayerNum(std::string& in){
00760   if(in.compare( "TIB_L1")==0)
00761     return TkLayerMap::TIB_L1;
00762   if(in.compare( "TIB_L2")==0)
00763     return TkLayerMap::TIB_L2;
00764   if(in.compare( "TIB_L3")==0)
00765     return TkLayerMap::TIB_L3;
00766   if(in.compare( "TIB_L4")==0)         
00767     return TkLayerMap::TIB_L4;         
00768   if(in.compare( "TIDP_D1")==0)
00769     return TkLayerMap::TIDP_D1;
00770   if(in.compare( "TIDP_D2")==0)
00771     return TkLayerMap::TIDP_D2;
00772   if(in.compare( "TIDP_D3")==0)
00773     return TkLayerMap::TIDP_D3;
00774   if(in.compare( "TIDM_D1")==0)
00775     return TkLayerMap::TIDM_D1;
00776   if(in.compare( "TIDM_D2")==0)
00777     return TkLayerMap::TIDM_D2;
00778   if(in.compare( "TIDM_D3")==0)
00779     return TkLayerMap::TIDM_D3;
00780   if(in.compare( "TOB_L1")==0)
00781     return TkLayerMap::TOB_L1;
00782   if(in.compare( "TOB_L2")==0)
00783     return TkLayerMap::TOB_L2;
00784   if(in.compare( "TOB_L3")==0)
00785     return TkLayerMap::TOB_L3;
00786   if(in.compare( "TOB_L4")==0)
00787     return TkLayerMap::TOB_L4;
00788   if(in.compare( "TOB_L5")==0)
00789     return TkLayerMap::TOB_L5;
00790   if(in.compare( "TOB_L6")==0)
00791     return TkLayerMap::TOB_L6;
00792   if(in.compare( "TECP_W1")==0)
00793     return TkLayerMap::TECP_W1;
00794   if(in.compare( "TECP_W2")==0)
00795     return TkLayerMap::TECP_W2;
00796   if(in.compare( "TECP_W3")==0)
00797     return TkLayerMap::TECP_W3;
00798   if(in.compare( "TECP_W4")==0)
00799     return TkLayerMap::TECP_W4;
00800   if(in.compare( "TECP_W5")==0)
00801     return TkLayerMap::TECP_W5; 
00802   if(in.compare( "TECP_W6")==0)
00803     return TkLayerMap::TECP_W6;
00804   if(in.compare( "TECP_W7")==0)
00805     return TkLayerMap::TECP_W7;
00806   if(in.compare( "TECP_W8")==0)
00807     return TkLayerMap::TECP_W8;
00808   if(in.compare( "TECP_W9")==0)
00809     return TkLayerMap::TECP_W9;
00810   if(in.compare( "TECM_W1")==0)
00811     return TkLayerMap::TECM_W1;
00812   if(in.compare( "TECM_W2")==0)
00813     return TkLayerMap::TECM_W2;
00814   if(in.compare( "TECM_W3")==0)
00815     return TkLayerMap::TECM_W3;
00816   if(in.compare( "TECM_W4")==0)
00817     return TkLayerMap::TECM_W4;
00818   if(in.compare( "TECM_W5")==0)
00819     return TkLayerMap::TECM_W5; 
00820   if(in.compare( "TECM_W6")==0)
00821     return TkLayerMap::TECM_W6;
00822   if(in.compare( "TECM_W7")==0)
00823     return TkLayerMap::TECM_W7;
00824   if(in.compare( "TECM_W8")==0)
00825     return TkLayerMap::TECM_W8;
00826   if(in.compare( "TECM_W9")==0)
00827     return TkLayerMap::TECM_W9;
00828   return 0;
00829 }
00830 
00831 void TkDetMap::getSubDetLayerSide(int& in,SiStripDetId::SubDetector& subDet,uint32_t& layer,uint32_t& side){
00832   switch (in)
00833     {
00834     case TkLayerMap::TIB_L1:
00835       subDet = SiStripDetId::TIB;
00836       layer = 1;
00837       break;
00838     case TkLayerMap::TIB_L2:
00839       subDet = SiStripDetId::TIB;
00840       layer = 2;
00841       break;
00842     case TkLayerMap::TIB_L3:
00843       subDet = SiStripDetId::TIB;
00844       layer = 3;
00845       break;
00846     case TkLayerMap::TIB_L4:
00847       subDet = SiStripDetId::TIB;
00848       layer = 4;
00849       break;
00850     case TkLayerMap::TIDP_D1:
00851       subDet = SiStripDetId::TID;
00852       layer = 1;
00853       side=2;
00854       break;
00855     case TkLayerMap::TIDP_D2:
00856       subDet = SiStripDetId::TID;
00857       layer = 2;
00858       side=2;
00859       break;
00860     case TkLayerMap::TIDP_D3:
00861       subDet = SiStripDetId::TID;
00862       layer = 3;
00863       side=2;
00864       break;
00865     case TkLayerMap::TIDM_D1:
00866       subDet = SiStripDetId::TID;
00867       layer = 1;
00868       side=1;
00869       break;
00870     case TkLayerMap::TIDM_D2:
00871       subDet = SiStripDetId::TID;
00872       layer = 2;
00873       side=1;
00874       break;
00875     case TkLayerMap::TIDM_D3:
00876       subDet = SiStripDetId::TID;
00877       layer = 3;
00878       side=1;
00879       break;
00880     case TkLayerMap::TOB_L1:
00881       subDet = SiStripDetId::TOB;
00882       layer = 1;
00883       break;
00884     case TkLayerMap::TOB_L2:
00885       subDet = SiStripDetId::TOB;
00886       layer = 2;
00887       break;
00888     case TkLayerMap::TOB_L3:
00889       subDet = SiStripDetId::TOB;
00890       layer = 3;
00891       break;
00892     case TkLayerMap::TOB_L4:
00893       subDet = SiStripDetId::TOB;
00894       layer = 4;
00895       break;
00896     case TkLayerMap::TOB_L5:
00897       subDet = SiStripDetId::TOB;
00898       layer = 5;
00899       break;
00900     case TkLayerMap::TOB_L6:
00901       subDet = SiStripDetId::TOB;
00902       layer = 6;
00903       break;
00904     case TkLayerMap::TECP_W1:
00905       subDet = SiStripDetId::TEC;
00906       layer = 1;
00907       side=2;
00908       break;
00909     case TkLayerMap::TECP_W2:
00910       subDet = SiStripDetId::TEC;
00911       layer = 2;
00912       side=2;
00913       break;
00914     case TkLayerMap::TECP_W3:
00915       subDet = SiStripDetId::TEC;
00916       layer = 3;
00917       side=2;
00918       break;
00919     case TkLayerMap::TECP_W4:
00920       subDet = SiStripDetId::TEC;
00921       layer = 4;
00922       side=2;
00923       break;
00924     case TkLayerMap::TECP_W5: 
00925       subDet = SiStripDetId::TEC;
00926       layer = 5;
00927       side=2;
00928       break;
00929     case TkLayerMap::TECP_W6:
00930       subDet = SiStripDetId::TEC;
00931       layer = 6;
00932       side=2;
00933       break;
00934     case TkLayerMap::TECP_W7:
00935       subDet = SiStripDetId::TEC;
00936       layer = 7;
00937       side=2;
00938       break;
00939     case TkLayerMap::TECP_W8:
00940       subDet = SiStripDetId::TEC;
00941       layer = 8;
00942       side=2;
00943       break;
00944     case TkLayerMap::TECP_W9:
00945       subDet = SiStripDetId::TEC;
00946       layer = 9;
00947       side=2;
00948       break;
00949     case TkLayerMap::TECM_W1:
00950       subDet = SiStripDetId::TEC;
00951       layer = 1;
00952       side=1;
00953       break;
00954     case TkLayerMap::TECM_W2:
00955       subDet = SiStripDetId::TEC;
00956       layer = 2;
00957       side=1;
00958       break;
00959     case TkLayerMap::TECM_W3:
00960       subDet = SiStripDetId::TEC;
00961       layer = 3;
00962       side=1;
00963       break;
00964     case TkLayerMap::TECM_W4:
00965       subDet = SiStripDetId::TEC;
00966       layer = 4;
00967       side=1;
00968       break;
00969     case TkLayerMap::TECM_W5: 
00970       subDet = SiStripDetId::TEC;
00971       layer = 5;
00972       side=1;
00973       break;
00974     case TkLayerMap::TECM_W6:
00975       subDet = SiStripDetId::TEC;
00976       layer = 6;
00977       side=1;
00978       break;
00979     case TkLayerMap::TECM_W7:
00980       subDet = SiStripDetId::TEC;
00981       layer = 7;
00982       side=1;
00983       break;
00984     case TkLayerMap::TECM_W8:
00985       subDet = SiStripDetId::TEC;
00986       layer = 8;
00987       side=1;
00988       break;
00989     case TkLayerMap::TECM_W9:
00990       subDet = SiStripDetId::TEC;
00991       layer = 9;
00992       side=1;
00993       break;
00994     }
00995 }
00996 
00997 //  LocalWords:  TkLayerMap