CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CalibMuon/CSCCalibration/src/CSCIndexerStartup.cc

Go to the documentation of this file.
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; // channels in 2008 installed chambers
00010   const LongIndexType lastplusznonme42 = 108864; // = 217728/2
00011   const LongIndexType firstme13  = 34561; // First channel of ME13
00012   const LongIndexType lastme13   = 48384; // Last channel of ME13
00013 
00014   const IndexType lastnonme42layer = 2808;
00015   const IndexType lastplusznonme42layer = 1404; // = 2808/2
00016   const IndexType firstme13layer  = 433; // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
00017   const IndexType lastme13layer   = 648; // = 108*6
00018 
00019   // All chambers but ME13 have 80 channels
00020   IndexType nchan = 80;
00021 
00022   // Set endcap to +z. This should work for ME42 channels too, since we don't need to calculate its endcap explicitly.
00023   IndexType ie = 1;
00024 
00025   LongIndexType istart = 0;
00026   IndexType layerOffset = 0;
00027 
00028   if ( isi <= lastnonme42 ) // Chambers as of 2008 Installation
00029   {
00030     if ( isi > lastplusznonme42 )
00031     {
00032       ie = 2;
00033       isi -= lastplusznonme42;
00034     }
00035     if ( isi > lastme13 ) // after ME13
00036     {
00037       istart = lastme13;
00038       layerOffset = lastme13layer;
00039     }
00040     else if ( isi >= firstme13 ) // ME13
00041     {
00042       istart = firstme13 - 1;
00043       layerOffset = firstme13layer - 1;
00044       nchan = 64;
00045     }
00046   }
00047   else // ME42 chambers
00048   {
00049     istart = lastnonme42;
00050     layerOffset = lastnonme42layer;
00051   }
00052 
00053   isi -= istart; // remove earlier group(s)
00054   IndexType ichan = (isi - 1)%nchan + 1;
00055   IndexType ili = (isi - 1)/nchan + 1;
00056   ili += layerOffset; // add appropriate offset for earlier group(s)
00057   if ( ie != 1 ) ili += lastplusznonme42layer; // add offset to -z endcap; ME42 doesn't need this.
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; // chips in 2008 installed chambers
00066   const LongIndexType lastplusznonme42 = 6804; // = 13608/2
00067   const LongIndexType firstme13  = 2161; // First channel of ME13
00068   const LongIndexType lastme13   = 3024; // Last channel of ME13
00069 
00070   const IndexType lastnonme42layer = 2808;
00071   const IndexType lastplusznonme42layer = 1404; // = 2808/2
00072   const IndexType firstme13layer  = 433; // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
00073   const IndexType lastme13layer   = 648; // = 108*6
00074 
00075   // All chambers but ME13 have 5 chips/layer
00076   IndexType nchipPerLayer = 5;
00077 
00078   // Set endcap to +z. This should work for ME42 channels too, since we don't need to calculate its endcap explicitly.
00079   IndexType ie = 1;
00080 
00081   LongIndexType istart = 0;
00082   IndexType layerOffset = 0;
00083 
00084   if ( ici <= lastnonme42 ) // Chambers as of 2008 Installation
00085   {
00086     if ( ici > lastplusznonme42 )
00087     {
00088       ie = 2;
00089       ici -= lastplusznonme42;
00090     }
00091     if ( ici > lastme13 ) // after ME13
00092     {
00093       istart = lastme13;
00094       layerOffset = lastme13layer;
00095     }
00096     else if ( ici >= firstme13 ) // ME13
00097     {
00098       istart = firstme13 - 1;
00099       layerOffset = firstme13layer - 1;
00100       nchipPerLayer = 4;
00101     }
00102   }
00103   else // ME42 chambers
00104   {
00105     istart = lastnonme42;
00106     layerOffset = lastnonme42layer;
00107   }
00108 
00109   ici -= istart; // remove earlier group(s)
00110   IndexType ichip = (ici - 1)%nchipPerLayer + 1;
00111   IndexType ili = (ici - 1)/nchipPerLayer + 1;
00112   ili += layerOffset; // add appropriate offset for earlier group(s)
00113   if ( ie != 1 ) ili += lastplusznonme42layer; // add offset to -z endcap; ME42 doesn't need this.
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   // The channels of ME1A are channels 65-80 of ME11
00128   if(st == 1 && rg == 4)
00129   {
00130     rg = 1;
00131     if(channel <= 16) channel += 64; // no trapping for any bizarreness
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   //+1/1 +1/2  +1/3  +2/1  +2/2  +3/1   +3/2   +4/1   -1/1   -1/2   -1/3   -2/1   -2/2   -3/1   -3/2   -4/1   +4/2   -4/2
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   // determine chamber type
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   // determine factors for #HVsectors and #chips
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   // extract chamber & layer
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   // extract HVsegment and chip numbers
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 }