CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Alignment/LaserAlignment/src/LASProfileJudge.cc

Go to the documentation of this file.
00001 
00002 
00003 #include "Alignment/LaserAlignment/interface/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, double offset ) {
00033 
00034   profile = aProfile;
00035   
00036   // need only approx values, so cast here to use integers throughout
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. ) ||  // if we see negativity, there was laser..
00045     ( isPeaks )             ||  // if we see a peak, " " "
00046     ( isNegativePeaks );    // same here
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   // need only approx values, so cast here to use integers throughout
00066   const int approxOffset = static_cast<int>( offset );
00067 
00068   // run the tests
00069   const double negativity = GetNegativity( approxOffset );
00070 
00071   bool isPeaks;
00072   if( !isZeroFilter ) isPeaks = true; // disable this test if set in cfg
00073   else isPeaks = IsPeaksInProfile( approxOffset );
00074 
00075   const bool isNegativePeaks = IsNegativePeaksInProfile( approxOffset );
00076 
00077   bool isOverdrive; // disable this test if set in cfg
00078   if( !isZeroFilter ) isOverdrive = false;
00079   else isOverdrive = IsOverdrive( approxOffset );
00080 
00081   bool result = 
00082     ( negativity > -1000. ) &&  // < 1000. = distorted profile
00083     ( isPeaks )             &&  // want to see a peak (zero filter)
00084     !( isNegativePeaks )    &&  // no negative peaks
00085     !( isOverdrive );           // no overdrive
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   // here we could later run the sum only on the affected (pair of) APV
00133 
00134   // expected beam position (in strips)
00135   const unsigned int meanPosition = 256 + offset;
00136   // backplane "alignment hole" (="signal region") approx. half size 
00137   const unsigned int halfWindowSize = 33;
00138   // half size of range over which is summed (must be > halfWindowSize)
00139   const unsigned int sumHalfRange = 128;
00140 
00141   double neg = 0;
00142   
00143   // need only x values, so cast here
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   // expected beam position (in strips)
00166   const unsigned int meanPosition = 256 + offset;
00167   // backplane "alignment hole" approx. half size (in strips)
00168   const unsigned int halfWindowSize = 33;
00169 
00170   bool returnValue = false;
00171   
00172   // calculate average out-of-signal
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   // find peaks well above noise level
00183   const double noiseLevel = 2.; // to be softcoded..
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   // expected beam position in middle of module (in strips)
00206   const unsigned int meanPosition = 256 + offset;
00207   // backplane "alignment hole" approx. half size (in strips)
00208   const unsigned int halfWindowSize = 33;
00209 
00210   bool returnValue = false;
00211   
00212   // calculate average out-of-signal
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   // find strips with negative amplitude way above noise level
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   // expected beam position in middle of module (in strips)
00248   const unsigned int meanPosition = 256 + offset;
00249   // backplane "alignment hole" approx. half size (in strips)
00250   const unsigned int halfWindowSize = 33;
00251 
00252   // find maximum strip amplitude in range
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 }