muzzle
November 28, 2005, 4:26pm
#1
Hi,
I have been using a TMultiGraph to join 3 different TGraphError and fit them with a pol0. My problem is I can’t get the Fit box to show. Not even with
gStyle->SetOptFit(1111);
I worked around this by printing the Chisquare and NDF on the std out but I think there should be a way to get what I want (like calling PaintFit(TF1 *fit) for a TGraph), I just cant find it.
Can you help me?
Michele
couet
November 28, 2005, 5:18pm
#2
Seems to me it should work. Can you send a small running example reproducing your problem ?
muzzle
November 28, 2005, 5:43pm
#3
Here it is, hope this helps.
#include <TGraph.h>
#include <TMultiGraph.h>
#include <TCanvas.h>
#include <TLegend.h>
#include <TROOT.h>
#include <TStyle.h>
void Example(){
TGraph *g1 = new TGraph();
TGraph *g2 = new TGraph();
TGraph *g3 = new TGraph();
TCanvas *ccc = new TCanvas();
Int_t i;
for(i=0;i<10;i++){
g1->SetPoint(i,i,i%3);
g2->SetPoint(i,i,i%4);
g3->SetPoint(i,i,i%2);
}
ccc->Clear();
g1->SetMarkerStyle(20);
g2->SetMarkerStyle(21);
g3->SetMarkerStyle(22);
g1->SetMarkerColor(2);
g2->SetMarkerColor(3);
g3->SetMarkerColor(4);
TLegend * leg = new TLegend(0.6,0.85,0.95,1);
leg->AddEntry(g1,"1");
leg->AddEntry(g2,"1");
leg->AddEntry(g3,"3");
TMultiGraph *ggg = new TMultiGraph("Esempio","Esempio");
ggg->Add(g1);
ggg->Add(g2);
ggg->Add(g3);
TF1 *ppp = new TF1("ppp","pol0");
gStyle->SetOptFit(1111);
ggg->SetTitle("Esempio");
ggg->Draw("AP");
ggg->Fit(ppp,"V");
//uncomment this to see th workaround I used
/*
char stt[80];
sprintf(stt,"Chisquare/NDF: %f/%d",ppp->GetChisquare(),ppp->GetNDF());
leg->AddEntry(ppp,stt);
leg->Draw();
*/
}
The 3 graph are filled and fitted with a pol0. I cant get a stat box to show up.
Bye,
Michele
esempio.C (1.04 KB)
brun
November 28, 2005, 7:02pm
#4
The fitbox is currently not implemented for a TMultiGraph.
A workaround is to replace in your script the lines:
[code]ggg->Draw(“AP”);
ggg->Fit(ppp,“V”);[/code]by
[code]ggg->Draw(“AP”);
ggg->Fit(ppp,“V0”);
g1.Fit(“pol0”,“q”);
TF1 ff = (TF1 )g1->GetListOfFunctions()->FindObject(“pol0”);
ggg->GetListOfFunctions()->Remove(ff);
g1->GetListOfFunctions()->Add(ppp);[/code]
Rene