Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:22

0001 #include <CalibMuon/CSCCalibration/interface/CSCIndexerPostls1.h>
0002 #include <algorithm>
0003 
0004 CSCIndexerPostls1::~CSCIndexerPostls1() {}
0005 
0006 std::pair<CSCDetId, CSCIndexerBase::IndexType> CSCIndexerPostls1::detIdFromStripChannelIndex(LongIndexType isi) const {
0007   const LongIndexType lastnonme1a = 252288;       // channels with ME42 installed
0008   const LongIndexType lastpluszme1a = 262656;     // last unganged ME1a +z channel = 252288 + 10368
0009   const LongIndexType lastnonme42 = 217728;       // channels in 2008 installed chambers
0010   const LongIndexType lastplusznonme42 = 108864;  // = 217728/2
0011   const LongIndexType firstme13 = 34561;          // First channel of ME13
0012   const LongIndexType lastme13 = 48384;           // Last channel of ME13
0013 
0014   const IndexType lastnonme42layer = 2808;
0015   const IndexType lastplusznonme42layer = 1404;  // = 2808/2
0016   const IndexType firstme13layer = 433;          // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
0017   const IndexType lastme13layer = 648;           // = 108*6
0018 
0019   bool me1a = false;
0020 
0021   // Most chambers (except ME13 & ME1a) have 80 channels index width allocated
0022   //   unganged ME1a have 48 channels
0023   //   ME13 have 64 channels
0024   IndexType nchan = 80;
0025 
0026   // Set endcap to +z initially
0027   IndexType ie = 1;
0028 
0029   LongIndexType istart = 0;
0030   IndexType layerOffset = 0;
0031 
0032   if (isi <= lastnonme42) {
0033     // Chambers as of 2008 Installation (ME11 keeps the same #of channels 80
0034     // allocated for it in the index)
0035     if (isi > lastplusznonme42) {
0036       ie = 2;
0037       isi -= lastplusznonme42;
0038     }
0039     if (isi > lastme13)  // after ME13
0040     {
0041       istart = lastme13;
0042       layerOffset = lastme13layer;
0043     } else if (isi >= firstme13)  // ME13
0044     {
0045       istart = firstme13 - 1;
0046       layerOffset = firstme13layer - 1;
0047       nchan = 64;
0048     }
0049   } else if (isi <= lastnonme1a)  // ME42 chambers
0050   {
0051     istart = lastnonme42;
0052     layerOffset = lastnonme42layer;
0053     // don't care about ie, as ME42 stretch of indices is uniform
0054   } else  // Unganged ME1a channels
0055   {
0056     me1a = true;
0057     if (isi > lastpluszme1a)
0058       ie = 2;
0059     istart = lastnonme1a;
0060     nchan = 48;
0061     // layerOffset stays 0, as we want to map them onto ME1b's layer indices
0062   }
0063 
0064   isi -= istart;  // remove earlier group(s)
0065   IndexType ichan = (isi - 1) % nchan + 1;
0066   IndexType ili = (isi - 1) / nchan + 1;
0067   ili += layerOffset;  // add appropriate offset for earlier group(s)
0068   if (ie != 1)
0069     ili += lastplusznonme42layer;  // add offset to -z endcap; ME42 doesn't need
0070                                    // this.
0071 
0072   CSCDetId id = detIdFromLayerIndex(ili);
0073 
0074   // For unganged ME1a we need to turn this ME11 detid into an ME1a one
0075   if (me1a)
0076     id = CSCDetId(id.endcap(), 1, 4, id.chamber(), id.layer());
0077 
0078   return std::make_pair(id, ichan);
0079 }
0080 
0081 std::pair<CSCDetId, CSCIndexerBase::IndexType> CSCIndexerPostls1::detIdFromChipIndex(IndexType ici) const {
0082   const LongIndexType lastnonme1a = 15768;      // chips in chambers with ME42 installed
0083   const LongIndexType lastpluszme1a = 16416;    // last unganged ME1a +z chip = 15768 + 648 = 16416
0084   const LongIndexType lastnonme42 = 13608;      // chips in 2008 installed chambers
0085   const LongIndexType lastplusznonme42 = 6804;  // = 13608/2
0086   const LongIndexType firstme13 = 2161;         // First channel of ME13
0087   const LongIndexType lastme13 = 3024;          // Last channel of ME13
0088 
0089   const IndexType lastnonme42layer = 2808;
0090   const IndexType lastplusznonme42layer = 1404;  // = 2808/2
0091   const IndexType firstme13layer = 433;          // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
0092   const IndexType lastme13layer = 648;           // = 108*6
0093 
0094   bool me1a = false;
0095 
0096   // Most chambers (except ME13, ME1a) have 5 chips/layer
0097   IndexType nchipPerLayer = 5;
0098 
0099   // Set endcap to +z. This should work for ME42 channels too, since we don't
0100   // need to calculate its endcap explicitly.
0101   IndexType ie = 1;
0102 
0103   LongIndexType istart = 0;
0104   IndexType layerOffset = 0;
0105 
0106   if (ici <= lastnonme42) {
0107     // Chambers as of 2008 Installation (ME11 keeps the same #of chips 5
0108     // allocated for it in the index)
0109     if (ici > lastplusznonme42) {
0110       ie = 2;
0111       ici -= lastplusznonme42;
0112     }
0113     if (ici > lastme13)  // after ME13
0114     {
0115       istart = lastme13;
0116       layerOffset = lastme13layer;
0117     } else if (ici >= firstme13)  // ME13
0118     {
0119       istart = firstme13 - 1;
0120       layerOffset = firstme13layer - 1;
0121       nchipPerLayer = 4;
0122     }
0123   } else if (ici <= lastnonme1a)  // ME42 chambers
0124   {
0125     istart = lastnonme42;
0126     layerOffset = lastnonme42layer;
0127     // don't care about ie, as ME42 stratch of indices is uniform
0128   } else  // Unganged ME1a channels
0129   {
0130     me1a = true;
0131     if (ici > lastpluszme1a)
0132       ie = 2;
0133     istart = lastnonme1a;
0134     nchipPerLayer = 3;
0135     // layerOffset stays 0, as we want to map them onto ME1b's layer indices
0136   }
0137 
0138   ici -= istart;  // remove earlier group(s)
0139   IndexType ichip = (ici - 1) % nchipPerLayer + 1;
0140   IndexType ili = (ici - 1) / nchipPerLayer + 1;
0141   ili += layerOffset;  // add appropriate offset for earlier group(s)
0142   if (ie != 1)
0143     ili += lastplusznonme42layer;  // add offset to -z endcap; ME42 doesn't need
0144                                    // this.
0145 
0146   CSCDetId id = detIdFromLayerIndex(ili);
0147 
0148   // For unganged ME1a we need to turn this ME11 detid into an ME1a one
0149   if (me1a)
0150     id = CSCDetId(id.endcap(), 1, 4, id.chamber(), id.layer());
0151 
0152   return std::make_pair(id, ichip);
0153 }
0154 
0155 int CSCIndexerPostls1::dbIndex(const CSCDetId &id, int &channel) const {
0156   int ec = id.endcap();
0157   int st = id.station();
0158   int rg = id.ring();
0159   int ch = id.chamber();
0160   int la = id.layer();
0161 
0162   return ec * 100000 + st * 10000 + rg * 1000 + ch * 10 + la;
0163 }
0164 
0165 CSCIndexerBase::GasGainIndexType CSCIndexerPostls1::detIdFromGasGainIndex(IndexType igg) const {
0166   const int n_types = 20;
0167   const IndexType type_starts[n_types] = {1,     1081,  4321,  6913,  8533,  13933, 15553, 20953, 22573, 23653,
0168                                           26893, 29485, 31105, 36505, 38125, 43525, 45145, 50545, 55945, 56593};
0169   //+1/1 +1/2  +1/3  +2/1  +2/2  +3/1   +3/2   +4/1   -1/1   -1/2   -1/3   -2/1
0170   //-2/2   -3/1   -3/2   -4/1   +4/2   -4/2   +1/4   -1/4
0171 
0172   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};
0173   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};
0174   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};
0175 
0176   // determine chamber type
0177   std::vector<IndexType> v_type_starts(type_starts, type_starts + n_types);
0178   int type = int(std::upper_bound(v_type_starts.begin(), v_type_starts.end(), igg) - v_type_starts.begin()) - 1;
0179 
0180   // determine factors for #HVsectors and #chips
0181   int sectors_per_layer = sectorsPerLayer(stations[type], rings[type]);
0182   int chips_per_layer = chipsPerLayer(stations[type], rings[type]);
0183 
0184   IndexType igg_chamber_etc = igg - type_starts[type] + 1;
0185 
0186   IndexType igg_chamber_and_layer = (igg_chamber_etc - 1) / sectors_per_layer + 1;
0187 
0188   // extract chamber & layer
0189   int chamber = (igg_chamber_and_layer - 1) / 6 + 1;
0190   int layer = (igg_chamber_and_layer - 1) % 6 + 1;
0191 
0192   IndexType igg_hvseg_etc = (igg_chamber_etc - 1) % sectors_per_layer + 1;
0193 
0194   // extract HVsegment and chip numbers
0195   IndexType hvsegment = (igg_hvseg_etc - 1) / chips_per_layer + 1;
0196   IndexType chip = (igg_hvseg_etc - 1) % chips_per_layer + 1;
0197 
0198   CSCDetId id(endcaps[type], stations[type], rings[type], chamber, layer);
0199   return std::make_tuple(id, hvsegment, chip);
0200 }