Hello everyone,
I’ve just begun using RooFit and I have a problem that is quite trivial, I think, but of which I can not find an answer anywhere.
I have to fit in different ways a dataset, I need also to plot these fit in different canvas, or in different sections of the same canvas. To accomplish that I tried to define different RooPlot variables, each from the very same RooRealVar and to draw them, but it does not work because it creates only a canvas.
Here the code ( = the lines where I defined the RooPlot variables):
RooRealVar x("x", "random variable", 0, 2);
RooRealVar mean1("mean1","Mean of Gaussian 1",0.5,0,2);
RooRealVar sigma1("sigma1","Width of Gaussian 1",0.5,0,2) ;
RooGaussian gauss1("gauss1","gauss(x,mean1,sigma1)",x,mean1,sigma1) ;
RooRealVar mean2("mean2","Mean of Gaussian 2",1.9,0,2) ;
RooRealVar sigma2("sigma2","Width of Gaussian 2",0.2,0,2) ;
RooGaussian gauss2("gauss2","gauss(x,mean2,sigma2)",x,mean2,sigma2) ;
RooRealVar tau("tau","Tau exponential",0,-5,1);
RooExponential exponential("exponential","exo(x,-tau)",x,tau) ;
RooRealVar alpha("alpha", "alpha",0.1, 0, 1);
RooRealVar beta("beta", "beta",0.3, 0, 1);
RooRealVar gamma("gamma", "gamma", 0.6, 0, 1);
RooAddPdf initial_model("model","model", RooArgList(gauss1,gauss2,exponential), RooArgList(alpha,beta));
RooAddPdf fit_model("fit_model","fit_model", RooArgList(gauss1,gauss2,exponential), RooArgList(alpha,beta, gamma));
// Fit ML
RooAddPdf model_ml = fit_model;
model_ml.fitTo(hist, RooFit::Extended());
:red_circle: RooPlot *frame_ml = x.frame(RooFit::Name("Fit ML"), RooFit::Title("Fit ML"));
hist.plotOn(frame_ml);
model_ml.plotOn(frame_ml);
frame_ml->Draw();
// Fit EML, already extended
RooAddPdf model_eml = initial_model;
model_eml.fitTo(hist);//already extended
:red_circle: RooPlot *frame_eml = x.frame(RooFit::Name("Fit EML"), RooFit::Title("Fit EML"));
hist.plotOn(frame_eml);
model_eml.plotOn(frame_eml);
frame_eml->Draw();
Thank you for your attntion
Riccardo