{ using namespace RooFit; // Model built with Low Level Factory RooWorkspace w("CMGWs","CMG workspace"); w.factory("Gaussian::signal(imass[105,140],sigmean[115,105,120],sigwidth[1,0,4])"); w.factory("Exponential::background(imass,exppar[-.1,-1,0])"); w.factory("SUM::model(nsig[150,0,10000]*signal,nbkg[1000,0,10000]*background)"); // Generate a toy sample according to the expected number of events RooRealVar* imass= w.var("imass"); RooAbsPdf* model = w.pdf("model"); RooDataSet *data = model->generate(*imass,Extended()); // ML fit of the model to the data model->fitTo(*data); // Plot everything on a frame RooPlot* imassframe = imass->frame(); data->plotOn(imassframe); model->plotOn(imassframe); model->plotOn(imassframe,Components(*w.pdf("background")),LineStyle(kDashed)); imassframe->Draw(); }