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, bool removeApvShots)
00010 : ChannelThreshold( chan ), SeedThreshold( seed ), ClusterThresholdSquared( cluster*cluster ),
00011 MaxSequentialHoles( holes ), MaxSequentialBad( bad ), MaxAdjacentBad( adj ), RemoveApvShots(removeApvShots) {
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 if(RemoveApvShots){
00029 ApvCleaner.clean(digis,scan,end);
00030 }
00031
00032 clearCandidate();
00033 while( scan != end ) {
00034 while( scan != end && !candidateEnded( scan->strip() ) )
00035 addToCandidate(*scan++);
00036 endCandidate(output);
00037 }
00038 }
00039
00040 inline
00041 bool ThreeThresholdAlgorithm::
00042 candidateEnded(const uint16_t& testStrip) const {
00043 uint16_t holes = testStrip - lastStrip - 1;
00044 return ( !ADCs.empty() &&
00045 holes > MaxSequentialHoles &&
00046 ( holes > MaxSequentialBad ||
00047 !allBadBetween( lastStrip, testStrip )));
00048 }
00049
00050 inline
00051 void ThreeThresholdAlgorithm::
00052 addToCandidate(const SiStripDigi& digi) {
00053 float Noise = noise( digi.strip() );
00054 if( bad(digi.strip()) || digi.adc() < static_cast<uint16_t>( Noise * ChannelThreshold))
00055 return;
00056
00057 if(candidateLacksSeed) candidateLacksSeed = digi.adc() < static_cast<uint16_t>( Noise * SeedThreshold);
00058 if(ADCs.empty()) lastStrip = digi.strip() - 1;
00059 while( ++lastStrip < digi.strip() ) ADCs.push_back(0);
00060
00061 ADCs.push_back( digi.adc() );
00062 noiseSquared += Noise*Noise;
00063 }
00064
00065 template <class T>
00066 inline
00067 void ThreeThresholdAlgorithm::
00068 endCandidate(T& out) {
00069 if(candidateAccepted()) {
00070 applyGains();
00071 appendBadNeighbors();
00072 out.push_back(SiStripCluster(currentId(), firstStrip(), ADCs.begin(), ADCs.end()));
00073 if (_setDetId) out.back().setId(currentId());
00074 }
00075 clearCandidate();
00076 }
00077
00078 inline
00079 bool ThreeThresholdAlgorithm::
00080 candidateAccepted() const {
00081 return ( !candidateLacksSeed &&
00082 noiseSquared * ClusterThresholdSquared
00083 <= std::pow( std::accumulate(ADCs.begin(),ADCs.end(),float(0)), 2));
00084 }
00085
00086 inline
00087 void ThreeThresholdAlgorithm::
00088 applyGains() {
00089 uint16_t strip = firstStrip();
00090 for( std::vector<uint16_t>::iterator adc = ADCs.begin(); adc != ADCs.end(); adc++) {
00091 if(*adc > 255) throw InvalidChargeException( SiStripDigi(strip,*adc) );
00092 if(*adc > 253) continue;
00093 uint16_t charge = static_cast<uint16_t>( *adc/gain(strip++) + 0.5 );
00094 *adc = ( charge > 1022 ? 255 :
00095 ( charge > 253 ? 254 : charge ));
00096 }
00097 }
00098
00099 inline
00100 void ThreeThresholdAlgorithm::
00101 appendBadNeighbors() {
00102 uint8_t max = MaxAdjacentBad;
00103 while(0 < max--) {
00104 if( bad( firstStrip()-1) ) { ADCs.insert( ADCs.begin(), 0); }
00105 if( bad( lastStrip + 1) ) { ADCs.push_back(0); lastStrip++; }
00106 }
00107 }
00108
00109
00110 void ThreeThresholdAlgorithm::clusterizeDetUnit(const edm::DetSet<SiStripDigi>& digis, output_t::FastFiller& output) {clusterizeDetUnit_(digis,output);}
00111 void ThreeThresholdAlgorithm::clusterizeDetUnit(const edmNew::DetSet<SiStripDigi>& digis, output_t::FastFiller& output) {clusterizeDetUnit_(digis,output);}
00112
00113 inline
00114 bool ThreeThresholdAlgorithm::
00115 stripByStripBegin(uint32_t id) {
00116 if( !isModuleUsable( id )) return false;
00117 setDetId( id );
00118 clearCandidate();
00119 return true;
00120 }
00121
00122 inline
00123 void ThreeThresholdAlgorithm::
00124 stripByStripAdd(uint16_t strip, uint16_t adc, std::vector<SiStripCluster>& out) {
00125 if(candidateEnded(strip))
00126 endCandidate(out);
00127 addToCandidate(SiStripDigi(strip,adc));
00128 }
00129
00130 inline
00131 void ThreeThresholdAlgorithm::
00132 stripByStripEnd(std::vector<SiStripCluster>& out) {
00133 endCandidate(out);
00134 }