Making a graph

hello experts
I would like to make a multiple graph which has fixed x-point but different y-point (every x-point has 4 y-point) i wrote my code but it didn’t work. :question: how can i add error bars too?
graph.C (1.24 KB)

Hi,

there were some C++ mistakes in your macro. You can find the corrected code below.
You are missing the definition of x, the coordinates of the points you want to display.

Cheers,
D

   TCanvas* c1 = new TCanvas("c1","Mwp_r.value",200,10,50,500);
   c1->SetGrid();
   TMultiGraph *mg = new TMultiGraph();

  
   const Int_t n = 11;
   Float_t xcls[n]  = {100,130,160,190,220,250,280,310,340,370,400};
   Float_t ycls[n]  = {0.045,0.125,0.245,0.305,0.485,0.795,0.825,1.395,1.995,2.715,3.835};

   Float_t xclsb0[n]  = {100,130,160,190,220,250,280,310,340,370,400};
   Float_t yclsb0[n] ={0.075,0.225,0.475,0.655,1.145,1.825,2.185,3.425,4.895,6.775,9.505};

   Float_t xcls_p[n]  = {100,130,160,190,220,250,280,310,340,370,400};
   Float_t yclsb_p[n]={0.055,0.155,0.335,0.455,0.805,1.285,1.545,2.415,3.445,4.785,6.745};

   Float_t xcls_m[n]  = {100,130,160,190,220,250,280,310,340,370,400};
   Float_t yclsb_m[n]={0.035,0.115,0.245,0.335,0.585,0.935,1.115,1.755,2.515,3.495,4.905};

   TGraph *gr1 = new TGraph(n,xcls,ycls);
   TGraph *gr2 = new TGraph(n,x,yclsb0,yclsb0);
   TGraph *gr3 = new TGraph(n,x,yclsb_p,yclsb_p);
   TGraph *gr4 = new TGraph(n,x,yclsb_m,yclsb_m);
  
   mg->Add(gr1);
   mg->Add(gr2);
   mg->Add(gr3);
   mg->Add(gr4);

   mg->SetTitle("TGraph m_rvalue");
   mg->GetXaxis()->SetTitle("wprime mass");
   mg->GetYaxis()->SetTitle("r_value");
   mg->GetXaxis()->CenterTitle();
   mg->GetYaxis()->CenterTitle();

  
   mg->Draw("AC");

now i corrected the definitions but it doesn’t work :exclamation:

[TCanvas* c1 = new TCanvas(“mass wp- rvalue”,“Mwp_r.value”,200,10,50,500);
c1->SetGrid();
TMultiGraph *mg = new TMultiGraph();

const Int_t n = 11;
Float_t xcls[n] = {100,130,160,190,220,250,280,310,340,370,400};
Float_t ycls[n] = {0.045,0.125,0.245,0.305,0.485,0.795,0.825,1.395,1.995,2.715,3.835};

Float_t xclsb0[n] = {100,130,160,190,220,250,280,310,340,370,400};
Float_t yclsb0[n] ={0.075,0.225,0.475,0.655,1.145,1.825,2.185,3.425,4.895,6.775,9.505};

Float_t xcls_p[n] = {100,130,160,190,220,250,280,310,340,370,400};
Float_t yclsb_p[n]={0.055,0.155,0.335,0.455,0.805,1.285,1.545,2.415,3.445,4.785,6.745};

Float_t xcls_m[n] = {100,130,160,190,220,250,280,310,340,370,400};
Float_t yclsb_m[n]={0.035,0.115,0.245,0.335,0.585,0.935,1.115,1.755,2.515,3.495,4.905};

TGraph *gr1 = new TGraph(n,xcls,ycls);
TGraph *gr2 = new TGraph(n,xclsb0,yclsb0,);
TGraph *gr3 = new TGraph(n,xclsb_p,yclsb_p);
TGraph *gr4 = new TGraph(n,xclsb_m,yclsb_m);

mg->Add(gr1);
mg->Add(gr2);
mg->Add(gr3);
mg->Add(gr4);

mg->SetTitle(“TGraph m_rvalue”);
mg->GetXaxis()->SetTitle(“wprime mass”);
mg->GetYaxis()->SetTitle(“r_value”);
mg->GetXaxis()->CenterTitle();
mg->GetYaxis()->CenterTitle();

mg->Draw(“AC”);]

Hi,

You are missing the definition of x, the coordinates of the points you want to display.

Cheers,
D

hi,
i defined x but again it has an error: [Error: Illegal Assignment to an undeclared symbol gr1 graph.C:19:
], how can i solve it?
thanks for your concern

Hi,

what code are you actually running?

hi,
this one!
graph.C (1.47 KB)

Please run this one:

void graph(){

TCanvas* c1 = new TCanvas("c1","Mwp_r.value",200,10,50,500);
   c1->SetGrid();
   TMultiGraph *mg = new TMultiGraph();

   const Int_t n = 11;
    
   Float_t  xcls[n]  = {100,130,160,190,220,250,280,310,340,370,400};
   Float_t  ycls[n]  = {0.045,0.125,0.245,0.305,0.485,0.795,0.825,1.395,1.995,2.715,3.835};
   TGraph *gr1 = new TGraph(n,xcls,ycls);
    gr1->SetMarkerColor(4);

    Float_t xclsb[n] = {100,130,160,190,220,250,280,310,340,370,400};
    Float_t yclsb[n] = {0.075,0.225,0.475,0.655,1.145,1.825,2.185,3.425,4.895,6.775,9.505};
    TGraph *gr2 = new TGraph(n,xclsb,yclsb);
     gr2->SetMarkerColor(2);

    Float_t xclsb_p[n] = {100,130,160,190,220,250,280,310,340,370,400};
    Float_t yclsb_p[n]= {0.055,0.155,0.335,0.455,0.805,1.285,1.545,2.415,3.445,4.785,6.745};
    TGraph *gr3 = new TGraph(n,xclsb_p,yclsb_p);
    gr3->SetMarkerColor(3);

     Float_t xclsb_m[n] = {100,130,160,190,220,250,280,310,340,370,400};
     Float_t yclsb_m[n]= {0.035,0.115,0.245,0.335,0.585,0.935,1.115,1.755,2.515,3.495,4.905};
     TGraph *gr4 = new TGraph(n,xclsb_m,yclsb_m);
    gr4->SetMarkerColor(1);
 
   mg->Add(gr1);
   mg->Add(gr2);
   mg->Add(gr3);
   mg->Add(gr4);
   mg->Draw("AC");

    mg->SetTitle("TGraph m_rvalue");
    mg->GetXaxis()->SetTitle("wprime mass");
    mg->GetYaxis()->SetTitle("r_value");
    mg->GetXaxis()->CenterTitle();
    mg->GetYaxis()->CenterTitle();

 
   mg->Draw("AC");
}