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