Getting StdDev() and Mean() from branch of a tree in saved root file

Hey! Greetings of the day,
I do not know if the question is silly, but the same thing works for other trees, in the same root file. Actually, I have a root file in which some trees are saved, one of the trees is E200, when I try to get StdDev and Mean from histograms for some branches, all I get is 0, while the same code works fine for other trees, I can’t figure out what’s wrong.
Obviously, I’ve checked in TBrowser that the histogram for all the branches shows non-zero standard deviation and mean values. Please help…! Thank you in advance…!

TTree *t;
TH1D *histo;
rootFile->GetObject("E200",t);
t->Draw("branch_name>>branch_get");
histo=(TH1D*)gPad->GetPrimitive("branch_get");
std_dev=(histo->GetStdDev())/2;
mean=histo->GetMean();
cout<<std_dev<<mean<<endl;

ROOT Version: 6.16
Platform: Ubuntu 18.04.4
Compiler: CINT


Hi!

It is hard to tell what can be tbh.
The only idea I have is that the other branch you are trying to read isnt “Double” but float or int. Then you need to plot it in TH1F, TH1I histos corespondingly.

If this is not the case. it’s hard to tell.

If you add the full code for both branches and the picture of the TBrowser structure of your root file it might help.

regards

1 Like

Hi FoxWise, Thanks for your kind reply. I intended to save everything as double, I did so, but now, I’ve also tried to change everything to float and then read it by TH1F and am facing the same problem. and there’s no difference in the code for other trees or branches, it’s just that I change the names accordingly.

As you asked for screenshot of the structure of root file, so all the trees have the same structure: as
tree_structure

Can you give me the file, so I can try?

1 Like

Thank you for trying to help, but the file is too big for me to be able to upload. Network too slow here.

Attach the output of: t->Print();
Give some example names of branches which you think are fine and some which are not.

1 Like

Hello there! I was trying to figure the solution out on my own, because I had an intuition that I must’ve done something (silly) wrong. So, the problem was that I was using pointer without deleting it later, before reusing it. It worked fine for few trees, then for the last tree, it gave result for some branches as 0. I’m so sorry for troubling you over this. Thanks for all the help.