Decimal digits in MultiGraph

Hello everybody,

I fit 4 TGraphErrors with a 5 parameters function ( background and gaus)and then i add them to a multigraph.I use SetOptFit and i obtain the parameters for each fit in the same canvas which is good.
The problem is that i want to specify the decimal digits to this parameters and i cannot find a way.
Could you please help me with this? I tried with SetFitFormat(“3.1g”) (1 stands for decimal, what 3 stands for?)before and after drawing but nothing happended , i used gPad->Modified(); gPad->Update(); also i tried with TPaveStats. My script is more or less this one:
Could you please help me with this?

thank you,
Marios.

{
   TCanvas *c1 = new TCanvas("c1","Fitting Demo",100,100,2000,2000);
   c1->ToggleEventStatus();
   c1->SetFillColor(38);
   c1->SetFrameFillColor(29);
   c1->SetGrid();


  TMultiGraph *mg = new TMultiGraph();		

                                    //1
   TGraphErrors *gr = new TGraphErrors("1");      

   TF1 *fitFcn = new TF1("fitFcn",fitFunction,emin1,emax1,5);					
   fitFcn->SetLineColor(kGreen);              
   fitFcn->SetParNames("1","2","Constant","Mean_value","Sigma");

   gr->Fit("fitFcn","MV+","epv",emin1,emax1); 

   Double_t par1[5];

   fitFcn->GetParameters(par1);
	

	                      //2

   TGraphErrors *gr2 = new TGraphErrors("2");      
   
   TF1 *fitFcn2 = new TF1("fitFcn",fitFunction,emin2,emax2,5);
   fitFcn2->SetLineColor(kBlue);            
   fitFcn2->SetParNames("1","2","Constant","Mean_value","Sigma");

   gr2->Fit("fitFcn","MV+","epv",emin2,emax2); 

   Double_t par2[5];


   fitFcn2->GetParameters(par2);
	
//the same for the next 2 graphs , and then
 
mg->Add(gr);
mg->Add(gr2);
mg->Add(gr3);
mg->Add(gr4);

mg->Draw("AP");	


  fitFcn2->GetParameters(par2);
   fitFcn1->GetParameters(par1);
   fitFcn4->GetParameters(par4);
   fitFcn3->GetParameters(par3);


mg-> GetXaxis()->SetRangeUser(emin4-5,emax4+5);
gStyle->SetOptFit(11);
gStyle->SetFitFormat("3.1g");


}

try to put…

gStyle->SetOptFit(11);
gStyle->SetFitFormat("3.1g");

… at the beginning of the macro. The format follows the C convention. In your case 3 is the total number of digits et 1 the number of digits after the dot.

Well thank you i partly did it but…

The problem is that parametres and their errors have the same decimal digits. So for example for a value 1234.56 (6 decimal) the error is 0.0123456 (6 decimal) and that happens to most of values, because errors are smaller than the values. I want to get something like 1234.56 +/- 0.07 . Is there a way to specify less decimal digits to errors than the parameters?
(Also i tried to put gStyle->SetOptFit(11); gStyle->SetFitFormat(“3.1g”); at the begining of the macro, the boxes do not show up (maybe because the parametres are not yet specified) )

Thank you again for your help.

For TGraph the same format is used for the value and error. (line 3896 in TGraphPainter). For histogram there is some automatic optimization done by GetBestFormat (line 8614 in THistPainter)
So to answer you question there is no way to get less digits in your case.

A workaround could be to get the errors

  Double_t par1[5], err1[5];
  fitFcn->GetParameters(par1);
  fitFcn->GetParErrors(err1); 

and print your own “stats” (e.g. in a TPaveText) so you can control the format you want for each variable, like

  printf(myline,"%6.2f%s%3.2f",par1[3]," +/- ",err1[3]);

etc.
( https://root.cern.ch/doc/master/classTF1.html#a8c0221f3e821e9557fe366e7edae90fa
https://root.cern.ch/doc/master/classTPaveText.html )

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.