OmnipotentEntity OmnipotentEntity - 16 days ago 5
C++ Question

How can you graph error as a shaded region?

When using TGraphErrors, the error bars appear as crosses, in the absence of significant X errors and many, many data points (such as MCA with 16k bins or so) I'd like to be able to remove the single points and single error bars and graph the error as a shaded region bounding the curve from above and below.

But I'm still a rank beginner at using ROOT, and I cannot figure out how to leverage TGraphErrors to do what I want. Will I need to instead use a TMultiGraph instead (and calculate the above and below bounding curves) and if so how can I control the shading region?

Something like the below would be along the lines of what I'm looking for. Source

Example graph

Answer

Take a look at the TGraphPainter documentation which gives a few examples. One way is to draw the TGRaphErrors using option 4:

A smoothed filled area is drawn through the end points of the vertical error bars.

You will probably find that to get the final plot to look as you want, you have to draw the same graph multiple times - once to get the shaded region, then again on top to get the central curve.

This blog post gives a working example. It's written in PyROOT, but can be easily adapted to C++.

Comments