CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DataFormats/MuonDetId/interface/CSCIndexer.h

Go to the documentation of this file.
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>  // for pair
00043 
00044 class CSCIndexer {
00045 
00046 public:
00047 
00048   //  typedef unsigned short int IndexType;
00049   //  typedef unsigned       int LongIndexType;
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; // -1 so start index _is_ 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}; // rings per station
00119       return nrins[is];
00120    }
00121 
00127    IndexType chambersInRingOfStation(IndexType is, IndexType ir) const {
00128       IndexType nc = 36; // most rings have 36 chambers
00129       if (is >1 && ir<2 ) nc = 18; // but 21, 31, 41 have 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      // These are in the ranges 1-217728 (CSCs 2008) and 217729-252288 (ME42).
00158      // There are 1-108884 channels per endcap (CSCs 2008) and 17280 channels per endcap (ME42).
00159      // Start of -z channels (CSCs 2008) is 108864 + 1 = 108865
00160      // Start of +z (ME42) is 217728 + 1 = 217729
00161      // Start of -z (ME42) is 217728 + 1 + 17280 = 235009
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      // These are in the ranges 1-13608 (CSCs 2008) and 13609-15768 (ME42).
00218      // There are 1-6804 chips per endcap (CSCs 2008) and 1080 channels per endcap (ME42).
00219      // Start of -z channels (CSCs 2008) is 6804 + 1 = 6805
00220      // Start of +z (ME42) is 13608 + 1 = 13609
00221      // Start of -z (ME42) is 13608 + 1 + 1080 = 14689
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      //printf("ME%d/%d/%d/%d layer %d  chip %d chipindex %d\n",ie,is,ir,ic,il,ichip,chipStart(ie,is,ir)+( (ic-1)*6 + il - 1 )*chipsPerLayer(is,ir) + (ichip-1));
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;   // There is only one HV segment in ME1/1
00306      
00307     if (is > 2 && ir == 1) {        // HV segments are the same in ME3/1 and ME4/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) { // HV segments are the same in ME2/2, ME3/2, and ME4/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     // There are 36 chambers * 6 layers * 5 CFEB's * 1 HV segment = 1080 gas-gain sectors in ME1/1
00344     // There are 36*6*5*3 = 3240 gas-gain sectors in ME1/2
00345     // There are 36*6*4*3 = 2592 gas-gain sectors in ME1/3
00346     // There are 18*6*5*3 = 1620 gas-gain sectors in ME[2-4]/1
00347     // There are 36*6*5*5 = 5400 gas-gain sectors in ME[2-4]/2
00348     // Start of -z channels (CSCs 2008) is 22572 + 1 = 22573
00349     // Start of +z (ME42) is 45144 + 1 = 45145
00350     // Start of -z (ME42) is 45144 + 1 + 5400 = 50545
00351     const IndexType nStart[24] = {1    ,1081 , 4321,   //ME+1/1,ME+1/2,ME+1/3
00352                                   6913 ,8533 ,    0,   //ME+2/1,ME+2/2,ME+2/3
00353                                   13933,15553,    0,   //ME+3/1,ME+3/2,ME+3/3
00354                                   20953,45145,    0,   //ME+4/1,ME+4/2,ME+4/3 (note, ME+4/2 index follows ME-4/1...)
00355                                   22573,23653,26893,   //ME-1/1,ME-1/2,ME-1/3
00356                                   29485,31105    ,0,   //ME-2/1,ME-2/2,ME-2/3
00357                                   36505,38125,    0,   //ME-3/1,ME-3/2,ME-3/3
00358                                   43525,50545,    0};  //ME-4/1,ME-4/2,ME-4/3 (note, ME-4/2 index follows ME+4/2...)                                   
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; // just for cross-checks
00400 
00408   int dbIndex(const CSCDetId & id, int & channel);
00409 
00410 private:
00411   void fillChamberLabel() const; // const so it can be called in const function detIdFromChamberIndex
00412 
00413   mutable std::vector<IndexType> chamberLabel; // mutable so can be filled by fillChamberLabel
00414 
00415 
00416 };
00417 
00418 #endif
00419 
00420 
00421 
00422 
00423 
00424