[307] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // C.Magneville 04/99
|
---|
[220] | 3 | #ifndef GENERALDATA_SEEN
|
---|
| 4 | #define GENERALDATA_SEEN
|
---|
| 5 |
|
---|
[490] | 6 | #include "objfio.h"
|
---|
| 7 | #include <iostream.h>
|
---|
[244] | 8 | #include "pexceptions.h"
|
---|
[220] | 9 | #include "ppersist.h"
|
---|
[490] | 10 | #include "ntupintf.h"
|
---|
[220] | 11 | #include "poly.h"
|
---|
| 12 |
|
---|
[552] | 13 | namespace SOPHYA {
|
---|
[307] | 14 |
|
---|
[220] | 15 | class GeneralFit;
|
---|
| 16 |
|
---|
| 17 | //================================================================
|
---|
| 18 | // GENERALFITDATA
|
---|
| 19 | //================================================================
|
---|
| 20 |
|
---|
[914] | 21 | /*!
|
---|
| 22 | Classe de stoquage de donnees a plusieurs variables avec erreur
|
---|
| 23 | sur l'ordonnee et sur les abscisses (options) :
|
---|
| 24 |
|
---|
| 25 | \f$ {x0(i),Ex0(i), x1(i),Ex1(i), x2(i),Ex2(i) ... ; Y(i),EY(i)} \f$
|
---|
| 26 | \verbatim
|
---|
| 27 | Pour memoire, structure du rangement (n=mNVar):
|
---|
| 28 | - Valeur des abscisses mXP (idem pour mErrXP):
|
---|
| 29 | x0,x1,x2,...,xn x0,x1,x2,...,xn .... x0,x1,x2,....,xn
|
---|
| 30 | | 1er point | | 2sd point | .... | point mNData |
|
---|
| 31 | Donc abscisse J=[0,mNVar[ du point numero I=[0,mNData[: mXP[I*mNVar+J]
|
---|
| 32 | - Valeur de l'ordonnee mF (idem pour mErr et mOK):
|
---|
| 33 | f f f
|
---|
| 34 | | 1er point | | 2sd point | .... | point mNData |
|
---|
| 35 | Donc point numero I [0,mNData[ : mF[i]
|
---|
| 36 | \endverbatim
|
---|
| 37 | */
|
---|
| 38 |
|
---|
[490] | 39 | class GeneralFitData : public AnyDataObj , public NTupleInterface {
|
---|
[307] | 40 | friend class GeneralFit;
|
---|
[490] | 41 | friend class ObjFileIO<GeneralFitData>;
|
---|
[220] | 42 | public:
|
---|
[914] | 43 | //! Valeurs par defaut pour l'utilisation des erreurs
|
---|
| 44 | enum {
|
---|
| 45 | Def_ErrF = 1, //!< erreurs sur F par defaut
|
---|
| 46 | Def_ErrX = 0 //!< pas d'erreurs sur les variables X,Y,... par defaut
|
---|
| 47 | };
|
---|
[220] | 48 |
|
---|
| 49 | GeneralFitData(unsigned int nVar, unsigned int nDataAlloc, uint_2 errx=0);
|
---|
[307] | 50 | GeneralFitData(const GeneralFitData& data, bool clean=false);
|
---|
[220] | 51 | GeneralFitData();
|
---|
| 52 | virtual ~GeneralFitData();
|
---|
| 53 |
|
---|
| 54 | void Alloc(unsigned int nVar, unsigned int nDataAlloc, int_2 errx=-1);
|
---|
| 55 | void SetDataPtr(int ptr = 0);
|
---|
| 56 |
|
---|
| 57 | void KillData(int i);
|
---|
| 58 | void KillData(int i1,int i2);
|
---|
| 59 |
|
---|
| 60 | void ValidData(int i);
|
---|
| 61 | void ValidData(int i1,int i2);
|
---|
| 62 | void ValidData();
|
---|
| 63 |
|
---|
| 64 | void RedefineData1(int i,double x,double f,double err=Def_ErrF,double errx=Def_ErrX);
|
---|
| 65 | void RedefineData2(int i,double x,double y,double f,double err=Def_ErrF
|
---|
| 66 | ,double errx=Def_ErrX,double erry=Def_ErrX);
|
---|
| 67 | void RedefineData(int i,double* xp,double f,double err=Def_ErrF,double* errxp=NULL);
|
---|
| 68 |
|
---|
| 69 | void AddData1(double x, double f, double err=Def_ErrF,double errx=Def_ErrX);
|
---|
| 70 | void AddData2(double x, double y, double f, double err=Def_ErrF
|
---|
| 71 | ,double errx=Def_ErrX,double erry=Def_ErrX);
|
---|
| 72 | void AddData(double* xp, double f, double err=Def_ErrF,double* errxp=NULL);
|
---|
| 73 | void AddData(float* xp, float f, float err=Def_ErrF,float* errxp=NULL);
|
---|
| 74 |
|
---|
| 75 | void SetData1(int nData,double* x,double* f,double *err=NULL,double *errx=NULL);
|
---|
| 76 | void SetData1(int nData,float* x,float* f,float* err=NULL,float *errx=NULL);
|
---|
| 77 | void SetData2(int nData,double* x,double* y,double* f,double *err=NULL
|
---|
| 78 | ,double *errx=NULL,double *erry=NULL);
|
---|
| 79 | void SetData2(int nData,float* x,float* y,float* f,float* err=NULL
|
---|
| 80 | ,float *errx=NULL,float *erry=NULL);
|
---|
| 81 | void SetData(int nData,double** xp,double *f,double *err=NULL,double** errxp=NULL);
|
---|
| 82 | void SetData(int nData,float** xp,float* f,float* err=NULL,float** errxp=NULL);
|
---|
| 83 |
|
---|
| 84 | void PrintStatus();
|
---|
| 85 | void PrintData(int i);
|
---|
| 86 | void PrintData(int i1,int i2);
|
---|
| 87 | void PrintData();
|
---|
[490] | 88 | void Show(ostream& os) const;
|
---|
| 89 | inline void Show() const {Show(cout);}
|
---|
[220] | 90 |
|
---|
[914] | 91 | //! Retourne la place restante dans la structure (nombre de donnees que l'on peut encore stoquer).
|
---|
[220] | 92 | inline int GetSpaceFree() const { return mNDataAlloc - mNData; }
|
---|
[914] | 93 | //! Retourne le nombre de variables Xi
|
---|
[220] | 94 | inline int NVar() const {return mNVar;}
|
---|
[914] | 95 | //! Retourne le nombre de donnees
|
---|
[220] | 96 | inline int NData() const {return mNData;}
|
---|
[914] | 97 | //! Retourne le nombre de bonnes donnees (utilisees pour le fit)
|
---|
[220] | 98 | inline int NDataGood() const {return mNDataGood;}
|
---|
[914] | 99 | //! Retourne la place maximale allouee pour les donnees
|
---|
[220] | 100 | inline int NDataAlloc() const {return mNDataAlloc;}
|
---|
| 101 |
|
---|
[914] | 102 | //! Retourne 1 si point valide, sinon 0
|
---|
[220] | 103 | inline unsigned short int IsValid(int i) const
|
---|
| 104 | {if(i>=0 && i<mNData) return mOK[i]; else return 0;}
|
---|
[914] | 105 | //! Retourne ``true'' si il y a des erreurs sur les variables d'abscisse, ``false'' sinon.
|
---|
[220] | 106 | inline bool HasXErrors() {if(mErrXP) return true; else return false;}
|
---|
| 107 |
|
---|
[914] | 108 | //! Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I
|
---|
[220] | 109 | inline double X1(int i) const
|
---|
| 110 | {if(i>=0 && i<mNData) return mXP[i]; else return 0.;}
|
---|
[914] | 111 | //! Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
|
---|
[220] | 112 | inline double X(int i) const
|
---|
| 113 | {if(i>=0 && i<mNData) return mXP[i*mNVar]; else return 0.;}
|
---|
[914] | 114 | //! Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
|
---|
[220] | 115 | inline double Y(int i) const
|
---|
| 116 | {if(i>=0 && i<mNData && 1<mNVar) return mXP[i*mNVar+1]; else return 0.;}
|
---|
[914] | 117 | //! etourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
|
---|
[220] | 118 | inline double Z(int i) const
|
---|
| 119 | {if(i>=0 && i<mNData && 2<mNVar) return mXP[i*mNVar+2]; else return 0.;}
|
---|
[914] | 120 | //! Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
|
---|
[220] | 121 | inline double Absc(int j,int i) const
|
---|
| 122 | {if(i>=0 && i<mNData && j<mNVar)return mXP[i*mNVar+j]; else return 0.;}
|
---|
[914] | 123 | //! Retourne la valeur de la Ieme donnee
|
---|
[220] | 124 | inline double Val(int i) const
|
---|
| 125 | {if(i>=0 && i<mNData) return mF[i]; else return 0.;}
|
---|
| 126 |
|
---|
[914] | 127 | //! Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I
|
---|
[220] | 128 | inline double EX1(int i) const
|
---|
| 129 | {if(mErrXP && i>=0 && i<mNData) return mErrXP[i]; else return 0.;}
|
---|
[914] | 130 | //! Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
|
---|
[220] | 131 | inline double EX(int i) const
|
---|
| 132 | {if(mErrXP && i>=0 && i<mNData) return mErrXP[i*mNVar]; else return 0.;}
|
---|
[914] | 133 | //! Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
|
---|
[220] | 134 | inline double EY(int i) const
|
---|
| 135 | {if(mErrXP && i>=0 && i<mNData && 1<mNVar) return mErrXP[i*mNVar+1];
|
---|
| 136 | else return 0.;}
|
---|
[914] | 137 | //! Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
|
---|
[220] | 138 | inline double EZ(int i) const
|
---|
| 139 | {if(mErrXP && i>=0 && i<mNData && 2<mNVar) return mErrXP[i*mNVar+2];
|
---|
| 140 | else return 0.;}
|
---|
[914] | 141 | //! Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
|
---|
[220] | 142 | inline double EAbsc(int j,int i) const
|
---|
| 143 | {if(mErrXP && i>=0 && i<mNData && j<mNVar) return mErrXP[i*mNVar+j];
|
---|
| 144 | else return 0.;}
|
---|
[914] | 145 | //! Retourne l'erreur de la Ieme donnee
|
---|
[220] | 146 | inline double EVal(int i) const
|
---|
| 147 | {if(i>=0 && i<mNData) return mErr[i]; else return 0.;}
|
---|
| 148 |
|
---|
[490] | 149 | r_8* GetVec(int n, r_8* ret=NULL) const;
|
---|
| 150 | r_4* GetVecR4(int n, r_4* ret=NULL) const;
|
---|
| 151 | int GetMnMx(int var,int& imin,int& imax) const;
|
---|
| 152 | int GetMnMx(int var,double& min,double& max) const;
|
---|
[220] | 153 | int GetMeanSigma(int var,double& mean,double& sigma,double min=1.,double max=-1.);
|
---|
| 154 | int GetMoMeMed(int var,double& mode,double& mean,double& median,
|
---|
| 155 | double min=1.,double max=-1.,double coeff=0.8);
|
---|
| 156 | int GetMode(int var,double& mode,double min=1.,double max=-1.,double coeff=0.8);
|
---|
| 157 | double PolFit(int varx,Poly& pol,int degre,bool ey=true);
|
---|
| 158 | double PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2=-1,bool ez=true);
|
---|
[307] | 159 | GeneralFitData FitResidus(GeneralFit& gfit);
|
---|
| 160 | GeneralFitData FitFunction(GeneralFit& gfit);
|
---|
[220] | 161 |
|
---|
[490] | 162 | // Declaration de l interface NTuple
|
---|
| 163 | virtual uint_4 NbLines() const;
|
---|
| 164 | virtual uint_4 NbColumns() const;
|
---|
| 165 | virtual r_8 * GetLineD(int n) const;
|
---|
| 166 | virtual r_8 GetCell(int n, int k) const;
|
---|
| 167 | virtual r_8 GetCell(int n, string const & nom) const;
|
---|
| 168 | virtual void GetMinMax(int k, double& min, double& max) const;
|
---|
| 169 | virtual void GetMinMax(string const & nom, double& min, double& max) const;
|
---|
| 170 | virtual int ColumnIndex(string const & nom) const;
|
---|
| 171 | virtual string ColumnName(int k) const;
|
---|
| 172 | virtual string VarList_C(const char* nomx=NULL) const;
|
---|
| 173 |
|
---|
[220] | 174 | protected:
|
---|
| 175 | void Delete();
|
---|
| 176 |
|
---|
| 177 | int_4 mNVar;
|
---|
| 178 | int_4 mNDataAlloc;
|
---|
| 179 | int_4 mNData;
|
---|
| 180 | int_4 mNDataGood;
|
---|
| 181 | uint_2 mOk_EXP;
|
---|
[914] | 182 | r_8* mXP; //!< x0 y0 z0, x1 y1 z1, ..., xn yn zn
|
---|
| 183 | r_8* mErrXP; //!< Ex0 Ey0 Ez0, Ex1 Ey1 Ez1, ..., Exn Eyn Ezn
|
---|
| 184 | r_8* mF; //!< F0, F1, ...., Fn
|
---|
| 185 | r_8* mErr; //!< EF0, EF1, ...., EFn
|
---|
| 186 | uint_2* mOK; //!< 1 si pt valid, 0 sinon
|
---|
[220] | 187 | r_8* BuffVar;
|
---|
| 188 | r_4* BuffVarR4;
|
---|
| 189 | };
|
---|
| 190 |
|
---|
[490] | 191 | inline ostream& operator << (ostream& s, GeneralFitData const & g)
|
---|
| 192 | {g.Show(s); return(s);}
|
---|
| 193 |
|
---|
[307] | 194 | /////////////////////////////////////////////////////////////////////////
|
---|
| 195 | // Classe pour la gestion de persistance
|
---|
| 196 |
|
---|
[490] | 197 | inline POutPersist& operator << (POutPersist& os, GeneralFitData & obj)
|
---|
| 198 | { ObjFileIO<GeneralFitData> fio(&obj); fio.Write(os); return(os); }
|
---|
| 199 | inline PInPersist& operator >> (PInPersist& is, GeneralFitData & obj)
|
---|
| 200 | { ObjFileIO<GeneralFitData> fio(&obj); fio.Read(is); return(is); }
|
---|
| 201 |
|
---|
| 202 | // Classe pour la gestion de persistance
|
---|
| 203 | // ObjFileIO<GeneralFitData>
|
---|
| 204 |
|
---|
[307] | 205 | } // Fin du namespace
|
---|
| 206 |
|
---|
[220] | 207 | #endif
|
---|