- Timestamp:
- Aug 13, 1999, 11:57:20 PM (26 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/piafitting.cc
r390 r392 6 6 //clic sur FIT 2sd fois -> core dump!!! 7 7 // 8 //9 8 #include <stdio.h> 10 9 #include <stdlib.h> 11 10 #include <ctype.h> 12 13 11 #include <iostream.h> 14 15 12 #include <typeinfo> 16 13 17 #include "piafitting.h"18 14 #include "strutil.h" 19 15 #include "nbtri.h" 20 16 #include "generalfit.h" 21 22 17 #include "fct1dfit.h" 23 18 #include "fct2dfit.h" 24 25 19 #include "matrix.h" 26 20 #include "cvector.h" 27 21 #include "ntuple.h" 28 22 #include "cimage.h" 29 30 23 #include "histos.h" 31 24 #include "histos2.h" … … 33 26 #include "hisprof.h" 34 27 28 #include "piafitting.h" 35 29 #include "nobjmgr.h" 36 30 #include "pistdimgapp.h" … … 179 173 , mFit(NULL) 180 174 , mV(NULL), mH(NULL), mM(NULL), mH2(NULL), mIm(NULL), mG(NULL) 181 , mFunction(NULL), mFName(""), mFunc(NULL) , mFitUserFunc(false)175 , mFunction(NULL), mFName(""), mFunc(NULL) 182 176 , mDlUFunc(NULL), mNameFitFunc(""), mFitFunc(NULL), mFitFuncDer(NULL) 183 177 , mUFNVar(0), mUFNPar(0) … … 507 501 return;} 508 502 if(mFunction!=NULL) {delete mFunction; mFunction=NULL;} 509 if(mFunc!=NULL) {delete mFunc; mFunc=NULL;} 510 mNPar=0; 511 mFitUserFunc = false; 503 if(mFunc !=NULL) {delete mFunc; mFunc=NULL;} 504 mNPar=0; mFName = ""; 512 505 513 506 if(func == mNameFitFunc) { // Fonction utilisateur 514 507 mFunc = new GeneralFunc(mUFNVar,mUFNPar,mFitFunc,mFitFuncDer); 515 508 mNPar = mUFNPar; 516 mFitUserFunc = true;517 509 cout<<"Fonction utilisateur nvar="<<mUFNVar<<", npar="<<mNPar<<endl; 518 510 } else if(func[0]=='p' && mNVar==1) { //polynome … … 556 548 cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl; 557 549 if(integ) {GauRhInt2D* myf = new GauRhInt2D; mFunction = myf;} 558 else {GauRho2D* myf = new GauRho2D;mFunction = myf;}550 else {GauRho2D* myf = new GauRho2D; mFunction = myf;} 559 551 mNPar = mFunction->NPar(); mFName = func; 560 552 … … 563 555 cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl; 564 556 if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; mFunction = myf;} 565 else {GdlRho2D* myf = new GdlRho2D; mFunction = myf;}557 else {GdlRho2D* myf = new GdlRho2D; mFunction = myf;} 566 558 mNPar = mFunction->NPar(); mFName = func; 567 559 … … 570 562 cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl; 571 563 if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; mFunction = myf;} 572 else {Gdl1Rho2D* myf = new Gdl1Rho2D; mFunction = myf;}564 else {Gdl1Rho2D* myf = new Gdl1Rho2D; mFunction = myf;} 573 565 mNPar = mFunction->NPar(); mFName = func; 574 566 … … 577 569 cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl; 578 570 if(integ) {MofRhInt2D* myf = new MofRhInt2D; mFunction = myf;} 579 else {MofRho2D* myf = new MofRho2D; mFunction = myf;}571 else {MofRho2D* myf = new MofRho2D; mFunction = myf;} 580 572 mNPar = mFunction->NPar(); mFName = func; 581 573 … … 606 598 // Initialisation automatique des parametres du fit 607 599 { 608 cout<<"CMV: to be done : PIAFitter::AutoIniFit"<<endl; 609 if(mFitUserFunc) { // Fonction utilisateur 600 if(mFunc) { // Fonction utilisateur 610 601 cout<<"PIAFitter::AutoIniFit : Fonction utilisateur, pas d'init auto"<<endl; 611 612 602 } else if(mFName[0]=='p' && mNVar==1) { //poly 1D 613 603 cout<<"PIAFitter::AutoIniFit : Auto Init type polynome 1D"<<endl; 614 615 } else if(mFName[0]=='e' && mNVar==1) { //expo+pol 1D 616 cout<<"PIAFitter::AutoIniFit : Auto Init type expo+pol 1D"<<endl; 604 IniFitP1ou2D(); 617 605 618 606 } else if(mFName[0]=='g' && mNVar==1) { //gauss en haut 1D 619 607 cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_haut+pol 1D"<<endl; 608 IniFitGhP1D(); 620 609 621 610 } else if(mFName[0]=='G' && mNVar==1) { //gauss en vol 1D 622 611 cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_vol+pol 1D"<<endl; 612 IniFitGvP1D(); 623 613 624 614 } else if(mFName[0]=='p' && mNVar==2) { //poly 2D 625 615 cout<<"PIAFitter::AutoIniFit : Auto Init type polynome 2D"<<endl; 616 IniFitP1ou2D(); 626 617 627 618 } else if((mFName[0]=='G'||mFName[0]=='d') && mNVar==2) { //gauss+fond en vol 628 619 cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_vol+fond 2D"<<endl; 620 IniFitGv2D(); 629 621 630 622 } else if(mFName[0]=='D' && mNVar==2) { //DLgauss+fond en vol 2D 631 623 cout<<"PIAFitter::AutoIniFit : Auto Init type DLgauss_vol+fond 2D"<<endl; 624 IniFitGv2D(); 632 625 Vector dum(mNPar); 633 626 dum = mPar; mPar(6)=0.5; mPar(7)=dum(6); … … 639 632 } else if(mFName[0]=='M' && mNVar==2) { //Moffat+fond en vol 2D 640 633 cout<<"PIAFitter::AutoIniFit : Auto Init type moffat_vol+fond 2D"<<endl; 634 IniFitGv2D(); 641 635 Vector dum(mNPar); 642 636 dum = mPar; mPar(6)=2.5; mPar(7)=dum(6); … … 715 709 // classe GeneraFit 716 710 if(mFit != NULL) {delete mFit; mFit= NULL;} 717 if(mFunction) mFit= new GeneralFit(mFunction); 718 else mFit= new GeneralFit(mFunc); 711 if(mFunction) mFit = new GeneralFit(mFunction); 712 else if(mFunc) mFit = new GeneralFit(mFunc); 713 if(!mFit) return(-1002); 714 719 715 // Options et Set de GeneralFit 720 716 mFit->SetDebug(mOpt.lpg); … … 767 763 if(mOpt.okfun) {Matrix* ob = mM->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);} 768 764 } else if(mH2) { 769 if(mOpt.okres) {Histo2D* ob = mH2->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);} 770 if(mOpt.okfun) {Histo2D* ob = mH2->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);} 765 if(mOpt.okres) 766 {Histo2D* ob = mH2->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);} 767 if(mOpt.okfun) 768 {Histo2D* ob = mH2->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);} 771 769 } else if(mIm) { 772 770 if(mOpt.okres) { … … 779 777 } 780 778 } else if(mG) { 781 if(mOpt.okres) {GeneralFitData* ob = mG->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);} 782 if(mOpt.okfun) {GeneralFitData* ob = mG->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);} 779 if(mOpt.okres) 780 {GeneralFitData* ob = mG->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);} 781 if(mOpt.okfun) 782 {GeneralFitData* ob = mG->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);} 783 783 } 784 784 } … … 923 923 return(-1); 924 924 } 925 925 926 // decodage des arguments de la commande 926 927 string mSp,mSs,mSm,mSM,mSf,mSo; … … 938 939 else if(c[0]=='o') {mSo += ","; mSo += c+2;} 939 940 } 941 940 942 // Execution des commandes 941 943 DecodeOptions(mSo); … … 960 962 } 961 963 964 /* --Methode-- */ 965 void PIAFitter::IniFitP1ou2D(void) 966 { 967 if(mNPar==0) return; 968 mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.; 969 if(!mGData) return; 970 double mean,sigma; 971 int rc = mGData->GetMeanSigma(0,mean,sigma); 972 if(rc<=0) return; 973 mPar(0) = mean; 974 return; 975 } 976 977 void PIAFitter::IniFitGhP1D(void) 978 { 979 if(mNPar==0) return; 980 mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.; 981 if(mNVar!=1 || mNPar<3) return; 982 double h,v,x0,y0,sx,sy,f; 983 int rc = IniFitGaus(*mGData,h,v,x0,y0,sx,sy,f); 984 if(rc!=0) return; 985 mPar(0)=h; mStep(0)=h/1000.; 986 mPar(1)=x0; mStep(1)=sx/10.; 987 mPar(2)=sx; mStep(2)=sx/10.; mMin(2)=0.; mMax(2)=20.*sx; 988 if(mNPar>3) {mPar(3)=f; mStep(3)=f/1000.;} else mPar(0)=h+f; 989 } 990 991 void PIAFitter::IniFitGvP1D(void) 992 { 993 if(mNPar==0) return; 994 mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.; 995 if(mNVar!=1 || mNPar<3) return; 996 double h,v,x0,y0,sx,sy,f; 997 int rc = IniFitGaus(*mGData,h,v,x0,y0,sx,sy,f); 998 if(rc!=0) return; 999 mPar(0)=v; mStep(0)=v/1000.; 1000 mPar(1)=x0; mStep(1)=sx/10.; 1001 mPar(2)=sx; mStep(2)=sx/10.; mMin(2)=0.; mMax(2)=20.*sx; 1002 if(mNPar>3) {mPar(3)=f; mStep(3)=f/1000.;} else mPar(0)=v+mNData*f; 1003 } 1004 1005 void PIAFitter::IniFitGv2D(void) 1006 { 1007 if(mNPar==0) return; 1008 mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.; 1009 if(mNVar!=2 || mNPar<6) return; 1010 double h,v,x0,y0,sx,sy,f; 1011 int rc = IniFitGaus(*mGData,h,v,x0,y0,sx,sy,f); 1012 if(rc!=0) return; 1013 mPar(0)=v; mStep(0)=v/1000.; 1014 mPar(1)=x0; mStep(1)=sx/10.; 1015 mPar(2)=y0; mStep(2)=sy/10.; 1016 mPar(3)=sx; mStep(3)=sx/10.; mMin(3)=0.; mMax(3)=20.*sx; 1017 mPar(4)=sy; mStep(4)=sy/10.; mMin(4)=0.; mMax(4)=20.*sy; 1018 mPar(5)=0.; mStep(5)=0.005; mMin(5)=-1.; mMax(5)=1.; 1019 if(mNPar>6) {mPar(6)=f; mStep(6)=f/1000.;} else mPar(0)=v+mNData*f; 1020 } 1021 1022 int PIAFitter::IniFitGaus(GeneralFitData& g,double& h,double& v 1023 ,double& x0,double& y0,double& sx,double& sy,double& f) 1024 // Pour initialiser une gaussienne 1D ou 2D 1025 // return code =0 si OK 1026 { 1027 h=v=x0=y0=sx=sy=f=0.; 1028 if(!&g) return(-1); 1029 int nvar = g.NVar(); 1030 int ndata = g.NData(); 1031 if(nvar<1 || 2<nvar || ndata<=0) return(-2); 1032 1033 // X et Y ordonnees croissant 1034 double *X=NULL, *Y=NULL; 1035 X = new double[ndata]; 1036 if(nvar==2) Y = new double[ndata]; 1037 {for(int i=0;i<ndata;i++) {X[i] = g.X(i); if(Y) Y[i] = g.Y(i);}} 1038 qsort(X,(size_t) ndata,sizeof(double),qSort_Dble); 1039 if(Y) qsort(Y,(size_t) ndata,sizeof(double),qSort_Dble); 1040 1041 // determination des zones externes=[0,1/3] et [2/3,1] 1042 // et des zones internes=[1/3,2/3] 1043 int k1=ndata/3,k2=2*ndata/3; 1044 double xmin,xmax, ymin=-1.,ymax=1.; 1045 xmin = X[k1]; xmax = X[k2]; 1046 if(Y) {ymin = Y[k1]; ymax = Y[k2];} 1047 1048 // recherche des parametres 1049 double nb=0, nc=0; 1050 {for(int i=0;i<ndata;i++) { 1051 double val,x,y=0.; 1052 x = g.X(i); if(Y) y = g.Y(i); val = g.Val(i); 1053 if(xmin<x && x<xmax && ymin<y && y<ymax) { // c'est le centre 1054 if(nc==0 || val>h) {h=val; x0=x; y0=y;} 1055 v += val; nc++; 1056 } else {f += val; nb++;} // c'est le bord 1057 1058 }} 1059 if(nb==0 || nc==0) {delete [] X; if(Y) delete [] Y; return(-3);} 1060 1061 // Calcul des parametres 1062 f /= (double) nb; h -= f; v -= f*nc; 1063 sx = (xmax-xmin)/2.; if(Y) sy = (ymax-ymin)/2.; 1064 1065 delete [] X; if(Y) delete [] Y; 1066 return(0); 1067 } 1068 1069 962 1070 //////////////////////////////////////////////////////////////////// 963 1071 ////---------- Classe de fenetre de fit interactive ------------//// … … 995 1103 cpx = spx; cpy = spy; 996 1104 string dum = "Object: "+mFitter->mNObj+" , Fun: "; 997 if(mFitter->mF itUserFunc) dum+=mFitter->mNameFitFunc; else dum+=mFitter->mFName;1105 if(mFitter->mFunc) dum+=mFitter->mNameFitFunc; else dum+=mFitter->mFName; 998 1106 lab[0] = new PILabel(this,dum.c_str(),4*bsx,bsy,cpx,cpy); 999 1107 lab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); … … 1351 1459 } 1352 1460 else if(2011<=msg && msg<=2013) { 1353 mFitter->mOpt.polc x= msg-2011;1461 mFitter->mOpt.polcy = msg-2011; 1354 1462 if(lp) cout<<"Centrage Y polcy="<<mFitter->mOpt.polcy 1355 1463 <<" yc="<<mFitter->mOpt.yc<<endl; -
trunk/SophyaPI/PIext/piafitting.h
r390 r392 69 69 void LinFit(void); 70 70 71 // pour initialiser les parametres du fit 72 void IniFitP1ou2D(void); 73 void IniFitGhP1D(void); 74 void IniFitGvP1D(void); 75 void IniFitGv2D(void); 76 static int IniFitGaus(GeneralFitData& g,double& h,double& v 77 ,double& x0,double& y0,double& sx,double& sy,double& f); 78 71 79 // Graphique 72 80 PIStdImgApp* mApp; // Do not delete … … 89 97 GeneralFunction* mFunction; string mFName; 90 98 // Gestion de fonction de fit definie par l'utilisateur 91 bool mFitUserFunc;92 99 GeneralFunc* mFunc; 93 100 PDynLinkMgr* mDlUFunc;
Note:
See TracChangeset
for help on using the changeset viewer.