#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 = "data_sigma_q.txt"; const char *dataout = "sigmavalue_q.png"; ofstream results; results.open("sigmavalue_results_q.txt", ios::out); TCanvas *c01 = new TCanvas("c01","multigraph",1280,1024); //c01->SetGrid(); float offx=1.; float offy=1.8; 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); graph->GetYaxis()->SetTitleSize(40); graph->GetYaxis()->SetTitleFont(43); graph->GetYaxis()->SetLabelFont(43); graph->GetYaxis()->SetLabelSize(40); graph->GetXaxis()->SetTitleSize(40); graph->GetXaxis()->SetTitleFont(43); //graph->GetXaxis()->SetLabelFont(43); graph->GetXaxis()->SetLabelSize(100); 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("k"); graph->GetYaxis()->SetTitle("ln(h_{0}/1m)"); graph->GetYaxis()->SetTitleOffset(offy); graph->GetXaxis()->SetTitleOffset(offx); 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->GetXaxis()->ChangeLabel(bin1, 70, 0.03, 31, -1, -1,Form("Cathetometer")); gPad->Update(); graph->GetXaxis()->ChangeLabel(bin2, 70, 0.03, 31, -1, -1,Form("Phyphox")); gPad->Update(); graph->GetXaxis()->ChangeLabel(bin3, 70, 0.03, 31, -1, -1,Form("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); }