#ifndef __CINT__ #include "RooGlobalFunc.h" #endif #include "RooRealVar.h" #include "RooDataSet.h" #include "RooDataHist.h" #include "RooGaussian.h" #include "RooChebychev.h" #include "RooAddPdf.h" #include "TCanvas.h" #include "RooPlot.h" #include "TTree.h" #include "TH1D.h" #include "TAxis.h" #include #include #include using namespace RooFit ; using namespace std; void acq32_roofit(){ auto c1 = new TCanvas("Acquisizione 3","1",700,500); c1->SetGridx(); c1->SetGridy(); c1->SetTickx(); c1->SetTicky(); TH1D *h = new TH1D("h", "Acquisizione 3", 301,.0,301); gStyle->SetOptStat(0); Int_t i=0, Ndata=0; Double_t X; ifstream assey("gaussy.txt"); if (assey.is_open()) { while(assey >> X) { //cout << "Il dato numero " << Ndata <<" รจ " << X << endl; h->Fill(i,X); h->SetBinContent(i+1,X); Ndata++; i++; } assey.close(); } using namespace RooFit; RooRealVar canale{"canale", "canale", 0, 0, 300}; canale.setRange("r1", 64, 300); // fit range canale.setRange("r1", 64, 150); // fit range RooDataHist dataHist{"dataHist", "dataHist", canale, h}; RooRealVar landauMean{"landauMean", "landauMean", 80, 50, 150}; RooRealVar landauSigma{"landauSigma", "landauSigma", 20, 1, 100}; RooLandau landau{"landau", "landau", canale, landauMean, landauSigma}; RooRealVar gaussMean{"gaussMean", "gaussMean", 0, -50, 50}; RooRealVar gaussSigma{"gaussSigma", "gaussSigma", 20, 1, 100}; RooGaussian gauss{"gauss", "gauss", canale, gaussMean, gaussSigma}; RooFFTConvPdf model("model","landau (X) gauss",canale,landau,gauss) ; model.fitTo(dataHist, Range("r1")); RooPlot* frame1 = canale.frame(); dataHist.plotOn(frame1, Range("r1")); model.plotOn(frame1, LineColor(kBlue)); frame1->Draw(); cout << "chi^2 = " << frame1->chiSquare() << endl; }