File indexing completed on 2024-04-06 11:58:22
0001 #include "CSCIndexerOldPostls1.h"
0002 #include <algorithm>
0003 #include <iostream>
0004
0005 void CSCIndexerOldPostls1::fillChamberLabel() const {
0006
0007
0008
0009
0010 chamberLabel.resize(271);
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;
0029
0030 if (is > 2 && ir == 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) {
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
0066
0067
0068 IndexType ie = 1;
0069 if (ici > 234) {
0070 ie = 2;
0071 ici -= 234;
0072 }
0073
0074
0075
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
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
0089 if (ici < startChamberIndexInEndcap(ie, js, jr)) {
0090 is = prevs[i];
0091 ir = prevr[i];
0092 break;
0093 }
0094
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
0103
0104
0105 IndexType ie = 1;
0106 if (ici > 468) {
0107
0108 ici -= 234;
0109 if (ici > 270) {
0110 ie = 2;
0111 ici -= 36;
0112 }
0113 } else {
0114 if (ici > 234) {
0115 ie = 2;
0116 ici -= 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
0127
0128
0129
0130
0131 if (ici > 468) {
0132
0133 ici -= 234;
0134 if (ici > 270) {
0135 ici -= 36;
0136 }
0137 } else {
0138 if (ici > 234) {
0139 ici -= 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;
0168 const LongIndexType lastpluszme1a = 262656;
0169 const LongIndexType lastnonme42 = 217728;
0170 const LongIndexType lastplusznonme42 = 108864;
0171 const LongIndexType firstme13 = 34561;
0172 const LongIndexType lastme13 = 48384;
0173
0174 const IndexType lastnonme42layer = 2808;
0175 const IndexType lastplusznonme42layer = 1404;
0176 const IndexType firstme13layer = 433;
0177 const IndexType lastme13layer = 648;
0178
0179 bool me1a = false;
0180
0181
0182
0183
0184 IndexType nchan = 80;
0185
0186
0187 IndexType ie = 1;
0188
0189 LongIndexType istart = 0;
0190 IndexType layerOffset = 0;
0191
0192 if (isi <= lastnonme42) {
0193
0194
0195
0196 if (isi > lastplusznonme42) {
0197 ie = 2;
0198 isi -= lastplusznonme42;
0199 }
0200
0201 if (isi > lastme13) {
0202 istart = lastme13;
0203 layerOffset = lastme13layer;
0204 } else if (isi >= firstme13) {
0205 istart = firstme13 - 1;
0206 layerOffset = firstme13layer - 1;
0207 nchan = 64;
0208 }
0209 } else if (isi <= lastnonme1a) {
0210
0211 istart = lastnonme42;
0212 layerOffset = lastnonme42layer;
0213
0214
0215 } else {
0216
0217 me1a = true;
0218 if (isi > lastpluszme1a)
0219 ie = 2;
0220 istart = lastnonme1a;
0221 nchan = 48;
0222
0223 }
0224
0225 isi -= istart;
0226 IndexType ichan = (isi - 1) % nchan + 1;
0227 IndexType ili = (isi - 1) / nchan + 1;
0228 ili += layerOffset;
0229 if (ie != 1)
0230 ili += lastplusznonme42layer;
0231
0232
0233 CSCDetId id = detIdFromLayerIndex(ili);
0234
0235
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;
0244 const LongIndexType lastpluszme1a = 16416;
0245 const LongIndexType lastnonme42 = 13608;
0246 const LongIndexType lastplusznonme42 = 6804;
0247 const LongIndexType firstme13 = 2161;
0248 const LongIndexType lastme13 = 3024;
0249
0250 const IndexType lastnonme42layer = 2808;
0251 const IndexType lastplusznonme42layer = 1404;
0252 const IndexType firstme13layer = 433;
0253 const IndexType lastme13layer = 648;
0254
0255 bool me1a = false;
0256
0257
0258 IndexType nchipPerLayer = 5;
0259
0260
0261
0262 IndexType ie = 1;
0263
0264 LongIndexType istart = 0;
0265 IndexType layerOffset = 0;
0266
0267 if (ici <= lastnonme42) {
0268
0269
0270
0271 if (ici > lastplusznonme42) {
0272 ie = 2;
0273 ici -= lastplusznonme42;
0274 }
0275
0276 if (ici > lastme13) {
0277 istart = lastme13;
0278 layerOffset = lastme13layer;
0279 } else if (ici >= firstme13) {
0280 istart = firstme13 - 1;
0281 layerOffset = firstme13layer - 1;
0282 nchipPerLayer = 4;
0283 }
0284 } else if (ici <= lastnonme1a) {
0285
0286 istart = lastnonme42;
0287 layerOffset = lastnonme42layer;
0288
0289
0290 } else {
0291
0292 me1a = true;
0293 if (ici > lastpluszme1a)
0294 ie = 2;
0295 istart = lastnonme1a;
0296 nchipPerLayer = 3;
0297
0298 }
0299
0300 ici -= istart;
0301 IndexType ichip = (ici - 1) % nchipPerLayer + 1;
0302 IndexType ili = (ici - 1) / nchipPerLayer + 1;
0303 ili += layerOffset;
0304 if (ie != 1)
0305 ili += lastplusznonme42layer;
0306
0307
0308 CSCDetId id = detIdFromLayerIndex(ili);
0309
0310
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
0322
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
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
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
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
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 }