Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:35

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