00001 #ifndef MuonDetId_CSCIndexer_h
00002 #define MuonDetId_CSCIndexer_h
00003
00039 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00040 #include <vector>
00041 #include <iosfwd>
00042 #include <utility>
00043
00044 class CSCIndexer {
00045
00046 public:
00047
00048
00049
00050 typedef uint16_t IndexType;
00051 typedef uint32_t LongIndexType;
00052
00053 CSCIndexer(){};
00054 ~CSCIndexer(){};
00055
00066 IndexType chamberIndex( const CSCDetId& id ) const {
00067 return chamberIndex( id.endcap(), id.station(), id.ring(), id.chamber() );
00068 }
00069
00080 IndexType layerIndex( const CSCDetId& id ) const {
00081 return layerIndex(id.endcap(), id.station(), id.ring(), id.chamber(), id.layer());
00082 }
00083
00088 IndexType startChamberIndexInEndcap(IndexType ie, IndexType is, IndexType ir) const {
00089 const IndexType nschin[24] = {1,37,73, 109,127,0, 163,181,0, 217,469,0,
00090 235,271,307, 343,361,0, 397,415,0, 451,505,0 };
00091 return nschin[(ie-1)*12 + (is-1)*3 + ir-1];
00092
00093 }
00094
00099 IndexType chamberIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic) const {
00100 return startChamberIndexInEndcap(ie,is,ir) + ic - 1;
00101 }
00102
00107 IndexType layerIndex(IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il) const {
00108 const IndexType layersInChamber = 6;
00109 return (chamberIndex(ie,is,ir,ic) - 1 ) * layersInChamber + il;
00110 }
00111
00117 IndexType ringsInStation( IndexType is ) const {
00118 const IndexType nrins[5] = {0,3,2,2,2};
00119 return nrins[is];
00120 }
00121
00127 IndexType chambersInRingOfStation(IndexType is, IndexType ir) const {
00128 IndexType nc = 36;
00129 if (is >1 && ir<2 ) nc = 18;
00130 return nc;
00131 }
00132
00142 IndexType stripChannelsPerLayer( IndexType is, IndexType ir ) const {
00143 const IndexType nSCinC[12] = { 80,80,64, 80,80,0, 80,80,0, 80,80,0 };
00144 return nSCinC[(is-1)*3 + ir - 1];
00145 }
00146
00155 LongIndexType stripChannelStart( IndexType ie, IndexType is, IndexType ir ) const {
00156
00157
00158
00159
00160
00161
00162 const LongIndexType nStart[24] = { 1,17281,34561, 48385,57025,0, 74305,82945,0, 100225,217729,0,
00163 108865,126145,143425, 157249,165889,0, 183169,191809,0, 209089,235009,0 };
00164 return nStart[(ie-1)*12 + (is-1)*3 + ir - 1];
00165 }
00166
00176 LongIndexType stripChannelIndex( IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType istrip ) const {
00177 return stripChannelStart(ie,is,ir)+( (ic-1)*6 + il - 1 )*stripChannelsPerLayer(is,ir) + (istrip-1);
00178 }
00179
00189 LongIndexType stripChannelIndex( const CSCDetId& id, IndexType istrip ) const {
00190 return stripChannelIndex(id.endcap(), id.station(), id.ring(), id.chamber(), id.layer(), istrip );
00191 }
00192
00202 IndexType chipsPerLayer( IndexType is, IndexType ir ) const {
00203 const IndexType nCinL[12] = { 5,5,4, 5,5,0, 5,5,0, 5,5,0 };
00204 return nCinL[(is-1)*3 + ir - 1];
00205 }
00206
00215 IndexType chipStart( IndexType ie, IndexType is, IndexType ir ) const {
00216
00217
00218
00219
00220
00221
00222 const IndexType nStart[24] = {1, 1081, 2161, 3025, 3565, 0, 4645, 5185, 0, 6265, 13609,0,
00223 6805, 7885, 8965, 9829, 10369,0, 11449, 11989, 0, 13069, 14689 ,0 };
00224
00225 return nStart[(ie-1)*12 + (is-1)*3 + ir - 1];
00226 }
00227
00237 IndexType chipIndex( IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType ichip ) const {
00238
00239 return chipStart(ie,is,ir)+( (ic-1)*6 + il - 1 )*chipsPerLayer(is,ir) + (ichip-1);
00240
00241 }
00242
00252 IndexType chipIndex( const CSCDetId& id, IndexType ichip ) const {
00253 return chipIndex(id.endcap(), id.station(), id.ring(), id.chamber(), id.layer(), ichip );
00254 }
00255
00266 IndexType chipIndex( IndexType istrip ) const {
00267 return (istrip-1)/16+1;
00268 }
00269
00278 IndexType hvSegmentsPerLayer( IndexType is, IndexType ir ) const {
00279 const IndexType nSinL[12] = { 1,3,3, 3,5,0, 3,5,0, 3,5,0 };
00280 return nSinL[(is-1)*3 + ir - 1];
00281 }
00282
00291 IndexType sectorsPerLayer( IndexType is, IndexType ir ) const {
00292 return chipsPerLayer(is,ir)*hvSegmentsPerLayer(is,ir);
00293 }
00294
00303 IndexType hvSegmentIndex(IndexType is, IndexType ir, IndexType iwire ) const {
00304
00305 IndexType hvSegment = 1;
00306
00307 if (is > 2 && ir == 1) {
00308 if ( iwire >= 33 && iwire <= 64 ) { hvSegment = 2; }
00309 else if ( iwire >= 65 && iwire <= 96 ) { hvSegment = 3; }
00310
00311 } else if (is > 1 && ir == 2) {
00312 if ( iwire >= 17 && iwire <= 28 ) { hvSegment = 2; }
00313 else if ( iwire >= 29 && iwire <= 40 ) { hvSegment = 3; }
00314 else if ( iwire >= 41 && iwire <= 52 ) { hvSegment = 4; }
00315 else if ( iwire >= 53 && iwire <= 64 ) { hvSegment = 5; }
00316
00317 } else if (is == 1 && ir == 2) {
00318 if ( iwire >= 25 && iwire <= 48 ) { hvSegment = 2; }
00319 else if ( iwire >= 49 && iwire <= 64 ) { hvSegment = 3; }
00320
00321 } else if (is == 1 && ir == 3) {
00322 if ( iwire >= 13 && iwire <= 22 ) { hvSegment = 2; }
00323 else if ( iwire >= 23 && iwire <= 32 ) { hvSegment = 3; }
00324
00325 } else if (is == 2 && ir == 1) {
00326 if ( iwire >= 45 && iwire <= 80 ) { hvSegment = 2; }
00327 else if ( iwire >= 81 && iwire <= 112) { hvSegment = 3; }
00328
00329 }
00330
00331 return hvSegment;
00332 }
00333
00342 IndexType sectorStart( IndexType ie, IndexType is, IndexType ir ) const {
00343
00344
00345
00346
00347
00348
00349
00350
00351 const IndexType nStart[24] = {1 ,1081 , 4321,
00352 6913 ,8533 , 0,
00353 13933,15553, 0,
00354 20953,45145, 0,
00355 22573,23653,26893,
00356 29485,31105 ,0,
00357 36505,38125, 0,
00358 43525,50545, 0};
00359 return nStart[(ie-1)*12 + (is-1)*3 + ir - 1];
00360 }
00361
00370 IndexType gasGainIndex( const CSCDetId& id, IndexType istrip, IndexType iwire ) const {
00371 return gasGainIndex(id.endcap(), id.station(), id.ring(), id.chamber(), id.layer(), istrip, iwire);
00372 }
00373
00383 IndexType gasGainIndex( IndexType ie, IndexType is, IndexType ir, IndexType ic, IndexType il, IndexType istrip, IndexType iwire ) const {
00384 IndexType ichip = this->chipIndex(istrip);
00385 IndexType ihvsegment = this->hvSegmentIndex(is,ir,iwire);
00386 return sectorStart(ie,is,ir)+( (ic-1)*6 + il - 1 )*sectorsPerLayer(is,ir) + (ihvsegment-1)*chipsPerLayer(is,ir) + (ichip-1);
00387 }
00388
00392 CSCDetId detIdFromLayerIndex( IndexType ili ) const;
00393 CSCDetId detIdFromChamberIndex( IndexType ici ) const;
00394 CSCDetId detIdFromChamberIndex_OLD( IndexType ici ) const;
00395 CSCDetId detIdFromChamberLabel( IndexType ie, IndexType icl ) const;
00396 std::pair<CSCDetId, IndexType> detIdFromStripChannelIndex( LongIndexType ichi ) const;
00397 std::pair<CSCDetId, IndexType> detIdFromChipIndex( IndexType ichi ) const;
00398
00399 IndexType chamberLabelFromChamberIndex( IndexType ) const;
00400
00408 int dbIndex(const CSCDetId & id, int & channel);
00409
00410 private:
00411 void fillChamberLabel() const;
00412
00413 mutable std::vector<IndexType> chamberLabel;
00414
00415
00416 };
00417
00418 #endif
00419
00420
00421
00422
00423
00424