Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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