int histo(){ // Definizione di un istogramma monodimensionale da riempire con float TH1F *h1 = new TH1F("h1","Istogramma 1D",100,-5.,5.); float x, y; fstream f, g; f.open("gaus.dat",ios::in); for (int i = 0; i < 10000; i++) { f >> x; h1->Fill(x); } f.close(); TCanvas *c1 = new TCanvas("c1","Istogramma 1D",600,400); h1->GetXaxis()->SetTitle("Titolo sull'asse X"); h1->GetYaxis()->SetTitle("Titolo sull'asse Y"); h1->Draw(); // Puoi prendere le informazioni che ti interessano cout << "La media dell'istrogramma h1 vale -->> " << h1->GetMean() << endl; cout << "L'RMS dell'istogramma h1 vale -->> " << h1->GetRMS() << endl; // Riempimento di un istogramma con FillRandom TH1F *h2 = new TH1F("h2","Istogramma 1D",100,-5.,5.); h2->FillRandom("gaus",10000); TCanvas *c2 = new TCanvas("c2","Istogramma 1D",600,400); h2->Draw(); cout << "La media dell'istrogramma h2 vale -->> " << h2->GetMean() << endl; cout << "L'RMS dell'istogramma h2 vale -->> " << h2->GetRMS() << endl; TCanvas *c3 = new TCanvas("c3","Confronto",600,400); h1->SetLineColor(2); h1->SetLineWidth(3); h2->SetLineColor(3); h1->SetFillColor(4); h1->Draw(); h2->Draw("same"); TLegend *leg = new TLegend(0.55,0.6,0.85,0.85); leg->AddEntry(h1,"Histo 1","l"); leg->AddEntry(h2,"Histo 2","l"); leg->Draw(); // Istogramma bidimensionale f.open("xy.dat",ios::in); TH2F *h4 = new TH2F("h4","Istogramma 2D",100,-0.003,0.003,100,-0.003,0.003); for (int i = 0; i < 10000; i++) { f >> x >> y; h4->Fill(x,y); } f.close(); g.close(); TCanvas *c4 = new TCanvas("c4","Istogramma 2D",600,400); h4->Draw("lego"); c4->Print("th2.ps"); }