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(currentId(), firstStrip(), ADCs.begin(), ADCs.end()));
83  if (_setDetId) out.back().setId(currentId());
84  }
85  clearCandidate();
86 }
87 
88 inline
91  return ( !candidateLacksSeed &&
93  <= std::pow( float(std::accumulate(ADCs.begin(),ADCs.end(), int(0))), 2.f));
94 }
95 
96 inline
99  uint16_t strip = firstStrip();
100  for( auto & adc : ADCs) {
101 #ifdef EDM_ML_DEBUG
102  if(adc > 255) throw InvalidChargeException( SiStripDigi(strip,adc) );
103 #endif
104  // if(adc > 253) continue; //saturated, do not scale
105  auto charge = int( float(adc)/gain(strip++) + 0.5f ); //adding 0.5 turns truncation into rounding
106  if(adc < 254) adc = ( charge > 1022 ? 255 :
107  ( charge > 253 ? 254 : charge ));
108  }
109 }
110 
111 inline
114  uint8_t max = MaxAdjacentBad;
115  while(0 < max--) {
116  if( bad( firstStrip()-1) ) { ADCs.insert( ADCs.begin(), 0); }
117  if( bad( lastStrip + 1) ) { ADCs.push_back(0); lastStrip++; }
118  }
119 }
120 
121 
124 
125 inline
127 stripByStripBegin(uint32_t id) {
128  if (!setDetId( id )) return false;
129 #ifdef EDM_ML_DEBUG
130  assert(isModuleUsable( id ));
131 #endif
132  clearCandidate();
133  return true;
134 }
135 
136 inline
138 stripByStripAdd(uint16_t strip, uint8_t adc, std::vector<SiStripCluster>& out) {
139  if(candidateEnded(strip)) endCandidate(out);
140  addToCandidate(SiStripDigi(strip,adc));
141 }
142 
143 inline
145 stripByStripEnd(std::vector<SiStripCluster>& out) {
146  endCandidate(out);
147 }
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