#include "TCanvas.h" #include "TPad.h" #include "TMultiGraph.h" #include "TGraph.h" #include "TGraphErrors.h" #include "TAxis.h" #include "TLegend.h" #include "TLatex.h" #include "TROOT.h" #include "TPaveStats.h" #include "TStyle.h" #include "TFitResult.h" #include "TF1.h" #include "Math/ProbFuncMathCore.h" #include "Math/QuantFuncMathCore.h" #include #include #include #include void sigmavalue() { gStyle->SetOptFit(0); const char *datain = "C:/data_sigma_m.txt"; const char *dataout = "C:/simulazione/sigmavalue_m.png"; ofstream results; results.open("C:/simulazione/sigmavalue_results_m.txt", ios::out); TCanvas *c01 = new TCanvas("c01","multigraph",1280,1024); //c01->SetGrid(); float offx=1.3; float offy=1.3; float margr=0.08; float w=3; float margl=0.12; float line=2; gPad->SetLeftMargin(margl); gPad->SetRightMargin(margr); TGraphErrors *graph = new TGraphErrors(datain,"%lg %lg 0 %lg"); graph->SetMarkerColor(kBlue); graph->SetLineColor(kBlue); graph->SetMarkerStyle(3); graph->SetMarkerSize(1.3); graph->SetLineWidth(line); TF1 *fitspettro = new TF1("fitspettro", "pol0", 1,3); TPaveText *t=new TPaveText(0.7,0.85,0.75,0.9,"brNDC"); // fitspettro->SetParName(0,"e_{h}"); fitspettro->SetParName(0,"k"); //fitspettro->SetParName(0,"q"); fitspettro->SetLineColor(kRed+2); auto result= graph->Fit("fitspettro","S"); double chi2 = result->Chi2(); double ndf = result->Ndf(); double pvalue = ROOT::Math::chisquared_cdf_c(chi2, ndf); fitspettro->SetLineWidth(line); fitspettro->Draw(); graph->Draw("ap"); fitspettro->GetYaxis()->SetTitleOffset(offy); fitspettro->GetXaxis()->SetTitleOffset(offx); // graph->SetTitle("Restitution coefficient"); graph->SetTitle(""); //graph->SetTitle("Initial height"); // graph->GetXaxis()->SetTitle("Collision"); //graph->GetYaxis()->SetTitle("e_{h}"); //graph->GetYaxis()->SetTitle("ln(h(x))(m)"); graph->GetYaxis()->SetTitle("m"); graph->GetYaxis()->SetTitleOffset(offy); graph->GetXaxis()->SetTitleOffset(offx); graph->GetXaxis()->ChangeLabel(0,-45,-1,-1,-1,-1,""); TLegend* leg = new TLegend(0.75, 0.75, .85, .85); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(graph, "Data", "ap"); leg->AddEntry(fitspettro, "Fit", "l"); leg->Draw(); gPad->Update(); /* TPaveStats *stat = (TPaveStats*)(graph->FindObject("stats")); stat->SetTextColor(kRed+2); stat->SetX1NDC(0.85); stat->SetX2NDC(0.98); stat->SetY1NDC(0.79); stat->SetY2NDC(0.94);*/ gPad->Update(); gPad->Update(); Int_t bin1= graph->GetXaxis()->FindBin(1); Int_t bin2= graph->GetXaxis()->FindBin(2); Int_t bin3= graph->GetXaxis()->FindBin(3); graph->GetHistogram()->GetXaxis()->SetBinLabel(bin1,"Cathetometer"); gPad->Update(); graph->GetHistogram()->GetXaxis()->SetBinLabel(bin2,"Phyphox"); gPad->Update(); graph->GetHistogram()->GetXaxis()->SetBinLabel(bin3,"Arduino"); gPad->Update(); gPad->Update(); std::cout << "p value of the fit : " << pvalue << std::endl; std::cout << "number of sigma is " << ROOT::Math::normal_quantile_c(0.5*pvalue,1) << std::endl; results << "p value of the fit : " << pvalue << endl; results << "number of sigma is " << ROOT::Math::normal_quantile_c(0.5*pvalue,1)<Print(dataout); }