Changeset 307 in Sophya for trunk/SophyaLib/NTools
- Timestamp:
- May 19, 1999, 5:58:06 PM (26 years ago)
- Location:
- trunk/SophyaLib/NTools
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/cvector.cc
r303 r307 171 171 ////////////////////////////////////////////////////////// 172 172 //++ 173 Vector * Vector::FitResidus(GeneralFit& gfit)173 Vector Vector::FitResidus(GeneralFit& gfit,double xorg,double dx) 174 174 // 175 175 // Retourne une classe contenant les residus du fit ``gfit''. 176 // On suppose que x=i. 177 //-- 178 { 179 if(NElts()<=0) return NULL; 176 // La coordonnee de l'element (i) est -> x = xorg + i*dx 177 //-- 178 { 179 if(NElts()<=0) 180 throw(SzMismatchError("Vector::FitResidus: size mismatch\n")); 180 181 GeneralFunction* f = gfit.GetFunction(); 181 if(f==NULL) return NULL; 182 if(f==NULL) 183 throw(NullPtrError("Vector::FitResidus: NULL pointer\n")); 182 184 Vector par = gfit.GetParm(); 183 Vector * v = new Vector(*this);185 Vector v(*this); 184 186 for(int i=0;i<NElts();i++) { 185 double x = (double)i;186 (*v)(i) -= f->Value(&x,par.Data());187 double x = xorg+i*dx; 188 v(i) -= f->Value(&x,par.Data()); 187 189 } 188 190 return v; … … 190 192 191 193 //++ 192 Vector * Vector::FitFunction(GeneralFit& gfit)194 Vector Vector::FitFunction(GeneralFit& gfit,double xorg,double dx) 193 195 // 194 196 // Retourne une classe contenant la fonction du fit ``gfit''. 195 // On suppose que x=i. 196 //-- 197 { 198 if(NElts()<=0) return NULL; 197 // La coordonnee de l'element (i) est -> x = xorg + i*dx 198 //-- 199 { 200 if(NElts()<=0) 201 throw(SzMismatchError("Vector::FitResidus: size mismatch\n")); 199 202 GeneralFunction* f = gfit.GetFunction(); 200 if(f==NULL) return NULL; 203 if(f==NULL) 204 throw(NullPtrError("Vector::FitResidus: NULL pointer\n")); 201 205 Vector par = gfit.GetParm(); 202 Vector * v = new Vector(*this);206 Vector v(*this); 203 207 for(int i=0;i<NElts();i++) { 204 double x = (double)i;205 (*v)(i) = f->Value(&x,par.Data());208 double x = xorg+i*dx; 209 v(i) = f->Value(&x,par.Data()); 206 210 } 207 211 return v; -
trunk/SophyaLib/NTools/cvector.h
r304 r307 5 5 #include "matrix.h" 6 6 7 class GeneralFit; 8 namespace PlanckDPC {template <class T> class TVector;} 7 namespace PlanckDPC { 8 class GeneralFit; 9 template <class T> class TVector; 10 } 9 11 10 12 // <summary> Vecteur colonne pour operations matricielles </summary> … … 66 68 67 69 // Residus et fonction fittees. 68 Vector * FitResidus(GeneralFit& gfit);69 Vector * FitFunction(GeneralFit& gfit);70 Vector FitResidus(GeneralFit& gfit,double xorg=0.,double dx=1.); 71 Vector FitFunction(GeneralFit& gfit,double xorg=0.,double dx=1.); 70 72 71 73 }; … … 98 100 99 101 #endif /* VECTOR_SEEN */ 100 101 102 -
trunk/SophyaLib/NTools/difeq.h
r244 r307 7 7 #include "cvector.h" 8 8 9 class GeneralFunction; 10 9 namespace PlanckDPC {class GeneralFunction;} 11 10 12 11 // <summary> fonction pour equadifs </summary> -
trunk/SophyaLib/NTools/fct1dfit.cc
r244 r307 8 8 #include "nbconst.h" 9 9 #include "tabmath.h" 10 11 using namespace PlanckDPC; 10 12 11 13 //define EXPO exp -
trunk/SophyaLib/NTools/fct1dfit.h
r220 r307 3 3 4 4 #include "generalfit.h" 5 6 namespace PlanckDPC { 5 7 6 8 //================================================================ … … 134 136 }; 135 137 138 } // Fin du namespace 139 136 140 #endif -
trunk/SophyaLib/NTools/fct2dfit.cc
r244 r307 16 16 #define EXPO tabFExp 17 17 #define MINEXPM (100.) 18 19 using namespace PlanckDPC; 18 20 19 21 //================================================================ -
trunk/SophyaLib/NTools/fct2dfit.h
r220 r307 3 3 4 4 #include "generalfit.h" 5 6 namespace PlanckDPC { 5 7 6 8 //================================================================ … … 193 195 }; 194 196 197 } // Fin du namespace 198 195 199 #endif -
trunk/SophyaLib/NTools/generaldata.cc
r244 r307 3 3 #include <stdlib.h> 4 4 #include <iostream.h> 5 #include <values.h> 5 6 #include <math.h> 6 7 #include <string.h> … … 11 12 #endif 12 13 13 #include "perrors.h"14 14 #include "nbtri.h" 15 15 #include "generalfit.h" 16 16 #include "generaldata.h" 17 #include "pexceptions.h" 18 #include "objfio.h" 19 20 using namespace PlanckDPC; 17 21 18 22 //================================================================ … … 52 56 , BuffVar(NULL), BuffVarR4(NULL) 53 57 { 54 TRY { 55 Alloc(nVar,ndatalloc,errx); 56 } CATCHALL { 57 cout<<"GeneralFitData::GeneralFitData Impossible d'allouer l'espace"<<endl; 58 THROW_SAME; 59 } ENDTRY 60 END_CONSTRUCTOR 61 } 62 63 //++ 64 GeneralFitData::GeneralFitData(GeneralFitData& data, bool clean) 58 try { 59 Alloc(nVar,ndatalloc,errx); 60 } catch(PException e) { 61 cout << "Exception : " << typeid(e).name() << " " << e.Msg() << endl; 62 throw; 63 } 64 } 65 66 //++ 67 GeneralFitData::GeneralFitData(const GeneralFitData& data, bool clean) 65 68 // 66 69 // Constructeur par copie. Si ``clean'' est ``true'' … … 74 77 , BuffVar(NULL), BuffVarR4(NULL) 75 78 { 76 TRY{77 78 } CATCHALL{79 cout<<"GeneralFitData::GeneralFitData Impossible d'allouer l'espace"<<endl;80 THROW_SAME;81 } ENDTRY 79 try { 80 Alloc(data.mNVar,((clean)?data.mNDataGood:data.mNDataAlloc),((data.mErrXP)?1:0)); 81 } catch(PException e) { 82 cout << "Exception : " << typeid(e).name() << " " << e.Msg() << endl; 83 throw; 84 } 82 85 83 86 // Remplissage … … 113 116 114 117 //++ 115 GeneralFitData::GeneralFitData(char *flnm)116 //117 // Constructeur par lecture d'un fichier ppersist..118 //--119 : mNVar(0), mNDataAlloc(0), mNData(0), mNDataGood(0), mOk_EXP(0)120 , mXP(NULL), mErrXP(NULL), mF(NULL), mErr(NULL), mOK(NULL)121 , BuffVar(NULL), BuffVarR4(NULL)122 {123 PInPersist s(flnm);124 Read(s);125 END_CONSTRUCTOR126 }127 128 //++129 118 GeneralFitData::~GeneralFitData() 130 119 // … … 153 142 mNDataAlloc = ndatalloc; 154 143 155 TRY{144 try { 156 145 mXP = new r_8[nVar*ndatalloc]; 157 146 if(mOk_EXP) mErrXP = new r_8[nVar*ndatalloc]; … … 161 150 BuffVar = new r_8[2*nVar+3]; 162 151 BuffVarR4 = (r_4 *) BuffVar; 163 } CATCHALL{164 THROW_SAME;165 } ENDTRY152 } catch(PException e) { 153 throw(AllocationError("GeneralFitData::Alloc allocation error\n")); 154 } 166 155 } 167 156 … … 824 813 ////////////////////////////////////////////////////////////////////// 825 814 //++ 826 GeneralFitData *GeneralFitData::FitResidus(GeneralFit& gfit)815 GeneralFitData GeneralFitData::FitResidus(GeneralFit& gfit) 827 816 // 828 817 // Retourne une classe contenant les residus du fit ``gfit''. 829 818 //-- 830 819 { 831 if(gfit.GetNVar()!=mNVar) return NULL; 820 if(gfit.GetNVar()!=mNVar) 821 throw(SzMismatchError("GeneralFitData::FitResidus: size mismatch\n")); 832 822 return gfit.DataResidus(true); 833 823 } 834 824 835 825 //++ 836 GeneralFitData *GeneralFitData::FitFunction(GeneralFit& gfit)826 GeneralFitData GeneralFitData::FitFunction(GeneralFit& gfit) 837 827 // 838 828 // Retourne une classe contenant la function du fit ``gfit''. 839 829 //-- 840 830 { 841 if(gfit.GetNVar()!=mNVar) return NULL; 831 if(gfit.GetNVar()!=mNVar) 832 throw(SzMismatchError("GeneralFitData::FitFunction: size mismatch\n")); 842 833 return gfit.DataFunction(true); 843 834 } … … 922 913 ////////////////////////////////////////////////////////////////////// 923 914 //++ 924 void GeneralFitData::WriteSelf(POutPersist& s) const 925 // 926 // Ecriture ppersist 927 //-- 928 { 915 // int inline int GetSpaceFree() const 916 // Retourne la place restante dans la structure (nombre de 917 // donnees que l'on peut encore stoquer). 918 //-- 919 //++ 920 // inline int NVar() const 921 // Retourne le nombre de variables Xi 922 //-- 923 //++ 924 // inline int NData() 925 // Retourne le nombre de donnees 926 //-- 927 //++ 928 // inline int NDataGood() const 929 // Retourne le nombre de bonnes donnees (utilisees pour le fit) 930 //-- 931 //++ 932 // inline int NDataAlloc() const 933 // Retourne la place maximale allouee pour les donnees 934 //-- 935 //++ 936 // inline unsigned short int IsValid(int i) const 937 // Retourne 1 si point valide, sinon 0 938 //-- 939 //++ 940 // inline bool HasXErrors() 941 // Retourne ``true'' si il y a des erreurs sur les variables 942 // d'abscisse, ``false'' sinon. 943 //-- 944 //++ 945 // inline double X1(int i) const 946 // Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I 947 //-- 948 //++ 949 // inline double X(int i) const 950 // Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I 951 //-- 952 //++ 953 // inline double Y(int i) const 954 // Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I 955 //-- 956 //++ 957 // inline double Z(int i) const 958 // Retourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I 959 //-- 960 //++ 961 // inline double Absc(int j,int i) const 962 // Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I 963 //-- 964 //++ 965 // inline double Val(int i) const 966 // Retourne la valeur de la Ieme donnee 967 //-- 968 //++ 969 // inline double EX1(int i) const 970 // Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I 971 //-- 972 //++ 973 // inline double EX(int i) const 974 // Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I 975 //-- 976 //++ 977 // inline double EY(int i) const 978 // Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I 979 //-- 980 //++ 981 // inline double EZ(int i) const 982 // Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I 983 //-- 984 //++ 985 // inline double EAbsc(int j,int i) const 986 // Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I 987 //-- 988 //++ 989 // inline double EVal(int i) const {return mErr[i];} 990 // Retourne l'erreur de la Ieme donnee 991 //-- 992 993 /////////////////////////////////////////////////////////// 994 // -------------------------------------------------------- 995 // Les objets delegues pour la gestion de persistance 996 // -------------------------------------------------------- 997 /////////////////////////////////////////////////////////// 998 999 FIO_GeneralFitData::FIO_GeneralFitData() 1000 { 1001 dobj=new GeneralFitData; 1002 ownobj=true; 1003 } 1004 1005 FIO_GeneralFitData::FIO_GeneralFitData(string const & filename) 1006 { 1007 dobj=new GeneralFitData; 1008 ownobj=true; 1009 Read(filename); 1010 } 1011 1012 FIO_GeneralFitData::FIO_GeneralFitData(const GeneralFitData & obj) 1013 { 1014 dobj = new GeneralFitData(obj); 1015 ownobj=true; 1016 } 1017 1018 FIO_GeneralFitData::FIO_GeneralFitData(GeneralFitData * obj) 1019 { 1020 dobj = obj; 1021 ownobj=false; 1022 } 1023 1024 FIO_GeneralFitData::~FIO_GeneralFitData() 1025 { 1026 if (ownobj && dobj) delete dobj; 1027 } 1028 1029 AnyDataObj* FIO_GeneralFitData::DataObj() 1030 { 1031 return(dobj); 1032 } 1033 1034 void FIO_GeneralFitData::ReadSelf(PInPersist& is) 1035 { 1036 char strg[256]; 1037 1038 if(dobj==NULL) dobj=new GeneralFitData; 1039 else dobj->Delete(); 1040 1041 // Lecture entete 1042 is.GetLine(strg, 255); 1043 1044 // Ecriture des valeurs de definitions 1045 int_4 nvar,ndatalloc,ndata,ndatagood; 1046 is.Get(nvar); 1047 is.Get(ndatalloc); 1048 is.Get(ndata); 1049 is.Get(ndatagood); 1050 is.Get(dobj->mOk_EXP); 1051 if(nvar<=0 || ndatalloc<=0 || ndata<=0 || ndatagood<0 || ndatalloc<ndata) return; 1052 1053 // Allocation de la place (attention Alloc efface mNData,mNDataGood); 1054 dobj->Alloc(nvar,ndatalloc,-1); 1055 dobj->mNData = ndata; 1056 dobj->mNDataGood = ndatagood; 1057 1058 // Lecture des datas 1059 is.GetLine(strg, 255); 1060 int blen = dobj->mNVar + 3; 1061 if(dobj->mOk_EXP) blen += dobj->mNVar; 1062 double *buff = new double[blen]; 1063 for(int i=0;i<dobj->mNData;i++) { 1064 is.Get(buff, blen); 1065 int ip = i*dobj->mNVar; 1066 {for(int j=0;j<dobj->mNVar;j++) dobj->mXP[ip+j] = buff[j];} 1067 dobj->mF[i] = buff[dobj->mNVar]; 1068 dobj->mErr[i] = buff[dobj->mNVar+1]; 1069 dobj->mOK[i] = (uint_2)(buff[dobj->mNVar+2]+0.01); 1070 if(dobj->mOk_EXP) {for(int j=0;j<dobj->mNVar;j++) 1071 dobj->mErrXP[ip+j] = buff[dobj->mNVar+3+j];} 1072 } 1073 delete [] buff; 1074 1075 return; 1076 } 1077 1078 void FIO_GeneralFitData::WriteSelf(POutPersist& os) const 1079 { 1080 if (dobj == NULL) return; 929 1081 char strg[256]; 930 1082 931 1083 // Ecriture entete pour identifier facilement 932 1084 sprintf(strg,"GeneralFitData: NVar=%d NDataAlloc=%d NData=%d NDataGood=%d Ok_EXP=%d" 933 , mNVar,mNDataAlloc,mNData,mNDataGood,mOk_EXP);934 s.PutLine(strg);1085 ,dobj->mNVar,dobj->mNDataAlloc,dobj->mNData,dobj->mNDataGood,dobj->mOk_EXP); 1086 os.PutLine(strg); 935 1087 936 1088 // Ecriture des valeurs de definitions 937 s.PutI4(mNVar);938 s.PutI4(mNDataAlloc);939 s.PutI4(mNData);940 s.PutI4(mNDataGood);941 s.PutU2(mOk_EXP);942 if( mNVar<=0 || mNDataAlloc<=0 || mNData<=0 ||mNDataGood<0) return;1089 os.Put(dobj->mNVar); 1090 os.Put(dobj->mNDataAlloc); 1091 os.Put(dobj->mNData); 1092 os.Put(dobj->mNDataGood); 1093 os.Put(dobj->mOk_EXP); 1094 if(dobj->mNVar<=0 || dobj->mNDataAlloc<=0 || dobj->mNData<=0 || dobj->mNDataGood<0) return; 943 1095 944 1096 // Ecriture des datas (on n'ecrit que mNData / mNDataAlloc) 945 1097 sprintf(strg 946 1098 ,"GeneralFitData: Abscisses, Ordonnee, Erreur Ordonnee, Flag, Erreur Abscisses"); 947 s.PutLine(strg);948 949 int blen = mNVar + 3;950 if( mOk_EXP) blen +=mNVar;1099 os.PutLine(strg); 1100 1101 int blen = dobj->mNVar + 3; 1102 if(dobj->mOk_EXP) blen += dobj->mNVar; 951 1103 double *buff = new double[blen]; 952 for(int i=0;i< mNData;i++) {953 {for(int j=0;j< mNVar;j++) buff[j] =Absc(j,i);}954 buff[ mNVar] =Val(i);955 buff[ mNVar+1] =EVal(i);956 buff[ mNVar+2] = (double)IsValid(i);957 if( mOk_EXP) {for(int j=0;j<mNVar;j++) buff[mNVar+3+j] =EAbsc(j,i);}958 s.PutR8s(buff, blen);1104 for(int i=0;i<dobj->mNData;i++) { 1105 {for(int j=0;j<dobj->mNVar;j++) buff[j] = dobj->Absc(j,i);} 1106 buff[dobj->mNVar] = dobj->Val(i); 1107 buff[dobj->mNVar+1] = dobj->EVal(i); 1108 buff[dobj->mNVar+2] = (double) dobj->IsValid(i); 1109 if(dobj->mOk_EXP) {for(int j=0;j<dobj->mNVar;j++) buff[dobj->mNVar+3+j] = dobj->EAbsc(j,i);} 1110 os.Put(buff, blen); 959 1111 } 960 1112 delete [] buff; … … 962 1114 return; 963 1115 } 964 965 //////////////////////////////////////////////////////////////////////966 //++967 void GeneralFitData::ReadSelf(PInPersist& s)968 //969 // Lecture ppersist970 //--971 {972 char strg[256];973 974 Delete();975 976 // Lecture entete977 s.GetLine(strg, 255);978 979 // Ecriture des valeurs de definitions980 int_4 nvar,ndatalloc,ndata,ndatagood;981 s.GetI4(nvar);982 s.GetI4(ndatalloc);983 s.GetI4(ndata);984 s.GetI4(ndatagood);985 s.GetU2(mOk_EXP);986 if(nvar<=0 || ndatalloc<=0 || ndata<=0 || ndatagood<0 || ndatalloc<ndata) return;987 988 // Allocation de la place (attention Alloc efface mNData,mNDataGood);989 Alloc(nvar,ndatalloc,-1);990 mNData = ndata;991 mNDataGood = ndatagood;992 993 // Lecture des datas994 s.GetLine(strg, 255);995 int blen = mNVar + 3;996 if(mOk_EXP) blen += mNVar;997 double *buff = new double[blen];998 for(int i=0;i<mNData;i++) {999 s.GetR8s(buff, blen);1000 int ip = i*mNVar;1001 {for(int j=0;j<mNVar;j++) mXP[ip+j] = buff[j];}1002 mF[i] = buff[mNVar];1003 mErr[i] = buff[mNVar+1];1004 mOK[i] = (uint_2)(buff[mNVar+2]+0.01);1005 if(mOk_EXP) {for(int j=0;j<mNVar;j++) mErrXP[ip+j] = buff[mNVar+3+j];}1006 }1007 delete [] buff;1008 1009 return;1010 }1011 1012 //////////////////////////////////////////////////////////////////////1013 //++1014 // int inline int GetSpaceFree() const1015 // Retourne la place restante dans la structure (nombre de1016 // donnees que l'on peut encore stoquer).1017 //--1018 //++1019 // inline int NVar() const1020 // Retourne le nombre de variables Xi1021 //--1022 //++1023 // inline int NData()1024 // Retourne le nombre de donnees1025 //--1026 //++1027 // inline int NDataGood() const1028 // Retourne le nombre de bonnes donnees (utilisees pour le fit)1029 //--1030 //++1031 // inline int NDataAlloc() const1032 // Retourne la place maximale allouee pour les donnees1033 //--1034 //++1035 // inline unsigned short int IsValid(int i) const1036 // Retourne 1 si point valide, sinon 01037 //--1038 //++1039 // inline bool HasXErrors()1040 // Retourne ``true'' si il y a des erreurs sur les variables1041 // d'abscisse, ``false'' sinon.1042 //--1043 //++1044 // inline double X1(int i) const1045 // Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I1046 //--1047 //++1048 // inline double X(int i) const1049 // Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I1050 //--1051 //++1052 // inline double Y(int i) const1053 // Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I1054 //--1055 //++1056 // inline double Z(int i) const1057 // Retourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I1058 //--1059 //++1060 // inline double Absc(int j,int i) const1061 // Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I1062 //--1063 //++1064 // inline double Val(int i) const1065 // Retourne la valeur de la Ieme donnee1066 //--1067 //++1068 // inline double EX1(int i) const1069 // Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I1070 //--1071 //++1072 // inline double EX(int i) const1073 // Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I1074 //--1075 //++1076 // inline double EY(int i) const1077 // Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I1078 //--1079 //++1080 // inline double EZ(int i) const1081 // Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I1082 //--1083 //++1084 // inline double EAbsc(int j,int i) const1085 // Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I1086 //--1087 //++1088 // inline double EVal(int i) const {return mErr[i];}1089 // Retourne l'erreur de la Ieme donnee1090 //-- -
trunk/SophyaLib/NTools/generaldata.h
r244 r307 1 // This may look like C code, but it is really -*- C++ -*- 2 // C.Magneville 04/99 1 3 #ifndef GENERALDATA_SEEN 2 4 #define GENERALDATA_SEEN … … 5 7 #include "ppersist.h" 6 8 #include "poly.h" 9 #include "anydataobj.h" 10 11 namespace PlanckDPC { 7 12 8 13 class GeneralFit; 14 class FIO_GeneralFitData; 9 15 10 16 //================================================================ … … 12 18 //================================================================ 13 19 14 class GeneralFitData : public PPersist { 20 class GeneralFitData : public AnyDataObj { 21 friend class GeneralFit; 22 friend class FIO_GeneralFitData; 15 23 public: 16 enum {classId = ClassId_GeneralFitData };17 24 enum {Def_ErrF = 1, Def_ErrX = 0}; 18 25 19 26 GeneralFitData(unsigned int nVar, unsigned int nDataAlloc, uint_2 errx=0); 20 GeneralFitData( GeneralFitData& data, bool clean=false);27 GeneralFitData(const GeneralFitData& data, bool clean=false); 21 28 GeneralFitData(); 22 GeneralFitData(char *flnm);23 29 virtual ~GeneralFitData(); 24 30 … … 107 113 double PolFit(int varx,Poly& pol,int degre,bool ey=true); 108 114 double PolFit(int varx,int vary,Poly2& pol,int degre1,int degre2=-1,bool ez=true); 109 GeneralFitData *FitResidus(GeneralFit& gfit);110 GeneralFitData *FitFunction(GeneralFit& gfit);115 GeneralFitData FitResidus(GeneralFit& gfit); 116 GeneralFitData FitFunction(GeneralFit& gfit); 111 117 string VarList_C(const char* nomx) const; 112 113 int_4 ClassId() const { return classId; }114 static PPersist* Create() { return new GeneralFitData;}115 116 virtual void WriteSelf(POutPersist&) const;117 virtual void ReadSelf(PInPersist&);118 119 friend class GeneralFit;120 118 121 119 protected: … … 136 134 }; 137 135 136 ///////////////////////////////////////////////////////////////////////// 137 // Classe pour la gestion de persistance 138 class FIO_GeneralFitData : public PPersist { 139 public: 140 FIO_GeneralFitData(); 141 FIO_GeneralFitData(string const & filename); 142 FIO_GeneralFitData(const GeneralFitData & obj); 143 FIO_GeneralFitData(GeneralFitData * obj); 144 virtual ~FIO_GeneralFitData(); 145 virtual AnyDataObj* DataObj(); 146 inline operator GeneralFitData() { return(*dobj); } 147 protected : 148 virtual void ReadSelf(PInPersist&); 149 virtual void WriteSelf(POutPersist&) const; 150 GeneralFitData * dobj; 151 bool ownobj; 152 }; 153 154 } // Fin du namespace 155 138 156 #endif -
trunk/SophyaLib/NTools/generalfit.cc
r244 r307 11 11 #endif 12 12 13 #include "pexceptions.h" 13 14 #include "generalfit.h" 14 #include "perrors.h"15 15 #include "cvector.h" 16 #include "nbconst.h"17 #include "tabmath.h"18 16 19 17 #define EPS_FIT_MIN 1.e-8 18 19 using namespace PlanckDPC; 20 20 21 21 //================================================================ … … 1433 1433 ////////////////////////////////////////////////////////////////////// 1434 1434 //++ 1435 GeneralFitData *GeneralFit::DataResidus(bool clean)1435 GeneralFitData GeneralFit::DataResidus(bool clean) 1436 1436 // 1437 1437 // Retourne une structure ``GeneralFitData'' contenant … … 1444 1444 //-- 1445 1445 { 1446 if(!mData ) return NULL;1447 if(!mFunction) return NULL;1448 GeneralFitData * datres = new GeneralFitData(*mData,clean);1446 if(!mData || !mFunction) 1447 throw(NullPtrError("GeneralFit::DataResidus: NULL pointer\n")); 1448 GeneralFitData datres(*mData,clean); 1449 1449 for(int k=0; k<mData->NData(); k++) 1450 datres ->mF[k] -= mFunction->Value(&datres->mXP[mNVar*k],Param.Data());1450 datres.mF[k] -= mFunction->Value(&datres.mXP[mNVar*k],Param.Data()); 1451 1451 return datres; 1452 1452 } … … 1454 1454 ////////////////////////////////////////////////////////////////////// 1455 1455 //++ 1456 GeneralFitData *GeneralFit::DataFunction(bool clean)1456 GeneralFitData GeneralFit::DataFunction(bool clean) 1457 1457 // 1458 1458 // Retourne une structure ``GeneralFitData'' contenant … … 1461 1461 //-- 1462 1462 { 1463 if(!mData ) return NULL;1464 if(!mFunction) return NULL;1465 GeneralFitData * datres = new GeneralFitData(*mData,clean);1463 if(!mData || !mFunction) 1464 throw(NullPtrError("GeneralFit::DataFunction: NULL pointer\n")); 1465 GeneralFitData datres(*mData,clean); 1466 1466 for(int k=0; k<mData->NData(); k++) 1467 datres ->mF[k] = mFunction->Value(&datres->mXP[mNVar*k],Param.Data());1467 datres.mF[k] = mFunction->Value(&datres.mXP[mNVar*k],Param.Data()); 1468 1468 return datres; 1469 1469 } -
trunk/SophyaLib/NTools/generalfit.h
r244 r307 8 8 #include "generaldata.h" 9 9 10 namespace PlanckDPC { 11 10 12 //================================================================ 11 13 // GeneralFunction 12 14 //================================================================ 13 15 14 class GeneralFunction EXC_AWARE{16 class GeneralFunction { 15 17 public: 16 18 GeneralFunction(unsigned int nVar, unsigned int nPar); … … 61 63 class GeneralFitData; 62 64 63 class GeneralXi2 EXC_AWARE{65 class GeneralXi2 { 64 66 public: 65 67 GeneralXi2(unsigned int nPar); … … 85 87 //================================================================ 86 88 87 class GeneralFit EXC_AWARE{89 class GeneralFit { 88 90 public: 89 91 GeneralFit(GeneralFunction* f); … … 152 154 int Fit(); 153 155 double ReCalChi2(int& nddl, double* par = NULL); 154 GeneralFitData *DataResidus(bool clean=true);155 GeneralFitData *DataFunction(bool clean=true);156 GeneralFitData DataResidus(bool clean=true); 157 GeneralFitData DataFunction(bool clean=true); 156 158 void PrintFitErr(int rc); 157 159 … … 227 229 }; 228 230 231 } // Fin du namespace 232 229 233 #endif -
trunk/SophyaLib/NTools/hisprof.cc
r244 r307 7 7 #include "cvector.h" 8 8 9 using namespace PlanckDPC; 10 9 11 //++ 10 12 // Class HProf … … 47 49 Histo::Errors(); 48 50 Zero(); 49 END_CONSTRUCTOR50 }51 52 /********* Methode *********/53 //++54 HProf::HProf(char *flnm)55 //56 // Constructeur a partir d'un fichier ppersist.57 //--58 : Histo()59 , SumY(NULL), SumY2(NULL), SumW(NULL), Ok(false), YMin(1.), YMax(-1.), Opt(0)60 {61 PInPersist s(flnm);62 Read(s);63 51 END_CONSTRUCTOR 64 52 } … … 261 249 //-- 262 250 { 263 if (b. bins!=a.bins) THROW(sizeMismatchErr);251 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 264 252 HProf c(a); 265 253 return (c += b); 266 254 } 267 255 268 /********* Methode *********/ 269 //++ 270 void HProf::WriteSelf(POutPersist& s) const 271 // 272 // Ecriture ppersist 273 //-- 256 // Rappel des inlines functions pour commentaires 257 //++ 258 // inline Histo GetHisto() 259 // Retourne l'histogramme de profil. 260 //-- 261 //++ 262 // inline void GetMean(Vector& v) 263 // Retourne le contenu de la moyenne dans le vecteur v 264 //-- 265 //++ 266 // inline void GetError2(Vector& v) 267 // Retourne le contenu au carre de la dispersion/erreur dans le vecteur v 268 //-- 269 //++ 270 // inline float operator()(int i) const 271 // Retourne le contenu du bin i 272 //-- 273 //++ 274 // inline float Error2(int i) const 275 // Retourne le carre de la dispersion/erreur du bin i 276 //-- 277 //++ 278 // inline float Error(int i) const 279 // Retourne la dispersion/erreur du bin i 280 //-- 281 //++ 282 // inline int Fit(GeneralFit& gfit) 283 // Fit du profile par ``gfit''. 284 //-- 285 //++ 286 // inline Histo* FitResidus(GeneralFit& gfit) 287 // Retourne l'Histogramme des residus par ``gfit''. 288 //-- 289 //++ 290 // inline Histo* FitFunction(GeneralFit& gfit) 291 // Retourne l'Histogramme de la fonction fittee par ``gfit''. 292 //-- 293 //++ 294 // inline void Print(int dyn,float hmin,float hmax,int pflag,int il,int ih) 295 // Print, voir detail dans Histo::Print 296 //-- 297 298 299 /////////////////////////////////////////////////////////// 300 // -------------------------------------------------------- 301 // Les objets delegues pour la gestion de persistance 302 // -------------------------------------------------------- 303 /////////////////////////////////////////////////////////// 304 305 FIO_HProf::FIO_HProf() 306 { 307 dobj=new HProf; 308 ownobj=true; 309 } 310 311 FIO_HProf::FIO_HProf(string const & filename) 312 { 313 dobj=new HProf; 314 ownobj=true; 315 Read(filename); 316 } 317 318 FIO_HProf::FIO_HProf(const HProf & obj) 319 { 320 dobj = new HProf(obj); 321 ownobj=true; 322 } 323 324 FIO_HProf::FIO_HProf(HProf * obj) 325 { 326 dobj = obj; 327 ownobj=false; 328 } 329 330 FIO_HProf::~FIO_HProf() 331 { 332 if (ownobj && dobj) delete dobj; 333 } 334 335 AnyDataObj* FIO_HProf::DataObj() 336 { 337 return(dobj); 338 } 339 340 void FIO_HProf::ReadSelf(PInPersist& is) 274 341 { 275 342 char strg[256]; 276 343 277 UpdateHisto(); 344 if(dobj==NULL) dobj=new HProf; 345 else dobj->Delete(); 346 347 // Lecture entete 348 is.GetLine(strg,255); 349 350 // Ecriture des valeurs 351 is.Get(dobj->bins); 352 is.Get(dobj->YMin); 353 is.Get(dobj->YMax); 354 is.Get(dobj->Opt); 355 dobj->Ok = true; 356 357 // Ecriture des donnees propres a l'histogramme de profil. 358 is.GetLine(strg,255); 359 dobj->SumY = new double[dobj->bins]; 360 dobj->SumY2 = new double[dobj->bins]; 361 dobj->SumW = new double[dobj->bins]; 362 is.Get(dobj->SumY, dobj->bins); 363 is.Get(dobj->SumY2, dobj->bins); 364 is.Get(dobj->SumW, dobj->bins); 365 366 // Ecriture de l'histogramme 367 FIO_Histo fio_h((Histo&)dobj); 368 fio_h.Read(is); 369 370 return; 371 } 372 373 void FIO_HProf::WriteSelf(POutPersist& os) const 374 { 375 if (dobj == NULL) return; 376 char strg[256]; 377 378 dobj->UpdateHisto(); 278 379 279 380 // Ecriture entete pour identifier facilement 280 sprintf(strg,"HProf: YMin=%f YMax=%f Opt=%1d", YMin,YMax,Opt);281 s.PutLine(strg);381 sprintf(strg,"HProf: YMin=%f YMax=%f Opt=%1d",dobj->YMin,dobj->YMax,dobj->Opt); 382 os.PutLine(strg); 282 383 283 384 // Ecriture des valeurs 284 s.PutI4(bins);285 s.PutR4(YMin);286 s.PutR4(YMax);287 s.PutU2(Opt);385 os.Put(dobj->bins); 386 os.Put(dobj->YMin); 387 os.Put(dobj->YMax); 388 os.Put(dobj->Opt); 288 389 289 390 // Ecriture des donnees propres a l'histogramme de profil. 290 391 sprintf(strg,"HProf: SumY SumY2 SumW"); 291 s.PutLine(strg);292 s.PutR8s(SumY,bins);293 s.PutR8s(SumY2,bins);294 s.PutR8s(SumW,bins);392 os.PutLine(strg); 393 os.Put(dobj->SumY, dobj->bins); 394 os.Put(dobj->SumY2, dobj->bins); 395 os.Put(dobj->SumW, dobj->bins); 295 396 296 397 // Ecriture de l'histogramme 297 Histo::WriteSelf(s); 398 FIO_Histo fio_h((Histo&)dobj); 399 fio_h.Write(os); 298 400 299 401 return; 300 402 } 301 302 /********* Methode *********/303 //++304 void HProf::ReadSelf(PInPersist& s)305 //306 // Lecture ppersist307 //--308 {309 char strg[256];310 311 Delete();312 313 // Lecture entete314 s.GetLine(strg,255);315 316 // Ecriture des valeurs317 s.GetI4(bins);318 s.GetR4(YMin);319 s.GetR4(YMax);320 s.GetU2(Opt);321 Ok = true;322 323 // Ecriture des donnees propres a l'histogramme de profil.324 s.GetLine(strg,255);325 SumY = new double[bins];326 SumY2 = new double[bins];327 SumW = new double[bins];328 s.GetR8s(SumY, bins);329 s.GetR8s(SumY2, bins);330 s.GetR8s(SumW, bins);331 332 // Ecriture de l'histogramme333 Histo::ReadSelf(s);334 335 return;336 }337 338 339 // Rappel des inlines functions pour commentaires340 //++341 // inline Histo GetHisto()342 // Retourne l'histogramme de profil.343 //--344 //++345 // inline void GetMean(Vector& v)346 // Retourne le contenu de la moyenne dans le vecteur v347 //--348 //++349 // inline void GetError2(Vector& v)350 // Retourne le contenu au carre de la dispersion/erreur dans le vecteur v351 //--352 //++353 // inline float operator()(int i) const354 // Retourne le contenu du bin i355 //--356 //++357 // inline float Error2(int i) const358 // Retourne le carre de la dispersion/erreur du bin i359 //--360 //++361 // inline float Error(int i) const362 // Retourne la dispersion/erreur du bin i363 //--364 //++365 // inline int Fit(GeneralFit& gfit)366 // Fit du profile par ``gfit''.367 //--368 //++369 // inline Histo* FitResidus(GeneralFit& gfit)370 // Retourne l'Histogramme des residus par ``gfit''.371 //--372 //++373 // inline Histo* FitFunction(GeneralFit& gfit)374 // Retourne l'Histogramme de la fonction fittee par ``gfit''.375 //--376 //++377 // inline void Print(int dyn,float hmin,float hmax,int pflag,int il,int ih)378 // Print, voir detail dans Histo::Print379 //-- -
trunk/SophyaLib/NTools/hisprof.h
r220 r307 8 8 #include "histos.h" 9 9 10 namespace PlanckDPC { 11 10 12 class HProf : public Histo { 11 13 friend class FIO_HProf; 12 14 public: 13 enum {classId = ClassId_HProf };14 15 15 16 // CREATOR / DESTRUCTOR 16 17 HProf(); 17 18 HProf(float xMin, float xMax, int nBin=100, float yMin=1., float yMax=-1.); 18 HProf(char *flnm);19 19 HProf(const HProf& H); 20 20 virtual ~HProf(); … … 44 44 inline int Fit(GeneralFit& gfit) 45 45 {if(!Ok) UpdateHisto(); return Histo::Fit(gfit,0);} 46 inline Histo *FitResidus(GeneralFit& gfit)46 inline Histo FitResidus(GeneralFit& gfit) 47 47 {if(!Ok) UpdateHisto(); return Histo::FitResidus(gfit);} 48 inline Histo *FitFunction(GeneralFit& gfit)48 inline Histo FitFunction(GeneralFit& gfit) 49 49 {if(!Ok) UpdateHisto(); return Histo::FitFunction(gfit);} 50 50 … … 52 52 inline void Print(int dyn=100,float hmin=1.,float hmax=-1.,int pflag=0,int il=1,int ih=-1) 53 53 {if(!Ok) UpdateHisto(); Histo::Print(dyn,hmin,hmax,pflag,il,ih);} 54 55 int_4 ClassId() const { return classId; }56 static PPersist* Create() { return new HProf;}57 58 virtual void WriteSelf(POutPersist&) const;59 virtual void ReadSelf(PInPersist&);60 61 54 62 55 protected: … … 72 65 }; 73 66 67 ///////////////////////////////////////////////////////////////////////// 68 // Classe pour la gestion de persistance 69 class FIO_HProf : public PPersist { 70 public: 71 FIO_HProf(); 72 FIO_HProf(string const & filename); 73 FIO_HProf(const HProf & obj); 74 FIO_HProf(HProf * obj); 75 virtual ~FIO_HProf(); 76 virtual AnyDataObj* DataObj(); 77 inline operator HProf() { return(*dobj); } 78 protected : 79 virtual void ReadSelf(PInPersist&); 80 virtual void WriteSelf(POutPersist&) const; 81 HProf * dobj; 82 bool ownobj; 83 }; 84 85 } // Fin du namespace 86 74 87 #endif // HISPROF_SEEN -
trunk/SophyaLib/NTools/histos.cc
r244 r307 1 1 // 2 // $Id: histos.cc,v 1. 2 1999-04-22 16:18:36ansari Exp $2 // $Id: histos.cc,v 1.3 1999-05-19 15:57:59 ansari Exp $ 3 3 // 4 4 … … 14 14 #include "generalfit.h" 15 15 16 using namespace PlanckDPC; 17 16 18 //++ 17 19 // Class Histo … … 50 52 { 51 53 Zero(); 52 END_CONSTRUCTOR53 }54 55 /********* Methode *********/56 //++57 Histo::Histo(char *flnm)58 //59 //--60 : data(NULL), err2(NULL),61 under(0), over(0), nHist(0), nEntries(0),62 bins(0), min(0), max(0), binWidth(0)63 {64 PInPersist s(flnm);65 Read(s);66 54 END_CONSTRUCTOR 67 55 } … … 379 367 //-- 380 368 { 381 if (b. bins!=a.bins) THROW(sizeMismatchErr);369 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 382 370 Histo c(a); 383 371 return (c += b); … … 389 377 //-- 390 378 { 391 if (b. bins!=a.bins) THROW(sizeMismatchErr);379 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 392 380 Histo c(a); 393 381 return (c -= b); … … 399 387 //-- 400 388 { 401 if (b. bins!=a.bins) THROW(sizeMismatchErr);389 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 402 390 Histo c(a); 403 391 return (c *= b); … … 409 397 //-- 410 398 { 411 if (b. bins!=a.bins) THROW(sizeMismatchErr);399 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 412 400 Histo c(a); 413 401 return (c /= b); … … 1446 1434 1447 1435 //++ 1448 Histo *Histo::FitResidus(GeneralFit& gfit)1436 Histo Histo::FitResidus(GeneralFit& gfit) 1449 1437 // 1450 1438 // Retourne une classe contenant les residus du fit ``gfit''. 1451 1439 //-- 1452 1440 { 1453 if(NBins()<=0) return NULL; 1441 if(NBins()<=0) 1442 throw(SzMismatchError("Histo::FitResidus: size mismatch\n")); 1454 1443 GeneralFunction* f = gfit.GetFunction(); 1455 if(f==NULL) return NULL; 1444 if(f==NULL) 1445 throw(NullPtrError("Histo::FitResidus: NULL pointer\n")); 1456 1446 Vector par = gfit.GetParm(); 1457 Histo * h = new Histo(*this);1447 Histo h(*this); 1458 1448 for(int i=0;i<NBins();i++) { 1459 1449 double x = (double) BinCenter(i); 1460 (*h)(i) -= (float) f->Value(&x,par.Data());1450 h(i) -= (float) f->Value(&x,par.Data()); 1461 1451 } 1462 1452 return h; … … 1464 1454 1465 1455 //++ 1466 Histo *Histo::FitFunction(GeneralFit& gfit)1456 Histo Histo::FitFunction(GeneralFit& gfit) 1467 1457 // 1468 1458 // Retourne une classe contenant la fonction du fit ``gfit''. 1469 1459 //-- 1470 1460 { 1471 if(NBins()<=0) return NULL; 1461 if(NBins()<=0) 1462 throw(SzMismatchError("Histo::FitFunction: size mismatch\n")); 1472 1463 GeneralFunction* f = gfit.GetFunction(); 1473 if(f==NULL) return NULL; 1464 if(f==NULL) 1465 throw(NullPtrError("Histo::FitFunction: NULL pointer\n")); 1474 1466 Vector par = gfit.GetParm(); 1475 Histo * h = new Histo(*this);1467 Histo h(*this); 1476 1468 for(int i=0;i<NBins();i++) { 1477 1469 double x = (double) BinCenter(i); 1478 (*h)(i) = (float) f->Value(&x,par.Data());1470 h(i) = (float) f->Value(&x,par.Data()); 1479 1471 } 1480 1472 return h; … … 1662 1654 Histo::PrintF(stdout, hdyn, hmin, hmax, pflag, il, ih); 1663 1655 } 1664 1665 1666 /********* Methode *********/ 1667 //++ 1668 void Histo::WriteSelf(POutPersist& s) const 1669 // 1670 // Ecriture ppersist 1671 //-- 1656 1657 1658 // Rappel des inlines functions pour commentaires 1659 //++ 1660 // inline float XMin() const 1661 // Retourne l'abscisse minimum 1662 //-- 1663 //++ 1664 // inline float XMax() const 1665 // Retourne l'abscisse maximum 1666 //-- 1667 //++ 1668 // inline int NBins() const 1669 // Retourne le nombre de bins 1670 //-- 1671 //++ 1672 // inline float BinWidth() const 1673 // Retourne la largeur du bin 1674 //-- 1675 //++ 1676 // inline float* Bins() const 1677 // Retourne le pointeur sur le tableaux des contenus 1678 //-- 1679 //++ 1680 // inline float operator()(int i) const 1681 // Retourne le contenu du bin i 1682 //-- 1683 //++ 1684 // inline float& operator()(int i) 1685 // Remplit le contenu du bin i 1686 //-- 1687 //++ 1688 // inline float Error(int i) const 1689 // Retourne l'erreur du bin i 1690 //-- 1691 //++ 1692 // inline double Error2(int i) const 1693 // Retourne l'erreur au carre du bin i 1694 //-- 1695 //++ 1696 // inline double& Error2(int i) 1697 // Remplit l'erreur au carre du bin i 1698 //-- 1699 //++ 1700 // inline float NData() const 1701 // Retourne la somme ponderee 1702 //-- 1703 //++ 1704 // inline float NEntries() 1705 // Retourne le nombre d'entrees 1706 //-- 1707 //++ 1708 // inline float NOver() const 1709 // Retourne le nombre d'overflow 1710 //-- 1711 //++ 1712 // inline float NUnder() const 1713 // Retourne le nombre d'underflow 1714 //-- 1715 //++ 1716 // inline float BinLowEdge(int i) const 1717 // Retourne l'abscisse du bord inferieur du bin i 1718 //-- 1719 //++ 1720 // inline float BinCenter(int i) const 1721 // Retourne l'abscisse du centre du bin i 1722 //-- 1723 //++ 1724 // inline float BinHighEdge(int i) const 1725 // Retourne l'abscisse du bord superieur du bin i 1726 //-- 1727 //++ 1728 // inline int FindBin(float x) const 1729 // Retourne le numero du bin contenant l'abscisse x 1730 //-- 1731 1732 1733 /////////////////////////////////////////////////////////// 1734 // -------------------------------------------------------- 1735 // Les objets delegues pour la gestion de persistance 1736 // -------------------------------------------------------- 1737 /////////////////////////////////////////////////////////// 1738 1739 FIO_Histo::FIO_Histo() 1740 { 1741 dobj=new Histo; 1742 ownobj=true; 1743 } 1744 1745 FIO_Histo::FIO_Histo(string const & filename) 1746 { 1747 dobj=new Histo; 1748 ownobj=true; 1749 Read(filename); 1750 } 1751 1752 FIO_Histo::FIO_Histo(const Histo & obj) 1753 { 1754 dobj = new Histo(obj); 1755 ownobj=true; 1756 } 1757 1758 FIO_Histo::FIO_Histo(Histo * obj) 1759 { 1760 dobj = obj; 1761 ownobj=false; 1762 } 1763 1764 FIO_Histo::~FIO_Histo() 1765 { 1766 if (ownobj && dobj) delete dobj; 1767 } 1768 1769 AnyDataObj* FIO_Histo::DataObj() 1770 { 1771 return(dobj); 1772 } 1773 1774 void FIO_Histo::ReadSelf(PInPersist& is) 1672 1775 { 1673 1776 char strg[256]; 1674 1777 1778 if(dobj==NULL) dobj=new Histo; 1779 else dobj->Delete(); 1780 1781 // Lecture entete 1782 is.GetLine(strg, 255); 1783 is.GetLine(strg, 255); 1784 is.GetLine(strg, 255); 1785 1786 // Lecture des valeurs 1787 is.Get(dobj->bins); 1788 is.Get(dobj->nEntries); 1789 int_4 errok; 1790 is.Get(errok); 1791 1792 is.Get(dobj->binWidth); 1793 is.Get(dobj->min); 1794 is.Get(dobj->max); 1795 is.Get(dobj->under); 1796 is.Get(dobj->over); 1797 1798 is.Get(dobj->nHist); 1799 1800 // Lecture des donnees Histo 1D 1801 dobj->data = new float[dobj->bins]; 1802 is.GetLine(strg, 255); 1803 is.Get(dobj->data, dobj->bins); 1804 1805 // Lecture des erreurs 1806 if(errok) { 1807 is.GetLine(strg, 255); 1808 dobj->err2 = new double[dobj->bins]; 1809 is.Get(dobj->err2, dobj->bins); 1810 } 1811 1812 return; 1813 } 1814 1815 void FIO_Histo::WriteSelf(POutPersist& os) const 1816 { 1817 if (dobj == NULL) return; 1818 char strg[256]; 1819 1675 1820 // Que faut-il ecrire? 1676 int errok = ( err2) ? 1 : 0;1821 int errok = (dobj->err2) ? 1 : 0; 1677 1822 1678 1823 // Ecriture entete pour identifier facilement 1679 sprintf(strg,"bins=%6d NEnt=%15d errok=%1d", bins,nEntries,errok);1680 s.PutLine(strg);1681 sprintf(strg,"binw=%g min=%g max=%g", binWidth,min,max);1682 s.PutLine(strg);1683 sprintf(strg, "under=%g over=%g nHist=%g", under,over,nHist);1684 s.PutLine(strg);1824 sprintf(strg,"bins=%6d NEnt=%15d errok=%1d",dobj->bins,dobj->nEntries,errok); 1825 os.PutLine(strg); 1826 sprintf(strg,"binw=%g min=%g max=%g",dobj->binWidth,dobj->min,dobj->max); 1827 os.PutLine(strg); 1828 sprintf(strg, "under=%g over=%g nHist=%g",dobj->under,dobj->over,dobj->nHist); 1829 os.PutLine(strg); 1685 1830 1686 1831 // Ecriture des valeurs 1687 s.PutI4(bins);1688 s.PutI4(nEntries);1689 s.PutI4(errok);1690 1691 s.PutR4(binWidth);1692 s.PutR4(min);1693 s.PutR4(max);1694 s.PutR4(under);1695 s.PutR4(over);1696 1697 s.PutR8(nHist);1832 os.Put(dobj->bins); 1833 os.Put(dobj->nEntries); 1834 os.Put(errok); 1835 1836 os.Put(dobj->binWidth); 1837 os.Put(dobj->min); 1838 os.Put(dobj->max); 1839 os.Put(dobj->under); 1840 os.Put(dobj->over); 1841 1842 os.Put(dobj->nHist); 1698 1843 1699 1844 // Ecriture des donnees Histo 1D 1700 sprintf(strg,"Histo: Tableau des donnees %d", bins);1701 s.PutLine(strg);1702 s.PutR4s(data,bins);1845 sprintf(strg,"Histo: Tableau des donnees %d",dobj->bins); 1846 os.PutLine(strg); 1847 os.Put(dobj->data, dobj->bins); 1703 1848 1704 1849 // Ecriture des erreurs 1705 1850 if(errok) { 1706 sprintf(strg,"Histo: Tableau des erreurs %d", bins);1707 s.PutLine(strg);1708 s.PutR8s(err2,bins);1851 sprintf(strg,"Histo: Tableau des erreurs %d",dobj->bins); 1852 os.PutLine(strg); 1853 os.Put(dobj->err2, dobj->bins); 1709 1854 } 1710 1855 1711 1856 return; 1712 1857 } 1713 1714 /********* Methode *********/1715 //++1716 void Histo::ReadSelf(PInPersist& s)1717 //1718 // Lecture ppersist1719 //--1720 {1721 char strg[256];1722 1723 Delete();1724 1725 // Lecture entete1726 s.GetLine(strg, 255);1727 s.GetLine(strg, 255);1728 s.GetLine(strg, 255);1729 1730 // Lecture des valeurs1731 s.GetI4(bins);1732 s.GetI4(nEntries);1733 int_4 errok;1734 s.GetI4(errok);1735 1736 s.GetR4(binWidth);1737 s.GetR4(min);1738 s.GetR4(max);1739 s.GetR4(under);1740 s.GetR4(over);1741 1742 s.GetR8(nHist);1743 1744 // Lecture des donnees Histo 1D1745 data = new float[bins];1746 s.GetLine(strg, 255);1747 s.GetR4s(data, bins);1748 1749 // Lecture des erreurs1750 if(errok) {1751 s.GetLine(strg, 255);1752 err2 = new double[bins];1753 s.GetR8s(err2, bins);1754 }1755 1756 return;1757 }1758 1759 1760 1761 // Rappel des inlines functions pour commentaires1762 //++1763 // inline float XMin() const1764 // Retourne l'abscisse minimum1765 //--1766 //++1767 // inline float XMax() const1768 // Retourne l'abscisse maximum1769 //--1770 //++1771 // inline int NBins() const1772 // Retourne le nombre de bins1773 //--1774 //++1775 // inline float BinWidth() const1776 // Retourne la largeur du bin1777 //--1778 //++1779 // inline float* Bins() const1780 // Retourne le pointeur sur le tableaux des contenus1781 //--1782 //++1783 // inline float operator()(int i) const1784 // Retourne le contenu du bin i1785 //--1786 //++1787 // inline float& operator()(int i)1788 // Remplit le contenu du bin i1789 //--1790 //++1791 // inline float Error(int i) const1792 // Retourne l'erreur du bin i1793 //--1794 //++1795 // inline double Error2(int i) const1796 // Retourne l'erreur au carre du bin i1797 //--1798 //++1799 // inline double& Error2(int i)1800 // Remplit l'erreur au carre du bin i1801 //--1802 //++1803 // inline float NData() const1804 // Retourne la somme ponderee1805 //--1806 //++1807 // inline float NEntries()1808 // Retourne le nombre d'entrees1809 //--1810 //++1811 // inline float NOver() const1812 // Retourne le nombre d'overflow1813 //--1814 //++1815 // inline float NUnder() const1816 // Retourne le nombre d'underflow1817 //--1818 //++1819 // inline float BinLowEdge(int i) const1820 // Retourne l'abscisse du bord inferieur du bin i1821 //--1822 //++1823 // inline float BinCenter(int i) const1824 // Retourne l'abscisse du centre du bin i1825 //--1826 //++1827 // inline float BinHighEdge(int i) const1828 // Retourne l'abscisse du bord superieur du bin i1829 //--1830 //++1831 // inline int FindBin(float x) const1832 // Retourne le numero du bin contenant l'abscisse x1833 //-- -
trunk/SophyaLib/NTools/histos.h
r220 r307 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: histos.h,v 1. 1.1.1 1999-04-09 17:57:56ansari Exp $3 // $Id: histos.h,v 1.2 1999-05-19 15:58:00 ansari Exp $ 4 4 // 5 5 … … 11 11 #include "cvector.h" 12 12 #include "ppersist.h" 13 #include "anydataobj.h" 14 15 namespace PlanckDPC { 13 16 14 17 class GeneralFit; 15 18 16 class Histo : public PPersist{17 19 class Histo : public AnyDataObj { 20 friend class FIO_Histo; 18 21 public: 19 enum {classId = ClassId_Histo1D };20 22 21 23 // CREATOR / DESTRUCTOR 22 24 Histo(); 23 25 Histo(float xMin, float xMax, int nBin=100); 24 Histo(char *flnm);25 26 Histo(const Histo& H); 26 27 virtual ~Histo(); … … 131 132 // Fit 132 133 int Fit(GeneralFit& gfit,unsigned short typ_err=0); 133 Histo *FitResidus(GeneralFit& gfit);134 Histo *FitFunction(GeneralFit& gfit);134 Histo FitResidus(GeneralFit& gfit); 135 Histo FitFunction(GeneralFit& gfit); 135 136 136 137 // Print et Display ASCII … … 139 140 void Print(int dyn = 100, float hmin = 1., float hmax = -1., 140 141 int pflag = 0, int il = 1, int ih = -1); 141 142 // PPersist objet143 int_4 ClassId() const { return classId; }144 static PPersist* Create() { return new Histo;}145 146 virtual void WriteSelf(POutPersist&) const;147 virtual void ReadSelf(PInPersist&);148 149 142 150 143 protected: … … 163 156 }; 164 157 158 ///////////////////////////////////////////////////////////////////////// 159 // Classe pour la gestion de persistance 160 class FIO_Histo : public PPersist { 161 public: 162 FIO_Histo(); 163 FIO_Histo(string const & filename); 164 FIO_Histo(const Histo & obj); 165 FIO_Histo(Histo * obj); 166 virtual ~FIO_Histo(); 167 virtual AnyDataObj* DataObj(); 168 inline operator Histo() { return(*dobj); } 169 protected : 170 virtual void ReadSelf(PInPersist&); 171 virtual void WriteSelf(POutPersist&) const; 172 Histo * dobj; 173 bool ownobj; 174 }; 175 176 } // Fin du namespace 177 165 178 #endif // HISTOS_SEEN -
trunk/SophyaLib/NTools/histos2.cc
r244 r307 16 16 #include "generalfit.h" 17 17 18 using namespace PlanckDPC; 19 18 20 //++ 19 21 // Class Histo2D … … 132 134 for(int i=0;i<3;i++) for(int j=0;j<3;j++) over[i][j]=0.; 133 135 b_s.H = NULL; 134 END_CONSTRUCTOR135 }136 137 //++138 Histo2D::Histo2D(char *flnm)139 //140 // Constructeur par lecture d'un fichier ppersist.141 //--142 : data(NULL), err2(NULL)143 , nHist(0), nEntries(0)144 , nx(0), ny(0), nxy(0)145 , xmin(0), xmax(0), ymin(0), ymax(0)146 , wbinx(0), wbiny(0)147 , hprojx(NULL), hprojy(NULL)148 {149 b_s.H = NULL;150 PInPersist s(flnm);151 Read(s);152 136 END_CONSTRUCTOR 153 137 } … … 582 566 //-- 583 567 { 584 if (b. nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);568 if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr); 585 569 Histo2D c(a); 586 570 return (c += b); … … 592 576 //-- 593 577 { 594 if (b. nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);578 if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr); 595 579 Histo2D c(a); 596 580 return (c -= b); … … 602 586 //-- 603 587 { 604 if (b. nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);588 if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr); 605 589 Histo2D c(a); 606 590 return (c *= b); … … 612 596 //-- 613 597 { 614 if (b. nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);598 if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr); 615 599 Histo2D c(a); 616 600 return (c /= b); … … 1113 1097 1114 1098 //++ 1115 Histo2D *Histo2D::FitResidus(GeneralFit& gfit)1099 Histo2D Histo2D::FitResidus(GeneralFit& gfit) 1116 1100 // 1117 1101 // Retourne une classe contenant les residus du fit ``gfit''. 1118 1102 //-- 1119 1103 { 1120 if(NBinX()<=0 || NBinY()<=0) return NULL; 1104 if(NBinX()<=0 || NBinY()<=0) 1105 throw(SzMismatchError("Histo2D::FitResidus: size mismatch\n")); 1121 1106 GeneralFunction* f = gfit.GetFunction(); 1122 if(f==NULL) return NULL; 1107 if(f==NULL) 1108 throw(NullPtrError("Histo2D::FitResidus: NULL pointer\n")); 1123 1109 Vector par = gfit.GetParm(); 1124 Histo2D * h2 = new Histo2D(*this);1110 Histo2D h2(*this); 1125 1111 for(int i=0;i<NBinX();i++) for(int j=0;j<NBinY();j++) { 1126 1112 float xc,yc; 1127 1113 BinCenter(i,j,xc,yc); 1128 1114 double x[2] = {(double)xc,(double)yc}; 1129 (*h2)(i,j) -= (float) f->Value(x,par.Data());1115 h2(i,j) -= (float) f->Value(x,par.Data()); 1130 1116 } 1131 1117 return h2; … … 1133 1119 1134 1120 //++ 1135 Histo2D *Histo2D::FitFunction(GeneralFit& gfit)1121 Histo2D Histo2D::FitFunction(GeneralFit& gfit) 1136 1122 // 1137 1123 // Retourne une classe contenant la fonction du fit ``gfit''. 1138 1124 //-- 1139 1125 { 1140 if(NBinX()<=0 || NBinY()<=0) return NULL; 1126 if(NBinX()<=0 || NBinY()<=0) 1127 throw(SzMismatchError("Histo2D::FitFunction: size mismatch\n")); 1141 1128 GeneralFunction* f = gfit.GetFunction(); 1142 if(f==NULL) return NULL; 1129 if(f==NULL) 1130 throw(NullPtrError("Histo2D::FitFunction: NULL pointer\n")); 1143 1131 Vector par = gfit.GetParm(); 1144 Histo2D * h2 = new Histo2D(*this);1132 Histo2D h2(*this); 1145 1133 for(int i=0;i<NBinX();i++) for(int j=0;j<NBinY();j++) { 1146 1134 float xc,yc; 1147 1135 BinCenter(i,j,xc,yc); 1148 1136 double x[2] = {(double)xc,(double)yc}; 1149 (*h2)(i,j) = (float) f->Value(x,par.Data());1137 h2(i,j) = (float) f->Value(x,par.Data()); 1150 1138 } 1151 1139 return h2; … … 1792 1780 1793 1781 1794 /////////////////////////////////////////////////////////////////// 1795 //++ 1796 // Titre Methodes pour ecriture ppersist 1797 //-- 1798 1799 //++ 1800 void Histo2D::WriteSelf(POutPersist& s) const 1801 // 1802 // Ecriture fichier de type ppersist. 1803 //-- 1782 /////////////////////////////////////////////////////////// 1783 // -------------------------------------------------------- 1784 // Les objets delegues pour la gestion de persistance 1785 // -------------------------------------------------------- 1786 /////////////////////////////////////////////////////////// 1787 1788 FIO_Histo2D::FIO_Histo2D() 1789 { 1790 dobj=new Histo2D; 1791 ownobj=true; 1792 } 1793 1794 FIO_Histo2D::FIO_Histo2D(string const & filename) 1795 { 1796 dobj=new Histo2D; 1797 ownobj=true; 1798 Read(filename); 1799 } 1800 1801 FIO_Histo2D::FIO_Histo2D(const Histo2D & obj) 1802 { 1803 dobj = new Histo2D(obj); 1804 ownobj=true; 1805 } 1806 1807 FIO_Histo2D::FIO_Histo2D(Histo2D * obj) 1808 { 1809 dobj = obj; 1810 ownobj=false; 1811 } 1812 1813 FIO_Histo2D::~FIO_Histo2D() 1814 { 1815 if (ownobj && dobj) delete dobj; 1816 } 1817 1818 AnyDataObj* FIO_Histo2D::DataObj() 1819 { 1820 return(dobj); 1821 } 1822 1823 void FIO_Histo2D::ReadSelf(PInPersist& is) 1804 1824 { 1805 1825 char strg[256]; 1806 int j; 1826 1827 if(dobj==NULL) dobj=new Histo2D; 1828 else dobj->Delete(); 1829 1807 1830 float min,max; 1808 1831 Histo* h; 1832 int_4 errok, projx, projy, nslix, nsliy, nbanx, nbany; 1833 1834 // Lecture entete 1835 is.GetLine(strg, 255); 1836 is.GetLine(strg, 255); 1837 is.GetLine(strg, 255); 1838 is.GetLine(strg, 255); 1839 is.GetLine(strg, 255); 1840 is.GetLine(strg, 255); 1841 1842 // Lecture variables de definitions 1843 is.Get(dobj->nx); 1844 is.Get(dobj->ny); 1845 is.Get(dobj->nxy); 1846 is.Get(errok); 1847 is.Get(dobj->nEntries); 1848 is.Get(dobj->nHist); 1849 1850 is.Get(dobj->xmin); 1851 is.Get(dobj->xmax); 1852 is.Get(dobj->ymin); 1853 is.Get(dobj->ymax); 1854 is.Get(dobj->wbinx); 1855 is.Get(dobj->wbiny); 1856 1857 is.Get(&(dobj->over[0][0]),9); 1858 1859 is.Get(projx); 1860 is.Get(projy); 1861 is.Get(nslix); 1862 is.Get(nsliy); 1863 is.Get(nbanx); 1864 is.Get(nbany); 1865 1866 // Lecture histo2D 1867 dobj->data = new float[dobj->nxy]; 1868 is.GetLine(strg, 255); 1869 {for(int j=0;j<dobj->ny;j++) is.Get(dobj->data+j*dobj->nx,dobj->nx);} 1870 1871 // Lecture erreurs 1872 if(errok) { 1873 is.GetLine(strg, 255); 1874 dobj->err2 = new double[dobj->nxy]; 1875 for(int j=0;j<dobj->ny;j++) is.Get(dobj->err2+j*dobj->nx,dobj->nx); 1876 } 1877 1878 // Lecture des projections 1879 if(projx) { 1880 is.GetLine(strg, 255); 1881 dobj->SetProjX(); 1882 FIO_Histo fio_h(dobj->hprojx); 1883 fio_h.Read(is); 1884 } 1885 if(projy) { 1886 is.GetLine(strg, 255); 1887 dobj->SetProjY(); 1888 FIO_Histo fio_h(dobj->hprojy); 1889 fio_h.Read(is); 1890 } 1891 1892 // Lecture des slices 1893 if(nslix>0) { 1894 is.GetLine(strg, 255); 1895 dobj->SetSliX(nslix); 1896 DBASSERT (nslix==dobj->NSliX()); 1897 for(int j=0;j<dobj->NSliX();j++) 1898 {FIO_Histo fio_h(dobj->HSliX(j)); fio_h.Read(is);} 1899 } 1900 if(nsliy>0) { 1901 is.GetLine(strg, 255); 1902 dobj->SetSliY(nsliy); 1903 DBASSERT (nsliy==dobj->NSliY()); 1904 for(int j=0;j<dobj->NSliY();j++) 1905 {FIO_Histo fio_h(dobj->HSliY(j)); fio_h.Read(is);} 1906 } 1907 1908 // Lecture des bandes 1909 if( nbanx>0 ) { 1910 is.GetLine(strg, 255); 1911 {for(int j=0; j<nbanx; j++) { 1912 is.Get(min); is.Get(max); 1913 dobj->SetBandX(min,max); 1914 }} 1915 DBASSERT (nbanx==dobj->NBandX()); 1916 {for(int j=0; j<dobj->NBandX(); j++) { 1917 FIO_Histo fio_h(dobj->HBandX(j)); 1918 fio_h.Read(is); 1919 }} 1920 } 1921 if( nbany>0 ) { 1922 is.GetLine(strg, 255); 1923 {for(int j=0; j<nbany; j++) { 1924 is.Get(min); is.Get(max); 1925 dobj->SetBandY(min,max); 1926 }} 1927 DBASSERT (nbany==dobj->NBandY()); 1928 {for(int j=0; j<dobj->NBandY(); j++) { 1929 FIO_Histo fio_h(dobj->HBandY(j)); 1930 fio_h.Read(is); 1931 }} 1932 } 1933 1934 return; 1935 } 1936 1937 void FIO_Histo2D::WriteSelf(POutPersist& os) const 1938 { 1939 if (dobj == NULL) return; 1940 char strg[256]; 1809 1941 1810 1942 // Que faut-il ecrire? 1811 int_4 errok = ( err2) ? 1 : 0;1812 int_4 projx = ( hprojx) ? 1 : 0;1813 int_4 projy = ( hprojy) ? 1 : 0;1814 int_4 nslix = NSliX();1815 int_4 nsliy = NSliY();1816 int_4 nbanx = NBandX();1817 int_4 nbany = NBandY();1943 int_4 errok = (dobj->err2) ? 1 : 0; 1944 int_4 projx = (dobj->hprojx) ? 1 : 0; 1945 int_4 projy = (dobj->hprojy) ? 1 : 0; 1946 int_4 nslix = dobj->NSliX(); 1947 int_4 nsliy = dobj->NSliY(); 1948 int_4 nbanx = dobj->NBandX(); 1949 int_4 nbany = dobj->NBandY(); 1818 1950 1819 1951 // Ecriture entete pour identifier facilement 1820 sprintf(strg,"nx=%d ny=%d nxy=%d errok=%1d",nx,ny,nxy,errok); 1821 s.PutLine(strg); 1822 sprintf(strg,"nHist=%g nEntries=%d",nHist,nEntries); 1823 s.PutLine(strg); 1824 sprintf(strg,"wbinx=%g wbiny=%g",wbinx,wbiny); 1825 s.PutLine(strg); 1826 sprintf(strg,"xmin=%g xmax=%g ymin=%g ymax=%g",xmin,xmax,ymin,ymax); 1827 s.PutLine(strg); 1952 sprintf(strg,"nx=%d ny=%d nxy=%d errok=%1d" 1953 ,dobj->nx,dobj->ny,dobj->nxy,errok); 1954 os.PutLine(strg); 1955 sprintf(strg,"nHist=%g nEntries=%d",dobj->nHist,dobj->nEntries); 1956 os.PutLine(strg); 1957 sprintf(strg,"wbinx=%g wbiny=%g",dobj->wbinx,dobj->wbiny); 1958 os.PutLine(strg); 1959 sprintf(strg,"xmin=%g xmax=%g ymin=%g ymax=%g" 1960 ,dobj->xmin,dobj->xmax,dobj->ymin,dobj->ymax); 1961 os.PutLine(strg); 1828 1962 sprintf(strg,"projx/y=%d %d nbandx/y=%d %d nbslix/y=%d %d" 1829 1963 ,projx,projy,nbanx,nbany,nslix,nsliy); 1830 s.PutLine(strg);1964 os.PutLine(strg); 1831 1965 sprintf(strg,"over %g %g %g %g %g %g %g %g %g" 1832 , over[0][0],over[0][1],over[0][2]1833 , over[1][0],over[1][1],over[1][2]1834 , over[2][0],over[2][1],over[2][2]);1835 s.PutLine(strg);1966 ,dobj->over[0][0],dobj->over[0][1],dobj->over[0][2] 1967 ,dobj->over[1][0],dobj->over[1][1],dobj->over[1][2] 1968 ,dobj->over[2][0],dobj->over[2][1],dobj->over[2][2]); 1969 os.PutLine(strg); 1836 1970 1837 1971 // Ecriture variables de definitions 1838 s.PutI4(nx);1839 s.PutI4(ny);1840 s.PutI4(nxy);1841 s.PutI4(errok);1842 s.PutI4(nEntries);1843 s.PutR8(nHist);1844 1845 s.PutR4(xmin);1846 s.PutR4(xmax);1847 s.PutR4(ymin);1848 s.PutR4(ymax);1849 s.PutR4(wbinx);1850 s.PutR4(wbiny);1851 1852 s.PutR4s(&over[0][0],9);1853 1854 s.PutI4(projx);1855 s.PutI4(projy);1856 s.PutI4(nslix);1857 s.PutI4(nsliy);1858 s.PutI4(nbanx);1859 s.PutI4(nbany);1972 os.Put(dobj->nx); 1973 os.Put(dobj->ny); 1974 os.Put(dobj->nxy); 1975 os.Put(errok); 1976 os.Put(dobj->nEntries); 1977 os.Put(dobj->nHist); 1978 1979 os.Put(dobj->xmin); 1980 os.Put(dobj->xmax); 1981 os.Put(dobj->ymin); 1982 os.Put(dobj->ymax); 1983 os.Put(dobj->wbinx); 1984 os.Put(dobj->wbiny); 1985 1986 os.Put(&(dobj->over[0][0]),9); 1987 1988 os.Put(projx); 1989 os.Put(projy); 1990 os.Put(nslix); 1991 os.Put(nsliy); 1992 os.Put(nbanx); 1993 os.Put(nbany); 1860 1994 1861 1995 // Ecriture histo2D 1862 sprintf(strg,"Histo2D: Tableau des donnees %d = %d * %d" ,nxy,nx,ny);1863 s.PutLine(strg);1864 for(j=0;j<ny;j++) s.PutR4s(data+j*nx,nx);1865 1996 sprintf(strg,"Histo2D: Tableau des donnees %d = %d * %d" 1997 ,dobj->nxy,dobj->nx,dobj->ny); 1998 os.PutLine(strg); 1999 {for(int j=0;j<dobj->ny;j++) os.Put(dobj->data+j*dobj->nx,dobj->nx);} 1866 2000 1867 2001 // Ecriture erreurs 1868 2002 if(errok) { 1869 sprintf(strg,"Histo2D: Tableau des erreurs %d = %d * %d",nxy,nx,ny); 1870 s.PutLine(strg); 1871 for(j=0;j<ny;j++) s.PutR8s(err2+j*nx,nx); 2003 sprintf(strg,"Histo2D: Tableau des erreurs %d = %d * %d" 2004 ,dobj->nxy,dobj->nx,dobj->ny); 2005 os.PutLine(strg); 2006 for(int j=0;j<dobj->ny;j++) os.Put(dobj->err2+j*dobj->nx,dobj->nx); 1872 2007 } 1873 2008 … … 1875 2010 if(projx) { 1876 2011 sprintf(strg,"Histo2D: Projection X"); 1877 s.PutLine(strg);1878 hprojx->Write(s);2012 os.PutLine(strg); 2013 FIO_Histo fio_h(dobj->hprojx); fio_h.Write(os); 1879 2014 } 1880 2015 if(projy) { 1881 2016 sprintf(strg,"Histo2D: Projection Y"); 1882 s.PutLine(strg);1883 hprojy->Write(s);2017 os.PutLine(strg); 2018 FIO_Histo fio_h(dobj->hprojy); fio_h.Write(os); 1884 2019 } 1885 2020 … … 1887 2022 if(nslix>0) { 1888 2023 sprintf(strg,"Histo2D: Slices X %d",nslix); 1889 s.PutLine(strg);1890 for( j=0;j<nslix;j++) {1891 h =HSliX(j);1892 h->Write(s);2024 os.PutLine(strg); 2025 for(int j=0;j<nslix;j++) { 2026 Histo* h = dobj->HSliX(j); 2027 FIO_Histo fio_h(h); fio_h.Write(os); 1893 2028 } 1894 2029 } 1895 2030 if(nsliy>0) { 1896 2031 sprintf(strg,"Histo2D: Slices Y %d",nsliy); 1897 s.PutLine(strg);1898 for( j=0;j<nsliy;j++) {1899 h =HSliY(j);1900 h->Write(s);2032 os.PutLine(strg); 2033 for(int j=0;j<nsliy;j++) { 2034 Histo* h = dobj->HSliY(j); 2035 FIO_Histo fio_h(h); fio_h.Write(os); 1901 2036 } 1902 2037 } … … 1905 2040 if( nbanx>0 ) { 1906 2041 sprintf(strg,"Histo2D: Bandes X %d",nbanx); 1907 s.PutLine(strg); 1908 list<bande_slice>::const_iterator it; 1909 for(it = lbandx.begin(); it != lbandx.end(); it++) { 1910 min = (*it).min; 1911 max = (*it).max; 1912 s.PutR4(min); 1913 s.PutR4(max); 1914 } 1915 for(it = lbandx.begin(); it != lbandx.end(); it++) { 1916 h = (*it).H; 1917 h->Write(s); 2042 os.PutLine(strg); 2043 list<Histo2D::bande_slice>::const_iterator it; 2044 for(it = dobj->lbandx.begin(); it != dobj->lbandx.end(); it++) { 2045 float min = (*it).min; float max = (*it).max; 2046 os.Put(min); os.Put(max); 2047 } 2048 for(it = dobj->lbandx.begin(); it != dobj->lbandx.end(); it++) { 2049 Histo* h = (*it).H; 2050 FIO_Histo fio_h(h); fio_h.Write(os); 1918 2051 } 1919 2052 } 1920 2053 if( nbany>0 ) { 1921 2054 sprintf(strg,"Histo2D: Bandes Y %d",nbany); 1922 s.PutLine(strg); 1923 list<bande_slice>::const_iterator it; 1924 for(it = lbandy.begin(); it != lbandy.end(); it++) { 1925 min = (*it).min; 1926 max = (*it).max; 1927 s.PutR4(min); 1928 s.PutR4(max); 1929 } 1930 for(it = lbandy.begin(); it != lbandy.end(); it++) { 1931 h = (*it).H; 1932 h->Write(s); 2055 os.PutLine(strg); 2056 list<Histo2D::bande_slice>::const_iterator it; 2057 for(it = dobj->lbandy.begin(); it != dobj->lbandy.end(); it++) { 2058 float min = (*it).min; float max = (*it).max; 2059 os.Put(min); os.Put(max); 2060 } 2061 for(it = dobj->lbandy.begin(); it != dobj->lbandy.end(); it++) { 2062 Histo* h = (*it).H; 2063 FIO_Histo fio_h(h); fio_h.Write(os); 1933 2064 } 1934 2065 } … … 1936 2067 return; 1937 2068 } 1938 1939 //++1940 void Histo2D::ReadSelf(PInPersist& s)1941 //1942 // Lecture fichier de type ppersist.1943 //--1944 {1945 Delete();1946 1947 int j;1948 float min,max;1949 Histo* h;1950 char strg[256];1951 int_4 errok, projx, projy, nslix, nsliy, nbanx, nbany;1952 1953 // Lecture entete1954 s.GetLine(strg, 255);1955 s.GetLine(strg, 255);1956 s.GetLine(strg, 255);1957 s.GetLine(strg, 255);1958 s.GetLine(strg, 255);1959 s.GetLine(strg, 255);1960 1961 1962 // Lecture variables de definitions1963 s.GetI4(nx);1964 s.GetI4(ny);1965 s.GetI4(nxy);1966 s.GetI4(errok);1967 s.GetI4(nEntries);1968 s.GetR8(nHist);1969 1970 s.GetR4(xmin);1971 s.GetR4(xmax);1972 s.GetR4(ymin);1973 s.GetR4(ymax);1974 s.GetR4(wbinx);1975 s.GetR4(wbiny);1976 1977 s.GetR4s(&over[0][0],9);1978 1979 s.GetI4(projx);1980 s.GetI4(projy);1981 s.GetI4(nslix);1982 s.GetI4(nsliy);1983 s.GetI4(nbanx);1984 s.GetI4(nbany);1985 1986 // Lecture histo2D1987 data = new float[nxy];1988 s.GetLine(strg, 255);1989 for(j=0;j<ny;j++) s.GetR4s(data+j*nx,nx);1990 1991 // Lecture erreurs1992 if(errok) {1993 s.GetLine(strg, 255);1994 err2 = new double[nxy];1995 for(j=0;j<ny;j++) s.GetR8s(err2+j*nx,nx);1996 }1997 1998 // Lecture des projections1999 if(projx) {2000 s.GetLine(strg, 255);2001 SetProjX();2002 hprojx->Read(s);2003 }2004 if(projy) {2005 s.GetLine(strg, 255);2006 SetProjY();2007 hprojy->Read(s);2008 }2009 2010 // Lecture des slices2011 if(nslix>0) {2012 s.GetLine(strg, 255);2013 SetSliX(nslix);2014 DBASSERT (nslix==NSliX());2015 for(j=0;j<NSliX();j++) HSliX(j)->Read(s);2016 }2017 if(nsliy>0) {2018 s.GetLine(strg, 255);2019 SetSliY(nsliy);2020 DBASSERT (nsliy==NSliY());2021 for(j=0;j<NSliY();j++) HSliY(j)->Read(s);2022 }2023 2024 // Lecture des bandes2025 if( nbanx>0 ) {2026 s.GetLine(strg, 255);2027 for( j=0; j<nbanx; j++) {2028 s.GetR4(min);2029 s.GetR4(max);2030 SetBandX(min,max);2031 }2032 DBASSERT (nbanx==NBandX());2033 for( j=0; j<NBandX(); j++) {2034 h = HBandX(j);2035 h->Read(s);2036 }2037 }2038 if( nbany>0 ) {2039 s.GetLine(strg, 255);2040 for( j=0; j<nbany; j++) {2041 s.GetR4(min);2042 s.GetR4(max);2043 SetBandY(min,max);2044 }2045 DBASSERT (nbany==NBandY());2046 for( j=0; j<NBandY(); j++) {2047 h = HBandY(j);2048 h->Read(s);2049 }2050 }2051 2052 return;2053 } -
trunk/SophyaLib/NTools/histos2.h
r244 r307 15 15 16 16 #include "peida.h" 17 #include "utils.h" 17 18 #include "histos.h" 18 #include "utils.h" 19 #include "ppersist.h" 20 19 20 namespace PlanckDPC { 21 21 22 22 class GeneralFit; 23 23 24 25 class Histo2D : public PPersist { 26 24 class Histo2D : public AnyDataObj { 25 friend class FIO_Histo2D; 27 26 public: 28 enum {classId = ClassId_Histo2D };29 27 30 28 // CREATOR / DESTRUCTOR … … 33 31 Histo2D(const Histo2D& h); 34 32 Histo2D(); 35 Histo2D(char *flnm);36 37 33 virtual ~Histo2D(); 38 34 … … 125 121 // Fit 126 122 int Fit(GeneralFit& gfit,unsigned short typ_err=0); 127 Histo2D *FitResidus(GeneralFit& gfit);128 Histo2D *FitFunction(GeneralFit& gfit);123 Histo2D FitResidus(GeneralFit& gfit); 124 Histo2D FitFunction(GeneralFit& gfit); 129 125 130 126 // Print et Display ASCII … … 175 171 void ShowSli(int lp = 0); 176 172 177 int_4 ClassId() const { return classId; }178 static PPersist* Create() { return new Histo2D;}179 180 virtual void WriteSelf(POutPersist&) const;181 virtual void ReadSelf(PInPersist&);182 183 173 #ifndef __DECCXX 184 174 protected: … … 224 214 }; 225 215 216 ///////////////////////////////////////////////////////////////////////// 217 // Classe pour la gestion de persistance 218 class FIO_Histo2D : public PPersist { 219 public: 220 FIO_Histo2D(); 221 FIO_Histo2D(string const & filename); 222 FIO_Histo2D(const Histo2D & obj); 223 FIO_Histo2D(Histo2D * obj); 224 virtual ~FIO_Histo2D(); 225 virtual AnyDataObj* DataObj(); 226 inline operator Histo2D() { return(*dobj); } 227 protected : 228 virtual void ReadSelf(PInPersist&); 229 virtual void WriteSelf(POutPersist&) const; 230 Histo2D * dobj; 231 bool ownobj; 232 }; 233 234 } // Fin du namespace 235 226 236 #endif // HISTOS2_SEEN -
trunk/SophyaLib/NTools/integ.h
r244 r307 3 3 // integ.h 4 4 // 5 // $Id: integ.h,v 1. 2 1999-04-22 16:18:40ansari Exp $5 // $Id: integ.h,v 1.3 1999-05-19 15:58:01 ansari Exp $ 6 6 // 7 7 … … 16 16 #endif 17 17 18 class GeneralFunction; 18 namespace PlanckDPC {class GeneralFunction;} 19 19 20 20 class Integrator EXC_AWARE { -
trunk/SophyaLib/NTools/matrix.cc
r288 r307 1 // $Id: matrix.cc,v 1. 3 1999-05-03 16:55:21ansari Exp $1 // $Id: matrix.cc,v 1.4 1999-05-19 15:58:02 ansari Exp $ 2 2 3 3 #include "machdefs.h" … … 983 983 ////////////////////////////////////////////////////////// 984 984 //++ 985 Matrix* Matrix::FitResidus(GeneralFit& gfit) 985 Matrix Matrix::FitResidus(GeneralFit& gfit 986 ,double xorg,double yorg,double dx,double dy) 986 987 // 987 988 // Retourne une classe contenant les residus du fit ``gfit''. 988 // On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j). 989 //-- 990 { 991 if(NCol()<=0||NRows()<=0) return NULL; 989 // Les coordonnees de l'element (i,j) sont : 990 // (i,j) -> x = xorg + j*dx , y = yorg + i*dy 991 //-- 992 { 993 if(NCol()<=0||NRows()<=0) 994 throw(SzMismatchError("Matrix::FitResidus: size mismatch\n")); 992 995 GeneralFunction* f = gfit.GetFunction(); 993 if(f==NULL) return NULL; 996 if(f==NULL) 997 throw(NullPtrError("Matrix::FitResidus: NULL pointer\n")); 994 998 Vector par = gfit.GetParm(); 995 Matrix * m = new Matrix(*this);999 Matrix m(*this); 996 1000 for(int i=0;i<NRows();i++) for(int j=0;j<NCol();j++) { 997 double x[2] = { (double)j,(double)i};998 (*m)(i,j) -= f->Value(x,par.Data());1001 double x[2] = {xorg+j*dx,yorg+i*dy}; 1002 m(i,j) -= f->Value(x,par.Data()); 999 1003 } 1000 1004 return m; … … 1002 1006 1003 1007 //++ 1004 Matrix* Matrix::FitFunction(GeneralFit& gfit) 1008 Matrix Matrix::FitFunction(GeneralFit& gfit 1009 ,double xorg,double yorg,double dx,double dy) 1005 1010 // 1006 1011 // Retourne une classe contenant la fonction du fit ``gfit''. 1007 // On suppose que x=j (colonnes) et y=i (lignes) pour m(i,j). 1008 //-- 1009 { 1010 if(NCol()<=0||NRows()<=0) return NULL; 1012 // Les coordonnees de l'element (i,j) sont : 1013 // (i,j) -> x = xorg + j*dx , y = yorg + i*dy 1014 //-- 1015 { 1016 if(NCol()<=0||NRows()<=0) 1017 throw(SzMismatchError("Matrix::FitFunction: size mismatch\n")); 1011 1018 GeneralFunction* f = gfit.GetFunction(); 1012 if(f==NULL) return NULL; 1019 if(f==NULL) 1020 throw(NullPtrError("Matrix::FitFunction: NULL pointer\n")); 1013 1021 Vector par = gfit.GetParm(); 1014 Matrix * m = new Matrix(*this);1022 Matrix m(*this); 1015 1023 for(int i=0;i<NRows();i++) for(int j=0;j<NCol();j++) { 1016 double x[2] = { (double)j,(double)i};1017 (*m)(i,j) = f->Value(x,par.Data());1024 double x[2] = {xorg+j*dx,yorg+i*dy}; 1025 m(i,j) = f->Value(x,par.Data()); 1018 1026 } 1019 1027 return m; -
trunk/SophyaLib/NTools/matrix.h
r304 r307 11 11 #include "ppersist.h" 12 12 13 class GeneralFit; 14 namespace PlanckDPC {template <class T> class TMatrix;} 13 namespace PlanckDPC { 14 class GeneralFit; 15 template <class T> class TMatrix; 16 } 15 17 16 18 // <summary> Operations matricielles </summary> … … 146 148 147 149 // Residus et fonction fittees. 148 Matrix* FitResidus(GeneralFit& gfit); 149 Matrix* FitFunction(GeneralFit& gfit); 150 Matrix FitResidus(GeneralFit& gfit 151 ,double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 152 Matrix FitFunction(GeneralFit& gfit 153 ,double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 150 154 151 155 protected: -
trunk/SophyaLib/NTools/outilsinit.cc
r278 r307 35 35 PPRegister(Poly2); 36 36 PPRegister(ObjFileIO<DVList>); 37 PPRegister(Histo);38 PPRegister(Histo2D);39 PPRegister(HProf);37 //PPRegister(Histo); 38 //PPRegister(Histo2D); 39 //PPRegister(HProf); 40 40 PPRegister(NTuple); 41 PPRegister(GeneralFitData);41 //PPRegister(GeneralFitData); 42 42 43 43 PPRegister(RzImage); -
trunk/SophyaLib/NTools/rzimage.h
r220 r307 15 15 #include "dvlist.h" 16 16 17 class GeneralFit; 17 namespace PlanckDPC {class GeneralFit;} 18 18 19 19 // Flags de verifications sur les indices -
trunk/SophyaLib/NTools/tmatrix.h
r304 r307 12 12 #include "ndatablock.h" 13 13 14 namespace PlanckDPC { 15 14 16 class GeneralFit; 15 16 namespace PlanckDPC {17 18 17 template <class T> class TVector; 19 18 template <class T> class TMatrixRC; -
trunk/SophyaLib/NTools/tvector.h
r306 r307 5 5 6 6 #include "tmatrix.h" 7 class GeneralFit;8 7 9 8 namespace PlanckDPC { 9 10 class GeneralFit; 10 11 11 12 template <class T>
Note:
See TracChangeset
for help on using the changeset viewer.