TGraph binning

Hi guys,
I wonder if anybody could help me…
I have a .txt file with two columns I use to fill a graph with TGraph. The first column refers to x values (time instants) and the second one to y values (amplitudes).

Time values are continous let’s say in an interval [a,b]. However I need to change the X axis in a discrete manner in such a way that each four lines a counter is incremented by one. In other words, I want that time values t0,t1,t2,t3 are relabeled with 1… t4,t5,t6,t7 with 2 and so on and so forth. In the end, I need a new TGraph with the new X axis.

Thanks


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


TGraphs are not binned, so if you want to somehow “add” the 4 points in each group, it cannot be done with a TGraph, maybe use a histogram instead.
If what you want is 4 points with the same x value (but possibly different y) for each of those groups of 4, that could be done with a TGraph, but having exactly the same x for more than 1 point may not be good for several things, e.g. if you want to fit.
In any case, I would read the file line by line (e.g. with ifstream) and do the assignments myself (either to a TGraph or a histo), in groups of 4 lines for each new ‘bin’. One simple way:

loop over nlines/4 with index i:
   loop over 4 lines, index j:
      read line (j) and assign/add/whatever to bin i

Hi,

Thanks for you reply. In the end I wrote a macro doing a very similar thing.

Thanks

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