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