How to work with histograms from a file


ROOT Version: 6.24.02
Platform: Ubuntu 20.04
Compiler: g++


I have a ROOT file with a number of histograms. I want to run analysis code that can read information from these histograms. However when I run these commands I get an error:

TFile* f = TFile::Open(“epKpKm_IN.root”)
TH1F* h = (TH1F*)f->Get(“RunNum”)
h->Draw()

RunNum is the title of the histogram, but the name of the histogram that shows above the statistics box is htemp. I don’t know if that is the name I should be using instead.

rootls -h
rootls -l epKpKm_IN.root

Thank you for your response. However, I am not sure this is the answer I am looking for. Won’t this command just list the contents of the file? I want to be able to work with the histograms; for example, I want to get the maximum bin of one of the histograms using h->GetMaximumBin();

You will see the names (and types) of histograms (and other objects) available in your file. You can then “Get” them and perform any actions on them you want.

When I do ls, I don’t see the names of the branches. All I see is the following output:

TFile** …/data/epKpKm_IN.root
TFile* …/data/epKpKm_IN.root
KEY: TTree T;35 Rec [current cycle]
KEY: TTree T;34 Rec [backup cycle]

ROOT Manual → Functional parts → Trees

BTW. You can also easily get the list of names of branches of your TTree using, e.g.: rootls -t epKpKm_IN.root

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