`FillColorAlpha()` in RooFit::plotOn()?

Dear Experts,
I didn’t find FillColorAlpha() in RooFit::plotOn(). At least, it is not here: ROOT: RooFit Namespace Reference
Is there any way to assign an alpha value to fill the color?
best regards
Himanshu

@jonas may know

Hi! RooFit doesn’t have a FillColorAlpha() flag for plotOn(), but you can get getAttFill() to get access to the TAttFill object that manages the fill attributes, and then you can proceed just like with regular ROOT described here (see section on “color transparency”):
https://root.cern.ch/doc/master/classTAttFill.html

Here is a small example how you can do this. Notice you have have to plot in PDF format to see the transparency effect:

void fillalpha()
{
    using namespace RooFit;

    RooRealVar x{"x", "x", 0, -10, 10};
    RooGaussian pdf{"pdf", "pdf", x, RooConst(0.), RooConst(3.)};

    auto frame = x.frame();

    pdf.plotOn(frame, DrawOption("F"));
    frame->getAttFill()->SetFillColorAlpha(kRed, 0.3);

    TCanvas c1;
    frame->Draw();
    c1.SaveAs("fillalpha.pdf");
}

I you think RooFit needs a FillColorAlpha() command to make this easier, please open an improvement suggestion on GitHub:

I hope this helps!

Cheers,
Jonas

Thanks, @jonas
I have two pdfs, pdf1 and pdf2, on the same frame. Will it work for this case?

And it works! I did:

pdf1.plotOn(frame, DrawOption("F"));
frame->getAttFill()->SetFillColorAlpha(kRed, 0.3);
pdf2.plotOn(frame, DrawOption("F"));
frame->getAttFill()->SetFillColorAlpha(kBlue, 0.3);

Ofcourse, the effects appear in pdf format.
Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.