FIT for Different lines

Hello all,

I have two different lines in the same canvas.As,
One of them contains x:10,20,30,40,50 - correspondibg y: 2,3,5,7,8
The second one contains x: 10,20,30,40,50 - y: 5,8,9,12,14

I want to make fit both of them seperately in the same frame. Is it possible to manage this?

Best Wishes,

Serkan Akkoyun

try this:

{
   TCanvas *c = new TCanvas("c","c",0,0,800,600);
   c->DrawFrame(0,0,60,15);     

   Double_t x1[5] = {10,20,30,40,50};
   Double_t y1[5] = {2,3,5,7,8};
   Double_t x2[5] = {10,20,30,40,50};
   Double_t y2[5] = {5,8,9,12,14};

   TGraph *g1 = new TGraph(5,x1,y1);
   TGraph *g2 = new TGraph(5,x2,y2);

   g1->Draw("L"); 
   g2->Draw("L"); 
}

thank you very much :slight_smile: it works now
best wishes
Serkan

I have new problem now.
I had error bars in the each points. But now, I cannot add the error bars in this code.
How can I add the bars?

Best Regards,

Serkan

Use TGraphErrors instead of TGraph. Read the doc at:
root.cern.ch/root/html/TGraphErrors.html

Thank you very much,

Each point has its own error. For instance the error for y1=0.04 or y2=0.06.
I could not do these error bars :frowning:
Wishes

Can you show me the macro you have now ?

I have 2 macros. I wanna draw them in the same frame. The values are seen in them.

 #include "TH1D.h"
#include "TGraph.h"
#include "TGraphQQ.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TMath.h"
TCanvas * Rserkan143(Float_t w=0)
{
  TH1D* h1 = new TH1D("h1",";Gamma-ray energy E_{#gamma}[keV];R_{P/B}", 1750, 0, 1750 );
 // h1->SetTitle("R");
  h1->SetBinContent(100, 0.94 );
  h1->SetBinContent(250, 1.17);
  h1->SetBinContent(400, 1.71);
  h1->SetBinContent(550, 1.98);
  h1->SetBinContent(700, 2.33);
  h1->SetBinContent(850, 2.65);
  h1->SetBinContent(1000, 2.4);
  h1->SetBinContent(1150, 2.5);
  h1->SetBinContent(1300, 2.46);
  h1->SetBinContent(1450, 2.93);

  h1->SetBinError(100, 0.04);
  h1->SetBinError(250, 0.04);
  h1->SetBinError(400, 0.08);
  h1->SetBinError(550, 0.09);
  h1->SetBinError(700, 0.12);
  h1->SetBinError(850, 0.11);
  h1->SetBinError(1000, 0.12);
  h1->SetBinError(1150, 0.13);
  h1->SetBinError(1300, 0.21);
  h1->SetBinError(1450, 0.23);
 //create Canvas
  TCanvas *c1 = new TCanvas("c1","Serkan AKKOYUN",10,10,700,600);
  gPad->SetFrameFillColor(0);
  h1->SetMarkerColor(4);
  h1->SetMarkerStyle(20);
 
  
h1->Draw();
  

}

The other is;

#include "TH1D.h"
#include "TGraph.h"
#include "TGraphQQ.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TMath.h"
TCanvas * Rserkan144ng(Float_t w=0)
{
 TH1D* h2 = new TH1D("h1",";Gamma-ray energy E_{#gamma}[keV];R_{P/B}", 1750, 0, 1750 );
 // h1->SetTitle("R");
  h2->SetBinContent(100, 0.93 );
  h2->SetBinContent(250, 1.1);
  h2->SetBinContent(400, 1.57);
  h2->SetBinContent(550, 1.8);
  h2->SetBinContent(700, 1.93);
  h2->SetBinContent(850, 2.15);
  h2->SetBinContent(1000, 1.97);
  h2->SetBinContent(1150, 1.89);
  h2->SetBinContent(1300, 2.00);
  h2->SetBinContent(1450, 2.28);

  h2->SetBinError(100, 0.04);
  h2->SetBinError(250, 0.04);
  h2->SetBinError(400, 0.07);
  h2->SetBinError(550, 0.08);
  h2->SetBinError(700, 0.09);
  h2->SetBinError(850, 0.08);
  h2->SetBinError(1000, 0.09);
  h2->SetBinError(1150, 0.09);
  h2->SetBinError(1300, 0.13);
  h2->SetBinError(1450, 0.16);
 //create Canvas
  TCanvas *c1 = new TCanvas("c1","Serkan AKKOYUN",10,10,700,600);
 gPad->SetFrameFillColor(0);
 h2->SetMarkerColor(4);
 h2->SetMarkerStyle(20);

  h2->Draw();
}

OK. The Problem was solved.This macro works.Regards,
Thank you.

#include "TH1D.h"
#include "TGraph.h"
#include "TGraphQQ.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TMath.h"
                TCanvas * dene(Float_t w=0)
{
   TCanvas *c = new TCanvas("c","c",0,0,800,600);
   c->DrawFrame(0,0,1750,3.5);


   Double_t x1[10] = {100,250,400,550,700,850,1000,1150,1300,1450};
   Double_t y1[10] = {0.94,1.17,1.71,1.98,2.33,2.65,2.4,2.5,2.46,2.93};
   Double_t x2[10] = {100,250,400,550,700,850,1000,1150,1300,1450};
   Double_t y2[10] = {0.93,1.1,1.57,1.8,1.93,2.15,1.97,1.89,2.00,2.28};
  Double_t ex1[10] = {0,0,0,0,0,0,0,0,0,0};
  Double_t ey1[10] = {0.04,0.04,0.08,0.09,0.12,0.11,0.12,0.13,0.21,0.23}; 
  Double_t ex2[10] = {0,0,0,0,0,0,0,0,0,0};
  Double_t ey2[10] = {0.04,0.04,0.07,0.08,0.09,0.08,0.09,0.09,0.13,0.16};

   TGraphErrors *g1 = new TGraphErrors(10,x1,y1,ex1,ey1);
   TGraphErrors *g2 = new TGraphErrors(10,x2,y2,ex2,ey2);

   g1->Draw();
   g2->Draw();
}