CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LASProfileJudge.cc
Go to the documentation of this file.
1 
2 
4 
5 // terminal colors
6 #define _R "\033[1;31m"
7 #define _B "\033[1;34m"
8 #define _G "\033[1;32m"
9 #define _N "\033[22;30m"
10 
14 LASProfileJudge::LASProfileJudge() : overdriveThreshold(0) {
15  // switch on the zero filter by default
16  isZeroFilter = true;
17 }
18 
24 bool LASProfileJudge::IsSignalIn(const LASModuleProfile& aProfile, double offset) {
25  profile = aProfile;
26 
27  // need only approx values, so cast here to use integers throughout
28  const int approxOffset = static_cast<int>(offset);
29 
30  const double negativity = GetNegativity(approxOffset);
31  const bool isPeaks = IsPeaksInProfile(approxOffset);
32  const bool isNegativePeaks = IsNegativePeaksInProfile(approxOffset);
33 
34  bool result = (negativity < -1000.) || // if we see negativity, there was laser..
35  (isPeaks) || // if we see a peak, " " "
36  (isNegativePeaks); // same here
37 
38  return (result);
39 }
40 
45 bool LASProfileJudge::JudgeProfile(const LASModuleProfile& aProfile, double offset = 0.) {
46  profile = aProfile;
47 
48  // need only approx values, so cast here to use integers throughout
49  const int approxOffset = static_cast<int>(offset);
50 
51  // run the tests
52  const double negativity = GetNegativity(approxOffset);
53 
54  bool isPeaks;
55  if (!isZeroFilter)
56  isPeaks = true; // disable this test if set in cfg
57  else
58  isPeaks = IsPeaksInProfile(approxOffset);
59 
60  const bool isNegativePeaks = IsNegativePeaksInProfile(approxOffset);
61 
62  bool isOverdrive; // disable this test if set in cfg
63  if (!isZeroFilter)
64  isOverdrive = false;
65  else
66  isOverdrive = IsOverdrive(approxOffset);
67 
68  bool result = (negativity > -1000.) && // < 1000. = distorted profile
69  (isPeaks) && // want to see a peak (zero filter)
70  !(isNegativePeaks) && // no negative peaks
71  !(isOverdrive); // no overdrive
72 
73  return (result);
74 }
75 
79 void LASProfileJudge::EnableZeroFilter(bool zeroFilter) {
80  if (!zeroFilter) {
81  std::cerr << " [LASProfileJudge::EnableZeroFilter] ** WARNING: Zero filter has been disabled." << std::endl;
82  }
83 
84  isZeroFilter = zeroFilter;
85 }
86 
90 void LASProfileJudge::SetOverdriveThreshold(unsigned int aThreshold) { overdriveThreshold = aThreshold; }
91 
98  // here we could later run the sum only on the affected (pair of) APV
99 
100  // expected beam position (in strips)
101  const unsigned int meanPosition = 256 + offset;
102  // backplane "alignment hole" (="signal region") approx. half size
103  const unsigned int halfWindowSize = 33;
104  // half size of range over which is summed (must be > halfWindowSize)
105  const unsigned int sumHalfRange = 128;
106 
107  double neg = 0;
108 
109  // need only x values, so cast here
110  for (unsigned int i = meanPosition - sumHalfRange; i < meanPosition - halfWindowSize; ++i) {
111  neg += profile.GetValue(i);
112  }
113 
114  for (unsigned int i = meanPosition + halfWindowSize; i < meanPosition + sumHalfRange; ++i) {
115  neg += profile.GetValue(i);
116  }
117 
118  return (neg);
119 }
120 
126  // expected beam position (in strips)
127  const unsigned int meanPosition = 256 + offset;
128  // backplane "alignment hole" approx. half size (in strips)
129  const unsigned int halfWindowSize = 33;
130 
131  bool returnValue = false;
132 
133  // calculate average out-of-signal
134  double average = 0., counterD = 0.;
135  for (unsigned int strip = 0; strip < 512; ++strip) {
136  if (strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize) {
137  average += profile.GetValue(strip);
138  counterD += 1.;
139  }
140  }
141  average /= counterD;
142 
143  // find peaks well above noise level
144  const double noiseLevel = 2.; // to be softcoded..
145  for (unsigned int strip = meanPosition - halfWindowSize; strip < meanPosition + halfWindowSize; ++strip) {
146  if (profile.GetValue(strip) > (average + 10. * noiseLevel)) {
147  returnValue = true;
148  thePeak.first = strip;
149  thePeak.second = profile.GetValue(strip);
150  break;
151  }
152  }
153 
154  return (returnValue);
155 }
156 
162  // expected beam position in middle of module (in strips)
163  const unsigned int meanPosition = 256 + offset;
164  // backplane "alignment hole" approx. half size (in strips)
165  const unsigned int halfWindowSize = 33;
166 
167  bool returnValue = false;
168 
169  // calculate average out-of-signal
170  double average = 0., counterD = 0.;
171  for (unsigned int strip = 0; strip < 512; ++strip) {
172  if (strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize) {
173  average += profile.GetValue(strip);
174  counterD += 1.;
175  }
176  }
177  average /= counterD;
178 
179  // find strips with negative amplitude way above noise level
180  const double noiseLevel = 2.;
181  for (unsigned int strip = 0; strip < 512; ++strip) {
182  if (profile.GetValue(strip) < (average - 10. * noiseLevel)) {
183  returnValue = true;
184  thePeak.first = strip;
185  thePeak.second = profile.GetValue(strip);
186  break;
187  }
188  }
189 
190  return (returnValue);
191 }
192 
198  // expected beam position in middle of module (in strips)
199  const unsigned int meanPosition = 256 + offset;
200  // backplane "alignment hole" approx. half size (in strips)
201  const unsigned int halfWindowSize = 33;
202 
203  // find maximum strip amplitude in range
204  for (unsigned int strip = meanPosition - halfWindowSize; strip < meanPosition + halfWindowSize; ++strip) {
206  return true;
207  }
208 
209  return false;
210 }
bool IsSignalIn(const LASModuleProfile &, double)
bool IsNegativePeaksInProfile(int)
double GetValue(unsigned int theStripNumber) const
tuple result
Definition: mps_fire.py:311
LASModuleProfile profile
bool IsPeaksInProfile(int)
bool JudgeProfile(const LASModuleProfile &, double)
std::pair< unsigned int, double > thePeak
unsigned int overdriveThreshold
void SetOverdriveThreshold(unsigned int)
int average
Definition: PDRates.py:138
double GetNegativity(int)
void EnableZeroFilter(bool)