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

Last change on this file since 3929 was 3062, checked in by cmv, 19 years ago

dans GeneralFitData int -> int_4
GeneralFitData creation operator =
cmv 14/8/2006

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