How to extract data from root file?

I got root file from geant4 so I could see histograms but I want to see the data about the histogram.
Could you please help me to export the data as a .txt or something to be able to analyse it in other programs?

TFile file = new TFile(“whitebeam.root”, “read”); TH1D h1 = (TH1D*) file -> Get(“1”); h1 -> Print(“all”); > aaa.txt

I’ve tried and tried to follow so many similar things like that, but couldn’t get any.
Please help me to get it.


Please read tips for efficient and successful posting and posting code

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


What you try to use works with ROOT 5 only.
With ROOT 6, you need to replace “> aaa.txt” with:

root [...] .> aaa.txt
root [...] h1->Print("all");
root [...] .>

I tried it but It said “error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.”.

Could you tell me what I should do to solve this problem?

Are you sure the histogram name in the file is “1”? Check with

 .ls

or

 f->ls()

after opening the file.

06

[class] [name];[cycle number]
so it name is histo??

it’s also the same root file. but the name looks different.

try

 TH1D *h1 = (TH1D*) file -> Get("histo/h1");

07

I did like that.

But the .txt file looks like this…

Print h1, not histo.

I did it, but I got an error message… Did I something wrong??

TH1D *h1; file->GetObject("histo/h1.1", h1);

Thank you so much.

Now I got it.

Thanks again!

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