Hello all,
I was trying to open a histogram in a macro, I followed this solution
Hi all,
I have a root file with inside histograms, now I would like to open this file and to see an histogram, that I know the name of this histogram in the file.
I red the “HowTo’s”, but I alway obtain an error.
My code is:
[code]{
TFile *f = new TFile(“myfile.root”);
f.ls ();
TH1F * h1 = new TH1F(“h1”,“h1 title” , 100, 0, 4);
h1 = (TH1F*)f.Get(hist1);
h1->Draw();
}[/code]
with the comand f.ls I obtain this:
KEY: TH1F hist1;1 Hist1
KEY: TH1F hist2;1 Hist2
KEY: TH1F hi…
Hi,
Don’t write your own main() unless you really have to. You are missing an event loop; you want GUI interaction - all of that is provided if you run your code in ROOT, instead of building your own main().
(You’re missing a TApplication object; its Run() method creates an event loop.)
Axel.
Hi Chris,
you should specify the correct type of object you are reading from the file. In addition, you need to invoke the Draw method of TH1F/D: please refer to root.cern.ch/doc/master/classTH1F.html
Assuming that the histogram is a TH1F (it could be a TH1D, it depends on who wrote it):
TFile f(newrootpath);
TH1F* T = NULL;
f.GetObject("pedestal", T);
T.Draw();
Cheers,
D
but in all the cases show me this error
and this is my histogram
how can I fix this problem?
TFile *f1 = new TFile("1cut.root");
TH1F* h1 =(TH1F*)f1->Get("MVA_BDT");
h1->Draw();
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
yus
November 30, 2020, 6:49pm
2
Hi Manuel,
based on your screnshot, the MVA_BDT
histogram is located in the TMVAppbdt1.root
, but your code
TFile *f1 = new TFile("1cut.root");
tries to open a different file. Why?
It’s usually a very good idea to check if your file exists, can be opened, and does contain the wanted histogram. To do this you should modify your code to something like this:
TFile *f1 = TFile::Open("1cut.root");
if (!f1 || f1->IsZombie())
{
printf("f1 can not be opened\n");
return;
}
TH1F* h1 = static_cast<TH1F*>(f1->Get("MVA_BDT"));
if (!h1)
{
printf("MVA_BDT can not be fetched from f1\n");
return;
}
yes thanks, I was very distracted and tired , sorry for posting that noob question hahaha
system
Closed
December 14, 2020, 7:02pm
4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.