#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 std; void acq32def(){ auto c1 = new TCanvas("Acquisizione 3","Alina's Fit",700,500); TH1D *h = new TH1D("Gaussian fit", "Acquisizione 3", 301,.0,301); c1->SetGridx(); c1->SetGridy(); c1->SetTickx(); c1->SetTicky(); Int_t i=0, Ndata=0; Double_t X; Double_t par[6],partotal[6], partotalerror[6],parerror[6]; ifstream assey("/Users/alinasoflau/Desktop/plateau/acquisizione3/gaussyy.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"); TF1 *g1 = new TF1("g1","gaus(0)", 64,94); // TF1 *g2 = new TF1("g2","landau(0)", 64,300); // g2->SetParNames("LandConst","MPV","LSigma"); // TF1 *g3 = new TF1("g3","gaus(0)+landau(3)", 64,300); //g3->SetParNames("Constant","Mean","Sigma","LandConst","MPV","LSigma"); g1->SetLineWidth(2); g1->SetLineColor(kMagenta); // g2->SetLineWidth(2); // g2->SetLineColor(kMagenta); // g3->SetLineWidth(2); // g3->SetLineColor(kGreen); h->Fit(g1,"WL R "); g1->GetParameters(&par[0]); gStyle->SetOptFit(1111); // h->Fit(g2,"WL R" ); // g2->GetParameters(&par[3]); // g3->SetParameters(par); // h->Fit(g3,"WL R" ); // g3->GetParameters(&partotal[0]); //TF1 *g4 = new TF1("g4","gaus(0)", 64,115); //TF1 *g5 = new TF1("g5","landau(0)", 64,150); //g4->SetParameters(&partotal[0]); //g5->SetParameters(&partotal[3]); //g4->SetLineWidth(2); //g4->SetLineColor(kYellow-7); //g5->SetLineWidth(2); //g5->SetLineColor(kOrange+1); auto legend = new TLegend(0.9,0.9,0.4,0.6); //estremo superiore, estremo destro, estremo sinistro, estremo inferiore, legend->SetHeader("Gaussian Fit","C"); // option "C" allows to center the header legend->SetFillColor(0); legend->SetNColumns(1); legend->AddEntry(g1,Form(" #sigma = %0.2f\n #pm %0.2f\n",par[2],g1->GetParError(2)),"p"); legend->AddEntry(g1,Form(" Mean = %0.2f\n #pm %0.2f\n",par[1],g1->GetParError(1)),"p"); legend->AddEntry(g1,Form(" Constant = %0.2f\n #pm %0.2f\n",par[0],g1->GetParError(0)),"p"); //legend->AddEntry(g2,Form(" #sigma = %0.2f\n #pm %0.2f\n",par[5],g2->GetParError(2)),"p"); // legend->AddEntry(g2,Form(" Constant = %0.2f\n #pm %0.2f\n",par[3],g2->GetParError(2)),"p"); // legend->AddEntry(g3,"Gaussian + Landau fit","l"); // legend->AddEntry(g4,Form("Gaussian extracted from total: #sigma = %0.2f\n #pm %0.2f\n",partotal[2],g3->GetParError(2)),"l"); // legend->AddEntry(g5,Form("Landau extracted from total: #sigma = %0.2f\n #pm %0.2f\n",partotal[5],g3->GetParError(5)),"l"); h->Draw(); g1->Draw("same"); // g2->Draw("same"); // g3->Draw("same"); //g4->Draw("same"); //g5->Draw("same"); //legend->DrawClone("Same"); // TLine *myLine = new TLine(0,75,300,75); //myLine->SetLineColor(4); // myLine->SetLineWidth(2); // myLine->Draw("same"); }