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