18 double invsq2pi = 0.3989422804014;
19 double mpshift = -0.22278298;
36 mpc = par[1] - mpshift * par[0];
39 xlow = x[0] - sc * par[3];
40 xupp = x[0] + sc * par[3];
42 step = (xupp-xlow) / np;
45 for(i=1.0; i<=np/2; i++) {
46 xx = xlow + (i-.5) *
step;
47 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
48 sum += fland * TMath::Gaus(x[0],xx,par[3]);
50 xx = xupp - (i-.5) *
step;
51 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
52 sum += fland * TMath::Gaus(x[0],xx,par[3]);
55 return (par[2] * step * sum * invsq2pi / par[3]);
59 int32_t
langaupro(
double *params,
double &maxx,
double &FWHM) {
60 edm::LogInfo(
"fitUtility") <<
"inside langaupro " << std::endl;
66 double p,
x,fy,fxr,fxl;
70 const int32_t MAXCALLS = 10000;
71 const double dlStop = 1
e-3;
74 p = params[1] - 0.1 * params[0];
75 step = 0.05 * params[0];
80 while ( (
TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
103 p = maxx + params[0];
110 while ( (
TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
131 p = maxx - 0.5 * params[0];
138 while ( (
TMath::Abs(dl)>dlStop ) && (i < MAXCALLS) ) {
169 if (par[2]) arg = (x[0] - par[1])/par[2];
171 double noise = par[0]*TMath::Exp(-0.5*arg*arg);
211 if (htoFit->Integral()!=0) {
212 edm::LogInfo(
"fitUtility")<<
"Fitting "<< htoFit->GetTitle() <<std::endl;
215 double sv[4], pllo[4], plhi[4];
216 fr[0]=0.5*htoFit->GetMean();
217 fr[1]=3.0*htoFit->GetMean();
220 int32_t imax=htoFit->GetMaximumBin();
221 double xmax=htoFit->GetBinCenter(imax);
222 double ymax=htoFit->GetBinContent(imax);
226 i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
227 i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
229 iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
230 iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
231 double AreaFWHM=htoFit->Integral(iArea[0],iArea[1],
"width");
234 sv[2]=htoFit->Integral(i[0],i[1],
"width");
235 sv[3]=AreaFWHM/(4*
ymax);
238 plhi[0]=25.0; plhi[1]=200.0; plhi[2]=1000000.0; plhi[3]=50.0;
239 pllo[0]=1.5 ; pllo[1]=10.0 ; pllo[2]=1.0 ; pllo[3]= 1.0;
242 sprintf(FunName,
"FitfcnLG_%s",htoFit->GetName());
245 langausFit->SetParameters(sv);
246 langausFit->SetParNames(
"Width",
"MP",
"Area",
"GSigma");
248 for (int32_t i=0; i<4; i++) {
249 langausFit->SetParLimits(i,pllo[i],plhi[i]);
253 htoFit->Fit(langausFit,
"R0");
255 langausFit->SetRange(fr[0],fr[1]);
257 std::memcpy((
void*)
epLanGausS, (
void*) langausFit->GetParErrors(), 4*
sizeof(double));
266 edm::LogInfo(
"fitUtility") <<
"langaupro: max " << sPeak << std::endl;
267 edm::LogInfo(
"fitUtility") <<
"langaupro: FWHM " << sFWHM << std::endl;
270 edm::LogError(
"fitUtility") <<
"problem in fitting " << htoFit->GetTitle() <<
" \n\tDefault values of the parameters will be used";
284 return htoFit->GetEntries();
293 if (htoFit->Integral()!=0) {
297 double sv[3], pllo[3], plhi[3];
298 fr[0]=htoFit->GetMean()-5*htoFit->GetRMS();
299 fr[1]=htoFit->GetMean()+5*htoFit->GetRMS();
301 int32_t imax=htoFit->GetMaximumBin();
302 double xmax=htoFit->GetBinCenter(imax);
303 double ymax=htoFit->GetBinContent(imax);
307 i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
308 i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
310 iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
311 iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
312 double AreaFWHM=htoFit->Integral(iArea[0],iArea[1],
"width");
314 sv[2]=AreaFWHM/(4*
ymax);
316 sv[0]=htoFit->Integral(i[0],i[1],
"width");
318 plhi[0]=1000000.0; plhi[1]=10.0; plhi[2]=10.;
319 pllo[0]=1.5 ; pllo[1]=0.1; pllo[2]=0.3;
321 sprintf(FunName,
"FitfcnLG_%s",htoFit->GetName());
323 gausFit->SetParameters(sv);
324 gausFit->SetParNames(
"Constant",
"GaussPeak",
"Sigma");
326 for (int32_t i=0; i<3; i++) {
327 gausFit->SetParLimits(i,pllo[i],plhi[i]);
331 htoFit->Fit(gausFit,
"R0");
333 gausFit->SetRange(fr[0],fr[1]);
334 gausFit->GetParameters(
pGausS);
335 std::memcpy((
void*)
epGausS, (
void*) gausFit->GetParErrors(), 3*
sizeof(double));
341 edm::LogError(
"fitUtility") <<
"problem in fitting " << htoFit->GetTitle() <<
" \n\tDefault values of the parameters will be used";
354 return htoFit->GetEntries();
359 if(s==
"landau_width")
365 else if(s==
"gauss_sigma")
372 if(s==
"landau_width")
378 else if(s==
"gauss_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)