File indexing completed on 2024-04-06 12:04:46
0001 #include <DataFormats/MuonDetId/interface/CSCIndexer.h>
0002 #include <iostream>
0003
0004 std::vector<CSCIndexer::IndexType> CSCIndexer::fillChamberLabel() {
0005
0006
0007
0008
0009 std::vector<IndexType> tChamberLabel;
0010
0011 tChamberLabel.resize(271);
0012 IndexType count = 0;
0013 tChamberLabel[count] = 0;
0014
0015 for (IndexType is = 1; is != 5; ++is) {
0016 IndexType irmax = ringsInStation(is);
0017 for (IndexType ir = 1; ir != irmax + 1; ++ir) {
0018 IndexType icmax = chambersInRingOfStation(is, ir);
0019 for (IndexType ic = 1; ic != icmax + 1; ++ic) {
0020 tChamberLabel[++count] = is * 1000 + ir * 100 + ic;
0021 }
0022 }
0023 }
0024 return tChamberLabel;
0025 }
0026
0027 const std::vector<CSCIndexer::IndexType>& CSCIndexer::chamberLabel() {
0028 static const auto s_chamberLabel = fillChamberLabel();
0029 return s_chamberLabel;
0030 }
0031
0032 CSCDetId CSCIndexer::detIdFromChamberIndex_OLD(IndexType ici) const {
0033
0034
0035
0036 IndexType ie = 1;
0037 if (ici > 234) {
0038 ie = 2;
0039 ici -= 234;
0040 }
0041
0042
0043
0044 const IndexType station[] = {0, 1, 1, 1, 2, 2, 3, 3, 4};
0045 const IndexType ring[] = {0, 1, 2, 3, 1, 2, 1, 2, 1};
0046
0047
0048 const IndexType prevs[] = {0, 0, 1, 1, 1, 2, 2, 3, 3};
0049 const IndexType prevr[] = {0, 0, 1, 2, 3, 1, 2, 1, 2};
0050
0051 IndexType is = 4;
0052 IndexType ir = 1;
0053 for (IndexType i = 2; i <= 8; ++i) {
0054 IndexType js = station[i];
0055 IndexType jr = ring[i];
0056
0057 if (ici < startChamberIndexInEndcap(ie, js, jr)) {
0058 is = prevs[i];
0059 ir = prevr[i];
0060 break;
0061 }
0062
0063 }
0064 IndexType ic = ici - startChamberIndexInEndcap(ie, is, ir) + 1;
0065
0066 return CSCDetId(ie, is, ir, ic);
0067 }
0068
0069 CSCDetId CSCIndexer::detIdFromChamberIndex(IndexType ici) const {
0070
0071
0072
0073 IndexType ie = 1;
0074 if (ici > 468) {
0075
0076 ici -= 234;
0077 if (ici > 270) {
0078 ie = 2;
0079 ici -= 36;
0080 }
0081 } else {
0082 if (ici > 234) {
0083 ie = 2;
0084 ici -= 234;
0085 }
0086 }
0087 IndexType label = chamberLabel()[ici];
0088 return detIdFromChamberLabel(ie, label);
0089 }
0090
0091 CSCIndexer::IndexType CSCIndexer::chamberLabelFromChamberIndex(IndexType ici) const {
0092
0093
0094
0095
0096
0097 if (ici > 468) {
0098
0099 ici -= 234;
0100 if (ici > 270) {
0101 ici -= 36;
0102 }
0103 } else {
0104 if (ici > 234) {
0105 ici -= 234;
0106 }
0107 }
0108 return chamberLabel()[ici];
0109 }
0110
0111 CSCDetId CSCIndexer::detIdFromChamberLabel(IndexType ie, IndexType label) const {
0112 IndexType is = label / 1000;
0113 label -= is * 1000;
0114 IndexType ir = label / 100;
0115 label -= ir * 100;
0116 IndexType ic = label;
0117
0118 return CSCDetId(ie, is, ir, ic);
0119 }
0120
0121 CSCDetId CSCIndexer::detIdFromLayerIndex(IndexType ili) const {
0122 IndexType il = (ili - 1) % 6 + 1;
0123 IndexType ici = (ili - 1) / 6 + 1;
0124 CSCDetId id = detIdFromChamberIndex(ici);
0125
0126 return CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), il);
0127 }
0128
0129 std::pair<CSCDetId, CSCIndexer::IndexType> CSCIndexer::detIdFromStripChannelIndex(LongIndexType isi) const {
0130 const LongIndexType lastnonme42 = 217728;
0131 const LongIndexType lastplusznonme42 = 108864;
0132 const LongIndexType firstme13 = 34561;
0133 const LongIndexType lastme13 = 48384;
0134
0135 const IndexType lastnonme42layer = 2808;
0136 const IndexType lastplusznonme42layer = 1404;
0137 const IndexType firstme13layer = 433;
0138 const IndexType lastme13layer = 648;
0139
0140
0141 IndexType nchan = 80;
0142
0143
0144 IndexType ie = 1;
0145
0146 LongIndexType istart = 0;
0147 IndexType layerOffset = 0;
0148
0149 if (isi <= lastnonme42) {
0150
0151
0152 if (isi > lastplusznonme42) {
0153 ie = 2;
0154 isi -= lastplusznonme42;
0155 }
0156
0157 if (isi > lastme13) {
0158 istart = lastme13;
0159 layerOffset = lastme13layer;
0160 } else if (isi >= firstme13) {
0161 istart = firstme13 - 1;
0162 layerOffset = firstme13layer - 1;
0163 nchan = 64;
0164 }
0165 } else {
0166
0167
0168 istart = lastnonme42;
0169 layerOffset = lastnonme42layer;
0170 }
0171
0172 isi -= istart;
0173 IndexType ichan = (isi - 1) % nchan + 1;
0174 IndexType ili = (isi - 1) / nchan + 1;
0175 ili += layerOffset;
0176 if (ie != 1)
0177 ili += lastplusznonme42layer;
0178
0179 return std::pair<CSCDetId, IndexType>(detIdFromLayerIndex(ili), ichan);
0180 }
0181
0182 std::pair<CSCDetId, CSCIndexer::IndexType> CSCIndexer::detIdFromChipIndex(IndexType ici) const {
0183 const LongIndexType lastnonme42 = 13608;
0184 const LongIndexType lastplusznonme42 = 6804;
0185 const LongIndexType firstme13 = 2161;
0186 const LongIndexType lastme13 = 3024;
0187
0188 const IndexType lastnonme42layer = 2808;
0189 const IndexType lastplusznonme42layer = 1404;
0190 const IndexType firstme13layer = 433;
0191 const IndexType lastme13layer = 648;
0192
0193
0194 IndexType nchipPerLayer = 5;
0195
0196
0197 IndexType ie = 1;
0198
0199 LongIndexType istart = 0;
0200 IndexType layerOffset = 0;
0201
0202 if (ici <= lastnonme42) {
0203
0204
0205 if (ici > lastplusznonme42) {
0206 ie = 2;
0207 ici -= lastplusznonme42;
0208 }
0209
0210 if (ici > lastme13) {
0211 istart = lastme13;
0212 layerOffset = lastme13layer;
0213 } else if (ici >= firstme13) {
0214 istart = firstme13 - 1;
0215 layerOffset = firstme13layer - 1;
0216 nchipPerLayer = 4;
0217 }
0218 } else {
0219
0220
0221 istart = lastnonme42;
0222 layerOffset = lastnonme42layer;
0223 }
0224
0225 ici -= istart;
0226 IndexType ichip = (ici - 1) % nchipPerLayer + 1;
0227 IndexType ili = (ici - 1) / nchipPerLayer + 1;
0228 ili += layerOffset;
0229 if (ie != 1)
0230 ili += lastplusznonme42layer;
0231
0232 return std::pair<CSCDetId, IndexType>(detIdFromLayerIndex(ili), ichip);
0233 }
0234
0235 int CSCIndexer::dbIndex(const CSCDetId& id, int& channel) {
0236 int ec = id.endcap();
0237 int st = id.station();
0238 int rg = id.ring();
0239 int ch = id.chamber();
0240 int la = id.layer();
0241
0242
0243 if (st == 1 && rg == 4) {
0244 rg = 1;
0245 if (channel <= 16)
0246 channel += 64;
0247 }
0248 return ec * 100000 + st * 10000 + rg * 1000 + ch * 10 + la;
0249 }