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)
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);
146 }
147 
148 void ThreeThresholdAlgorithm::stripByStripEnd(State& state, std::vector<SiStripCluster>& out) const {
149  endCandidate(state, out);
150 }
HLT_2018_cff.MaxSequentialHoles
MaxSequentialHoles
Definition: HLT_2018_cff.py:8163
ecalMGPA::adc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
Definition: EcalMGPASample.h:11
ThreeThresholdAlgorithm::MaxAdjacentBad
uint8_t MaxAdjacentBad
Definition: ThreeThresholdAlgorithm.h:62
StripClusterizerAlgorithm::State::candidateLacksSeed
bool candidateLacksSeed
Definition: StripClusterizerAlgorithm.h:50
MessageLogger.h
StripClusterizerAlgorithm::qualityLabel
std::string qualityLabel
Definition: StripClusterizerAlgorithm.h:94
ThreeThresholdAlgorithm::addToCandidate
void addToCandidate(State &state, const SiStripDigi &digi) const
Definition: ThreeThresholdAlgorithm.h:56
ThreeThresholdAlgorithm::candidateAccepted
bool candidateAccepted(State const &state) const
Definition: ThreeThresholdAlgorithm.cc:96
ThreeThresholdAlgorithm::endCandidate
void endCandidate(State &state, T &) const
Definition: ThreeThresholdAlgorithm.cc:86
StripClusterizerAlgorithm::State::det
Det const & det() const
Definition: StripClusterizerAlgorithm.h:46
ThreeThresholdAlgorithm::candidateEnded
bool candidateEnded(State const &state, const uint16_t &) const
Definition: ThreeThresholdAlgorithm.cc:59
edm::DetSet< SiStripDigi >
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
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:64
edmNew::DetSetVector::TSFastFiller
Definition: DetSetVectorNew.h:334
StripClusterizerAlgorithm::Det::allBadBetween
bool allBadBetween(uint16_t L, const uint16_t &R) const
Definition: StripClusterizerAlgorithm.h:30
ThreeThresholdAlgorithm.h
ThreeThresholdAlgorithm::appendBadNeighbors
void appendBadNeighbors(State &state) const
Definition: ThreeThresholdAlgorithm.cc:115
ThreeThresholdAlgorithm::ThreeThresholdAlgorithm
ThreeThresholdAlgorithm(float, float, float, unsigned, unsigned, unsigned, std::string qualityLabel, bool removeApvShots, float minGoodCharge)
Definition: ThreeThresholdAlgorithm.cc:10
StripClusterizerAlgorithm::State::lastStrip
uint16_t lastStrip
Definition: StripClusterizerAlgorithm.h:48
end
#define end
Definition: vmac.h:39
ThreeThresholdAlgorithm::ClusterThresholdSquared
float ClusterThresholdSquared
Definition: ThreeThresholdAlgorithm.h:61
StripClusterizerAlgorithm::State
Definition: StripClusterizerAlgorithm.h:44
ThreeThresholdAlgorithm::stripByStripEnd
void stripByStripEnd(State &state, std::vector< SiStripCluster > &out) const override
Definition: ThreeThresholdAlgorithm.cc:148
ThreeThresholdAlgorithm::firstStrip
uint16_t firstStrip(State const &state) const
Definition: ThreeThresholdAlgorithm.h:44
ThreeThresholdAlgorithm::clusterizeDetUnit
void clusterizeDetUnit(const edm::DetSet< SiStripDigi > &, output_t::TSFastFiller &) const override
Definition: ThreeThresholdAlgorithm.cc:128
StripClusterizerAlgorithm::State::ADCs
std::vector< uint8_t > ADCs
Definition: StripClusterizerAlgorithm.h:47
ThreeThresholdAlgorithm::SeedThreshold
float SeedThreshold
Definition: ThreeThresholdAlgorithm.h:61
StripClusterizerAlgorithm::State::noiseSquared
float noiseSquared
Definition: StripClusterizerAlgorithm.h:49
StripClusterizerAlgorithm::Det
Definition: StripClusterizerAlgorithm.h:25
SiStripDigi.h
HLT_2018_cff.ChannelThreshold
ChannelThreshold
Definition: HLT_2018_cff.py:8122
edmNew::DetSet
Definition: DetSetNew.h:22
ThreeThresholdAlgorithm::applyGains
void applyGains(State &state) const
Definition: ThreeThresholdAlgorithm.cc:102
ThreeThresholdAlgorithm::stripByStripAdd
void stripByStripAdd(State &state, uint16_t strip, uint8_t adc, std::vector< SiStripCluster > &out) const override
Definition: ThreeThresholdAlgorithm.cc:139
ThreeThresholdAlgorithm::RemoveApvShots
bool RemoveApvShots
Definition: ThreeThresholdAlgorithm.h:63
ThreeThresholdAlgorithm::MaxSequentialBad
uint8_t MaxSequentialBad
Definition: ThreeThresholdAlgorithm.h:62
SiStripClusterTools.h
ThreeThresholdAlgorithm::clusterizeDetUnit_
void clusterizeDetUnit_(const T &, output_t::TSFastFiller &) const
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
SiStripApvShotCleaner
Definition: SiStripApvShotCleaner.h:11
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
StripClusterizerAlgorithm::findDetId
Det findDetId(const uint32_t) const
Definition: StripClusterizerAlgorithm.cc:161
ThreeThresholdAlgorithm::clearCandidate
void clearCandidate(State &state) const
Definition: ThreeThresholdAlgorithm.h:51
SiStripCluster.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
HLT_2018_cff.SeedThreshold
SeedThreshold
Definition: HLT_2018_cff.py:8137
StripClusterizerAlgorithm::Det::gain
float gain(const uint16_t &strip) const
Definition: StripClusterizerAlgorithm.h:28
StripClusterizerAlgorithm::Det::detId
uint32_t detId
Definition: StripClusterizerAlgorithm.h:39
createfilelist.int
int
Definition: createfilelist.py:10
ThreeThresholdAlgorithm::stripByStripBegin
Det stripByStripBegin(uint32_t id) const override
Definition: ThreeThresholdAlgorithm.cc:137
ThreeThresholdAlgorithm::ChannelThreshold
float ChannelThreshold
Definition: ThreeThresholdAlgorithm.h:61
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
HLT_2018_cff.MaxSequentialBad
MaxSequentialBad
Definition: HLT_2018_cff.py:8166
StripClusterizerAlgorithm::Det::bad
bool bad(const uint16_t &strip) const
Definition: StripClusterizerAlgorithm.h:29
StripClusterizerAlgorithm::isModuleBad
bool isModuleBad(const uint32_t &id) const
Definition: StripClusterizerAlgorithm.h:91
StripClusterizerAlgorithm::Det::noise
float noise(const uint16_t &strip) const
Definition: StripClusterizerAlgorithm.h:27
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_2018_cff.MaxAdjacentBad
MaxAdjacentBad
Definition: HLT_2018_cff.py:8161
StripClusterizerAlgorithm::isModuleUsable
bool isModuleUsable(const uint32_t &id) const
Definition: StripClusterizerAlgorithm.h:92
ThreeThresholdAlgorithm::MaxSequentialHoles
uint8_t MaxSequentialHoles
Definition: ThreeThresholdAlgorithm.h:62
HLT_2018_cff.RemoveApvShots
RemoveApvShots
Definition: HLT_2018_cff.py:8164
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:30
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:9
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295