mmgData.SetName('mmgData')
        # w.Import(mmgData)

        ## Define the translated mass
        mmgMassFunc = w.factory('''FormulaVar::mmgMassFunc(
            "((mmgMass - mmgMode) / mmgScale + mmgMode)  - fPho*phoScale/100.",
            {mmgMass, mmgMode[91.2,70,110], mmgScale[1.,0.1,5], fPho, phoScale}
            )''')
        mmgMode = w.var('mmgMode')
        mmgScale = w.var('mmgScale')

        ## Get the nominal model for translation, use rho=2
        model = RooKeysPdf('model', 'model', mmgMass, mmgData, RooKeysPdf.NoMirror, 2)

        ## Sample nominal model to binned data, no Poisson fluctuation
        modelHist = model.createHistogram('mmgMass', 10000)
        modelDH = RooDataHist('modelDH', 'modelDH', RooArgList(mmgMass), modelHist)

        ## Use the sampled model to build a transformed model, interpolation order=2
        tmodel = RooHistPdf('tmodel', 'tmodel', RooArgList(mmgMassFunc),
                            RooArgList(mmgMass), modelDH, 2)


        ## Find the mode of the tmodel.
        mmgMode.setVal(modelHist.GetBinCenter(modelHist.GetMaximumBin()))
        mmgMode.setConstant(True)
        fPho.setConstant(True)

        ## Fit the photon scale
        phoScale.setConstant(False)
        mmgScale.setConstant(True)
data1 = g.generate(ArgSet(x), 10000)

w.var('gm').setVal(-3.)
w.var('gs').setVal(2)
data2 = g.generate(ArgSet(x), 10000)

w.var('gm').setVal(0.)
w.var('gs').setVal(1.)

## 3. Use data 1 to build Keys PDF k1(x|s1,m1)
k = KeysPdf('k', 'k', x, data1, KeysPdf.NoMirror, 2)

## 4. Use k to build HistPDF with _transformed_ x variable t = (x-m)/s
##    h1((x-hm)/hs|m1,s1)
t = w.factory('FormulaVar::t("(x - hm) / hs", {x, hm[0,-5,5], hs[1,0.1,3]})')
hist = k.createHistogram('x', 10000)
dh = DataHist('dh', 'dh', ArgList(x), hist)
h = HistPdf('h', 'h', ArgList(t), ArgList(x), dh, 2)

## 5. Plot results
f1 = x.frame()
f1.SetTitle('Training Data')
data1.plotOn(f1)
g.plotOn(f1)
k.plotOn(f1, LineColor(kRed), LineStyle(kDashed))
h.plotOn(f1, LineColor(kBlack), LineStyle(kDashed))
canvases.next('Training_Data')
f1.Draw()

## 6. Fit h1 to data2 to simulate a "measurement" of m2, s2.
h.fitTo(data2)