CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ThreeThresholdAlgorithm.cc
Go to the documentation of this file.
4 #include <cmath>
5 #include <numeric>
7 
9 ThreeThresholdAlgorithm(float chan, float seed, float cluster, unsigned holes, unsigned bad, unsigned adj, std::string qL,
10  bool setDetId, bool removeApvShots)
11  : ChannelThreshold( chan ), SeedThreshold( seed ), ClusterThresholdSquared( cluster*cluster ),
12  MaxSequentialHoles( holes ), MaxSequentialBad( bad ), MaxAdjacentBad( adj ), RemoveApvShots(removeApvShots) {
14  qualityLabel = (qL);
15  ADCs.reserve(128);
16 }
17 
18 template<class digiDetSet>
19 inline
21 clusterizeDetUnit_(const digiDetSet& digis, output_t::FastFiller& output) {
22  if(isModuleBad(digis.detId())) return;
23  if (!setDetId( digis.detId() )) return;
24 
25 #ifdef EDM_ML_DEBUG
26  if(!isModuleUsable(digis.detId() ))
27  LogWarning("ThreeThresholdAlgorithm") << " id " << digis.detId() << " not usable???" << std::endl;
28 #endif
29 
30 
31  typename digiDetSet::const_iterator
32  scan( digis.begin() ),
33  end( digis.end() );
34 
35  if(RemoveApvShots){
36  ApvCleaner.clean(digis,scan,end);
37  }
38 
40  while( scan != end ) {
41  while( scan != end && !candidateEnded( scan->strip() ) )
42  addToCandidate(*scan++);
43  endCandidate(output);
44  }
45 }
46 
47 inline
49 candidateEnded(const uint16_t& testStrip) const {
50  uint16_t holes = testStrip - lastStrip - 1;
51  return ( ( (!ADCs.empty()) & // a candidate exists, and
52  (holes > MaxSequentialHoles ) // too many holes if not all are bad strips, and
53  ) &&
54  ( holes > MaxSequentialBad || // (too many bad strips anyway, or
55  !allBadBetween( lastStrip, testStrip ) // not all holes are bad strips)
56  )
57  );
58 }
59 
60 inline
62 addToCandidate(uint16_t strip, uint8_t adc) {
63  float Noise = noise( strip );
64  if( adc < static_cast<uint8_t>( Noise * ChannelThreshold) || bad(strip) )
65  return;
66 
67  if(candidateLacksSeed) candidateLacksSeed = adc < static_cast<uint8_t>( Noise * SeedThreshold);
68  if(ADCs.empty()) lastStrip = strip - 1; // begin candidate
69  while( ++lastStrip < strip ) ADCs.push_back(0); // pad holes
70 
71  ADCs.push_back( adc );
72  noiseSquared += Noise*Noise;
73 }
74 
75 template <class T>
76 inline
79  if(candidateAccepted()) {
80  applyGains();
82  out.push_back(SiStripCluster(firstStrip(), ADCs.begin(), ADCs.end()));
83  }
84  clearCandidate();
85 }
86 
87 inline
90  return ( !candidateLacksSeed &&
92  <= std::pow( float(std::accumulate(ADCs.begin(),ADCs.end(), int(0))), 2.f));
93 }
94 
95 inline
98  uint16_t strip = firstStrip();
99  for( auto & adc : ADCs) {
100 #ifdef EDM_ML_DEBUG
101  if(adc > 255) throw InvalidChargeException( SiStripDigi(strip,adc) );
102 #endif
103  // if(adc > 253) continue; //saturated, do not scale
104  auto charge = int( float(adc)/gain(strip++) + 0.5f ); //adding 0.5 turns truncation into rounding
105  if(adc < 254) adc = ( charge > 1022 ? 255 :
106  ( charge > 253 ? 254 : charge ));
107  }
108 }
109 
110 inline
113  uint8_t max = MaxAdjacentBad;
114  while(0 < max--) {
115  if( bad( firstStrip()-1) ) { ADCs.insert( ADCs.begin(), 0); }
116  if( bad( lastStrip + 1) ) { ADCs.push_back(0); lastStrip++; }
117  }
118 }
119 
120 
121 void ThreeThresholdAlgorithm::clusterizeDetUnit(const edm::DetSet<SiStripDigi>& digis, output_t::FastFiller& output) {clusterizeDetUnit_(digis,output);}
123 
124 inline
126 stripByStripBegin(uint32_t id) {
127  if (!setDetId( id )) return false;
128 #ifdef EDM_ML_DEBUG
129  assert(isModuleUsable( id ));
130 #endif
131  clearCandidate();
132  return true;
133 }
134 
135 inline
137 stripByStripAdd(uint16_t strip, uint8_t adc, std::vector<SiStripCluster>& out) {
138  if(candidateEnded(strip)) endCandidate(out);
139  addToCandidate(SiStripDigi(strip,adc));
140 }
141 
142 inline
144 stripByStripEnd(std::vector<SiStripCluster>& out) {
145  endCandidate(out);
146 }
int adc(sample_type sample)
get the ADC sample (12 bits)
bool bad(const uint16_t &strip) const
bool isModuleBad(const uint32_t &id) const
float noise(const uint16_t &strip) const
double charge(const std::vector< uint8_t > &Ampls)
void addToCandidate(const SiStripDigi &digi)
int bad(Items const &cont)
bool candidateEnded(const uint16_t &) const
void stripByStripAdd(uint16_t strip, uint8_t adc, std::vector< SiStripCluster > &out)
const T & max(const T &a, const T &b)
SiStripApvShotCleaner ApvCleaner
double f[11][100]
#define end
Definition: vmac.h:37
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
ThreeThresholdAlgorithm(float, float, float, unsigned, unsigned, unsigned, std::string qualityLabel, bool setDetId, bool removeApvShots=false)
tuple out
Definition: dbtoconf.py:99
std::vector< uint8_t > ADCs
void stripByStripEnd(std::vector< SiStripCluster > &out)
bool isModuleUsable(const uint32_t &id) const
bool allBadBetween(uint16_t L, const uint16_t &R) const
void clusterizeDetUnit(const edm::DetSet< SiStripDigi > &, output_t::FastFiller &)
float gain(const uint16_t &strip) const
void clusterizeDetUnit_(const T &, output_t::FastFiller &)
bool clean(const edmNew::DetSet< SiStripDigi > &in, edmNew::DetSet< SiStripDigi >::const_iterator &scan, edmNew::DetSet< SiStripDigi >::const_iterator &end)
long double T
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40