Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:31

0001 #include "RecoLocalTracker/SiStripZeroSuppression/interface/PercentileCMNSubtractor.h"
0002 
0003 void PercentileCMNSubtractor::subtract(uint32_t detId, uint16_t firstAPV, std::vector<int16_t>& digis) {
0004   subtract_(detId, firstAPV, digis);
0005 }
0006 void PercentileCMNSubtractor::subtract(uint32_t detId, uint16_t firstAPV, std::vector<float>& digis) {
0007   subtract_(detId, firstAPV, digis);
0008 }
0009 
0010 template <typename T>
0011 inline void PercentileCMNSubtractor::subtract_(uint32_t detId, uint16_t firstAPV, std::vector<T>& digis) {
0012   std::vector<T> tmp;
0013   tmp.reserve(128);
0014   typename std::vector<T>::iterator strip(digis.begin()), end(digis.end()), endAPV;
0015 
0016   _vmedians.clear();
0017 
0018   while (strip < end) {
0019     endAPV = strip + 128;
0020     tmp.clear();
0021     tmp.insert(tmp.end(), strip, endAPV);
0022     const float offset = percentile(tmp, percentile_);
0023 
0024     _vmedians.push_back(std::pair<short, float>((strip - digis.begin()) / 128 + firstAPV, offset));
0025 
0026     while (strip < endAPV) {
0027       *strip = static_cast<T>(*strip - offset);
0028       strip++;
0029     }
0030   }
0031 }
0032 
0033 template <typename T>
0034 inline float PercentileCMNSubtractor::percentile(std::vector<T>& sample, double pct) {
0035   typename std::vector<T>::iterator mid = sample.begin() + int(sample.size() * pct / 100.0);
0036   std::nth_element(sample.begin(), mid, sample.end());
0037   return *mid;
0038 }