[381] | 1 | //CMVBUG reste pb suivant sous Linux-egcs (OSF1-cxx c'est ok):
|
---|
[379] | 2 | //openppf cmvwppf.ppf
|
---|
| 3 | //fitw h1g g2 p:4500,45,10,900
|
---|
| 4 | //delobjs h1g
|
---|
| 5 | //clic sur FIT -> OK
|
---|
| 6 | //clic sur FIT 2sd fois -> core dump!!!
|
---|
| 7 | //
|
---|
[361] | 8 | #include <stdio.h>
|
---|
| 9 | #include <stdlib.h>
|
---|
| 10 | #include <ctype.h>
|
---|
| 11 | #include <iostream.h>
|
---|
| 12 | #include <typeinfo>
|
---|
| 13 |
|
---|
| 14 | #include "strutil.h"
|
---|
[392] | 15 | #include "nbtri.h"
|
---|
[361] | 16 | #include "generalfit.h"
|
---|
| 17 | #include "fct1dfit.h"
|
---|
| 18 | #include "fct2dfit.h"
|
---|
| 19 | #include "ntuple.h"
|
---|
| 20 | #include "cimage.h"
|
---|
| 21 | #include "histos.h"
|
---|
| 22 | #include "histos2.h"
|
---|
| 23 | #include "ntuple.h"
|
---|
| 24 | #include "hisprof.h"
|
---|
| 25 |
|
---|
[544] | 26 | #ifdef SANS_EVOLPLANCK
|
---|
| 27 | #include "matrix.h"
|
---|
| 28 | #include "cvector.h"
|
---|
| 29 | #else
|
---|
| 30 | #include "tmatrix.h"
|
---|
| 31 | #include "tvector.h"
|
---|
[769] | 32 | #include "objfitter.h"
|
---|
[544] | 33 | #endif
|
---|
| 34 |
|
---|
[392] | 35 | #include "piafitting.h"
|
---|
[361] | 36 | #include "nobjmgr.h"
|
---|
| 37 | #include "pistdimgapp.h"
|
---|
| 38 |
|
---|
[379] | 39 | ////////////////////////////////////////////////////////////////////
|
---|
| 40 | ////---------- Classe de fenetre de fit interactive ------------////
|
---|
| 41 | ////////////////////////////////////////////////////////////////////
|
---|
[361] | 42 | class PIAFitterWind : public PIWindow {
|
---|
| 43 | public :
|
---|
| 44 | PIAFitterWind(PIStdImgApp* par, PIAFitter* fiter);
|
---|
| 45 | virtual ~PIAFitterWind();
|
---|
| 46 | virtual void Show();
|
---|
| 47 | virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
|
---|
[379] | 48 | void SetState(void);
|
---|
[361] | 49 | protected :
|
---|
[379] | 50 | PIStdImgApp* mDap;
|
---|
| 51 | PIAFitter* mFitter;
|
---|
| 52 | PILabel** lab; int nlab;
|
---|
| 53 | PIText** txt; int ntxt;
|
---|
| 54 | PIButton** but; int nbut;
|
---|
| 55 | PICheckBox** ckb; int nckb;
|
---|
[381] | 56 | PIOptMenu** pom; int npom;
|
---|
[379] | 57 | bool ReFillGData;
|
---|
[381] | 58 | int saveI1,saveI2, saveJ1, saveJ2;
|
---|
[385] | 59 | double ErrValue;
|
---|
[361] | 60 | };
|
---|
| 61 |
|
---|
[379] | 62 | ////////////////////////////////////////////////////////////////////////
|
---|
[466] | 63 | // --- Generation automatique du "usage" pour helpfit:
|
---|
| 64 | // 1-/ copier le texte ci-dessous de piafitting.cc dans toto
|
---|
| 65 | // 2-/ cat toto | sed 's?^//?usage+="\\n?' | sed 's?$? ";?'
|
---|
| 66 | // NE PAS EFFACER LA SUITE: c'est elle qui doit etre modifiee,
|
---|
| 67 | // le usage du helpfit sera regenere a l'aide des commandes ci-dessus.
|
---|
| 68 | ////////////////////////////////////////////////////////////////////////
|
---|
[379] | 69 | //| --------------- Fit Lineaire a 1 et 2 dimensions ---------------
|
---|
| 70 | //| Syntaxe:
|
---|
| 71 | //| fitlin nom pnn [o:.aa,bb,cc, o;dd,ee,ff o:gg,hh,jj,kk etc...]
|
---|
| 72 | //| avec:
|
---|
[466] | 73 | //| nom : cf commentaire ordre ''fit''
|
---|
[379] | 74 | //| pnn : fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D
|
---|
[466] | 75 | //| o:aa,...,bb : cf commentaires ordre ''fit''
|
---|
[379] | 76 | //|
|
---|
| 77 | ////////////////////////////////////////////////////////////////////////
|
---|
[361] | 78 | //| --------------- Fit d'objets a 1 et 2 dimensions ---------------
|
---|
[379] | 79 | //| avec interface d'aide graphique
|
---|
| 80 | //| Syntaxe:
|
---|
| 81 | //| fitw nom func
|
---|
| 82 | //| [p:p1,p2,...,pn s:s1,s2,...,sn m:m1,m2,...,mn M:M1,mM2,...,Mn f:f1,...,fn]
|
---|
| 83 | //| [o:.aa,bb,cc, o;dd,ee,ff o:gg,hh,jj,kk etc...]
|
---|
[466] | 84 | //| cf commentaire ordre ''fit''
|
---|
[379] | 85 | //|
|
---|
| 86 | ////////////////////////////////////////////////////////////////////////
|
---|
| 87 | //| --------------- Fit d'objets a 1 et 2 dimensions ---------------
|
---|
| 88 | //| Syntaxe:
|
---|
| 89 | //| fit nom func
|
---|
| 90 | //| [p:p1,p2,...,pn s:s1,s2,...,sn m:m1,m2,...,mn M:M1,mM2,...,Mn f:f1,...,fn]
|
---|
| 91 | //| [o:.aa,bb,cc, o;dd,ee,ff o:gg,hh,jj,kk etc...]
|
---|
| 92 | //|----- OBJET -----
|
---|
[361] | 93 | //| nom : nom de l'objet qui peut etre:
|
---|
| 94 | //| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D)
|
---|
| 95 | //| fit-2D: Matrix,Histo2D,Image<T> ou GeneraFitData(2D)
|
---|
[379] | 96 | //|
|
---|
| 97 | //|----- FUNCTION -----
|
---|
| 98 | //| func : pnn : fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D
|
---|
[361] | 99 | //| : gnn : fit gaussienne (hauteur) + polynome de degre nn 1D
|
---|
| 100 | //| : g : fit gaussienne (hauteur) 1D
|
---|
| 101 | //| : enn : fit exponentielle + polynome de degre nn 1D
|
---|
| 102 | //| : e : fit exponentielle 1D
|
---|
| 103 | //| : Gnn : fit gaussienne (volume) + polynome de degre nn 1D
|
---|
| 104 | //| : G : fit gaussienne (volume) 1D
|
---|
| 105 | //| : : fit gaussienne+fond (volume) 2D
|
---|
| 106 | //| : Gi : fit gaussienne+fond integree (volume) 2D
|
---|
| 107 | //| : d : fit DL de gaussienne+fond (volume) 2D
|
---|
| 108 | //| : di : fit DL de gaussienne+fond integree (volume) 2D
|
---|
| 109 | //| : D : fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D
|
---|
| 110 | //| : Di : fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D
|
---|
| 111 | //| : M : fit Moffat+fond (expos=p6) (volume) 2D
|
---|
| 112 | //| : Mi : fit Moffat+fond integree (expos=p6) (volume) 2D
|
---|
[385] | 113 | //| : Autre : fonction definie par l'utilisateur (cf commentaires ci apres)
|
---|
[379] | 114 | //|
|
---|
| 115 | //|----- INIT PARAMETRES ET ETAT DU FIT -----
|
---|
| 116 | //| p : p1,...,pn : valeur d'initialisation des parametres (def=0)
|
---|
| 117 | //| s : s1,...,sn : valeur des steps de depart (def=1)
|
---|
| 118 | //| m : m1,...,mn : valeur des minima (def=1)
|
---|
| 119 | //| M : M1,...,Mn : valeur des maxima (def=-1) (max<=min : pas de limite)
|
---|
| 120 | //| f : f1,...,fn : si >=1 parametre fixe sinon libre (def=0)
|
---|
| 121 | //| - Remarque: si pi,si,mi ou Mi = '!' la valeur correspondante n'est pas changee
|
---|
| 122 | //|
|
---|
| 123 | //|----- OPTIONS -----
|
---|
[466] | 124 | //| o : options ''o:Eaa.b,eaa.b,f,r,caa.b,Xaa.b''
|
---|
[379] | 125 | //| F : initialisation a partir des resultats et de l'etat du fit precedent
|
---|
| 126 | //| (option non prioritaire sur les definitions p:,s:,m:,M:,f:o:)
|
---|
[390] | 127 | //| a : initialisation automatique des parametres du fit (si disponible)
|
---|
| 128 | //| (option non prioritaire sur les definitions p:,s:,m:,M:,f:o:
|
---|
[466] | 129 | //| et sur l'initialisation pa l'option ''F'')
|
---|
[361] | 130 | //| f : generation d'un Objet identique contenant la fonction fittee
|
---|
| 131 | //| r : generation d'un Objet identique contenant les residus
|
---|
| 132 | //| Xaa.b : aa.b valeur du DXi2 d'arret (def=1.e-3)
|
---|
| 133 | //| Naa : aa nombre maximum d'iterations (def=100)
|
---|
[466] | 134 | //| la : niveau ''a'' de print: a=niveau de print Fit1/2D
|
---|
| 135 | //| da : niveau ''a'' de debug: a=niveau de GeneralFit
|
---|
[379] | 136 | //| Ii1/i2 : numeros des bins X de l'histos utilises pour le fit [i1,i2]
|
---|
| 137 | //|2D Jj1/j2 : numeros des bins Y de l'histos utilises pour le fit [j1,j2]
|
---|
| 138 | //| - L'erreur est celle associee a l'objet (si elle existe),
|
---|
| 139 | //| elle est mise a 1 sinon, sauf si E... ou e... est precise:
|
---|
[361] | 140 | //| Eaa.b : si |val|>=1 erreur = aa.b*sqrt(|val|)
|
---|
| 141 | //| si |val|<1 erreur = aa.b
|
---|
| 142 | //| si aa.b <=0 alors aa.b=1.0
|
---|
| 143 | //| E seul est equivalent a E1.0
|
---|
| 144 | //| eaa.b : erreur = aa.b
|
---|
| 145 | //| si aa.b <=0 alors aa.b=1.0
|
---|
| 146 | //| e seul est equivalent a e1.0
|
---|
| 147 | //| xaa.b : demande de centrage: on fit x-aa.b au lieu de x)
|
---|
| 148 | //| x : demande de centrage: on fit x-xc au lieu de x
|
---|
| 149 | //| avec xc=abscisse du milieu de l'histogramme
|
---|
[379] | 150 | //| Actif pour exp+poly 1D, poly 1D
|
---|
| 151 | //| Pour gauss+poly 1D, xc est le centre de la gaussienne.
|
---|
[466] | 152 | //|2D yaa.b et y : idem ''xaa.b et x'' mais pour y
|
---|
[385] | 153 | //|
|
---|
[379] | 154 | ////////////////////////////////////////////////////////////////////////
|
---|
[385] | 155 | //| --------------- Def des fcts de fit par l'utilisateur ---------------
|
---|
| 156 | //| Pour definir une fonction parametree utilisateur:
|
---|
| 157 | //| Un exemple de fichier contenant des fonctions a fitter: PIext/userfitfunex.c
|
---|
| 158 | //| > crfitfil nom_fichier nom_fonction nvar npar
|
---|
| 159 | //| pour creer un squelette de fichier C contenant la fonction a fitter
|
---|
| 160 | //| nom_fichier : nom du fichier ou est le code de la fonction
|
---|
| 161 | //| c'est un fichier C de nom blabla.c
|
---|
| 162 | //| nom_fonction : nom de la fonction ex: gauss2
|
---|
| 163 | //| nvar : nombre de variables x[] (1D=1, 2D=2, etc...)
|
---|
| 164 | //| npar : nombre de parametre p[]
|
---|
| 165 | //| - La fonction est donc F(x[];p[]), soit par ex:
|
---|
| 166 | //| double gauss2(double const* x,double const* p)
|
---|
| 167 | //| - L'utilisateur a la possibilite de donner egalement la fonction
|
---|
| 168 | //| retournant les derivees de la fonction par rapport aux parametres
|
---|
| 169 | //| double gauss2_der(double const* x,double const* p,double* dp)
|
---|
| 170 | //| ou dp[i] = dF(x[];p[])/dp[i]
|
---|
[466] | 171 | //| Par convention, cette fonction a le meme nom suivi de ''_der''
|
---|
[385] | 172 | //| > crfitfun nom_fichier nom_fonction nvar npar
|
---|
[466] | 173 | //| Permet de compiler le fichier ''nom_fichier'' et de linker
|
---|
| 174 | //| la fonction ''nom_fonction''
|
---|
[385] | 175 | //| - Un meme fichier peut contenir plusieurs fonctions a fitter
|
---|
| 176 | //|
|
---|
| 177 | ////////////////////////////////////////////////////////////////////////
|
---|
[379] | 178 |
|
---|
| 179 | /* --Methode-- */
|
---|
| 180 | PIAFitter::PIAFitter(PIACmd *piac, PIStdImgApp* app)
|
---|
| 181 | : mApp(app), FWindFit(NULL)
|
---|
[385] | 182 | , mNObj(""), mObj(NULL), mGData(NULL)
|
---|
[379] | 183 | , mNPar(0), mNVar(0), mNBinX(0), mNBinY(0), mNData(0)
|
---|
| 184 | , mPar(1), mStep(1), mMin(1), mMax(1), mFix(1)
|
---|
| 185 | , mParSave(1), mStepSave(1), mMinSave(1), mMaxSave(1), mFixSave(1)
|
---|
| 186 | , mFit(NULL)
|
---|
| 187 | , mV(NULL), mH(NULL), mM(NULL), mH2(NULL), mIm(NULL), mG(NULL)
|
---|
[392] | 188 | , mFunction(NULL), mFName(""), mFunc(NULL)
|
---|
[384] | 189 | , mDlUFunc(NULL), mNameFitFunc(""), mFitFunc(NULL), mFitFuncDer(NULL)
|
---|
| 190 | , mUFNVar(0), mUFNPar(0)
|
---|
[361] | 191 | {
|
---|
[379] | 192 | // Init et Set des options
|
---|
| 193 | mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.;
|
---|
| 194 | mParSave=0.; mStepSave=1.; mMinSave=1.; mMaxSave=-1.; mFixSave=0.;
|
---|
| 195 | ResetOptions();
|
---|
| 196 | mOptSave = mOpt;
|
---|
[361] | 197 |
|
---|
[379] | 198 | // enregistrement des ordres de fit
|
---|
[466] | 199 | string kw, usage, grp = "Fitting";
|
---|
[379] | 200 |
|
---|
[466] | 201 | kw = "helpfit";
|
---|
| 202 | usage="";
|
---|
| 203 | usage+="\n////////////////////////////////////////////////////////////////////// ";
|
---|
| 204 | usage+="\n| --------------- Fit Lineaire a 1 et 2 dimensions --------------- ";
|
---|
| 205 | usage+="\n| Syntaxe: ";
|
---|
| 206 | usage+="\n| fitlin nom pnn [o:.aa,bb,cc, o;dd,ee,ff o:gg,hh,jj,kk etc...] ";
|
---|
| 207 | usage+="\n| avec: ";
|
---|
| 208 | usage+="\n| nom : cf commentaire ordre ''fit'' ";
|
---|
| 209 | usage+="\n| pnn : fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D ";
|
---|
| 210 | usage+="\n| o:aa,...,bb : cf commentaires ordre ''fit'' ";
|
---|
| 211 | usage+="\n| ";
|
---|
| 212 | usage+="\n////////////////////////////////////////////////////////////////////// ";
|
---|
| 213 | usage+="\n| --------------- Fit d'objets a 1 et 2 dimensions --------------- ";
|
---|
| 214 | usage+="\n| avec interface d'aide graphique ";
|
---|
| 215 | usage+="\n| Syntaxe: ";
|
---|
| 216 | usage+="\n| fitw nom func ";
|
---|
| 217 | usage+="\n| [p:p1,p2,...,pn s:s1,s2,...,sn m:m1,m2,...,mn M:M1,mM2,...,Mn f:f1,...,fn] ";
|
---|
| 218 | usage+="\n| [o:.aa,bb,cc, o;dd,ee,ff o:gg,hh,jj,kk etc...] ";
|
---|
| 219 | usage+="\n| cf commentaire ordre ''fit'' ";
|
---|
| 220 | usage+="\n| ";
|
---|
| 221 | usage+="\n////////////////////////////////////////////////////////////////////// ";
|
---|
| 222 | usage+="\n| --------------- Fit d'objets a 1 et 2 dimensions --------------- ";
|
---|
| 223 | usage+="\n| Syntaxe: ";
|
---|
| 224 | usage+="\n| fit nom func ";
|
---|
| 225 | usage+="\n| [p:p1,p2,...,pn s:s1,s2,...,sn m:m1,m2,...,mn M:M1,mM2,...,Mn f:f1,...,fn] ";
|
---|
| 226 | usage+="\n| [o:.aa,bb,cc, o;dd,ee,ff o:gg,hh,jj,kk etc...] ";
|
---|
| 227 | usage+="\n|----- OBJET ----- ";
|
---|
| 228 | usage+="\n| nom : nom de l'objet qui peut etre: ";
|
---|
| 229 | usage+="\n| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D) ";
|
---|
| 230 | usage+="\n| fit-2D: Matrix,Histo2D,Image<T> ou GeneraFitData(2D) ";
|
---|
| 231 | usage+="\n| ";
|
---|
| 232 | usage+="\n|----- FUNCTION ----- ";
|
---|
| 233 | usage+="\n| func : pnn : fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D ";
|
---|
| 234 | usage+="\n| : gnn : fit gaussienne (hauteur) + polynome de degre nn 1D ";
|
---|
| 235 | usage+="\n| : g : fit gaussienne (hauteur) 1D ";
|
---|
| 236 | usage+="\n| : enn : fit exponentielle + polynome de degre nn 1D ";
|
---|
| 237 | usage+="\n| : e : fit exponentielle 1D ";
|
---|
| 238 | usage+="\n| : Gnn : fit gaussienne (volume) + polynome de degre nn 1D ";
|
---|
| 239 | usage+="\n| : G : fit gaussienne (volume) 1D ";
|
---|
| 240 | usage+="\n| : : fit gaussienne+fond (volume) 2D ";
|
---|
| 241 | usage+="\n| : Gi : fit gaussienne+fond integree (volume) 2D ";
|
---|
| 242 | usage+="\n| : d : fit DL de gaussienne+fond (volume) 2D ";
|
---|
| 243 | usage+="\n| : di : fit DL de gaussienne+fond integree (volume) 2D ";
|
---|
| 244 | usage+="\n| : D : fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D ";
|
---|
| 245 | usage+="\n| : Di : fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D ";
|
---|
| 246 | usage+="\n| : M : fit Moffat+fond (expos=p6) (volume) 2D ";
|
---|
| 247 | usage+="\n| : Mi : fit Moffat+fond integree (expos=p6) (volume) 2D ";
|
---|
| 248 | usage+="\n| : Autre : fonction definie par l'utilisateur (cf commentaires ci apres) ";
|
---|
| 249 | usage+="\n| ";
|
---|
| 250 | usage+="\n|----- INIT PARAMETRES ET ETAT DU FIT ----- ";
|
---|
| 251 | usage+="\n| p : p1,...,pn : valeur d'initialisation des parametres (def=0) ";
|
---|
| 252 | usage+="\n| s : s1,...,sn : valeur des steps de depart (def=1) ";
|
---|
| 253 | usage+="\n| m : m1,...,mn : valeur des minima (def=1) ";
|
---|
| 254 | usage+="\n| M : M1,...,Mn : valeur des maxima (def=-1) (max<=min : pas de limite) ";
|
---|
| 255 | usage+="\n| f : f1,...,fn : si >=1 parametre fixe sinon libre (def=0) ";
|
---|
| 256 | usage+="\n| - Remarque: si pi,si,mi ou Mi = '!' la valeur correspondante n'est pas changee ";
|
---|
| 257 | usage+="\n| ";
|
---|
| 258 | usage+="\n|----- OPTIONS ----- ";
|
---|
| 259 | usage+="\n| o : options ''o:Eaa.b,eaa.b,f,r,caa.b,Xaa.b'' ";
|
---|
| 260 | usage+="\n| F : initialisation a partir des resultats et de l'etat du fit precedent ";
|
---|
| 261 | usage+="\n| (option non prioritaire sur les definitions p:,s:,m:,M:,f:o:) ";
|
---|
| 262 | usage+="\n| a : initialisation automatique des parametres du fit (si disponible) ";
|
---|
| 263 | usage+="\n| (option non prioritaire sur les definitions p:,s:,m:,M:,f:o: ";
|
---|
| 264 | usage+="\n| et sur l'initialisation pa l'option ''F'') ";
|
---|
| 265 | usage+="\n| f : generation d'un Objet identique contenant la fonction fittee ";
|
---|
| 266 | usage+="\n| r : generation d'un Objet identique contenant les residus ";
|
---|
| 267 | usage+="\n| Xaa.b : aa.b valeur du DXi2 d'arret (def=1.e-3) ";
|
---|
| 268 | usage+="\n| Naa : aa nombre maximum d'iterations (def=100) ";
|
---|
| 269 | usage+="\n| la : niveau ''a'' de print: a=niveau de print Fit1/2D ";
|
---|
| 270 | usage+="\n| da : niveau ''a'' de debug: a=niveau de GeneralFit ";
|
---|
| 271 | usage+="\n| Ii1/i2 : numeros des bins X de l'histos utilises pour le fit [i1,i2] ";
|
---|
| 272 | usage+="\n|2D Jj1/j2 : numeros des bins Y de l'histos utilises pour le fit [j1,j2] ";
|
---|
| 273 | usage+="\n| - L'erreur est celle associee a l'objet (si elle existe), ";
|
---|
| 274 | usage+="\n| elle est mise a 1 sinon, sauf si E... ou e... est precise: ";
|
---|
| 275 | usage+="\n| Eaa.b : si |val|>=1 erreur = aa.b*sqrt(|val|) ";
|
---|
| 276 | usage+="\n| si |val|<1 erreur = aa.b ";
|
---|
| 277 | usage+="\n| si aa.b <=0 alors aa.b=1.0 ";
|
---|
| 278 | usage+="\n| E seul est equivalent a E1.0 ";
|
---|
| 279 | usage+="\n| eaa.b : erreur = aa.b ";
|
---|
| 280 | usage+="\n| si aa.b <=0 alors aa.b=1.0 ";
|
---|
| 281 | usage+="\n| e seul est equivalent a e1.0 ";
|
---|
| 282 | usage+="\n| xaa.b : demande de centrage: on fit x-aa.b au lieu de x) ";
|
---|
| 283 | usage+="\n| x : demande de centrage: on fit x-xc au lieu de x ";
|
---|
| 284 | usage+="\n| avec xc=abscisse du milieu de l'histogramme ";
|
---|
| 285 | usage+="\n| Actif pour exp+poly 1D, poly 1D ";
|
---|
| 286 | usage+="\n| Pour gauss+poly 1D, xc est le centre de la gaussienne. ";
|
---|
| 287 | usage+="\n|2D yaa.b et y : idem ''xaa.b et x'' mais pour y ";
|
---|
| 288 | usage+="\n| ";
|
---|
| 289 | usage+="\n////////////////////////////////////////////////////////////////////// ";
|
---|
| 290 | usage+="\n| --------------- Def des fcts de fit par l'utilisateur --------------- ";
|
---|
| 291 | usage+="\n| Pour definir une fonction parametree utilisateur: ";
|
---|
| 292 | usage+="\n| Un exemple de fichier contenant des fonctions a fitter: PIext/userfitfunex.c ";
|
---|
| 293 | usage+="\n| > crfitfil nom_fichier nom_fonction nvar npar ";
|
---|
| 294 | usage+="\n| pour creer un squelette de fichier C contenant la fonction a fitter ";
|
---|
| 295 | usage+="\n| nom_fichier : nom du fichier ou est le code de la fonction ";
|
---|
| 296 | usage+="\n| c'est un fichier C de nom blabla.c ";
|
---|
| 297 | usage+="\n| nom_fonction : nom de la fonction ex: gauss2 ";
|
---|
| 298 | usage+="\n| nvar : nombre de variables x[] (1D=1, 2D=2, etc...) ";
|
---|
| 299 | usage+="\n| npar : nombre de parametre p[] ";
|
---|
| 300 | usage+="\n| - La fonction est donc F(x[];p[]), soit par ex: ";
|
---|
| 301 | usage+="\n| double gauss2(double const* x,double const* p) ";
|
---|
| 302 | usage+="\n| - L'utilisateur a la possibilite de donner egalement la fonction ";
|
---|
| 303 | usage+="\n| retournant les derivees de la fonction par rapport aux parametres ";
|
---|
| 304 | usage+="\n| double gauss2_der(double const* x,double const* p,double* dp) ";
|
---|
| 305 | usage+="\n| ou dp[i] = dF(x[];p[])/dp[i] ";
|
---|
| 306 | usage+="\n| Par convention, cette fonction a le meme nom suivi de ''_der'' ";
|
---|
| 307 | usage+="\n| > crfitfun nom_fichier nom_fonction nvar npar ";
|
---|
| 308 | usage+="\n| Permet de compiler le fichier ''nom_fichier'' et de linker ";
|
---|
| 309 | usage+="\n| la fonction ''nom_fonction'' ";
|
---|
| 310 | usage+="\n| - Un meme fichier peut contenir plusieurs fonctions a fitter ";
|
---|
| 311 | usage+="\n| ";
|
---|
| 312 | usage+="\n////////////////////////////////////////////////////////////////////// ";
|
---|
| 313 | piac->RegisterHelp(kw,usage,grp);
|
---|
| 314 |
|
---|
[379] | 315 | kw = "fit";
|
---|
| 316 | usage = "Fitting function to DataObjects (Histo, Histo2D, Vector, ...)";
|
---|
| 317 | usage += "\n Usage: fit nomobj func [Options]";
|
---|
| 318 | usage += "\n [p:p1,...,pn s:s1,...,sn m:m1,...,mn M:M1,...,Mn o:... o:...]";
|
---|
[466] | 319 | usage += "\n Related commands: fitw fitlin crfitfun crfitfil";
|
---|
| 320 | piac->RegisterCommand(kw,usage,this,grp);
|
---|
[379] | 321 |
|
---|
| 322 | kw = "fitw";
|
---|
| 323 | usage = "Fitting function to DataObjects with Interactive Window Help";
|
---|
| 324 | usage += "\n Usage: fitw nomobj func [Options]";
|
---|
| 325 | usage += "\n [p:p1,...,pn s:s1,...,sn m:m1,...,mn M:M1,...,Mn o:... o:...]";
|
---|
[466] | 326 | usage += "\n Related commands: fit fitlin crfitfun crfitfil";
|
---|
| 327 | piac->RegisterCommand(kw,usage,this,grp);
|
---|
[379] | 328 |
|
---|
| 329 | kw = "fitlin";
|
---|
| 330 | usage = "Linear Fitting of Polynoms to DataObjects";
|
---|
| 331 | usage += "\n Usage: fitlin nomobj func [o:... o:...]";
|
---|
[466] | 332 | usage += "\n Related commands: fit fitw crfitfun crfitfil";
|
---|
| 333 | piac->RegisterCommand(kw,usage,this,grp);
|
---|
[384] | 334 |
|
---|
| 335 | kw = "crfitfun";
|
---|
[385] | 336 | usage = "Creation et link de function utilisateur pour le fit";
|
---|
[384] | 337 | usage += "\n Usage: crfitfun file func nvar npar";
|
---|
[466] | 338 | usage += "\n Related commands: fit fitw fitlin crfitfil";
|
---|
| 339 | piac->RegisterCommand(kw,usage,this,grp);
|
---|
[385] | 340 |
|
---|
| 341 | kw = "crfitfil";
|
---|
| 342 | usage = "Creation de fichier C pour function utilisateur du fit";
|
---|
| 343 | usage += "\n Usage: crfitfil file func nvar npar";
|
---|
[466] | 344 | usage += "\n Related commands: fit fitw fitlin crfitfun";
|
---|
| 345 | piac->RegisterCommand(kw,usage,this,grp);
|
---|
[379] | 346 | }
|
---|
| 347 |
|
---|
| 348 | /* --Methode-- */
|
---|
| 349 | PIAFitter::~PIAFitter()
|
---|
| 350 | {
|
---|
[385] | 351 | if(mFit != NULL) {delete mFit; mFit=NULL;}
|
---|
| 352 | if(mFunction != NULL) {delete mFunction; mFunction=NULL;}
|
---|
| 353 | if(mFunc != NULL) {delete mFunc; mFunc=NULL;}
|
---|
| 354 | if(mGData != NULL) {delete mGData; mGData=NULL;}
|
---|
| 355 | if(FWindFit != NULL) {delete FWindFit; FWindFit=NULL;}
|
---|
| 356 | if (mDlUFunc != NULL) {delete mDlUFunc; mDlUFunc=NULL;}
|
---|
[379] | 357 | }
|
---|
| 358 |
|
---|
| 359 | /* --Methode-- */
|
---|
| 360 | void PIAFitter::ResetDPointer(void)
|
---|
| 361 | // Reset des pointeurs sur les donnees
|
---|
| 362 | {
|
---|
| 363 | mNObj = ""; mObj=NULL;
|
---|
| 364 | mV=NULL; mH=NULL; mM=NULL; mH2=NULL; mIm=NULL; mG=NULL;
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | /* --Methode-- */
|
---|
| 368 | void PIAFitter::ResetOptions(void)
|
---|
| 369 | // Reset des options
|
---|
| 370 | {
|
---|
| 371 | mOpt.okres = mOpt.okfun = false;
|
---|
| 372 | mOpt.polcx = mOpt.polcy = 0;
|
---|
| 373 | mOpt.xc = mOpt.yc = 0.;
|
---|
| 374 | mOpt.stc2 = 1.e-3;
|
---|
| 375 | mOpt.nstep = 100;
|
---|
| 376 | mOpt.err_e = mOpt.err_E = -1.;
|
---|
| 377 | mOpt.lp = 1; mOpt.lpg = 0;
|
---|
| 378 | mOpt.i1 = mOpt.j1 = mOpt.i2 = mOpt.j2 = -1;
|
---|
| 379 | mOpt.fromlastfit = false;
|
---|
[390] | 380 | mOpt.autoinifit = false;
|
---|
[379] | 381 | }
|
---|
| 382 |
|
---|
| 383 | /* --Methode-- */
|
---|
| 384 | void PIAFitter::DecodeOptions(string opt)
|
---|
| 385 | // Decodage des options a partir des chaines de caracteres
|
---|
| 386 | {
|
---|
| 387 | ResetOptions();
|
---|
| 388 | if(opt.length()<=0) return;
|
---|
| 389 |
|
---|
| 390 | size_t p,q; string dum;
|
---|
| 391 | opt = "," + opt + ",";
|
---|
| 392 |
|
---|
| 393 | if(strstr(opt.c_str(),",F,")) // init options/param a partir du fit precedent
|
---|
| 394 | {mOpt = mOptSave; mOpt.fromlastfit = true;}
|
---|
[390] | 395 | if(strstr(opt.c_str(),",a,")) mOpt.autoinifit = true; // init auto par fit
|
---|
[379] | 396 | if(strstr(opt.c_str(),",r,")) mOpt.okres = true; // residus
|
---|
| 397 | if(strstr(opt.c_str(),",f,")) mOpt.okfun = true; // fonction fittee
|
---|
| 398 | if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc)
|
---|
| 399 | mOpt.polcx = 2; // Le centrage est calcule automatiquement
|
---|
| 400 | p = opt.find(",x"); q = opt.find_first_of(',',p+1);
|
---|
| 401 | dum = opt.substr(p,q-p);
|
---|
| 402 | if(dum.length()>2) {
|
---|
| 403 | sscanf(dum.c_str(),",x%lf",&mOpt.xc);
|
---|
| 404 | mOpt.polcx = 1; // Le centrage est fixe par la valeur lue
|
---|
| 405 | }
|
---|
| 406 | }
|
---|
| 407 | if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc)
|
---|
| 408 | mOpt.polcy = 2; // Le centrage est calcule automatiquement
|
---|
| 409 | p = opt.find(",y"); q = opt.find_first_of(',',p+1);
|
---|
| 410 | dum = opt.substr(p,q-p);
|
---|
| 411 | if(dum.length()>2) {
|
---|
| 412 | sscanf(dum.c_str(),",y%lf",&mOpt.yc);
|
---|
| 413 | mOpt.polcy = 1; // Le centrage est fixe par la valeur lue
|
---|
| 414 | }
|
---|
| 415 | }
|
---|
| 416 | if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)"
|
---|
| 417 | p = opt.find(",E"); q = opt.find_first_of(',',p+1);
|
---|
| 418 | dum = opt.substr(p,q-p);
|
---|
| 419 | if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&mOpt.err_E);
|
---|
| 420 | if(mOpt.err_E<=0.) mOpt.err_E = 1.; //mOpt.err_e=-1.;
|
---|
| 421 | }
|
---|
| 422 | if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b"
|
---|
| 423 | p = opt.find(",e"); q = opt.find_first_of(',',p+1);
|
---|
| 424 | dum = opt.substr(p,q-p);
|
---|
| 425 | if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&mOpt.err_e);
|
---|
| 426 | if(mOpt.err_e<=0.) mOpt.err_e = 1.; //mOpt.err_E=-1.;
|
---|
| 427 | }
|
---|
| 428 | if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2
|
---|
| 429 | p = opt.find(",X"); q = opt.find_first_of(',',p+1);
|
---|
| 430 | dum = opt.substr(p,q-p);
|
---|
| 431 | if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&mOpt.stc2);
|
---|
| 432 | }
|
---|
| 433 | if(strstr(opt.c_str(),",N")) { // Nombre maximum d'iterations
|
---|
| 434 | p = opt.find(",N"); q = opt.find_first_of(',',p+1);
|
---|
| 435 | dum = opt.substr(p,q-p);
|
---|
| 436 | if(dum.length()>2) sscanf(dum.c_str(),",N%d",&mOpt.nstep);
|
---|
| 437 | }
|
---|
| 438 | if(strstr(opt.c_str(),",l")) { // niveau de print
|
---|
| 439 | p = opt.find(",l"); q = opt.find_first_of(',',p+1);
|
---|
| 440 | dum = opt.substr(p,q-p);
|
---|
| 441 | if(dum.length()>2) sscanf(dum.c_str(),",l%d",&mOpt.lp);
|
---|
| 442 | }
|
---|
| 443 | if(strstr(opt.c_str(),",d")) { // niveau de debug du fit
|
---|
| 444 | p = opt.find(",d"); q = opt.find_first_of(',',p+1);
|
---|
| 445 | dum = opt.substr(p,q-p);
|
---|
| 446 | if(dum.length()>2) sscanf(dum.c_str(),",d%d",&mOpt.lpg);
|
---|
| 447 | }
|
---|
| 448 | if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X
|
---|
| 449 | p = opt.find(",I"); q = opt.find_first_of(',',p+1);
|
---|
| 450 | dum = opt.substr(p,q-p);
|
---|
| 451 | if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&mOpt.i1,&mOpt.i2);
|
---|
| 452 | }
|
---|
| 453 | if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y
|
---|
| 454 | p = opt.find(",J"); q = opt.find_first_of(',',p+1);
|
---|
| 455 | dum = opt.substr(p,q-p);
|
---|
| 456 | if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&mOpt.j1,&mOpt.j2);
|
---|
| 457 | }
|
---|
| 458 |
|
---|
| 459 | return;
|
---|
| 460 | }
|
---|
| 461 |
|
---|
| 462 | /* --Methode-- */
|
---|
| 463 | void PIAFitter::DecodeObject(string obj)
|
---|
| 464 | // Decodage de l'objet a fitter
|
---|
| 465 | {
|
---|
[361] | 466 | NamedObjMgr omg;
|
---|
[379] | 467 | AnyDataObj* mobj = omg.GetObj(obj);
|
---|
| 468 | if(mobj == NULL)
|
---|
| 469 | {cout<<"PIAFitter::DecodeObject Error , Pas d'objet de nom "<<obj<<endl;
|
---|
[361] | 470 | return;}
|
---|
| 471 |
|
---|
[379] | 472 | // Reset
|
---|
| 473 | ResetDPointer();
|
---|
| 474 | mNVar = mNBinX = mNBinY = mNData = 0;
|
---|
[361] | 475 |
|
---|
[379] | 476 | mObj = mobj; mNObj = obj;
|
---|
| 477 | string ctyp = typeid(*mObj).name();
|
---|
| 478 |
|
---|
| 479 | // 1D
|
---|
| 480 | if (typeid(*mObj) == typeid(Vector)) {
|
---|
| 481 | mNVar = 1;
|
---|
| 482 | mV = (Vector*) mObj; mNBinX = mV->NElts(); mNBinY = 1;
|
---|
[361] | 483 | }
|
---|
[379] | 484 | else if ( (typeid(*mObj) == typeid(HProf)) || (typeid(*mObj) == typeid(Histo)) ) {
|
---|
| 485 | mNVar = 1;
|
---|
| 486 | mH = (Histo*) mObj; mNBinX = mH->NBins(); mNBinY = 1;
|
---|
[361] | 487 | }
|
---|
[379] | 488 | // 2D
|
---|
| 489 | else if (typeid(*mObj) == typeid(Matrix)) {
|
---|
| 490 | mNVar = 2;
|
---|
| 491 | mM = (Matrix*) mObj; mNBinX = mM->NCol(); mNBinY =mM->NRows();
|
---|
[361] | 492 | }
|
---|
[379] | 493 | else if (typeid(*mObj) == typeid(Histo2D)) {
|
---|
| 494 | mNVar = 2;
|
---|
| 495 | mH2 = (Histo2D*) mObj; mNBinX = mH2->NBinX(); mNBinY = mH2->NBinY();
|
---|
[361] | 496 | }
|
---|
[379] | 497 | else if (typeid(*mObj) == typeid(GeneralFitData)) {
|
---|
| 498 | mG = (GeneralFitData*) mObj; mNBinX = mG->NData(); mNBinY = 1;
|
---|
| 499 | if( mG->NVar()==1) mNVar = 1;
|
---|
| 500 | else if(mG->NVar()==2) mNVar = 2;
|
---|
| 501 | else
|
---|
| 502 | {cout<<"PIAFitter::DecodeObject Error: \n"
|
---|
| 503 | <<" GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: "
|
---|
| 504 | <<((GeneralFitData*) mObj)->NVar()<<endl;
|
---|
| 505 | return;}
|
---|
[361] | 506 | }
|
---|
[493] | 507 | #ifdef SANS_EVOLPLANCK
|
---|
[379] | 508 | else if (dynamic_cast<RzImage*>(mObj)) {
|
---|
| 509 | mNVar = 2;
|
---|
| 510 | mIm = (RzImage*) mObj; mNBinX = mIm->XSize(); mNBinY = mIm->YSize();
|
---|
[361] | 511 | }
|
---|
[493] | 512 | #else
|
---|
| 513 | //CMV_A_FAIRE else if (dynamic_cast<RzImage*>(mObj)) {
|
---|
| 514 | //CMV_A_FAIRE mNVar = 2;
|
---|
| 515 | //CMV_A_FAIRE mIm = (RzImage*) mObj; mNBinX = mIm->XSize(); mNBinY = mIm->YSize();
|
---|
| 516 | //CMV_A_FAIRE }
|
---|
| 517 | #endif
|
---|
[379] | 518 | else {
|
---|
| 519 | cout<<"PIAFitter::DecodeObject Error , Objet n'est pas un "
|
---|
[361] | 520 | <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl;
|
---|
[379] | 521 | return;
|
---|
[361] | 522 | }
|
---|
| 523 |
|
---|
[379] | 524 | mNData = mNBinX*mNBinY;
|
---|
| 525 | if(mNData<=0) {
|
---|
| 526 | cout<<"L'objet a "<<mNBinX<<","<<mNBinY<<" bins ("<<mNData<<")"<<endl;
|
---|
| 527 | return;
|
---|
| 528 | }
|
---|
[361] | 529 |
|
---|
[379] | 530 | return;
|
---|
[361] | 531 | }
|
---|
[379] | 532 |
|
---|
| 533 | /* --Methode-- */
|
---|
| 534 | void PIAFitter::CheckOptions(void)
|
---|
| 535 | // Check consistence des choix des options
|
---|
| 536 | // ATTENTION: cette methode a besoin que l'objet a fitter soit deja lu
|
---|
| 537 | {
|
---|
| 538 | if(mOpt.lp<0) mOpt.lp = 0;
|
---|
| 539 | if(mOpt.lpg<0) mOpt.lpg = 0;
|
---|
| 540 | mOpt.i1 = (mOpt.i1<0||mOpt.i1>=mNBinX)? 0: mOpt.i1;
|
---|
[381] | 541 | mOpt.i2 = (mOpt.i2<0||mOpt.i2>=mNBinX||mOpt.i2<=mOpt.i1)? mNBinX-1: mOpt.i2;
|
---|
[379] | 542 | if(mNVar>=2) {
|
---|
| 543 | mOpt.j1 = (mOpt.j1<0||mOpt.j1>=mNBinY)? 0: mOpt.j1;
|
---|
[381] | 544 | mOpt.j2 = (mOpt.j2<0||mOpt.j2>=mNBinY||mOpt.j2<=mOpt.j1)? mNBinY-1: mOpt.j2;
|
---|
[379] | 545 | } else mOpt.j2 = mOpt.j1 = 0;
|
---|
| 546 | if(mOpt.polcx==2) {
|
---|
| 547 | if(mV||mM) mOpt.xc = (mOpt.i2-mOpt.i1+1)/2.;
|
---|
| 548 | else if(mH) mOpt.xc = (mH->XMin()+mH->XMax())/2.;
|
---|
| 549 | else if(mH2) mOpt.xc = (mH2->XMin()+mH2->XMax())/2.;
|
---|
| 550 | else if(mG) {double mini,maxi; mG->GetMinMax(2,mini,maxi); mOpt.xc=(mini+maxi)/2.;}
|
---|
| 551 | else if(mIm) {mOpt.xc = mIm->XOrg() * mIm->XPxSize()*(mOpt.i2-mOpt.i1+1)/2.;}
|
---|
[361] | 552 | }
|
---|
[379] | 553 | if(mOpt.polcy==2 && mNVar>=2) {
|
---|
| 554 | if(mM) mOpt.yc = (mOpt.j2-mOpt.j1+1)/2.;
|
---|
| 555 | if(mH2) mOpt.yc = (mH2->YMin()+mH2->YMax())/2.;
|
---|
| 556 | if(mG) {double mini,maxi; mG->GetMinMax(12,mini,maxi); mOpt.yc=(mini+maxi)/2.;}
|
---|
| 557 | if(mIm) {mOpt.yc = mIm->YOrg() * mIm->YPxSize()*(mOpt.j2-mOpt.j1+1)/2.;}
|
---|
| 558 | }
|
---|
| 559 | if(mOpt.err_e>0.) mOpt.err_E=-1.;
|
---|
| 560 | if(mOpt.err_E>0.) mOpt.err_e =-1.;
|
---|
| 561 | if(mOpt.stc2<=0.) mOpt.stc2 = 1.e-3;
|
---|
| 562 | if(mOpt.nstep<2) mOpt.nstep = 100;
|
---|
[361] | 563 |
|
---|
[379] | 564 | return;
|
---|
| 565 | }
|
---|
[361] | 566 |
|
---|
[379] | 567 | /* --Methode-- */
|
---|
| 568 | void PIAFitter::PrintOptions(void)
|
---|
| 569 | // Print des options
|
---|
| 570 | {
|
---|
| 571 | cout<<"Fit["<<mNBinX<<","<<mNBinY<<"] ("<<mNData<<") dim="<<mNVar<<":"
|
---|
| 572 | <<" Int=["<<mOpt.i1<<","<<mOpt.i2<<"],["<<mOpt.j1<<","<<mOpt.j2<<"]"<<endl
|
---|
| 573 | <<" Cent="<<mOpt.polcx<<","<<mOpt.polcy<<","<<mOpt.xc<<"+x"<<","<<mOpt.yc<<"+y"
|
---|
| 574 | <<" TypE="<<mOpt.err_e<<","<<mOpt.err_E
|
---|
[385] | 575 | <<" StpX2="<<mOpt.stc2<<" Nstep="<<mOpt.nstep<<endl
|
---|
[390] | 576 | <<" Init.LFit="<<mOpt.fromlastfit<<" AutoIni.Fit="<<mOpt.autoinifit
|
---|
[379] | 577 | <<" lp,lpg="<<mOpt.lp<<","<<mOpt.lpg<<endl;
|
---|
| 578 | return;
|
---|
| 579 | }
|
---|
| 580 |
|
---|
| 581 | /* --Methode-- */
|
---|
| 582 | void PIAFitter::FillGData(void)
|
---|
| 583 | // Fill generalfitdata pour le fit
|
---|
| 584 | // ATTENTION: cette methode a besoin que les options soient decodees et checkees
|
---|
| 585 | {
|
---|
| 586 | if(mNData<=0) return;
|
---|
| 587 | if(mGData!=NULL) {delete mGData; mGData=NULL;}
|
---|
| 588 | mGData = new GeneralFitData(mNVar,mNData,0);
|
---|
| 589 |
|
---|
| 590 | for(int i=mOpt.i1;i<=mOpt.i2;i++) for(int j=mOpt.j1;j<=mOpt.j2;j++) {
|
---|
| 591 | double x,y=0.,f,e;
|
---|
| 592 |
|
---|
| 593 | if(mV)
|
---|
| 594 | {x= (double) i; f=(*mV)(i); e=1.;}
|
---|
| 595 | else if(mH)
|
---|
| 596 | {x=mH->BinCenter(i); f=(*mH)(i); e=(mH->HasErrors())?mH->Error(i):1.;}
|
---|
| 597 | else if(mM)
|
---|
| 598 | {x=(double) i; y=(double) j; f=(*mM)(j,i); e=1.;}
|
---|
| 599 | else if(mH2)
|
---|
| 600 | {float xf,yf; mH2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf;
|
---|
| 601 | f=(*mH2)(i,j); e=(mH2->HasErrors())?mH2->Error(i,j):1.;}
|
---|
| 602 | else if(mIm)
|
---|
| 603 | {x=mIm->XOrg()+(i+0.5)*mIm->XPxSize(); y=mIm->YOrg()+(j+0.5)*mIm->YPxSize();
|
---|
| 604 | f=mIm->DValue(i,j); e=1.;}
|
---|
| 605 | else if(mG&&mNVar==1) {x= mG->X(i); f=mG->Val(i); e=mG->EVal(i);}
|
---|
| 606 | else if(mG&&mNVar==2) {x= mG->X(i); y=mG->Y(i); f=mG->Val(i); e=mG->EVal(i);}
|
---|
[361] | 607 | else x=y=f=e=0.;
|
---|
| 608 |
|
---|
| 609 | // Gestion des erreurs a utiliser
|
---|
[379] | 610 | if(mOpt.err_e>0.) e=mOpt.err_e;
|
---|
| 611 | else if(mOpt.err_E>0.) {e=(f<-1.||f>1.)?mOpt.err_E*sqrt(fabs(f)):mOpt.err_E;}
|
---|
[361] | 612 |
|
---|
[379] | 613 | // Remplissage de generalfitdata
|
---|
| 614 | if(mFName[0]=='p') {x -= mOpt.xc; if(mNVar>=2) y -= mOpt.yc;}
|
---|
| 615 | if(mNVar==1) mGData->AddData1(x,f,e);
|
---|
| 616 | else if(mNVar==2) mGData->AddData2(x,y,f,e);
|
---|
[361] | 617 | }
|
---|
| 618 |
|
---|
[379] | 619 | if(mGData->NData()<=0) {
|
---|
| 620 | cout<<"Pas de donnees dans GeneralFitData: "<<mGData->NData()<<endl;
|
---|
[361] | 621 | return;
|
---|
[379] | 622 | }
|
---|
[361] | 623 |
|
---|
[379] | 624 | if(mOpt.lpg>1) {
|
---|
| 625 | mGData->PrintStatus();
|
---|
| 626 | mGData->PrintData(0);
|
---|
| 627 | mGData->PrintData(mGData->NData()-1);
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | return;
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 | /* --Methode-- */
|
---|
| 634 | void PIAFitter::DecodeFunction(string func)
|
---|
| 635 | // Fonction a fitter
|
---|
| 636 | // ATTENTION: cette methode a besoin que les donnees soient lues
|
---|
| 637 | {
|
---|
[385] | 638 | if(func.length()<=0)
|
---|
| 639 | {cout<<"PIAFitter::DecodeFunction Donnez un nom de fonction a fitter."<<endl;
|
---|
| 640 | return;}
|
---|
| 641 | if(mFunction!=NULL) {delete mFunction; mFunction=NULL;}
|
---|
[392] | 642 | if(mFunc !=NULL) {delete mFunc; mFunc=NULL;}
|
---|
| 643 | mNPar=0; mFName = "";
|
---|
[379] | 644 |
|
---|
[385] | 645 | if(func == mNameFitFunc) { // Fonction utilisateur
|
---|
| 646 | mFunc = new GeneralFunc(mUFNVar,mUFNPar,mFitFunc,mFitFuncDer);
|
---|
| 647 | mNPar = mUFNPar;
|
---|
[386] | 648 | cout<<"Fonction utilisateur nvar="<<mUFNVar<<", npar="<<mNPar<<endl;
|
---|
[385] | 649 | } else if(func[0]=='p' && mNVar==1) { //polynome
|
---|
| 650 | int degre=0; if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
[361] | 651 | cout<<"Fit polynome 1D de degre "<<degre<<endl;
|
---|
[379] | 652 | Polyn1D* myf = new Polyn1D(degre,mOpt.xc);
|
---|
[385] | 653 | mFunction = myf; mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 654 |
|
---|
[379] | 655 | } else if(func[0]=='e' && mNVar==1) { //exponentielle
|
---|
[385] | 656 | int degre=-1; if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
[361] | 657 | cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
|
---|
| 658 | Exp1DPol* myf;
|
---|
[379] | 659 | if(degre>=0) myf = new Exp1DPol((unsigned int)degre,mOpt.xc);
|
---|
| 660 | else myf = new Exp1DPol(mOpt.xc);
|
---|
[385] | 661 | mFunction = myf; mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 662 |
|
---|
[379] | 663 | } else if(func[0]=='g' && mNVar==1) { //gaussienne en hauteur
|
---|
[385] | 664 | int degre=-1; if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
[361] | 665 | cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl;
|
---|
| 666 | Gauss1DPol* myf;
|
---|
[379] | 667 | if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((mOpt.polcx)?true:false));
|
---|
| 668 | else { bool bfg = (mOpt.polcx)?true:false; myf = new Gauss1DPol(bfg); }
|
---|
[385] | 669 | mFunction = myf; mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 670 |
|
---|
[379] | 671 | } else if(func[0]=='G' && mNVar==1) { //gaussienne en volume
|
---|
[385] | 672 | int degre=-1; if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
[361] | 673 | cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl;
|
---|
| 674 | GaussN1DPol* myf;
|
---|
[379] | 675 | if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((mOpt.polcx)?true:false));
|
---|
| 676 | else { bool bfg = (mOpt.polcx)?true:false; myf = new GaussN1DPol(bfg); }
|
---|
[385] | 677 | mFunction = myf; mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 678 |
|
---|
[379] | 679 | } else if(func[0]=='p' && mNVar==2) { //polynome 2D
|
---|
[385] | 680 | int degre=0; if(func.length()>1) sscanf(func.c_str()+1,"%d",°re);
|
---|
[361] | 681 | cout<<"Fit polynome 2D de degre "<<degre<<endl;
|
---|
[379] | 682 | Polyn2D* myf = new Polyn2D(degre,mOpt.xc,mOpt.yc);
|
---|
[385] | 683 | mFunction = myf; mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 684 |
|
---|
[379] | 685 | } else if(func[0]=='G' && mNVar==2) { //gaussienne+fond en volume
|
---|
[385] | 686 | int integ=0; if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
[361] | 687 | cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl;
|
---|
[385] | 688 | if(integ) {GauRhInt2D* myf = new GauRhInt2D; mFunction = myf;}
|
---|
[392] | 689 | else {GauRho2D* myf = new GauRho2D; mFunction = myf;}
|
---|
[385] | 690 | mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 691 |
|
---|
[379] | 692 | } else if(func[0]=='d' && mNVar==2) { //DL gaussienne+fond en volume
|
---|
[385] | 693 | int integ=0; if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
[361] | 694 | cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl;
|
---|
[385] | 695 | if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; mFunction = myf;}
|
---|
[392] | 696 | else {GdlRho2D* myf = new GdlRho2D; mFunction = myf;}
|
---|
[385] | 697 | mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 698 |
|
---|
[379] | 699 | } else if(func[0]=='D' && mNVar==2) { //DL gaussienne+fond avec coeff variable p6 en volume
|
---|
[385] | 700 | int integ=0; if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
[361] | 701 | cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl;
|
---|
[385] | 702 | if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; mFunction = myf;}
|
---|
[392] | 703 | else {Gdl1Rho2D* myf = new Gdl1Rho2D; mFunction = myf;}
|
---|
[385] | 704 | mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 705 |
|
---|
[379] | 706 | } else if(func[0]=='M' && mNVar==2) { //Moffat+fond (volume)
|
---|
[385] | 707 | int integ=0; if(func.length()>1) if(func[1]=='i') integ=1;
|
---|
[361] | 708 | cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl;
|
---|
[385] | 709 | if(integ) {MofRhInt2D* myf = new MofRhInt2D; mFunction = myf;}
|
---|
[392] | 710 | else {MofRho2D* myf = new MofRho2D; mFunction = myf;}
|
---|
[385] | 711 | mNPar = mFunction->NPar(); mFName = func;
|
---|
[361] | 712 |
|
---|
| 713 | } else {
|
---|
[379] | 714 | cout<<"Fonction "<<func<<" inconnue pour la dim "<<mNVar<<endl;
|
---|
[361] | 715 | return;
|
---|
| 716 | }
|
---|
| 717 |
|
---|
[379] | 718 | return;
|
---|
[361] | 719 | }
|
---|
| 720 |
|
---|
[379] | 721 | /* --Methode-- */
|
---|
| 722 | void PIAFitter::ReSetParam(void)
|
---|
| 723 | // Pour (re)dimensionner les tableaux des parametres
|
---|
| 724 | // ATTENTION: cette methode a besoin que la fonction soit connue
|
---|
| 725 | {
|
---|
| 726 | if(mNPar==0) return;
|
---|
| 727 | mPar.Realloc(mNPar); mPar=0.;
|
---|
| 728 | mStep.Realloc(mNPar); mStep=1.;
|
---|
| 729 | mMin.Realloc(mNPar); mMin=1.;
|
---|
| 730 | mMax.Realloc(mNPar); mMax=-1.;
|
---|
| 731 | mFix.Realloc(mNPar); mFix=0.;
|
---|
| 732 | return;
|
---|
[361] | 733 | }
|
---|
| 734 |
|
---|
[379] | 735 | /* --Methode-- */
|
---|
[390] | 736 | void PIAFitter::AutoIniFit(void)
|
---|
| 737 | // Initialisation automatique des parametres du fit
|
---|
| 738 | {
|
---|
[392] | 739 | if(mFunc) { // Fonction utilisateur
|
---|
[390] | 740 | cout<<"PIAFitter::AutoIniFit : Fonction utilisateur, pas d'init auto"<<endl;
|
---|
| 741 | } else if(mFName[0]=='p' && mNVar==1) { //poly 1D
|
---|
| 742 | cout<<"PIAFitter::AutoIniFit : Auto Init type polynome 1D"<<endl;
|
---|
[392] | 743 | IniFitP1ou2D();
|
---|
[390] | 744 |
|
---|
| 745 | } else if(mFName[0]=='g' && mNVar==1) { //gauss en haut 1D
|
---|
| 746 | cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_haut+pol 1D"<<endl;
|
---|
[392] | 747 | IniFitGhP1D();
|
---|
[390] | 748 |
|
---|
| 749 | } else if(mFName[0]=='G' && mNVar==1) { //gauss en vol 1D
|
---|
| 750 | cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_vol+pol 1D"<<endl;
|
---|
[392] | 751 | IniFitGvP1D();
|
---|
[390] | 752 |
|
---|
| 753 | } else if(mFName[0]=='p' && mNVar==2) { //poly 2D
|
---|
| 754 | cout<<"PIAFitter::AutoIniFit : Auto Init type polynome 2D"<<endl;
|
---|
[392] | 755 | IniFitP1ou2D();
|
---|
[390] | 756 |
|
---|
| 757 | } else if((mFName[0]=='G'||mFName[0]=='d') && mNVar==2) { //gauss+fond en vol
|
---|
| 758 | cout<<"PIAFitter::AutoIniFit : Auto Init type gauss_vol+fond 2D"<<endl;
|
---|
[392] | 759 | IniFitGv2D();
|
---|
[390] | 760 |
|
---|
| 761 | } else if(mFName[0]=='D' && mNVar==2) { //DLgauss+fond en vol 2D
|
---|
| 762 | cout<<"PIAFitter::AutoIniFit : Auto Init type DLgauss_vol+fond 2D"<<endl;
|
---|
[392] | 763 | IniFitGv2D();
|
---|
[390] | 764 | Vector dum(mNPar);
|
---|
| 765 | dum = mPar; mPar(6)=0.5; mPar(7)=dum(6);
|
---|
| 766 | dum = mStep; mStep(6)=0.05; mStep(7)=dum(6);
|
---|
| 767 | dum = mMin; mMin(6)=0.; mMin(7)=dum(6);
|
---|
| 768 | dum = mMax; mMax(6)=10.; mMax(7)=dum(6);
|
---|
| 769 | dum = mFix; mFix(6)=1.1; mFix(7)=dum(6);
|
---|
| 770 |
|
---|
| 771 | } else if(mFName[0]=='M' && mNVar==2) { //Moffat+fond en vol 2D
|
---|
| 772 | cout<<"PIAFitter::AutoIniFit : Auto Init type moffat_vol+fond 2D"<<endl;
|
---|
[392] | 773 | IniFitGv2D();
|
---|
[390] | 774 | Vector dum(mNPar);
|
---|
| 775 | dum = mPar; mPar(6)=2.5; mPar(7)=dum(6);
|
---|
| 776 | dum = mStep; mStep(6)=0.05; mStep(7)=dum(6);
|
---|
| 777 | dum = mMin; mMin(6)=1.2; mMin(7)=dum(6);
|
---|
| 778 | dum = mMax; mMax(6)=10.; mMax(7)=dum(6);
|
---|
| 779 | dum = mFix; mFix(6)=1.1; mFix(7)=dum(6);
|
---|
| 780 |
|
---|
| 781 | } else {
|
---|
| 782 | cout<<"PIAFitter::AutoIniFit : Fonction "<<mFName
|
---|
| 783 | <<", \n pas d'init auto en dim "<<mNVar<<endl;
|
---|
| 784 | return;
|
---|
| 785 | }
|
---|
| 786 |
|
---|
| 787 | return;
|
---|
| 788 | }
|
---|
| 789 |
|
---|
| 790 | /* --Methode-- */
|
---|
[379] | 791 | void PIAFitter::InitParFromLastFit(void)
|
---|
| 792 | // Initialisation du fit a partir des resultats du fit precedent
|
---|
| 793 | // (Les arguments de la ligne de commande sont prioritaires)
|
---|
| 794 | // ATTENTION: cette methode a besoin que la fonction soit connue
|
---|
| 795 | {
|
---|
| 796 | if(mNPar==0) return;
|
---|
| 797 | int n = mParSave.NElts();
|
---|
| 798 | if(n==0) return;
|
---|
| 799 |
|
---|
| 800 | for(int i=0;i<mNPar;i++) {
|
---|
| 801 | if(i>=n) break;
|
---|
| 802 | mPar(i) = mParSave(i);
|
---|
| 803 | mStep(i) = mStepSave(i);
|
---|
| 804 | mMin(i) = mMinSave(i);
|
---|
| 805 | mMax(i) = mMaxSave(i);
|
---|
| 806 | mFix(i) = mFixSave(i);
|
---|
| 807 | }
|
---|
| 808 |
|
---|
[361] | 809 | return;
|
---|
| 810 | }
|
---|
| 811 |
|
---|
[379] | 812 | /* --Methode-- */
|
---|
| 813 | void PIAFitter::DecodeParam(string par,string step,string min,string max,string fix)
|
---|
| 814 | // Decodage des parametres
|
---|
| 815 | // ATTENTION: cette methode a besoin que la fonction soit connue
|
---|
| 816 | // et que les options soient decodees
|
---|
[361] | 817 | {
|
---|
[379] | 818 | if(mNPar==0) return;
|
---|
| 819 | ReSetParam();
|
---|
[390] | 820 | if(mOpt.autoinifit) AutoIniFit();
|
---|
[379] | 821 | if(mOpt.fromlastfit) InitParFromLastFit();
|
---|
| 822 | Vector* v=NULL; string* s=NULL;
|
---|
| 823 | for(int j=0;j<5;j++) {
|
---|
| 824 | if(j==0) {v=&mPar; s=∥} else if(j==1) {v=&mStep; s=&step;}
|
---|
| 825 | else if(j==2) {v=&mMin; s=&min;} else if(j==3) {v=&mMax; s=&max;}
|
---|
| 826 | else if(j==4) {v=&mFix; s=&fix;}
|
---|
| 827 | if(s->length()>0) *s += ",";
|
---|
| 828 | for(int i=0;i<mNPar;i++) {
|
---|
| 829 | if(s->length()<=0) break;
|
---|
| 830 | if((*s)[0]!='!') sscanf(s->c_str(),"%lf",&(*v)(i));
|
---|
| 831 | size_t p = s->find_first_of(',') + 1;
|
---|
| 832 | if(p>=s->length()) *s = ""; else *s = s->substr(p);
|
---|
[361] | 833 | }
|
---|
| 834 | }
|
---|
[379] | 835 | return;
|
---|
| 836 | }
|
---|
[361] | 837 |
|
---|
[379] | 838 | /* --Methode-- */
|
---|
| 839 | int PIAFitter::DoFit(void)
|
---|
| 840 | // Fit avec generalfit
|
---|
| 841 | {
|
---|
| 842 | if(mNPar==0) return -1000;
|
---|
[385] | 843 | if((mFunction==NULL && mFunc==NULL) || mGData==NULL) {
|
---|
| 844 | cout<<"PIAFitter::DoFit error: mFunction,mFunc="<<mFunction<<","<<mFunc
|
---|
| 845 | <<" mGData="<<mGData<<endl;
|
---|
[379] | 846 | return -1001;
|
---|
| 847 | }
|
---|
| 848 | // classe GeneraFit
|
---|
| 849 | if(mFit != NULL) {delete mFit; mFit= NULL;}
|
---|
[392] | 850 | if(mFunction) mFit = new GeneralFit(mFunction);
|
---|
| 851 | else if(mFunc) mFit = new GeneralFit(mFunc);
|
---|
| 852 | if(!mFit) return(-1002);
|
---|
| 853 |
|
---|
[379] | 854 | // Options et Set de GeneralFit
|
---|
| 855 | mFit->SetDebug(mOpt.lpg);
|
---|
| 856 | mFit->SetData(mGData);
|
---|
| 857 | mFit->SetStopChi2(mOpt.stc2);
|
---|
| 858 | mFit->SetMaxStep(mOpt.nstep);
|
---|
[385] | 859 | {for(int i=0;i<mNPar;i++) {
|
---|
[379] | 860 | char str[10];
|
---|
| 861 | sprintf(str,"P%d",i);
|
---|
| 862 | mFit->SetParam(i,str,mPar(i),mStep(i),mMin(i),mMax(i));
|
---|
| 863 | if((int)(mFix(i)+0.001)>=1.) mFit->SetFix(i);
|
---|
| 864 | }}
|
---|
| 865 | if(mOpt.lp>1) mFit->PrintFit();
|
---|
[361] | 866 |
|
---|
[379] | 867 | // Fit
|
---|
[1051] | 868 | mParSave.Clone(mPar); mStepSave.Clone(mStep); mFixSave.Clone(mFix);
|
---|
| 869 | mMinSave.Clone(mMin); mMaxSave.Clone(mMax); mOptSave = mOpt;
|
---|
[379] | 870 | double c2r = -1.;
|
---|
| 871 | int rcfit = mFit->Fit();
|
---|
| 872 | if(mOpt.lp>0) mFit->PrintFit();
|
---|
| 873 | if(rcfit>0) {
|
---|
| 874 | c2r = mFit->GetChi2Red();
|
---|
| 875 | cout<<"C2r_Reduit = "<<c2r<<" nstep="<<mFit->GetNStep()<<" rc="<<rcfit<<endl;
|
---|
[385] | 876 | for(int i=0;i<mNPar;i++) mParSave(i)=mFit->GetParm(i);
|
---|
[379] | 877 | } else {
|
---|
| 878 | cout<<"echec Fit, rc = "<<rcfit<<" nstep="<<mFit->GetNStep()<<endl;
|
---|
| 879 | mFit->PrintFitErr(rcfit);
|
---|
| 880 | }
|
---|
[361] | 881 |
|
---|
[379] | 882 | return rcfit;
|
---|
[361] | 883 | }
|
---|
[379] | 884 |
|
---|
| 885 | /* --Methode-- */
|
---|
| 886 | void PIAFitter::FitFunRes(void)
|
---|
| 887 | // Mise a disposition des resultats (fonction fitee et residus)
|
---|
| 888 | {
|
---|
[385] | 889 | if(mFit && (mOpt.okres||mOpt.okfun)) {
|
---|
[379] | 890 | NamedObjMgr omg;
|
---|
[384] | 891 | string nomres = mNObj + "_res";
|
---|
| 892 | string nomfun = mNObj + "_fun";
|
---|
[493] | 893 | //####################
|
---|
| 894 | #ifdef SANS_EVOLPLANCK
|
---|
| 895 | //####################
|
---|
[379] | 896 | if(mV) {
|
---|
| 897 | if(mOpt.okres) {Vector* ob = mV->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);}
|
---|
| 898 | if(mOpt.okfun) {Vector* ob = mV->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);}
|
---|
| 899 | } else if(mH) {
|
---|
| 900 | if(mOpt.okres) {Histo* ob = mH->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);}
|
---|
| 901 | if(mOpt.okfun) {Histo* ob = mH->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);}
|
---|
| 902 | } else if(mM) {
|
---|
| 903 | if(mOpt.okres) {Matrix* ob = mM->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);}
|
---|
| 904 | if(mOpt.okfun) {Matrix* ob = mM->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);}
|
---|
| 905 | } else if(mH2) {
|
---|
[392] | 906 | if(mOpt.okres)
|
---|
| 907 | {Histo2D* ob = mH2->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);}
|
---|
| 908 | if(mOpt.okfun)
|
---|
| 909 | {Histo2D* ob = mH2->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);}
|
---|
[379] | 910 | } else if(mIm) {
|
---|
[384] | 911 | if(mOpt.okres) {
|
---|
| 912 | RzImage* ob = mIm->FitResidus(*mFit);
|
---|
| 913 | if(ob) {ImageR4* rob = new ImageR4(*ob); omg.AddObj(rob,nomres); delete ob;}
|
---|
| 914 | }
|
---|
| 915 | if(mOpt.okfun) {
|
---|
| 916 | RzImage* ob = mIm->FitFunction(*mFit);
|
---|
| 917 | if(ob) {ImageR4* rob = new ImageR4(*ob); omg.AddObj(rob,nomfun); delete ob;}
|
---|
| 918 | }
|
---|
[379] | 919 | } else if(mG) {
|
---|
[392] | 920 | if(mOpt.okres)
|
---|
| 921 | {GeneralFitData* ob = mG->FitResidus(*mFit); if(ob) omg.AddObj(ob,nomres);}
|
---|
| 922 | if(mOpt.okfun)
|
---|
| 923 | {GeneralFitData* ob = mG->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);}
|
---|
[361] | 924 | }
|
---|
[493] | 925 | //####################
|
---|
| 926 | #else
|
---|
| 927 | //####################
|
---|
| 928 | if(mV) {
|
---|
[769] | 929 | if(mOpt.okres) {
|
---|
| 930 | Vector* ob = new Vector(ObjectFitter::FitResidus(*mV, *mFit),true);
|
---|
| 931 | if(ob) omg.AddObj(ob,nomres);
|
---|
| 932 | }
|
---|
| 933 | if(mOpt.okfun) {
|
---|
| 934 | Vector* ob = new Vector(ObjectFitter::FitFunction(*mV, *mFit),true);
|
---|
| 935 | if(ob) omg.AddObj(ob,nomfun);
|
---|
| 936 | }
|
---|
[493] | 937 | } else if(mH) {
|
---|
| 938 | if(mOpt.okres) {Histo* ob = new Histo(mH->FitResidus(*mFit)); if(ob) omg.AddObj(ob,nomres);}
|
---|
| 939 | if(mOpt.okfun) {Histo* ob = new Histo(mH->FitFunction(*mFit)); if(ob) omg.AddObj(ob,nomfun);}
|
---|
| 940 | } else if(mM) {
|
---|
[769] | 941 | if(mOpt.okres) {
|
---|
| 942 | Matrix* ob = new Matrix(ObjectFitter::FitResidus(*mM, *mFit), true);
|
---|
| 943 | if(ob) omg.AddObj(ob,nomres);
|
---|
| 944 | }
|
---|
| 945 | if(mOpt.okfun) {
|
---|
| 946 | Matrix* ob = new Matrix(ObjectFitter::FitFunction(*mM, *mFit), true);
|
---|
| 947 | if(ob) omg.AddObj(ob,nomfun);
|
---|
| 948 | }
|
---|
[493] | 949 | } else if(mH2) {
|
---|
| 950 | if(mOpt.okres)
|
---|
| 951 | {Histo2D* ob = new Histo2D(mH2->FitResidus(*mFit)); if(ob) omg.AddObj(ob,nomres);}
|
---|
| 952 | if(mOpt.okfun)
|
---|
| 953 | {Histo2D* ob = new Histo2D(mH2->FitFunction(*mFit)); if(ob) omg.AddObj(ob,nomfun);}
|
---|
| 954 | //CMV_A_FAIRE } else if(mIm) {
|
---|
| 955 | //CMV_A_FAIRE if(mOpt.okres) {
|
---|
| 956 | //CMV_A_FAIRE RzImage* ob = mIm->FitResidus(*mFit);
|
---|
| 957 | //CMV_A_FAIRE if(ob) {ImageR4* rob = new ImageR4(*ob); omg.AddObj(rob,nomres); delete ob;}
|
---|
| 958 | //CMV _A_FAIRE }
|
---|
| 959 | //CMV_A_FAIRE if(mOpt.okfun) {
|
---|
| 960 | //CMV_A_FAIRE RzImage* ob = mIm->FitFunction(*mFit);
|
---|
| 961 | //CMV_A_FAIRE if(ob) {ImageR4* rob = new ImageR4(*ob); omg.AddObj(rob,nomfun); delete ob;}
|
---|
| 962 | //CMV_A_FAIRE }
|
---|
| 963 | } else if(mG) {
|
---|
| 964 | if(mOpt.okres)
|
---|
| 965 | {GeneralFitData* ob = new GeneralFitData(mG->FitResidus(*mFit)); if(ob) omg.AddObj(ob,nomres);}
|
---|
| 966 | if(mOpt.okfun)
|
---|
| 967 | {GeneralFitData* ob = new GeneralFitData(mG->FitFunction(*mFit)); if(ob) omg.AddObj(ob,nomfun);}
|
---|
| 968 | }
|
---|
| 969 | //####################
|
---|
| 970 | #endif
|
---|
| 971 | //####################
|
---|
[361] | 972 | }
|
---|
[379] | 973 | return;
|
---|
[361] | 974 | }
|
---|
[379] | 975 |
|
---|
| 976 | /* --Methode-- */
|
---|
| 977 | void PIAFitter::LinFit(void)
|
---|
| 978 | // Fit lineaire de polynomes
|
---|
| 979 | {
|
---|
| 980 | if(mFName.length()<=0)
|
---|
| 981 | {cout<<"PIAFitter::LinFit Donnez un nom de fonction a fitter."<<endl;
|
---|
| 982 | return;}
|
---|
| 983 | if(!mGData)
|
---|
| 984 | {cout<<"PIAFitter::LinFit pas de Data."<<endl; return;}
|
---|
| 985 | if(mFName[0]!='p')
|
---|
| 986 | {cout<<"PIAFitter::LinFit fonction non prevue "<<mFName<<endl;
|
---|
| 987 | return;}
|
---|
| 988 | int degre = 0;
|
---|
| 989 | if(mFName.length()>1) sscanf(mFName.c_str()+1,"%d",°re);
|
---|
| 990 |
|
---|
| 991 | if(mNVar==1) { // Fit lineaire de polynome 1D
|
---|
| 992 | cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl;
|
---|
| 993 | Poly p1(0);
|
---|
| 994 | double c2rl = mGData->PolFit(0,p1,degre);
|
---|
| 995 | cout<<"C2r_lineaire = "<<c2rl<<endl;
|
---|
| 996 | if(mOpt.lp>0) cout<<p1<<endl;
|
---|
| 997 | } else if(mNVar==2) { // Fit lineaire de polynome 2D
|
---|
| 998 | cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl;
|
---|
| 999 | Poly2 p2(0);
|
---|
| 1000 | double c2rl = mGData->PolFit(0,1,p2,degre);
|
---|
| 1001 | cout<<"C2r_lineaire = "<<c2rl<<endl;
|
---|
| 1002 | if(mOpt.lp>0) cout<<p2<<endl;
|
---|
[361] | 1003 | }
|
---|
[379] | 1004 |
|
---|
| 1005 | return;
|
---|
[361] | 1006 | }
|
---|
[379] | 1007 |
|
---|
| 1008 | /* --Methode-- */
|
---|
[385] | 1009 | void PIAFitter::LinkFitFunc(string const& fname, string const& funcname
|
---|
| 1010 | ,int nvar,int npar)
|
---|
| 1011 | // Compilation et link dynamique de la fonction a fitter
|
---|
[384] | 1012 | {
|
---|
[385] | 1013 | if(nvar<1 || npar<1) return;
|
---|
| 1014 | if(mDlUFunc != NULL) {delete mDlUFunc; mDlUFunc=NULL;}
|
---|
| 1015 | mFitFunc = NULL; mFitFuncDer = NULL;
|
---|
| 1016 | mUFNVar= mUFNPar = 0; mNameFitFunc = "";
|
---|
[384] | 1017 |
|
---|
| 1018 | // On compile le fichier C, on fabrique un .so et on l'ouvre
|
---|
| 1019 | mDlUFunc = PDynLinkMgr::BuildFromCFile(fname);
|
---|
[385] | 1020 | if(mDlUFunc == NULL)
|
---|
| 1021 | {cerr<<"PIAFitter::LinkFitFunc() Erreur building .so "<<endl; return;}
|
---|
[384] | 1022 |
|
---|
| 1023 | // On recupere la fonction de fit
|
---|
| 1024 | mFitFunc = (DlUserFitFunc) mDlUFunc->GetFunction(funcname);
|
---|
[385] | 1025 | if(mFitFunc == NULL) // Probleme, on n'a pas trouve etc ...
|
---|
| 1026 | {cerr<<"PIAFitter::LinkFitFunc() Erreur linking function"<<funcname<<endl;
|
---|
| 1027 | delete mDlUFunc; mDlUFunc = NULL; return;}
|
---|
[384] | 1028 |
|
---|
[385] | 1029 | // On recupere la fonction des derivees
|
---|
[384] | 1030 | string fnameder = funcname+"_der";
|
---|
| 1031 | mFitFuncDer = (DlUserFitFuncDer) mDlUFunc->GetFunction(fnameder);
|
---|
[385] | 1032 | if(mFitFuncDer == NULL)
|
---|
| 1033 | {cout<<"PIAFitter::LinkFitFunc() No derive for"<<fnameder<<endl;}
|
---|
[384] | 1034 |
|
---|
[385] | 1035 | // Variables et pointeurs definissant le link a la fonction utilisateur
|
---|
[384] | 1036 | mNameFitFunc = funcname;
|
---|
| 1037 | mUFNVar = nvar;
|
---|
| 1038 | mUFNPar = npar;
|
---|
[385] | 1039 | cout<<"PIAFitter::LinkFitFunc() UserFitFunc="<<mNameFitFunc
|
---|
| 1040 | <<" NVar="<<mUFNVar<<" NPar="<<mUFNPar<<endl;
|
---|
[384] | 1041 |
|
---|
[385] | 1042 | return;
|
---|
| 1043 | }
|
---|
[384] | 1044 |
|
---|
| 1045 | /* --Methode-- */
|
---|
[385] | 1046 | void PIAFitter::PrepareFitFuncCFile(string const& fname, string const& funcname
|
---|
| 1047 | , int nvar, int npar)
|
---|
| 1048 | // Pour ecrire un squelette des fichier C avec pour une fonction a fitter
|
---|
[384] | 1049 | {
|
---|
[385] | 1050 | if(fname.length()<=0 || funcname.length()<=0 || nvar<=0 || npar <=0) {
|
---|
| 1051 | cerr<<"PIAFitter::PrepareFitFuncCFile: error "
|
---|
| 1052 | <<" nvar="<<nvar<<" npar="<<npar<<endl
|
---|
| 1053 | <<" file_name="<<fname<<" func_name="<<funcname<<endl
|
---|
| 1054 | <<" ---- No File Created ! ----"<<endl;
|
---|
| 1055 | return;
|
---|
[384] | 1056 | }
|
---|
| 1057 |
|
---|
[385] | 1058 | FILE* fip = fopen(fname.c_str(),"w");
|
---|
| 1059 | if(fip==NULL)
|
---|
| 1060 | {cerr<<"PIAFitter::PrepareFitFuncCFile: error opening file for writing\n"
|
---|
| 1061 | <<fname<<endl; return;}
|
---|
| 1062 |
|
---|
| 1063 | fprintf(fip,"#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n\n");
|
---|
| 1064 | fprintf(fip,"/* - many functions can be written in this file: */\n");
|
---|
| 1065 | fprintf(fip,"/* here is an exemple for creation of function %s */\n\n"
|
---|
| 1066 | ,funcname.c_str());
|
---|
| 1067 | fprintf(fip,"double %s(double const* x,double const* p)\n",funcname.c_str());
|
---|
| 1068 | fprintf(fip,"/* Function : F(x[0-%d];p[0-%d]) */\n",nvar-1,npar-1);
|
---|
| 1069 | fprintf(fip,"/* variables x1=x[0],x2=x[1],...,x%d=x[%d] */\n",nvar,nvar-1);
|
---|
| 1070 | fprintf(fip,"/* parameters p1=p[0],p2=p[1],...,p%d=p[%d] */\n",nvar,nvar-1);
|
---|
| 1071 | fprintf(fip,"{\n val = F(x[];p[]);\n return(val);\n}\n\n");
|
---|
| 1072 | string fder = funcname + "_der";
|
---|
| 1073 | fprintf(fip,"/* That function is optional */\n");
|
---|
| 1074 | fprintf(fip,"/*\n");
|
---|
| 1075 | fprintf(fip,"double %s(double const* x,double const* p,double* dp)\n",fder.c_str());
|
---|
| 1076 | fprintf(fip,"{\n");
|
---|
| 1077 | for(int i=0;i<npar;i++) fprintf(fip," dp[%d] = dF(x[];p[])/dp[%d]\n",i,i);
|
---|
| 1078 | fprintf(fip," val = F(x[];p[]);\n return(val);\n}\n\n");
|
---|
| 1079 | fprintf(fip,"*/\n");
|
---|
| 1080 |
|
---|
| 1081 | fclose(fip);
|
---|
| 1082 | }
|
---|
| 1083 |
|
---|
[384] | 1084 | /* --Methode-- */
|
---|
[379] | 1085 | int PIAFitter::Execute(string& kw, vector<string>& tokens)
|
---|
| 1086 | // Execution des commandes de fit : "fit" et "fitw"
|
---|
| 1087 | {
|
---|
[385] | 1088 | ////// Les commandes pour creer les fonctions de fit utilisateur
|
---|
| 1089 | if(kw == "crfitfil") {
|
---|
| 1090 | if (tokens.size() < 4)
|
---|
| 1091 | {cout<<"Usage:crfitfil filename funcname nvar npar"<<endl;return(-1);}
|
---|
| 1092 | int nvar = atoi(tokens[2].c_str()), npar = atoi(tokens[3].c_str());
|
---|
| 1093 | PrepareFitFuncCFile(tokens[0],tokens[1],nvar,npar);
|
---|
| 1094 | return(0);
|
---|
| 1095 | } else if (kw == "crfitfun") {
|
---|
| 1096 | if (tokens.size() < 4)
|
---|
| 1097 | {cout<<"Usage:crfitfun filename funcname nvar npar"<<endl;return(-1);}
|
---|
| 1098 | int nvar = atoi(tokens[2].c_str()), npar = atoi(tokens[3].c_str());
|
---|
| 1099 | LinkFitFunc(tokens[0],tokens[1],nvar,npar);
|
---|
| 1100 | return(0);
|
---|
| 1101 | }
|
---|
| 1102 |
|
---|
| 1103 | ////// Les commandes pour fitter
|
---|
[379] | 1104 | if(tokens.size() < 2) {
|
---|
| 1105 | cout
|
---|
| 1106 | <<"Usage:fit nomobj func [Options]\n"
|
---|
| 1107 | <<" ou fitw nomobj func [Options]\n"
|
---|
| 1108 | <<" avec Options: [p:p1,...,pn s:s1,...,sn m:m1,...,mn \n"
|
---|
| 1109 | <<" M:M1,...,Mn f:f1,...,fn o:.,.,. o:.,.,.]\n"
|
---|
| 1110 | <<" ou fitlin nomobj func [o:.,.,. o:.,.,.]\n";
|
---|
| 1111 | return(-1);
|
---|
[361] | 1112 | }
|
---|
[392] | 1113 |
|
---|
[379] | 1114 | // decodage des arguments de la commande
|
---|
| 1115 | string mSp,mSs,mSm,mSM,mSf,mSo;
|
---|
| 1116 | mSp=""; mSs=""; mSm=""; mSM=""; mSf=""; mSo="";
|
---|
| 1117 | if(tokens.size()>2)
|
---|
| 1118 | for(int ip=2;ip<(int)tokens.size();ip++) {
|
---|
| 1119 | if(tokens[ip].length()<=2) continue;
|
---|
| 1120 | const char *c = tokens[ip].c_str();
|
---|
| 1121 | if(c[1]!=':') continue;
|
---|
| 1122 | if(c[0]=='p') mSp=c+2;
|
---|
| 1123 | else if(c[0]=='s') mSs=c+2;
|
---|
| 1124 | else if(c[0]=='m') mSm=c+2;
|
---|
| 1125 | else if(c[0]=='M') mSM=c+2;
|
---|
| 1126 | else if(c[0]=='f') mSf=c+2;
|
---|
| 1127 | else if(c[0]=='o') {mSo += ","; mSo += c+2;}
|
---|
| 1128 | }
|
---|
[392] | 1129 |
|
---|
[379] | 1130 | // Execution des commandes
|
---|
| 1131 | DecodeOptions(mSo);
|
---|
| 1132 | DecodeObject(tokens[0]);
|
---|
| 1133 | CheckOptions();
|
---|
| 1134 | if(mOpt.lp>0) PrintOptions();
|
---|
| 1135 | FillGData();
|
---|
| 1136 | DecodeFunction(tokens[1]);
|
---|
| 1137 | DecodeParam(mSp,mSs,mSm,mSM,mSf);
|
---|
| 1138 | if (kw == "fit") {
|
---|
| 1139 | int rc = DoFit();
|
---|
| 1140 | if(rc>=0) FitFunRes();
|
---|
| 1141 | } else if (kw == "fitlin") {
|
---|
| 1142 | LinFit();
|
---|
| 1143 | } else if (kw == "fitw") {
|
---|
| 1144 | if(FWindFit!=NULL) {delete FWindFit; FWindFit=NULL;}
|
---|
| 1145 | FWindFit = new PIAFitterWind(mApp,this);
|
---|
| 1146 | FWindFit->Show();
|
---|
[361] | 1147 | }
|
---|
[379] | 1148 |
|
---|
| 1149 | return(0);
|
---|
[361] | 1150 | }
|
---|
| 1151 |
|
---|
[392] | 1152 | /* --Methode-- */
|
---|
| 1153 | void PIAFitter::IniFitP1ou2D(void)
|
---|
| 1154 | {
|
---|
| 1155 | if(mNPar==0) return;
|
---|
| 1156 | mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.;
|
---|
| 1157 | if(!mGData) return;
|
---|
| 1158 | double mean,sigma;
|
---|
| 1159 | int rc = mGData->GetMeanSigma(0,mean,sigma);
|
---|
| 1160 | if(rc<=0) return;
|
---|
| 1161 | mPar(0) = mean;
|
---|
| 1162 | return;
|
---|
| 1163 | }
|
---|
| 1164 |
|
---|
| 1165 | void PIAFitter::IniFitGhP1D(void)
|
---|
| 1166 | {
|
---|
| 1167 | if(mNPar==0) return;
|
---|
| 1168 | mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.;
|
---|
| 1169 | if(mNVar!=1 || mNPar<3) return;
|
---|
| 1170 | double h,v,x0,y0,sx,sy,f;
|
---|
| 1171 | int rc = IniFitGaus(*mGData,h,v,x0,y0,sx,sy,f);
|
---|
| 1172 | if(rc!=0) return;
|
---|
| 1173 | mPar(0)=h; mStep(0)=h/1000.;
|
---|
| 1174 | mPar(1)=x0; mStep(1)=sx/10.;
|
---|
| 1175 | mPar(2)=sx; mStep(2)=sx/10.; mMin(2)=0.; mMax(2)=20.*sx;
|
---|
| 1176 | if(mNPar>3) {mPar(3)=f; mStep(3)=f/1000.;} else mPar(0)=h+f;
|
---|
| 1177 | }
|
---|
| 1178 |
|
---|
| 1179 | void PIAFitter::IniFitGvP1D(void)
|
---|
| 1180 | {
|
---|
| 1181 | if(mNPar==0) return;
|
---|
| 1182 | mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.;
|
---|
| 1183 | if(mNVar!=1 || mNPar<3) return;
|
---|
| 1184 | double h,v,x0,y0,sx,sy,f;
|
---|
| 1185 | int rc = IniFitGaus(*mGData,h,v,x0,y0,sx,sy,f);
|
---|
| 1186 | if(rc!=0) return;
|
---|
| 1187 | mPar(0)=v; mStep(0)=v/1000.;
|
---|
| 1188 | mPar(1)=x0; mStep(1)=sx/10.;
|
---|
| 1189 | mPar(2)=sx; mStep(2)=sx/10.; mMin(2)=0.; mMax(2)=20.*sx;
|
---|
| 1190 | if(mNPar>3) {mPar(3)=f; mStep(3)=f/1000.;} else mPar(0)=v+mNData*f;
|
---|
| 1191 | }
|
---|
| 1192 |
|
---|
| 1193 | void PIAFitter::IniFitGv2D(void)
|
---|
| 1194 | {
|
---|
| 1195 | if(mNPar==0) return;
|
---|
| 1196 | mPar=0.; mStep=1.; mMin=1.; mMax=-1.; mFix=0.;
|
---|
| 1197 | if(mNVar!=2 || mNPar<6) return;
|
---|
| 1198 | double h,v,x0,y0,sx,sy,f;
|
---|
| 1199 | int rc = IniFitGaus(*mGData,h,v,x0,y0,sx,sy,f);
|
---|
| 1200 | if(rc!=0) return;
|
---|
| 1201 | mPar(0)=v; mStep(0)=v/1000.;
|
---|
| 1202 | mPar(1)=x0; mStep(1)=sx/10.;
|
---|
| 1203 | mPar(2)=y0; mStep(2)=sy/10.;
|
---|
| 1204 | mPar(3)=sx; mStep(3)=sx/10.; mMin(3)=0.; mMax(3)=20.*sx;
|
---|
| 1205 | mPar(4)=sy; mStep(4)=sy/10.; mMin(4)=0.; mMax(4)=20.*sy;
|
---|
| 1206 | mPar(5)=0.; mStep(5)=0.005; mMin(5)=-1.; mMax(5)=1.;
|
---|
| 1207 | if(mNPar>6) {mPar(6)=f; mStep(6)=f/1000.;} else mPar(0)=v+mNData*f;
|
---|
| 1208 | }
|
---|
| 1209 |
|
---|
| 1210 | int PIAFitter::IniFitGaus(GeneralFitData& g,double& h,double& v
|
---|
| 1211 | ,double& x0,double& y0,double& sx,double& sy,double& f)
|
---|
| 1212 | // Pour initialiser une gaussienne 1D ou 2D
|
---|
| 1213 | // return code =0 si OK
|
---|
| 1214 | {
|
---|
| 1215 | h=v=x0=y0=sx=sy=f=0.;
|
---|
| 1216 | if(!&g) return(-1);
|
---|
| 1217 | int nvar = g.NVar();
|
---|
| 1218 | int ndata = g.NData();
|
---|
| 1219 | if(nvar<1 || 2<nvar || ndata<=0) return(-2);
|
---|
| 1220 |
|
---|
| 1221 | // X et Y ordonnees croissant
|
---|
| 1222 | double *X=NULL, *Y=NULL;
|
---|
| 1223 | X = new double[ndata];
|
---|
| 1224 | if(nvar==2) Y = new double[ndata];
|
---|
| 1225 | {for(int i=0;i<ndata;i++) {X[i] = g.X(i); if(Y) Y[i] = g.Y(i);}}
|
---|
| 1226 | qsort(X,(size_t) ndata,sizeof(double),qSort_Dble);
|
---|
| 1227 | if(Y) qsort(Y,(size_t) ndata,sizeof(double),qSort_Dble);
|
---|
| 1228 |
|
---|
| 1229 | // determination des zones externes=[0,1/3] et [2/3,1]
|
---|
| 1230 | // et des zones internes=[1/3,2/3]
|
---|
| 1231 | int k1=ndata/3,k2=2*ndata/3;
|
---|
| 1232 | double xmin,xmax, ymin=-1.,ymax=1.;
|
---|
| 1233 | xmin = X[k1]; xmax = X[k2];
|
---|
| 1234 | if(Y) {ymin = Y[k1]; ymax = Y[k2];}
|
---|
| 1235 |
|
---|
| 1236 | // recherche des parametres
|
---|
| 1237 | double nb=0, nc=0;
|
---|
| 1238 | {for(int i=0;i<ndata;i++) {
|
---|
| 1239 | double val,x,y=0.;
|
---|
| 1240 | x = g.X(i); if(Y) y = g.Y(i); val = g.Val(i);
|
---|
| 1241 | if(xmin<x && x<xmax && ymin<y && y<ymax) { // c'est le centre
|
---|
| 1242 | if(nc==0 || val>h) {h=val; x0=x; y0=y;}
|
---|
| 1243 | v += val; nc++;
|
---|
| 1244 | } else {f += val; nb++;} // c'est le bord
|
---|
| 1245 |
|
---|
| 1246 | }}
|
---|
| 1247 | if(nb==0 || nc==0) {delete [] X; if(Y) delete [] Y; return(-3);}
|
---|
| 1248 |
|
---|
| 1249 | // Calcul des parametres
|
---|
| 1250 | f /= (double) nb; h -= f; v -= f*nc;
|
---|
| 1251 | sx = (xmax-xmin)/2.; if(Y) sy = (ymax-ymin)/2.;
|
---|
| 1252 |
|
---|
| 1253 | delete [] X; if(Y) delete [] Y;
|
---|
| 1254 | return(0);
|
---|
| 1255 | }
|
---|
| 1256 |
|
---|
| 1257 |
|
---|
[379] | 1258 | ////////////////////////////////////////////////////////////////////
|
---|
| 1259 | ////---------- Classe de fenetre de fit interactive ------------////
|
---|
| 1260 | ////////////////////////////////////////////////////////////////////
|
---|
[361] | 1261 |
|
---|
| 1262 | /* --Methode-- */
|
---|
| 1263 | PIAFitterWind::PIAFitterWind(PIStdImgApp* par, PIAFitter* fiter)
|
---|
[385] | 1264 | : PIWindow((PIMsgHandler*)par, "PIAFitter", PIWK_normal, 240, 240, 150, 150)
|
---|
| 1265 | , mDap(par), mFitter(fiter), ReFillGData(false)
|
---|
| 1266 | , saveI1(0), saveI2(0), saveJ1(0), saveJ2(0), ErrValue(1.)
|
---|
[361] | 1267 | {
|
---|
[495] | 1268 | #ifdef SANS_EVOLPLANCK
|
---|
[386] | 1269 | COMPATIBLE_ASSERT(mFitter);
|
---|
[495] | 1270 | #else
|
---|
| 1271 | ASSERT(mFitter);
|
---|
| 1272 | #endif
|
---|
| 1273 |
|
---|
[379] | 1274 | int npar = mFitter->mNPar;
|
---|
[361] | 1275 |
|
---|
[379] | 1276 | // Alloc de la taille
|
---|
[390] | 1277 | nlab = 13+npar; lab = new PILabel*[nlab]; {for(int i=0;i<nlab;i++) lab[i]=NULL;}
|
---|
[385] | 1278 | ntxt = 10+4*npar; txt = new PIText*[ntxt]; {for(int i=0;i<ntxt;i++) txt[i]=NULL;}
|
---|
[390] | 1279 | nbut = 6; but = new PIButton*[nbut]; {for(int i=0;i<nbut;i++) but[i]=NULL;}
|
---|
[385] | 1280 | nckb = 2+npar; ckb = new PICheckBox*[nckb]; {for(int i=0;i<nckb;i++) ckb[i]=NULL;}
|
---|
| 1281 | npom = 3; pom = new PIOptMenu*[npom]; {for(int i=0;i<npom;i++) pom[i]=NULL;}
|
---|
[379] | 1282 |
|
---|
| 1283 | // On definit la taille a partir de la taille par defaut des composantes
|
---|
| 1284 | // bsx,bsy = environ 6 lettres
|
---|
| 1285 | int bsx,bsy;
|
---|
[361] | 1286 | par->PrefCompSz(bsx, bsy);
|
---|
[379] | 1287 | int spx = (bsx>=10) ? bsx/10 : 1; // intervalle entre lettres X
|
---|
| 1288 | int spy = (bsy>=6) ? bsy/6 : 1; // intervalle entre lettres Y
|
---|
[361] | 1289 |
|
---|
[379] | 1290 | int wszx = (5*bsx+5*spx)+spx;
|
---|
[386] | 1291 | int wszy = 8*(bsy+spy)+npar*(bsy+spy)+2*spy;
|
---|
[361] | 1292 | SetSize(wszx, wszy);
|
---|
[379] | 1293 | int cpx,cpy;
|
---|
[361] | 1294 |
|
---|
[381] | 1295 | // new ligne
|
---|
[385] | 1296 | cpx = spx; cpy = spy;
|
---|
[390] | 1297 | string dum = "Object: "+mFitter->mNObj+" , Fun: ";
|
---|
[392] | 1298 | if(mFitter->mFunc) dum+=mFitter->mNameFitFunc; else dum+=mFitter->mFName;
|
---|
[386] | 1299 | lab[0] = new PILabel(this,dum.c_str(),4*bsx,bsy,cpx,cpy);
|
---|
[385] | 1300 | lab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1301 |
|
---|
| 1302 | // new ligne
|
---|
| 1303 | cpx = spx; cpy += bsy+spy;
|
---|
[379] | 1304 | but[0] = new PIButton(this,"Fr.Last",111,bsx,bsy,cpx,cpy);
|
---|
| 1305 | but[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1306 | cpx += bsx+spx;
|
---|
| 1307 | but[1] = new PIButton(this,"Default",222,bsx,bsy,cpx,cpy);
|
---|
| 1308 | but[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1309 | cpx += bsx+spx;
|
---|
[379] | 1310 | ckb[0] = new PICheckBox(this,"Gen Fun",1001,bsx,bsy,cpx,cpy);
|
---|
| 1311 | ckb[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1312 | cpx += bsx+2*spx;
|
---|
| 1313 | ckb[1] = new PICheckBox(this,"Res",1002,bsx,bsy,cpx,cpy);
|
---|
| 1314 | ckb[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[361] | 1315 |
|
---|
[381] | 1316 | // new ligne
|
---|
[385] | 1317 | cpx = spx; cpy += bsy+spy;
|
---|
| 1318 | pom[0] = new PIOptMenu(this,"Err def",1.5*bsx,bsy,cpx,cpy);
|
---|
| 1319 | pom[0]->AppendItem("Err def",2101);
|
---|
| 1320 | pom[0]->AppendItem("Err cste",2102);
|
---|
| 1321 | pom[0]->AppendItem("Err sqrt",2103);
|
---|
[386] | 1322 | pom[0]->SetValue(2101);
|
---|
[381] | 1323 | pom[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1324 | cpx += int(1.5*bsx+spx);
|
---|
[379] | 1325 | txt[0] = new PIText(this,"",bsx,bsy,cpx,cpy);
|
---|
| 1326 | txt[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1327 | cpx += bsx+spx;
|
---|
| 1328 | lab[1] = new PILabel(this,"Prt,dbg",bsx,bsy,cpx,cpy);
|
---|
| 1329 | lab[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1330 | cpx += bsx+spx;
|
---|
[379] | 1331 | txt[1] = new PIText(this,"",bsx,bsy,cpx,cpy);
|
---|
| 1332 | txt[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[361] | 1333 |
|
---|
[381] | 1334 | // new ligne
|
---|
[385] | 1335 | cpx = spx; cpy += bsy+spy;
|
---|
| 1336 | lab[2] = new PILabel(this,"Stop Xi2",1.25*bsx,bsy,cpx,cpy);
|
---|
[381] | 1337 | lab[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1338 | cpx += int(1.25*bsx+spx);
|
---|
[379] | 1339 | txt[2] = new PIText(this,"",bsx,bsy,cpx,cpy);
|
---|
| 1340 | txt[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1341 | cpx += bsx+spx;
|
---|
| 1342 | lab[3] = new PILabel(this,"Iter",bsx, bsy, cpx, cpy);
|
---|
[381] | 1343 | lab[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1344 | cpx += bsx+spx;
|
---|
[379] | 1345 | txt[3] = new PIText(this,"",bsx,bsy,cpx,cpy);
|
---|
| 1346 | txt[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[361] | 1347 |
|
---|
[381] | 1348 | // new ligne
|
---|
[385] | 1349 | cpx = spx; cpy += bsy+spy;
|
---|
| 1350 | lab[4] = new PILabel(this,"Range X",bsx,bsy,cpx,cpy);
|
---|
[381] | 1351 | lab[4]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1352 | cpx += bsx+spx;
|
---|
| 1353 | txt[4] = new PIText(this,"",0.75*bsx,bsy,cpx,cpy);
|
---|
[379] | 1354 | txt[4]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1355 | cpx += int(0.75*bsx+spx);
|
---|
| 1356 | txt[5] = new PIText(this,"",0.75*bsx,bsy,cpx,cpy);
|
---|
| 1357 | txt[5]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1358 | cpx += int(0.75*bsx+spx);
|
---|
| 1359 | lab[5] = new PILabel(this,"Y",bsx/2,bsy,cpx,cpy);
|
---|
[381] | 1360 | lab[5]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1361 | cpx += int(bsx/2.+spx);
|
---|
| 1362 | txt[6] = new PIText(this,"",0.75*bsx,bsy,cpx,cpy);
|
---|
[379] | 1363 | txt[6]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1364 | cpx += int(0.75*bsx+spx);
|
---|
| 1365 | txt[7] = new PIText(this,"",0.75*bsx,bsy,cpx,cpy);
|
---|
[379] | 1366 | txt[7]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[361] | 1367 |
|
---|
[381] | 1368 | // new ligne
|
---|
[385] | 1369 | cpx = spx; cpy += bsy+spy;
|
---|
| 1370 | lab[6] = new PILabel(this,"Cent",bsx/2,bsy,cpx,cpy);
|
---|
| 1371 | lab[6]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1372 | cpx += int(bsx/2.+spx);
|
---|
| 1373 | pom[1] = new PIOptMenu(this,"X.No",1.25*bsx,bsy,cpx,cpy);
|
---|
| 1374 | pom[1]->AppendItem("X.No",2001);
|
---|
| 1375 | pom[1]->AppendItem("X.Value",2002);
|
---|
| 1376 | pom[1]->AppendItem("X.Auto",2003);
|
---|
[386] | 1377 | pom[1]->SetValue(2001);
|
---|
[385] | 1378 | pom[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1379 | cpx += int(1.25*bsx+spx);
|
---|
| 1380 | txt[8] = new PIText(this,"",bsx,bsy,cpx,cpy);
|
---|
[379] | 1381 | txt[8]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1382 | cpx += bsx+spx;
|
---|
| 1383 | pom[2] = new PIOptMenu(this,"Y.No",1.25*bsx,bsy,cpx,cpy);
|
---|
| 1384 | pom[2]->AppendItem("Y.No",2011);
|
---|
| 1385 | pom[2]->AppendItem("Y.Value",2012);
|
---|
| 1386 | pom[2]->AppendItem("Y.Auto",2013);
|
---|
[386] | 1387 | pom[2]->SetValue(2011);
|
---|
[385] | 1388 | pom[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1389 | cpx += int(1.25*bsx+spx);
|
---|
| 1390 | txt[9] = new PIText(this,"",bsx,bsy,cpx,cpy);
|
---|
[379] | 1391 | txt[9]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[368] | 1392 |
|
---|
[381] | 1393 | // new ligne
|
---|
[385] | 1394 | cpx = spx; cpy += bsy+spy;
|
---|
[379] | 1395 | but[2] = new PIButton(this, "Dismiss",777,bsx,bsy,cpx,cpy);
|
---|
| 1396 | but[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1397 | cpx += bsx+spx;
|
---|
[385] | 1398 | but[3] = new PIButton(this, "Check",666,bsx,bsy,cpx,cpy);
|
---|
[379] | 1399 | but[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1400 | cpx += bsx+spx;
|
---|
| 1401 | but[4] = new PIButton(this, "Fit",333,bsx,bsy,cpx,cpy);
|
---|
| 1402 | but[4]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1403 | cpx += bsx+spx;
|
---|
[390] | 1404 | but[5] = new PIButton(this, "Ini Auto",444,bsx,bsy,cpx,cpy);
|
---|
| 1405 | but[5]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1406 |
|
---|
| 1407 | // new ligne
|
---|
| 1408 | cpx = spx; cpy += bsy+spy;
|
---|
[390] | 1409 | lab[7] = new PILabel(this,"Par",bsx/2,bsy,cpx,cpy);
|
---|
| 1410 | lab[7]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1411 | cpx += int(bsx/2.+spx);
|
---|
| 1412 | lab[8] = new PILabel(this,"Fx",bsx/3,bsy,cpx,cpy);
|
---|
[385] | 1413 | lab[8]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[390] | 1414 | cpx += int(bsx/3.+spx);
|
---|
| 1415 | lab[9] = new PILabel(this,"Init",bsx,bsy,cpx,cpy);
|
---|
[385] | 1416 | lab[9]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[390] | 1417 | cpx += bsx+spx;
|
---|
| 1418 | lab[10] = new PILabel(this,"Step",bsx,bsy,cpx,cpy);
|
---|
[381] | 1419 | lab[10]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1420 | cpx += bsx+spx;
|
---|
[390] | 1421 | lab[11] = new PILabel(this,"Min",bsx,bsy,cpx,cpy);
|
---|
[381] | 1422 | lab[11]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1423 | cpx += bsx+spx;
|
---|
[390] | 1424 | lab[12] = new PILabel(this,"Max",bsx,bsy,cpx,cpy);
|
---|
[381] | 1425 | lab[12]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1426 |
|
---|
| 1427 | // new lines: Parametres (npar lignes)
|
---|
[379] | 1428 | if(npar>0) {
|
---|
| 1429 | for(int i=0;i<npar;i++) {
|
---|
[385] | 1430 | cpx = spx; cpy += bsy+spy;
|
---|
[379] | 1431 | char str[8]; sprintf(str,"P%d",i);
|
---|
[390] | 1432 | lab[13+i] = new PILabel(this,str,bsx/2,bsy,cpx,cpy);
|
---|
| 1433 | lab[13+i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
[385] | 1434 | cpx += int(bsx/2.+spx);
|
---|
[379] | 1435 | // Attention pas de message entre 1500 et 2000 (permet 500 parametres!)
|
---|
[390] | 1436 | ckb[2+i] = new PICheckBox(this,"",1500+i,bsx/3,bsy,cpx,cpy+spy);
|
---|
[385] | 1437 | ckb[2+i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1438 | cpx+=int(bsx/3.+spx);
|
---|
[379] | 1439 | for(int j=0;j<4;j++) {
|
---|
[385] | 1440 | txt[10+4*i+j] = new PIText(this,"",bsx,bsy,cpx,cpy);
|
---|
| 1441 | txt[10+4*i+j]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 1442 | cpx += bsx+spx;
|
---|
[379] | 1443 | }
|
---|
| 1444 | }
|
---|
[361] | 1445 | }
|
---|
[368] | 1446 |
|
---|
[379] | 1447 | return;
|
---|
| 1448 | }
|
---|
| 1449 |
|
---|
[361] | 1450 | /* --Methode-- */
|
---|
| 1451 | PIAFitterWind::~PIAFitterWind()
|
---|
| 1452 | {
|
---|
[368] | 1453 | int i;
|
---|
[379] | 1454 | for(i=0;i<nlab;i++) if(lab[i]) {delete lab[i]; lab[i]=NULL;}
|
---|
| 1455 | for(i=0;i<ntxt;i++) if(txt[i]) {delete txt[i]; txt[i]=NULL;}
|
---|
| 1456 | for(i=0;i<nbut;i++) if(but[i]) {delete but[i]; but[i]=NULL;}
|
---|
| 1457 | for(i=0;i<nckb;i++) if(ckb[i]) {delete ckb[i]; ckb[i]=NULL;}
|
---|
[381] | 1458 | for(i=0;i<npom;i++) if(pom[i]) {delete pom[i]; pom[i]=NULL;}
|
---|
[379] | 1459 | if(lab) {delete lab; lab=NULL; nlab=0;}
|
---|
| 1460 | if(txt) {delete txt; txt=NULL; ntxt=0;}
|
---|
| 1461 | if(but) {delete but; but=NULL; nbut=0;}
|
---|
| 1462 | if(ckb) {delete ckb; ckb=NULL; nckb=0;}
|
---|
[381] | 1463 | if(pom) {delete pom; pom=NULL; npom=0;}
|
---|
[361] | 1464 | }
|
---|
[368] | 1465 |
|
---|
[361] | 1466 | /* --Methode-- */
|
---|
[379] | 1467 | void PIAFitterWind::Show()
|
---|
[368] | 1468 | {
|
---|
[379] | 1469 | //mDap->SetBlocked();
|
---|
| 1470 | SetState();
|
---|
| 1471 | PIWindow::Show();
|
---|
| 1472 | return;
|
---|
| 1473 | }
|
---|
[368] | 1474 |
|
---|
[379] | 1475 | /* --Methode-- */
|
---|
| 1476 | void PIAFitterWind::SetState(void)
|
---|
| 1477 | // Ecriture et positionnement des ckb et txt
|
---|
| 1478 | {
|
---|
| 1479 | int npar = mFitter->mNPar;
|
---|
[368] | 1480 |
|
---|
[379] | 1481 | // Les check-boxes
|
---|
| 1482 | ckb[0]->SetState(mFitter->mOpt.okfun);
|
---|
| 1483 | ckb[1]->SetState(mFitter->mOpt.okres);
|
---|
| 1484 | if(npar>0)
|
---|
[385] | 1485 | for(int i=0;i<npar;i++) ckb[2+i]->SetState((mFitter->mFix(i)>=1.)?true:false);
|
---|
[368] | 1486 |
|
---|
[379] | 1487 | // Les champs textes
|
---|
| 1488 | char str[128]; string dum;
|
---|
[385] | 1489 | sprintf(str,"%f",ErrValue); dum=str; txt[0]->SetText(dum);
|
---|
| 1490 | sprintf(str,"%d,%d",mFitter->mOpt.lp,mFitter->mOpt.lpg); dum=str; txt[1]->SetText(dum);
|
---|
| 1491 | sprintf(str,"%f",mFitter->mOpt.stc2); dum=str; txt[2]->SetText(dum);
|
---|
| 1492 | sprintf(str,"%d",mFitter->mOpt.nstep); dum=str; txt[3]->SetText(dum);
|
---|
| 1493 | sprintf(str,"%d",mFitter->mOpt.i1); dum=str; txt[4]->SetText(dum);
|
---|
| 1494 | sprintf(str,"%d",mFitter->mOpt.i2); dum=str; txt[5]->SetText(dum);
|
---|
| 1495 | sprintf(str,"%d",mFitter->mOpt.j1); dum=str; txt[6]->SetText(dum);
|
---|
| 1496 | sprintf(str,"%d",mFitter->mOpt.j2); dum=str; txt[7]->SetText(dum);
|
---|
| 1497 | sprintf(str,"%f",mFitter->mOpt.xc); dum=str; txt[8]->SetText(dum);
|
---|
| 1498 | sprintf(str,"%f",mFitter->mOpt.yc); dum=str; txt[9]->SetText(dum);
|
---|
[379] | 1499 | if(npar>0) {
|
---|
| 1500 | for(int i=0;i<npar;i++) {
|
---|
[385] | 1501 | sprintf(str,"%f",mFitter->mPar(i)); dum=str; txt[10+4*i+0]->SetText(dum);
|
---|
| 1502 | sprintf(str,"%f",mFitter->mStep(i)); dum=str; txt[10+4*i+1]->SetText(dum);
|
---|
| 1503 | sprintf(str,"%f",mFitter->mMin(i)); dum=str; txt[10+4*i+2]->SetText(dum);
|
---|
| 1504 | sprintf(str,"%f",mFitter->mMax(i)); dum=str; txt[10+4*i+3]->SetText(dum);
|
---|
[368] | 1505 | }
|
---|
| 1506 | }
|
---|
| 1507 |
|
---|
[379] | 1508 | return;
|
---|
[361] | 1509 | }
|
---|
| 1510 |
|
---|
| 1511 | /* --Methode-- */
|
---|
| 1512 | void PIAFitterWind::Process(PIMessage msg, PIMsgHandler* sender, void* data)
|
---|
| 1513 | {
|
---|
[381] | 1514 | int lp = (mFitter->mOpt.lp>2)?1:0;;
|
---|
[379] | 1515 | int npar = mFitter->mNPar;
|
---|
[361] | 1516 |
|
---|
[385] | 1517 | // Decodage des messages, init et dismiss
|
---|
| 1518 | msg = UserMsg(msg);
|
---|
| 1519 | if(msg ==777) {
|
---|
| 1520 | if(lp) cout<<"Dismiss"<<endl;
|
---|
| 1521 | //mDap->SetReady();
|
---|
| 1522 | Hide();
|
---|
| 1523 | return;
|
---|
| 1524 | }
|
---|
| 1525 |
|
---|
[379] | 1526 | // L'objet existe t-il encore?
|
---|
| 1527 | NamedObjMgr omg;
|
---|
| 1528 | if(omg.GetObj(mFitter->mNObj) == NULL) {
|
---|
[381] | 1529 | cout<<"PIAFitterWind::Process Error , Pas d'objet de nom "
|
---|
| 1530 | <<mFitter->mNObj<<endl;
|
---|
[379] | 1531 | mFitter->ResetDPointer(); return;
|
---|
| 1532 | }
|
---|
[368] | 1533 |
|
---|
[379] | 1534 | // On recupere les champs textes
|
---|
| 1535 | string dum; char str[128];
|
---|
[385] | 1536 | // Attention gestion du type d'erreur
|
---|
[379] | 1537 | dum=txt[0]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1538 | sscanf(str,"%lf",&ErrValue); if(ErrValue<=0.) ErrValue=1.;
|
---|
| 1539 | if(mFitter->mOpt.err_e>0. ) mFitter->mOpt.err_e = ErrValue;
|
---|
| 1540 | if(mFitter->mOpt.err_E>0. ) mFitter->mOpt.err_E = ErrValue;
|
---|
[379] | 1541 | dum=txt[1]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1542 | sscanf(str,"%d,%d",&(mFitter->mOpt.lp),&(mFitter->mOpt.lpg));
|
---|
[379] | 1543 | dum=txt[2]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1544 | sscanf(str,"%lf",&(mFitter->mOpt.stc2));
|
---|
[379] | 1545 | dum=txt[3]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1546 | sscanf(str,"%d",&(mFitter->mOpt.nstep));
|
---|
| 1547 | // Attention si les valeurs de mOpt.i1/.i2/.j1/.j2 ont ete changees
|
---|
[379] | 1548 | dum=txt[4]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1549 | sscanf(str,"%d",&(mFitter->mOpt.i1));
|
---|
[379] | 1550 | dum=txt[5]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1551 | sscanf(str,"%d",&(mFitter->mOpt.i2));
|
---|
[379] | 1552 | dum=txt[6]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1553 | sscanf(str,"%d",&(mFitter->mOpt.j1));
|
---|
[379] | 1554 | dum=txt[7]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1555 | sscanf(str,"%d",&(mFitter->mOpt.j2));
|
---|
| 1556 | if(saveI1!=mFitter->mOpt.i1 || saveI2!=mFitter->mOpt.i2 ||
|
---|
| 1557 | saveJ1!=mFitter->mOpt.j1 || saveJ2!=mFitter->mOpt.j2 ) {
|
---|
| 1558 | if(lp)
|
---|
| 1559 | cout<<"Range changed: I("<<saveI1<<","<<saveI2
|
---|
| 1560 | <<") -> I("<<mFitter->mOpt.i1<<","<<mFitter->mOpt.i2
|
---|
| 1561 | <<") ou J("<<saveJ1<<","<<saveJ2
|
---|
| 1562 | <<") -> J("<<mFitter->mOpt.j1<<","<<mFitter->mOpt.j2
|
---|
| 1563 | <<")"<<endl;
|
---|
| 1564 | ReFillGData = true;
|
---|
| 1565 | saveI1=mFitter->mOpt.i1; saveI2=mFitter->mOpt.i2;
|
---|
| 1566 | saveJ1=mFitter->mOpt.j1; saveJ2=mFitter->mOpt.j2;
|
---|
| 1567 | }
|
---|
[379] | 1568 | dum=txt[8]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1569 | sscanf(str,"%lf",&(mFitter->mOpt.xc));
|
---|
[379] | 1570 | dum=txt[9]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[385] | 1571 | sscanf(str,"%lf",&(mFitter->mOpt.yc));
|
---|
[381] | 1572 |
|
---|
[379] | 1573 | if(npar>0) {
|
---|
| 1574 | for(int i=0;i<npar;i++) {
|
---|
[385] | 1575 | dum=txt[10+4*i+0]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[379] | 1576 | sscanf(str,"%lf",&(mFitter->mPar(i)));
|
---|
[385] | 1577 | dum=txt[10+4*i+1]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[379] | 1578 | sscanf(str,"%lf",&(mFitter->mStep(i)));
|
---|
[385] | 1579 | dum=txt[10+4*i+2]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[379] | 1580 | sscanf(str,"%lf",&(mFitter->mMin(i)));
|
---|
[385] | 1581 | dum=txt[10+4*i+3]->GetText(); strcpy(str,dum.c_str()); strip(str,'B',' ');
|
---|
[379] | 1582 | sscanf(str,"%lf",&(mFitter->mMax(i)));
|
---|
[368] | 1583 | }
|
---|
[379] | 1584 | }
|
---|
[361] | 1585 |
|
---|
[385] | 1586 | // Decodage des messages, suite
|
---|
| 1587 | if(msg ==666) {
|
---|
| 1588 | if(lp) cout<<"Check"<<endl;
|
---|
[381] | 1589 | mFitter->CheckOptions();
|
---|
[379] | 1590 | if(ReFillGData) mFitter->FillGData();
|
---|
| 1591 | ReFillGData = false;
|
---|
[386] | 1592 | if(mFitter->mFit) mFitter->mFit->PrintStatus();
|
---|
[379] | 1593 | }
|
---|
[381] | 1594 | else if(msg ==111) {
|
---|
[379] | 1595 | if(lp) cout<<"Update from last"<<endl;
|
---|
| 1596 | mFitter->ResetOptions();
|
---|
| 1597 | mFitter->mOpt = mFitter->mOptSave;
|
---|
| 1598 | mFitter->ReSetParam();
|
---|
| 1599 | mFitter->InitParFromLastFit();
|
---|
| 1600 | ReFillGData = true;
|
---|
| 1601 | }
|
---|
[381] | 1602 | else if(msg ==222) {
|
---|
[379] | 1603 | if(lp) cout<<"Default options/par"<<endl;
|
---|
| 1604 | mFitter->ResetOptions();
|
---|
| 1605 | mFitter->ReSetParam();
|
---|
| 1606 | ReFillGData = true;
|
---|
| 1607 | }
|
---|
[381] | 1608 | else if(msg ==333) {
|
---|
[379] | 1609 | if(lp) cout<<"Do the fit"<<endl;
|
---|
[381] | 1610 | mFitter->CheckOptions();
|
---|
[379] | 1611 | if(ReFillGData) mFitter->FillGData();
|
---|
| 1612 | ReFillGData = false;
|
---|
| 1613 | int rc = mFitter->DoFit();
|
---|
| 1614 | if(rc>=0) mFitter->FitFunRes();
|
---|
| 1615 | }
|
---|
[390] | 1616 | else if(msg ==444) {
|
---|
| 1617 | if(lp) cout<<"Automatic initialisation"<<endl;
|
---|
| 1618 | mFitter->AutoIniFit();
|
---|
| 1619 | }
|
---|
[381] | 1620 | else if(msg==1001) {
|
---|
[379] | 1621 | if(ckb[0]->GetState()) {
|
---|
| 1622 | if(lp) cout<<"Gen fitted function"<<endl;
|
---|
| 1623 | mFitter->mOpt.okfun = true;
|
---|
| 1624 | } else if(!ckb[0]->GetState()) {
|
---|
| 1625 | if(lp) cout<<"No Gen fitted function"<<endl;
|
---|
| 1626 | mFitter->mOpt.okfun = false;
|
---|
[361] | 1627 | }
|
---|
[379] | 1628 | }
|
---|
[381] | 1629 | else if(msg==1002) {
|
---|
[379] | 1630 | if(ckb[1]->GetState()) {
|
---|
| 1631 | if(lp) cout<<"Gen fitted residus"<<endl;
|
---|
| 1632 | mFitter->mOpt.okres = true;
|
---|
| 1633 | } else if(!ckb[1]->GetState()) {
|
---|
| 1634 | if(lp) cout<<"No Gen fitted residus"<<endl;
|
---|
| 1635 | mFitter->mOpt.okres = false;
|
---|
| 1636 | }
|
---|
| 1637 | }
|
---|
[385] | 1638 | else if(2101<=msg && msg<=2103) {
|
---|
| 1639 | mFitter->mOpt.err_e = mFitter->mOpt.err_E = -1.;
|
---|
| 1640 | if(msg==2102) mFitter->mOpt.err_e = ErrValue;
|
---|
| 1641 | else if(msg==2103) mFitter->mOpt.err_E = ErrValue;
|
---|
| 1642 | if(lp) cout<<"Err_cste="<<mFitter->mOpt.err_e
|
---|
| 1643 | <<" Err_sqrt="<<mFitter->mOpt.err_E
|
---|
| 1644 | <<" ErrValue="<<ErrValue<<endl;
|
---|
| 1645 | ReFillGData = true;
|
---|
| 1646 | }
|
---|
[381] | 1647 | else if(2001<=msg && msg<=2003) {
|
---|
| 1648 | mFitter->mOpt.polcx = msg-2001;
|
---|
| 1649 | if(lp) cout<<"Centrage X polcx="<<mFitter->mOpt.polcx
|
---|
| 1650 | <<" xc="<<mFitter->mOpt.xc<<endl;
|
---|
[379] | 1651 | ReFillGData = true;
|
---|
| 1652 | }
|
---|
[381] | 1653 | else if(2011<=msg && msg<=2013) {
|
---|
[392] | 1654 | mFitter->mOpt.polcy = msg-2011;
|
---|
[381] | 1655 | if(lp) cout<<"Centrage Y polcy="<<mFitter->mOpt.polcy
|
---|
| 1656 | <<" yc="<<mFitter->mOpt.yc<<endl;
|
---|
[379] | 1657 | ReFillGData = true;
|
---|
| 1658 | }
|
---|
[381] | 1659 | else if(msg>=1500 && msg<2000) {
|
---|
[379] | 1660 | int ip = msg-1500;
|
---|
[385] | 1661 | if(ckb[2+ip]->GetState()) {
|
---|
[379] | 1662 | if(lp) cout<<"Fix Param "<<ip<<endl;
|
---|
| 1663 | mFitter->mFix(ip) = 1.001;
|
---|
[385] | 1664 | } else if(!ckb[2+ip]->GetState()) {
|
---|
[379] | 1665 | if(lp) cout<<"Not Fix Param "<<ip<<endl;
|
---|
| 1666 | mFitter->mFix(ip) = 0.;
|
---|
| 1667 | }
|
---|
| 1668 | }
|
---|
[361] | 1669 |
|
---|
[379] | 1670 | mFitter->CheckOptions();
|
---|
| 1671 | SetState();
|
---|
| 1672 | if(mFitter->mOpt.lp>1) mFitter->PrintOptions();
|
---|
| 1673 |
|
---|
| 1674 | return;
|
---|
[361] | 1675 | }
|
---|