void generate_test() { //Setting up RooFit gSystem->Load("libRooFit"); using namespace RooFit; //Open histos file TFile *dTR= new TFile("Test_RooFit_D.root"); TFile *eTR= new TFile("Test_RooFit_E.root"); TCanvas *c1= new TCanvas; TH1D* imass_D_mb,*imass_D_elec,*imass_D_mb_ss,*imass_D_elec_ss; TH1D* imass_E_mb,*imass_E_elec,*imass_E_mb_ss,*imass_E_elec_ss; TH1D* imass_D_mb_cont, *hbkg; RooPlot *frame; RooDataHist *mbshape, *mbbkg, *hsignal; //Build the pdf imass_D_mb=(TH1D *)dTR->Get("Z_mass_elec_OS"); imass_E_mb=(TH1D *)eTR->Get("Z_mass_elec_OS"); //Needed for correct errors imass_D_mb->Sumw2(); imass_E_mb->Sumw2(); imass_D_mb->Add(imass_E_mb); imass_D_mb_ss=(TH1D *)dTR->Get("Z_mass_elec_SS"); imass_E_mb_ss=(TH1D *)eTR->Get("Z_mass_elec_SS"); imass_D_mb_ss->Sumw2(); imass_E_mb_ss->Sumw2(); //os-ss imass_D_mb_ss->Scale(-1.); imass_E_mb_ss->Scale(-1.); imass_D_mb->Add(imass_D_mb_ss); imass_D_mb->Add(imass_E_mb_ss); imass_D_mb_cont=imass_D_mb; //Generate bkg to match s/b and save as TH1 //Doesn't work so well - generateBinned gives back less than 250 bins... x = new RooRealVar("x","m_{ee} (GeV)",0.,25.); frame = x->frame(); //input has 250 bins mbshape = new RooDataHist("mbshape", "bkg shape",RooArgList(*x),imass_D_mb_cont); //RooHistPdf plot looks like it has more than 250 bins mbpdf = new RooHistPdf("mbpdf","mbpdf",*x,*mbshape); //Result of generateBinned has much less than 250 bins :-( mbbkg = mbpdf->generateBinned(*x,100000,kTRUE); mbbkg->plotOn(frame, Name("data"), DataError(RooAbsData::SumW2)); frame->Draw(); frame->SetTitle(""); frame->GetYaxis()->SetTitleOffset(1.2); //c1->Print("test_bkg_shape","eps"); hbkg = (TH1D*)mbbkg->createHistogram("hbkg",*x,Binning(250,0.,25.)); hbkg->Sumw2(); hbkg->Draw(); hbkg->GetXaxis()->SetRangeUser(1.,5.); }