CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/CalibMuon/CSCCalibration/src/CSCIndexerPostls1.cc

Go to the documentation of this file.
00001 #include <CalibMuon/CSCCalibration/interface/CSCIndexerPostls1.h>
00002 
00003 
00004 CSCIndexerPostls1::~CSCIndexerPostls1() {}
00005 
00006 
00007 std::pair<CSCDetId, CSCIndexerBase::IndexType>  CSCIndexerPostls1::detIdFromStripChannelIndex( LongIndexType isi ) const
00008 {
00009   const LongIndexType lastnonme1a       = 252288; // channels with ME42 installed
00010   const LongIndexType lastpluszme1a     = 262656; // last unganged ME1a +z channel = 252288 + 10368
00011   const LongIndexType lastnonme42 = 217728; // channels in 2008 installed chambers
00012   const LongIndexType lastplusznonme42 = 108864; // = 217728/2
00013   const LongIndexType firstme13  = 34561; // First channel of ME13
00014   const LongIndexType lastme13   = 48384; // Last channel of ME13
00015 
00016   const IndexType lastnonme42layer = 2808;
00017   const IndexType lastplusznonme42layer = 1404; // = 2808/2
00018   const IndexType firstme13layer  = 433; // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
00019   const IndexType lastme13layer   = 648; // = 108*6
00020 
00021   bool me1a = false;
00022 
00023   // Most chambers (except ME13 & ME1a) have 80 channels index width allocated
00024   //   unganged ME1a have 48 channels
00025   //   ME13 have 64 channels
00026   IndexType nchan = 80;
00027 
00028   // Set endcap to +z initially
00029   IndexType ie = 1;
00030 
00031   LongIndexType istart = 0;
00032   IndexType layerOffset = 0;
00033 
00034   if ( isi <= lastnonme42 )
00035   {
00036     // Chambers as of 2008 Installation (ME11 keeps the same #of channels 80 allocated for it in the index)
00037     if ( isi > lastplusznonme42 )
00038     {
00039       ie = 2;
00040       isi -= lastplusznonme42;
00041     }
00042     if ( isi > lastme13 ) // after ME13
00043     {
00044       istart = lastme13;
00045       layerOffset = lastme13layer;
00046     }
00047     else if ( isi >= firstme13 ) // ME13
00048     {
00049       istart = firstme13 - 1;
00050       layerOffset = firstme13layer - 1;
00051       nchan = 64;
00052     }
00053   }
00054   else if ( isi <= lastnonme1a ) // ME42 chambers
00055   {
00056     istart = lastnonme42;
00057     layerOffset = lastnonme42layer;
00058     // don't care about ie, as ME42 stretch of indices is uniform
00059   }
00060   else // Unganged ME1a channels
00061   {
00062     me1a = true;
00063     if (isi > lastpluszme1a) ie = 2;
00064     istart = lastnonme1a;
00065     nchan = 48;
00066     // layerOffset stays 0, as we want to map them onto ME1b's layer indices
00067   }
00068 
00069   isi -= istart; // remove earlier group(s)
00070   IndexType ichan = (isi - 1)%nchan + 1;
00071   IndexType ili = (isi - 1)/nchan + 1;
00072   ili += layerOffset; // add appropriate offset for earlier group(s)
00073   if ( ie != 1 ) ili += lastplusznonme42layer; // add offset to -z endcap; ME42 doesn't need this.
00074 
00075   CSCDetId id = detIdFromLayerIndex(ili);
00076 
00077   // For unganged ME1a we need to turn this ME11 detid into an ME1a one
00078   if ( me1a ) id = CSCDetId( id.endcap(), 1, 4, id.chamber(), id.layer() );
00079 
00080   return std::make_pair(id, ichan);
00081 }
00082 
00083 
00084 std::pair<CSCDetId, CSCIndexerBase::IndexType>  CSCIndexerPostls1::detIdFromChipIndex( IndexType ici ) const
00085 {
00086   const LongIndexType lastnonme1a       = 15768; // chips in chambers with ME42 installed
00087   const LongIndexType lastpluszme1a     = 16416; // last unganged ME1a +z chip = 15768 + 648 = 16416
00088   const LongIndexType lastnonme42 = 13608; // chips in 2008 installed chambers
00089   const LongIndexType lastplusznonme42 = 6804; // = 13608/2
00090   const LongIndexType firstme13  = 2161; // First channel of ME13
00091   const LongIndexType lastme13   = 3024; // Last channel of ME13
00092 
00093   const IndexType lastnonme42layer = 2808;
00094   const IndexType lastplusznonme42layer = 1404; // = 2808/2
00095   const IndexType firstme13layer  = 433; // = 72*6 + 1 (ME13 chambers are 72-108 in range 1-234)
00096   const IndexType lastme13layer   = 648; // = 108*6
00097 
00098   bool me1a = false;
00099 
00100   // Most chambers (except ME13, ME1a) have 5 chips/layer
00101   IndexType nchipPerLayer = 5;
00102 
00103   // Set endcap to +z. This should work for ME42 channels too, since we don't need to calculate its endcap explicitly.
00104   IndexType ie = 1;
00105 
00106   LongIndexType istart = 0;
00107   IndexType layerOffset = 0;
00108 
00109   if ( ici <= lastnonme42 )
00110   {
00111     // Chambers as of 2008 Installation (ME11 keeps the same #of chips 5 allocated for it in the index)
00112     if ( ici > lastplusznonme42 )
00113     {
00114       ie = 2;
00115       ici -= lastplusznonme42;
00116     }
00117     if ( ici > lastme13 ) // after ME13
00118     {
00119       istart = lastme13;
00120       layerOffset = lastme13layer;
00121     }
00122     else if ( ici >= firstme13 ) // ME13
00123     {
00124       istart = firstme13 - 1;
00125       layerOffset = firstme13layer - 1;
00126       nchipPerLayer = 4;
00127     }
00128   }
00129   else if ( ici <= lastnonme1a ) // ME42 chambers
00130   {
00131     istart = lastnonme42;
00132     layerOffset = lastnonme42layer;
00133     // don't care about ie, as ME42 stratch of indices is uniform
00134   }
00135   else  // Unganged ME1a channels
00136   {
00137     me1a = true;
00138     if (ici > lastpluszme1a) ie = 2;
00139     istart = lastnonme1a;
00140     nchipPerLayer = 3;
00141     // layerOffset stays 0, as we want to map them onto ME1b's layer indices
00142   }
00143 
00144   ici -= istart; // remove earlier group(s)
00145   IndexType ichip = (ici - 1)%nchipPerLayer + 1;
00146   IndexType ili = (ici - 1)/nchipPerLayer + 1;
00147   ili += layerOffset; // add appropriate offset for earlier group(s)
00148   if ( ie != 1 ) ili += lastplusznonme42layer; // add offset to -z endcap; ME42 doesn't need this.
00149 
00150   CSCDetId id = detIdFromLayerIndex(ili);
00151 
00152   // For unganged ME1a we need to turn this ME11 detid into an ME1a one
00153   if ( me1a ) id = CSCDetId( id.endcap(), 1, 4, id.chamber(), id.layer() );
00154 
00155   return std::make_pair(id, ichip);
00156 }
00157 
00158 
00159 int CSCIndexerPostls1::dbIndex(const CSCDetId & id, int & channel) const
00160 {
00161   int ec = id.endcap();
00162   int st = id.station();
00163   int rg = id.ring();
00164   int ch = id.chamber();
00165   int la = id.layer();
00166 
00167   return ec*100000 + st*10000 + rg*1000 + ch*10 + la;
00168 }
00169 
00170 
00171 CSCIndexerBase::GasGainIndexType  CSCIndexerPostls1::detIdFromGasGainIndex( IndexType igg ) const
00172 {
00173   const int n_types = 20;
00174   const IndexType type_starts[n_types] =
00175     {1,  1081, 4321, 6913, 8533, 13933, 15553, 20953, 22573, 23653, 26893, 29485, 31105, 36505, 38125, 43525, 45145, 50545, 55945, 56593};
00176   //+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   +1/4   -1/4
00177 
00178   const int endcaps[n_types] =
00179     {1,  1,    1,    1,    1,    1,     1,     1,     2,     2,     2,     2,     2,     2,     2,     2,     1,     2,     1,     2};
00180   const int stations[n_types] =
00181     {1,  1,    1,    2,    2,    3,     3,     4,     1,     1,     1,     2,     2,     3,     3,     4,     4,     4,     1,     1};
00182   const int rings[n_types] =
00183     {1,  2,    3,    1,    2,    1,     2,     1,     1,     2,     3,     1,     2,     1,     2,     1,     2,     2,     4,     4};
00184 
00185   // determine chamber type
00186   std::vector<IndexType> v_type_starts(type_starts, type_starts + n_types);
00187   int type = int(std::upper_bound(v_type_starts.begin(), v_type_starts.end(), igg) -  v_type_starts.begin()) - 1;
00188 
00189   // determine factors for #HVsectors and #chips
00190   int sectors_per_layer = sectorsPerLayer(stations[type], rings[type]);
00191   int chips_per_layer = chipsPerLayer(stations[type], rings[type]);
00192 
00193   IndexType igg_chamber_etc = igg - type_starts[type] + 1;
00194 
00195   IndexType igg_chamber_and_layer = (igg_chamber_etc - 1) / sectors_per_layer + 1;
00196 
00197   // extract chamber & layer
00198   int chamber = (igg_chamber_and_layer - 1) / 6 + 1;
00199   int layer   = (igg_chamber_and_layer - 1) % 6 + 1;
00200 
00201   IndexType igg_hvseg_etc         = (igg_chamber_etc - 1) % sectors_per_layer + 1;
00202 
00203   // extract HVsegment and chip numbers
00204   IndexType hvsegment = (igg_hvseg_etc - 1) / chips_per_layer + 1;
00205   IndexType chip      = (igg_hvseg_etc - 1) % chips_per_layer + 1;
00206 
00207   CSCDetId id(endcaps[type], stations[type], rings[type], chamber, layer);
00208   return boost::make_tuple(id, hvsegment, chip);
00209 }