Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-24 01:44:09

0001 #include <DataFormats/MuonDetId/interface/CSCIndexer.h>
0002 #include <iostream>
0003 
0004 std::vector<CSCIndexer::IndexType> CSCIndexer::fillChamberLabel() {
0005   // Fill the member vector which permits decoding of the linear chamber index
0006   // Logically const since initializes cache only,
0007   // Beware that the ME42 indices 235-270 within this vector do NOT correspond to
0008   // their 'real' linear indices (which are 469-504 for +z)
0009   std::vector<IndexType> tChamberLabel;
0010 
0011   tChamberLabel.resize(271);  // one more than #chambers per endcap. Includes ME42.
0012   IndexType count = 0;
0013   tChamberLabel[count] = 0;
0014 
0015   for (IndexType is = 1; is != 5; ++is) {
0016     IndexType irmax = ringsInStation(is);
0017     for (IndexType ir = 1; ir != irmax + 1; ++ir) {
0018       IndexType icmax = chambersInRingOfStation(is, ir);
0019       for (IndexType ic = 1; ic != icmax + 1; ++ic) {
0020         tChamberLabel[++count] = is * 1000 + ir * 100 + ic;
0021       }
0022     }
0023   }
0024   return tChamberLabel;
0025 }
0026 
0027 const std::vector<CSCIndexer::IndexType>& CSCIndexer::chamberLabel() {
0028   static const auto s_chamberLabel = fillChamberLabel();
0029   return s_chamberLabel;
0030 }
0031 
0032 CSCDetId CSCIndexer::detIdFromChamberIndex_OLD(IndexType ici) const {
0033   // Will not work as is for ME42
0034   // ============================
0035 
0036   IndexType ie = 1;
0037   if (ici > 234) {
0038     ie = 2;
0039     ici -= 234;
0040   }
0041   // Now ici is in range 1-234 (assuming valid input in range 1-468)
0042 
0043   // MEij pairs...
0044   const IndexType station[] = {0, 1, 1, 1, 2, 2, 3, 3, 4};
0045   const IndexType ring[] = {0, 1, 2, 3, 1, 2, 1, 2, 1};
0046 
0047   // MEij preceding a given MEij matching linear index above
0048   const IndexType prevs[] = {0, 0, 1, 1, 1, 2, 2, 3, 3};
0049   const IndexType prevr[] = {0, 0, 1, 2, 3, 1, 2, 1, 2};
0050 
0051   IndexType is = 4;
0052   IndexType ir = 1;
0053   for (IndexType i = 2; i <= 8; ++i) {
0054     IndexType js = station[i];
0055     IndexType jr = ring[i];
0056     // if it's before start of MEjs/jr then it's in the previous MEis/ir
0057     if (ici < startChamberIndexInEndcap(ie, js, jr)) {
0058       is = prevs[i];
0059       ir = prevr[i];
0060       break;
0061     }
0062     // otherwise it's in ME41
0063   }
0064   IndexType ic = ici - startChamberIndexInEndcap(ie, is, ir) + 1;
0065 
0066   return CSCDetId(ie, is, ir, ic);
0067 }
0068 
0069 CSCDetId CSCIndexer::detIdFromChamberIndex(IndexType ici) const {
0070   // Expected range of input range argument is 1-540.
0071   // 1-468 for CSCs installed at 2008 start-up. 469-540 for ME42.
0072 
0073   IndexType ie = 1;
0074   if (ici > 468) {
0075     // ME42
0076     ici -= 234;       // now in range 235-306
0077     if (ici > 270) {  // -z
0078       ie = 2;
0079       ici -= 36;  // now in range 235-270
0080     }
0081   } else {            // in range 1-468
0082     if (ici > 234) {  // -z
0083       ie = 2;
0084       ici -= 234;  // now in range 1-234
0085     }
0086   }
0087   IndexType label = chamberLabel()[ici];
0088   return detIdFromChamberLabel(ie, label);
0089 }
0090 
0091 CSCIndexer::IndexType CSCIndexer::chamberLabelFromChamberIndex(IndexType ici) const {
0092   // This is just for cross-checking
0093 
0094   // Expected range of input range argument is 1-540.
0095   // 1-468 for CSCs installed at 2008 start-up. 469-540 for ME42.
0096 
0097   if (ici > 468) {
0098     // ME42
0099     ici -= 234;       // now in range 235-306
0100     if (ici > 270) {  // -z
0101       ici -= 36;      // now in range 235-270
0102     }
0103   } else {            // in range 1-468
0104     if (ici > 234) {  // -z
0105       ici -= 234;     // now in range 1-234
0106     }
0107   }
0108   return chamberLabel()[ici];
0109 }
0110 
0111 CSCDetId CSCIndexer::detIdFromChamberLabel(IndexType ie, IndexType label) const {
0112   IndexType is = label / 1000;
0113   label -= is * 1000;
0114   IndexType ir = label / 100;
0115   label -= ir * 100;
0116   IndexType ic = label;
0117 
0118   return CSCDetId(ie, is, ir, ic);
0119 }
0120 
0121 CSCDetId CSCIndexer::detIdFromLayerIndex(IndexType ili) const {
0122   IndexType il = (ili - 1) % 6 + 1;
0123   IndexType ici = (ili - 1) / 6 + 1;
0124   CSCDetId id = detIdFromChamberIndex(ici);
0125 
0126   return CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), il);
0127 }
0128 
0129 std::pair<CSCDetId, CSCIndexer::IndexType> CSCIndexer::detIdFromStripChannelIndex(LongIndexType isi) const {
0130   const LongIndexType lastnonme42 = 217728;       // channels in 2008 installed chambers
0131   const LongIndexType lastplusznonme42 = 108864;  // = 217728/2
0132   const LongIndexType firstme13 = 34561;          // First channel of ME13
0133   const LongIndexType lastme13 = 48384;           // Last channel of ME13
0134 
0135   const IndexType lastnonme42layer = 2808;
0136   const IndexType lastplusznonme42layer = 1404;  // = 2808/2
0137   const IndexType firstme13layer = 433;          // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
0138   const IndexType lastme13layer = 648;           // = 108*6
0139 
0140   // All chambers but ME13 have 80 channels
0141   IndexType nchan = 80;
0142 
0143   // Set endcap to +z. This should work for ME42 channels too, since we don't need to calculate its endcap explicitly.
0144   IndexType ie = 1;
0145 
0146   LongIndexType istart = 0;
0147   IndexType layerOffset = 0;
0148 
0149   if (isi <= lastnonme42) {
0150     // Chambers as of 2008 Installation
0151 
0152     if (isi > lastplusznonme42) {
0153       ie = 2;
0154       isi -= lastplusznonme42;
0155     }
0156 
0157     if (isi > lastme13) {  // after ME13
0158       istart = lastme13;
0159       layerOffset = lastme13layer;
0160     } else if (isi >= firstme13) {  // ME13
0161       istart = firstme13 - 1;
0162       layerOffset = firstme13layer - 1;
0163       nchan = 64;
0164     }
0165   } else {
0166     // ME42 chambers
0167 
0168     istart = lastnonme42;
0169     layerOffset = lastnonme42layer;
0170   }
0171 
0172   isi -= istart;  // remove earlier group(s)
0173   IndexType ichan = (isi - 1) % nchan + 1;
0174   IndexType ili = (isi - 1) / nchan + 1;
0175   ili += layerOffset;  // add appropriate offset for earlier group(s)
0176   if (ie != 1)
0177     ili += lastplusznonme42layer;  // add offset to -z endcap; ME42 doesn't need this.
0178 
0179   return std::pair<CSCDetId, IndexType>(detIdFromLayerIndex(ili), ichan);
0180 }
0181 
0182 std::pair<CSCDetId, CSCIndexer::IndexType> CSCIndexer::detIdFromChipIndex(IndexType ici) const {
0183   const LongIndexType lastnonme42 = 13608;      // chips in 2008 installed chambers
0184   const LongIndexType lastplusznonme42 = 6804;  // = 13608/2
0185   const LongIndexType firstme13 = 2161;         // First channel of ME13
0186   const LongIndexType lastme13 = 3024;          // Last channel of ME13
0187 
0188   const IndexType lastnonme42layer = 2808;
0189   const IndexType lastplusznonme42layer = 1404;  // = 2808/2
0190   const IndexType firstme13layer = 433;          // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
0191   const IndexType lastme13layer = 648;           // = 108*6
0192 
0193   // All chambers but ME13 have 5 chips/layer
0194   IndexType nchipPerLayer = 5;
0195 
0196   // Set endcap to +z. This should work for ME42 channels too, since we don't need to calculate its endcap explicitly.
0197   IndexType ie = 1;
0198 
0199   LongIndexType istart = 0;
0200   IndexType layerOffset = 0;
0201 
0202   if (ici <= lastnonme42) {
0203     // Chambers as of 2008 Installation
0204 
0205     if (ici > lastplusznonme42) {
0206       ie = 2;
0207       ici -= lastplusznonme42;
0208     }
0209 
0210     if (ici > lastme13) {  // after ME13
0211       istart = lastme13;
0212       layerOffset = lastme13layer;
0213     } else if (ici >= firstme13) {  // ME13
0214       istart = firstme13 - 1;
0215       layerOffset = firstme13layer - 1;
0216       nchipPerLayer = 4;
0217     }
0218   } else {
0219     // ME42 chambers
0220 
0221     istart = lastnonme42;
0222     layerOffset = lastnonme42layer;
0223   }
0224 
0225   ici -= istart;  // remove earlier group(s)
0226   IndexType ichip = (ici - 1) % nchipPerLayer + 1;
0227   IndexType ili = (ici - 1) / nchipPerLayer + 1;
0228   ili += layerOffset;  // add appropriate offset for earlier group(s)
0229   if (ie != 1)
0230     ili += lastplusznonme42layer;  // add offset to -z endcap; ME42 doesn't need this.
0231 
0232   return std::pair<CSCDetId, IndexType>(detIdFromLayerIndex(ili), ichip);
0233 }
0234 
0235 int CSCIndexer::dbIndex(const CSCDetId& id, int& channel) {
0236   int ec = id.endcap();
0237   int st = id.station();
0238   int rg = id.ring();
0239   int ch = id.chamber();
0240   int la = id.layer();
0241 
0242   // The channels of ME1A are channels 65-80 of ME11
0243   if (st == 1 && rg == 4) {
0244     rg = 1;
0245     if (channel <= 16)
0246       channel += 64;  // no trapping for any bizarreness
0247   }
0248   return ec * 100000 + st * 10000 + rg * 1000 + ch * 10 + la;
0249 }