Dear all,
I am a beginner in ROOT, that I am trying to use to plot the outputs file generated by Geant4. From the Geant4 forum, they also suggested to write here for a problem in the extended
examples, related to the macro root files named plotHisto.C
.
In particular, I would like to plot the histograms of the gps examples in examples/extended/eventgenerator/exgps
for the beam source defined in the test30.mac
macro.
I tried to correct the errors reported by writing the script of the plotHisto.C
macro as follow:
{
gROOT->Reset();
// Draw histos filled by Geant4 simulation
//
//TFile f = TFile("test02.root");
TFile f("build/test30.root");
TCanvas* c1 = new TCanvas("c1", " ");
//TDirectory* dir = (TDirectory*)f.Get("histo");
TH1D* hist1 = (TH1D*)f.Get("h1.1");
hist1->Draw("HIST");
/*
TH1D* hist2 = (TH1D*)dir->Get("h1.2");
hist2->Draw("HIST");
*/
TH1D* hist3 = (TH1D*)f.Get("h1.3");
hist3->Draw("HIST");
TH1D* hist4 = (TH1D*)f.Get("h1.4");
hist4->Draw("HIST");
TH2D* hist5 = (TH2D*)f.Get("h2.1");
hist5->Draw("HIST");
/*
TH2D* hist6 = (TH2D*)f.Get("h2.2");
hist6->Draw("HIST");
TH2D* hist7 = (TH2D*)dir->Get("h2.3");
hist7->Draw("HIST");
*/
TH2D* hist8 = (TH2D*)f.Get("h2.4");
hist8->Draw("HIST");
}
Unfortunately, I am still having the following error messages when I run plotHisto.C
:
I would ask, please, if someone has some suggestions to fix this problem.
Thanks in advance for your time.
Best regards,
Christian
yus
February 8, 2022, 2:26pm
2
Hi Christian,
could you please share your test30.root
? I bet it does not contain one or more of the histograms you are trying to retrieve from it.
1 Like
Thank you for helping! I tried to attach the file but as a new user in the forum, Iām not allowed to it.
Christian
yus
February 8, 2022, 5:11pm
5
Okay, then please change your code as follows and run it:
{
gROOT->Reset();
// Draw histos filled by Geant4 simulation
//
//TFile f = TFile("test02.root");
TFile f("build/test30.root");
TCanvas* c1 = new TCanvas("c1", " ");
//TDirectory* dir = (TDirectory*)f.Get("histo");
TH1D* hist1 = (TH1D*)f.Get("h1.1");
if (!hist1)
{
printf("No h1.1 in the input file\n");
return;
}
hist1->Draw("HIST");
/*
TH1D* hist2 = (TH1D*)dir->Get("h1.2");
hist2->Draw("HIST");
*/
TH1D* hist3 = (TH1D*)f.Get("h1.3");
if (!hist3)
{
printf("No h1.3 in the input file\n");
return;
}
hist3->Draw("HIST");
TH1D* hist4 = (TH1D*)f.Get("h1.4");
if (!hist4)
{
printf("No h1.4 in the input file\n");
return;
}
hist4->Draw("HIST");
TH2D* hist5 = (TH2D*)f.Get("h2.1");
if (!hist5)
{
printf("No h2.1 in the input file\n");
return;
}
hist5->Draw("HIST");
/*
TH2D* hist6 = (TH2D*)f.Get("h2.2");
if (!hist6)
{
printf("No h2.2 in the input file\n");
return;
}
hist6->Draw("HIST");
TH2D* hist7 = (TH2D*)dir->Get("h2.3");
if (!hist7)
{
printf("No h2.3 in the input file\n");
return;
}
hist7->Draw("HIST");
*/
TH2D* hist8 = (TH2D*)f.Get("h2.4");
if (!hist8)
{
printf("No h2.4 in the input file\n");
return;
}
hist8->Draw("HIST");
}
1 Like
Dear @yus ,
sorry for the late reply. You were right, with f.ls(); I saw that it does not contain the histograms I tried to obtain. It was a mistake in the name of the histograms in the Geant4 example.
Thank you very much!
Christian