CMS 3D CMS Logo

LASProfileJudge.cc

Go to the documentation of this file.
00001 
00002 
00003 #include "Alignment/LaserAlignment/src/LASProfileJudge.h"
00004 
00005 
00006 // terminal colors
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   // switch on the zero filter by default
00019   isZeroFilter = true;
00020 
00021 }
00022 
00023 
00024 
00025 
00026 
00032 bool LASProfileJudge::IsSignalIn( const LASModuleProfile& aProfile, int offset ) {
00033 
00034   profile = aProfile;
00035   
00036   double negativity = GetNegativity( offset );
00037   bool isPeaks = IsPeaksInProfile( offset );
00038   bool isNegativePeaks = IsNegativePeaksInProfile( offset );
00039   
00040   bool result = 
00041     ( negativity < -1000. ) ||  // if we see negativity, there was laser..
00042     ( isPeaks )             ||  // if we see a peak, " " "
00043     ( isNegativePeaks );    // same here
00044   
00045   return( result );
00046 
00047 
00048 }
00049 
00050 
00051 
00052 
00053 
00058 bool LASProfileJudge::JudgeProfile( const LASModuleProfile& aProfile, int offset = 0 ) {
00059 
00060   profile = aProfile;
00061   
00062   // run the tests
00063   double negativity = GetNegativity( offset );
00064 
00065   bool isPeaks;
00066   if( isZeroFilter ) isPeaks = true; // disable this test if set in cfg
00067   else isPeaks = IsPeaksInProfile( offset );
00068 
00069   bool isNegativePeaks = IsNegativePeaksInProfile( offset );
00070 
00071   bool result = 
00072     ( negativity > -1000. ) &&  // < 1000. = distorted profile
00073     ( isPeaks )             &&  // want to see a peak (zero filter)
00074     !( isNegativePeaks ); // no negative peaks
00075 
00076   return( result );
00077 
00078 }
00079 
00080 
00081 
00082 
00083 
00087 void LASProfileJudge::EnableZeroFilter( bool zeroFilter ) {
00088 
00089   isZeroFilter = zeroFilter;
00090 
00091 }
00092 
00093 
00094 
00095 
00096 
00102 double LASProfileJudge::GetNegativity( int offset ) {
00103 
00104   // here we could later run the sum only on the affected (pair of) APV
00105 
00106   // expected beam position (in strips)
00107   const unsigned int meanPosition = 256 + offset;
00108   // backplane "alignment hole" (="signal region") approx. half size 
00109   const unsigned int halfWindowSize = 33;
00110   // half size of range over which is summed (must be > halfWindowSize)
00111   const unsigned int sumHalfRange = 128;
00112 
00113   double neg = 0;
00114   
00115   for( unsigned int i = meanPosition - sumHalfRange; i < meanPosition - halfWindowSize; ++i ) {
00116     neg += profile.GetValue( i );
00117   }
00118 
00119   for( unsigned int i = meanPosition + halfWindowSize; i < meanPosition + sumHalfRange; ++i ) {
00120     neg += profile.GetValue( i );
00121   }
00122 
00123   return( neg );
00124 
00125 }
00126 
00127 
00128 
00129 
00134 bool LASProfileJudge::IsPeaksInProfile( int offset ) {
00135 
00136   // expected beam position (in strips)
00137   const unsigned int meanPosition = 256 + offset;
00138   // backplane "alignment hole" approx. half size (in strips)
00139   const unsigned int halfWindowSize = 33;
00140 
00141   bool returnValue = false;
00142   
00143   // calculate average out-of-signal
00144   double average = 0., counterD = 0.;
00145   for( unsigned int strip = 0; strip < 512; ++strip ) {
00146     if( strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize ) {
00147       average += profile.GetValue( strip );
00148       counterD += 1.;
00149     }
00150   }
00151   average /= counterD;
00152 
00153   // find peaks well above noise level
00154   const double noiseLevel = 2.; // to be softcoded..
00155   for( unsigned int strip = meanPosition - halfWindowSize; strip < meanPosition + halfWindowSize; ++strip ) {
00156     if( profile.GetValue( strip ) > ( average + 10. * noiseLevel ) ) { 
00157       returnValue = true;
00158       thePeak.first = strip; thePeak.second = profile.GetValue( strip );
00159       break;
00160     }
00161   }
00162 
00163   return( returnValue );
00164 
00165 }
00166 
00167 
00168 
00169 
00174 bool LASProfileJudge::IsNegativePeaksInProfile( int offset ) {
00175 
00176   // expected beam position in middle of module (in strips)
00177   const unsigned int meanPosition = 256 + offset;
00178   // backplane "alignment hole" approx. half size (in strips)
00179   const unsigned int halfWindowSize = 33;
00180 
00181   bool returnValue = false;
00182   
00183   // calculate average out-of-signal
00184   double average = 0., counterD = 0.;
00185   for( unsigned int strip = 0; strip < 512; ++strip ) {
00186     if( strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize ) {
00187       average += profile.GetValue( strip );
00188       counterD += 1.;
00189     }
00190   }
00191   average /= counterD;
00192   
00193   // find strips with negative amplitude way above noise level
00194   const double noiseLevel = 2.;
00195   for( unsigned int strip = 0; strip < 512; ++strip ) {
00196     if( profile.GetValue( strip ) < ( average - 10. * noiseLevel ) ) { 
00197       returnValue = true;
00198       thePeak.first = strip; thePeak.second = profile.GetValue( strip );
00199       break;
00200     }
00201   }
00202 
00203   return( returnValue );
00204 
00205 }

Generated on Tue Jun 9 17:24:09 2009 for CMSSW by  doxygen 1.5.4