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 
11 ThreeThresholdAlgorithm(float chan, float seed, float cluster, unsigned holes, unsigned bad, unsigned adj, std::string qL,
12  bool setDetId, bool removeApvShots, float minGoodCharge)
13  : ChannelThreshold( chan ), SeedThreshold( seed ), ClusterThresholdSquared( cluster*cluster ),
14  MaxSequentialHoles( holes ), MaxSequentialBad( bad ), MaxAdjacentBad( adj ), RemoveApvShots(removeApvShots), minGoodCharge(minGoodCharge) {
16  qualityLabel = (qL);
17  ADCs.reserve(128);
18 
19  // this has to be initialized before the first call to candidateEnded()
20  // and this is probably a bad place to initialize it
21  lastStrip = 0;
22 }
23 
24 template<class digiDetSet>
25 inline
27 clusterizeDetUnit_(const digiDetSet& digis, output_t::FastFiller& output) {
28  if(isModuleBad(digis.detId())) return;
29  if (!setDetId( digis.detId() )) return;
30 
31 #ifdef EDM_ML_DEBUG
32  if(!isModuleUsable(digis.detId() ))
33  LogWarning("ThreeThresholdAlgorithm") << " id " << digis.detId() << " not usable???" << std::endl;
34 #endif
35 
36 
37  typename digiDetSet::const_iterator
38  scan( digis.begin() ),
39  end( digis.end() );
40 
41  if(RemoveApvShots){
42  ApvCleaner.clean(digis,scan,end);
43  }
44 
46  while( scan != end ) {
47  while( scan != end && !candidateEnded( scan->strip() ) )
48  addToCandidate(*scan++);
49  endCandidate(output);
50  }
51 }
52 
53 inline
55 candidateEnded(const uint16_t& testStrip) const {
56  uint16_t holes = testStrip - lastStrip - 1;
57  return ( ( (!ADCs.empty()) & // a candidate exists, and
58  (holes > MaxSequentialHoles ) // too many holes if not all are bad strips, and
59  ) &&
60  ( holes > MaxSequentialBad || // (too many bad strips anyway, or
61  !allBadBetween( lastStrip, testStrip ) // not all holes are bad strips)
62  )
63  );
64 }
65 
66 inline
68 addToCandidate(uint16_t strip, uint8_t adc) {
69  float Noise = noise( strip );
70  if( adc < static_cast<uint8_t>( Noise * ChannelThreshold) || bad(strip) )
71  return;
72 
73  if(candidateLacksSeed) candidateLacksSeed = adc < static_cast<uint8_t>( Noise * SeedThreshold);
74  if(ADCs.empty()) lastStrip = strip - 1; // begin candidate
75  while( ++lastStrip < strip ) ADCs.push_back(0); // pad holes
76 
77  ADCs.push_back( adc );
78  noiseSquared += Noise*Noise;
79 }
80 
81 template <class T>
82 inline
85  if(candidateAccepted()) {
86  applyGains();
89  out.push_back(SiStripCluster(firstStrip(), ADCs.begin(), ADCs.end()));
90  }
91  clearCandidate();
92 }
93 
94 inline
97  return ( !candidateLacksSeed &&
99  <= std::pow( float(std::accumulate(ADCs.begin(),ADCs.end(), int(0))), 2.f));
100 }
101 
102 inline
105  uint16_t strip = firstStrip();
106  for( auto & adc : ADCs) {
107 #ifdef EDM_ML_DEBUG
108  if(adc > 255) throw InvalidChargeException( SiStripDigi(strip,adc) );
109 #endif
110  // if(adc > 253) continue; //saturated, do not scale
111  auto charge = int( float(adc)/gain(strip++) + 0.5f ); //adding 0.5 turns truncation into rounding
112  if(adc < 254) adc = ( charge > 1022 ? 255 :
113  ( charge > 253 ? 254 : charge ));
114  }
115 }
116 
117 inline
120  uint8_t max = MaxAdjacentBad;
121  while(0 < max--) {
122  if( bad( firstStrip()-1) ) { ADCs.insert( ADCs.begin(), 0); }
123  if( bad( lastStrip + 1) ) { ADCs.push_back(0); lastStrip++; }
124  }
125 }
126 
127 
128 void ThreeThresholdAlgorithm::clusterizeDetUnit(const edm::DetSet<SiStripDigi>& digis, output_t::FastFiller& output) {clusterizeDetUnit_(digis,output);}
130 
131 inline
133 stripByStripBegin(uint32_t id) {
134  if (!setDetId( id )) return false;
135 #ifdef EDM_ML_DEBUG
136  assert(isModuleUsable( id ));
137 #endif
138  clearCandidate();
139  return true;
140 }
141 
142 inline
144 stripByStripAdd(uint16_t strip, uint8_t adc, std::vector<SiStripCluster>& out) {
145  if(candidateEnded(strip)) endCandidate(out);
146  addToCandidate(SiStripDigi(strip,adc));
147 }
148 
149 inline
151 stripByStripEnd(std::vector<SiStripCluster>& out) {
152  endCandidate(out);
153 }
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 chargePerCM(DetId detid, Iter a, Iter b)
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)
SiStripApvShotCleaner ApvCleaner
ThreeThresholdAlgorithm(float, float, float, unsigned, unsigned, unsigned, std::string qualityLabel, bool setDetId, bool removeApvShots, float minGoodCharge)
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
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