Sorry, I might not have explained myself properly.
Maybe an example in 1D will be better
void testPlot() {
RooRealVar x("x", "x", -1, 1);
RooRealVar y("y", "y", -1, 1);
// basic but not too basic pdf
// 1+r^2-3/4r^4
RooGenericPdf pdf("pdf", "1+(x*x+y*y)-3./4*(x*x+y*y)*(x*x+y*y)", RooArgList(x,y));
auto data = pdf.generate(RooArgSet(x, y), 100000); // just necessary to plot the proper normalization
auto xFrame = x.frame();
pdf.plotOn(xFrame);
auto hist = pdf.createHistogram("testHist", x, RooFit::Binning(100, -1, 1));
y.setVal(1); // setting value of y should not matter if it is actually projected in the plot
pdf.plotOn(xFrame, RooFit::LineColor(kRed));
auto hist2 = pdf.createHistogram("testHist2", x, RooFit::Binning(100, -1, 1));
hist2->SetLineColor(kRed);
// plotting data before changes the projection behaviour
auto xFrame2 = x.frame();
data->plotOn(xFrame2);
// this works too if you don't want to plot the data
// plotting data calls this method in the end
//xFrame2->updateNormVars(RooArgSet(x, y));
pdf.plotOn(xFrame2);
TCanvas* c = new TCanvas;
c->Divide(2, 2);
c->GetPad(1)->cd();
xFrame->Draw();
c->GetPad(2)->cd();
xFrame2->Draw();
c->GetPad(3)->cd();
hist2->Draw();
hist->Draw("SAME");
TLatex* l = new TLatex(0.175, 0.5, "How to get above plot with createHistogram?");
c->GetPad(4)->cd();
l->Draw();
}
The difference in the two RooPlot
s is expected and stated in the documentation: if you don’t plot data before the pdf (or manually set the frame normalization variables) the pdf will be plotted as a slice in every observable not on the frame (meaning that in the example y
is sliced, hence why setting its value changes the plot).
I can reproduce the slicing behaviour with createHistogram
(bottom left) but I don’t know how to project y
instead, to reproduce the top right frame. This is not very useful when drawing 1D plots, but in D>1 I have no way to draw the top right plot.
ConditionalObservables
does not do what I’m trying to do, I tried every combination of x
and y
to place inside the RooArgSet and nothing changes in the plot.
I hope this clarifies a bit what I’m asking.