CMS 3D CMS Logo

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