File indexing completed on 2023-03-17 10:42:12
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;
0008 const LongIndexType lastplusznonme42 = 108864;
0009 const LongIndexType firstme13 = 34561;
0010 const LongIndexType lastme13 = 48384;
0011
0012 const IndexType lastnonme42layer = 2808;
0013 const IndexType lastplusznonme42layer = 1404;
0014 const IndexType firstme13layer = 433;
0015 const IndexType lastme13layer = 648;
0016
0017
0018 IndexType nchan = 80;
0019
0020
0021
0022 IndexType ie = 1;
0023
0024 LongIndexType istart = 0;
0025 IndexType layerOffset = 0;
0026
0027 if (isi <= lastnonme42)
0028 {
0029 if (isi > lastplusznonme42) {
0030 ie = 2;
0031 isi -= lastplusznonme42;
0032 }
0033 if (isi > lastme13)
0034 {
0035 istart = lastme13;
0036 layerOffset = lastme13layer;
0037 } else if (isi >= firstme13)
0038 {
0039 istart = firstme13 - 1;
0040 layerOffset = firstme13layer - 1;
0041 nchan = 64;
0042 }
0043 } else
0044 {
0045 istart = lastnonme42;
0046 layerOffset = lastnonme42layer;
0047 }
0048
0049 isi -= istart;
0050 IndexType ichan = (isi - 1) % nchan + 1;
0051 IndexType ili = (isi - 1) / nchan + 1;
0052 ili += layerOffset;
0053 if (ie != 1)
0054 ili += lastplusznonme42layer;
0055
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;
0062 const LongIndexType lastplusznonme42 = 6804;
0063 const LongIndexType firstme13 = 2161;
0064 const LongIndexType lastme13 = 3024;
0065
0066 const IndexType lastnonme42layer = 2808;
0067 const IndexType lastplusznonme42layer = 1404;
0068 const IndexType firstme13layer = 433;
0069 const IndexType lastme13layer = 648;
0070
0071
0072 IndexType nchipPerLayer = 5;
0073
0074
0075
0076 IndexType ie = 1;
0077
0078 LongIndexType istart = 0;
0079 IndexType layerOffset = 0;
0080
0081 if (ici <= lastnonme42)
0082 {
0083 if (ici > lastplusznonme42) {
0084 ie = 2;
0085 ici -= lastplusznonme42;
0086 }
0087 if (ici > lastme13)
0088 {
0089 istart = lastme13;
0090 layerOffset = lastme13layer;
0091 } else if (ici >= firstme13)
0092 {
0093 istart = firstme13 - 1;
0094 layerOffset = firstme13layer - 1;
0095 nchipPerLayer = 4;
0096 }
0097 } else
0098 {
0099 istart = lastnonme42;
0100 layerOffset = lastnonme42layer;
0101 }
0102
0103 ici -= istart;
0104 IndexType ichip = (ici - 1) % nchipPerLayer + 1;
0105 IndexType ili = (ici - 1) / nchipPerLayer + 1;
0106 ili += layerOffset;
0107 if (ie != 1)
0108 ili += lastplusznonme42layer;
0109
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
0122 if (st == 1 && rg == 4) {
0123 rg = 1;
0124 if (channel <= 16)
0125 channel += 64;
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
0151
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
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
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
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
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 }