How to fit array of values in RooFit?

Hello!

How to fit array of values in RooFit?
For example, I have experimental array:

How to fit it?

“RooDataSet” class has “add” method, but its input type is “RooArgSet”.
Have I use “setRealValue” of “RooArgSet” class in order to fill container?

My example:

[code]void RooFit_my()
{
RooRealVar t(“t”,“time”, 0, 250);
RooRealVar tau(“tau”,“tau parameter”, 50, 1, 100);
RooGenericPdf genpdf(“genpdf”,“genpdf”,"( 1 / tau * exp( - t / tau ) )", RooArgSet(t, tau));

double x[5] = {0, 5, 4, 8, 0};
//RooDataSet* data = genpdf.generate(t, 500);

genpdf.fitTo(*data);
tau.Print();

RooPlot* tframe = t.frame(Title("Interpreted expression pdf"));
data->plotOn(tframe);
genpdf.plotOn(tframe);

TCanvas* c = new TCanvas("rf103_interprfuncs","rf103_interprfuncs",800,400);
tframe->GetYaxis()->SetTitleOffset(1.4);
tframe->Draw();

}[/code]

Could you give me a simple example how to fill in RooDataSet object with experimental data?

Hi,

You need to define first one (or more) RooRealVar depending if your data set is one or multi-dimensional.
For example for the simple case you have you can do

 std::vector<double> x = {0, 5, 4, 8, 0};
RooRealVar varx("x","x",-TMath::Infinity(), TMath::Infinity() );  
RooDataSet data("data","data",varx); 
for (unsigned int i = 0; i < x.size(); ++i) { 
	varx.setVal(x[i] ); 
	data.add(varx); 
}
data.Print("v");

Lorenzo

1 Like

Thank you very much!