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