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