CMS 3D CMS Logo

ThreeThresholdAlgorithm.cc
Go to the documentation of this file.
4 #include <cmath>
5 #include <numeric>
7 
9 
11  float seed,
12  float cluster,
13  unsigned holes,
14  unsigned bad,
15  unsigned adj,
16  std::string qL,
17  bool removeApvShots,
18  float minGoodCharge)
19  : ChannelThreshold(chan),
20  SeedThreshold(seed),
21  ClusterThresholdSquared(cluster * cluster),
22  MaxSequentialHoles(holes),
23  MaxSequentialBad(bad),
24  MaxAdjacentBad(adj),
25  RemoveApvShots(removeApvShots),
26  minGoodCharge(minGoodCharge) {
27  qualityLabel = (qL);
28 }
29 
30 template <class digiDetSet>
31 inline void ThreeThresholdAlgorithm::clusterizeDetUnit_(const digiDetSet& digis, output_t::TSFastFiller& output) const {
32  if (isModuleBad(digis.detId()))
33  return;
34 
35  auto const& det = findDetId(digis.detId());
36  if (!det.valid())
37  return;
38 
39 #ifdef EDM_ML_DEBUG
40  if (!isModuleUsable(digis.detId()))
41  edm::LogWarning("ThreeThresholdAlgorithm") << " id " << digis.detId() << " not usable???" << std::endl;
42 #endif
43 
44  typename digiDetSet::const_iterator scan(digis.begin()), end(digis.end());
45 
46  SiStripApvShotCleaner ApvCleaner;
47  if (RemoveApvShots) {
48  ApvCleaner.clean(digis, scan, end);
49  }
50 
51  State state(det);
52  while (scan != end) {
53  while (scan != end && !candidateEnded(state, scan->strip()))
54  addToCandidate(state, *scan++);
55  endCandidate(state, output);
56  }
57 }
58 
59 inline bool ThreeThresholdAlgorithm::candidateEnded(State const& state, const uint16_t& testStrip) const {
60  uint16_t holes = testStrip - state.lastStrip - 1;
61  return (((!state.ADCs.empty()) & // a candidate exists, and
62  (holes > MaxSequentialHoles) // too many holes if not all are bad strips, and
63  ) &&
64  (holes > MaxSequentialBad || // (too many bad strips anyway, or
65  !state.det().allBadBetween(state.lastStrip, testStrip) // not all holes are bad strips)
66  ));
67 }
68 
69 inline void ThreeThresholdAlgorithm::addToCandidate(State& state, uint16_t strip, uint8_t adc) const {
70  float Noise = state.det().noise(strip);
71  if (adc < static_cast<uint8_t>(Noise * ChannelThreshold) || state.det().bad(strip))
72  return;
73 
74  if (state.candidateLacksSeed)
75  state.candidateLacksSeed = adc < static_cast<uint8_t>(Noise * SeedThreshold);
76  if (state.ADCs.empty())
77  state.lastStrip = strip - 1; // begin candidate
78  while (++state.lastStrip < strip)
79  state.ADCs.push_back(0); // pad holes
80 
81  state.ADCs.push_back(adc);
82  state.noiseSquared += Noise * Noise;
83 }
84 
85 template <class T>
86 inline void ThreeThresholdAlgorithm::endCandidate(State& state, T& out) const {
87  if (candidateAccepted(state)) {
88  applyGains(state);
89  appendBadNeighbors(state);
90  if (siStripClusterTools::chargePerCM(state.det().detId, state.ADCs.begin(), state.ADCs.end()) > minGoodCharge)
91  out.push_back(SiStripCluster(firstStrip(state), state.ADCs.begin(), state.ADCs.end()));
92  }
93  clearCandidate(state);
94 }
95 
96 inline bool ThreeThresholdAlgorithm::candidateAccepted(State const& state) const {
97  return (!state.candidateLacksSeed &&
99  std::pow(float(std::accumulate(state.ADCs.begin(), state.ADCs.end(), int(0))), 2.f));
100 }
101 
102 inline void ThreeThresholdAlgorithm::applyGains(State& state) const {
103  uint16_t strip = firstStrip(state);
104  for (auto& adc : state.ADCs) {
105 #ifdef EDM_ML_DEBUG
106  // if(adc > 255) throw InvalidChargeException( SiStripDigi(strip,adc) );
107 #endif
108  // if(adc > 253) continue; //saturated, do not scale
109  auto charge = int(float(adc) / state.det().gain(strip++) + 0.5f); //adding 0.5 turns truncation into rounding
110  if (adc < 254)
111  adc = (charge > 1022 ? 255 : (charge > 253 ? 254 : charge));
112  }
113 }
114 
116  uint8_t max = MaxAdjacentBad;
117  while (0 < max--) {
118  if (state.det().bad(firstStrip(state) - 1)) {
119  state.ADCs.insert(state.ADCs.begin(), 0);
120  }
121  if (state.det().bad(state.lastStrip + 1)) {
122  state.ADCs.push_back(0);
123  state.lastStrip++;
124  }
125  }
126 }
127 
130  clusterizeDetUnit_(digis, output);
131 }
134  clusterizeDetUnit_(digis, output);
135 }
136 
138 
140  uint16_t strip,
141  uint8_t adc,
142  std::vector<SiStripCluster>& out) const {
143  if (candidateEnded(state, strip))
144  endCandidate(state, out);
145  addToCandidate(state, SiStripDigi(strip, adc));
146 }
147 
148 void ThreeThresholdAlgorithm::stripByStripEnd(State& state, std::vector<SiStripCluster>& out) const {
149  endCandidate(state, out);
150 }
ThreeThresholdAlgorithm(float, float, float, unsigned, unsigned, unsigned, std::string qualityLabel, bool removeApvShots, float minGoodCharge)
bool isModuleBad(const uint32_t &id) const
void clusterizeDetUnit(const edm::DetSet< SiStripDigi > &, output_t::TSFastFiller &) const override
float chargePerCM(DetId detid, Iter a, Iter b)
bool candidateAccepted(State const &state) const
Det stripByStripBegin(uint32_t id) const override
void endCandidate(State &state, T &) const
void clearCandidate(State &state) const
void appendBadNeighbors(State &state) const
void stripByStripEnd(State &state, std::vector< SiStripCluster > &out) const override
bool bad(const uint16_t &strip) const
#define end
Definition: vmac.h:39
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
bool candidateEnded(State const &state, const uint16_t &) const
bool allBadBetween(uint16_t L, const uint16_t &R) const
float gain(const uint16_t &strip) const
void addToCandidate(State &state, const SiStripDigi &digi) const
bool isModuleUsable(const uint32_t &id) const
void stripByStripAdd(State &state, uint16_t strip, uint8_t adc, std::vector< SiStripCluster > &out) const override
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
void applyGains(State &state) const
Det findDetId(const uint32_t) const
bool clean(const edmNew::DetSet< SiStripDigi > &in, edmNew::DetSet< SiStripDigi >::const_iterator &scan, edmNew::DetSet< SiStripDigi >::const_iterator &end)
long double T
uint16_t firstStrip(State const &state) const
float noise(const uint16_t &strip) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
void clusterizeDetUnit_(const T &, output_t::TSFastFiller &) const