CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LASProfileJudge.cc
Go to the documentation of this file.
1 
2 
4 
5 
6 // terminal colors
7 #define _R "\033[1;31m"
8 #define _B "\033[1;34m"
9 #define _G "\033[1;32m"
10 #define _N "\033[22;30m"
11 
12 
17  overdriveThreshold(0)
18 {
19 
20  // switch on the zero filter by default
21  isZeroFilter = true;
22 
23 }
24 
25 
26 
27 
28 
34 bool LASProfileJudge::IsSignalIn( const LASModuleProfile& aProfile, double offset ) {
35 
36  profile = aProfile;
37 
38  // need only approx values, so cast here to use integers throughout
39  const int approxOffset = static_cast<int>( offset );
40 
41  const double negativity = GetNegativity( approxOffset );
42  const bool isPeaks = IsPeaksInProfile( approxOffset );
43  const bool isNegativePeaks = IsNegativePeaksInProfile( approxOffset );
44 
45  bool result =
46  ( negativity < -1000. ) || // if we see negativity, there was laser..
47  ( isPeaks ) || // if we see a peak, " " "
48  ( isNegativePeaks ); // same here
49 
50  return( result );
51 
52 
53 }
54 
55 
56 
57 
58 
63 bool LASProfileJudge::JudgeProfile( const LASModuleProfile& aProfile, double offset = 0. ) {
64 
65  profile = aProfile;
66 
67  // need only approx values, so cast here to use integers throughout
68  const int approxOffset = static_cast<int>( offset );
69 
70  // run the tests
71  const double negativity = GetNegativity( approxOffset );
72 
73  bool isPeaks;
74  if( !isZeroFilter ) isPeaks = true; // disable this test if set in cfg
75  else isPeaks = IsPeaksInProfile( approxOffset );
76 
77  const bool isNegativePeaks = IsNegativePeaksInProfile( approxOffset );
78 
79  bool isOverdrive; // disable this test if set in cfg
80  if( !isZeroFilter ) isOverdrive = false;
81  else isOverdrive = IsOverdrive( approxOffset );
82 
83  bool result =
84  ( negativity > -1000. ) && // < 1000. = distorted profile
85  ( isPeaks ) && // want to see a peak (zero filter)
86  !( isNegativePeaks ) && // no negative peaks
87  !( isOverdrive ); // no overdrive
88 
89  return( result );
90 
91 }
92 
93 
94 
95 
96 
100 void LASProfileJudge::EnableZeroFilter( bool zeroFilter ) {
101 
102  if( !zeroFilter ) {
103  std::cerr << " [LASProfileJudge::EnableZeroFilter] ** WARNING: Zero filter has been disabled." << std::endl;
104  }
105 
106  isZeroFilter = zeroFilter;
107 
108 }
109 
110 
111 
112 
113 
117 void LASProfileJudge::SetOverdriveThreshold( unsigned int aThreshold ) {
118 
119  overdriveThreshold = aThreshold;
120 
121 }
122 
123 
124 
125 
126 
133 
134  // here we could later run the sum only on the affected (pair of) APV
135 
136  // expected beam position (in strips)
137  const unsigned int meanPosition = 256 + offset;
138  // backplane "alignment hole" (="signal region") approx. half size
139  const unsigned int halfWindowSize = 33;
140  // half size of range over which is summed (must be > halfWindowSize)
141  const unsigned int sumHalfRange = 128;
142 
143  double neg = 0;
144 
145  // need only x values, so cast here
146  for( unsigned int i = meanPosition - sumHalfRange; i < meanPosition - halfWindowSize; ++i ) {
147  neg += profile.GetValue( i );
148  }
149 
150  for( unsigned int i = meanPosition + halfWindowSize; i < meanPosition + sumHalfRange; ++i ) {
151  neg += profile.GetValue( i );
152  }
153 
154  return( neg );
155 
156 }
157 
158 
159 
160 
166 
167  // expected beam position (in strips)
168  const unsigned int meanPosition = 256 + offset;
169  // backplane "alignment hole" approx. half size (in strips)
170  const unsigned int halfWindowSize = 33;
171 
172  bool returnValue = false;
173 
174  // calculate average out-of-signal
175  double average = 0., counterD = 0.;
176  for( unsigned int strip = 0; strip < 512; ++strip ) {
177  if( strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize ) {
178  average += profile.GetValue( strip );
179  counterD += 1.;
180  }
181  }
182  average /= counterD;
183 
184  // find peaks well above noise level
185  const double noiseLevel = 2.; // to be softcoded..
186  for( unsigned int strip = meanPosition - halfWindowSize; strip < meanPosition + halfWindowSize; ++strip ) {
187  if( profile.GetValue( strip ) > ( average + 10. * noiseLevel ) ) {
188  returnValue = true;
189  thePeak.first = strip; thePeak.second = profile.GetValue( strip );
190  break;
191  }
192  }
193 
194  return( returnValue );
195 
196 }
197 
198 
199 
200 
206 
207  // expected beam position in middle of module (in strips)
208  const unsigned int meanPosition = 256 + offset;
209  // backplane "alignment hole" approx. half size (in strips)
210  const unsigned int halfWindowSize = 33;
211 
212  bool returnValue = false;
213 
214  // calculate average out-of-signal
215  double average = 0., counterD = 0.;
216  for( unsigned int strip = 0; strip < 512; ++strip ) {
217  if( strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize ) {
218  average += profile.GetValue( strip );
219  counterD += 1.;
220  }
221  }
222  average /= counterD;
223 
224  // find strips with negative amplitude way above noise level
225  const double noiseLevel = 2.;
226  for( unsigned int strip = 0; strip < 512; ++strip ) {
227  if( profile.GetValue( strip ) < ( average - 10. * noiseLevel ) ) {
228  returnValue = true;
229  thePeak.first = strip; thePeak.second = profile.GetValue( strip );
230  break;
231  }
232  }
233 
234  return( returnValue );
235 
236 }
237 
238 
239 
240 
241 
247 
248 
249  // expected beam position in middle of module (in strips)
250  const unsigned int meanPosition = 256 + offset;
251  // backplane "alignment hole" approx. half size (in strips)
252  const unsigned int halfWindowSize = 33;
253 
254  // find maximum strip amplitude in range
255  for( unsigned int strip = meanPosition - halfWindowSize; strip < meanPosition + halfWindowSize; ++strip ) {
256  if( profile.GetValue( strip ) > overdriveThreshold ) return true;
257  }
258 
259  return false;
260 
261 }
bool IsSignalIn(const LASModuleProfile &, double)
int i
Definition: DBlmapReader.cc:9
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
bool IsNegativePeaksInProfile(int)
double GetValue(unsigned int theStripNumber) const
LASModuleProfile profile
bool IsPeaksInProfile(int)
tuple result
Definition: query.py:137
bool JudgeProfile(const LASModuleProfile &, double)
std::pair< unsigned int, double > thePeak
unsigned int offset(bool)
unsigned int overdriveThreshold
void SetOverdriveThreshold(unsigned int)
int average
Definition: PDRates.py:137
double GetNegativity(int)
void EnableZeroFilter(bool)