File indexing completed on 2023-03-17 10:42:12
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;
0008 const LongIndexType lastpluszme1a = 262656;
0009 const LongIndexType lastnonme42 = 217728;
0010 const LongIndexType lastplusznonme42 = 108864;
0011 const LongIndexType firstme13 = 34561;
0012 const LongIndexType lastme13 = 48384;
0013
0014 const IndexType lastnonme42layer = 2808;
0015 const IndexType lastplusznonme42layer = 1404;
0016 const IndexType firstme13layer = 433;
0017 const IndexType lastme13layer = 648;
0018
0019 bool me1a = false;
0020
0021
0022
0023
0024 IndexType nchan = 80;
0025
0026
0027 IndexType ie = 1;
0028
0029 LongIndexType istart = 0;
0030 IndexType layerOffset = 0;
0031
0032 if (isi <= lastnonme42) {
0033
0034
0035 if (isi > lastplusznonme42) {
0036 ie = 2;
0037 isi -= lastplusznonme42;
0038 }
0039 if (isi > lastme13)
0040 {
0041 istart = lastme13;
0042 layerOffset = lastme13layer;
0043 } else if (isi >= firstme13)
0044 {
0045 istart = firstme13 - 1;
0046 layerOffset = firstme13layer - 1;
0047 nchan = 64;
0048 }
0049 } else if (isi <= lastnonme1a)
0050 {
0051 istart = lastnonme42;
0052 layerOffset = lastnonme42layer;
0053
0054 } else
0055 {
0056 me1a = true;
0057 if (isi > lastpluszme1a)
0058 ie = 2;
0059 istart = lastnonme1a;
0060 nchan = 48;
0061
0062 }
0063
0064 isi -= istart;
0065 IndexType ichan = (isi - 1) % nchan + 1;
0066 IndexType ili = (isi - 1) / nchan + 1;
0067 ili += layerOffset;
0068 if (ie != 1)
0069 ili += lastplusznonme42layer;
0070
0071
0072 CSCDetId id = detIdFromLayerIndex(ili);
0073
0074
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;
0083 const LongIndexType lastpluszme1a = 16416;
0084 const LongIndexType lastnonme42 = 13608;
0085 const LongIndexType lastplusznonme42 = 6804;
0086 const LongIndexType firstme13 = 2161;
0087 const LongIndexType lastme13 = 3024;
0088
0089 const IndexType lastnonme42layer = 2808;
0090 const IndexType lastplusznonme42layer = 1404;
0091 const IndexType firstme13layer = 433;
0092 const IndexType lastme13layer = 648;
0093
0094 bool me1a = false;
0095
0096
0097 IndexType nchipPerLayer = 5;
0098
0099
0100
0101 IndexType ie = 1;
0102
0103 LongIndexType istart = 0;
0104 IndexType layerOffset = 0;
0105
0106 if (ici <= lastnonme42) {
0107
0108
0109 if (ici > lastplusznonme42) {
0110 ie = 2;
0111 ici -= lastplusznonme42;
0112 }
0113 if (ici > lastme13)
0114 {
0115 istart = lastme13;
0116 layerOffset = lastme13layer;
0117 } else if (ici >= firstme13)
0118 {
0119 istart = firstme13 - 1;
0120 layerOffset = firstme13layer - 1;
0121 nchipPerLayer = 4;
0122 }
0123 } else if (ici <= lastnonme1a)
0124 {
0125 istart = lastnonme42;
0126 layerOffset = lastnonme42layer;
0127
0128 } else
0129 {
0130 me1a = true;
0131 if (ici > lastpluszme1a)
0132 ie = 2;
0133 istart = lastnonme1a;
0134 nchipPerLayer = 3;
0135
0136 }
0137
0138 ici -= istart;
0139 IndexType ichip = (ici - 1) % nchipPerLayer + 1;
0140 IndexType ili = (ici - 1) / nchipPerLayer + 1;
0141 ili += layerOffset;
0142 if (ie != 1)
0143 ili += lastplusznonme42layer;
0144
0145
0146 CSCDetId id = detIdFromLayerIndex(ili);
0147
0148
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
0170
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
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
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
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
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 }