using namespace RooFit ; void ex15() { gSystem->Load("libRooFit") ; TFile* f = TFile::Open("ex15.root") ; TH1* h_sig = f->Get("h_sig") ; TH1* h_bkg = f->Get("h_bkg") ; TH1* h_data = f->Get("h_data") ; TH1* h_data_small = f->Get("h_data_small") ; TH1* h_data_large = f->Get("h_data_large") ; // Create a workspace with observable x[0,120] RooWorkspace w("w",1) ; w.factory("x[20,120]") ; w->var("x")->setBins(20) ; // Tie TF1 h_sig to observable x in RooFit binned dataset dh_sig RooDataHist dh_sig("dh_sig","dh_sig",*w.var("x"),h_sig) ; // Same for the other datasets RooDataHist dh_bkg("dh_bkg","dh_bkg",*w.var("x"),h_bkg) ; RooDataHist data("data","data",*w.var("x"),h_data) ; RooDataHist data_small("data_small","data_small",*w.var("x"),h_data_small) ; RooDataHist data_large("data_large","data_large",*w.var("x"),h_data_large) ; // Import both template datasets in the workspace w.import(dh_sig) ; w.import(dh_bkg) ; // Construct yield functions, as done in Ex 10 w.factory("HistFunc::hf_sig(x,dh_sig)") ; w.factory("HistFunc::hf_bkg(x,dh_bkg)") ; // In ex10 we used 100 bins, now we use 20, which causes the // bin width to change from 1 unit of x to 5 units of x. // // This modifies the expected yields with that factor // To keep the original interpretation of the mu and nu // parameters of ex 10, we multiply these with the // inverse of the bin width, i.e. 0.2 w.factory("prod::ksig(mu[1,0,5],binw[0.2])") ; w.factory("prod::kbkg(nu[1],binw)") ; // Construct a probability model from the sum of two yield functions w.factory("ASUM::model(ksig*hf_sig,kbkg*hf_bkg)") ; w.Print("t") ; }