2D interpolation using moment morphing

Hi Lorenzo,

Thanks for your answer after the changes you suggested it works but these errors come up which are related to the plotting.

[#1] INFO:ObjectHandling -- RooWorkspace::exportToCint(w) INFO: references to all objects in this workspace will be created in CINT in 'namespace w'
[#0] ERROR:Plotting -- RooGaussian::gaussian1:plotOn: WARNING: variable is not an explicit dependent: alpha
[#0] ERROR:Plotting -- RooGaussian::gaussian1:plotOn: WARNING: variable is not an explicit dependent: alpha
[#0] ERROR:Plotting -- RooGaussian::gaussian1:createPlotProjection: "alpha" is not a dependent and will be ignored.
[#0] ERROR:Plotting -- RooGaussian::gaussian2:plotOn: WARNING: variable is not an explicit dependent: alpha
[#0] ERROR:Plotting -- RooGaussian::gaussian2:plotOn: WARNING: variable is not an explicit dependent: alpha
[#0] ERROR:Plotting -- RooGaussian::gaussian2:createPlotProjection: "alpha" is not a dependent and will be ignored.

The code has been changed like this after your suggestions:

// This example builds two normal distributions and uses moment morphing to
// interpolate between the templates using RooFit.
using namespace RooFit;

// Create a persistable container for RooFit projects, allowing to use a simplified
// scripting language to build the p.d.f.s needed in this example
RooWorkspace w("w", 1);

// Build two normal distributions, corresponding to different values in the morph
 // parameter space. They share the same observable, but have otherwise different
 // moments, i.e. mean and width.
 w.factory("RooGaussian::gaussian1(obs[0,400],50,15)");
 w.factory("RooGaussian::gaussian2(obs,300,40)");

 // Build a RooMomentMorph p.d.f. which interpolates between the normal distributions
 // created before. The interpolation is parametrized by the parameter alpha and the
 // reference templates map to alpha=0 and alpha=1 respectively.
 w.factory("RooMomentMorph::morphpdf(alpha[0,1],obs,{gaussian1,gaussian2},{0,1})");

 // Set the morphing parameter alpha explicitly to 0.5.
 //w::alpha->setVal(0.5);
 w.var("alpha")->setVal(0.5); 

 // Create a frame to draw the p.d.f. from before and show the input templates as
 // solid blue curves and the moment morph p.d.f. at alpha=0.5 in dashed red.
 RooPlot* frame = w.var("alpha")->frame();
 w.pdf("gaussian1")->plotOn(frame, LineColor(kBlue), LineStyle(kSolid));
 w.pdf("gaussian2")->plotOn(frame, LineColor(kBlue), LineStyle(kSolid));
 w.pdf("morphpdf")->plotOn(frame, LineColor(kRed), LineStyle(kDashed));
 frame->Draw();

Best regards,

Diallo.