CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IteratedMedianCMNSubtractor.cc
Go to the documentation of this file.
2 
5 #include <cmath>
6 
8  if (noiseWatcher_.check(es)) {
10  }
11  if (qualityWatcher_.check(es)) {
13  }
14 }
15 
16 void IteratedMedianCMNSubtractor::subtract(uint32_t detId, uint16_t firstAPV, std::vector<int16_t>& digis) {
17  subtract_(detId, firstAPV, digis);
18 }
19 void IteratedMedianCMNSubtractor::subtract(uint32_t detId, uint16_t firstAPV, std::vector<float>& digis) {
20  subtract_(detId, firstAPV, digis);
21 }
22 
23 template <typename T>
24 inline void IteratedMedianCMNSubtractor::subtract_(uint32_t detId, uint16_t firstAPV, std::vector<T>& digis) {
25  SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detId);
26  SiStripQuality::Range detQualityRange = qualityHandle->getRange(detId);
27 
28  typename std::vector<T>::iterator fs, ls;
29  float offset = 0;
30  std::vector<std::pair<float, float> > subset;
31  subset.reserve(128);
32 
33  _vmedians.clear();
34 
35  uint16_t APV = firstAPV;
36  for (; APV < digis.size() / 128 + firstAPV; ++APV) {
37  subset.clear();
38  // fill subset vector with all good strips and their noises
39  for (uint16_t istrip = APV * 128; istrip < (APV + 1) * 128; ++istrip) {
40  if (!qualityHandle->IsStripBad(detQualityRange, istrip)) {
41  std::pair<float, float> pin((float)digis[istrip - firstAPV * 128],
42  (float)noiseHandle->getNoiseFast(istrip, detNoiseRange));
43  subset.push_back(pin);
44  }
45  }
46 
47  // caluate offset for all good strips (first iteration)
48  if (!subset.empty())
49  offset = pairMedian(subset);
50 
51  // for second, third... iterations, remove strips over threshold
52  // and recalculate offset on remaining strips
53  for (int ii = 0; ii < iterations_ - 1; ++ii) {
54  std::vector<std::pair<float, float> >::iterator si = subset.begin();
55  while (si != subset.end()) {
56  if (si->first - offset > cut_to_avoid_signal_ * si->second)
57  si = subset.erase(si);
58  else
59  ++si;
60  }
61  if (subset.empty())
62  break;
63  offset = pairMedian(subset);
64  }
65 
66  _vmedians.push_back(std::pair<short, float>(APV, offset));
67 
68  // remove offset
69  fs = digis.begin() + (APV - firstAPV) * 128;
70  ls = digis.begin() + (APV - firstAPV + 1) * 128;
71  while (fs < ls) {
72  *fs = static_cast<T>(*fs - offset);
73  fs++;
74  }
75  }
76 }
77 
78 inline float IteratedMedianCMNSubtractor::pairMedian(std::vector<std::pair<float, float> >& sample) {
79  std::vector<std::pair<float, float> >::iterator mid = sample.begin() + sample.size() / 2;
80  std::nth_element(sample.begin(), mid, sample.end());
81  if (sample.size() & 1) //odd size
82  return (*mid).first;
83  return ((*std::max_element(sample.begin(), mid)).first + (*mid).first) / 2.;
84 }
float pairMedian(std::vector< std::pair< float, float > > &sample)
edm::ESGetToken< SiStripQuality, SiStripQualityRcd > qualityToken_
void init(const edm::EventSetup &es) override
bool IsStripBad(const uint32_t &detid, const short &strip) const
def ls
Definition: eostools.py:349
int ii
Definition: cuy.py:589
bool getData(T &iHolder) const
Definition: EventSetup.h:122
static float getNoiseFast(const uint16_t &strip, const Range &range)
Definition: SiStripNoises.h:68
void subtract(uint32_t detId, uint16_t firstAPV, std::vector< int16_t > &digis) override
void subtract_(uint32_t detId, uint16_t firstAPV, std::vector< T > &digis)
edm::ESWatcher< SiStripNoisesRcd > noiseWatcher_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ESWatcher< SiStripQualityRcd > qualityWatcher_
const Range getRange(const uint32_t detID) const
const Range getRange(const uint32_t detID) const
std::pair< ContainerIterator, ContainerIterator > Range
edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > noiseToken_
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
long double T
std::vector< std::pair< short, float > > _vmedians