{ // Declare observable x RooRealVar x("x","x",0,10); // Create two Gaussian PDFs: g1 and g2 RooRealVar mean("mean","mean of gaussians",5,0,10); RooRealVar sigma1("sigma1","width of gaussians",0.5); RooRealVar sigma2("sigma2","width of gaussians",1); RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1); RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2); // Build Chebychev polynomial p.d.f. RooRealVar a0("a0","a0",0.5,0.,1.); RooRealVar a1("a1","a1",-0.2,0.,1.); RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)); // Sum the signal components into a composite signal p.d.f. RooRealVar sig1frac("sig1frac","fraction1 in signal",0.8,0.,1.); RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac); // Sum the composite signal and background RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.); RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac); // Generate a data sample of 1000 events in x from model RooDataSet *data = model.generate(x,1000); // Create a new empty workspace RooWorkspace *w = new RooWorkspace("CMGWs","CMG workspace"); // Import model, all its components and data into the workspace w->import(model); w->import(*data); // Print workspace contents w->Print(); // Save the workspace into a ROOT file w->writeToFile("CMG_workspace.root"); }