CMS 3D CMS Logo

CSCIndexer.cc
Go to the documentation of this file.
2 #include <iostream>
3 
5  // Fill the member vector which permits decoding of the linear chamber index
6  // Logically const since initializes cache only,
7  // Beware that the ME42 indices 235-270 within this vector do NOT correspond to
8  // their 'real' linear indices (which are 469-504 for +z)
9  chamberLabel.resize(271); // one more than #chambers per endcap. Includes ME42.
10  IndexType count = 0;
11  chamberLabel[count] = 0;
12 
13  for (IndexType is = 1; is != 5; ++is) {
14  IndexType irmax = ringsInStation(is);
15  for (IndexType ir = 1; ir != irmax + 1; ++ir) {
16  IndexType icmax = chambersInRingOfStation(is, ir);
17  for (IndexType ic = 1; ic != icmax + 1; ++ic) {
18  chamberLabel[++count] = is * 1000 + ir * 100 + ic;
19  }
20  }
21  }
22 }
23 
25  // Will not work as is for ME42
26  // ============================
27 
28  IndexType ie = 1;
29  if (ici > 234) {
30  ie = 2;
31  ici -= 234;
32  }
33  // Now ici is in range 1-234 (assuming valid input in range 1-468)
34 
35  // MEij pairs...
36  const IndexType station[] = {0, 1, 1, 1, 2, 2, 3, 3, 4};
37  const IndexType ring[] = {0, 1, 2, 3, 1, 2, 1, 2, 1};
38 
39  // MEij preceding a given MEij matching linear index above
40  const IndexType prevs[] = {0, 0, 1, 1, 1, 2, 2, 3, 3};
41  const IndexType prevr[] = {0, 0, 1, 2, 3, 1, 2, 1, 2};
42 
43  IndexType is = 4;
44  IndexType ir = 1;
45  for (IndexType i = 2; i <= 8; ++i) {
46  IndexType js = station[i];
47  IndexType jr = ring[i];
48  // if it's before start of MEjs/jr then it's in the previous MEis/ir
49  if (ici < startChamberIndexInEndcap(ie, js, jr)) {
50  is = prevs[i];
51  ir = prevr[i];
52  break;
53  }
54  // otherwise it's in ME41
55  }
56  IndexType ic = ici - startChamberIndexInEndcap(ie, is, ir) + 1;
57 
58  return CSCDetId(ie, is, ir, ic);
59 }
60 
62  // Expected range of input range argument is 1-540.
63  // 1-468 for CSCs installed at 2008 start-up. 469-540 for ME42.
64 
65  IndexType ie = 1;
66  if (ici > 468) {
67  // ME42
68  ici -= 234; // now in range 235-306
69  if (ici > 270) { // -z
70  ie = 2;
71  ici -= 36; // now in range 235-270
72  }
73  } else { // in range 1-468
74  if (ici > 234) { // -z
75  ie = 2;
76  ici -= 234; // now in range 1-234
77  }
78  }
79  if (chamberLabel.empty())
82  return detIdFromChamberLabel(ie, label);
83 }
84 
86  // This is just for cross-checking
87 
88  // Expected range of input range argument is 1-540.
89  // 1-468 for CSCs installed at 2008 start-up. 469-540 for ME42.
90 
91  if (ici > 468) {
92  // ME42
93  ici -= 234; // now in range 235-306
94  if (ici > 270) { // -z
95  ici -= 36; // now in range 235-270
96  }
97  } else { // in range 1-468
98  if (ici > 234) { // -z
99  ici -= 234; // now in range 1-234
100  }
101  }
102  if (chamberLabel.empty())
104  return chamberLabel[ici];
105 }
106 
108  IndexType is = label / 1000;
109  label -= is * 1000;
110  IndexType ir = label / 100;
111  label -= ir * 100;
112  IndexType ic = label;
113 
114  return CSCDetId(ie, is, ir, ic);
115 }
116 
118  IndexType il = (ili - 1) % 6 + 1;
119  IndexType ici = (ili - 1) / 6 + 1;
121 
122  return CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), il);
123 }
124 
125 std::pair<CSCDetId, CSCIndexer::IndexType> CSCIndexer::detIdFromStripChannelIndex(LongIndexType isi) const {
126  const LongIndexType lastnonme42 = 217728; // channels in 2008 installed chambers
127  const LongIndexType lastplusznonme42 = 108864; // = 217728/2
128  const LongIndexType firstme13 = 34561; // First channel of ME13
129  const LongIndexType lastme13 = 48384; // Last channel of ME13
130 
131  const IndexType lastnonme42layer = 2808;
132  const IndexType lastplusznonme42layer = 1404; // = 2808/2
133  const IndexType firstme13layer = 433; // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
134  const IndexType lastme13layer = 648; // = 108*6
135 
136  // All chambers but ME13 have 80 channels
137  IndexType nchan = 80;
138 
139  // Set endcap to +z. This should work for ME42 channels too, since we don't need to calculate its endcap explicitly.
140  IndexType ie = 1;
141 
142  LongIndexType istart = 0;
143  IndexType layerOffset = 0;
144 
145  if (isi <= lastnonme42) {
146  // Chambers as of 2008 Installation
147 
148  if (isi > lastplusznonme42) {
149  ie = 2;
150  isi -= lastplusznonme42;
151  }
152 
153  if (isi > lastme13) { // after ME13
154  istart = lastme13;
155  layerOffset = lastme13layer;
156  } else if (isi >= firstme13) { // ME13
157  istart = firstme13 - 1;
158  layerOffset = firstme13layer - 1;
159  nchan = 64;
160  }
161  } else {
162  // ME42 chambers
163 
164  istart = lastnonme42;
165  layerOffset = lastnonme42layer;
166  }
167 
168  isi -= istart; // remove earlier group(s)
169  IndexType ichan = (isi - 1) % nchan + 1;
170  IndexType ili = (isi - 1) / nchan + 1;
171  ili += layerOffset; // add appropriate offset for earlier group(s)
172  if (ie != 1)
173  ili += lastplusznonme42layer; // add offset to -z endcap; ME42 doesn't need this.
174 
175  return std::pair<CSCDetId, IndexType>(detIdFromLayerIndex(ili), ichan);
176 }
177 
178 std::pair<CSCDetId, CSCIndexer::IndexType> CSCIndexer::detIdFromChipIndex(IndexType ici) const {
179  const LongIndexType lastnonme42 = 13608; // chips in 2008 installed chambers
180  const LongIndexType lastplusznonme42 = 6804; // = 13608/2
181  const LongIndexType firstme13 = 2161; // First channel of ME13
182  const LongIndexType lastme13 = 3024; // Last channel of ME13
183 
184  const IndexType lastnonme42layer = 2808;
185  const IndexType lastplusznonme42layer = 1404; // = 2808/2
186  const IndexType firstme13layer = 433; // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
187  const IndexType lastme13layer = 648; // = 108*6
188 
189  // All chambers but ME13 have 5 chips/layer
190  IndexType nchipPerLayer = 5;
191 
192  // Set endcap to +z. This should work for ME42 channels too, since we don't need to calculate its endcap explicitly.
193  IndexType ie = 1;
194 
195  LongIndexType istart = 0;
196  IndexType layerOffset = 0;
197 
198  if (ici <= lastnonme42) {
199  // Chambers as of 2008 Installation
200 
201  if (ici > lastplusznonme42) {
202  ie = 2;
203  ici -= lastplusznonme42;
204  }
205 
206  if (ici > lastme13) { // after ME13
207  istart = lastme13;
208  layerOffset = lastme13layer;
209  } else if (ici >= firstme13) { // ME13
210  istart = firstme13 - 1;
211  layerOffset = firstme13layer - 1;
212  nchipPerLayer = 4;
213  }
214  } else {
215  // ME42 chambers
216 
217  istart = lastnonme42;
218  layerOffset = lastnonme42layer;
219  }
220 
221  ici -= istart; // remove earlier group(s)
222  IndexType ichip = (ici - 1) % nchipPerLayer + 1;
223  IndexType ili = (ici - 1) / nchipPerLayer + 1;
224  ili += layerOffset; // add appropriate offset for earlier group(s)
225  if (ie != 1)
226  ili += lastplusznonme42layer; // add offset to -z endcap; ME42 doesn't need this.
227 
228  return std::pair<CSCDetId, IndexType>(detIdFromLayerIndex(ili), ichip);
229 }
230 
231 int CSCIndexer::dbIndex(const CSCDetId& id, int& channel) {
232  int ec = id.endcap();
233  int st = id.station();
234  int rg = id.ring();
235  int ch = id.chamber();
236  int la = id.layer();
237 
238  // The channels of ME1A are channels 65-80 of ME11
239  if (st == 1 && rg == 4) {
240  rg = 1;
241  if (channel <= 16)
242  channel += 64; // no trapping for any bizarreness
243  }
244  return ec * 100000 + st * 10000 + rg * 1000 + ch * 10 + la;
245 }
CSCDetId detIdFromChamberIndex(IndexType ici) const
Definition: CSCIndexer.cc:61
IndexType ringsInStation(IndexType is) const
Definition: CSCIndexer.h:114
char const * label
IndexType chambersInRingOfStation(IndexType is, IndexType ir) const
Definition: CSCIndexer.h:124
int dbIndex(const CSCDetId &id, int &channel)
Definition: CSCIndexer.cc:231
CSCDetId detIdFromLayerIndex(IndexType ili) const
Definition: CSCIndexer.cc:117
uint16_t IndexType
Definition: CSCIndexer.h:48
CSCDetId detIdFromChamberLabel(IndexType ie, IndexType icl) const
Definition: CSCIndexer.cc:107
IndexType chamberLabelFromChamberIndex(IndexType) const
Definition: CSCIndexer.cc:85
std::pair< CSCDetId, IndexType > detIdFromChipIndex(IndexType ichi) const
Definition: CSCIndexer.cc:178
uint32_t LongIndexType
Definition: CSCIndexer.h:49
IndexType startChamberIndexInEndcap(IndexType ie, IndexType is, IndexType ir) const
Definition: CSCIndexer.h:86
std::pair< CSCDetId, IndexType > detIdFromStripChannelIndex(LongIndexType ichi) const
Definition: CSCIndexer.cc:125
CSCDetId detIdFromChamberIndex_OLD(IndexType ici) const
Definition: CSCIndexer.cc:24
void fillChamberLabel() const
Definition: CSCIndexer.cc:4
std::vector< IndexType > chamberLabel
Definition: CSCIndexer.h:424