Hi,
I have a compiled ROOT-file with loads of histrograms, what I need is the data (x-and y-values) of one single histogram.
Is there a way to get them (without having the source data)?
thanks a lot
Hi,
I have a compiled ROOT-file with loads of histrograms, what I need is the data (x-and y-values) of one single histogram.
Is there a way to get them (without having the source data)?
thanks a lot
If you have a ROOT file myfile.root containing a histogram “h1”,
you can retrieve the x and y values into local arrays with
TFile *f = TFile::Open("myfile.root");
TH1 *h1 = (TH1*)f->Get("h1");
Int_t nbins = h1->GetXaxis()->GetNbins();
double *x = new double[nbins];
double *y = new double[nbins];
for (int bin=1;bin<nbins>GetXaxis()->GetBinCenter(bin);
y[bin] = h1->GetBinContent(bin);
}
Rene
At first thanks for the FAST answer!
With the help of that code I got the data, but I have one further question:
In the histogram there are the y-values together with the errors, as far as I can see I only get the medians with “GetBinContent()”.
That is fine so far but can I retrieve the error value as well?
see the long list of methods available in the TH1 class.
In your case do
myhist.GetBinError(bin)
Rene