Importing a histogram from filename.root into RooStats

Hi RooStats experts,

Would you please give a direction on how to import a histogram from filename.root into RooStats
in order to calculate signal significance?

Thanks in advance,
Luiz Regis

Hello @OtaviusDecius, I think @jonas will be able to help you with this.

Hi @silverweed,

Who is @jonas? RooStats expert?

Thanks
Luiz

Yes, he is our RooFit expert. In the meantime, have you tried looking at the RooStats Tutorials? Maybe you can find your answer there.

Yes, I am relying on the templates SimpleHypoTest.C and GausExpModel.C. I have modified the example to include the Breit-Wigner signal function on a Gaussian background (BreitGausModel2.C included in the attachment). My main difficulty is that I could not make it to import my data histogram into the data statement as follows:

RooWorkspace w(“w”);
w.factory(“Gaussian:bkg_pdf(x[0,10], mass1[3.5,3.7], sigma1[0.1,0.3])”);
w.factory(“BreitWigner:sig_pdf(x, mass2[3.4,3.5], sigma2[0.002,.010])”);

w.factory(“SUM:model(nsig[0,10000]*sig_pdf, nbkg[0,10000]*bkg_pdf)”); // for extended model

RooAbsPdf * pdf = w.pdf(“model”);
RooRealVar * x = w.var(“x”); // the observable

// set the desired value of signal and background events
w.var(“nsig”)->setVal(nsig);
w.var(“nbkg”)->setVal(nbkg);

// generate the data

TFile* f = new TFile(“entire2018-83.root”);

TH1 *omegas;
f->GetObject(“/demo/hm6rec2OSomegas”,omegas);

std::cout<<" omegas = "<<omegas<<std::endl;

RooDataHist dh(“dh”, “dh”, *x, Import(*omegas));

RooPlot *frame = x->frame(Title(“Imported TH1 with Poisson error bars”));
dh.plotOn(frame);

// use fixed random numbers for reproducibility (use 0 for changing every time)
////RooRandom::randomGenerator()->SetSeed(111);

// fix number of bins to 50 to plot or to generate data (default is 100 bins)
x->setBins(100);

RooDataSet data(“data”, “data”, RooArgSet(*x), Import(*omegas)); <----------???

w.import(data);

//data->Print();
data.Print();

RooPlot * plot = x->frame(Title(“Breit-Wigner Signal over Gaussian Background”));
//data->plotOn(plot);
data.plotOn(plot);
plot->Draw();

//RooFitResult * r = pdf->fitTo(*data, RooFit::Save(true), RooFit::Minimizer(“Minuit2”,“Migrad”));
RooFitResult * r = pdf->fitTo(data, RooFit::Save(true), RooFit::Minimizer(“Minuit2”,“Migrad”));
r->Print();

pdf->plotOn(plot);
//draw the two separate pdf’s
pdf->plotOn(plot, RooFit::Components(“bkg_pdf”), RooFit::LineStyle(kDashed) );
pdf->plotOn(plot, RooFit::Components(“sig_pdf”), RooFit::LineColor(kRed), RooFit::LineStyle(kDashed) );

pdf->paramOn(plot,Layout(0.5,0.9,0.85));

plot->Draw();

Best,
Luiz
BreitGausModel2.C (3.2 KB)

I figured out I do not need RooDataSet. Instead, I can use RooDataHis directly:

RooDataHist dh(“dh”, “dh”, *x, Import(*omegas));

w.import(dh);

//data->Print();
// data.Print();
dh.Print();

RooPlot * plot = x->frame(Title(“Breit-Wigner Signal over Gaussian Background”));
//data->plotOn(plot);
// data.plotOn(plot);
dh.plotOn(plot);
plot->Draw();

//RooFitResult * r = pdf->fitTo(*data, RooFit::Save(true), RooFit::Minimizer(“Minuit2”,“Migrad”));
RooFitResult * r = pdf->fitTo(dh, RooFit::Save(true), RooFit::Minimizer(“Minuit2”,“Migrad”));
r->Print();

pdf->plotOn(plot);
//draw the two separate pdf’s
pdf->plotOn(plot, RooFit::Components(“bkg_pdf”), RooFit::LineStyle(kDashed) );
pdf->plotOn(plot, RooFit::Components(“sig_pdf”), RooFit::LineColor(kRed), RooFit::LineStyle(kDashed) );

pdf->paramOn(plot,Layout(0.5,0.9,0.85));

plot->Draw();