CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCDetId.cc
Go to the documentation of this file.
1 
10 
11 #include<iostream>
12 
14 
15 
16 RPCDetId::RPCDetId(uint32_t id):DetId(id),trind(0) {
17  // std::cout<<" constructor of the RPCDetId" <<std::endl;
19  throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
20  << " det: " << det()
21  << " subdet: " << subdetId()
22  << " is not a valid RPC id";
23  }
24 }
25 RPCDetId::RPCDetId(DetId id):DetId(id),trind(0) {
26  // std::cout<<" constructor of the RPCDetId" <<std::endl;
28  throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
29  << " det: " << det()
30  << " subdet: " << subdetId()
31  << " is not a valid RPC id";
32  }
33 }
34 
35 
36 
37 RPCDetId::RPCDetId(int region, int ring, int station, int sector, int layer,int subsector, int roll):
38  DetId(DetId::Muon, MuonSubdetId::RPC),trind(0)
39 {
40  this->init(region,ring,station,sector,layer,subsector,roll);
41 }
42 
43 
44 void
45 RPCDetId::buildfromDB(int region, int ring, int trlayer, int sector,
46  const std::string& subs,
47  const std::string& roll,
48  const std::string& dbname){
49 
50  bool barrel = (region==0);
51  //STATION
52  int station = -1;
53  if (barrel) {
54  if (trlayer==1 || trlayer==2) station = 1;
55  else if (trlayer==3 || trlayer==4) station = 2;
56  else station = trlayer-2;
57  } else {
58  station = abs(ring);
59  }
60 
61 
62  //LAYER
63  //int layer = 1;
64  //if (barrel && station==1) layer = trlayer;
65  //if (barrel && station==2) layer = trlayer-2;
66 
67  //SUBSECTOR
68  int subsector = 1;
69 
70  if (barrel) {
71  if (station==3 && subs=="+") subsector = 2;
72  if (station==4 &&
73  ( sector==1 || sector==2 || sector==3
74  || sector==5 || sector==6
75  || sector==7 || sector==8
76  || sector==10 || sector==12)
77  && (subs=="+")) {
78  subsector = 2;
79  }
80 
81  if (station==4 && sector==4) {
82  if (subs=="--") subsector=1;
83  if (subs=="-") subsector=2;
84  if (subs=="+") subsector=3;
85  if (subs=="++") subsector=4;
86  }
87  }
88 
89  // ROLL
90  int iroll=0;
91 
92  if (roll=="Backward" || roll=="A") iroll = 1;
93  else if (roll=="Central" || roll=="B") iroll = 2;
94  else if (roll=="Forward" || roll=="C") iroll = 3;
95  else if (roll=="D") iroll = 4;
96  else {
97  std::cout << "** RPC: DBSpecToDetUnit, how to assigne roll to: "
98  <<roll<<" ???" << std::endl;
99  }
100 
101  int trIndex = 0;
102  if(barrel){
103  //cout <<" BARREL: " << endl;
104  int eta_id = 6+ring;
105  int plane_id = station;
106  if(trlayer==2) plane_id=5;
107  if(trlayer==4) plane_id=6;
108  int sector_id = sector*3;
109  int copy_id = subsector;
110  int roll_id = iroll;
111  trIndex=(eta_id*10000+plane_id*1000+sector_id*10+copy_id)*10+roll_id;
112  }
113  else {
114  // cout << "ENDCAP : " << endl;
115  int eta_id = trlayer;
116  if(ring>0) eta_id = 12-trlayer;
117  int plane_id = abs(ring);
118  int sector_id = sector;
119 
120  if (region <0){
121  if (sector_id < 20 ){
122  sector_id = 19+ 1-sector_id;
123  }else{
124  sector_id = 36+20-sector_id;
125  }
126  }
127  sector_id-=1;
128 
129  //
130  int copy_id = 1;
131  int roll_id = iroll;
132  trIndex=(eta_id*10000+plane_id*1000+sector_id*10+copy_id)*10+ roll_id;
133  }
134  this->buildfromTrIndex(trIndex);
135 }
136 
137 void
139 {
140  trind = trIndex;
141  int eta_id = trIndex/100000;
142  int region=0;
143  int ring =0;
144  if (eta_id <=3 ){
145  region = -1;
146  ring = eta_id;
147  }
148  else if (eta_id >=9 ) {
149  region = 1;
150  ring = 12-eta_id;
151  }
152  else{
153  region = 0;
154  ring = eta_id - 6;
155  }
156  trIndex = trIndex%100000;
157  int plane_id = trIndex/10000;
158  int station=0;
159  int layer=0;
160  if (plane_id <=4){
161  station = plane_id;
162  layer = 1;
163  }
164  else{
165  station = plane_id -4;
166  layer = 2;
167  }
168  trIndex = trIndex%10000;
169  int sector_id = trIndex/100;
170 
171  // RE+1/1 :: the chamber at x=0 (phi=0) start as CH02 instead of CH01, which is not desired
172  // while for other chambers: RE+1/(2,3) and RE+2,3,4/(2,3) the rotation seems to be arbitrary
173  // I will leave the code for the existing chambers as it is, but will remove RE+1/1 from selection
174  // These lines are programmed very asymmetric between Pos \& Neg endcap:
175  // - it affects the whole Negative Endcap
176  // - it affects the whole RE+/-1 Station
177  // - it affects all RE+(1,2,3,4)/(2,3)
178  // ==> why does it act differently on RE-(2,3,4)/1 and RE+(2,3,4)/1 ???
179  if (region!=0) {
180  if ( !(ring == 1 && station > 1 && region==1)) {
181  // skip RE+1/1 (ri=1, st=1, re=-1,+1)
182  if(!(ring == 1 && station == 1 && region!=0)) {
183  sector_id+=1;
184  if (sector_id==37) sector_id=1;
185  }
186  }
187  }
188 
189  if (region==-1){
190  if (sector_id < 20 ){
191  sector_id = 19+ 1-sector_id;
192  }else{
193  sector_id = 36+20-sector_id;
194  }
195  }
196  trIndex = trIndex%100;
197  int copy_id = trIndex/10;
198  int sector=(sector_id-1)/3+1;
199  if (region!=0) {
200  sector=(sector+1)/2;
201  }
202  int subsector=0;
203  if ( region == 0 ) {
204  subsector = copy_id;
205  }
206  else {
207  if ( ring == 1 && station > 1) {
208  // 20 degree chambers
209  subsector = ((sector_id+1)/2-1)%3+1;
210  }else {
211  // 10 degree chambers
212  subsector = (sector_id-1)%6+1;
213  }
214 // std::cout <<" RE"<<station*region<<"/"<<ring<<" sector_id "<<sector_id
215 // << " sector "<<sector <<" sub "<<subsector<<std::endl;
216  }
217 
218 
219  int roll=trIndex%10;
220  this->init(region,ring,station,sector,layer,subsector,roll);
221 }
222 
223 
224 
225 void
226 RPCDetId::init(int region,int ring,int station,int sector,
227  int layer,int subsector,int roll)
228 {
229  int minRing=0;
231  if (!region)
232  {
235  }
236 
237  if ( region < minRegionId || region > maxRegionId ||
238  ring < minRing || ring > maxRing ||
239  station < minStationId || station > maxStationId ||
240  sector < minSectorId || sector > maxSectorId ||
241  layer < minLayerId || layer > maxLayerId ||
242  subsector < minSubSectorId || subsector > maxSubSectorId ||
243  roll < minRollId || roll > maxRollId) {
244  throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
245  << " Invalid parameters: "
246  << " region "<<region
247  << " ring "<<ring
248  << " station "<<station
249  << " sector "<<sector
250  << " layer "<<layer
251  << " subsector "<<subsector
252  << " roll "<<roll
253  << std::endl;
254  }
255 
256 
257  int regionInBits=region-minRegionId;
258  int ringInBits =0;
259  if(region != 0) ringInBits = ring - minRingForwardId;
260  if(!region) ringInBits = ring + RingBarrelOffSet - minRingBarrelId;
261 
262  int stationInBits=station-minStationId;
263  int sectorInBits=sector-(minSectorId+1);
264  int layerInBits=layer-minLayerId;
265  int subSectorInBits=subsector-(minSubSectorId+1);
266  int rollInBits=roll;
267 
268  id_ |= ( regionInBits & RegionMask_) << RegionStartBit_ |
269  ( ringInBits & RingMask_) << RingStartBit_ |
270  ( stationInBits & StationMask_) << StationStartBit_ |
271  ( sectorInBits & SectorMask_) << SectorStartBit_ |
272  ( layerInBits & LayerMask_) << LayerStartBit_ |
273  ( subSectorInBits & SubSectorMask_) << SubSectorStartBit_ |
274  ( rollInBits & RollMask_) << RollStartBit_ ;
275 
276 }
277 
278 
279 
280 std::ostream& operator<<( std::ostream& os, const RPCDetId& id ){
281 
282 
283  os << " Re "<<id.region()
284  << " Ri "<<id.ring()
285  << " St "<<id.station()
286  << " Se "<<id.sector()
287  << " La "<<id.layer()
288  << " Su "<<id.subsector()
289  << " Ro "<<id.roll()
290  << " Tr "<<id.trIndex()
291  <<" ";
292 
293  return os;
294 }
295 
296 
static const int maxStationId
Definition: RPCDetId.h:145
RPCDetId()
Definition: RPCDetId.cc:13
static const unsigned int RingMask_
Definition: RPCDetId.h:177
static const int SubSectorStartBit_
Definition: RPCDetId.h:193
void buildfromDB(int region, int ring, int layer, int sector, const std::string &subsector, const std::string &roll, const std::string &dbname)
Definition: RPCDetId.cc:45
void buildfromTrIndex(int trIndex)
Built from the trigger det Index.
Definition: RPCDetId.cc:138
void init(int region, int ring, int station, int sector, int layer, int subsector, int roll)
Definition: RPCDetId.cc:226
static const int maxLayerId
Definition: RPCDetId.h:155
int trind
Definition: RPCDetId.h:211
static const int maxRingForwardId
Definition: RPCDetId.h:139
static const int minRingBarrelId
Definition: RPCDetId.h:140
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
static const int minSubSectorId
Definition: RPCDetId.h:157
static const int LayerStartBit_
Definition: RPCDetId.h:189
static const int minSectorId
Definition: RPCDetId.h:147
static const int StationStartBit_
Definition: RPCDetId.h:180
int roll() const
Definition: RPCDetId.h:120
static const unsigned int SectorMask_
Definition: RPCDetId.h:186
static const int minRegionId
Definition: RPCDetId.h:135
static const unsigned int LayerMask_
Definition: RPCDetId.h:190
int ring() const
Definition: RPCDetId.h:72
static const int maxSubSectorId
Definition: RPCDetId.h:158
static const int RingStartBit_
Definition: RPCDetId.h:176
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int RegionStartBit_
Definition: RPCDetId.h:172
static const int RegionMask_
Definition: RPCDetId.h:173
static const unsigned int SubSectorMask_
Definition: RPCDetId.h:194
static const int maxRollId
Definition: RPCDetId.h:165
static const int SectorStartBit_
Definition: RPCDetId.h:185
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
static const int RingBarrelOffSet
Definition: RPCDetId.h:142
static const int maxRegionId
Definition: RPCDetId.h:136
static const int minStationId
Definition: RPCDetId.h:144
static const int RollStartBit_
Definition: RPCDetId.h:197
static const unsigned int StationMask_
Definition: RPCDetId.h:181
int layer() const
Definition: RPCDetId.h:108
Definition: DetId.h:18
int trIndex() const
Definition: RPCDetId.h:125
uint32_t id_
Definition: DetId.h:55
static const int maxRingBarrelId
Definition: RPCDetId.h:141
static const int maxSectorId
Definition: RPCDetId.h:148
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:114
static const int minRingForwardId
Definition: RPCDetId.h:138
static const int RPC
Definition: MuonSubdetId.h:14
static const unsigned int RollMask_
Definition: RPCDetId.h:198
tuple cout
Definition: gather_cfg.py:145
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
static const int minLayerId
Definition: RPCDetId.h:154
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96