Adding two TGraphs, x bin alignment

Hi Roooters

I would like to add two TGraph objects together. The X axis is energy calibrated and the Y axis is relative intensities. The operation is not simple since it does not consist in adding bin by bin but rather to add the proper intensities at te same energy value. This problem arises when the X axis of both plots don’t align due to the calibration curves (imagine using two detectors running at slightly different gains). I am unsig TGraph objects in a TMultiGraph container. Does ROOT offer any kind of function that will add bins properly checking for “proper x energy” alignment when performing the addition?

Consider the case

Y1[]={ 10, 20, 30, 20, 10}

Y2[]={ 100, 200, 300, 200, 100}

The operation should return either:

Ysum[4]={ 110, 220, 330, 220}


Ysum[6]={ 10, 110, 220, 330, 220, 100}

This is assuming an x bin resolution of “plus minus” 500 units.
I could write my own algorithm but I am hopping I do not need to re-invent the wheel. Even to do some kind of interpolation when it does the addition in case both plots have differnt bin resolution?

Thanks for your assitance!

TGraph::Add does not exist. You should do it yourself by adding the two Y vectors.
I think the function Eval might help you:
If the graphs do not have the same X values, you can use one graph as reference for the X value and evaluate the Y values for the other graph at the X values from the reference graph.
It should be simple to write a generic macro doing that.