CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DataFormats/MuonDetId/src/RPCDetId.cc

Go to the documentation of this file.
00001 
00009 #include <DataFormats/MuonDetId/interface/RPCDetId.h>
00010 #include <DataFormats/MuonDetId/interface/MuonSubdetId.h> 
00011 
00012 RPCDetId::RPCDetId():DetId(DetId::Muon, MuonSubdetId::RPC),trind(0){}
00013 
00014 
00015 RPCDetId::RPCDetId(uint32_t id):DetId(id),trind(0) {
00016   //  std::cout<<" constructor of the RPCDetId" <<std::endl;
00017   if (det()!=DetId::Muon || subdetId()!=MuonSubdetId::RPC) {
00018     throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
00019                                          << " det: " << det()
00020                                          << " subdet: " << subdetId()
00021                                          << " is not a valid RPC id";  
00022   }
00023 }
00024 RPCDetId::RPCDetId(DetId id):DetId(id),trind(0) {
00025   //  std::cout<<" constructor of the RPCDetId" <<std::endl;
00026   if (det()!=DetId::Muon || subdetId()!=MuonSubdetId::RPC) {
00027     throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
00028                                          << " det: " << det()
00029                                          << " subdet: " << subdetId()
00030                                          << " is not a valid RPC id";  
00031   }
00032 }
00033 
00034 
00035 
00036 RPCDetId::RPCDetId(int region, int ring, int station, int sector, int layer,int subsector, int roll):         
00037   DetId(DetId::Muon, MuonSubdetId::RPC),trind(0)
00038 {
00039   this->init(region,ring,station,sector,layer,subsector,roll);
00040 }
00041 
00042 
00043 void 
00044 RPCDetId::buildfromDB(int region, int ring, int trlayer, int sector, 
00045                       const std::string& subs,
00046                       const std::string& roll,
00047                       const std::string& dbname){
00048 
00049   bool barrel = (region==0);
00050   //STATION
00051   int station = -1;
00052   if (barrel) {
00053     if (trlayer==1 || trlayer==2) station = 1;
00054     else if (trlayer==3 || trlayer==4) station = 2;
00055     else station = trlayer-2;
00056   } else {   
00057    station = abs(ring); 
00058   }
00059 
00060 
00061   //LAYER
00062   //int layer = 1;
00063   //if (barrel && station==1) layer = trlayer;
00064   //if (barrel && station==2) layer = trlayer-2; 
00065 
00066   //SUBSECTOR
00067   int subsector = 1;
00068 
00069   if (barrel) {
00070     if (station==3 && subs=="+") subsector = 2;
00071     if (station==4 && 
00072          (   sector==1 || sector==2 || sector==3 
00073                        || sector==5 || sector==6   
00074           || sector==7 || sector==8 
00075           || sector==10             || sector==12)
00076           && (subs=="+")) {
00077          subsector = 2;
00078     }
00079 
00080     if (station==4 && sector==4) {
00081       if (subs=="--") subsector=1;
00082       if (subs=="-")  subsector=2;
00083       if (subs=="+")  subsector=3;
00084       if (subs=="++") subsector=4;
00085     } 
00086   }
00087 
00088    // ROLL
00089   int iroll=0;
00090 
00091   if      (roll=="Backward" || roll=="A") iroll = 1;
00092   else if (roll=="Central" || roll=="B") iroll = 2;
00093   else if (roll=="Forward" || roll=="C") iroll = 3;
00094   else if (roll=="D") iroll = 4;
00095   else {
00096     std::cout << "** RPC: DBSpecToDetUnit, how to assigne roll to: "
00097          <<roll<<" ???" << std::endl;
00098   }
00099 
00100   int trIndex = 0;
00101   if(barrel){   
00102     //cout <<" BARREL: " << endl; 
00103     int eta_id = 6+ring;
00104     int plane_id = station;
00105     if(trlayer==2) plane_id=5;
00106     if(trlayer==4) plane_id=6;
00107     int sector_id = sector*3;
00108     int copy_id = subsector;
00109     int roll_id = iroll;
00110     trIndex=(eta_id*10000+plane_id*1000+sector_id*10+copy_id)*10+roll_id;
00111   } 
00112   else { 
00113     //    cout << "ENDCAP : " << endl;
00114     int eta_id = trlayer;
00115     if(ring>0) eta_id = 12-trlayer;
00116     int plane_id = abs(ring);
00117     int sector_id = sector;
00118 
00119     if (region <0){
00120       if (sector_id < 20 ){
00121         sector_id = 19+ 1-sector_id;
00122       }else{
00123         sector_id = 36+20-sector_id;
00124       }
00125     }
00126     sector_id-=1;
00127 
00128     //
00129     int copy_id = 1;
00130     int roll_id = iroll;
00131     trIndex=(eta_id*10000+plane_id*1000+sector_id*10+copy_id)*10+ roll_id;
00132   }
00133   this->buildfromTrIndex(trIndex);
00134 }
00135 
00136 void
00137 RPCDetId::buildfromTrIndex(int trIndex)
00138 {
00139   trind = trIndex;
00140   int eta_id = trIndex/100000;
00141   int region=0;
00142   int ring =0; 
00143   if (eta_id <=3 ){
00144     region = -1;
00145     ring = eta_id;
00146   }
00147   else if (eta_id >=9 ) {
00148     region = 1;
00149     ring = 12-eta_id;
00150   }
00151   else{
00152     region = 0;
00153     ring = eta_id - 6;
00154   }
00155   trIndex = trIndex%100000;
00156   int plane_id = trIndex/10000;
00157   int station=0;
00158   int layer=0;
00159   if (plane_id <=4){
00160     station = plane_id;
00161     layer = 1;
00162   }
00163   else{
00164     station = plane_id -4;
00165     layer = 2;
00166   }
00167   trIndex = trIndex%10000;
00168   int sector_id = trIndex/100;
00169   if (region!=0) {
00170         if ( !(ring == 1 && station > 1 && region==1)) {     
00171          sector_id+=1;
00172          if (sector_id==37)sector_id=1;
00173      }
00174   }
00175   if (region==-1){
00176     if (sector_id < 20 ){
00177       sector_id = 19+ 1-sector_id;
00178     }else{
00179       sector_id = 36+20-sector_id;
00180     }
00181   }
00182   trIndex = trIndex%100;
00183   int copy_id = trIndex/10;
00184   int sector=(sector_id-1)/3+1;
00185   if (region!=0) {
00186     sector=(sector+1)/2;
00187   }
00188   int subsector=0;
00189   if ( region == 0 ) {
00190     subsector = copy_id;
00191   }
00192   else {
00193     if ( ring == 1 && station > 1) {
00194       // 20 degree chambers
00195        subsector = ((sector_id+1)/2-1)%3+1;
00196     }else {
00197       // 10 degree chambers
00198       subsector = (sector_id-1)%6+1;
00199     }
00200 //     std::cout <<" RE"<<station*region<<"/"<<ring<<" sector_id "<<sector_id
00201 //            << " sector "<<sector <<" sub "<<subsector<<std::endl;
00202   }
00203 
00204 
00205   int roll=trIndex%10;
00206   this->init(region,ring,station,sector,layer,subsector,roll);
00207 }
00208 
00209 
00210 
00211 void
00212 RPCDetId::init(int region,int ring,int station,int sector,
00213                int layer,int subsector,int roll)
00214 {
00215   int minRing=0;
00216   int maxRing=RPCDetId::maxRingForwardId;
00217   if (!region) 
00218     {
00219       minRing=RPCDetId::minRingBarrelId;
00220       maxRing=RPCDetId::maxRingBarrelId;
00221     } 
00222   
00223   if ( region     < minRegionId    || region    > maxRegionId ||
00224        ring       < minRing        || ring      > maxRing ||
00225        station    < minStationId   || station   > maxStationId ||
00226        sector     < minSectorId    || sector    > maxSectorId ||
00227        layer      < minLayerId     || layer     > maxLayerId ||
00228        subsector  < minSubSectorId || subsector > maxSubSectorId ||
00229        roll       < minRollId      || roll      > maxRollId) {
00230     throw cms::Exception("InvalidDetId") << "RPCDetId ctor:" 
00231                                          << " Invalid parameters: " 
00232                                          << " region "<<region
00233                                          << " ring "<<ring
00234                                          << " station "<<station
00235                                          << " sector "<<sector
00236                                          << " layer "<<layer
00237                                          << " subsector "<<subsector
00238                                          << " roll "<<roll
00239                                          << std::endl;
00240   }
00241               
00242   
00243   int regionInBits=region-minRegionId;
00244   int ringInBits =0;
00245   if(region != 0) ringInBits = ring - minRingForwardId;
00246   if(!region) ringInBits = ring + RingBarrelOffSet - minRingBarrelId;
00247   
00248   int stationInBits=station-minStationId;
00249   int sectorInBits=sector-(minSectorId+1);
00250   int layerInBits=layer-minLayerId;
00251   int subSectorInBits=subsector-(minSubSectorId+1);
00252   int rollInBits=roll;
00253   
00254   id_ |= ( regionInBits    & RegionMask_)    << RegionStartBit_    | 
00255          ( ringInBits      & RingMask_)      << RingStartBit_      |
00256          ( stationInBits   & StationMask_)   << StationStartBit_   |
00257          ( sectorInBits    & SectorMask_)    << SectorStartBit_    |
00258          ( layerInBits     & LayerMask_)     << LayerStartBit_     |
00259          ( subSectorInBits & SubSectorMask_) << SubSectorStartBit_ |
00260          ( rollInBits      & RollMask_)      << RollStartBit_        ;
00261    
00262 }
00263 
00264 
00265 
00266 std::ostream& operator<<( std::ostream& os, const RPCDetId& id ){
00267 
00268 
00269   os <<  " Re "<<id.region()
00270      << " Ri "<<id.ring()
00271      << " St "<<id.station()
00272      << " Se "<<id.sector()
00273      << " La "<<id.layer()
00274      << " Su "<<id.subsector()
00275      << " Ro "<<id.roll()
00276      << " Tr "<<id.trIndex()
00277      <<" ";
00278 
00279   return os;
00280 }
00281 
00282