How to call back histograms and their features with unknown name?

Hi

I’m having some issues calling back histograms from a TFile
Below is an example of what I see if this was done in terminal.

root [0] TFile *f1 = new TFile("Filtered_0800DT_Flag0_Results.root")
(TFile *) 0x56541b572700
root [1] f1->ls()
TFile**		Filtered_0800DT_Flag0_Results.root	
 TFile*		Filtered_0800DT_Flag0_Results.root	
  KEY: TH1D	hidff1;1	Frequency versus time difference between counts
  KEY: TH1D	hdiff2;1	
  KEY: TH1D	hdiff3;1	
  KEY: TH1D	hdiff4;1	
root [2] TH1D* hdiff2 = (TH1D*)f1->Get("hdiff2")
(TH1D *) 0x56541c34b320
root [3] hdiff2->Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [4] 

The problem I have is that the files I have don’t have the exact same names for all four histograms being stored, so I can’t do the exact same calling names. The first Histogram is an example
Where if I do

TH1D* hdiff1 = (TH1D*)f1->Get("hdiff1")

I would get back an empty histogram, maybe because of the title?
What can I do that would give back a TString with the appropriate name for each histogram?


Please read tips for efficient and successful posting and posting code

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


Hi @scheng5134
I think there is a typo:
In your file: “hidff1”
In Get(…): “hdiff1”
Maybe this is not THE problem, but surely this is A problem.
Bye :slightly_smiling_face:

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