00001 #include <DataFormats/MuonDetId/interface/CSCIndexer.h>
00002 #include <iostream>
00003
00004 void CSCIndexer::fillChamberLabel() const {
00005
00006
00007
00008
00009 chamberLabel.resize( 271 );
00010 IndexType count = 0;
00011 chamberLabel[count] = 0;
00012
00013 for ( IndexType is = 1 ; is != 5; ++is ) {
00014 IndexType irmax = ringsInStation(is);
00015 for ( IndexType ir = 1; ir != irmax+1; ++ir ) {
00016 IndexType icmax = chambersInRingOfStation(is, ir);
00017 for ( IndexType ic = 1; ic != icmax+1; ++ic ) {
00018 chamberLabel[ ++count ] = is*1000 + ir*100 + ic ;
00019 }
00020 }
00021 }
00022 }
00023
00024 CSCDetId CSCIndexer::detIdFromChamberIndex_OLD( IndexType ici ) const {
00025
00026
00027
00028
00029 IndexType ie = 1;
00030 if (ici > 234 ) {
00031 ie = 2;
00032 ici -= 234;
00033 }
00034
00035
00036
00037 const IndexType station[] = {0,1,1,1,2,2,3,3,4};
00038 const IndexType ring[] = {0,1,2,3,1,2,1,2,1};
00039
00040
00041 const IndexType prevs[] = {0,0,1,1,1,2,2,3,3};
00042 const IndexType prevr[] = {0,0,1,2,3,1,2,1,2};
00043
00044 IndexType is = 4;
00045 IndexType ir = 1;
00046 for ( IndexType i = 2; i<=8; ++i) {
00047 IndexType js = station[i];
00048 IndexType jr = ring[i];
00049
00050 if ( ici < startChamberIndexInEndcap(ie,js,jr) ) {
00051 is = prevs[i];
00052 ir = prevr[i];
00053 break;
00054 }
00055
00056 }
00057 IndexType ic = ici - startChamberIndexInEndcap(ie,is,ir) + 1;
00058
00059 return CSCDetId( ie, is, ir, ic );
00060 }
00061
00062 CSCDetId CSCIndexer::detIdFromChamberIndex( IndexType ici ) const {
00063
00064
00065
00066 IndexType ie = 1;
00067 if ( ici > 468 ) {
00068
00069 ici -= 234;
00070 if ( ici > 270 ) {
00071 ie = 2;
00072 ici -= 36;
00073 }
00074 }
00075 else {
00076 if ( ici > 234 ) {
00077 ie = 2;
00078 ici -= 234;
00079 }
00080 }
00081 if (chamberLabel.empty()) fillChamberLabel();
00082 IndexType label = chamberLabel[ici];
00083 return detIdFromChamberLabel( ie, label );
00084 }
00085
00086 CSCIndexer::IndexType CSCIndexer::chamberLabelFromChamberIndex( IndexType ici ) const {
00087
00088
00089
00090
00091
00092 if ( ici > 468 ) {
00093
00094 ici -= 234;
00095 if ( ici > 270 ) {
00096 ici -= 36;
00097 }
00098 }
00099 else {
00100 if ( ici > 234 ) {
00101 ici -= 234;
00102 }
00103 }
00104 if (chamberLabel.empty()) fillChamberLabel();
00105 return chamberLabel[ici];
00106
00107 }
00108
00109 CSCDetId CSCIndexer::detIdFromChamberLabel( IndexType ie, IndexType label ) const {
00110
00111 IndexType is = label/1000;
00112 label -= is*1000;
00113 IndexType ir = label/100;
00114 label -= ir*100;
00115 IndexType ic = label;
00116
00117 return CSCDetId( ie, is, ir, ic );
00118 }
00119
00120 CSCDetId CSCIndexer::detIdFromLayerIndex( IndexType ili ) const {
00121
00122 IndexType il = (ili-1)%6 + 1;
00123 IndexType ici = (ili-1)/6 + 1;
00124 CSCDetId id = detIdFromChamberIndex( ici );
00125
00126 return CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), il);
00127 }
00128
00129 std::pair<CSCDetId, CSCIndexer::IndexType> CSCIndexer::detIdFromStripChannelIndex( LongIndexType isi ) const {
00130
00131 const LongIndexType lastnonme42 = 217728;
00132 const LongIndexType lastplusznonme42 = 108864;
00133 const LongIndexType firstme13 = 34561;
00134 const LongIndexType lastme13 = 48384;
00135
00136 const IndexType lastnonme42layer = 2808;
00137 const IndexType lastplusznonme42layer = 1404;
00138 const IndexType firstme13layer = 433;
00139 const IndexType lastme13layer = 648;
00140
00141
00142 IndexType nchan = 80;
00143
00144
00145 IndexType ie = 1;
00146
00147 LongIndexType istart = 0;
00148 IndexType layerOffset = 0;
00149
00150 if ( isi <= lastnonme42 ) {
00151
00152
00153 if ( isi > lastplusznonme42 ) {
00154 ie = 2;
00155 isi -= lastplusznonme42;
00156 }
00157
00158 if ( isi > lastme13 ) {
00159 istart = lastme13;
00160 layerOffset = lastme13layer;
00161 }
00162 else if ( isi >= firstme13 ) {
00163 istart = firstme13 - 1;
00164 layerOffset = firstme13layer - 1;
00165 nchan = 64;
00166 }
00167 }
00168 else {
00169
00170
00171 istart = lastnonme42;
00172 layerOffset = lastnonme42layer;
00173 }
00174
00175 isi -= istart;
00176 IndexType ichan = (isi-1)%nchan + 1;
00177 IndexType ili = (isi-1)/nchan + 1;
00178 ili += layerOffset;
00179 if ( ie != 1 ) ili+= lastplusznonme42layer;
00180
00181 return std::pair<CSCDetId, IndexType>(detIdFromLayerIndex(ili), ichan);
00182 }
00183
00184
00185 std::pair<CSCDetId, CSCIndexer::IndexType> CSCIndexer::detIdFromChipIndex( IndexType ici ) const {
00186
00187 const LongIndexType lastnonme42 = 13608;
00188 const LongIndexType lastplusznonme42 = 6804;
00189 const LongIndexType firstme13 = 2161;
00190 const LongIndexType lastme13 = 3024;
00191
00192 const IndexType lastnonme42layer = 2808;
00193 const IndexType lastplusznonme42layer = 1404;
00194 const IndexType firstme13layer = 433;
00195 const IndexType lastme13layer = 648;
00196
00197
00198 IndexType nchipPerLayer = 5;
00199
00200
00201 IndexType ie = 1;
00202
00203 LongIndexType istart = 0;
00204 IndexType layerOffset = 0;
00205
00206 if ( ici <= lastnonme42 ) {
00207
00208
00209 if ( ici > lastplusznonme42 ) {
00210 ie = 2;
00211 ici -= lastplusznonme42;
00212 }
00213
00214 if ( ici > lastme13 ) {
00215 istart = lastme13;
00216 layerOffset = lastme13layer;
00217 }
00218 else if ( ici >= firstme13 ) {
00219 istart = firstme13 - 1;
00220 layerOffset = firstme13layer - 1;
00221 nchipPerLayer = 4;
00222 }
00223 }
00224 else {
00225
00226
00227 istart = lastnonme42;
00228 layerOffset = lastnonme42layer;
00229 }
00230
00231 ici -= istart;
00232 IndexType ichip = (ici-1)%nchipPerLayer + 1;
00233 IndexType ili = (ici-1)/nchipPerLayer + 1;
00234 ili += layerOffset;
00235 if ( ie != 1 ) ili+= lastplusznonme42layer;
00236
00237 return std::pair<CSCDetId, IndexType>(detIdFromLayerIndex(ili), ichip);
00238 }
00239
00240 int CSCIndexer::dbIndex(const CSCDetId & id, int & channel)
00241 {
00242 int ec = id.endcap();
00243 int st = id.station();
00244 int rg = id.ring();
00245 int ch = id.chamber();
00246 int la = id.layer();
00247
00248
00249 if(st == 1 && rg == 4)
00250 {
00251 rg = 1;
00252 if(channel <= 16) channel += 64;
00253 }
00254 return ec*100000 + st*10000 + rg*1000 + ch*10 + la;
00255 }