Composite pdf not plotting points

I have a composite pdf that plots just fine on the frame:

model.plotOn(sigframe); // works great

But when I then try to plot some points (code below) they all line up near zero:

RooDataSet* xmodel = model.generate(sighep,100);
xmodel->plotOn(sigframe); // yields 100 points along the x-axis

Zooming near the axis I can see that they are non-zero, yet all less by several orders of magnitude than the signal.

Am I wrongly assuming that the two parameter call will work like the gaussian.generate(x,n)? If necessary, how do I transfer the fit parameters into this call?

Thanks, Dave

Hi Dave,

Can you post a complete example? I need a bit more information than the 3 lines of code you sent to be able to help you.

Thanks, Wouter

PS: We now have a new dedicated ‘math&stats’ forum on root.cern.ch. I would like to encourage everybody to post new RooFit questions over there.

This is the last section of the code

[code]…
RooRealVar f1(“f1”,“Fraction from gamma1”,0.85,.1,1.0);
RooRealVar fbkg(“fbkg”,“Gamma fraction”,0.1,0.0,1.0);
RooAddPdf gmodel(“gmodel”,“gmodel”,RooArgList(g1,g2),f1);
RooAddPdf model(“model”,“gmodel+sig”,RooArgList(gmodel,sig),fbkg);

// — Perform extended ML fit of composite PDF to toy data —
RooChi2Var chi2(“chi2”,“chi2”,model,qdc);

RooMinuit m(chi2);
m.migrad();
m.hesse();
m.minos();

RooDataSet* xmodel = model.generate(sighep,100); // this worked except for yielding values near zero

// – Plot histogram and composite PDF overlaid –
TCanvas * Cfit = new TCanvas(“Cfit”,“CHI2 fitting”,1100,700);
RooPlot* sigframe = sighep.frame();

qdc.plotOn(sigframe,MarkerStyle(21)); // default 21

model.plotOn(sigframe);
model.plotOn(sigframe,Components(gauss1),LineColor(kGreen),LineStyle(kDashed));
model.plotOn(sigframe,Components(gauss2),LineColor(kCyan),LineStyle(kDashed));
model.plotOn(sigframe,LineColor(kBlue));
model.plotOn(sigframe,Components(gmodel),LineColor(kRed),LineStyle(kDashed));
model.paramOn(sigframe,Parameters(RooArgSet(f1,k1,w1,fbkg,fracleft,splitting,sigmean,sigwidth)),Layout(0.90,0.60,0.90
));

xmodel->plotOn(sigframe); // shows the points down along the x-axis

sigframe->Draw();[/code]

We now have a new dedicated ‘math&stats’ forum on root.cern.ch
Great.

Hi,

I see nothing obviously wrong… Can you post the result of

xmodel->tree().Scan()

Wouter

Wouter,
Your requested code (+1) was added as shown:

[code]model.tree().Scan() ; //115
xmodel->tree().Scan() ; //116
xmodel->plotOn(sigframe) ;

sigframe->Draw();[/code]

Results in error:

/home/work/hep-roo/hepBi207/./hepBi207x.C:115: error: 'class RooAddPdf' has no member named 'tree' /home/work/hep-roo/hepBi207/./hepBi207x.C:116: error: passing `const TTree' as `this' argument of `virtual Long64_t TTree::Scan(const char*, const char*, const Option_t*, Long64_t, Long64_t)' discards qualifiers

Thanks for the attention to my efforts…

Wouter,
_The included code below takes a toy gaussian and adds a peak finding function. However, I believe that I can say I’ve found that Roofit will not really do what I’m hoping.
_The code below isn’t yielding the model values that it later plots well just a few lines down.
_If I could capture the actual peak values of the model, I could send them to a file. (also, what are the basic point or line plotting functions in RooFit…not in tutorial)
_My goal is to develop a Peak/FWHM “finder”.
_Any other suggestions are welcome.

(thanks for all past helps)

Dave

[code]void peaktest(){

// Test fit of a single Gaussian

gSystem->Load(“libRooFit”);
using namespace RooFit;

bool eml=false;
Double_t uprcut = 4;
Double_t lwrcut = -2;
RooRealVar x(“x”,“x”,lwrcut,uprcut,“x”);

RooRealVar mean(“mean”,“Mean of Gaussian”,1.0,-1.0,3.0);
RooRealVar sigma(“sigma”,“Sigma of Gaussian”,1.0,0.1,2.0);
RooGaussian gauss(“gauss”,“gauss(x,mean,sigma)”,x,mean,sigma);

RooDataSet data = gauss.generate(x,1000);
RooPlot
xframe=x.frame();
data->plotOn(xframe);
xframe->Draw();

// Bin the data
x.setBins(60);
RooDataHist* db = new RooDataHist(“db”,“db”,RooArgSet(x),*data);
// Do chi-squared fit
RooChi2Var chi2(“chi2”,“chi2”,gauss,*db);

RooMinuit m(chi2);
m.migrad();
m.hesse();
m.minos();

// find the peak

Double_t sigVal = lwrcut;
Double_t sigRes = (uprcut-lwrcut)/60 / 5;
double newVal=0;
double pastVal=0;
double farVal=0;

RooDataSet xmodel(“xmodel”,“xmodel”,RooArgSet(x));

while(sigVal < uprcut){
x.setVal(sigVal); // sighep for model
newVal = gauss.getVal();
cout << "newVal= " << newVal << " at x= " << sigVal << endl;
if ((newVal < pastVal) && (pastVal > farVal)) { // if the mid value is higher than both
x.setVal(sigVal-sigRes);
x=(Double_t)pastVal;
xmodel.add(RooArgSet(x)); //contains peak(s)
cout << "peakVal= " << pastVal << " at x= " << (sigVal-sigRes) << endl;
x.setVal(sigVal);
}
sigVal = sigVal + sigRes;
farVal = pastVal;
pastVal = newVal;
}

gauss.plotOn(xframe,LineColor(kBlue));
gauss.paramOn(xframe,Parameters(RooArgSet(mean,sigma)),Layout(0.90,0.58,0.90));

xmodel.plotOn(xframe,LineColor(kGreen));

xframe->Draw();

delete data;
} [/code]

Hi Dave,

I’ll have a look. Sorry for the late reply, I’ve been away for 2 weeks
and am now catching up.

Wouter

Wouter,
Thanks for looking into this.
Part of the problem is recovering the needed values to reconstruct the points to match the curve.
I’d like to be able to place at least 3 points on the graph: one at maximum and two at half-maximum. This would be enough.
Then I’d have those values available for my calibration.
As I understand it…most of this can be easily done on the root side, but some additional graphics utility in roofit would be worth the effort?

Thanks,
Dave