CMS 3D CMS Logo

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 
00051   //STATION
00052   int station = -1;
00053   if (barrel) {
00054     if (trlayer==1 || trlayer==2) station = 1;
00055     else if (trlayer==3 || trlayer==4) station = 2;
00056     else station = trlayer-2;
00057   } else {   
00058    station = abs(ring); 
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     // patch to fix phi rotation
00119     sector_id--;
00120     if (sector_id==0){
00121       sector_id=36;
00122       if (plane_id > 1 && trlayer == 1 )
00123         sector_id=18;
00124     }
00125     //
00126     int copy_id = 1;
00127     int roll_id = iroll;
00128     trIndex=(eta_id*10000+plane_id*1000+sector_id*10+copy_id)*10+ roll_id;
00129   }
00130   this->buildfromTrIndex(trIndex);
00131 
00132 }
00133 
00134 void
00135 RPCDetId::buildfromTrIndex(int trIndex)
00136 {
00137   trind = trIndex;
00138   int eta_id = trIndex/100000;
00139   int region=0;
00140   int ring =0; 
00141   if (eta_id <=3 ){
00142     region = -1;
00143     ring = eta_id;
00144   }
00145   else if (eta_id >=9 ) {
00146     region = 1;
00147     ring = 12-eta_id;
00148   }
00149   else{
00150     region = 0;
00151     ring = eta_id - 6;
00152   }
00153   trIndex = trIndex%100000;
00154   int plane_id = trIndex/10000;
00155   int station=0;
00156   int layer=0;
00157   if (plane_id <=4){
00158     station = plane_id;
00159     layer = 1;
00160   }
00161   else{
00162     station = plane_id -4;
00163     layer = 2;
00164   }
00165   trIndex = trIndex%10000;
00166   int sector_id = trIndex/100;
00167   trIndex = trIndex%100;
00168   int copy_id = trIndex/10;
00169   int sector=(sector_id-1)/3+1;
00170   if (region!=0) {
00171     sector=(sector+1)/2;
00172   }
00173   int subsector=0;
00174   if ( region == 0 ) {
00175     subsector = copy_id;
00176   }
00177   else {
00178     if ( ring == 1 && station > 1) {
00179       // 20 degree chambers
00180       subsector = (sector_id/2-1)%3+1;
00181     }else {
00182       // 10 degree chambers
00183       subsector = (sector_id-1)%6+1;
00184     }
00185     // std::cout << "RE"<<station<<"/"<<ring<<" sector_id "<<sector_id
00186     //        << " sector "<<sector <<" sub "<<subsector<<std::endl;
00187   }
00188 
00189 
00190   int roll=trIndex%10;
00191   this->init(region,ring,station,sector,layer,subsector,roll);
00192 }
00193 
00194 
00195 
00196 void
00197 RPCDetId::init(int region,int ring,int station,int sector,
00198                int layer,int subsector,int roll)
00199 {
00200   int minRing=0;
00201   int maxRing=RPCDetId::maxRingForwardId;
00202   if (!region) 
00203     {
00204       minRing=RPCDetId::minRingBarrelId;
00205       maxRing=RPCDetId::maxRingBarrelId;
00206     } 
00207   
00208   if ( region     < minRegionId    || region    > maxRegionId ||
00209        ring       < minRing        || ring      > maxRing ||
00210        station    < minStationId   || station   > maxStationId ||
00211        sector     < minSectorId    || sector    > maxSectorId ||
00212        layer      < minLayerId     || layer     > maxLayerId ||
00213        subsector  < minSubSectorId || subsector > maxSubSectorId ||
00214        roll       < minRollId      || roll      > maxRollId) {
00215     throw cms::Exception("InvalidDetId") << "RPCDetId ctor:" 
00216                                          << " Invalid parameters: " 
00217                                          << " region "<<region
00218                                          << " ring "<<ring
00219                                          << " station "<<station
00220                                          << " sector "<<sector
00221                                          << " layer "<<layer
00222                                          << " subsector "<<subsector
00223                                          << " roll "<<roll
00224                                          << std::endl;
00225   }
00226               
00227   
00228   int regionInBits=region-minRegionId;
00229   int ringInBits =0;
00230   if(region != 0) ringInBits = ring - minRingForwardId;
00231   if(!region) ringInBits = ring + RingBarrelOffSet - minRingBarrelId;
00232   
00233   int stationInBits=station-minStationId;
00234   int sectorInBits=sector-(minSectorId+1);
00235   int layerInBits=layer-minLayerId;
00236   int subSectorInBits=subsector-(minSubSectorId+1);
00237   int rollInBits=roll;
00238   
00239   id_ |= ( regionInBits    & RegionMask_)    << RegionStartBit_    | 
00240          ( ringInBits      & RingMask_)      << RingStartBit_      |
00241          ( stationInBits   & StationMask_)   << StationStartBit_   |
00242          ( sectorInBits    & SectorMask_)    << SectorStartBit_    |
00243          ( layerInBits     & LayerMask_)     << LayerStartBit_     |
00244          ( subSectorInBits & SubSectorMask_) << SubSectorStartBit_ |
00245          ( rollInBits      & RollMask_)      << RollStartBit_        ;
00246    
00247 }
00248 
00249 
00250 
00251 std::ostream& operator<<( std::ostream& os, const RPCDetId& id ){
00252 
00253 
00254   os <<  " Re "<<id.region()
00255      << " Ri "<<id.ring()
00256      << " St "<<id.station()
00257      << " Se "<<id.sector()
00258      << " La "<<id.layer()
00259      << " Su "<<id.subsector()
00260      << " Ro "<<id.roll()
00261      << " Tr "<<id.trIndex()
00262      <<" ";
00263 
00264   return os;
00265 }
00266 
00267 

Generated on Tue Jun 9 17:31:20 2009 for CMSSW by  doxygen 1.5.4