/// used in display_beamprofile() : not working ! void getEllipseParameters(const float * x_data, const float * y_data, const unsigned int N, float& x_width, float& y_width, float& angle) { // In order to fit a good ellipse on the scattered plot : // 1) The TH2 is copied into a TGraph, to fit it with y(x) = ax => to retrieve the angle // 2) Rotation of the Graph to get the RMS in X and Y // 3) Creation of the final ellipse, with the good widths and angle TCanvas * ca0 = new TCanvas; ca0->Divide(2,1); ca0->cd(1); TGraph * draft = new TGraph(N,x_data,y_data); draft->Draw("AP"); draft->Fit("pol1","Q"); TF1 * pol1 = draft->GetFunction("pol1"); pol1->Draw("same"); // gets the angle [rad] angle = asin(1.) - atan(pol1->GetParameter(1)); double x_datarot[N], y_datarot[N]; for (unsigned int i=0; i<N; i++) { x_datarot[i]= x_data[i]*cos(angle) - y_data[i]*sin(angle); y_datarot[i]= x_data[i]*sin(angle) + y_data[i]*cos(angle); } ca0->cd(2); TGraph * draft2 = new TGraph(N,x_datarot,y_datarot); draft2->Draw("AP"); x_width = draft2->GetRMS(1); y_width = draft2->GetRMS(2); angle = 180-90*angle/asin(1.); // draft->Draw("AP"); ca0->cd(1); TEllipse * ell = new TEllipse(draft->GetMean(1),draft2->GetMean(2),x_width*3,y_width*3); ell->SetTheta(angle); ell->Draw("same"); //cout << "x = " << x_width << "\t y = " << y_width << "\t angle = " << angle << endl; // delete draft2; // delete draft; // delete ca0; return; }