CMS 3D CMS Logo

LASPeakFinder.cc
Go to the documentation of this file.
1 
3 
8  amplitudeThreshold = 0.; // default
9 }
10 
17  std::pair<double, double>& result,
18  TH1D* histogram,
19  const double offset) {
20  // this function will be propagated to the histo output file,
21  // therefore we do some cosmetics already here
22  TF1 fitFunction("fitFunction", "gaus");
23  fitFunction.SetLineColor(2);
24  fitFunction.SetLineWidth(2);
25 
26  std::pair<int, double> largestAmplitude(0, 0.); // strip, amplitude
27  double anAmplitude = 0.;
28 
29  // need approximate position -> cast to int
30  const int approxOffset = static_cast<int>(offset);
31 
32  // expected beam position (in strips)
33  const unsigned int meanPosition = 256 + approxOffset;
34 
35  // backplane "alignment hole" approx. half size (in strips)
36  const unsigned int halfWindowSize = 33;
37 
38  // loop over the strips in the "alignment hole"
39  // to fill the histogram
40  // and determine fit parameter estimates
41  double sum0 = 0.; // this is the sum of all amplitudes
42  for (unsigned int strip = meanPosition - halfWindowSize; strip < meanPosition + halfWindowSize; ++strip) {
43  anAmplitude = aProfile.GetValue(strip);
44  sum0 += anAmplitude;
45  histogram->SetBinContent(1 + strip, anAmplitude);
46  if (anAmplitude > largestAmplitude.second) {
47  largestAmplitude.first = strip;
48  largestAmplitude.second = anAmplitude;
49  }
50  }
51 
52  // loop outside the "alignment hole"
53  // to determine the noise level = sqrt(variance)
54  double sum1 = 0., sum2 = 0.;
55  int nStrips = 0;
56  for (unsigned int strip = 0; strip < 512; ++strip) {
57  if (strip < meanPosition - halfWindowSize || strip > meanPosition + halfWindowSize) {
58  anAmplitude = aProfile.GetValue(strip);
59  sum0 += anAmplitude;
60  sum1 += anAmplitude;
61  sum2 += pow(anAmplitude, 2);
62  nStrips++;
63  }
64  }
65 
66  // noise as sqrt of the amplitude variance
67  const double noise = sqrt(1. / (nStrips - 1) * (sum2 - pow(sum1, 2) / nStrips));
68 
69  // empty profile?
70  if (fabs(sum0) < 1.e-3) {
71  std::cerr << " [LASPeakFinder::FindPeakIn] ** WARNING: Empty profile (sum=" << sum0 << ")." << std::endl;
72  return false;
73  }
74 
75  // no reasonable peak?
76  if (largestAmplitude.second < amplitudeThreshold * noise) {
77  std::cerr << " [LASPeakFinder::FindPeakIn] ** WARNING: No reasonably large peak." << std::endl;
78  return false;
79  }
80 
81  // prepare fit function: starting values..
82  fitFunction.SetParameter(0, largestAmplitude.second); // amp
83  fitFunction.SetParameter(1, largestAmplitude.first); // mean
84  fitFunction.SetParameter(2, 3.); // width
85 
86  // ..and parameter limits
87  fitFunction.SetParLimits(
88  0, largestAmplitude.second * 0.3, largestAmplitude.second * 1.8); // amp of the order of the peak height
89  fitFunction.SetParLimits(
90  1, largestAmplitude.first - 12, largestAmplitude.first + 12); // mean around the peak maximum
91  fitFunction.SetParLimits(2, 0.5, 8.); // reasonable width
92 
93  // fit options: Quiet / all Weights=1 / better Errors / enable fix&Bounds on parameters
94  histogram->Fit(&fitFunction, "QWEB", "", largestAmplitude.first - 12, largestAmplitude.first + 12);
95 
96  // prepare output
97  result.first = fitFunction.GetParameter(1);
98  result.second = fitFunction.GetParError(1);
99 
100  return true;
101 }
102 
106 void LASPeakFinder::SetAmplitudeThreshold(double aThreshold) { amplitudeThreshold = aThreshold; }
double fitFunction(double *x, double *par)
constexpr int pow(int x)
Definition: conifer.h:24
double GetValue(unsigned int theStripNumber) const
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
bool FindPeakIn(const LASModuleProfile &, std::pair< double, double > &, TH1D *, const double)
T sqrt(T t)
Definition: SSEVec.h:19
double amplitudeThreshold
Definition: LASPeakFinder.h:26
void SetAmplitudeThreshold(double)