Shade under RooGaussian

Hey All,

I am trying to shade a range under a RooGaussian…
I have tried with the following commands on the frame.

RooGaussian signal("signal", "signal PDF", mes, sigmean, sigwidth);
signal.plotOn(frame);

frame->getAttLine()->SetLineColor(kBlue);
frame->getAttFill()->SetFillColor(kRed);
frame->getAttFill()->SetFillStyle(3013);
frame->Draw();

This however just prints a blue Gaussian line with no fill color… Is there a way to specify that I want to fill the Gaussian?

Thanks!!!
Rob

Here is a running macro showing the problem

rootForum_18881.C (393 Bytes)

And this is the fix.

{
   RooRealVar mes("mes","",-5,5);
   RooRealVar sigmean("m","",0);
   RooRealVar sigwidth("s","",1);
   RooGaussian signal("signal", "signal PDF", mes, sigmean, sigwidth);

   RooPlot * frame = mes->frame();

   signal.plotOn(frame, RooFit::FillColor(kRed), RooFit::FillStyle(3013), RooFit::DrawOption("F"), RooFit::LineColor(kBlue));

   frame->Draw();
}

The fill options must be set in the function and not the RooPlot which is just a container of plowable objects.
So you should pass the fill color and style in the RooAbsPdf::plotOn command. You must also indicate that you want to plot the RooAbsPdf with the option “F”. At the end it will be plotted as a RooCurve, which his a TGraph and in order to get a filled Graph you need to use the drawing option “F”

Hi Momenta,

Thanks for the post. That clears up a lot!

Is there a way to plot a given x-asix range? I tried inserting RooFit::Range Function as below:

RooRealVar mes("mes","",-5,5);
mes.setRange("range", 0, 100);
   RooRealVar sigmean("m","",0);
   RooRealVar sigwidth("s","",1);
   RooGaussian signal("signal", "signal PDF", mes, sigmean, sigwidth);

   RooPlot * frame = mes->frame();

   signal.plotOn(frame, RooFit::FillColor(kRed), RooFit::FillStyle(3013), RooFit::DrawOption("F"), RooFit::LineColor(kBlue), RooFit::Range("range"));

   frame->Draw();

but this seems to fill with a straight line from the point on the curve at lower range directly to the point on the curve at upper range.

Thanks for the help!

Regards,
Rob

Hi,

This is a known issue when making filled region of TGraph’curves. The filled region is obtained from the first and last point of the curve.
An alternative is instead of using the option “F” is to use the option “B”. In that case you might need to increase the number of function sampling point by decreasing the default precision. You could do in this case:

signal.plotOn(frame, RooFit::FillColor(kRed), RooFit::FillStyle(3013), RooFit::DrawOption("B"), RooFit::LineColor(kBlue),RooFit::Range("range"), RooFit::Precision(1.E-5));

Cheers

Lorenzo

Hi Lorenzo,

Thanks a lot for that. Its useful to know.

I have tried to just plot the original function and then plot it again with the ranges and (“B”) as you suggest. The problem I am seeing is that the ranged function has a higher Y value than the original. This should not be the case. Just because I fill in a given range it should not affect the count number, right?

I defined the range by setting the range on my measured RooRealVar mes. Frame is also defined using mes.

RooRealVar mes("measureRange", "Events (N)", -300, 300);
mes.setRange("range", 0, 100);
signal.plotOn(frame);
signal.plotOn(frame, RooFit::FillColor(kRed), RooFit::FillStyle(3013), RooFit::DrawOption("BC"), RooFit::LineColor(kBlue),RooFit::Range("range"), RooFit::Precision(1.E-5));

Do I have to normalise this filled region to the original or something?

Thanks a lot!
Rob

Hi Again,

So I found a comment in a forum about PDF normalisation and since they always default to normalise to 1 it caused the ranged PDF to be larger than the original. I integrated the range on the original PDF and set the new PDF to have that as its normalization value.

Shown in bold:

RooRealVar mes("measureRange", "Events (N)", -300, 300);
mes.setRange("range", 0, 100);
[b]RooAbsReal * intSignal = signal.createIntegral(mes, NormSet(mes), Range("range"));[/b]
signal.plotOn(frame);
signal.plotOn(frame, RooFit::FillColor(kRed), RooFit::FillStyle(3013), RooFit::DrawOption("BC"), RooFit::LineColor(kBlue),RooFit::Range("range"), RooFit::Precision(1.E-5),[b]RooFit::Normalization(intSignal->getVal(mes))[/b]);