CMS 3D CMS Logo

SiStripMedianCommonModeNoiseSubtraction.cc

Go to the documentation of this file.
00001 #include "CommonTools/SiStripZeroSuppression/interface/SiStripMedianCommonModeNoiseSubtraction.h"
00002 #include <sstream>
00003 
00004 void SiStripMedianCommonModeNoiseSubtraction::subtract(const uint32_t& detId,std::vector<int16_t>& digis){
00005   
00006 #ifdef DEBUG_SiStripZeroSuppression_
00007   LogDebug("SiStripZeroSuppression") << "[SiStripMedianCommonModeNoiseSubtraction::subtract] digis.size()= " << digis.size();
00008 #endif
00009   std::vector<int16_t> APVdigis;
00010   std::vector<int16_t>::iterator fs;
00011   std::vector<int16_t>::iterator ls;
00012   float CM;
00013   APVdigis.reserve(128);
00014   int nAPV = digis.size()/128;
00015   std::vector<int16_t>::iterator mid = APVdigis.begin() + 64;
00016   
00017 #ifdef DEBUG_SiStripZeroSuppression_
00018   if (edm::isDebugEnabled())
00019     LogDebug("SiStripZeroSuppression") << "[SiStripMedianCommonModeNoiseSubtraction::subtract] DetId " << detId << " number of apvs: nAPV= " << nAPV;
00020 #endif
00021   for (int iAPV=0; iAPV<nAPV; iAPV++){
00022     APVdigis.clear(); //added verify
00023     fs = digis.begin()+iAPV*128;
00024     ls = digis.begin()+(iAPV+1)*128;
00025     APVdigis.insert(APVdigis.end(), fs, ls );
00026 
00028     // std::sort(APVdigis.begin(),APVdigis.end());
00029     // CM = (APVdigis[63]+APVdigis[64])/2.;
00033     std::nth_element(APVdigis.begin(), mid, APVdigis.end());
00034     std::vector<int16_t>::iterator i63 = std::max_element(APVdigis.begin(), mid);
00035     CM = (*mid + *i63)/2.;
00036 
00037 #ifdef DEBUG_SiStripZeroSuppression_
00038     std::stringstream ss;
00039     if (edm::isDebugEnabled())
00040       ss << "[SiStripMedianCommonModeNoiseSubtraction::subtract] DetId " << detId << " iApv= " <<iAPV << " CM= " << CM << std::endl;
00041 #endif    
00042 
00043     while (fs < ls) {
00044       *fs = (int16_t) (*fs-CM);
00045 #ifdef DEBUG_SiStripZeroSuppression_
00046       if (edm::isDebugEnabled())
00047         ss << "[SiStripMedianCommonModeNoiseSubtraction::subtract] DetId " << detId << " strip " << fs-digis.begin() << " adc CM subtr " << *fs << std::endl;
00048 #endif
00049       fs++;
00050     }
00051 #ifdef DEBUG_SiStripZeroSuppression_
00052     LogDebug("SiStripZeroSuppression") << ss.str().c_str();
00053 #endif
00054   }
00055 }
00056 

Generated on Tue Jun 9 17:26:02 2009 for CMSSW by  doxygen 1.5.4