CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLocalTracker/SiStripZeroSuppression/src/PercentileCMNSubtractor.cc

Go to the documentation of this file.
00001 #include "RecoLocalTracker/SiStripZeroSuppression/interface/PercentileCMNSubtractor.h"
00002 
00003 void PercentileCMNSubtractor::subtract(const uint32_t& detId,std::vector<int16_t>& digis) {subtract_(detId,digis);}
00004 void PercentileCMNSubtractor::subtract(const uint32_t& detId,std::vector<float>& digis) {subtract_(detId,digis);}
00005 
00006 template<typename T> 
00007 inline
00008 void PercentileCMNSubtractor::
00009 subtract_(const uint32_t& detId,std::vector<T>& digis){
00010   
00011   std::vector<T> tmp;  tmp.reserve(128);  
00012   typename std::vector<T>::iterator  
00013     strip( digis.begin() ), 
00014     end(   digis.end()   ),
00015     endAPV;
00016   
00017   _vmedians.clear();
00018 
00019   while( strip < end ) {
00020     endAPV = strip+128; tmp.clear();
00021     tmp.insert(tmp.end(),strip,endAPV);
00022     const float offset = percentile(tmp,percentile_);
00023 
00024     _vmedians.push_back(std::pair<short,float>((strip-digis.begin())/128,offset));
00025 
00026     while (strip < endAPV) {
00027       *strip = static_cast<T>(*strip-offset);
00028       strip++;
00029     }
00030 
00031   }
00032 }
00033 
00034 
00035 template<typename T>
00036 inline
00037 float PercentileCMNSubtractor::
00038 percentile( std::vector<T>& sample, double pct) {
00039   typename std::vector<T>::iterator mid = sample.begin() + int(sample.size()*pct/100.0);
00040   std::nth_element(sample.begin(), mid, sample.end());
00041   return *mid;
00042 } 
00043