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