CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
fitUtilities.h File Reference
#include <vector>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include "TH1.h"
#include "TF1.h"
#include "TMath.h"
#include "DQMServices/Core/interface/MonitorElement.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

Go to the source code of this file.

Classes

class  fitUtilities
 

Functions

double Gauss (double *x, double *par)
 
double langaufun (double *x, double *par)
 
int32_t langaupro (double *params, double &maxx, double &FWHM)
 

Function Documentation

double Gauss ( double *  x,
double *  par 
)

Definition at line 225 of file fitUtilities.h.

References HLT_25ns14e33_v1_cff::noise.

Referenced by fitUtilities::doGaussFit().

226 {
227  // The noise function: a gaussian
228 
229  double arg = 0;
230  if (par[2]) arg = (x[0] - par[1])/par[2];
231 
232  double noise = par[0]*TMath::Exp(-0.5*arg*arg);
233  return noise;
234 }
A arg
Definition: Factorize.h:36
T x() const
Cartesian x coordinate.
double langaufun ( double *  x,
double *  par 
)

@ class fitUtilities @ fit Landau distributions to historic monitoring elements @ fits from Susy's analysis (DQM/SiStripHistoricInfoClient/test/TrendsWithFits)

Definition at line 66 of file fitUtilities.h.

References i, np, and relval_parameters_module::step.

66  {
67  //Fit parameters:
68  //par[0]=Width (scale) parameter of Landau density
69  //par[1]=Most Probable (MP, location) parameter of Landau density
70  //par[2]=Total area (integral -inf to inf, normalization constant)
71  //par[3]=Width (sigma) of convoluted Gaussian function
72  //
73  //In the Landau distribution (represented by the CERNLIB approximation),
74  //the maximum is located at x=-0.22278298 with the location parameter=0.
75  //This shift is corrected within this function, so that the actual
76  //maximum is identical to the MP parameter.
77 
78  // Numeric constants
79  double invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
80  double mpshift = -0.22278298; // Landau maximum location
81 
82  // Control constants
83  double np = 100.0; // number of convolution steps
84  double sc = 5.0; // convolution extends to +-sc Gaussian sigmas
85 
86  // Variables
87  double xx;
88  double mpc;
89  double fland;
90  double sum = 0.0;
91  double xlow,xupp;
92  double step;
93  double i;
94 
95 
96  // MP shift correction
97  mpc = par[1] - mpshift * par[0];
98 
99  // Range of convolution integral
100  xlow = x[0] - sc * par[3];
101  xupp = x[0] + sc * par[3];
102 
103  step = (xupp-xlow) / np;
104 
105  // Landau Distribution Production
106  for(i=1.0; i<=np/2; i++) {
107  xx = xlow + (i-.5) * step;
108  fland = TMath::Landau(xx,mpc,par[0]) / par[0];
109  sum += fland * TMath::Gaus(x[0],xx,par[3]);
110 
111  xx = xupp - (i-.5) * step;
112  fland = TMath::Landau(xx,mpc,par[0]) / par[0];
113  sum += fland * TMath::Gaus(x[0],xx,par[3]);
114  }
115 
116  return (par[2] * step * sum * invsq2pi / par[3]);
117 }
int i
Definition: DBlmapReader.cc:9
T x() const
Cartesian x coordinate.
int np
Definition: AMPTWrapper.h:33
int32_t langaupro ( double *  params,
double &  maxx,
double &  FWHM 
)

Definition at line 120 of file fitUtilities.h.

References Abs(), alignCSCRings::e, i, prof2calltree::l, langaufun(), AlCaHLTBitMon_ParallelJobs::p, relval_parameters_module::step, and x().

Referenced by MuonTestSummary::doEnergyTests(), and fitUtilities::doLanGaussFit().

120  {
121  edm::LogInfo("fitUtility") << "inside langaupro " << std::endl;
122  // Seaches for the location (x value) at the maximum of the
123  // Landau and its full width at half-maximum.
124  //
125  // The search is probably not very efficient, but it's a first try.
126 
127  double p,x,fy,fxr,fxl;
128  double step;
129  double l,lold,dl;
130  int32_t i = 0;
131  const int32_t MAXCALLS = 10000;
132  const double dlStop = 1e-3; // relative change < .001
133 
134  // Search for maximum
135  p = params[1] - 0.1 * params[0];
136  step = 0.05 * params[0];
137  lold = -2.0;
138  l = -1.0;
139 
140  dl = (l-lold)/lold; // FIXME catch divide by zero
141  while ( (TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
142  i++;
143 
144  lold = l;
145  x = p + step;
146  l = langaufun(&x,params);
147  dl = (l-lold)/lold; // FIXME catch divide by zero
148 
149  if (l < lold)
150  step = -step/10;
151 
152  p += step;
153  }
154 
155  if (i == MAXCALLS)
156  return (-1);
157 
158  maxx = x;
159 
160  fy = l/2;
161 
162 
163  // Search for right x location of fy
164  p = maxx + params[0];
165  step = params[0];
166  lold = -2.0;
167  l = -1e300;
168  i = 0;
169 
170  dl = (l-lold)/lold; // FIXME catch divide by zero
171  while ( ( TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
172  i++;
173 
174  lold = l;
175  x = p + step;
176  l = TMath::Abs(langaufun(&x,params) - fy);
177  dl = (l-lold)/lold; // FIXME catch divide by zero
178 
179  if (l > lold)
180  step = -step/10;
181 
182  p += step;
183  }
184 
185  if (i == MAXCALLS)
186  return (-2);
187 
188  fxr = x;
189 
190 
191  // Search for left x location of fy
192  p = maxx - 0.5 * params[0];
193  step = -params[0];
194  lold = -2.0;
195  l = -1e300;
196  i = 0;
197 
198  dl = (l-lold)/lold; // FIXME catch divide by zero
199  while ( ( TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
200  i++;
201 
202  lold = l;
203  x = p + step;
204  l = TMath::Abs(langaufun(&x,params) - fy);
205  dl = (l-lold)/lold; // FIXME catch divide by zero
206 
207  if (l > lold)
208  step = -step/10;
209 
210  p += step;
211  }
212 
213  if (i == MAXCALLS)
214  return (-3);
215 
216 
217  fxl = x;
218 
219  FWHM = fxr - fxl;
220  return (0);
221 }
int i
Definition: DBlmapReader.cc:9
T x() const
Cartesian x coordinate.
T Abs(T a)
Definition: MathUtil.h:49
Double_t langaufun(Double_t *x, Double_t *par)