#include void random2() { TCanvas* c1 = new TCanvas ("c1","Random",100,10,700,500); const Double_t xMin = 0; const Double_t xMax = 1;//TMath::Pi(); const Int_t nEv = 1000; TH1F* h1 = new TH1F ("h1","Random",100,xMin,xMax); TF1* f1 = new TF1 ("f1","gaus",xMin,xMax); f1->SetParameters(1,0.5,0.02); TF1* f2 = new TF1 ("f2","pol1",xMin,xMax); f2->SetParameters(1,10); h1->FillRandom("f1",nEv); h1->FillRandom("f2",10000); h1->Draw(); // Fit di h1 con retta TF1* fAll = new TF1 ("fAll","gaus+x*[3]+[4]",xMin,xMax); fAll->SetParameters(1,1,0.01,1,100); h1->Fit("fAll"); f2->SetParameters(fAll->GetParameter(4),fAll->GetParameter(3)); f2->SetLineColor(2); f2->SetLineStyle(4); f2->Draw("same"); TNtuple* ntuple = new TNtuple; TFile* file = new TFile ("pippo.root","RECREATE","Demo ROOT file with histograms"); h1->Write(); file->Close(); }