CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
LASPeakFinder Class Reference

#include <LASPeakFinder.h>

Public Member Functions

bool FindPeakIn (const LASModuleProfile &, std::pair< double, double > &, TH1D *, const double)
 
 LASPeakFinder ()
 
void SetAmplitudeThreshold (double)
 

Private Attributes

double amplitudeThreshold
 

Detailed Description

class for fitting laser peaks in a LASModuleProfile; (will replace BeamProfileFitter)

Definition at line 19 of file LASPeakFinder.h.

Constructor & Destructor Documentation

◆ LASPeakFinder()

LASPeakFinder::LASPeakFinder ( )

Definition at line 7 of file LASPeakFinder.cc.

References amplitudeThreshold.

7  {
8  amplitudeThreshold = 0.; // default
9 }
double amplitudeThreshold
Definition: LASPeakFinder.h:26

Member Function Documentation

◆ FindPeakIn()

bool LASPeakFinder::FindPeakIn ( const LASModuleProfile aProfile,
std::pair< double, double > &  result,
TH1D *  histogram,
const double  offset 
)

set a profile to work on and start peak finding; the pair<> will return mean/meanError (in strips); offset is necessary for tob modules which are hit off-center

Definition at line 16 of file LASPeakFinder.cc.

References amplitudeThreshold, DMR_cfg::cerr, MillePedeFileConverter_cfg::e, siStripLACalibration::fitFunction(), LASModuleProfile::GetValue(), hgchebackDigitizer_cfi::noise, me0TriggerPseudoDigis_cff::nStrips, hltrates_dqm_sourceclient-live_cfg::offset, conifer::pow(), mps_fire::result, mathSSE::sqrt(), and nano_mu_digi_cff::strip.

Referenced by LaserAlignment::endRunProduce().

19  {
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 }
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...
T sqrt(T t)
Definition: SSEVec.h:19
double amplitudeThreshold
Definition: LASPeakFinder.h:26

◆ SetAmplitudeThreshold()

void LASPeakFinder::SetAmplitudeThreshold ( double  aThreshold)

Definition at line 106 of file LASPeakFinder.cc.

References amplitudeThreshold.

Referenced by LaserAlignment::endRunProduce().

106 { amplitudeThreshold = aThreshold; }
double amplitudeThreshold
Definition: LASPeakFinder.h:26

Member Data Documentation

◆ amplitudeThreshold

double LASPeakFinder::amplitudeThreshold
private

Definition at line 26 of file LASPeakFinder.h.

Referenced by FindPeakIn(), LASPeakFinder(), and SetAmplitudeThreshold().