Go to the documentation of this file.00001 #include "RecoLocalTracker/SiStripClusterizer/interface/ThreeThresholdAlgorithm.h"
00002 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00003 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00004 #include <cmath>
00005 #include <numeric>
00006
00007 ThreeThresholdAlgorithm::
00008 ThreeThresholdAlgorithm(float chan, float seed, float cluster, unsigned holes, unsigned bad, unsigned adj, std::string qL,
00009 bool setDetId)
00010 : ChannelThreshold( chan ), SeedThreshold( seed ), ClusterThresholdSquared( cluster*cluster ),
00011 MaxSequentialHoles( holes ), MaxSequentialBad( bad ), MaxAdjacentBad( adj ) {
00012 _setDetId=setDetId;
00013 qualityLabel = (qL);
00014 ADCs.reserve(128);
00015 }
00016
00017 template<class digiDetSet>
00018 inline
00019 void ThreeThresholdAlgorithm::
00020 clusterizeDetUnit_(const digiDetSet& digis, output_t::FastFiller& output) {
00021 if( !isModuleUsable( digis.detId() )) return;
00022 setDetId( digis.detId() );
00023
00024 typename digiDetSet::const_iterator
00025 scan( digis.begin() ),
00026 end( digis.end() );
00027
00028 clearCandidate();
00029 while( scan != end ) {
00030 while( scan != end && !candidateEnded( scan->strip() ) )
00031 addToCandidate(*scan++);
00032 endCandidate(output);
00033 }
00034 }
00035
00036 inline
00037 bool ThreeThresholdAlgorithm::
00038 candidateEnded(const uint16_t& testStrip) const {
00039 uint16_t holes = testStrip - lastStrip - 1;
00040 return ( !ADCs.empty() &&
00041 holes > MaxSequentialHoles &&
00042 ( holes > MaxSequentialBad ||
00043 !allBadBetween( lastStrip, testStrip )));
00044 }
00045
00046 inline
00047 void ThreeThresholdAlgorithm::
00048 addToCandidate(const SiStripDigi& digi) {
00049 float Noise = noise( digi.strip() );
00050 if( bad(digi.strip()) || digi.adc() < static_cast<uint16_t>( Noise * ChannelThreshold))
00051 return;
00052
00053 if(candidateLacksSeed) candidateLacksSeed = digi.adc() < static_cast<uint16_t>( Noise * SeedThreshold);
00054 if(ADCs.empty()) lastStrip = digi.strip() - 1;
00055 while( ++lastStrip < digi.strip() ) ADCs.push_back(0);
00056
00057 ADCs.push_back( digi.adc() );
00058 noiseSquared += Noise*Noise;
00059 }
00060
00061 template <class T>
00062 inline
00063 void ThreeThresholdAlgorithm::
00064 endCandidate(T& out) {
00065 if(candidateAccepted()) {
00066 applyGains();
00067 appendBadNeighbors();
00068 out.push_back(SiStripCluster(currentId(), firstStrip(), ADCs.begin(), ADCs.end()));
00069 if (_setDetId) out.back().setId(currentId());
00070 }
00071 clearCandidate();
00072 }
00073
00074 inline
00075 bool ThreeThresholdAlgorithm::
00076 candidateAccepted() const {
00077 return ( !candidateLacksSeed &&
00078 noiseSquared * ClusterThresholdSquared
00079 <= std::pow( std::accumulate(ADCs.begin(),ADCs.end(),float(0)), 2));
00080 }
00081
00082 inline
00083 void ThreeThresholdAlgorithm::
00084 applyGains() {
00085 uint16_t strip = firstStrip();
00086 for( std::vector<uint16_t>::iterator adc = ADCs.begin(); adc != ADCs.end(); adc++) {
00087 if(*adc > 255) throw InvalidChargeException( SiStripDigi(strip,*adc) );
00088 if(*adc > 253) continue;
00089 uint16_t charge = static_cast<uint16_t>( *adc/gain(strip++) + 0.5 );
00090 *adc = ( charge > 1022 ? 255 :
00091 ( charge > 253 ? 254 : charge ));
00092 }
00093 }
00094
00095 inline
00096 void ThreeThresholdAlgorithm::
00097 appendBadNeighbors() {
00098 uint8_t max = MaxAdjacentBad;
00099 while(0 < max--) {
00100 if( bad( firstStrip()-1) ) { ADCs.insert( ADCs.begin(), 0); }
00101 if( bad( lastStrip + 1) ) { ADCs.push_back(0); lastStrip++; }
00102 }
00103 }
00104
00105
00106 void ThreeThresholdAlgorithm::clusterizeDetUnit(const edm::DetSet<SiStripDigi>& digis, output_t::FastFiller& output) {clusterizeDetUnit_(digis,output);}
00107 void ThreeThresholdAlgorithm::clusterizeDetUnit(const edmNew::DetSet<SiStripDigi>& digis, output_t::FastFiller& output) {clusterizeDetUnit_(digis,output);}
00108
00109 inline
00110 bool ThreeThresholdAlgorithm::
00111 stripByStripBegin(uint32_t id) {
00112 if( !isModuleUsable( id )) return false;
00113 setDetId( id );
00114 clearCandidate();
00115 return true;
00116 }
00117
00118 inline
00119 void ThreeThresholdAlgorithm::
00120 stripByStripAdd(uint16_t strip, uint16_t adc, std::vector<SiStripCluster>& out) {
00121 if(candidateEnded(strip))
00122 endCandidate(out);
00123 addToCandidate(SiStripDigi(strip,adc));
00124 }
00125
00126 inline
00127 void ThreeThresholdAlgorithm::
00128 stripByStripEnd(std::vector<SiStripCluster>& out) {
00129 endCandidate(out);
00130 }