#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(){ 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("/Users/alinasoflau/Desktop/plateau/gaussy.txt"); if (assey.is_open()) { while(assey >> X) { //cout << "Il dato numero " << Ndata <<" รจ " << X << endl; h->Fill(i,X); Ndata++; i++; } assey.close(); } h->GetYaxis()->SetTitle("Eventi"); h->GetXaxis()->CenterTitle(true); h->GetXaxis()->SetTitle("Canale"); h->GetYaxis()->CenterTitle(true); h->SetLineWidth(0); h->SetFillColor(kAzure+1); h->GetXaxis()->SetLimits(0,300); h->SetMinimum(0.); h->SetMaximum(200.); h->SetOption("hist"); Double_t par[5]; TF1 *g1 = new TF1("g1","gaus(0)", 64,115); g1->GetParameters(&par[0]); TF1 *g2 = new TF1("g2","landau(0)", 64,300); g2->GetParameters(&par[3]); g2->SetParNames("LandConst","MPV","LSigma"); TF1 *g3 = new TF1("g3","gaus(0)+landau(3)", 64,300); g3->SetParameters(par); g1->SetLineWidth(2); g1->SetLineColor(kRed); g2->SetLineWidth(2); g2->SetLineColor(kGreen); g3->SetLineWidth(2); g3->SetLineColor(kBlack); h->Fit(g1,"WL R "); h->Fit(g2,"WL R+" ); h->Fit(g3,"WL R+" ); auto legend = new TLegend(0.9,0.9,0.7,0.7); // legend->SetHeader("Fit","C"); // option "C" allows to center the header legend->SetFillColor(0); legend->SetNColumns(1); legend->AddEntry(g1,"Gaussian fit","l"); legend->AddEntry(g2,"Landau fit","l"); legend->AddEntry(g3,"Landau+Gaussian fit","l"); h->Draw(); g1->Draw("same"); g2->Draw("same"); g3->Draw("same"); legend->DrawClone("Same"); }