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();
00023 fs = digis.begin()+iAPV*128;
00024 ls = digis.begin()+(iAPV+1)*128;
00025 APVdigis.insert(APVdigis.end(), fs, ls );
00026
00028
00029
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