using namespace RooFit ; void one(){ // C r e a t e m o d e l w i t h p a r a m e t e r c o n s t r a i n t // --------------------------------------------------------------------------- // Observable RooRealVar x("x","x",-10,10) ; // Signal component RooRealVar m("m","m",0,-10,10) ; RooRealVar s("s","s",2,0.1,10) ; RooGaussian g("g","g",x,m,s) ; // Background component RooPolynomial p("p","p",x) ; // Composite model RooRealVar f("f","f",0.4,0.,1.) ; RooAddPdf sum("sum","sum",RooArgSet(g,p),f) ; // S e t u p t o y s t u d y w i t h m o d e l // --------------------------------------------------- // Perform toy study RooMCStudy mcs(sum,x,Silence(), Extended()); // Run 500 toys of 2000 events. mcs.generateAndFit(500,2000) ; // Make plot of distribution of generated value of f parameter TH1* h_f_gen = mcs.fitParDataSet().createHistogram("f",-40) ; // Make plot of distribution of fitted value of f parameter RooPlot* frame1 = mcs.plotParam(f,Bins(40)) ; frame1->SetTitle("Distribution of fitted f values") ; TCanvas* c = new TCanvas("c","c",1200,600) ; c->Divide(2) ; c->cd(1) ; gPad->SetLeftMargin(0.15) ; h_f_gen->GetYaxis()->SetTitleOffset(1.4) ; h_f_gen->Draw() ; c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ; }