#include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TGaxis.h" #include "TRandom.h" void histo(Int_t xlow, Int_t xup) { //example of macro illustrating how to superimpose two histograms //with different scales in the "same" pad. // To see the output of this macro, click here TCanvas *c1 = new TCanvas("c1","hists with different scales",600,400); gStyle->SetOptFit(1112); gStyle->SetOptStat(111); //create/fill draw h1 gStyle->SetOptStat(kTRUE); TH1F *h1 = new TH1F("hcal","Calibrazione",2048,-0.5,2047.5); TH1F *h2 = new TH1F("hcal","Selected bin",xup-xlow+1,xlow-0.5,xup+0.5); string fileNameString = "../dati/camac/calibrazione-070606.dat"; char* fileName = fileNameString.c_str(); ifstream inputFile; inputFile.open(fileName); Int_t ncanale = 0; Float_t formato1 = 0; Float_t formato2 = 0; Float_t conteggio = 0; inputFile >> formato1 >> formato2; while (1) { inputFile >> conteggio; if (!inputFile.good()) break; // riempiamo l'istogramma h1->Fill(ncanale,conteggio); h2->Fill(ncanale,conteggio); ncanale++; } h1->Draw(); TF1* f1 = new TF1("gausID","gaus",xlow,xup); h1->Fit("gausID","R"); Double_t chi2 = f1->GetChisquare(); Double_t p0 = f1->GetParameter(0); Double_t p1 = f1->GetParameter(1); Double_t p2 = f1->GetParameter(2); Double_t ep0 = f1->GetParError(0); Double_t ep1 = f1->GetParError(1); Double_t ep2 = f1->GetParError(2); cout <<" Chi2 = "<Update(); c1->WaitPrimitive(); h2->Draw("E"); }