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
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
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 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 int layer = 1;
00062 if (barrel && station==1) layer = trlayer;
00063 if (barrel && station==2) layer = trlayer-2;
00064
00065
00066 int subsector = 1;
00067
00068 if (barrel) {
00069 if (station==3 && subs=="+") subsector = 2;
00070 if (station==4 &&
00071 ( sector==1 || sector==2 || sector==3
00072 || sector==5 || sector==6
00073 || sector==7 || sector==8
00074 || sector==10 || sector==12)
00075 && (subs=="+")) {
00076 subsector = 2;
00077 }
00078
00079 if (station==4 && sector==4) {
00080 if (subs=="--") subsector=1;
00081 if (subs=="-") subsector=2;
00082 if (subs=="+") subsector=3;
00083 if (subs=="++") subsector=4;
00084 }
00085 }
00086
00087
00088 int iroll=0;
00089
00090 if (roll=="Backward" || roll=="A") iroll = 1;
00091 else if (roll=="Central" || roll=="B") iroll = 2;
00092 else if (roll=="Forward" || roll=="C") iroll = 3;
00093 else if (roll=="D") iroll = 4;
00094 else {
00095 std::cout << "** RPC: DBSpecToDetUnit, how to assigne roll to: "
00096 <<roll<<" ???" << std::endl;
00097 }
00098
00099 int trIndex = 0;
00100 if(barrel){
00101
00102 int eta_id = 6+ring;
00103 int plane_id = station;
00104 if(trlayer==2) plane_id=5;
00105 if(trlayer==4) plane_id=6;
00106 int sector_id = sector*3;
00107 int copy_id = subsector;
00108 int roll_id = iroll;
00109 trIndex=(eta_id*10000+plane_id*1000+sector_id*10+copy_id)*10+roll_id;
00110 }
00111 else {
00112
00113 int eta_id = trlayer;
00114 if(ring>0) eta_id = 12-trlayer;
00115 int plane_id = abs(ring);
00116 int sector_id = sector;
00117
00118 if (region <0){
00119 if (sector_id < 20 ){
00120 sector_id = 19+ 1-sector_id;
00121 }else{
00122 sector_id = 36+20-sector_id;
00123 }
00124 }
00125 sector_id-=1;
00126
00127
00128 int copy_id = 1;
00129 int roll_id = iroll;
00130 trIndex=(eta_id*10000+plane_id*1000+sector_id*10+copy_id)*10+ roll_id;
00131 }
00132 this->buildfromTrIndex(trIndex);
00133 }
00134
00135 void
00136 RPCDetId::buildfromTrIndex(int trIndex)
00137 {
00138 trind = trIndex;
00139 int eta_id = trIndex/100000;
00140 int region=0;
00141 int ring =0;
00142 if (eta_id <=3 ){
00143 region = -1;
00144 ring = eta_id;
00145 }
00146 else if (eta_id >=9 ) {
00147 region = 1;
00148 ring = 12-eta_id;
00149 }
00150 else{
00151 region = 0;
00152 ring = eta_id - 6;
00153 }
00154 trIndex = trIndex%100000;
00155 int plane_id = trIndex/10000;
00156 int station=0;
00157 int layer=0;
00158 if (plane_id <=4){
00159 station = plane_id;
00160 layer = 1;
00161 }
00162 else{
00163 station = plane_id -4;
00164 layer = 2;
00165 }
00166 trIndex = trIndex%10000;
00167 int sector_id = trIndex/100;
00168 if (region!=0) {
00169 if ( !(ring == 1 && station > 1 && region==1)) {
00170 sector_id+=1;
00171 if (sector_id==37)sector_id=1;
00172 }
00173 }
00174 if (region==-1){
00175 if (sector_id < 20 ){
00176 sector_id = 19+ 1-sector_id;
00177 }else{
00178 sector_id = 36+20-sector_id;
00179 }
00180 }
00181 trIndex = trIndex%100;
00182 int copy_id = trIndex/10;
00183 int sector=(sector_id-1)/3+1;
00184 if (region!=0) {
00185 sector=(sector+1)/2;
00186 }
00187 int subsector=0;
00188 if ( region == 0 ) {
00189 subsector = copy_id;
00190 }
00191 else {
00192 if ( ring == 1 && station > 1) {
00193
00194 subsector = ((sector_id+1)/2-1)%3+1;
00195 }else {
00196
00197 subsector = (sector_id-1)%6+1;
00198 }
00199
00200
00201 }
00202
00203
00204 int roll=trIndex%10;
00205 this->init(region,ring,station,sector,layer,subsector,roll);
00206 }
00207
00208
00209
00210 void
00211 RPCDetId::init(int region,int ring,int station,int sector,
00212 int layer,int subsector,int roll)
00213 {
00214 int minRing=0;
00215 int maxRing=RPCDetId::maxRingForwardId;
00216 if (!region)
00217 {
00218 minRing=RPCDetId::minRingBarrelId;
00219 maxRing=RPCDetId::maxRingBarrelId;
00220 }
00221
00222 if ( region < minRegionId || region > maxRegionId ||
00223 ring < minRing || ring > maxRing ||
00224 station < minStationId || station > maxStationId ||
00225 sector < minSectorId || sector > maxSectorId ||
00226 layer < minLayerId || layer > maxLayerId ||
00227 subsector < minSubSectorId || subsector > maxSubSectorId ||
00228 roll < minRollId || roll > maxRollId) {
00229 throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
00230 << " Invalid parameters: "
00231 << " region "<<region
00232 << " ring "<<ring
00233 << " station "<<station
00234 << " sector "<<sector
00235 << " layer "<<layer
00236 << " subsector "<<subsector
00237 << " roll "<<roll
00238 << std::endl;
00239 }
00240
00241
00242 int regionInBits=region-minRegionId;
00243 int ringInBits =0;
00244 if(region != 0) ringInBits = ring - minRingForwardId;
00245 if(!region) ringInBits = ring + RingBarrelOffSet - minRingBarrelId;
00246
00247 int stationInBits=station-minStationId;
00248 int sectorInBits=sector-(minSectorId+1);
00249 int layerInBits=layer-minLayerId;
00250 int subSectorInBits=subsector-(minSubSectorId+1);
00251 int rollInBits=roll;
00252
00253 id_ |= ( regionInBits & RegionMask_) << RegionStartBit_ |
00254 ( ringInBits & RingMask_) << RingStartBit_ |
00255 ( stationInBits & StationMask_) << StationStartBit_ |
00256 ( sectorInBits & SectorMask_) << SectorStartBit_ |
00257 ( layerInBits & LayerMask_) << LayerStartBit_ |
00258 ( subSectorInBits & SubSectorMask_) << SubSectorStartBit_ |
00259 ( rollInBits & RollMask_) << RollStartBit_ ;
00260
00261 }
00262
00263
00264
00265 std::ostream& operator<<( std::ostream& os, const RPCDetId& id ){
00266
00267
00268 os << " Re "<<id.region()
00269 << " Ri "<<id.ring()
00270 << " St "<<id.station()
00271 << " Se "<<id.sector()
00272 << " La "<<id.layer()
00273 << " Su "<<id.subsector()
00274 << " Ro "<<id.roll()
00275 << " Tr "<<id.trIndex()
00276 <<" ";
00277
00278 return os;
00279 }
00280
00281