Hello. I want to use roofit. But my code doesn’t work as I expected.
The histogram is consisted of gaussian and Compton cross section.
Here are code and result.
RooRealVar x("x", "x", 0., 0.8);
// read histogram
TFile* file = new TFile("test.root");
TH1F* roothist1 = (TH1F*)file->Get("h1");
// Reading histogram from existing TH1
RooDataHist* hist = new RooDataHist("Rfit:x", "convo", x, (TH1F*)roothist1);
RooPlot* frame = x.frame(Name("xframe"), Title("convotest"));
// gauss
RooRealVar mean("mean", "mean", 0.25, 0.30);
RooRealVar sigma("sigma", "sigma", 0.15,0.20);
RooGaussian gauss("gauss", "gauss", x, mean, sigma);
//compton
RooRealVar hn("hn", "hn", 0.662);//ev
RooRealVar re("re", "re", 0.00000000000000281794);
RooRealVar me("me", "me", 0.511);//ev
RooFormulaVar s("s", "@0/0.662", RooArgList(x));
RooFormulaVar ga("ga", "@0/@1", RooArgList(hn, me));
RooGenericPdf pdf("function", "function", "1/@2/@2*(@0 *( (@1*@1)/((@2*@2)*(1-@1)*(1-@1)) + @1/(1-@1)*(@1-2/@2) + 2))", RooArgList(me, s, ga));
RooNumConvPdf fff("model", "model", x, pdf,gauss);
x.setBins(100);
gauss.fitTo(*hist);
pdf.fitTo(*hist);
fff.fitTo(*hist);
hist->plotOn(frame, DrawOption("B"), DataError(RooAbsData::None), XErrorSize(0), FillColor(kBlue));
gauss.plotOn(frame, Range(0.05, 0.8), LineColor(kMagenta));
pdf.plotOn(frame, Range(0.05, 0.8), LineColor(kBlack));
fff.plotOn(frame, Range(0.05, 0.8), LineColor(kYellow));
frame->GetYaxis()->SetTitleOffset(1.6);
frame->Draw();
Should I use RooAbsReal?
I think that convolution doesn’t work well.
Thank you for your help.
Regards.
Nea