Invert the Ratio in a TRatioPlot

Hi all,

is there a way to invert the ratio calculated by TRatioPlot?
I have a TH1 with my data events and a THStack with all backgrounds and would like to see Data/Background in the ratio window, not Background/Data.



_ROOT Version: 6.16
Platform: SL6 x86_64
Compiler: GCC 8.2

You can find all the details about TRatioPlot here:
I do not remember having seen such option. But have look .

Good morning couet,

I haven’t seen such an option, that is why I am asking, but from a quick look at the code this seems to be impossible to me.
Also, I couldn’t find an option to invert in TGraph or TGraphErrors, so it seems to me as if I had to hack in a graph inversion myself by going through the array of the graph entries. Is there really no easier way?



For everyone interested, I found a workaround:

First, invert the graph with this function:

from array import array

def invert_graph(graph):
    yvalues = array('d', [0 if y==0 else 1/y for y in graph.GetY()])
    errors = array('d', [0 if y==0 else e/(y**2) for y, e in zip(graph.GetY(), graph.GetEY())])
    return ROOT.TGraphErrors(len(errors), graph.GetX(), yvalues, graph.GetEX(), errors)

and draw it to the lower pad. Then make the original ratio graph invisible:


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