I have two histograms,
h1=(TH1D*)l->Get(“hist0”);
h2=(TH1D*)l->Get(“hist1”);
I want to plot the Bin Contents of h1 and h2 as (x,y) co-ordinates. How should I do it?
ROOT Version: 6.24
Platform: Focal Release 20.04
Compiler: C++
I have two histograms,
h1=(TH1D*)l->Get(“hist0”);
h2=(TH1D*)l->Get(“hist1”);
I want to plot the Bin Contents of h1 and h2 as (x,y) co-ordinates. How should I do it?
ROOT Version: 6.24
Platform: Focal Release 20.04
Compiler: C++
This is not possible (you would need a TH2D which cannot be built from two TH1D).
Corresponding to each of h1 and h2, we have i-th bin and its BinContent(i). Is it not possible to extract their BinContent(i) and plot them as x and y set of points?
This you can do: TGraph
// assuming both histograms have the same number of bins
TGraph *g = new TGraph(h1->GetNbinsX(), h1->GetArray() + 1, h2->GetArray() + 1);
g->Draw("AL*");
If you also want the underflow and overflow bins, use:
TGraph *g = new TGraph(h1->GetNbinsX() + 2, h1->GetArray(), h2->GetArray());
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.