void Calibration(){ auto fenetre = new TCanvas("Regression_lineaire", "Calibration", 700 , 500) ; fenetre->SetLeftMargin(0.15); gStyle->SetOptFit(1); // Display the fir parameters const Int_t n = 8 ; // Total number of data points in file. // number of data in Si1 files : 11 // number of data in Si2 files : 10 // number of data in Si3 files : 8 // number of data in Si4 files : 6 //_____________________________________________________________________________________ // Experimental datas. // Storing values of ENERGIES in a 1D array. Double_t E[n+3] ; Double_t C[n+3] ; // Uncertainty on the energy. Double_t X_a[3]; Double_t Y_a[3]; Double_t X[n]; Double_t Y[n]; // part for Si calibration ifstream data("E_loss_24_86_Si_3.txt"); // file storing channel datas. for(Int_t i = 0 ; i < n+3 ; i++){ data >> C[i] >> E[i] ; // filling the arrays with the values of the file. } data.close(); for (Int_t i = 0 ; i < n ; i++) { Y[i] = C[i]; X[i] = E[i]; } for (Int_t i = 0 ; i < 3 ; i++){ Y_a[i] = C[n+i]; X_a[i] = E[n+i]; } TMultiGraph *mg = new TMultiGraph(); mg->SetTitle("Calibration Ligne Faisceau"); // Drawing the Graph with the TGraph class. TGraph *f1 = new TGraph(n, X, Y); f1->SetMarkerColor(4); f1->SetMarkerSize(2); f1->SetLineColor(4); TGraph *alpha = new TGraph(3, X_a, Y_a); alpha->SetMarkerColor(3); alpha->SetMarkerSize(2); alpha->SetLineColor(3); // adding all the Graphs into the total graph for the plot. mg->Add(f1); mg->Add(alpha); alpha->Draw("AL*"); mg->Draw("AL*"); mg->GetXaxis()->SetTitle("Energy [keV]"); mg->GetYaxis()->SetTitle("Channels"); //_____________________________________________________________________________________ // Linear regression = linear fit with a straight line (type y = ax +b) TF1 *reglin = new TF1("Regression lineaire","[0]*x+[1]", 3000, 11000); reglin->SetParameters(0.2,2); reglin->SetParNames("Gain", "E0"); //parametrisation : a = gain ; b = offset energy (E0) mg->Fit(reglin); float chi2 = reglin->GetChisquare(); cout << "chi2 = " << chi2 << endl; }