How to use RooHistPdf to do 2D fit and plot the fit result?

Hi, root expert,

I use 3 2D Histogram h1, h2, h3 to fit another 2D Histogram h4. I creat 3 RooHistPdf using h1, h2, h3:

        RooDataHist* D1_MC = new RooDataHist("D1_MC", "data", RooArgSet(x,y), h1_D0);
        RooHistPdf pdf_D1("pdf_D1","pdf_D1", RooArgSet(x,y), *D1_MC);

        RooDataHist* psipp_MC = new RooDataHist("psipp_MC", "data", RooArgSet(x,y), h1_psipp_D0);
        RooHistPdf pdf_psipp("pdf_psipp","pdf_psipp", RooArgSet(x,y), *psipp_MC);
        
        RooDataHist* side = new RooDataHist("psipp_MC", "data", RooArgSet(x,y), h1_PHSP_D0);
        RooHistPdf pdf_side("pdf_side","pdf_side", RooArgSet(x,y), *side);
       
then creat a model: 
         RooAddPdf modelxy( "modelxy", "modelxy", RooArgList(pdf_psipp, pdf_D1, pdf_side), RooArgList(N_psipp, N_D1, N_bg));

          then use this model to fit the dataHist:
          RooDataHist* data = new RooDataHist("data", "data", RooArgSet(x,y), dh1_D0);

           modelxy.fitTo(*data);

 I want to plot the fit result using those code:
             TH2* h = modelxy.createHistogram("x,y",60,40);
        h->SetLineColor(kBlue) ;

        RooPlot *xframe = x.frame();
        data->plotOn( xframe);
        modelxy.plotOn( xframe );

        RooPlot *yframe = y.frame();
        data->plotOn( yframe);
        modelxy.plotOn( yframe );

        TCanvas *c = new TCanvas("rf304_uncorrprod","rf304_uncorrprod",1500, 500);
        c->Divide(3);
        c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.1) ; xframe->Draw() ;
        c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.1) ; yframe->Draw() ;
        c->cd(3) ; gPad->SetLeftMargin(0.15) ;  h->Draw() ;

but the model don’t normalize to data.

Hi,

you would need to scale the histogram to th observed number of events. I am not sure, but you might try to use the option RoOFit::Extended(true) in RooAbsReal::createHIstogram, otherwise you would need to rescale your produced histogram by hand calling TH1::Scale

Best Regards

Lorenzo