CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCIndexer.h
Go to the documentation of this file.
1 #ifndef MuonDetId_CSCIndexer_h
2 #define MuonDetId_CSCIndexer_h
3 
40 #include <vector>
41 #include <iosfwd>
42 #include <utility> // for pair
43 
44 class CSCIndexer {
45 public:
46  // typedef unsigned short int IndexType;
47  // typedef unsigned int LongIndexType;
48  typedef uint16_t IndexType;
49  typedef uint32_t LongIndexType;
50 
53 
64  IndexType chamberIndex(const CSCDetId& id) const {
65  return chamberIndex(id.endcap(), id.station(), id.ring(), id.chamber());
66  }
67 
78  IndexType layerIndex(const CSCDetId& id) const {
79  return layerIndex(id.endcap(), id.station(), id.ring(), id.chamber(), id.layer());
80  }
81 
87  const IndexType nschin[24] = {1, 37, 73, 109, 127, 0, 163, 181, 0, 217, 469, 0,
88  235, 271, 307, 343, 361, 0, 397, 415, 0, 451, 505, 0};
89  return nschin[(ie - 1) * 12 + (is - 1) * 3 + ir - 1];
90  }
91 
97  return startChamberIndexInEndcap(ie, is, ir) + ic - 1; // -1 so start index _is_ ic=1
98  }
99 
105  const IndexType layersInChamber = 6;
106  return (chamberIndex(ie, is, ir, ic) - 1) * layersInChamber + il;
107  }
108 
115  const IndexType nrins[5] = {0, 3, 2, 2, 2}; // rings per station
116  return nrins[is];
117  }
118 
125  IndexType nc = 36; // most rings have 36 chambers
126  if (is > 1 && ir < 2)
127  nc = 18; // but 21, 31, 41 have 18
128  return nc;
129  }
130 
141  const IndexType nSCinC[12] = {80, 80, 64, 80, 80, 0, 80, 80, 0, 80, 80, 0};
142  return nSCinC[(is - 1) * 3 + ir - 1];
143  }
144 
154  // These are in the ranges 1-217728 (CSCs 2008) and 217729-252288 (ME42).
155  // There are 1-108884 channels per endcap (CSCs 2008) and 17280 channels per endcap (ME42).
156  // Start of -z channels (CSCs 2008) is 108864 + 1 = 108865
157  // Start of +z (ME42) is 217728 + 1 = 217729
158  // Start of -z (ME42) is 217728 + 1 + 17280 = 235009
159  const LongIndexType nStart[24] = {1, 17281, 34561, 48385, 57025, 0, 74305, 82945, 0, 100225, 217729, 0,
160  108865, 126145, 143425, 157249, 165889, 0, 183169, 191809, 0, 209089, 235009, 0};
161  return nStart[(ie - 1) * 12 + (is - 1) * 3 + ir - 1];
162  }
163 
174  IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType istrip) const {
175  return stripChannelStart(ie, is, ir) + ((ic - 1) * 6 + il - 1) * stripChannelsPerLayer(is, ir) + (istrip - 1);
176  }
177 
188  return stripChannelIndex(id.endcap(), id.station(), id.ring(), id.chamber(), id.layer(), istrip);
189  }
190 
201  const IndexType nCinL[12] = {5, 5, 4, 5, 5, 0, 5, 5, 0, 5, 5, 0};
202  return nCinL[(is - 1) * 3 + ir - 1];
203  }
204 
214  // These are in the ranges 1-13608 (CSCs 2008) and 13609-15768 (ME42).
215  // There are 1-6804 chips per endcap (CSCs 2008) and 1080 channels per endcap (ME42).
216  // Start of -z channels (CSCs 2008) is 6804 + 1 = 6805
217  // Start of +z (ME42) is 13608 + 1 = 13609
218  // Start of -z (ME42) is 13608 + 1 + 1080 = 14689
219  const IndexType nStart[24] = {1, 1081, 2161, 3025, 3565, 0, 4645, 5185, 0, 6265, 13609, 0,
220  6805, 7885, 8965, 9829, 10369, 0, 11449, 11989, 0, 13069, 14689, 0};
221 
222  return nStart[(ie - 1) * 12 + (is - 1) * 3 + ir - 1];
223  }
224 
235  //printf("ME%d/%d/%d/%d layer %d chip %d chipindex %d\n",ie,is,ir,ic,il,ichip,chipStart(ie,is,ir)+( (ic-1)*6 + il - 1 )*chipsPerLayer(is,ir) + (ichip-1));
236  return chipStart(ie, is, ir) + ((ic - 1) * 6 + il - 1) * chipsPerLayer(is, ir) + (ichip - 1);
237  }
238 
248  IndexType chipIndex(const CSCDetId& id, IndexType ichip) const {
249  return chipIndex(id.endcap(), id.station(), id.ring(), id.chamber(), id.layer(), ichip);
250  }
251 
262  IndexType chipIndex(IndexType istrip) const { return (istrip - 1) / 16 + 1; }
263 
273  const IndexType nSinL[12] = {1, 3, 3, 3, 5, 0, 3, 5, 0, 3, 5, 0};
274  return nSinL[(is - 1) * 3 + ir - 1];
275  }
276 
286  return chipsPerLayer(is, ir) * hvSegmentsPerLayer(is, ir);
287  }
288 
298  IndexType hvSegment = 1; // There is only one HV segment in ME1/1
299 
300  if (is > 2 && ir == 1) { // HV segments are the same in ME3/1 and ME4/1
301  if (iwire >= 33 && iwire <= 64) {
302  hvSegment = 2;
303  } else if (iwire >= 65 && iwire <= 96) {
304  hvSegment = 3;
305  }
306 
307  } else if (is > 1 && ir == 2) { // HV segments are the same in ME2/2, ME3/2, and ME4/2
308  if (iwire >= 17 && iwire <= 28) {
309  hvSegment = 2;
310  } else if (iwire >= 29 && iwire <= 40) {
311  hvSegment = 3;
312  } else if (iwire >= 41 && iwire <= 52) {
313  hvSegment = 4;
314  } else if (iwire >= 53 && iwire <= 64) {
315  hvSegment = 5;
316  }
317 
318  } else if (is == 1 && ir == 2) {
319  if (iwire >= 25 && iwire <= 48) {
320  hvSegment = 2;
321  } else if (iwire >= 49 && iwire <= 64) {
322  hvSegment = 3;
323  }
324 
325  } else if (is == 1 && ir == 3) {
326  if (iwire >= 13 && iwire <= 22) {
327  hvSegment = 2;
328  } else if (iwire >= 23 && iwire <= 32) {
329  hvSegment = 3;
330  }
331 
332  } else if (is == 2 && ir == 1) {
333  if (iwire >= 45 && iwire <= 80) {
334  hvSegment = 2;
335  } else if (iwire >= 81 && iwire <= 112) {
336  hvSegment = 3;
337  }
338  }
339 
340  return hvSegment;
341  }
342 
352  // There are 36 chambers * 6 layers * 5 CFEB's * 1 HV segment = 1080 gas-gain sectors in ME1/1
353  // There are 36*6*5*3 = 3240 gas-gain sectors in ME1/2
354  // There are 36*6*4*3 = 2592 gas-gain sectors in ME1/3
355  // There are 18*6*5*3 = 1620 gas-gain sectors in ME[2-4]/1
356  // There are 36*6*5*5 = 5400 gas-gain sectors in ME[2-4]/2
357  // Start of -z channels (CSCs 2008) is 22572 + 1 = 22573
358  // Start of +z (ME42) is 45144 + 1 = 45145
359  // Start of -z (ME42) is 45144 + 1 + 5400 = 50545
360  const IndexType nStart[24] = {1, 1081, 4321, //ME+1/1,ME+1/2,ME+1/3
361  6913, 8533, 0, //ME+2/1,ME+2/2,ME+2/3
362  13933, 15553, 0, //ME+3/1,ME+3/2,ME+3/3
363  20953, 45145, 0, //ME+4/1,ME+4/2,ME+4/3 (note, ME+4/2 index follows ME-4/1...)
364  22573, 23653, 26893, //ME-1/1,ME-1/2,ME-1/3
365  29485, 31105, 0, //ME-2/1,ME-2/2,ME-2/3
366  36505, 38125, 0, //ME-3/1,ME-3/2,ME-3/3
367  43525, 50545, 0}; //ME-4/1,ME-4/2,ME-4/3 (note, ME-4/2 index follows ME+4/2...)
368  return nStart[(ie - 1) * 12 + (is - 1) * 3 + ir - 1];
369  }
370 
379  IndexType gasGainIndex(const CSCDetId& id, IndexType istrip, IndexType iwire) const {
380  return gasGainIndex(id.endcap(), id.station(), id.ring(), id.chamber(), id.layer(), istrip, iwire);
381  }
382 
393  IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType istrip, IndexType iwire) const {
394  IndexType ichip = this->chipIndex(istrip);
395  IndexType ihvsegment = this->hvSegmentIndex(is, ir, iwire);
396  return sectorStart(ie, is, ir) + ((ic - 1) * 6 + il - 1) * sectorsPerLayer(is, ir) +
397  (ihvsegment - 1) * chipsPerLayer(is, ir) + (ichip - 1);
398  }
399 
407  std::pair<CSCDetId, IndexType> detIdFromStripChannelIndex(LongIndexType ichi) const;
408  std::pair<CSCDetId, IndexType> detIdFromChipIndex(IndexType ichi) const;
409 
410  IndexType chamberLabelFromChamberIndex(IndexType) const; // just for cross-checks
411 
419  int dbIndex(const CSCDetId& id, int& channel);
420 
421 private:
422  void fillChamberLabel() const; // const so it can be called in const function detIdFromChamberIndex
423 
424  mutable std::vector<IndexType> chamberLabel; // mutable so can be filled by fillChamberLabel
425 };
426 
427 #endif
std::pair< CSCDetId, IndexType > detIdFromStripChannelIndex(LongIndexType ichi) const
Definition: CSCIndexer.cc:125
IndexType chamberLabelFromChamberIndex(IndexType) const
Definition: CSCIndexer.cc:85
IndexType chipsPerLayer(IndexType is, IndexType ir) const
Definition: CSCIndexer.h:200
IndexType layerIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il) const
Definition: CSCIndexer.h:104
IndexType chamberIndex(const CSCDetId &id) const
Definition: CSCIndexer.h:64
void fillChamberLabel() const
Definition: CSCIndexer.cc:4
IndexType chambersInRingOfStation(IndexType is, IndexType ir) const
Definition: CSCIndexer.h:124
constexpr std::array< uint8_t, layerIndexSize > layer
IndexType hvSegmentIndex(IndexType is, IndexType ir, IndexType iwire) const
Definition: CSCIndexer.h:297
LongIndexType stripChannelIndex(const CSCDetId &id, IndexType istrip) const
Definition: CSCIndexer.h:187
IndexType ringsInStation(IndexType is) const
Definition: CSCIndexer.h:114
int dbIndex(const CSCDetId &id, int &channel)
Definition: CSCIndexer.cc:231
CSCDetId detIdFromChamberIndex(IndexType ici) const
Definition: CSCIndexer.cc:61
CSCDetId detIdFromChamberIndex_OLD(IndexType ici) const
Definition: CSCIndexer.cc:24
uint16_t IndexType
Definition: CSCIndexer.h:48
std::pair< CSCDetId, IndexType > detIdFromChipIndex(IndexType ichi) const
Definition: CSCIndexer.cc:178
IndexType chamberIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic) const
Definition: CSCIndexer.h:96
IndexType chipIndex(IndexType istrip) const
Definition: CSCIndexer.h:262
IndexType chipStart(IndexType ie, IndexType is, IndexType ir) const
Definition: CSCIndexer.h:213
CSCDetId detIdFromChamberLabel(IndexType ie, IndexType icl) const
Definition: CSCIndexer.cc:107
uint32_t LongIndexType
Definition: CSCIndexer.h:49
IndexType sectorsPerLayer(IndexType is, IndexType ir) const
Definition: CSCIndexer.h:285
IndexType chipIndex(const CSCDetId &id, IndexType ichip) const
Definition: CSCIndexer.h:248
IndexType stripChannelsPerLayer(IndexType is, IndexType ir) const
Definition: CSCIndexer.h:140
IndexType layerIndex(const CSCDetId &id) const
Definition: CSCIndexer.h:78
IndexType chipIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType ichip) const
Definition: CSCIndexer.h:234
IndexType startChamberIndexInEndcap(IndexType ie, IndexType is, IndexType ir) const
Definition: CSCIndexer.h:86
std::vector< IndexType > chamberLabel
Definition: CSCIndexer.h:424
IndexType hvSegmentsPerLayer(IndexType is, IndexType ir) const
Definition: CSCIndexer.h:272
LongIndexType stripChannelStart(IndexType ie, IndexType is, IndexType ir) const
Definition: CSCIndexer.h:153
LongIndexType stripChannelIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType istrip) const
Definition: CSCIndexer.h:173
IndexType gasGainIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType istrip, IndexType iwire) const
Definition: CSCIndexer.h:392
CSCDetId detIdFromLayerIndex(IndexType ili) const
Definition: CSCIndexer.cc:117
IndexType gasGainIndex(const CSCDetId &id, IndexType istrip, IndexType iwire) const
Definition: CSCIndexer.h:379
IndexType sectorStart(IndexType ie, IndexType is, IndexType ir) const
Definition: CSCIndexer.h:351