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