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>
6 
8 ThreeThresholdAlgorithm(float chan, float seed, float cluster, unsigned holes, unsigned bad, unsigned adj, std::string qL,
9  bool setDetId, bool removeApvShots)
10  : ChannelThreshold( chan ), SeedThreshold( seed ), ClusterThresholdSquared( cluster*cluster ),
11  MaxSequentialHoles( holes ), MaxSequentialBad( bad ), MaxAdjacentBad( adj ), RemoveApvShots(removeApvShots) {
13  qualityLabel = (qL);
14  ADCs.reserve(128);
15 }
16 
17 template<class digiDetSet>
18 inline
20 clusterizeDetUnit_(const digiDetSet& digis, output_t::FastFiller& output) {
21  if( !isModuleUsable( digis.detId() )) return;
22  setDetId( digis.detId() );
23 
24  typename digiDetSet::const_iterator
25  scan( digis.begin() ),
26  end( digis.end() );
27 
28  if(RemoveApvShots){
29  ApvCleaner.clean(digis,scan,end);
30  }
31 
33  while( scan != end ) {
34  while( scan != end && !candidateEnded( scan->strip() ) )
35  addToCandidate(*scan++);
36  endCandidate(output);
37  }
38 }
39 
40 inline
42 candidateEnded(const uint16_t& testStrip) const {
43  uint16_t holes = testStrip - lastStrip - 1;
44  return ( !ADCs.empty() && // a candidate exists, and
45  holes > MaxSequentialHoles && // too many holes if not all are bad strips, and
46  ( holes > MaxSequentialBad || // (too many bad strips anyway, or
47  !allBadBetween( lastStrip, testStrip ))); // not all holes are bad strips)
48 }
49 
50 inline
52 addToCandidate(const SiStripDigi& digi) {
53  float Noise = noise( digi.strip() );
54  if( bad(digi.strip()) || digi.adc() < static_cast<uint16_t>( Noise * ChannelThreshold))
55  return;
56 
57  if(candidateLacksSeed) candidateLacksSeed = digi.adc() < static_cast<uint16_t>( Noise * SeedThreshold);
58  if(ADCs.empty()) lastStrip = digi.strip() - 1; // begin candidate
59  while( ++lastStrip < digi.strip() ) ADCs.push_back(0); // pad holes
60 
61  ADCs.push_back( digi.adc() );
62  noiseSquared += Noise*Noise;
63 }
64 
65 template <class T>
66 inline
69  if(candidateAccepted()) {
70  applyGains();
72  out.push_back(SiStripCluster(currentId(), firstStrip(), ADCs.begin(), ADCs.end()));
73  if (_setDetId) out.back().setId(currentId());
74  }
75  clearCandidate();
76 }
77 
78 inline
81  return ( !candidateLacksSeed &&
83  <= std::pow( std::accumulate(ADCs.begin(),ADCs.end(),float(0)), 2));
84 }
85 
86 inline
89  uint16_t strip = firstStrip();
90  for( std::vector<uint16_t>::iterator adc = ADCs.begin(); adc != ADCs.end(); adc++) {
91  if(*adc > 255) throw InvalidChargeException( SiStripDigi(strip,*adc) );
92  if(*adc > 253) continue; //saturated, do not scale
93  uint16_t charge = static_cast<uint16_t>( *adc/gain(strip++) + 0.5 ); //adding 0.5 turns truncation into rounding
94  *adc = ( charge > 1022 ? 255 :
95  ( charge > 253 ? 254 : charge ));
96  }
97 }
98 
99 inline
102  uint8_t max = MaxAdjacentBad;
103  while(0 < max--) {
104  if( bad( firstStrip()-1) ) { ADCs.insert( ADCs.begin(), 0); }
105  if( bad( lastStrip + 1) ) { ADCs.push_back(0); lastStrip++; }
106  }
107 }
108 
109 
112 
113 inline
115 stripByStripBegin(uint32_t id) {
116  if( !isModuleUsable( id )) return false;
117  setDetId( id );
118  clearCandidate();
119  return true;
120 }
121 
122 inline
124 stripByStripAdd(uint16_t strip, uint16_t adc, std::vector<SiStripCluster>& out) {
125  if(candidateEnded(strip))
126  endCandidate(out);
127  addToCandidate(SiStripDigi(strip,adc));
128 }
129 
130 inline
132 stripByStripEnd(std::vector<SiStripCluster>& out) {
133  endCandidate(out);
134 }
int adc(sample_type sample)
get the ADC sample (12 bits)
bool bad(const uint16_t &strip) const
void addToCandidate(const SiStripDigi &)
float noise(const uint16_t &strip) const
double charge(const std::vector< uint8_t > &Ampls)
int bad(Items const &cont)
void stripByStripAdd(uint16_t strip, uint16_t adc, std::vector< SiStripCluster > &out)
bool candidateEnded(const uint16_t &) const
const T & max(const T &a, const T &b)
SiStripApvShotCleaner ApvCleaner
const uint16_t & strip() const
Definition: SiStripDigi.h:40
std::vector< uint16_t > ADCs
#define end
Definition: vmac.h:38
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
virtual void setDetId(const uint32_t)
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)
const uint16_t & adc() const
Definition: SiStripDigi.h:41
long double T
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40