Get the mean from several leaves from a TTree

Hi,

I’m reading a data.txt file and storing what is inside (three column of values) in a tree :

mytree->ReadFile("data.txt","x/I:E/I:alpha/D);

x | E | alpha
1 1 0.456
1 1 0.345
1 2 0.567
1 2 0.435
1 3 0.987
1 3 0.133

I now have a thousand of leaves in mytree.

Is it possible to write a request to get the mean of all the ‘alpha’ for x=1 and E=3 (for instance) ?

Thanks.

Hi,
one way to do it is with RDataFrame. Example code, I haven’t tested it but it should give you an idea:

ROOT::RDataFrame df(*mytree);
double mean = df.Filter("x == 1 && E == 3").Mean("alpha").GetValue();

Cheers,
Enrico

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