CMS 3D CMS Logo

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 }
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
SiStripNoises::getNoiseFast
static float getNoiseFast(const uint16_t &strip, const Range &range)
Definition: SiStripNoises.h:68
SiStripBadStrip::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripBadStrip.cc:27
IteratedMedianCMNSubtractor::pairMedian
float pairMedian(std::vector< std::pair< float, float > > &sample)
Definition: IteratedMedianCMNSubtractor.cc:78
IteratedMedianCMNSubtractor::noiseToken_
edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > noiseToken_
Definition: IteratedMedianCMNSubtractor.h:34
simplePhotonAnalyzer_cfi.sample
sample
Definition: simplePhotonAnalyzer_cfi.py:12
SiStripCommonModeNoiseSubtractor::_vmedians
std::vector< std::pair< short, float > > _vmedians
Definition: SiStripCommonModeNoiseSubtractor.h:25
IteratedMedianCMNSubtractor::qualityToken_
edm::ESGetToken< SiStripQuality, SiStripQualityRcd > qualityToken_
Definition: IteratedMedianCMNSubtractor.h:35
IteratedMedianCMNSubtractor::qualityWatcher_
edm::ESWatcher< SiStripQualityRcd > qualityWatcher_
Definition: IteratedMedianCMNSubtractor.h:39
mathSSE::return
return((rh ^ lh) &mask)
SiStripNoises.h
SiStripNoises::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripNoises.cc:34
IteratedMedianCMNSubtractor::noiseWatcher_
edm::ESWatcher< SiStripNoisesRcd > noiseWatcher_
Definition: IteratedMedianCMNSubtractor.h:38
IteratedMedianCMNSubtractor::init
void init(const edm::EventSetup &es) override
Definition: IteratedMedianCMNSubtractor.cc:7
SiStripBadStrip::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripBadStrip.h:53
SiStripNoises::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
SiStripQuality::IsStripBad
bool IsStripBad(const uint32_t &detid, const short &strip) const
Definition: SiStripQuality.cc:623
IteratedMedianCMNSubtractor::subtract_
void subtract_(uint32_t detId, uint16_t firstAPV, std::vector< T > &digis)
Definition: IteratedMedianCMNSubtractor.cc:24
IteratedMedianCMNSubtractor::noiseHandle
const SiStripNoises * noiseHandle
Definition: IteratedMedianCMNSubtractor.h:36
IteratedMedianCMNSubtractor.h
sistrip::APV
Definition: ConstantsForGranularity.h:79
IteratedMedianCMNSubtractor::iterations_
int iterations_
Definition: IteratedMedianCMNSubtractor.h:33
IteratedMedianCMNSubtractor::cut_to_avoid_signal_
double cut_to_avoid_signal_
Definition: IteratedMedianCMNSubtractor.h:31
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
SiStripQuality.h
IteratedMedianCMNSubtractor::qualityHandle
const SiStripQuality * qualityHandle
Definition: IteratedMedianCMNSubtractor.h:37
IteratedMedianCMNSubtractor::subtract
void subtract(uint32_t detId, uint16_t firstAPV, std::vector< int16_t > &digis) override
Definition: IteratedMedianCMNSubtractor.cc:16
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
cuy.ii
ii
Definition: cuy.py:590