1 #ifndef DQM_SiStripHistoricInfoClient_fitUtilities_H
2 #define DQM_SiStripHistoricInfoClient_fitUtilities_H
25 int32_t
langaupro(
double *params,
double &maxx,
double &FWHM);
63 #endif // DQM_SiStripHistoricInfoClient_fitUtilities_H
79 double invsq2pi = 0.3989422804014;
80 double mpshift = -0.22278298;
97 mpc = par[1] - mpshift * par[0];
100 xlow = x[0] - sc * par[3];
101 xupp = x[0] + sc * par[3];
103 step = (xupp-xlow) / np;
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]);
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]);
116 return (par[2] * step * sum * invsq2pi / par[3]);
120 int32_t
langaupro(
double *params,
double &maxx,
double &FWHM) {
121 edm::LogInfo(
"fitUtility") <<
"inside langaupro " << std::endl;
127 double p,
x,fy,fxr,fxl;
131 const int32_t MAXCALLS = 10000;
132 const double dlStop = 1e-3;
135 p = params[1] - 0.1 * params[0];
136 step = 0.05 * params[0];
141 while ( (TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
164 p = maxx + params[0];
171 while ( ( TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
176 l = TMath::Abs(
langaufun(&x,params) - fy);
192 p = maxx - 0.5 * params[0];
199 while ( ( TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
204 l = TMath::Abs(
langaufun(&x,params) - fy);
230 if (par[2]) arg = (x[0] - par[1])/par[2];
232 double noise = par[0]*TMath::Exp(-0.5*arg*arg);
270 if (htoFit->GetEntries()!=0) {
271 edm::LogInfo(
"fitUtility")<<
"Fitting "<< htoFit->GetTitle() <<std::endl;
274 double sv[4], pllo[4], plhi[4];
275 fr[0]=0.5*htoFit->GetMean();
276 fr[1]=3.0*htoFit->GetMean();
279 int32_t imax=htoFit->GetMaximumBin();
280 double xmax=htoFit->GetBinCenter(imax);
281 double ymax=htoFit->GetBinContent(imax);
285 i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
286 i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
288 iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
289 iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
290 double AreaFWHM=htoFit->Integral(iArea[0],iArea[1],
"width");
293 sv[2]=htoFit->Integral(i[0],i[1],
"width");
294 sv[3]=AreaFWHM/(4*ymax);
297 plhi[0]=25.0; plhi[1]=200.0; plhi[2]=1000000.0; plhi[3]=50.0;
298 pllo[0]=1.5 ; pllo[1]=10.0 ; pllo[2]=1.0 ; pllo[3]= 1.0;
301 sprintf(FunName,
"FitfcnLG_%s",htoFit->GetName());
304 langausFit->SetParameters(sv);
305 langausFit->SetParNames(
"Width",
"MP",
"Area",
"GSigma");
307 for (int32_t i=0; i<4; i++) {
308 langausFit->SetParLimits(i,pllo[i],plhi[i]);
312 htoFit->Fit(langausFit,
"R0");
314 langausFit->SetRange(fr[0],fr[1]);
316 std::memcpy((
void*)
epLanGausS, (
void*) langausFit->GetParErrors(), 4*
sizeof(double));
325 edm::LogInfo(
"fitUtility") <<
"langaupro: max " << sPeak << std::endl;
326 edm::LogInfo(
"fitUtility") <<
"langaupro: FWHM " << sFWHM << std::endl;
329 edm::LogError(
"fitUtility") <<
"problem in fitting " << htoFit->GetTitle() <<
" \n\tDefault values of the parameters will be used";
343 return htoFit->GetEntries();
351 if (htoFit->GetEntries()!=0) {
355 double sv[3], pllo[3], plhi[3];
356 fr[0]=htoFit->GetMean()-5*htoFit->GetRMS();
357 fr[1]=htoFit->GetMean()+5*htoFit->GetRMS();
359 int32_t imax=htoFit->GetMaximumBin();
360 double xmax=htoFit->GetBinCenter(imax);
361 double ymax=htoFit->GetBinContent(imax);
365 i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
366 i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
368 iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
369 iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
370 double AreaFWHM=htoFit->Integral(iArea[0],iArea[1],
"width");
372 sv[2]=AreaFWHM/(4*ymax);
374 sv[0]=htoFit->Integral(i[0],i[1],
"width");
376 plhi[0]=1000000.0; plhi[1]=10.0; plhi[2]=10.;
377 pllo[0]=1.5 ; pllo[1]=0.1; pllo[2]=0.3;
379 sprintf(FunName,
"FitfcnLG_%s",htoFit->GetName());
381 gausFit->SetParameters(sv);
382 gausFit->SetParNames(
"Constant",
"GaussPeak",
"Sigma");
384 for (int32_t i=0; i<3; i++) {
385 gausFit->SetParLimits(i,pllo[i],plhi[i]);
389 htoFit->Fit(gausFit,
"R0");
391 gausFit->SetRange(fr[0],fr[1]);
392 gausFit->GetParameters(
pGausS);
393 std::memcpy((
void*)
epGausS, (
void*) gausFit->GetParErrors(), 3*
sizeof(double));
399 edm::LogError(
"fitUtility") <<
"problem in fitting " << htoFit->GetTitle() <<
" \n\tDefault values of the parameters will be used";
412 return htoFit->GetEntries();
417 if(s==
"landau_width")
423 else if(s==
"gauss_sigma")
430 if(s==
"landau_width")
436 else if(s==
"gauss_sigma")
double getLanGaussParErr(std::string s)
double getGaussPar(std::string s)
double doGaussFit(MonitorElement *ME)
double Gauss(double *x, double *par)
double getLanGaussConv(std::string s)
double getLanGaussPar(std::string s)
int32_t langaupro(double *params, double &maxx, double &FWHM)
double getGaussParErr(std::string s)
TH1F * getTH1F(void) const
double doLanGaussFit(MonitorElement *ME)
Double_t langaufun(Double_t *x, Double_t *par)
const double par[8 *NPar][4]