Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:14

0001 #ifndef RECOLOCALTRACKER_SISTRIPZEROSUPPRESSION_SISTRIPCOMMONMODENOISESUBTRACTOR_H
0002 #define RECOLOCALTRACKER_SISTRIPZEROSUPPRESSION_SISTRIPCOMMONMODENOISESUBTRACTOR_H
0003 
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include <vector>
0006 #include <algorithm>
0007 #include <cstdint>
0008 
0009 class SiStripCommonModeNoiseSubtractor {
0010   friend class SiStripRawProcessingFactory;
0011 
0012 public:
0013   virtual ~SiStripCommonModeNoiseSubtractor(){};
0014   virtual void init(const edm::EventSetup& es){};
0015   virtual void subtract(uint32_t detId, uint16_t firstStrip, std::vector<int16_t>& digis) = 0;
0016   virtual void subtract(uint32_t detId, uint16_t firstStrip, std::vector<float>& digis) = 0;
0017 
0018   const std::vector<std::pair<short, float> >& getAPVsCM() const { return _vmedians; }
0019 
0020 protected:
0021   SiStripCommonModeNoiseSubtractor(){};
0022   template <typename T>
0023   float median(std::vector<T>&);
0024 
0025   std::vector<std::pair<short, float> > _vmedians;
0026 };
0027 
0028 template <typename T>
0029 inline float SiStripCommonModeNoiseSubtractor::median(std::vector<T>& sample) {
0030   typename std::vector<T>::iterator mid = sample.begin() + sample.size() / 2;
0031   std::nth_element(sample.begin(), mid, sample.end());
0032   if (sample.size() & 1)  //odd size
0033     return *mid;
0034   return (*std::max_element(sample.begin(), mid) + *mid) / 2.;
0035 }
0036 #endif