# 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

X1[]={1000,2000,3000,4000,5000}
Y1[]={ 10, 20, 30, 20, 10}

X2[]={1930,3000,4005,5055,6066}
Y2[]={ 100, 200, 300, 200, 100}

The operation should return either:

Xsum[4]={2000,3000,4000,5000}
Ysum[4]={ 110, 220, 330, 220}

OR

Xsum[6]={1000,2000,3000,4000,5000,6000}
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?