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