00001 #include <CalibMuon/CSCCalibration/interface/CSCIndexerPostls1.h>
00002
00003
00004 CSCIndexerPostls1::~CSCIndexerPostls1() {}
00005
00006
00007 std::pair<CSCDetId, CSCIndexerBase::IndexType> CSCIndexerPostls1::detIdFromStripChannelIndex( LongIndexType isi ) const
00008 {
00009 const LongIndexType lastnonme1a = 252288;
00010 const LongIndexType lastpluszme1a = 262656;
00011 const LongIndexType lastnonme42 = 217728;
00012 const LongIndexType lastplusznonme42 = 108864;
00013 const LongIndexType firstme13 = 34561;
00014 const LongIndexType lastme13 = 48384;
00015
00016 const IndexType lastnonme42layer = 2808;
00017 const IndexType lastplusznonme42layer = 1404;
00018 const IndexType firstme13layer = 433;
00019 const IndexType lastme13layer = 648;
00020
00021 bool me1a = false;
00022
00023
00024
00025
00026 IndexType nchan = 80;
00027
00028
00029 IndexType ie = 1;
00030
00031 LongIndexType istart = 0;
00032 IndexType layerOffset = 0;
00033
00034 if ( isi <= lastnonme42 )
00035 {
00036
00037 if ( isi > lastplusznonme42 )
00038 {
00039 ie = 2;
00040 isi -= lastplusznonme42;
00041 }
00042 if ( isi > lastme13 )
00043 {
00044 istart = lastme13;
00045 layerOffset = lastme13layer;
00046 }
00047 else if ( isi >= firstme13 )
00048 {
00049 istart = firstme13 - 1;
00050 layerOffset = firstme13layer - 1;
00051 nchan = 64;
00052 }
00053 }
00054 else if ( isi <= lastnonme1a )
00055 {
00056 istart = lastnonme42;
00057 layerOffset = lastnonme42layer;
00058
00059 }
00060 else
00061 {
00062 me1a = true;
00063 if (isi > lastpluszme1a) ie = 2;
00064 istart = lastnonme1a;
00065 nchan = 48;
00066
00067 }
00068
00069 isi -= istart;
00070 IndexType ichan = (isi - 1)%nchan + 1;
00071 IndexType ili = (isi - 1)/nchan + 1;
00072 ili += layerOffset;
00073 if ( ie != 1 ) ili += lastplusznonme42layer;
00074
00075 CSCDetId id = detIdFromLayerIndex(ili);
00076
00077
00078 if ( me1a ) id = CSCDetId( id.endcap(), 1, 4, id.chamber(), id.layer() );
00079
00080 return std::make_pair(id, ichan);
00081 }
00082
00083
00084 std::pair<CSCDetId, CSCIndexerBase::IndexType> CSCIndexerPostls1::detIdFromChipIndex( IndexType ici ) const
00085 {
00086 const LongIndexType lastnonme1a = 15768;
00087 const LongIndexType lastpluszme1a = 16416;
00088 const LongIndexType lastnonme42 = 13608;
00089 const LongIndexType lastplusznonme42 = 6804;
00090 const LongIndexType firstme13 = 2161;
00091 const LongIndexType lastme13 = 3024;
00092
00093 const IndexType lastnonme42layer = 2808;
00094 const IndexType lastplusznonme42layer = 1404;
00095 const IndexType firstme13layer = 433;
00096 const IndexType lastme13layer = 648;
00097
00098 bool me1a = false;
00099
00100
00101 IndexType nchipPerLayer = 5;
00102
00103
00104 IndexType ie = 1;
00105
00106 LongIndexType istart = 0;
00107 IndexType layerOffset = 0;
00108
00109 if ( ici <= lastnonme42 )
00110 {
00111
00112 if ( ici > lastplusznonme42 )
00113 {
00114 ie = 2;
00115 ici -= lastplusznonme42;
00116 }
00117 if ( ici > lastme13 )
00118 {
00119 istart = lastme13;
00120 layerOffset = lastme13layer;
00121 }
00122 else if ( ici >= firstme13 )
00123 {
00124 istart = firstme13 - 1;
00125 layerOffset = firstme13layer - 1;
00126 nchipPerLayer = 4;
00127 }
00128 }
00129 else if ( ici <= lastnonme1a )
00130 {
00131 istart = lastnonme42;
00132 layerOffset = lastnonme42layer;
00133
00134 }
00135 else
00136 {
00137 me1a = true;
00138 if (ici > lastpluszme1a) ie = 2;
00139 istart = lastnonme1a;
00140 nchipPerLayer = 3;
00141
00142 }
00143
00144 ici -= istart;
00145 IndexType ichip = (ici - 1)%nchipPerLayer + 1;
00146 IndexType ili = (ici - 1)/nchipPerLayer + 1;
00147 ili += layerOffset;
00148 if ( ie != 1 ) ili += lastplusznonme42layer;
00149
00150 CSCDetId id = detIdFromLayerIndex(ili);
00151
00152
00153 if ( me1a ) id = CSCDetId( id.endcap(), 1, 4, id.chamber(), id.layer() );
00154
00155 return std::make_pair(id, ichip);
00156 }
00157
00158
00159 int CSCIndexerPostls1::dbIndex(const CSCDetId & id, int & channel) const
00160 {
00161 int ec = id.endcap();
00162 int st = id.station();
00163 int rg = id.ring();
00164 int ch = id.chamber();
00165 int la = id.layer();
00166
00167 return ec*100000 + st*10000 + rg*1000 + ch*10 + la;
00168 }
00169
00170
00171 CSCIndexerBase::GasGainIndexType CSCIndexerPostls1::detIdFromGasGainIndex( IndexType igg ) const
00172 {
00173 const int n_types = 20;
00174 const IndexType type_starts[n_types] =
00175 {1, 1081, 4321, 6913, 8533, 13933, 15553, 20953, 22573, 23653, 26893, 29485, 31105, 36505, 38125, 43525, 45145, 50545, 55945, 56593};
00176
00177
00178 const int endcaps[n_types] =
00179 {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2};
00180 const int stations[n_types] =
00181 {1, 1, 1, 2, 2, 3, 3, 4, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 1, 1};
00182 const int rings[n_types] =
00183 {1, 2, 3, 1, 2, 1, 2, 1, 1, 2, 3, 1, 2, 1, 2, 1, 2, 2, 4, 4};
00184
00185
00186 std::vector<IndexType> v_type_starts(type_starts, type_starts + n_types);
00187 int type = int(std::upper_bound(v_type_starts.begin(), v_type_starts.end(), igg) - v_type_starts.begin()) - 1;
00188
00189
00190 int sectors_per_layer = sectorsPerLayer(stations[type], rings[type]);
00191 int chips_per_layer = chipsPerLayer(stations[type], rings[type]);
00192
00193 IndexType igg_chamber_etc = igg - type_starts[type] + 1;
00194
00195 IndexType igg_chamber_and_layer = (igg_chamber_etc - 1) / sectors_per_layer + 1;
00196
00197
00198 int chamber = (igg_chamber_and_layer - 1) / 6 + 1;
00199 int layer = (igg_chamber_and_layer - 1) % 6 + 1;
00200
00201 IndexType igg_hvseg_etc = (igg_chamber_etc - 1) % sectors_per_layer + 1;
00202
00203
00204 IndexType hvsegment = (igg_hvseg_etc - 1) / chips_per_layer + 1;
00205 IndexType chip = (igg_hvseg_etc - 1) % chips_per_layer + 1;
00206
00207 CSCDetId id(endcaps[type], stations[type], rings[type], chamber, layer);
00208 return boost::make_tuple(id, hvsegment, chip);
00209 }