CMS 3D CMS Logo

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