#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" #include "TGraph.h" double FunFit(const double *x, const double *p) { double l = x[0]; double a = p[0]; double b = p[1]; double c = p[2]; y = (l/15+0.964)*(l/15+0.964)*a+2*(l/15+0.964)*(l*l*/15-0.36*l)*b+(l*l*/15-0.36*l)*(l*l*/15-0.36*l)*c; return y; } void grafico() { char datagamma[200]= "D:/Datifit.txt"; char dataout[200]="D:/graph.pdf"; TCanvas *c36 = new TCanvas("c36","multigraph",1280,1024); //c36->SetLogx(); //c36->SetLogy(); float offx=1.1; float offy=1.5; float margr=0.08; float margl=0.12; gStyle->SetOptFit(); gPad->SetLeftMargin(margl); gPad->SetRightMargin(margr); TMultiGraph *mg = new TMultiGraph(); gStyle->SetOptStat("nemr"); // "nemr" or "neMR" gStyle->SetOptFit(112); TGraphErrors *gamma = new TGraphErrors(datagamma,"%lg %lg"); gamma->SetMarkerColor(kBlue); gamma->SetLineColor(kBlue); gamma->SetMarkerStyle(kFullCircle); mg->Add(gamma); mg->Draw("ALP"); mg->SetTitle("Title"); mg->GetXaxis()->SetTitle("x (m)"); mg->GetYaxis()->SetTitle("y (m)"); mg->GetYaxis()->SetTitleOffset(offy); c36->Modified(); c36->Update(); TF1 *myfit = new TF1("myfit", FunFit); myfit->SetParNames("a", "b", "c"); myfit->SetParameters(1, 1, 1); const char *fit_options = ""; // e.g. "" or "L" or "W" or "WW" myfit->SetParameters(1, 1, 1); myfit->SetLineColor(kOrange); //fitdistrlatele->SetLineStyle(8); mg->Fit(myfit, fit_options); c->Update(); c36->Modified(); c36->Update(); TLegend* leg10 = new TLegend(0.7, 0.83, .6, .89); leg10->SetNColumns(1); leg10->AddEntry(gamma, "Dati", "lp"); leg10->Draw("same"); c36->Modified(); gROOT->SetBatch(); c36->Print(dataout);delete c36; gROOT->SetBatch(); exit(); }