18 double invsq2pi = 0.3989422804014;
19 double mpshift = -0.22278298;
35 mpc = par[1] - mpshift * par[0];
38 xlow = x[0] - sc * par[3];
39 xupp = x[0] + sc * par[3];
41 step = (xupp - xlow) / np;
44 for (i = 1.0; i <= np / 2; i++) {
45 xx = xlow + (i - .5) *
step;
46 fland = TMath::Landau(xx, mpc, par[0]) / par[0];
47 sum += fland * TMath::Gaus(x[0], xx, par[3]);
49 xx = xupp - (i - .5) *
step;
50 fland = TMath::Landau(xx, mpc, par[0]) / par[0];
51 sum += fland * TMath::Gaus(x[0], xx, par[3]);
54 return (par[2] * step * sum * invsq2pi / par[3]);
58 int32_t
langaupro(
double *params,
double &maxx,
double &FWHM) {
59 edm::LogInfo(
"fitUtility") <<
"inside langaupro " << std::endl;
65 double p, x, fy, fxr, fxl;
69 const int32_t MAXCALLS = 10000;
70 const double dlStop = 1
e-3;
73 p = params[1] - 0.1 * params[0];
74 step = 0.05 * params[0];
78 dl = (l - lold) / lold;
79 while ((
TMath::Abs(dl) > dlStop) && (i < MAXCALLS)) {
85 dl = (l - lold) / lold;
101 p = maxx + params[0];
107 dl = (l - lold) / lold;
108 while ((
TMath::Abs(dl) > dlStop) && (i < MAXCALLS)) {
114 dl = (l - lold) / lold;
128 p = maxx - 0.5 * params[0];
134 dl = (l - lold) / lold;
135 while ((
TMath::Abs(dl) > dlStop) && (i < MAXCALLS)) {
141 dl = (l - lold) / lold;
159 double Gauss(
double *x,
double *par) {
164 arg = (x[0] - par[1]) / par[2];
166 double noise = par[0] * TMath::Exp(-0.5 * arg * arg);
215 if (htoFit->Integral() != 0) {
216 edm::LogInfo(
"fitUtility") <<
"Fitting " << htoFit->GetTitle() << std::endl;
219 double sv[4], pllo[4], plhi[4];
220 fr[0] = 0.5 * htoFit->GetMean();
221 fr[1] = 3.0 * htoFit->GetMean();
224 int32_t imax = htoFit->GetMaximumBin();
225 double xmax = htoFit->GetBinCenter(imax);
226 double ymax = htoFit->GetBinContent(imax);
230 i[0] = htoFit->GetXaxis()->FindBin(fr[0]);
231 i[1] = htoFit->GetXaxis()->FindBin(fr[1]);
233 iArea[0] = htoFit->GetXaxis()->FindBin(fr[0]);
234 iArea[1] = htoFit->GetXaxis()->FindBin(fr[1]);
235 double AreaFWHM = htoFit->Integral(iArea[0], iArea[1],
"width");
238 sv[2] = htoFit->Integral(i[0], i[1],
"width");
239 sv[3] = AreaFWHM / (4 *
ymax);
252 sprintf(FunName,
"FitfcnLG_%s", htoFit->GetName());
255 langausFit->SetParameters(sv);
256 langausFit->SetParNames(
"Width",
"MP",
"Area",
"GSigma");
258 for (int32_t i = 0; i < 4; i++) {
259 langausFit->SetParLimits(i, pllo[i], plhi[i]);
263 htoFit->Fit(langausFit,
"R0");
265 langausFit->SetRange(fr[0], fr[1]);
267 std::memcpy((
void *)
epLanGausS, (
void *)langausFit->GetParErrors(), 4 *
sizeof(double));
276 edm::LogInfo(
"fitUtility") <<
"langaupro: max " << sPeak << std::endl;
277 edm::LogInfo(
"fitUtility") <<
"langaupro: FWHM " << sFWHM << std::endl;
279 edm::LogError(
"fitUtility") <<
"problem in fitting " << htoFit->GetTitle()
280 <<
" \n\tDefault values of the parameters will be used";
309 return htoFit->GetEntries();
316 if (htoFit->Integral() != 0) {
319 double sv[3], pllo[3], plhi[3];
320 fr[0] = htoFit->GetMean() - 5 * htoFit->GetRMS();
321 fr[1] = htoFit->GetMean() + 5 * htoFit->GetRMS();
323 int32_t imax = htoFit->GetMaximumBin();
324 double xmax = htoFit->GetBinCenter(imax);
325 double ymax = htoFit->GetBinContent(imax);
329 i[0] = htoFit->GetXaxis()->FindBin(fr[0]);
330 i[1] = htoFit->GetXaxis()->FindBin(fr[1]);
332 iArea[0] = htoFit->GetXaxis()->FindBin(fr[0]);
333 iArea[1] = htoFit->GetXaxis()->FindBin(fr[1]);
334 double AreaFWHM = htoFit->Integral(iArea[0], iArea[1],
"width");
336 sv[2] = AreaFWHM / (4 *
ymax);
338 sv[0] = htoFit->Integral(i[0], i[1],
"width");
347 sprintf(FunName,
"FitfcnLG_%s", htoFit->GetName());
349 gausFit->SetParameters(sv);
350 gausFit->SetParNames(
"Constant",
"GaussPeak",
"Sigma");
352 for (int32_t i = 0; i < 3; i++) {
353 gausFit->SetParLimits(i, pllo[i], plhi[i]);
357 htoFit->Fit(gausFit,
"R0");
359 gausFit->SetRange(fr[0], fr[1]);
360 gausFit->GetParameters(
pGausS);
361 std::memcpy((
void *)
epGausS, (
void *)gausFit->GetParErrors(), 3 *
sizeof(double));
366 edm::LogError(
"fitUtility") <<
"problem in fitting " << htoFit->GetTitle()
367 <<
" \n\tDefault values of the parameters will be used";
389 return htoFit->GetEntries();
394 if (s ==
"landau_width")
398 else if (s ==
"area")
400 else if (s ==
"gauss_sigma")
407 if (s ==
"landau_width")
411 else if (s ==
"area")
413 else if (s ==
"gauss_sigma")
422 else if (s ==
"fwhm")
431 else if (s ==
"mean")
433 else if (s ==
"sigma")
442 else if (s ==
"mean")
444 else if (s ==
"sigma")
int32_t langaupro(double *params, double &maxx, double &FWHM)
double getLanGaussParErr(std::string s)
double doGaussFit(MonitorElement *ME)
double getLanGaussConv(std::string s)
double getGaussParErr(std::string s)
double Gauss(double *x, double *par)
double getLanGaussPar(std::string s)
double langaufun(double *x, double *par)
double getGaussPar(std::string s)
double doLanGaussFit(MonitorElement *ME)