Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CSCIndexerOldPostls1.h"
0002 #include <algorithm>
0003 #include <iostream>
0004 
0005 void CSCIndexerOldPostls1::fillChamberLabel() const {
0006   // Fill the member vector which permits decoding of the linear chamber index
0007   // Logically const since initializes cache only,
0008   // Beware that the ME42 indices 235-270 within this vector do NOT correspond
0009   // to their 'real' linear indices (which are 469-504 for +z)
0010   chamberLabel.resize(271);  // one more than #chambers per endcap. Includes ME42.
0011   IndexType count = 0;
0012   chamberLabel[count] = 0;
0013 
0014   for (IndexType is = 1; is != 5; ++is) {
0015     IndexType irmax = ringsInStation(is);
0016     for (IndexType ir = 1; ir != irmax + 1; ++ir) {
0017       IndexType icmax = chambersInRingOfStation(is, ir);
0018       for (IndexType ic = 1; ic != icmax + 1; ++ic) {
0019         chamberLabel[++count] = is * 1000 + ir * 100 + ic;
0020       }
0021     }
0022   }
0023 }
0024 
0025 CSCIndexerOldPostls1::IndexType CSCIndexerOldPostls1::hvSegmentIndex(IndexType is,
0026                                                                      IndexType ir,
0027                                                                      IndexType iwire) const {
0028   IndexType hvSegment = 1;  // There is only one HV segment in ME1/1
0029 
0030   if (is > 2 && ir == 1) {  // HV segments are the same in ME3/1 and ME4/1
0031     if (iwire >= 33 && iwire <= 64)
0032       hvSegment = 2;
0033     else if (iwire >= 65 && iwire <= 96)
0034       hvSegment = 3;
0035   } else if (is > 1 && ir == 2) {  // HV segments are the same in ME2/2, ME3/2, and ME4/2
0036     if (iwire >= 17 && iwire <= 28)
0037       hvSegment = 2;
0038     else if (iwire >= 29 && iwire <= 40)
0039       hvSegment = 3;
0040     else if (iwire >= 41 && iwire <= 52)
0041       hvSegment = 4;
0042     else if (iwire >= 53 && iwire <= 64)
0043       hvSegment = 5;
0044   } else if (is == 1 && ir == 2) {
0045     if (iwire >= 25 && iwire <= 48)
0046       hvSegment = 2;
0047     else if (iwire >= 49 && iwire <= 64)
0048       hvSegment = 3;
0049   } else if (is == 1 && ir == 3) {
0050     if (iwire >= 13 && iwire <= 22)
0051       hvSegment = 2;
0052     else if (iwire >= 23 && iwire <= 32)
0053       hvSegment = 3;
0054   } else if (is == 2 && ir == 1) {
0055     if (iwire >= 45 && iwire <= 80)
0056       hvSegment = 2;
0057     else if (iwire >= 81 && iwire <= 112)
0058       hvSegment = 3;
0059   }
0060 
0061   return hvSegment;
0062 }
0063 
0064 CSCDetId CSCIndexerOldPostls1::detIdFromChamberIndex_OLD(IndexType ici) const {
0065   // Will not work as is for ME42
0066   // ============================
0067 
0068   IndexType ie = 1;
0069   if (ici > 234) {
0070     ie = 2;
0071     ici -= 234;
0072   }
0073   // Now ici is in range 1-234 (assuming valid input in range 1-468)
0074 
0075   // MEij pairs...
0076   const IndexType station[] = {0, 1, 1, 1, 2, 2, 3, 3, 4};
0077   const IndexType ring[] = {0, 1, 2, 3, 1, 2, 1, 2, 1};
0078 
0079   // MEij preceding a given MEij matching linear index above
0080   const IndexType prevs[] = {0, 0, 1, 1, 1, 2, 2, 3, 3};
0081   const IndexType prevr[] = {0, 0, 1, 2, 3, 1, 2, 1, 2};
0082 
0083   IndexType is = 4;
0084   IndexType ir = 1;
0085   for (IndexType i = 2; i <= 8; ++i) {
0086     IndexType js = station[i];
0087     IndexType jr = ring[i];
0088     // if it's before start of MEjs/jr then it's in the previous MEis/ir
0089     if (ici < startChamberIndexInEndcap(ie, js, jr)) {
0090       is = prevs[i];
0091       ir = prevr[i];
0092       break;
0093     }
0094     // otherwise it's in ME41
0095   }
0096   IndexType ic = ici - startChamberIndexInEndcap(ie, is, ir) + 1;
0097 
0098   return CSCDetId(ie, is, ir, ic);
0099 }
0100 
0101 CSCDetId CSCIndexerOldPostls1::detIdFromChamberIndex(IndexType ici) const {
0102   // Expected range of input range argument is 1-540.
0103   // 1-468 for CSCs installed at 2008 start-up. 469-540 for ME42.
0104 
0105   IndexType ie = 1;
0106   if (ici > 468) {
0107     // ME42
0108     ici -= 234;       // now in range 235-306
0109     if (ici > 270) {  // -z
0110       ie = 2;
0111       ici -= 36;  // now in range 235-270
0112     }
0113   } else {            // in range 1-468
0114     if (ici > 234) {  // -z
0115       ie = 2;
0116       ici -= 234;  // now in range 1-234
0117     }
0118   }
0119   if (chamberLabel.empty())
0120     fillChamberLabel();
0121   IndexType label = chamberLabel[ici];
0122   return detIdFromChamberLabel(ie, label);
0123 }
0124 
0125 CSCIndexerOldPostls1::IndexType CSCIndexerOldPostls1::chamberLabelFromChamberIndex(IndexType ici) const {
0126   // This is just for cross-checking
0127 
0128   // Expected range of input range argument is 1-540.
0129   // 1-468 for CSCs installed at 2008 start-up. 469-540 for ME42.
0130 
0131   if (ici > 468) {
0132     // ME42
0133     ici -= 234;       // now in range 235-306
0134     if (ici > 270) {  // -z
0135       ici -= 36;      // now in range 235-270
0136     }
0137   } else {            // in range 1-468
0138     if (ici > 234) {  // -z
0139       ici -= 234;     // now in range 1-234
0140     }
0141   }
0142   if (chamberLabel.empty())
0143     fillChamberLabel();
0144   return chamberLabel[ici];
0145 }
0146 
0147 CSCDetId CSCIndexerOldPostls1::detIdFromChamberLabel(IndexType ie, IndexType label) const {
0148   IndexType is = label / 1000;
0149   label -= is * 1000;
0150   IndexType ir = label / 100;
0151   label -= ir * 100;
0152   IndexType ic = label;
0153 
0154   return CSCDetId(ie, is, ir, ic);
0155 }
0156 
0157 CSCDetId CSCIndexerOldPostls1::detIdFromLayerIndex(IndexType ili) const {
0158   IndexType il = (ili - 1) % 6 + 1;
0159   IndexType ici = (ili - 1) / 6 + 1;
0160   CSCDetId id = detIdFromChamberIndex(ici);
0161 
0162   return CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), il);
0163 }
0164 
0165 std::pair<CSCDetId, CSCIndexerOldPostls1::IndexType> CSCIndexerOldPostls1::detIdFromStripChannelIndex(
0166     LongIndexType isi) const {
0167   const LongIndexType lastnonme1a = 252288;       // channels with ME42 installed
0168   const LongIndexType lastpluszme1a = 262656;     // last unganged ME1a +z channel = 252288 + 10368
0169   const LongIndexType lastnonme42 = 217728;       // channels in 2008 installed chambers
0170   const LongIndexType lastplusznonme42 = 108864;  // = 217728/2
0171   const LongIndexType firstme13 = 34561;          // First channel of ME13
0172   const LongIndexType lastme13 = 48384;           // Last channel of ME13
0173 
0174   const IndexType lastnonme42layer = 2808;
0175   const IndexType lastplusznonme42layer = 1404;  // = 2808/2
0176   const IndexType firstme13layer = 433;          // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
0177   const IndexType lastme13layer = 648;           // = 108*6
0178 
0179   bool me1a = false;
0180 
0181   // Most chambers (except ME13 & ME1a) have 80 channels index width allocated
0182   //   unganged ME1a have 48 channels
0183   //   ME13 have 64 channels
0184   IndexType nchan = 80;
0185 
0186   // Set endcap to +z initially
0187   IndexType ie = 1;
0188 
0189   LongIndexType istart = 0;
0190   IndexType layerOffset = 0;
0191 
0192   if (isi <= lastnonme42) {
0193     // Chambers as of 2008 Installation (ME11 keeps the same #of channels 80
0194     // allocated for it in the index)
0195 
0196     if (isi > lastplusznonme42) {
0197       ie = 2;
0198       isi -= lastplusznonme42;
0199     }
0200 
0201     if (isi > lastme13) {  // after ME13
0202       istart = lastme13;
0203       layerOffset = lastme13layer;
0204     } else if (isi >= firstme13) {  // ME13
0205       istart = firstme13 - 1;
0206       layerOffset = firstme13layer - 1;
0207       nchan = 64;
0208     }
0209   } else if (isi <= lastnonme1a) {  // ME42 chambers
0210 
0211     istart = lastnonme42;
0212     layerOffset = lastnonme42layer;
0213 
0214     // don't care about ie, as ME42 stratch of indices is uniform
0215   } else {  // Unganged ME1a channels
0216 
0217     me1a = true;
0218     if (isi > lastpluszme1a)
0219       ie = 2;
0220     istart = lastnonme1a;
0221     nchan = 48;
0222     // layerOffset stays 0, as we want to map them onto ME1b's layer indices
0223   }
0224 
0225   isi -= istart;  // remove earlier group(s)
0226   IndexType ichan = (isi - 1) % nchan + 1;
0227   IndexType ili = (isi - 1) / nchan + 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   CSCDetId id = detIdFromLayerIndex(ili);
0234 
0235   // For unganged ME1a we need to turn this ME11 detid into an ME1a one
0236   if (me1a)
0237     id = CSCDetId(id.endcap(), 1, 4, id.chamber(), id.layer());
0238 
0239   return std::make_pair(id, ichan);
0240 }
0241 
0242 std::pair<CSCDetId, CSCIndexerOldPostls1::IndexType> CSCIndexerOldPostls1::detIdFromChipIndex(IndexType ici) const {
0243   const LongIndexType lastnonme1a = 15768;      // chips in chambers with ME42 installed
0244   const LongIndexType lastpluszme1a = 16416;    // last unganged ME1a +z chip = 15768 + 648 = 16416
0245   const LongIndexType lastnonme42 = 13608;      // chips in 2008 installed chambers
0246   const LongIndexType lastplusznonme42 = 6804;  // = 13608/2
0247   const LongIndexType firstme13 = 2161;         // First channel of ME13
0248   const LongIndexType lastme13 = 3024;          // Last channel of ME13
0249 
0250   const IndexType lastnonme42layer = 2808;
0251   const IndexType lastplusznonme42layer = 1404;  // = 2808/2
0252   const IndexType firstme13layer = 433;          // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
0253   const IndexType lastme13layer = 648;           // = 108*6
0254 
0255   bool me1a = false;
0256 
0257   // Most chambers (except ME13, ME1a) have 5 chips/layer
0258   IndexType nchipPerLayer = 5;
0259 
0260   // Set endcap to +z. This should work for ME42 channels too, since we don't
0261   // need to calculate its endcap explicitly.
0262   IndexType ie = 1;
0263 
0264   LongIndexType istart = 0;
0265   IndexType layerOffset = 0;
0266 
0267   if (ici <= lastnonme42) {
0268     // Chambers as of 2008 Installation (ME11 keeps the same #of chips 5
0269     // allocated for it in the index)
0270 
0271     if (ici > lastplusznonme42) {
0272       ie = 2;
0273       ici -= lastplusznonme42;
0274     }
0275 
0276     if (ici > lastme13) {  // after ME13
0277       istart = lastme13;
0278       layerOffset = lastme13layer;
0279     } else if (ici >= firstme13) {  // ME13
0280       istart = firstme13 - 1;
0281       layerOffset = firstme13layer - 1;
0282       nchipPerLayer = 4;
0283     }
0284   } else if (ici <= lastnonme1a) {  // ME42 chambers
0285 
0286     istart = lastnonme42;
0287     layerOffset = lastnonme42layer;
0288 
0289     // don't care about ie, as ME42 stratch of indices is uniform
0290   } else {  // Unganged ME1a channels
0291 
0292     me1a = true;
0293     if (ici > lastpluszme1a)
0294       ie = 2;
0295     istart = lastnonme1a;
0296     nchipPerLayer = 3;
0297     // layerOffset stays 0, as we want to map them onto ME1b's layer indices
0298   }
0299 
0300   ici -= istart;  // remove earlier group(s)
0301   IndexType ichip = (ici - 1) % nchipPerLayer + 1;
0302   IndexType ili = (ici - 1) / nchipPerLayer + 1;
0303   ili += layerOffset;  // add appropriate offset for earlier group(s)
0304   if (ie != 1)
0305     ili += lastplusznonme42layer;  // add offset to -z endcap; ME42 doesn't need
0306                                    // this.
0307 
0308   CSCDetId id = detIdFromLayerIndex(ili);
0309 
0310   // For unganged ME1a we need to turn this ME11 detid into an ME1a one
0311   if (me1a)
0312     id = CSCDetId(id.endcap(), 1, 4, id.chamber(), id.layer());
0313 
0314   return std::make_pair(id, ichip);
0315 }
0316 
0317 CSCIndexerOldPostls1::GasGainTuple CSCIndexerOldPostls1::detIdFromGasGainIndex(IndexType igg) const {
0318   const int n_types = 20;
0319   const IndexType type_starts[n_types] = {1,     1081,  4321,  6913,  8533,  13933, 15553, 20953, 22573, 23653,
0320                                           26893, 29485, 31105, 36505, 38125, 43525, 45145, 50545, 55945, 56593};
0321   //+1/1 +1/2  +1/3  +2/1  +2/2  +3/1   +3/2   +4/1   -1/1   -1/2   -1/3   -2/1
0322   //-2/2   -3/1   -3/2   -4/1   +4/2   -4/2   +1/4   -1/4
0323 
0324   const int endcaps[n_types] = {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2};
0325   const int stations[n_types] = {1, 1, 1, 2, 2, 3, 3, 4, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 1, 1};
0326   const int rings[n_types] = {1, 2, 3, 1, 2, 1, 2, 1, 1, 2, 3, 1, 2, 1, 2, 1, 2, 2, 4, 4};
0327 
0328   // determine chamber type
0329   std::vector<IndexType> v_type_starts(type_starts, type_starts + n_types);
0330   int type = int(std::upper_bound(v_type_starts.begin(), v_type_starts.end(), igg) - v_type_starts.begin()) - 1;
0331 
0332   // determine factors for #HVsectors and #chips
0333   int sectors_per_layer = sectorsPerLayer(stations[type], rings[type]);
0334   int chips_per_layer = chipsPerLayer(stations[type], rings[type]);
0335 
0336   IndexType igg_chamber_etc = igg - type_starts[type] + 1;
0337 
0338   IndexType igg_chamber_and_layer = (igg_chamber_etc - 1) / sectors_per_layer + 1;
0339 
0340   // extract chamber & layer
0341   int chamber = (igg_chamber_and_layer - 1) / 6 + 1;
0342   int layer = (igg_chamber_and_layer - 1) % 6 + 1;
0343 
0344   IndexType igg_hvseg_etc = (igg_chamber_etc - 1) % sectors_per_layer + 1;
0345 
0346   // extract HVsegment and chip numbers
0347   IndexType hvsegment = (igg_hvseg_etc - 1) / chips_per_layer + 1;
0348   IndexType chip = (igg_hvseg_etc - 1) % chips_per_layer + 1;
0349 
0350   CSCDetId id(endcaps[type], stations[type], rings[type], chamber, layer);
0351   return std::make_tuple(id, hvsegment, chip);
0352 }
0353 
0354 int CSCIndexerOldPostls1::dbIndex(const CSCDetId &id, int &channel) {
0355   int ec = id.endcap();
0356   int st = id.station();
0357   int rg = id.ring();
0358   int ch = id.chamber();
0359   int la = id.layer();
0360 
0361   return ec * 100000 + st * 10000 + rg * 1000 + ch * 10 + la;
0362 }