CMS 3D CMS Logo

SlidingPeakFinder.h
Go to the documentation of this file.
1 #ifndef RecoTracker_PixelLowPtUtilities_SlidingPeakFinder_h
2 #define RecoTracker_PixelLowPtUtilities_SlidingPeakFinder_h
3 
4 #include <algorithm>
5 #include <vector>
6 #include <cmath>
7 #include <cstdint>
10 
12 public:
13  SlidingPeakFinder(unsigned int size) : size_(size), half_((size + 1) / 2) {}
14 
15  template <typename Test>
16  bool apply(const uint8_t *x,
17  const uint8_t *begin,
18  const uint8_t *end,
19  const Test &test,
20  bool verbose = false,
21  int firststrip = 0) {
22  const uint8_t *ileft = (x != begin) ? std::min_element(x - 1, x + half_) : begin - 1;
23  const uint8_t *iright = ((x + size_) < end) ? std::min_element(x + half_, std::min(x + size_ + 1, end)) : end;
24  uint8_t left = (ileft < begin ? 0 : *ileft);
25  uint8_t right = (iright >= end ? 0 : *iright);
26  uint8_t center = *std::max_element(x, std::min(x + size_, end));
27  uint8_t maxmin = std::max(left, right);
28  if (maxmin < center) {
29  bool ret = test(center, maxmin);
30  if (ret) {
31  ret = test(ileft, iright, begin, end);
32  }
33  return ret;
34  } else {
35  return false;
36  }
37  }
38 
39  template <typename V, typename Test>
40  bool apply(const V &ampls, const Test &test, bool verbose = false, int firststrip = 0) {
41  const uint8_t *begin = &*ampls.begin();
42  const uint8_t *end = &*ampls.end();
43  for (const uint8_t *x = begin; x < end - (half_ - 1); ++x) {
44  if (apply(x, begin, end, test, verbose, firststrip)) {
45  return true;
46  }
47  }
48  return false;
49  }
50 
51 private:
52  unsigned int size_, half_;
53 };
54 
56  PeakFinderTest(float mip,
57  uint32_t detid,
58  uint32_t firstStrip,
59  const SiStripNoises *theNoise,
60  float seedCutMIPs,
61  float seedCutSN,
62  float subclusterCutMIPs,
63  float subclusterCutSN)
64  : mip_(mip),
65  detid_(detid),
66  firstStrip_(firstStrip),
67  noiseObj_(theNoise),
68  noises_(theNoise->getRange(detid)),
72  cut_ = std::min<float>(seedCutMIPs * mip, seedCutSN * noiseObj_->getNoise(firstStrip + 1, noises_));
73  }
74 
75  bool operator()(uint8_t max, uint8_t min) const { return max - min > cut_; }
76  bool operator()(const uint8_t *left, const uint8_t *right, const uint8_t *begin, const uint8_t *end) const {
77  int yleft = (left < begin ? 0 : *left);
78  int yright = (right >= end ? 0 : *right);
79  float sum = 0.0;
80  int maxval = 0;
81  float noise = 0;
82  for (const uint8_t *x = left + 1; x < right; ++x) {
83  int baseline = (yleft * int(right - x) + yright * int(x - left)) / int(right - left);
84  sum += int(*x) - baseline;
85  noise += std::pow(noiseObj_->getNoise(firstStrip_ + int(x - begin), noises_), 2);
86  maxval = std::max(maxval, int(*x) - baseline);
87  }
88  if (sum > sumCut_ && sum * sum > noise * subclusterCutSN2_)
89  return true;
90  return false;
91  }
92 
93 private:
94  float mip_;
95  unsigned int detid_;
99  uint8_t cut_;
101 };
102 #endif
size
Write out results.
bool verbose
ret
prodAgent to be discontinued
constexpr int pow(int x)
Definition: conifer.h:24
unsigned int detid_
bool apply(const uint8_t *x, const uint8_t *begin, const uint8_t *end, const Test &test, bool verbose=false, int firststrip=0)
static float getNoise(uint16_t strip, const Range &range)
Definition: SiStripNoises.h:73
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
bool operator()(uint8_t max, uint8_t min) const
bool operator()(const uint8_t *left, const uint8_t *right, const uint8_t *begin, const uint8_t *end) const
PeakFinderTest(float mip, uint32_t detid, uint32_t firstStrip, const SiStripNoises *theNoise, float seedCutMIPs, float seedCutSN, float subclusterCutMIPs, float subclusterCutSN)
SlidingPeakFinder(unsigned int size)
const SiStripNoises * noiseObj_
SiStripNoises::Range noises_
bool apply(const V &ampls, const Test &test, bool verbose=false, int firststrip=0)
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47