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  // this has to be initialized before the first call to candidateEnded()
18  // and this is probably a bad place to initialize it
19  lastStrip = 0;
20 }
21 
22 template<class digiDetSet>
23 inline
25 clusterizeDetUnit_(const digiDetSet& digis, output_t::FastFiller& output) {
26  if(isModuleBad(digis.detId())) return;
27  if (!setDetId( digis.detId() )) return;
28 
29 #ifdef EDM_ML_DEBUG
30  if(!isModuleUsable(digis.detId() ))
31  LogWarning("ThreeThresholdAlgorithm") << " id " << digis.detId() << " not usable???" << std::endl;
32 #endif
33 
34 
35  typename digiDetSet::const_iterator
36  scan( digis.begin() ),
37  end( digis.end() );
38 
39  if(RemoveApvShots){
40  ApvCleaner.clean(digis,scan,end);
41  }
42 
44  while( scan != end ) {
45  while( scan != end && !candidateEnded( scan->strip() ) )
46  addToCandidate(*scan++);
47  endCandidate(output);
48  }
49 }
50 
51 inline
53 candidateEnded(const uint16_t& testStrip) const {
54  uint16_t holes = testStrip - lastStrip - 1;
55  return ( ( (!ADCs.empty()) & // a candidate exists, and
56  (holes > MaxSequentialHoles ) // too many holes if not all are bad strips, and
57  ) &&
58  ( holes > MaxSequentialBad || // (too many bad strips anyway, or
59  !allBadBetween( lastStrip, testStrip ) // not all holes are bad strips)
60  )
61  );
62 }
63 
64 inline
66 addToCandidate(uint16_t strip, uint8_t adc) {
67  float Noise = noise( strip );
68  if( adc < static_cast<uint8_t>( Noise * ChannelThreshold) || bad(strip) )
69  return;
70 
71  if(candidateLacksSeed) candidateLacksSeed = adc < static_cast<uint8_t>( Noise * SeedThreshold);
72  if(ADCs.empty()) lastStrip = strip - 1; // begin candidate
73  while( ++lastStrip < strip ) ADCs.push_back(0); // pad holes
74 
75  ADCs.push_back( adc );
76  noiseSquared += Noise*Noise;
77 }
78 
79 template <class T>
80 inline
83  if(candidateAccepted()) {
84  applyGains();
86  out.push_back(SiStripCluster(firstStrip(), ADCs.begin(), ADCs.end()));
87  }
88  clearCandidate();
89 }
90 
91 inline
94  return ( !candidateLacksSeed &&
96  <= std::pow( float(std::accumulate(ADCs.begin(),ADCs.end(), int(0))), 2.f));
97 }
98 
99 inline
102  uint16_t strip = firstStrip();
103  for( auto & adc : 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)/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
117  uint8_t max = MaxAdjacentBad;
118  while(0 < max--) {
119  if( bad( firstStrip()-1) ) { ADCs.insert( ADCs.begin(), 0); }
120  if( bad( lastStrip + 1) ) { ADCs.push_back(0); lastStrip++; }
121  }
122 }
123 
124 
125 void ThreeThresholdAlgorithm::clusterizeDetUnit(const edm::DetSet<SiStripDigi>& digis, output_t::FastFiller& output) {clusterizeDetUnit_(digis,output);}
127 
128 inline
130 stripByStripBegin(uint32_t id) {
131  if (!setDetId( id )) return false;
132 #ifdef EDM_ML_DEBUG
133  assert(isModuleUsable( id ));
134 #endif
135  clearCandidate();
136  return true;
137 }
138 
139 inline
141 stripByStripAdd(uint16_t strip, uint8_t adc, std::vector<SiStripCluster>& out) {
142  if(candidateEnded(strip)) endCandidate(out);
143  addToCandidate(SiStripDigi(strip,adc));
144 }
145 
146 inline
148 stripByStripEnd(std::vector<SiStripCluster>& out) {
149  endCandidate(out);
150 }
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
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