Home | News | Documentation | Download

TRatio in graph

Dear Expert,

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).

Here is the script that I am using: mean_variation_data.txt (668 Bytes)mean_variation_mc14ri_d.txt (667 Bytes)
read_graph_txt_MC_data.C (3.0 KB)

Can you please confirm there is any way to do this?

Regards
Chanchal

__
Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hii @Wile_E_Coyote,

I am looking into this, but I don’t understand how I will do this:
TH1F h3 = (TH1F)h1->Clone(“h3”); for graph.

Can you please help me in that?

Regards
Chanchal

Assuming that the “MyOriginal” is a pointer to a “TGraphErrors” object:
TGraphErrors *MyClone = (TGraphErrors*)MyOriginal->Clone(); // () or ("MyClone")

Hii @Wile_E_Coyote,

Thanks for your reply.

I am trying like:
TGraphErrors graph3 = (TGraphErrors)graph2.Clone();
graph3->Divide(graph1);
graph3->DrawClone(“AP”);

But this is giving error:

Can you please have a look into this?

Regards
Chanchal

I’m afraid you need to loop over all data points and make the division yourself (and “calculate” the errors yourself, too).

Hii @Wile_E_Coyote,

Sorry for late reply.

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?

Please suggest if there is any way to do this.

Regards
Chanchal

assuming the graph points are equidistant:

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("*");
}

Hii @couet,

Can I make a histogram with uncertainty from txt file?

Here is the txt file: mean_variation.txt (667 Bytes)
MC.txt (666 Bytes)

Can you please suggest?

Regards
Chanchal

You should use SetBinError