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]