I’d like to do an unbinned fit with a pdf that’s a basic gaussian with fixed parameters and an adjustable linear background. I have an attached data set that should be a small/nonexistent gaussian yield and a basic small slope. I’m a RooFit beginner, so I understand that part of the problem with this is that the a simple m*x+b formula doesn’t normalize to 1, and that the formula will by definition be negative at some point. The linear background should never be negative over the provided range, but I don’t understand how to encode that inequality into a RooFormulaVar.
using namespace RooFit;
void linfit(){
TFile *f = new TFile("Linefit.root");
TTree *t = (TTree*)f->Get("G2 m4 T");
RooRealVar En("Energy","Energy",690,790);
RooRealVar mean("mean","mean",735);
RooRealVar fwhm("fwhm","fwhm",5);
RooGaussian gss("gss","gss",En,mean,fwhm);
RooRealVar c1("c1","c1",1,-1000,1000);
RooRealVar c2("c2","c2",1,-1000,1000);
RooGenericPdf linear("linear","c1+c2*(Energy)",RooArgList(c1,c2,En));
RooRealVar sigy("sigy","sigy",1,0,10000);
RooRealVar bkgy("bkgy","bkgy",1,0,10000);
RooAddPdf model("model","model",RooArgList(gss,linear),RooArgList(sigy,bkgy));
RooDataSet data("data","data",RooArgSet(En),Import(*t));
model.fitTo(data,Range(690,790),Extended());
RooPlot *P = En.frame();
data.plotOn(P);
model.plotOn(P);
model.plotOn(P,Components(gss),LineColor(kRed));
P->Draw();
}
Any assistance is appreciated!
ForumPost.C (852 Bytes)
Linefit.root (318.3 KB)