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