CMS 3D CMS Logo

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