I have drawn two graphs using TMultigraph which are corresponding to two txt files (data.txt
and MC.txt).
Now I want to make a graph which is the ratio of two txt files (data.txt / MC.txt) as TRatio for histograms (h1/h2).
Assuming that the “MyOriginal” is a pointer to a “TGraphErrors” object: TGraphErrors *MyClone = (TGraphErrors*)MyOriginal->Clone(); // () or ("MyClone")
I am doing manually by dividing the data points and calculate the uncertainty. But its very difficult for me to calculate each time as I have other more txt files (about 15 sets of txt file).
I was thinking, Is it possible to convert these two graph in histogram and then plot TRatio of the same?
void graph2hist()
{
auto c = new TCanvas();
c->SetGridx();
auto g = new TGraph();
g->AddPoint(1.,1.);
g->AddPoint(2.,2.);
g->AddPoint(3.,3.);
g->AddPoint(4.,4.);
g->AddPoint(5.,5.);
g->AddPoint(6.,4.);
g->AddPoint(7.,3.);
g->AddPoint(8.,2.);
g->AddPoint(9.,1.);
int n = g->GetN();
double x0 = g->GetPointX(0);
double xn = g->GetPointX(n-1);
double w = (xn-x0)/n;
double w2 = w/2.;
auto h = new TH1F("h","graph 2 hist",n,x0-w2,xn+w2);
for (int i = 0; i<9 ; i++)h->SetBinContent(i+1, g->GetPointY(i));
h->Draw();
g->Draw("*");
}