#include //////////////functions//////////////// double trace(double A[2][2]){ double ans; ans=A[0][0]+A[1][1]; return ans; } double det(double A[2][2]){ double ans; ans=A[0][0]*A[1][1]-A[0][1]*A[1][0]; return ans; } int TtoT(double A[2][2],double B[2][2],double C[2][2]){ for(int i=0;i<2;++i){ for(int j=0;j<2;++j){ C[i][j]=0; for(int k=0;k<2;++k){ C[i][j]=C[i][j]+A[i][k]*B[k][j]; } printf("%lf ",C[i][j]); } printf("\n"); } return 1; } int SumTwo(double A[2][2], double B[2][2],double C[2][2]){ for(int i=0;i<2;++i){ for(int j=0;j<2;++j){ C[i][j]=0; C[i][j]=A[i][j]+B[i][j]; } } return 1; } int DiffTwo(double A[2][2], double B[2][2],double C[2][2]){ for(int i=0;i<2;++i){ for(int j=0;j<2;++j){ C[i][j]=0; C[i][j]=A[i][j]-B[i][j]; } } return 1; } int FtoF(double A[4][4], double B[4][4],double C[4][4]){ printf("FtoF-A*B---\n"); printf("---A-------------\n"); printf("%lf %lf %lf %lf\n",A[0][0],A[0][1],A[0][2],A[0][3]); printf("%lf %lf %lf %lf\n",A[1][0],A[1][1],A[1][2],A[1][3]); printf("%lf %lf %lf %lf\n",A[2][0],A[2][1],A[2][2],A[2][3]); printf("%lf %lf %lf %lf\n",A[3][0],A[3][1],A[3][2],A[3][3]); printf("---B-------------\n"); printf("%lf %lf %lf %lf\n",B[0][0],B[0][1],B[0][2],B[0][3]); printf("%lf %lf %lf %lf\n",B[1][0],B[1][1],B[1][2],B[1][3]); printf("%lf %lf %lf %lf\n",B[2][0],B[2][1],B[2][2],B[2][3]); printf("%lf %lf %lf %lf\n",B[3][0],B[3][1],B[3][2],B[3][3]); printf("---A*B-------------\n"); for(int i=0;i<4;++i){ for(int j=0;j<4;++j){ C[i][j]=0; for(int k=0;k<4;++k){ C[i][j]=C[i][j]+A[i][k]*B[k][j]; } printf("%lf ",C[i][j]); } printf("\n"); } return 1; } int Inverse(double A[4][4],double B[4][4]){ int i,j,k; double tmp_a[4][4]; double inv_a[4][4]; double buf; int n=4; for(i=0;i=0){ t_mu=1-symp; t_mu=sqrt(t_mu); if(muMinus==1)t_mu=-1*t_mu; // printf("t_mu=%lf\n",t_mu); //x-x' inpA=t_mu*fDD[0][0]; inpB=t_r4*fDD[2][2]-t_r2*fDD[3][2]; inpC=t_mu*fDD[1][0]; inpD=t_r1*fDD[3][2]-t_r3*fDD[2][2]; // printf("inpA,B,C,D=%lf %lf %lf %lf\n",inpA,inpB,inpC,inpD); ellipseABC(inpA,inpB,inpC,inpD,&outA,&outB,&outC); // printf("outA,B,C=%lf %lf %lf\n",outA,outB,outC); //ans= slope(outA,outB,outC); ans= ellipseTheta(outA,outB,outC); ans=ans*-1; ans=tan(ans); judgexxp=(ax-ans)/(double)ax; if(sqrt(pow(judgexxp,2))-1){ //judge=sqrt(pow(judgeyyp,2)+pow(judgexy,2)); //2018Feb3-keep //judge=sqrt(pow(judgexy,2)); //2018Feb3-keep judge=sqrt(pow(judgexxp,2)+pow(judgeyyp,2)+pow(judgexy,2)); //2018Feb3-keep // judge=sqrt(pow(judgexxp,2)+pow(judgeyyp,2)+pow(judgexy,2)+pow(judgexpyp,2)); //judge=sqrt(pow(judgexy,2)+pow(judgexpyp,2)); //judge=sqrt(pow(judgeyyp,2)+pow(judgexy,2)+pow(judgexpyp,2)); //judge=sqrt(pow(judgexxp,2)+pow(judgeyyp,2)); //judge=sqrt(pow(judgexy,2)); if(minimum>judge){ printf("good sample :%d %d %d %d: %lf %lf %lf %lf mu=%lf r1r4-r2r3=%lf\n",i_1,i_2,i_3,i_4,t_r1,t_r2,t_r3,t_r4,t_mu,symp); printf("judge :: %lf %lf %lf %lf \n",judgexxp,judgeyyp,judgexy,judgexpyp); minimum=judge; ResultsR[0]=t_r1; ResultsR[1]=t_r2; ResultsR[2]=t_r3; ResultsR[3]=t_r4; ResultMu=t_mu; } } if(i_1==(num1/2-1) && i_2==(num2/2-1) && i_3==(num3/2-1) && i_4==(num4/2-1)){ printf("R1,R2,R3,R4: %lf %lf %lf %lf\n",sR[0],sR[1],sR[2],sR[3]); printf(":%d %d %d %d: %lf %lf %lf %lf mu=%lf\n",i_1,i_2,i_3,i_4,t_r1,t_r2,t_r3,t_r4,t_mu); printf("judge=%lf minimum=%lf\n",judge,minimum); getchar(); } }//end if(symp<1) } } } } //////////RESULT/////////////// printf("---GET RESULT R1-R4\n"); printf("R=%lf %lf %lf %lf mu=%lf\n",ResultsR[0],ResultsR[1],ResultsR[2],ResultsR[3],ResultMu); printf("R2/R1=%lf R3/R1=%lf R4/R1=%lf\n",ResultsR[1]/(double)ResultsR[0],ResultsR[2]/(double)ResultsR[0],ResultsR[3]/(double)ResultsR[0]); //MAIN END //input r1-r4 and mu double R1,R2,R3,R4; R1=ResultsR[0];R2= ResultsR[1];R3=ResultsR[2];R4= ResultsR[3];//2018Feb3 keep //R1=-0.19;R2= -1.0;R3=-2.26;R4= -1.66;//2018Feb3 keep double Rmu=1-(R1*R4-R2*R3); Rmu=sqrt(Rmu); printf("R1-4 =%lf %lf %lf %lf\n",R1,R2,R3,R4); //////////////////////////// RR[0][0]=Rmu;RR[0][1]=0; RR[0][2]=-1*R4;RR[0][3]=R2; RR[1][0]=0; RR[1][1]=Rmu;RR[1][2]=R3; RR[1][3]=-1*R1; RR[2][0]=R1; RR[2][1]=R2; RR[2][2]=Rmu; RR[2][3]=0; RR[3][0]=R3; RR[3][1]=R4; RR[3][2]=0; RR[3][3]=Rmu; RRini[0][0]=1; RRini[0][1]=0;RRini[0][2]=0; RRini[0][3]=0; RRini[1][0]=0; RRini[1][1]=1;RRini[1][2]=0; RRini[1][3]=0; RRini[2][0]=0; RRini[2][1]=0;RRini[2][2]=1; RRini[2][3]=0; RRini[3][0]=0; RRini[3][1]=0;RRini[3][2]=0; RRini[3][3]=1; ///symplectic check/// TransT4(RR,tRR); FtoF(tRR,JJ4,dmy4); FtoF(dmy4,RR,sRR); printf("symplectic? RR---\n"); for(int ii=0;ii<4;++ii){ for(int jj=0;jj<4;++jj){ printf("%lf ",sRR[ii][jj]); } printf("\n"); } if(pow(sRR[0][0],2)>1)getchar(); ////////////////// double RR_inv[4][4]; Inverse(RR,RR_inv); printf(" RR---\n"); for(int ii=0;ii<4;++ii){ for(int jj=0;jj<4;++jj){ printf("%lf ",RR[ii][jj]); } printf("\n"); } printf(" RR_inv---\n"); for(int ii=0;ii<4;++ii){ for(int jj=0;jj<4;++jj){ printf("%lf ",RR_inv[ii][jj]); } printf("\n"); } getchar(); Inverse(RRini,RRini_inv); ///////////////////////////// FtoF(RR_inv,fDD,MAT); ///symplectic check/// TransT4(MAT,tMAT); FtoF(tMAT,JJ4,dmy4); FtoF(dmy4,MAT,sMAT); printf("symplectic? MAT---\n"); for(int ii=0;ii<4;++ii){ for(int jj=0;jj<4;++jj){ printf("%lf ",sMAT[ii][jj]); } printf("\n"); } if(pow(sMAT[0][0],2)>1)getchar(); ////check plot////////// double VecIn[4],VecOut[4],theta; double cos_alphaX,cos_alphaY; double sin_alphaX,sin_alphaY; cos_alphaX=ax; sin_alphaX=sqrt(1-cos_alphaX*cos_alphaX); cos_alphaY=ay; sin_alphaY=sqrt(1-cos_alphaY*cos_alphaY); double fx[128],fy[128],fz[128]; double fxx[128],fyy[128]; double fVx[128],fVy[128],fVz[128]; double fVxx[128],fVyy[128]; double fy2[128],fVy2[128]; double rang=0.02;//3cm for(int ii=0;ii<128;++ii){ fx[ii]=(ii-64)/(double)64*rang; fz[ii]=0; fy[ii]=fx[ii]*a1; fVy[ii]=fy[ii]*ay; fVx[ii]=fx[ii]*ax; fVyy[ii]=fVxx[ii]*a2; fyy[ii]=fxx[ii]*a1; } TGraph *gr_testx; TGraph *gr_testy; TGraph *gr_testxy,*gr_testxpyp; gr_testx = new TGraph(128,fx,fVx); gr_testy = new TGraph(128,fy,fVy); gr_testxy = new TGraph(128,fx,fy); gr_testxpyp = new TGraph(128,fVx,fVy); ////////////CIRCLE///////////// int evtNum=100; double xc[100],yc[100],pxc[100],pyc[100]; double xc1[100],yc1[100],pxc1[100],pyc1[100]; double xc2[100],yc2[100],pxc2[100],pyc2[100]; double xc0[100],yc0[100],pxc0[100],pyc0[100]; double xc20[100],yc20[100],pxc20[100],pyc20[100]; double ranx=2E-3; double rany=2E-3; double ranpx=7E-5; double ranpy=7E-5; srand((unsigned) time(NULL)); double dd1,dd2,dd3,dd4; double theta1,theta2; double theta3,theta4; //cirmod0 x-x' theta1, y-y' theta1 //cirmod01,02 x-x' theta1, y-y' -theta1 //cirmod5,03 x-x' theta1, y-y' theta2 //cirmod6,04 x-y theta1, x'-y' theta2 //cirmod7,05 x theta1, x' theta2 y theta3 y' theta4 for(int i=0;iSetStyle("Plain"); gROOT->ForceStyle(); gStyle->SetOptStat(0); gStyle->SetCanvasBorderMode(0); gStyle->SetPadColor(0); gStyle->SetTitleFillColor(0); gStyle->SetStatColor(0); int color=0; TCanvas *c2 = new TCanvas("c2","Acceptance c2",200,100,600,600); c2->Divide(2,2); /// c2->cd(1); c2->cd(1)->SetLeftMargin(0.18); // TH2F* frame2_1 = new TH2F("frame2_1"," ",10, -6, 6, 10, -6, 6); TH2F* frame2_1 = new TH2F("frame2_1"," ",10, -2E-2, 2E-2, 10, -2*1E-2, 2*1E-2); frame2_1->SetTitle(""); frame2_1->GetXaxis()->SetLabelSize(0.04); frame2_1->GetXaxis()->SetTitleSize(0.05); frame2_1->GetYaxis()->SetLabelSize(0.04); frame2_1->GetYaxis()->SetTitleSize(0.05); frame2_1->GetXaxis()->SetTitle("X (m)"); frame2_1->GetYaxis()->SetTitle("X' (rad)"); frame2_1->GetYaxis()->SetTitleOffset(1.3); frame2_1->SetStats(0); frame2_1->Draw(); gr_xc0->SetMarkerStyle(7); gr_xc0->SetMarkerColor(2); gr_xc0->SetLineColor(2); gr_xc0->Draw("pl"); gr_xc1->SetMarkerStyle(7); gr_xc1->SetMarkerColor(3); gr_xc1->SetLineColor(3); // gr_xc1->Draw("pl"); gr_xc20->SetMarkerStyle(7); gr_xc20->SetMarkerColor(4); gr_xc20->SetLineColor(4); gr_xc20->Draw("p"); gr_testx->SetMarkerStyle(7); gr_testx->SetMarkerColor(3); gr_testx->SetLineColor(6); gr_testx->Draw("l"); c2->cd(1)->SetGridx(); c2->cd(1)->SetGridy(); c2->cd(2); c2->cd(2)->SetLeftMargin(0.18); TH2F* frame2_2 = new TH2F("frame2_2"," ",10, -2E-2, 2E-2, 10, -2E-2, 2E-2); frame2_2->SetTitle(""); frame2_2->GetXaxis()->SetLabelSize(0.04); frame2_2->GetXaxis()->SetTitleSize(0.05); frame2_2->GetYaxis()->SetLabelSize(0.04); frame2_2->GetYaxis()->SetTitleSize(0.05); frame2_2->GetXaxis()->SetTitle("Y (m)"); frame2_2->GetYaxis()->SetTitle("Y' (rad)"); frame2_2->GetYaxis()->SetTitleOffset(1.3); frame2_2->SetStats(0); frame2_2->Draw(); gr_yc0->SetMarkerStyle(7); gr_yc0->SetMarkerColor(2); gr_yc0->SetLineColor(2); gr_yc0->Draw("pl"); gr_yc1->SetMarkerStyle(7); gr_yc1->SetMarkerColor(3); gr_yc1->SetLineColor(3); // gr_yc1->Draw("pl"); gr_yc20->SetMarkerStyle(7); gr_yc20->SetMarkerColor(4); gr_yc20->SetLineColor(4); gr_yc20->Draw("pl"); // gr_testy->SetMarkerStyle(7); gr_testy->SetMarkerColor(3); gr_testy->SetLineColor(6); gr_testy->Draw("l"); c2->cd(2)->SetGridx(); c2->cd(2)->SetGridy(); /// /// c2->cd(3); c2->cd(3)->SetLeftMargin(0.18); TH2F* frame2_3 = new TH2F("frame2_3"," ",10, -2E-2, 2E-2, 10, -2E-2, 2E-2); frame2_3->SetTitle(""); frame2_3->GetXaxis()->SetLabelSize(0.04); frame2_3->GetXaxis()->SetTitleSize(0.05); frame2_3->GetYaxis()->SetLabelSize(0.04); frame2_3->GetYaxis()->SetTitleSize(0.05); frame2_3->GetXaxis()->SetTitle("X (m)"); frame2_3->GetYaxis()->SetTitle("Y (m)"); frame2_3->GetYaxis()->SetTitleOffset(1.3); frame2_3->SetStats(0); frame2_3->Draw(); gr_xyc0->SetMarkerStyle(7); gr_xyc0->SetMarkerColor(2); gr_xyc0->SetLineColor(2); gr_xyc0->Draw("lp"); gr_xyc1->SetMarkerStyle(9); gr_xyc1->SetMarkerColor(3); gr_xyc1->SetLineColor(3); // gr_xyc1->Draw("p"); gr_xyc20->SetMarkerStyle(7); gr_xyc20->SetMarkerColor(4); gr_xyc20->SetLineColor(4); gr_xyc20->Draw("lp"); gr_xyc2->SetMarkerStyle(7); gr_xyc2->SetMarkerColor(7); gr_xyc2->SetLineColor(4); // gr_xyc2->Draw("p"); // gr_testxy->SetMarkerStyle(7); gr_testxy->SetMarkerColor(3); gr_testxy->SetLineColor(6); gr_testxy->Draw("l"); color=1; c2->cd(3)->SetGridx(); c2->cd(3)->SetGridy(); c2->cd(4); c2->cd(4)->SetLeftMargin(0.18); TH2F* frame2_4 = new TH2F("frame2_4"," ",10, -2E-2, 2E-2, 10, -2E-2, 2E-2); frame2_4->SetTitle(""); frame2_4->GetXaxis()->SetLabelSize(0.04); frame2_4->GetXaxis()->SetTitleSize(0.05); frame2_4->GetYaxis()->SetLabelSize(0.04); frame2_4->GetYaxis()->SetTitleSize(0.05); frame2_4->GetXaxis()->SetTitle("X' (rad)"); frame2_4->GetYaxis()->SetTitle("Y' (rad)"); frame2_4->GetYaxis()->SetTitleOffset(1.3); frame2_4->SetStats(0); frame2_4->Draw(); gr_xpypc0->SetMarkerStyle(7); gr_xpypc0->SetMarkerColor(2); gr_xpypc0->SetLineColor(2); gr_xpypc0->Draw("pl"); gr_xpypc1->SetMarkerStyle(9); gr_xpypc1->SetMarkerColor(3); gr_xpypc1->SetLineColor(3); // gr_xpypc1->Draw("p"); // gr_xpypc->SetMarkerStyle(9); // gr_xpypc->SetMarkerColor(kGray); // gr_xpypc->SetLineColor(kGray); // gr_xpypc->Draw("pl"); gr_xpypc20->SetMarkerStyle(7); gr_xpypc20->SetMarkerColor(4); gr_xpypc20->SetLineColor(4); gr_xpypc20->Draw("pl"); gr_testxpyp->SetMarkerStyle(7); gr_testxpyp->SetMarkerColor(3); gr_testxpyp->SetLineColor(6); gr_testxpyp->Draw("l"); color=1; c2->cd(4)->SetGridx(); c2->cd(4)->SetGridy(); ////check plot END////////// printf("R=%lf %lf %lf %lf mu=%lf\n",ResultsR[0],ResultsR[1],ResultsR[2],ResultsR[3],ResultMu); }