// -----------------------------------------------------------------------------// // MISALIGNMENT MATRIX CALCULATION FOR JEMX // // // // -- author: Pascal Favre, ISDC // // pascal.favre@obs.unige.ch // // // // -- root help: // // http://root.cern.ch/root/html/TMinuit.html // // http://root.cern.ch/root/html/ClassIndex.html // // // // -- minimization: see doc // // // const Double_t sigma_ra=0.001*(3.14159265358979323846/180.0); const Double_t sigma_dec=0.001*(3.14159265358979323846/180.0); const Int_t numlines=352; // // // -----------------------------------------------------------------------------// const Double_t pi = 3.14159265358979323846; Double_t mes[3*numlines]; Double_t cat[3*numlines]; Double_t error[3*numlines]; Double_t ra_scx[numlines]; Double_t dec_scx[numlines]; Double_t ra_scz[numlines]; Double_t dec_scz[numlines]; // ---------- Compute chi-square -----------------------------------------------// // Approximation of Minuit Fcn: FCN(npar: num of variable params,grad: optional // vector of first deriv, fval: calculated function value,xval: vect of parms, // iflag: what is to be calculated) void chisq(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag) { Double_t chi=0.0; Double_t chisquare=0.0; Double_t stmscatx,stmscaty,stmscatz; TMatrixD S(3,3); for (Int_t ind=0;indReset(); don't put this !!! reset the global variables !!! FILE *file = fopen("sources","r"); Double_t ra_cat[numlines]; Double_t dec_cat[numlines]; Double_t ra_mes[numlines]; Double_t dec_mes[numlines]; Int_t nline=0; while (nline instead of gMin.SetFCN() gMin->SetFCN(chisq); // mnexcm: "MiNuitEXecuteCoMmand" // mnexcm("command",numeric(s) arg of the command,num of arg specified, // error flag (0 if went fine)) // SET ERRordef [up] Double_t arglist[3]; // array of size max num of param Int_t ierflg = 0; arglist[0] = 1; // default for a chisquare gMin->mnexcm("SET ERR",arglist,1,ierflg); // starting values and step sizes for parameters Double_t start=0.0; // this is radian !! Double_t ste=0.00000001; Double_t vstart[3] = {start,start,start}; Double_t step[3] = {ste,ste,ste}; // MNPARM(param num, "param name", start val, step size, low bound, high bound, // err flag). If low bound=high bound=0 then the param is considered unbounded gMin->mnparm(0,"alpha",vstart[0],step[0],0,0,ierflg); gMin->mnparm(1,"beta",vstart[1],step[1],0,0,ierflg); gMin->mnparm(2,"gamma",vstart[2],step[2],0,0,ierflg); // launch Migrad : Migrad [maxcalls] [tolerance] arglist[0] = 500; // *approximated* max number of calls, even if did not converge arglist[1] = 1.; // minimization stop when EDM < 0.001*tolerance*UP; default tolerance 0.1 gMin->mnexcm("MIGRAD",arglist,2,ierflg); // results // MNSTAT(fmin: best function found,edm,errdef: UP,npari: num of var params, // nparx,istat: has to be 3!) Double_t fmin,edm,errdef; Int_t nvpari,nparx,istat; gMin->mnstat(fmin,edm,errdef,nvpari,nparx,istat); gMin->mnprin(3,fmin); Double_t param[3]; TString name; Double_t val; Double_t error; Double_t bnd1; Double_t bnd2; Int_t ivarbl; for (Int_t t=0;t<3;t++){ gMin->mnpout(t,name,val,error,bnd1,bnd2,ivarbl); param[t]=val; } // Final Misalignment Matrix Obtained by Minimization TMatrixD M=TMatrixD(3,3); Double_t alpha=param[0]; // still radians, thus no need *180.0/pi below Double_t beta=param[1]; Double_t gamma=param[2]; // line 0 M(0,0)=cos(beta)*cos(gamma); M(0,1)=cos(gamma)*sin(alpha)*sin(beta)-cos(alpha)*sin(gamma); M(0,2)=cos(alpha)*cos(gamma)*sin(beta)+sin(alpha)*sin(gamma); // line 1 M(1,0)=cos(beta)*sin(gamma); M(1,1)=cos(alpha)*cos(gamma)+sin(alpha)*sin(beta)*sin(gamma); M(1,2)=(-cos(gamma))*sin(alpha)+cos(alpha)*sin(beta)*sin(gamma); // line 2 M(2,0)=(-sin(beta)); M(2,1)=cos(beta)*sin(alpha); M(2,2)=cos(alpha)*cos(beta); cout << "\n Matrix M: " << endl; M.Print(""); cout << "since diagonal elements are rounded off, here are the details...\n" << endl; for (Int_t j=0;j<3;j++){ for (Int_t p=0;p<3;p++){ printf("%1.12lf ",M(j,p)); } printf(" \n"); } // Testing: det=1 Double_t det; det=M.Determinant(); printf("\n testing orthogonality: det M = %1.12lf",det); // Testing: orthogonality M^T M=1 cout << "\n testing orthogonality: M^T M = " << endl; TMatrixD MT(TMatrixD::kTransposed,M); TMatrixD result=TMatrixD(3,3); result.Mult(MT,M); result.Print(""); // ---------- Fill the fits file --------------------------------------------// dal_element *fitsfile=NULL; DALobjectOpen("inst_misalign_20030701.fits[1]",&fitsfile,0); double buffer[9]; int l=0; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { buffer[l]=M(i,j); l++; } } long nrow=5; // jemx2 DALtablePutColBins(fitsfile,"MATRIX",0,DAL_DOUBLE,nrow,nrow,9,buffer,0); DALobjectClose(fitsfile,DAL_SAVE,0); //---------- Testing on mes data --------------------------------------------// cout << "\n we now apply (S^TMS)^T on mes[..] to deduce the corrected \n" << endl; cout << "\n vectors cor, to be compared with cat \n" << endl; Double_t cor[3*numlines]; TMatrixD S_n(3,3); Double_t corx,cory,corz; for (Int_t i=0;i0) && (cor[3*j+1]>0)){ cout<< "quadrant I"<0)){ cout<< "quadrant II"<0) && (cor[3*j+1]<0)){ cout<< "quadrant IV"<SetGrid(); c1->SetFillColor(kWhite); // multi graph TMultiGraph *m1= new TMultiGraph(); if (delta==0){cata->SetMarkerStyle(2); cata->SetMarkerColor(kGreen); m1->Add(cata);} mesu->SetMarkerStyle(5); mesu->SetMarkerColor(kBlack); m1->Add(mesu); corr->SetMarkerStyle(30); corr->SetMarkerColor(kRed); m1->Add(corr); if (delta==0){dal->SetMarkerStyle(5); dal->SetMarkerColor(kBlue); m1->Add(dal);} m1->Draw("AP"); m1->GetXaxis()->SetLabelFont(50); m1->GetXaxis()->SetLabelSize(0.03); m1->GetYaxis()->SetLabelFont(50); m1->GetYaxis()->SetLabelSize(0.03); //m1->GetXaxis()->SetTitle("RA [deg]"); //m1->GetYaxis()->SetTitle("DEC [deg]"); m1->GetXaxis()->SetTitle("delta RA [deg]"); m1->GetYaxis()->SetTitle("delta DEC [deg]"); m1->GetXaxis()->CenterTitle(); m1->GetYaxis()->SetTitleOffset(1.5); m1->Draw("AP"); // label TPaveLabel *label = new TPaveLabel(0,0.09,0.14,0.098,"Crab observed by JEMX-2"); label->SetFillColor(kWhite); label->SetTextSize(.38); label->SetTextColor(kBlack); label->Draw(); TText *ttt = new TText(); ttt->SetTextFont(50); ttt->SetTextColor(kBlack); ttt->SetTextSize(0.02); ttt->DrawText(299.435,35.135,"positions measured with a unity matrix"); TText *tttt = new TText(); tttt->SetTextFont(50); tttt->SetTextColor(kRed); tttt->SetTextSize(0.02); tttt->DrawText(299.505,35.205,"positions corrected with the misalignment matrix"); TText *tt = new TText(); tt->SetTextFont(50); tt->SetTextColor(kBlue); tt->SetTextSize(0.02); tt->DrawText(299.508,35.195,"result of the analysis with the updated software"); TText *tc = new TText(); tc->SetTextFont(50); tc->SetTextColor(kGreen); tc->SetTextSize(0.02); tc->DrawText(299.545,35.201,"catalog position"); TText *td = new TText(); td->SetTextFont(50); td->SetTextColor(kBlack); td->SetTextSize(0.02); td->DrawText(0.1,0.001,"P. Favre, ISDC (14 MAY 2003)"); c1->Modified(); c1->Update(); }