Get Mean and RMS of all branches in a tree

Hi all,
Is there any easy way to get the Mean and RMS of all the branches in a tree?
Thanks!

I would recommend looping over all the branches and getting the names of the branches as strings (or just hardcoding that yourself, if it’s a small number of branches). In the loop, use TTree::Draw to make a histogram for each branch, then use TH1::GetMean() and GetRMS() on each histogram.

Jean-François

thanks for the suggestion. I try.
One more question, how to get a TH1 histogram with TTree::Draw(). It seems this member function has a type void.
Thanks!
Lei

The TTree::Draw function doesn’t return the histogram, but one is created in memory. If you do something like mytree->Draw(“branchname”), then a temporary histogram called “htemp” is created. You can retrieve it by doing

TH1F *htemp = (TH1F*)gPad->GetPrimitive("htemp");.

You could also to mytree->Draw(“branchname >> myhist”) to choose a specific name instead of “htemp”. The relevant docs are at root.cern.ch/root/html/TTree.html#TTree:Draw@2 if you search for the string “htemp” and read from there.

Jean-François

Thanks very much!
But it crashes when the branch is in vector<vector> format.
I got this error message:
Warning in TSelectorDraw::ProcessFillObject: Not implemented for vector<vector >

Best,
Lei

There are many posts about people having trouble with vector<vector> branches in TTrees in the forum. A quick search reveals for example:

Unfortunately I don’t remember how to make this work myself.

Jean-François

See: [url]How to read a 2D vector in root file