Go to the documentation of this file.00001
00002
00003 #include "Alignment/LaserAlignment/interface/LASProfileJudge.h"
00004
00005
00006
00007 #define _R "\033[1;31m"
00008 #define _B "\033[1;34m"
00009 #define _G "\033[1;32m"
00010 #define _N "\033[22;30m"
00011
00012
00016 LASProfileJudge::LASProfileJudge() {
00017
00018
00019 isZeroFilter = true;
00020
00021 }
00022
00023
00024
00025
00026
00032 bool LASProfileJudge::IsSignalIn( const LASModuleProfile& aProfile, double offset ) {
00033
00034 profile = aProfile;
00035
00036
00037 const int approxOffset = static_cast<int>( offset );
00038
00039 const double negativity = GetNegativity( approxOffset );
00040 const bool isPeaks = IsPeaksInProfile( approxOffset );
00041 const bool isNegativePeaks = IsNegativePeaksInProfile( approxOffset );
00042
00043 bool result =
00044 ( negativity < -1000. ) ||
00045 ( isPeaks ) ||
00046 ( isNegativePeaks );
00047
00048 return( result );
00049
00050
00051 }
00052
00053
00054
00055
00056
00061 bool LASProfileJudge::JudgeProfile( const LASModuleProfile& aProfile, double offset = 0. ) {
00062
00063 profile = aProfile;
00064
00065
00066 const int approxOffset = static_cast<int>( offset );
00067
00068
00069 const double negativity = GetNegativity( approxOffset );
00070
00071 bool isPeaks;
00072 if( !isZeroFilter ) isPeaks = true;
00073 else isPeaks = IsPeaksInProfile( approxOffset );
00074
00075 const bool isNegativePeaks = IsNegativePeaksInProfile( approxOffset );
00076
00077 bool isOverdrive;
00078 if( !isZeroFilter ) isOverdrive = false;
00079 else isOverdrive = IsOverdrive( approxOffset );
00080
00081 bool result =
00082 ( negativity > -1000. ) &&
00083 ( isPeaks ) &&
00084 !( isNegativePeaks ) &&
00085 !( isOverdrive );
00086
00087 return( result );
00088
00089 }
00090
00091
00092
00093
00094
00098 void LASProfileJudge::EnableZeroFilter( bool zeroFilter ) {
00099
00100 if( !zeroFilter ) {
00101 std::cerr << " [LASProfileJudge::EnableZeroFilter] ** WARNING: Zero filter has been disabled." << std::endl;
00102 }
00103
00104 isZeroFilter = zeroFilter;
00105
00106 }
00107
00108
00109
00110
00111
00115 void LASProfileJudge::SetOverdriveThreshold( unsigned int aThreshold ) {
00116
00117 overdriveThreshold = aThreshold;
00118
00119 }
00120
00121
00122
00123
00124
00130 double LASProfileJudge::GetNegativity( int offset ) {
00131
00132
00133
00134
00135 const unsigned int meanPosition = 256 + offset;
00136
00137 const unsigned int halfWindowSize = 33;
00138
00139 const unsigned int sumHalfRange = 128;
00140
00141 double neg = 0;
00142
00143
00144 for( unsigned int i = meanPosition - sumHalfRange; i < meanPosition - halfWindowSize; ++i ) {
00145 neg += profile.GetValue( i );
00146 }
00147
00148 for( unsigned int i = meanPosition + halfWindowSize; i < meanPosition + sumHalfRange; ++i ) {
00149 neg += profile.GetValue( i );
00150 }
00151
00152 return( neg );
00153
00154 }
00155
00156
00157
00158
00163 bool LASProfileJudge::IsPeaksInProfile( int offset ) {
00164
00165
00166 const unsigned int meanPosition = 256 + offset;
00167
00168 const unsigned int halfWindowSize = 33;
00169
00170 bool returnValue = false;
00171
00172
00173 double average = 0., counterD = 0.;
00174 for( unsigned int strip = 0; strip < 512; ++strip ) {
00175 if( strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize ) {
00176 average += profile.GetValue( strip );
00177 counterD += 1.;
00178 }
00179 }
00180 average /= counterD;
00181
00182
00183 const double noiseLevel = 2.;
00184 for( unsigned int strip = meanPosition - halfWindowSize; strip < meanPosition + halfWindowSize; ++strip ) {
00185 if( profile.GetValue( strip ) > ( average + 10. * noiseLevel ) ) {
00186 returnValue = true;
00187 thePeak.first = strip; thePeak.second = profile.GetValue( strip );
00188 break;
00189 }
00190 }
00191
00192 return( returnValue );
00193
00194 }
00195
00196
00197
00198
00203 bool LASProfileJudge::IsNegativePeaksInProfile( int offset ) {
00204
00205
00206 const unsigned int meanPosition = 256 + offset;
00207
00208 const unsigned int halfWindowSize = 33;
00209
00210 bool returnValue = false;
00211
00212
00213 double average = 0., counterD = 0.;
00214 for( unsigned int strip = 0; strip < 512; ++strip ) {
00215 if( strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize ) {
00216 average += profile.GetValue( strip );
00217 counterD += 1.;
00218 }
00219 }
00220 average /= counterD;
00221
00222
00223 const double noiseLevel = 2.;
00224 for( unsigned int strip = 0; strip < 512; ++strip ) {
00225 if( profile.GetValue( strip ) < ( average - 10. * noiseLevel ) ) {
00226 returnValue = true;
00227 thePeak.first = strip; thePeak.second = profile.GetValue( strip );
00228 break;
00229 }
00230 }
00231
00232 return( returnValue );
00233
00234 }
00235
00236
00237
00238
00239
00244 bool LASProfileJudge::IsOverdrive( int offset ) {
00245
00246
00247
00248 const unsigned int meanPosition = 256 + offset;
00249
00250 const unsigned int halfWindowSize = 33;
00251
00252
00253 for( unsigned int strip = meanPosition - halfWindowSize; strip < meanPosition + halfWindowSize; ++strip ) {
00254 if( profile.GetValue( strip ) > overdriveThreshold ) return true;
00255 }
00256
00257 return false;
00258
00259 }