Converting a time series TGraph plot into TH1F hist

Hello,
I am trying to plot a time-series TGraph plot and both the file.txt (data file) and code (test.C) and output in .png attached. Is it possible to convert this TGraph plot into a TH1F hist plot which can be saved in “.root” format,
thanks in advance
Debasish.
test.C (1.5 KB)
file.txt (101.4 KB)

Did you try searching the forum?
You can find, for example:

Do you need a TH1F, or do you simply need to save your data in a root file? If your only requirement is to save your data in a root file, there’s no need to convert your TGraph into a TH1F. A TGraph can be saved directly in a root file.

No I need to convert to TH1F and the save the histogram as .root. I am facing a tricky situation as the TGraph is in time series as above. Any suggestions please.

No I need to convert to TH1F and the save the histogram as .root

Given your data style, it appears that a TGraph would be simpler and more suitable for your needs. Why do you require a TH1F?

I do agree. I want to use TH1F for TSpectrum Class functions!

Just create a TH1S from the very beginning.

h = new TH1I(…, points, 0, 15x60xpoints);
int i=1;
while(f >> … )
{
h->SetBinContent(i, z);
i++;
}

Thanks , it worked and I am able to make the histogram. But I also wanted the time series on X-axis of histogram, which I was not sure how to get. I fitted with “pol0”. Is there a way to plot the 1 and 2 sigma lines on 1D histogram?

You can add custom time labels using SetBinLabel, see ROOT: TH1 Class Reference

Something like if ix15x60%500 == 0 h->SetBinLabel(i, t.Convert());

Alternatively, maybe this is easier, you can activate the time format:
see Time axis for histograms - #5 by couet

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