CMS 3D CMS Logo

IteratedMedianCMNSubtractor.cc
Go to the documentation of this file.
2 
7 #include <cmath>
8 
10  uint32_t n_cache_id = es.get<SiStripNoisesRcd>().cacheIdentifier();
11  uint32_t q_cache_id = es.get<SiStripQualityRcd>().cacheIdentifier();
12 
13  if (n_cache_id != noise_cache_id) {
15  noise_cache_id = n_cache_id;
16  }
17  if (q_cache_id != quality_cache_id) {
19  quality_cache_id = q_cache_id;
20  }
21 }
22 
23 void IteratedMedianCMNSubtractor::subtract(uint32_t detId, uint16_t firstAPV, std::vector<int16_t>& digis) {
24  subtract_(detId, firstAPV, digis);
25 }
26 void IteratedMedianCMNSubtractor::subtract(uint32_t detId, uint16_t firstAPV, std::vector<float>& digis) {
27  subtract_(detId, firstAPV, digis);
28 }
29 
30 template <typename T>
31 inline void IteratedMedianCMNSubtractor::subtract_(uint32_t detId, uint16_t firstAPV, std::vector<T>& digis) {
32  SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detId);
33  SiStripQuality::Range detQualityRange = qualityHandle->getRange(detId);
34 
35  typename std::vector<T>::iterator fs, ls;
36  float offset = 0;
37  std::vector<std::pair<float, float> > subset;
38  subset.reserve(128);
39 
40  _vmedians.clear();
41 
42  uint16_t APV = firstAPV;
43  for (; APV < digis.size() / 128 + firstAPV; ++APV) {
44  subset.clear();
45  // fill subset vector with all good strips and their noises
46  for (uint16_t istrip = APV * 128; istrip < (APV + 1) * 128; ++istrip) {
47  if (!qualityHandle->IsStripBad(detQualityRange, istrip)) {
48  std::pair<float, float> pin((float)digis[istrip - firstAPV * 128],
49  (float)noiseHandle->getNoiseFast(istrip, detNoiseRange));
50  subset.push_back(pin);
51  }
52  }
53 
54  // caluate offset for all good strips (first iteration)
55  if (!subset.empty())
56  offset = pairMedian(subset);
57 
58  // for second, third... iterations, remove strips over threshold
59  // and recalculate offset on remaining strips
60  for (int ii = 0; ii < iterations_ - 1; ++ii) {
61  std::vector<std::pair<float, float> >::iterator si = subset.begin();
62  while (si != subset.end()) {
63  if (si->first - offset > cut_to_avoid_signal_ * si->second)
64  si = subset.erase(si);
65  else
66  ++si;
67  }
68  if (subset.empty())
69  break;
70  offset = pairMedian(subset);
71  }
72 
73  _vmedians.push_back(std::pair<short, float>(APV, offset));
74 
75  // remove offset
76  fs = digis.begin() + (APV - firstAPV) * 128;
77  ls = digis.begin() + (APV - firstAPV + 1) * 128;
78  while (fs < ls) {
79  *fs = static_cast<T>(*fs - offset);
80  fs++;
81  }
82  }
83 }
84 
85 inline float IteratedMedianCMNSubtractor::pairMedian(std::vector<std::pair<float, float> >& sample) {
86  std::vector<std::pair<float, float> >::iterator mid = sample.begin() + sample.size() / 2;
87  std::nth_element(sample.begin(), mid, sample.end());
88  if (sample.size() & 1) //odd size
89  return (*mid).first;
90  return ((*std::max_element(sample.begin(), mid)).first + (*mid).first) / 2.;
91 }
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:66
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:85
simplePhotonAnalyzer_cfi.sample
sample
Definition: simplePhotonAnalyzer_cfi.py:12
SiStripCommonModeNoiseSubtractor::_vmedians
std::vector< std::pair< short, float > > _vmedians
Definition: SiStripCommonModeNoiseSubtractor.h:25
mathSSE::return
return((rh ^ lh) &mask)
SiStripNoises.h
SiStripNoises::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripNoises.cc:34
SiStripNoisesRcd
Definition: SiStripCondDataRecords.h:40
IteratedMedianCMNSubtractor::init
void init(const edm::EventSetup &es) override
Definition: IteratedMedianCMNSubtractor.cc:9
SiStripBadStrip::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripBadStrip.h:53
IteratedMedianCMNSubtractor::qualityHandle
edm::ESHandle< SiStripQuality > qualityHandle
Definition: IteratedMedianCMNSubtractor.h:29
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
SiStripNoises::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
SiStripQualityRcd
Definition: SiStripDependentRecords.h:56
SiStripQuality::IsStripBad
bool IsStripBad(const uint32_t &detid, const short &strip) const
Definition: SiStripQuality.cc:628
IteratedMedianCMNSubtractor::subtract_
void subtract_(uint32_t detId, uint16_t firstAPV, std::vector< T > &digis)
Definition: IteratedMedianCMNSubtractor.cc:31
IteratedMedianCMNSubtractor.h
sistrip::APV
Definition: ConstantsForGranularity.h:79
IteratedMedianCMNSubtractor::iterations_
int iterations_
Definition: IteratedMedianCMNSubtractor.h:27
IteratedMedianCMNSubtractor::cut_to_avoid_signal_
double cut_to_avoid_signal_
Definition: IteratedMedianCMNSubtractor.h:25
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
SiStripQuality.h
SiStripQualityRcd.h
IteratedMedianCMNSubtractor::quality_cache_id
uint32_t quality_cache_id
Definition: IteratedMedianCMNSubtractor.h:30
SiStripNoisesRcd.h
IteratedMedianCMNSubtractor::subtract
void subtract(uint32_t detId, uint16_t firstAPV, std::vector< int16_t > &digis) override
Definition: IteratedMedianCMNSubtractor.cc:23
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
IteratedMedianCMNSubtractor::noise_cache_id
uint32_t noise_cache_id
Definition: IteratedMedianCMNSubtractor.h:30
IteratedMedianCMNSubtractor::noiseHandle
edm::ESHandle< SiStripNoises > noiseHandle
Definition: IteratedMedianCMNSubtractor.h:28
cuy.ii
ii
Definition: cuy.py:590