RooFit and Pull plots

Hello,

I’m trying to plot two distributions and then get the pull plot from the two. I’ve run into a problem which I was hoping someone may help me fix? Below is the code

[code]void plot_pull() {
TFile myfile = TFile::Open(“momentum_acc_filtered_plots.root”);
TH1F
pip_d0 = (TH1F*)myfile->Get(“p_pip_d0”);
TH1F* pim_d0 = (TH1F*)myfile->Get(“p_pim_d0”);
TH1F* pip_db = (TH1F*)myfile->Get(“p_pip_db”);
TH1F* pim_db = (TH1F*)myfile->Get(“p_pim_db”);

RooRealVar d0_pip_momentum("p_pip_d0", "p", 0, 120 * 1000);// Declare variables
RooRealVar d0_pim_momentum("p_pim_d0", "p2", 0, 120 * 1000);

RooDataHist h_pip_d0("h_pip_d0", "", d0_pip_momentum, pip_d0);// Declare histograms
RooDataHist h_pip_db("h_pip_db", "", d0_pip_momentum, pip_db);


RooPlot* frame_d0_pip = d0_pip_momentum.frame();// frames

h_pip_d0.plotOn(frame_d0_pip, RooFit::XErrorSize(0), RooFit::Name("plot1"));// plot frames
h_pip_db.plotOn(frame_d0_pip, RooFit::XErrorSize(0), RooFit::MarkerColor(kBlue), RooFit::Name("plot3"));

RooHist* pull = frame_d0_pip->pullHist();
RooPlot* pframe = d0_pip_momentum.frame();
pframe->addPlotable(pull, "P");

TCanvas* c7 = new TCanvas("c7","c7",1000,500);
c7->Divide(2);
c7->cd(1);
gPad->SetLeftMargin(0.15);
frame_d0_pip->GetYaxis()->SetTitleOffset(1.6);
frame_d0_pip->GetXaxis()->SetTitle("Momentum [MeV]");
leg = new TLegend(0.57,0.6,0.89,0.89); 
leg->AddEntry(frame_d0_pip->findObject("plot1"),"#pi^{+}, D^{0}","lp");
leg->AddEntry(frame_d0_pip->findObject("plot3"),"#pi^{-}, #bar{D}^{0}","lp");
leg->SetTextSize(0.05);
frame_d0_pip->Draw();
leg->Draw();
//c7->cd(2);
//gPad->SetLeftMargin(0.15);
//pframe5->GetYaxis()->SetTitleOffset(1.6);
//pframe5->Draw();

}[/code]

When running, I get the error

[#0] ERROR:InputArguments – RooPlot::findObject(frame_p_pip_d0_2d300d0) cannot find object
[#0] ERROR:InputArguments – RooPlot::residHist(frame_p_pip_d0_2d300d0) cannot find curve

and then the program seg faults. It looks like the function to produce the pull histogram can’t find one of the two it is using but I don’t understand why. Could someone please help?

Thanks

Hi,

Looking at your code, you are plotting only the data sets. For making a pull plot you need to plot also a curve (i.e. a pdf)

Lorenzo

Ah, I thought that may have been the problem. I did want to test the statistical compatibility of two histograms so I guess it’s probably easiest if I just code this myself.

Thanks for your help