Bin content at least up to 6 decimal places

Hi,

I was trying to get histogram information in a source code. where I’m getting bin content up to 3 decimal places. Some what like,
PT__1->SetBinContent(1, 2404.312);
PT__1->SetBinContent(2, 2425.423);
PT__1->SetBinContent(3, 2371.472);
PT__1->SetBinContent(4, 2545.052);
PT__1->SetBinContent(5, 2533.324);
I need bin content with precision of at least 5-6 decimal places.
For histogram I’m using,
TH1D *hist_PT = new TH1D(“PT”, “PT”, 30, 0, 500);

in your example you do not “Get” but you “Set”.

The 6 digits are there:

root [0] TH1D *hist_PT = new TH1D("PT", "PT", 30, 0, 500);
root [1] hist_PT->SetBinContent(1,999.123456);
root [2] printf("%10.6f\n",hist_PT->GetBinContent(1));
999.123456

Thank you for answer. I think, I didn’t explain question more precisely. Let me explain,
I’m generating a histogram in main macro and I’m saving details (like bin contents etc.) in some other .C file by command,
canvas->SaveAs(“hist.C”);
In this “his.C” file, I see that bin content is up to 3 decimal places as I have shown in starting of main question. I want those bin contents up to some desired decimals. Do I have control on that using main macro?

With canvas->SaveAs(“hist.C”); you cannot specify the precision. To save the bins contants with the precision you require, you will need to write a small method looping over the bins and using a format similar to the one I showed in the previous post.

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