CMS 3D CMS Logo

ThreeThresholdAlgorithm.cc
Go to the documentation of this file.
4 #include <cmath>
5 #include <numeric>
7 
9 
12  float chan,
13  float seed,
14  float cluster,
15  unsigned holes,
16  unsigned bad,
17  unsigned adj,
18  bool removeApvShots,
19  float minGoodCharge)
20  : StripClusterizerAlgorithm(conditionsToken),
23  ClusterThresholdSquared(cluster * cluster),
24  MaxSequentialHoles(holes),
25  MaxSequentialBad(bad),
26  MaxAdjacentBad(adj),
27  RemoveApvShots(removeApvShots),
28  minGoodCharge(minGoodCharge) {}
29 
30 template <class digiDetSet>
31 inline void ThreeThresholdAlgorithm::clusterizeDetUnit_(const digiDetSet& digis, output_t::TSFastFiller& output) const {
32  const auto& cond = conditions();
33  if (cond.isModuleBad(digis.detId()))
34  return;
35 
36  auto const& det = cond.findDetId(digis.detId());
37  if (!det.valid())
38  return;
39 
40 #ifdef EDM_ML_DEBUG
41  if (!cond.isModuleUsable(digis.detId()))
42  edm::LogWarning("ThreeThresholdAlgorithm") << " id " << digis.detId() << " not usable???" << std::endl;
43 #endif
44 
45  typename digiDetSet::const_iterator scan(digis.begin()), end(digis.end());
46 
47  SiStripApvShotCleaner ApvCleaner;
48  if (RemoveApvShots) {
49  ApvCleaner.clean(digis, scan, end);
50  }
51 
52  output.reserve(16);
53  State state(det);
54  while (scan != end) {
55  while (scan != end && !candidateEnded(state, scan->strip()))
56  addToCandidate(state, *scan++);
58  }
59 }
60 
61 inline bool ThreeThresholdAlgorithm::candidateEnded(State const& state, const uint16_t& testStrip) const {
62  uint16_t holes = testStrip - state.lastStrip - 1;
63  return (((!state.ADCs.empty()) & // a candidate exists, and
64  (holes > MaxSequentialHoles) // too many holes if not all are bad strips, and
65  ) &&
66  (holes > MaxSequentialBad || // (too many bad strips anyway, or
67  !state.det().allBadBetween(state.lastStrip, testStrip) // not all holes are bad strips)
68  ));
69 }
70 
71 inline void ThreeThresholdAlgorithm::addToCandidate(State& state, uint16_t strip, uint8_t adc) const {
72  float Noise = state.det().noise(strip);
73  if (adc < static_cast<uint8_t>(Noise * ChannelThreshold) || state.det().bad(strip))
74  return;
75 
76  if (state.candidateLacksSeed)
77  state.candidateLacksSeed = adc < static_cast<uint8_t>(Noise * SeedThreshold);
78  if (state.ADCs.empty())
79  state.lastStrip = strip - 1; // begin candidate
80  while (++state.lastStrip < strip)
81  state.ADCs.push_back(0); // pad holes
82 
83  state.ADCs.push_back(adc);
84  state.noiseSquared += Noise * Noise;
85 }
86 
87 template <class T>
89  if (candidateAccepted(state)) {
91  if (MaxAdjacentBad > 0)
93  if (minGoodCharge <= 0 ||
94  siStripClusterTools::chargePerCM(state.det().detId, state.ADCs.begin(), state.ADCs.end()) > minGoodCharge)
95  out.push_back(std::move(SiStripCluster(firstStrip(state), state.ADCs.begin(), state.ADCs.end())));
96  }
98 }
99 
101  return (!state.candidateLacksSeed &&
102  state.noiseSquared * ClusterThresholdSquared <=
103  std::pow(float(std::accumulate(state.ADCs.begin(), state.ADCs.end(), int(0))), 2.f));
104 }
105 
107  uint16_t strip = firstStrip(state);
108  for (auto& adc : state.ADCs) {
109 #ifdef EDM_ML_DEBUG
110  // if(adc > 255) throw InvalidChargeException( SiStripDigi(strip,adc) );
111 #endif
112  // if(adc > 253) continue; //saturated, do not scale
113  auto charge = int(float(adc) * state.det().weight(strip++) + 0.5f); //adding 0.5 turns truncation into rounding
114  if (adc < 254)
115  adc = (charge > 1022 ? 255 : (charge > 253 ? 254 : charge));
116  }
117 }
118 
120  uint8_t max = MaxAdjacentBad;
121  while (0 < max--) {
122  if (state.det().bad(firstStrip(state) - 1)) {
123  state.ADCs.insert(state.ADCs.begin(), 0);
124  }
125  if (state.det().bad(state.lastStrip + 1)) {
126  state.ADCs.push_back(0);
127  state.lastStrip++;
128  }
129  }
130 }
131 
134  clusterizeDetUnit_(digis, output);
135 }
138  clusterizeDetUnit_(digis, output);
139 }
140 
142  uint16_t strip,
143  uint8_t adc,
144  std::vector<SiStripCluster>& out) const {
145  if (candidateEnded(state, strip))
148 }
149 
150 void ThreeThresholdAlgorithm::stripByStripEnd(State& state, std::vector<SiStripCluster>& out) const {
152 }
StripClusterizerAlgorithm
Definition: StripClusterizerAlgorithm.h:16
ThreeThresholdAlgorithm::MaxAdjacentBad
uint8_t MaxAdjacentBad
Definition: ThreeThresholdAlgorithm.h:60
MessageLogger.h
ThreeThresholdAlgorithm::addToCandidate
void addToCandidate(State &state, const SiStripDigi &digi) const
Definition: ThreeThresholdAlgorithm.h:54
ThreeThresholdAlgorithm::candidateAccepted
bool candidateAccepted(State const &state) const
Definition: ThreeThresholdAlgorithm.cc:100
ThreeThresholdAlgorithm::endCandidate
void endCandidate(State &state, T &) const
Definition: ThreeThresholdAlgorithm.cc:88
ThreeThresholdAlgorithm::candidateEnded
bool candidateEnded(State const &state, const uint16_t &) const
Definition: ThreeThresholdAlgorithm.cc:61
edm::DetSet< SiStripDigi >
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
gpuClustering::adc
uint16_t *__restrict__ uint16_t const *__restrict__ adc
Definition: gpuClusterChargeCut.h:20
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
siStripClusterTools::chargePerCM
float chargePerCM(DetId detid, Iter a, Iter b)
Definition: SiStripClusterTools.h:29
ThreeThresholdAlgorithm::minGoodCharge
float minGoodCharge
Definition: ThreeThresholdAlgorithm.h:62
HLT_FULL_cff.MaxSequentialHoles
MaxSequentialHoles
Definition: HLT_FULL_cff.py:9481
edmNew::DetSetVector::TSFastFiller
Definition: DetSetVectorNew.h:300
ThreeThresholdAlgorithm.h
ThreeThresholdAlgorithm::appendBadNeighbors
void appendBadNeighbors(State &state) const
Definition: ThreeThresholdAlgorithm.cc:119
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
ThreeThresholdAlgorithm::ClusterThresholdSquared
float ClusterThresholdSquared
Definition: ThreeThresholdAlgorithm.h:59
StripClusterizerAlgorithm::State
Definition: StripClusterizerAlgorithm.h:21
fileCollector.seed
seed
Definition: fileCollector.py:127
ThreeThresholdAlgorithm::stripByStripEnd
void stripByStripEnd(State &state, std::vector< SiStripCluster > &out) const override
Definition: ThreeThresholdAlgorithm.cc:150
ThreeThresholdAlgorithm::firstStrip
uint16_t firstStrip(State const &state) const
Definition: ThreeThresholdAlgorithm.h:42
HLT_FULL_cff.ChannelThreshold
ChannelThreshold
Definition: HLT_FULL_cff.py:9441
ThreeThresholdAlgorithm::clusterizeDetUnit
void clusterizeDetUnit(const edm::DetSet< SiStripDigi > &, output_t::TSFastFiller &) const override
Definition: ThreeThresholdAlgorithm.cc:132
ThreeThresholdAlgorithm::SeedThreshold
float SeedThreshold
Definition: ThreeThresholdAlgorithm.h:59
SiStripDigi.h
mps_fire.end
end
Definition: mps_fire.py:242
edmNew::DetSet
Definition: DetSetNew.h:22
ThreeThresholdAlgorithm::applyGains
void applyGains(State &state) const
Definition: ThreeThresholdAlgorithm.cc:106
ThreeThresholdAlgorithm::stripByStripAdd
void stripByStripAdd(State &state, uint16_t strip, uint8_t adc, std::vector< SiStripCluster > &out) const override
Definition: ThreeThresholdAlgorithm.cc:141
ThreeThresholdAlgorithm::RemoveApvShots
bool RemoveApvShots
Definition: ThreeThresholdAlgorithm.h:61
ThreeThresholdAlgorithm::MaxSequentialBad
uint8_t MaxSequentialBad
Definition: ThreeThresholdAlgorithm.h:60
SiStripClusterTools.h
ThreeThresholdAlgorithm::clusterizeDetUnit_
void clusterizeDetUnit_(const T &, output_t::TSFastFiller &) const
SiStripApvShotCleaner
Definition: SiStripApvShotCleaner.h:11
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
cond
Definition: plugin.cc:23
ThreeThresholdAlgorithm::clearCandidate
void clearCandidate(State &state) const
Definition: ThreeThresholdAlgorithm.h:49
StripClusterizerAlgorithm::conditions
const SiStripClusterizerConditions & conditions() const
Definition: StripClusterizerAlgorithm.h:36
SiStripCluster.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
HLT_FULL_cff.RemoveApvShots
RemoveApvShots
Definition: HLT_FULL_cff.py:9482
createfilelist.int
int
Definition: createfilelist.py:10
edm::ESGetToken< SiStripClusterizerConditions, SiStripClusterizerConditionsRcd >
ThreeThresholdAlgorithm::ChannelThreshold
float ChannelThreshold
Definition: ThreeThresholdAlgorithm.h:59
ThreeThresholdAlgorithm::ThreeThresholdAlgorithm
ThreeThresholdAlgorithm(const edm::ESGetToken< SiStripClusterizerConditions, SiStripClusterizerConditionsRcd > &, float, float, float, unsigned, unsigned, unsigned, bool removeApvShots, float minGoodCharge)
Definition: ThreeThresholdAlgorithm.cc:10
eostools.move
def move(src, dest)
Definition: eostools.py:511
SiStripApvShotCleaner::clean
bool clean(const edmNew::DetSet< SiStripDigi > &in, edmNew::DetSet< SiStripDigi >::const_iterator &scan, edmNew::DetSet< SiStripDigi >::const_iterator &end)
Definition: SiStripApvShotCleaner.h:19
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
T
long double T
Definition: Basic3DVectorLD.h:48
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
HLT_FULL_cff.SeedThreshold
SeedThreshold
Definition: HLT_FULL_cff.py:9456
ThreeThresholdAlgorithm::MaxSequentialHoles
uint8_t MaxSequentialHoles
Definition: ThreeThresholdAlgorithm.h:60
HLT_FULL_cff.MaxSequentialBad
MaxSequentialBad
Definition: HLT_FULL_cff.py:9484
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
SiStripDigi
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
DigiDM_cff.Noise
Noise
Definition: DigiDM_cff.py:38
SiStripCluster
Definition: SiStripCluster.h:8
HLT_FULL_cff.MaxAdjacentBad
MaxAdjacentBad
Definition: HLT_FULL_cff.py:9479
gpuVertexFinder::while
while(__syncthreads_or(more))
Definition: gpuClusterTracksIterative.h:109