source: Sophya/trunk/SophyaLib/NTools/generaldata.h@ 1584

Last change on this file since 1584 was 1204, checked in by ansari, 25 years ago

pour les adaptateurs de fit cmv 29/9/00

  • Property svn:executable set to *
File size: 8.8 KB
RevLine 
[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]13namespace SOPHYA {
[307]14
[220]15class GeneralFit;
16
17//================================================================
18// GENERALFITDATA
19//================================================================
20
[926]21//! Classe de stoquage de donnees a plusieurs variables avec erreur
[490]22class GeneralFitData : public AnyDataObj , public NTupleInterface {
[307]23 friend class GeneralFit;
[490]24 friend class ObjFileIO<GeneralFitData>;
[220]25public:
[914]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 };
[220]31
32 GeneralFitData(unsigned int nVar, unsigned int nDataAlloc, uint_2 errx=0);
[307]33 GeneralFitData(const GeneralFitData& data, bool clean=false);
[220]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
[1110]67 void PrintStatus() const;
68 void PrintData(int i) const;
69 void PrintData(int i1,int i2) const;
70 void PrintData() const;
[490]71 void Show(ostream& os) const;
72 inline void Show() const {Show(cout);}
[220]73
[914]74 //! Retourne la place restante dans la structure (nombre de donnees que l'on peut encore stoquer).
[220]75 inline int GetSpaceFree() const { return mNDataAlloc - mNData; }
[914]76 //! Retourne le nombre de variables Xi
[220]77 inline int NVar() const {return mNVar;}
[914]78 //! Retourne le nombre de donnees
[220]79 inline int NData() const {return mNData;}
[914]80 //! Retourne le nombre de bonnes donnees (utilisees pour le fit)
[220]81 inline int NDataGood() const {return mNDataGood;}
[914]82 //! Retourne la place maximale allouee pour les donnees
[220]83 inline int NDataAlloc() const {return mNDataAlloc;}
84
[914]85 //! Retourne 1 si point valide, sinon 0
[220]86 inline unsigned short int IsValid(int i) const
87 {if(i>=0 && i<mNData) return mOK[i]; else return 0;}
[914]88 //! Retourne ``true'' si il y a des erreurs sur les variables d'abscisse, ``false'' sinon.
[220]89 inline bool HasXErrors() {if(mErrXP) return true; else return false;}
90
[914]91 //! Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I
[220]92 inline double X1(int i) const
93 {if(i>=0 && i<mNData) return mXP[i]; else return 0.;}
[914]94 //! Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
[220]95 inline double X(int i) const
96 {if(i>=0 && i<mNData) return mXP[i*mNVar]; else return 0.;}
[914]97 //! Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
[220]98 inline double Y(int i) const
99 {if(i>=0 && i<mNData && 1<mNVar) return mXP[i*mNVar+1]; else return 0.;}
[914]100 //! etourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
[220]101 inline double Z(int i) const
102 {if(i>=0 && i<mNData && 2<mNVar) return mXP[i*mNVar+2]; else return 0.;}
[914]103 //! Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
[220]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.;}
[914]106 //! Retourne la valeur de la Ieme donnee
[220]107 inline double Val(int i) const
108 {if(i>=0 && i<mNData) return mF[i]; else return 0.;}
109
[914]110 //! Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I
[220]111 inline double EX1(int i) const
112 {if(mErrXP && i>=0 && i<mNData) return mErrXP[i]; else return 0.;}
[914]113 //! Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
[220]114 inline double EX(int i) const
115 {if(mErrXP && i>=0 && i<mNData) return mErrXP[i*mNVar]; else return 0.;}
[914]116 //! Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
[220]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.;}
[914]120 //! Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
[220]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.;}
[914]124 //! Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
[220]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.;}
[914]128 //! Retourne l'erreur de la Ieme donnee
[220]129 inline double EVal(int i) const
130 {if(i>=0 && i<mNData) return mErr[i]; else return 0.;}
131
[1110]132 r_8* GetVec(int n, r_8* ret=NULL) const;
133 r_4* GetVecR4(int n, r_4* ret=NULL) const;
[490]134 int GetMnMx(int var,int& imin,int& imax) const;
135 int GetMnMx(int var,double& min,double& max) const;
[1110]136 int GetMeanSigma(int var,double& mean,double& sigma,double min=1.,double max=-1.) const;
[220]137 int GetMoMeMed(int var,double& mode,double& mean,double& median,
[1110]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;
[1204]140 double PolFit(int varx,Poly& pol,int degre,bool ey=true,double xc=0.) const;
141 double PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2=-1,bool ez=true
142 ,double xc=0.,double yc=0.) const;
[1110]143 GeneralFitData FitResidus(GeneralFit& gfit) const;
144 GeneralFitData FitFunction(GeneralFit& gfit) const;
[220]145
[490]146// Declaration de l interface NTuple
147 virtual uint_4 NbLines() const;
148 virtual uint_4 NbColumns() const;
149 virtual r_8 * GetLineD(int n) const;
150 virtual r_8 GetCell(int n, int k) const;
151 virtual r_8 GetCell(int n, string const & nom) const;
152 virtual void GetMinMax(int k, double& min, double& max) const;
153 virtual void GetMinMax(string const & nom, double& min, double& max) const;
154 virtual int ColumnIndex(string const & nom) const;
155 virtual string ColumnName(int k) const;
156 virtual string VarList_C(const char* nomx=NULL) const;
157
[1204]158 enum FitErrType {DefaultError,ConstantError,SqrtError,ProporError};
159 static double ComputeError(double val,double err,FitErrType errtype=DefaultError
160 ,double errscale=1.,double errmin=0.,bool nozero=false);
161
[220]162protected:
163 void Delete();
164
[958]165 int_4 mNVar; //!< number of variables
166 int_4 mNDataAlloc; //!< space allocated for datas
167 int_4 mNData; //!< number of datas
168 int_4 mNDataGood; //!< number of good datas (not killed)
169 uint_2 mOk_EXP; //!< true if errors on variables X,Y,..
[914]170 r_8* mXP; //!< x0 y0 z0, x1 y1 z1, ..., xn yn zn
171 r_8* mErrXP; //!< Ex0 Ey0 Ez0, Ex1 Ey1 Ez1, ..., Exn Eyn Ezn
172 r_8* mF; //!< F0, F1, ...., Fn
173 r_8* mErr; //!< EF0, EF1, ...., EFn
174 uint_2* mOK; //!< 1 si pt valid, 0 sinon
[958]175 r_8* BuffVar; //!< dummy buffer
176 r_4* BuffVarR4; //!< dummy buffer
[220]177};
178
[490]179inline ostream& operator << (ostream& s, GeneralFitData const & g)
180 {g.Show(s); return(s);}
181
[307]182/////////////////////////////////////////////////////////////////////////
183// Classe pour la gestion de persistance
184
[958]185//! For persistance management
[490]186inline POutPersist& operator << (POutPersist& os, GeneralFitData & obj)
187{ ObjFileIO<GeneralFitData> fio(&obj); fio.Write(os); return(os); }
[958]188//! For persistance management
[490]189inline PInPersist& operator >> (PInPersist& is, GeneralFitData & obj)
190{ ObjFileIO<GeneralFitData> fio(&obj); fio.Read(is); return(is); }
191
192// Classe pour la gestion de persistance
193// ObjFileIO<GeneralFitData>
194
[307]195} // Fin du namespace
196
[220]197#endif
Note: See TracBrowser for help on using the repository browser.