Edit: this answer recommends using the RooLinearVar, but it’s probably better to use the more tested RooFormulaVar as explained in my second post.
Hi @Emil_R,
it’s still a good question though!
You can’t create a RooHistPdf for a non-fundamental variable like a RooFormulaVar
, as attempted in the original post. But this is what the RooLinearVar there for: it behaves like a fundamental variable, but is actually a linearly transformed fundamental variable.
You can therefore use it to implement your horizontal shift. Just create your RooDataHist for the template and the RooHistPdf for the shifted variable, the RooLinearVar:
// Helper function to create the RooDataHist for the template shape
std::unique_ptr<RooDataHist> createDataHist()
{
RooRealVar xShifted{"x_shifted", "x_shifted", 0.0, -10, 10};
RooRealVar mu{"mu", "mu", 0.0, -10, 10};
RooRealVar sigma{"sigma", "sigma", 2.0, 0.1, 10};
RooGaussian gauss{"gauss", "gauss", xShifted, mu, sigma};
return std::unique_ptr<RooDataHist>{gauss.generateBinned(xShifted, 10000)};
}
void demo()
{
using namespace RooFit;
// Observable "x"
RooRealVar x{"x", "x", 0.0, -10, 10};
// The shift will be a fit parameter
RooRealVar shift{"shift", "shift", 5.0, -10, 10}; // shift by 5 to the left
// Using RooLinearVar is the key here
RooLinearVar xShifted{"x_shifted", "x_shifted", x, RooConst(1.0), shift};
// Create the template RooHistPdf
std::unique_ptr<RooDataHist> dataHist = createDataHist();
RooHistPdf histPdf{"histPdf", "histPdf", xShifted, *dataHist};
// Just to check that it works
auto xframe = x.frame();
histPdf.plotOn(xframe);
xframe->Draw();
}
The RooLinearVar is not so much used and tested though, so expect some rough edges. If you encounter some, please follow up here, or it it is a bug, head over to the GitHub issues and open a bug report 
I hope that helps!
Cheers,
Jonas