Print in Graph Legend fit parameters

Hello to everyone!

I have fitted two data sets in a graph and all I want is to print the parameters in the legend.
I used ->Print(“all”), however it prints only in terminal.

I also used ->GetParameters(), but again nothing happens.
Any ideas?

P.S.:The code I am using is:

[code]# include “TCanvas.h”

include “TROOT.h”

include “TGraphErrors.h”

include “TF1.h”

include “TLegend.h”

include “TArrow.h”

include “TLatex.h”

void gain(){

TCanvas *mycanvas = new TCanvas("c","c",600, 400);
TMultiGraph * mg = new TMultiGraph("gain curve","GAIN CURVE");

// The values on the X,Y axes and error on Y axis
const int n_Fe=20;
double x_Fe[n_Fe]={560,565,570,575,580,585,590,595,600,605,610,615,620,625,630,635,640,645,650,655};
double y_Fe[n_Fe]={1056,1200,1392,1584,1824,2064,2304,2688,3024,3456,3984,4512,5088,5856,6624,7488,8640,9792,11280,12624};
double errorY_Fe[n_Fe];
for (int i=0; i<n_Fe; i++){
	errorY_Fe[i]=192;
}


const int n_alpha=9;
double x_alpha[n_alpha]={500,535,540,545,550,555,560,565,570};
double y_alpha[n_alpha]={220,490,556,622,710,754,849,959,1098};
double errorY_alpha[n_alpha];
for (int i=0; i<n_alpha; i++){
	errorY_alpha[i]=30;
}

gROOT->SetStyle("Plain");

TGraphErrors * gr1 = new TGraphErrors( n_Fe, x_Fe, y_Fe, NULL, errorY_Fe );
gr1->SetName(“gr1”);
gr1->SetTitle(“Fe”);
gr1->SetMarkerStyle(20);
gr1->SetMarkerColor(4);
gr1->SetDrawOption(“AP”);
gr1->SetLineColor(4);
gr1->SetLineWidth(1);
gr1->SetFillStyle(0);

TGraphErrors * gr2 = new TGraphErrors( n_alpha, x_alpha, y_alpha, NULL, errorY_alpha);
gr2->SetName(“gr2”);
gr2->SetTitle(“alpha”);
gr2->SetMarkerStyle(20);
gr2->SetMarkerColor(2);
gr2->SetDrawOption(“P”);
gr2->SetLineColor(2);
gr2->SetLineWidth(1);
gr2->SetFillStyle(0);

gr1->Fit(“expo”);
gr1->GetFunction(“expo”)->SetLineColor(4);
gr1->GetFunction(“expo”)->SetLineWidth(2);
gr1->Print(“all”);
gr2->Fit(“expo”);
gr2->GetFunction(“expo”)->SetLineColor(2);
gr2->GetFunction(“expo”)->SetLineWidth(2);

mg->Add(gr1);
mg->Add(gr2);
mg->Draw(“AP”);
mg->SetTitle(“Gain Curve for Fe X-rays and Po-210 alpha particles;Vmesh[V];Gain”);
mycanvas->BuildLegend(0.15, 0.7, 0.4, 0.9,“Ar-CO2–>70%-30%”);
mycanvas->SetLogy(1);
mycanvas->Print(“graph_with_law.pdf”);

}
[/code]

[code]# include “TCanvas.h”

include “TROOT.h”

include “TStyle.h”

include “TMultiGraph.h”

include “TGraphErrors.h”

include “TF1.h”

include “TLegend.h”

include “TPaveStats.h”

include “TArrow.h”

include “TLatex.h”

void gain(){

TCanvas *mycanvas = new TCanvas(“c”,“c”,600, 400);
TMultiGraph * mg = new TMultiGraph(“gain curve”,“GAIN CURVE”);

// The values on the X,Y axes and error on Y axis

const int n_Fe=20;
double x_Fe[n_Fe]={560,565,570,575,580,585,590,595,600,605,610,615,620,625,630,635,640,645,650,655};
double y_Fe[n_Fe]={1056,1200,1392,1584,1824,2064,2304,2688,3024,3456,3984,4512,5088,5856,6624,7488,8640,9792,11280,12624};
double errorY_Fe[n_Fe];
for (int i=0; i<n_Fe; i++){
errorY_Fe[i]=192;
}

const int n_alpha=9;
double x_alpha[n_alpha]={500,535,540,545,550,555,560,565,570};
double y_alpha[n_alpha]={220,490,556,622,710,754,849,959,1098};
double errorY_alpha[n_alpha];
for (int i=0; i<n_alpha; i++){
errorY_alpha[i]=30;
}

gROOT->SetStyle(“Plain”);
// See: http://root.cern.ch/root/html/TStyle.html#TStyle:SetOptFit
gStyle->SetOptFit(1111);

TGraphErrors * gr1 = new TGraphErrors( n_Fe, x_Fe, y_Fe, NULL, errorY_Fe );
gr1->SetName(“gr1”);
gr1->SetTitle(“Fe”);
gr1->SetMarkerStyle(20);
gr1->SetMarkerColor(4);
gr1->SetDrawOption(“AP”);
gr1->SetLineColor(4);
gr1->SetLineWidth(1);
gr1->SetFillStyle(0);

TGraphErrors * gr2 = new TGraphErrors( n_alpha, x_alpha, y_alpha, NULL, errorY_alpha);
gr2->SetName(“gr2”);
gr2->SetTitle(“alpha”);
gr2->SetMarkerStyle(20);
gr2->SetMarkerColor(2);
gr2->SetDrawOption(“P”);
gr2->SetLineColor(2);
gr2->SetLineWidth(1);
gr2->SetFillStyle(0);

gr1->Fit(“expo”);
gr1->GetFunction(“expo”)->SetLineColor(4);
gr1->GetFunction(“expo”)->SetLineWidth(2);
gr1->Print(“all”);
gr2->Fit(“expo”);
gr2->GetFunction(“expo”)->SetLineColor(2);
gr2->GetFunction(“expo”)->SetLineWidth(2);

mg->Add(gr1);
mg->Add(gr2);
mg->Draw(“AP”);
mg->SetTitle(“Gain Curve for Fe X-rays and Po-210 alpha particles;Vmesh[V];Gain”);
mycanvas->BuildLegend(0.15, 0.7, 0.4, 0.9,“Ar-CO2–>70%-30%”);
mycanvas->SetLogy(1);

mycanvas->Modified(); mycanvas->Update(); // make sure it’s really (re)drawn
TPaveStats st = ((TPaveStats)(gr1->GetListOfFunctions()->FindObject(“stats”)));
if (st) {
st->SetTextColor(gr1->GetLineColor());
st->SetX1NDC(0.64); st->SetX2NDC(0.99);
st->SetY1NDC(0.4); st->SetY2NDC(0.6);
}
st = ((TPaveStats*)(gr2->GetListOfFunctions()->FindObject(“stats”)));
if (st) {
st->SetTextColor(gr2->GetLineColor());
st->SetX1NDC(0.64); st->SetX2NDC(0.99);
st->SetY1NDC(0.15); st->SetY2NDC(0.35);
}
mycanvas->Modified(); mycanvas->Update(); // make sure it’s really (re)drawn

mycanvas->Print(“graph_with_law.pdf”);

return;
}[/code]

Thank you very much!!!
Your comments were really helpful.
I have to admit that the fact that you colored each stats box according to the data set’s color was amazing!!!

Thank you VERY MUCH again!!! :smiley:

P.S.:You must be my savior!!!
Next time I’ll send you directly a pm :slight_smile: {I am joking!}