Hi,
I have this strange problem: I want to extract data from the TH2D histogram (detTimeProf) that I read from the root file. I know that histogram exists and is read from the file but while trying to extract data from the histo the segfault occurs. For example, while line #1 works perfectly line #2 returns segFault.
1 const int nRuns = detTimeProf->GetXaxis()->GetNbins();
2 const int nRuns = detTimeProf->GetNbinsX();
Also all my attempts to extract histo integral (GetIntegral) or actually any other information straight from histo fail.
Here is a short sample of my code:
#include <TH2D.h>
#include <TFile.h>
int main()
{
TH2D *detTimeProf;
detTimeProf = openDetTimeProfile( detId );
if( detTimeProf == nullptr )
return 1;
const int nRuns = detTimeProf->GetXaxis()->GetNbins(); //this works
const int nChns = detTimeProf->GetYaxis()->GetNbins(); //this works
const double content = detTimeProf->GetBinContent( 1, 1 ); //here I have segFault
return 0;
}
TH2D* openDetTimeProfile( const int detId )
{
TFile rootFile( "detTimeProf.root" );
return (TH2D*)rootFile->Get( "histoTest" );
}
ROOT Version: 6.18/04
Thx for help in advance.