Changeset 307 in Sophya for trunk/SophyaLib/NTools


Ignore:
Timestamp:
May 19, 1999, 5:58:06 PM (26 years ago)
Author:
ansari
Message:

FIO_... + grosses modifs cmv 19/5/99

Location:
trunk/SophyaLib/NTools
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/cvector.cc

    r303 r307  
    171171//////////////////////////////////////////////////////////
    172172//++
    173 Vector* Vector::FitResidus(GeneralFit& gfit)
     173Vector Vector::FitResidus(GeneralFit& gfit,double xorg,double dx)
    174174//
    175175//      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{
     179if(NElts()<=0)
     180  throw(SzMismatchError("Vector::FitResidus: size mismatch\n"));
    180181GeneralFunction* f = gfit.GetFunction();
    181 if(f==NULL) return NULL;
     182if(f==NULL)
     183  throw(NullPtrError("Vector::FitResidus: NULL pointer\n"));
    182184Vector par = gfit.GetParm();
    183 Vector* v = new Vector(*this);
     185Vector v(*this);
    184186for(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());
    187189}
    188190return v;
     
    190192
    191193//++
    192 Vector* Vector::FitFunction(GeneralFit& gfit)
     194Vector Vector::FitFunction(GeneralFit& gfit,double xorg,double dx)
    193195//
    194196//      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{
     200if(NElts()<=0)
     201  throw(SzMismatchError("Vector::FitResidus: size mismatch\n"));
    199202GeneralFunction* f = gfit.GetFunction();
    200 if(f==NULL) return NULL;
     203if(f==NULL)
     204  throw(NullPtrError("Vector::FitResidus: NULL pointer\n"));
    201205Vector par = gfit.GetParm();
    202 Vector* v = new Vector(*this);
     206Vector v(*this);
    203207for(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());
    206210}
    207211return v;
  • trunk/SophyaLib/NTools/cvector.h

    r304 r307  
    55#include "matrix.h"
    66
    7 class GeneralFit;
    8 namespace PlanckDPC {template <class T> class TVector;}
     7namespace PlanckDPC {
     8  class GeneralFit;
     9  template <class T> class TVector;
     10}
    911
    1012// <summary> Vecteur colonne pour operations matricielles </summary>
     
    6668
    6769  // 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.);
    7072
    7173};
     
    98100
    99101#endif /* VECTOR_SEEN */
    100 
    101 
    102 
  • trunk/SophyaLib/NTools/difeq.h

    r244 r307  
    77#include "cvector.h"
    88
    9 class GeneralFunction;
    10 
     9namespace PlanckDPC {class GeneralFunction;}
    1110
    1211// <summary> fonction pour equadifs </summary>
  • trunk/SophyaLib/NTools/fct1dfit.cc

    r244 r307  
    88#include "nbconst.h"
    99#include "tabmath.h"
     10
     11using namespace PlanckDPC;
    1012
    1113//define EXPO exp
  • trunk/SophyaLib/NTools/fct1dfit.h

    r220 r307  
    33
    44#include "generalfit.h"
     5
     6namespace PlanckDPC {
    57
    68//================================================================
     
    134136};
    135137
     138} // Fin du namespace
     139
    136140#endif
  • trunk/SophyaLib/NTools/fct2dfit.cc

    r244 r307  
    1616#define EXPO tabFExp
    1717#define MINEXPM (100.)
     18
     19using namespace PlanckDPC;
    1820
    1921//================================================================
  • trunk/SophyaLib/NTools/fct2dfit.h

    r220 r307  
    33
    44#include "generalfit.h"
     5
     6namespace PlanckDPC {
    57
    68//================================================================
     
    193195};
    194196
     197} // Fin du namespace
     198
    195199#endif
  • trunk/SophyaLib/NTools/generaldata.cc

    r244 r307  
    33#include <stdlib.h>
    44#include <iostream.h>
     5#include <values.h>
    56#include <math.h>
    67#include <string.h>
     
    1112#endif
    1213
    13 #include "perrors.h"
    1414#include "nbtri.h"
    1515#include "generalfit.h"
    1616#include "generaldata.h"
     17#include "pexceptions.h"
     18#include "objfio.h"
     19
     20using namespace PlanckDPC;
    1721
    1822//================================================================
     
    5256  , BuffVar(NULL), BuffVarR4(NULL)
    5357{
    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)
     58try {
     59  Alloc(nVar,ndatalloc,errx);
     60} catch(PException e) {
     61  cout << "Exception : " << typeid(e).name() << " " << e.Msg() << endl;
     62  throw;
     63}
     64}
     65
     66//++
     67GeneralFitData::GeneralFitData(const GeneralFitData& data, bool clean)
    6568//
    6669//      Constructeur par copie. Si ``clean'' est ``true''
     
    7477  , BuffVar(NULL), BuffVarR4(NULL)
    7578{
    76  TRY {
    77    Alloc(data.mNVar,((clean)?data.mNDataGood:data.mNDataAlloc),((data.mErrXP)?1:0));
    78  } CATCHALL {
    79    cout<<"GeneralFitData::GeneralFitData Impossible d'allouer l'espace"<<endl;
    80    THROW_SAME;
    81  } ENDTRY
     79try {
     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}
    8285
    8386 // Remplissage
     
    113116
    114117//++
    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_CONSTRUCTOR
    126 }
    127 
    128 //++
    129118GeneralFitData::~GeneralFitData()
    130119//
     
    153142mNDataAlloc = ndatalloc;
    154143
    155 TRY {
     144try {
    156145  mXP  = new r_8[nVar*ndatalloc];
    157146  if(mOk_EXP) mErrXP  = new r_8[nVar*ndatalloc];
     
    161150  BuffVar   = new r_8[2*nVar+3];
    162151  BuffVarR4 = (r_4 *) BuffVar;
    163 } CATCHALL {
    164   THROW_SAME;
    165 } ENDTRY
     152} catch(PException e) {
     153  throw(AllocationError("GeneralFitData::Alloc allocation error\n"));
     154}
    166155}
    167156
     
    824813//////////////////////////////////////////////////////////////////////
    825814//++
    826 GeneralFitData* GeneralFitData::FitResidus(GeneralFit& gfit)
     815GeneralFitData GeneralFitData::FitResidus(GeneralFit& gfit)
    827816//
    828817//      Retourne une classe contenant les residus du fit ``gfit''.
    829818//--
    830819{
    831 if(gfit.GetNVar()!=mNVar) return NULL;
     820if(gfit.GetNVar()!=mNVar)
     821  throw(SzMismatchError("GeneralFitData::FitResidus: size mismatch\n"));
    832822return gfit.DataResidus(true);
    833823}
    834824
    835825//++
    836 GeneralFitData* GeneralFitData::FitFunction(GeneralFit& gfit)
     826GeneralFitData GeneralFitData::FitFunction(GeneralFit& gfit)
    837827//
    838828//      Retourne une classe contenant la function du fit ``gfit''.
    839829//--
    840830{
    841 if(gfit.GetNVar()!=mNVar) return NULL;
     831if(gfit.GetNVar()!=mNVar)
     832  throw(SzMismatchError("GeneralFitData::FitFunction: size mismatch\n"));
    842833return gfit.DataFunction(true);
    843834}
     
    922913//////////////////////////////////////////////////////////////////////
    923914//++
    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
     999FIO_GeneralFitData::FIO_GeneralFitData()
     1000{
     1001dobj=new GeneralFitData;
     1002ownobj=true;
     1003}
     1004
     1005FIO_GeneralFitData::FIO_GeneralFitData(string const & filename)
     1006{
     1007dobj=new GeneralFitData;
     1008ownobj=true;
     1009Read(filename);
     1010}
     1011
     1012FIO_GeneralFitData::FIO_GeneralFitData(const GeneralFitData & obj)
     1013{
     1014dobj = new GeneralFitData(obj);
     1015ownobj=true;
     1016}
     1017
     1018FIO_GeneralFitData::FIO_GeneralFitData(GeneralFitData * obj)
     1019{
     1020dobj = obj;
     1021ownobj=false;
     1022}
     1023
     1024FIO_GeneralFitData::~FIO_GeneralFitData()
     1025{
     1026if (ownobj && dobj) delete dobj;
     1027}
     1028
     1029AnyDataObj* FIO_GeneralFitData::DataObj()
     1030{
     1031return(dobj);
     1032}
     1033
     1034void FIO_GeneralFitData::ReadSelf(PInPersist& is)
     1035{
     1036char strg[256];
     1037
     1038if(dobj==NULL) dobj=new GeneralFitData;
     1039  else         dobj->Delete();
     1040
     1041// Lecture entete
     1042is.GetLine(strg, 255);
     1043
     1044// Ecriture des valeurs de definitions
     1045int_4 nvar,ndatalloc,ndata,ndatagood;
     1046is.Get(nvar);
     1047is.Get(ndatalloc);
     1048is.Get(ndata);
     1049is.Get(ndatagood);
     1050is.Get(dobj->mOk_EXP);
     1051if(nvar<=0 || ndatalloc<=0 || ndata<=0 || ndatagood<0 || ndatalloc<ndata) return;
     1052
     1053// Allocation de la place (attention Alloc efface mNData,mNDataGood);
     1054dobj->Alloc(nvar,ndatalloc,-1);
     1055dobj->mNData = ndata;
     1056dobj->mNDataGood = ndatagood;
     1057
     1058// Lecture des datas
     1059is.GetLine(strg, 255);
     1060int blen = dobj->mNVar + 3;
     1061if(dobj->mOk_EXP) blen += dobj->mNVar;
     1062double *buff = new double[blen];
     1063for(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}
     1073delete [] buff;
     1074
     1075return;
     1076}
     1077
     1078void FIO_GeneralFitData::WriteSelf(POutPersist& os) const
     1079{
     1080if (dobj == NULL)   return;
    9291081char strg[256];
    9301082
    9311083// Ecriture entete pour identifier facilement
    9321084sprintf(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);
     1086os.PutLine(strg);
    9351087
    9361088// 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;
     1089os.Put(dobj->mNVar);
     1090os.Put(dobj->mNDataAlloc);
     1091os.Put(dobj->mNData);
     1092os.Put(dobj->mNDataGood);
     1093os.Put(dobj->mOk_EXP);
     1094if(dobj->mNVar<=0 || dobj->mNDataAlloc<=0 || dobj->mNData<=0 || dobj->mNDataGood<0) return;
    9431095
    9441096// Ecriture des datas (on n'ecrit que mNData / mNDataAlloc)
    9451097sprintf(strg
    9461098       ,"GeneralFitData: Abscisses, Ordonnee, Erreur Ordonnee, Flag, Erreur Abscisses");
    947 s.PutLine(strg);
    948 
    949 int blen = mNVar + 3;
    950 if(mOk_EXP) blen += mNVar;
     1099os.PutLine(strg);
     1100
     1101int blen = dobj->mNVar + 3;
     1102if(dobj->mOk_EXP) blen += dobj->mNVar;
    9511103double *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);
     1104for(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);
    9591111}
    9601112delete [] buff;
     
    9621114return;
    9631115}
    964 
    965 //////////////////////////////////////////////////////////////////////
    966 //++
    967 void GeneralFitData::ReadSelf(PInPersist& s)
    968 //
    969 //      Lecture ppersist
    970 //--
    971 {
    972 char strg[256];
    973 
    974 Delete();
    975 
    976 // Lecture entete
    977 s.GetLine(strg, 255);
    978 
    979 // Ecriture des valeurs de definitions
    980 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 datas
    994 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() const
    1015 //      Retourne la place restante dans la structure (nombre de
    1016 //      donnees que l'on peut encore stoquer).
    1017 //--
    1018 //++
    1019 // inline int  NVar()       const
    1020 //      Retourne le nombre de variables Xi
    1021 //--
    1022 //++
    1023 // inline int  NData()
    1024 //      Retourne le nombre de donnees
    1025 //--
    1026 //++
    1027 // inline int  NDataGood()  const
    1028 //      Retourne le nombre de bonnes donnees (utilisees pour le fit)
    1029 //--
    1030 //++
    1031 // inline int  NDataAlloc() const
    1032 //      Retourne la place maximale allouee pour les donnees
    1033 //--
    1034 //++
    1035 // inline unsigned short int IsValid(int i) const
    1036 //      Retourne 1 si point valide, sinon 0
    1037 //--
    1038 //++
    1039 // inline bool HasXErrors()
    1040 //      Retourne ``true'' si il y a des erreurs sur les variables
    1041 //      d'abscisse, ``false'' sinon.
    1042 //--
    1043 //++
    1044 // inline double X1(int i) const
    1045 //      Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I
    1046 //--
    1047 //++
    1048 // inline double X(int i) const
    1049 //      Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
    1050 //--
    1051 //++
    1052 // inline double Y(int i) const
    1053 //      Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
    1054 //--
    1055 //++
    1056 // inline double Z(int i) const
    1057 //      Retourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
    1058 //--
    1059 //++
    1060 // inline double Absc(int j,int i) const
    1061 //      Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
    1062 //--
    1063 //++
    1064 // inline double Val(int i) const
    1065 //      Retourne la valeur de la Ieme donnee
    1066 //--
    1067 //++
    1068 // inline double EX1(int i) const
    1069 //      Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I
    1070 //--
    1071 //++
    1072 // inline double EX(int i) const
    1073 //      Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
    1074 //--
    1075 //++
    1076 // inline double EY(int i) const
    1077 //      Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
    1078 //--
    1079 //++
    1080 // inline double EZ(int i) const
    1081 //      Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
    1082 //--
    1083 //++
    1084 // inline double EAbsc(int j,int i) const
    1085 //      Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
    1086 //--
    1087 //++
    1088 // inline double EVal(int i) const {return mErr[i];}
    1089 //      Retourne l'erreur de la Ieme donnee
    1090 //--
  • trunk/SophyaLib/NTools/generaldata.h

    r244 r307  
     1// This may look like C code, but it is really -*- C++ -*-
     2//                         C.Magneville          04/99
    13#ifndef GENERALDATA_SEEN
    24#define GENERALDATA_SEEN
     
    57#include "ppersist.h"
    68#include "poly.h"
     9#include "anydataobj.h"
     10
     11namespace PlanckDPC {
    712
    813class GeneralFit;
     14class FIO_GeneralFitData;
    915
    1016//================================================================
     
    1218//================================================================
    1319
    14 class GeneralFitData : public PPersist {
     20class GeneralFitData : public AnyDataObj {
     21  friend class GeneralFit;
     22  friend class FIO_GeneralFitData;
    1523public:
    16   enum {classId = ClassId_GeneralFitData };
    1724  enum {Def_ErrF = 1, Def_ErrX = 0};
    1825
    1926  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);
    2128  GeneralFitData();
    22   GeneralFitData(char *flnm);
    2329  virtual ~GeneralFitData();
    2430
     
    107113  double PolFit(int varx,Poly& pol,int degre,bool ey=true);
    108114  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);
    111117  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;
    120118
    121119protected:
     
    136134};
    137135
     136/////////////////////////////////////////////////////////////////////////
     137// Classe pour la gestion de persistance
     138class FIO_GeneralFitData : public  PPersist  {
     139public:
     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); }
     147protected :
     148  virtual void ReadSelf(PInPersist&);           
     149  virtual void WriteSelf(POutPersist&) const; 
     150  GeneralFitData * dobj;
     151  bool ownobj;
     152};
     153
     154} // Fin du namespace
     155
    138156#endif
  • trunk/SophyaLib/NTools/generalfit.cc

    r244 r307  
    1111#endif
    1212
     13#include "pexceptions.h"
    1314#include "generalfit.h"
    14 #include "perrors.h"
    1515#include "cvector.h"
    16 #include "nbconst.h"
    17 #include "tabmath.h"
    1816
    1917#define EPS_FIT_MIN 1.e-8
     18
     19using namespace PlanckDPC;
    2020
    2121//================================================================
     
    14331433//////////////////////////////////////////////////////////////////////
    14341434//++
    1435 GeneralFitData* GeneralFit::DataResidus(bool clean)
     1435GeneralFitData GeneralFit::DataResidus(bool clean)
    14361436//
    14371437//      Retourne une structure ``GeneralFitData'' contenant
     
    14441444//--
    14451445{
    1446 if(!mData) return NULL;
    1447 if(!mFunction) return NULL;
    1448 GeneralFitData* datres = new GeneralFitData(*mData,clean);
     1446if(!mData || !mFunction)
     1447  throw(NullPtrError("GeneralFit::DataResidus: NULL pointer\n"));
     1448GeneralFitData datres(*mData,clean);
    14491449for(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());
    14511451return datres;
    14521452}
     
    14541454//////////////////////////////////////////////////////////////////////
    14551455//++
    1456 GeneralFitData* GeneralFit::DataFunction(bool clean)
     1456GeneralFitData GeneralFit::DataFunction(bool clean)
    14571457//
    14581458//      Retourne une structure ``GeneralFitData'' contenant
     
    14611461//--
    14621462{
    1463 if(!mData) return NULL;
    1464 if(!mFunction) return NULL;
    1465 GeneralFitData* datres = new GeneralFitData(*mData,clean);
     1463if(!mData || !mFunction)
     1464  throw(NullPtrError("GeneralFit::DataFunction: NULL pointer\n"));
     1465GeneralFitData datres(*mData,clean);
    14661466for(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());
    14681468return datres;
    14691469}
  • trunk/SophyaLib/NTools/generalfit.h

    r244 r307  
    88#include "generaldata.h"
    99
     10namespace PlanckDPC {
     11
    1012//================================================================
    1113// GeneralFunction
    1214//================================================================
    1315
    14 class GeneralFunction EXC_AWARE {
     16class GeneralFunction {
    1517public:
    1618  GeneralFunction(unsigned int nVar, unsigned int nPar);
     
    6163class GeneralFitData;
    6264
    63 class GeneralXi2 EXC_AWARE {
     65class GeneralXi2 {
    6466public:
    6567  GeneralXi2(unsigned int nPar);
     
    8587//================================================================
    8688
    87 class GeneralFit EXC_AWARE {
     89class GeneralFit {
    8890public:
    8991  GeneralFit(GeneralFunction* f);
     
    152154  int             Fit();
    153155  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);
    156158  void            PrintFitErr(int rc);
    157159
     
    227229};
    228230
     231} // Fin du namespace
     232
    229233#endif
  • trunk/SophyaLib/NTools/hisprof.cc

    r244 r307  
    77#include "cvector.h"
    88
     9using namespace PlanckDPC;
     10
    911//++
    1012// Class        HProf
     
    4749  Histo::Errors();
    4850  Zero();
    49   END_CONSTRUCTOR
    50 }
    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);
    6351  END_CONSTRUCTOR
    6452}
     
    261249//--
    262250{
    263 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     251if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    264252HProf c(a);
    265253return (c += b);
    266254}
    267255
    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
     305FIO_HProf::FIO_HProf()
     306{
     307dobj=new HProf;
     308ownobj=true;
     309}
     310
     311FIO_HProf::FIO_HProf(string const & filename)
     312{
     313dobj=new HProf;
     314ownobj=true;
     315Read(filename);
     316}
     317
     318FIO_HProf::FIO_HProf(const HProf & obj)
     319{
     320dobj = new HProf(obj);
     321ownobj=true;
     322}
     323
     324FIO_HProf::FIO_HProf(HProf * obj)
     325{
     326dobj = obj;
     327ownobj=false;
     328}
     329
     330FIO_HProf::~FIO_HProf()
     331{
     332if (ownobj && dobj) delete dobj;
     333}
     334
     335AnyDataObj* FIO_HProf::DataObj()
     336{
     337return(dobj);
     338}
     339
     340void FIO_HProf::ReadSelf(PInPersist& is)
    274341{
    275342char strg[256];
    276343
    277 UpdateHisto();
     344if(dobj==NULL) dobj=new HProf;
     345  else         dobj->Delete();
     346
     347// Lecture entete
     348is.GetLine(strg,255);
     349
     350// Ecriture des valeurs
     351is.Get(dobj->bins);
     352is.Get(dobj->YMin);
     353is.Get(dobj->YMax);
     354is.Get(dobj->Opt);
     355dobj->Ok = true;
     356
     357// Ecriture des donnees propres a l'histogramme de profil.
     358is.GetLine(strg,255);
     359dobj->SumY  = new double[dobj->bins];
     360dobj->SumY2 = new double[dobj->bins];
     361dobj->SumW  = new double[dobj->bins];
     362is.Get(dobj->SumY,  dobj->bins);
     363is.Get(dobj->SumY2, dobj->bins);
     364is.Get(dobj->SumW,  dobj->bins);
     365
     366// Ecriture de l'histogramme
     367FIO_Histo fio_h((Histo&)dobj);
     368fio_h.Read(is);
     369
     370return;
     371}
     372
     373void FIO_HProf::WriteSelf(POutPersist& os) const
     374{
     375if (dobj == NULL)   return;
     376char strg[256];
     377
     378dobj->UpdateHisto();
    278379
    279380// Ecriture entete pour identifier facilement
    280 sprintf(strg,"HProf: YMin=%f  YMax=%f  Opt=%1d",YMin,YMax,Opt);
    281 s.PutLine(strg);
     381sprintf(strg,"HProf: YMin=%f  YMax=%f  Opt=%1d",dobj->YMin,dobj->YMax,dobj->Opt);
     382os.PutLine(strg);
    282383
    283384// Ecriture des valeurs
    284 s.PutI4(bins);
    285 s.PutR4(YMin);
    286 s.PutR4(YMax);
    287 s.PutU2(Opt);
     385os.Put(dobj->bins);
     386os.Put(dobj->YMin);
     387os.Put(dobj->YMax);
     388os.Put(dobj->Opt);
    288389
    289390// Ecriture des donnees propres a l'histogramme de profil.
    290391sprintf(strg,"HProf: SumY SumY2 SumW");
    291 s.PutLine(strg);
    292 s.PutR8s(SumY,  bins);
    293 s.PutR8s(SumY2, bins);
    294 s.PutR8s(SumW,  bins);
     392os.PutLine(strg);
     393os.Put(dobj->SumY,  dobj->bins);
     394os.Put(dobj->SumY2, dobj->bins);
     395os.Put(dobj->SumW,  dobj->bins);
    295396
    296397// Ecriture de l'histogramme
    297 Histo::WriteSelf(s);
     398FIO_Histo fio_h((Histo&)dobj);
     399fio_h.Write(os);
    298400
    299401return;
    300402}
    301 
    302 /********* Methode *********/
    303 //++
    304 void  HProf::ReadSelf(PInPersist& s)
    305 //
    306 //      Lecture ppersist
    307 //--
    308 {
    309 char strg[256];
    310 
    311 Delete();
    312 
    313 // Lecture entete
    314 s.GetLine(strg,255);
    315 
    316 // Ecriture des valeurs
    317 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'histogramme
    333 Histo::ReadSelf(s);
    334 
    335 return;
    336 }
    337 
    338 
    339 // Rappel des inlines functions pour commentaires
    340 //++
    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 v
    347 //--
    348 //++
    349 // inline void GetError2(Vector& v)
    350 //      Retourne le contenu au carre de la dispersion/erreur dans le vecteur v
    351 //--
    352 //++
    353 // inline float operator()(int i) const
    354 //      Retourne le contenu du bin i
    355 //--
    356 //++
    357 // inline float Error2(int i) const
    358 //      Retourne le carre de la dispersion/erreur du bin i
    359 //--
    360 //++
    361 // inline float Error(int i) const
    362 //      Retourne la dispersion/erreur du bin i
    363 //--
    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::Print
    379 //--
  • trunk/SophyaLib/NTools/hisprof.h

    r220 r307  
    88#include "histos.h"
    99
     10namespace PlanckDPC {
     11
    1012class HProf : public Histo {
    11 
     13  friend class FIO_HProf;
    1214public:
    13   enum {classId = ClassId_HProf };
    1415
    1516  // CREATOR / DESTRUCTOR
    1617  HProf();
    1718  HProf(float xMin, float xMax, int nBin=100, float yMin=1., float yMax=-1.);
    18   HProf(char *flnm);
    1919  HProf(const HProf& H);
    2020  virtual ~HProf();
     
    4444  inline int    Fit(GeneralFit& gfit)
    4545         {if(!Ok) UpdateHisto(); return Histo::Fit(gfit,0);}
    46   inline Histo* FitResidus(GeneralFit& gfit)
     46  inline Histo  FitResidus(GeneralFit& gfit)
    4747         {if(!Ok) UpdateHisto(); return Histo::FitResidus(gfit);}
    48   inline Histo* FitFunction(GeneralFit& gfit)
     48  inline Histo  FitFunction(GeneralFit& gfit)
    4949         {if(!Ok) UpdateHisto(); return Histo::FitFunction(gfit);}
    5050
     
    5252  inline void Print(int dyn=100,float hmin=1.,float hmax=-1.,int pflag=0,int il=1,int ih=-1)
    5353                           {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 
    6154
    6255protected:
     
    7265};
    7366
     67/////////////////////////////////////////////////////////////////////////
     68// Classe pour la gestion de persistance
     69class FIO_HProf : public  PPersist  {
     70public:
     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); }
     78protected :
     79  virtual void ReadSelf(PInPersist&);           
     80  virtual void WriteSelf(POutPersist&) const; 
     81  HProf * dobj;
     82  bool ownobj;
     83};
     84
     85} // Fin du namespace
     86
    7487#endif // HISPROF_SEEN
  • trunk/SophyaLib/NTools/histos.cc

    r244 r307  
    11//
    2 // $Id: histos.cc,v 1.2 1999-04-22 16:18:36 ansari Exp $
     2// $Id: histos.cc,v 1.3 1999-05-19 15:57:59 ansari Exp $
    33//
    44
     
    1414#include "generalfit.h"
    1515
     16using namespace PlanckDPC;
     17
    1618//++
    1719// Class        Histo
     
    5052{
    5153  Zero();
    52   END_CONSTRUCTOR
    53 }
    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);
    6654  END_CONSTRUCTOR
    6755}
     
    379367//--
    380368{
    381 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     369if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    382370Histo c(a);
    383371return (c += b);
     
    389377//--
    390378{
    391 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     379if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    392380Histo c(a);
    393381return (c -= b);
     
    399387//--
    400388{
    401 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     389if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    402390Histo c(a);
    403391return (c *= b);
     
    409397//--
    410398{
    411 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     399if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    412400Histo c(a);
    413401return (c /= b);
     
    14461434
    14471435//++
    1448 Histo* Histo::FitResidus(GeneralFit& gfit)
     1436Histo Histo::FitResidus(GeneralFit& gfit)
    14491437//
    14501438//      Retourne une classe contenant les residus du fit ``gfit''.
    14511439//--
    14521440{
    1453 if(NBins()<=0) return NULL;
     1441if(NBins()<=0)
     1442  throw(SzMismatchError("Histo::FitResidus: size mismatch\n"));
    14541443GeneralFunction* f = gfit.GetFunction();
    1455 if(f==NULL) return NULL;
     1444if(f==NULL)
     1445  throw(NullPtrError("Histo::FitResidus: NULL pointer\n"));
    14561446Vector par = gfit.GetParm();
    1457 Histo* h = new Histo(*this);
     1447Histo h(*this);
    14581448for(int i=0;i<NBins();i++) {
    14591449  double x = (double) BinCenter(i);
    1460   (*h)(i) -= (float) f->Value(&x,par.Data());
     1450  h(i) -= (float) f->Value(&x,par.Data());
    14611451}
    14621452return h;
     
    14641454
    14651455//++
    1466 Histo* Histo::FitFunction(GeneralFit& gfit)
     1456Histo Histo::FitFunction(GeneralFit& gfit)
    14671457//
    14681458//      Retourne une classe contenant la fonction du fit ``gfit''.
    14691459//--
    14701460{
    1471 if(NBins()<=0) return NULL;
     1461if(NBins()<=0)
     1462  throw(SzMismatchError("Histo::FitFunction: size mismatch\n"));
    14721463GeneralFunction* f = gfit.GetFunction();
    1473 if(f==NULL) return NULL;
     1464if(f==NULL)
     1465  throw(NullPtrError("Histo::FitFunction: NULL pointer\n"));
    14741466Vector par = gfit.GetParm();
    1475 Histo* h = new Histo(*this);
     1467Histo h(*this);
    14761468for(int i=0;i<NBins();i++) {
    14771469  double x = (double) BinCenter(i);
    1478   (*h)(i) = (float) f->Value(&x,par.Data());
     1470  h(i) = (float) f->Value(&x,par.Data());
    14791471}
    14801472return h;
     
    16621654 Histo::PrintF(stdout, hdyn, hmin, hmax, pflag, il, ih);
    16631655}
    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
     1739FIO_Histo::FIO_Histo()
     1740{
     1741dobj=new Histo;
     1742ownobj=true;
     1743}
     1744
     1745FIO_Histo::FIO_Histo(string const & filename)
     1746{
     1747dobj=new Histo;
     1748ownobj=true;
     1749Read(filename);
     1750}
     1751
     1752FIO_Histo::FIO_Histo(const Histo & obj)
     1753{
     1754dobj = new Histo(obj);
     1755ownobj=true;
     1756}
     1757
     1758FIO_Histo::FIO_Histo(Histo * obj)
     1759{
     1760dobj = obj;
     1761ownobj=false;
     1762}
     1763
     1764FIO_Histo::~FIO_Histo()
     1765{
     1766if (ownobj && dobj) delete dobj;
     1767}
     1768
     1769AnyDataObj* FIO_Histo::DataObj()
     1770{
     1771return(dobj);
     1772}
     1773
     1774void FIO_Histo::ReadSelf(PInPersist& is)
    16721775{
    16731776char strg[256];
    16741777
     1778if(dobj==NULL) dobj=new Histo;
     1779  else         dobj->Delete();
     1780
     1781// Lecture entete
     1782is.GetLine(strg, 255);
     1783is.GetLine(strg, 255);
     1784is.GetLine(strg, 255);
     1785
     1786// Lecture des valeurs
     1787is.Get(dobj->bins);
     1788is.Get(dobj->nEntries);
     1789int_4 errok;
     1790is.Get(errok);
     1791
     1792is.Get(dobj->binWidth);
     1793is.Get(dobj->min);
     1794is.Get(dobj->max);
     1795is.Get(dobj->under);
     1796is.Get(dobj->over);
     1797
     1798is.Get(dobj->nHist);
     1799
     1800// Lecture des donnees Histo 1D
     1801dobj->data = new float[dobj->bins];
     1802is.GetLine(strg, 255);
     1803is.Get(dobj->data, dobj->bins);
     1804
     1805// Lecture des erreurs
     1806if(errok) {
     1807  is.GetLine(strg, 255);
     1808  dobj->err2 = new double[dobj->bins];
     1809  is.Get(dobj->err2, dobj->bins);
     1810}
     1811
     1812return;
     1813}
     1814
     1815void FIO_Histo::WriteSelf(POutPersist& os) const
     1816{
     1817if (dobj == NULL)   return;
     1818char strg[256];
     1819
    16751820// Que faut-il ecrire?
    1676 int errok = (err2) ? 1 : 0;
     1821int errok = (dobj->err2) ? 1 : 0;
    16771822
    16781823// 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);
     1824sprintf(strg,"bins=%6d  NEnt=%15d  errok=%1d",dobj->bins,dobj->nEntries,errok);
     1825os.PutLine(strg);
     1826sprintf(strg,"binw=%g  min=%g max=%g",dobj->binWidth,dobj->min,dobj->max);
     1827os.PutLine(strg);
     1828sprintf(strg, "under=%g over=%g nHist=%g",dobj->under,dobj->over,dobj->nHist);
     1829os.PutLine(strg);
    16851830
    16861831// 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);
     1832os.Put(dobj->bins);
     1833os.Put(dobj->nEntries);
     1834os.Put(errok);
     1835
     1836os.Put(dobj->binWidth);
     1837os.Put(dobj->min);
     1838os.Put(dobj->max);
     1839os.Put(dobj->under);
     1840os.Put(dobj->over);
     1841
     1842os.Put(dobj->nHist);
    16981843
    16991844// Ecriture des donnees Histo 1D
    1700 sprintf(strg,"Histo: Tableau des donnees %d",bins);
    1701 s.PutLine(strg);
    1702 s.PutR4s(data, bins);
     1845sprintf(strg,"Histo: Tableau des donnees %d",dobj->bins);
     1846os.PutLine(strg);
     1847os.Put(dobj->data, dobj->bins);
    17031848
    17041849// Ecriture des erreurs
    17051850if(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);
    17091854}
    17101855
    17111856return;
    17121857}
    1713 
    1714 /********* Methode *********/
    1715 //++
    1716 void  Histo::ReadSelf(PInPersist& s)
    1717 //
    1718 //      Lecture ppersist
    1719 //--
    1720 {
    1721 char strg[256];
    1722 
    1723 Delete();
    1724 
    1725 // Lecture entete
    1726 s.GetLine(strg, 255);
    1727 s.GetLine(strg, 255);
    1728 s.GetLine(strg, 255);
    1729 
    1730 // Lecture des valeurs
    1731 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 1D
    1745 data = new float[bins];
    1746 s.GetLine(strg, 255);
    1747 s.GetR4s(data, bins);
    1748 
    1749 // Lecture des erreurs
    1750 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 commentaires
    1762 //++
    1763 // inline float          XMin() const
    1764 //      Retourne l'abscisse minimum
    1765 //--
    1766 //++
    1767 // inline float          XMax() const
    1768 //      Retourne l'abscisse maximum
    1769 //--
    1770 //++
    1771 // inline int            NBins() const
    1772 //      Retourne le nombre de bins
    1773 //--
    1774 //++
    1775 // inline float          BinWidth() const
    1776 //      Retourne la largeur du bin
    1777 //--
    1778 //++
    1779 // inline float*         Bins() const
    1780 //      Retourne le pointeur sur le tableaux des contenus
    1781 //--
    1782 //++
    1783 // inline float          operator()(int i) const
    1784 //      Retourne le contenu du bin i
    1785 //--
    1786 //++
    1787 // inline float&         operator()(int i)
    1788 //      Remplit le contenu du bin i
    1789 //--
    1790 //++
    1791 // inline float          Error(int i) const
    1792 //      Retourne l'erreur du bin i
    1793 //--
    1794 //++
    1795 // inline double         Error2(int i) const
    1796 //      Retourne l'erreur au carre du bin i
    1797 //--
    1798 //++
    1799 // inline double&        Error2(int i)
    1800 //      Remplit l'erreur au carre du bin i
    1801 //--
    1802 //++
    1803 // inline float          NData() const
    1804 //      Retourne la somme ponderee
    1805 //--
    1806 //++
    1807 // inline float          NEntries()
    1808 //      Retourne le nombre d'entrees
    1809 //--
    1810 //++
    1811 // inline float          NOver() const
    1812 //      Retourne le nombre d'overflow
    1813 //--
    1814 //++
    1815 // inline float          NUnder() const
    1816 //      Retourne le nombre d'underflow
    1817 //--
    1818 //++
    1819 // inline float          BinLowEdge(int i)  const
    1820 //      Retourne l'abscisse du bord inferieur du bin i
    1821 //--
    1822 //++
    1823 // inline float          BinCenter(int i)   const
    1824 //      Retourne l'abscisse du centre du bin i
    1825 //--
    1826 //++
    1827 // inline float          BinHighEdge(int i) const
    1828 //      Retourne l'abscisse du bord superieur du bin i
    1829 //--
    1830 //++
    1831 // inline int            FindBin(float x) const   
    1832 //      Retourne le numero du bin contenant l'abscisse x
    1833 //--
  • trunk/SophyaLib/NTools/histos.h

    r220 r307  
    11// This may look like C code, but it is really -*- C++ -*-
    22//
    3 // $Id: histos.h,v 1.1.1.1 1999-04-09 17:57:56 ansari Exp $
     3// $Id: histos.h,v 1.2 1999-05-19 15:58:00 ansari Exp $
    44//
    55
     
    1111#include "cvector.h"
    1212#include "ppersist.h"
     13#include "anydataobj.h"
     14
     15namespace PlanckDPC {
    1316
    1417class GeneralFit;
    1518
    16 class Histo : public PPersist {
    17 
     19class Histo : public AnyDataObj {
     20  friend class FIO_Histo;
    1821public:
    19   enum {classId = ClassId_Histo1D };
    2022
    2123  // CREATOR / DESTRUCTOR
    2224  Histo();
    2325  Histo(float xMin, float xMax, int nBin=100);
    24   Histo(char *flnm);
    2526  Histo(const Histo& H);
    2627  virtual        ~Histo();
     
    131132  // Fit
    132133  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);
    135136
    136137  // Print et Display ASCII
     
    139140  void           Print(int dyn = 100, float hmin = 1., float hmax = -1.,
    140141                        int pflag = 0, int il = 1, int ih = -1);
    141 
    142   // PPersist objet
    143   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 
    149142
    150143protected:
     
    163156};
    164157
     158/////////////////////////////////////////////////////////////////////////
     159// Classe pour la gestion de persistance
     160class FIO_Histo : public  PPersist  {
     161public:
     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); }
     169protected :
     170  virtual void ReadSelf(PInPersist&);           
     171  virtual void WriteSelf(POutPersist&) const; 
     172  Histo * dobj;
     173  bool ownobj;
     174};
     175
     176} // Fin du namespace
     177
    165178#endif // HISTOS_SEEN
  • trunk/SophyaLib/NTools/histos2.cc

    r244 r307  
    1616#include "generalfit.h"
    1717
     18using namespace PlanckDPC;
     19
    1820//++
    1921// Class        Histo2D
     
    132134for(int i=0;i<3;i++) for(int j=0;j<3;j++) over[i][j]=0.;
    133135b_s.H = NULL;
    134 END_CONSTRUCTOR
    135 }
    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);
    152136END_CONSTRUCTOR
    153137}
     
    582566//--
    583567{
    584 if (b.nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);
     568if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
    585569Histo2D c(a);
    586570return (c += b);
     
    592576//--
    593577{
    594 if (b.nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);
     578if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
    595579Histo2D c(a);
    596580return (c -= b);
     
    602586//--
    603587{
    604 if (b.nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);
     588if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
    605589Histo2D c(a);
    606590return (c *= b);
     
    612596//--
    613597{
    614 if (b.nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);
     598if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
    615599Histo2D c(a);
    616600return (c /= b);
     
    11131097
    11141098//++
    1115 Histo2D* Histo2D::FitResidus(GeneralFit& gfit)
     1099Histo2D Histo2D::FitResidus(GeneralFit& gfit)
    11161100//
    11171101//      Retourne une classe contenant les residus du fit ``gfit''.
    11181102//--
    11191103{
    1120 if(NBinX()<=0 || NBinY()<=0) return NULL;
     1104if(NBinX()<=0 || NBinY()<=0)
     1105  throw(SzMismatchError("Histo2D::FitResidus: size mismatch\n"));
    11211106GeneralFunction* f = gfit.GetFunction();
    1122 if(f==NULL) return NULL;
     1107if(f==NULL)
     1108  throw(NullPtrError("Histo2D::FitResidus: NULL pointer\n"));
    11231109Vector par = gfit.GetParm();
    1124 Histo2D* h2 = new Histo2D(*this);
     1110Histo2D h2(*this);
    11251111for(int i=0;i<NBinX();i++) for(int j=0;j<NBinY();j++) {
    11261112  float xc,yc;
    11271113  BinCenter(i,j,xc,yc);
    11281114  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());
    11301116}
    11311117return h2;
     
    11331119
    11341120//++
    1135 Histo2D* Histo2D::FitFunction(GeneralFit& gfit)
     1121Histo2D Histo2D::FitFunction(GeneralFit& gfit)
    11361122//
    11371123//      Retourne une classe contenant la fonction du fit ``gfit''.
    11381124//--
    11391125{
    1140 if(NBinX()<=0 || NBinY()<=0) return NULL;
     1126if(NBinX()<=0 || NBinY()<=0)
     1127  throw(SzMismatchError("Histo2D::FitFunction: size mismatch\n"));
    11411128GeneralFunction* f = gfit.GetFunction();
    1142 if(f==NULL) return NULL;
     1129if(f==NULL)
     1130  throw(NullPtrError("Histo2D::FitFunction: NULL pointer\n"));
    11431131Vector par = gfit.GetParm();
    1144 Histo2D* h2 = new Histo2D(*this);
     1132Histo2D h2(*this);
    11451133for(int i=0;i<NBinX();i++) for(int j=0;j<NBinY();j++) {
    11461134  float xc,yc;
    11471135  BinCenter(i,j,xc,yc);
    11481136  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());
    11501138}
    11511139return h2;
     
    17921780
    17931781
    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
     1788FIO_Histo2D::FIO_Histo2D()
     1789{
     1790dobj=new Histo2D;
     1791ownobj=true;
     1792}
     1793
     1794FIO_Histo2D::FIO_Histo2D(string const & filename)
     1795{
     1796dobj=new Histo2D;
     1797ownobj=true;
     1798Read(filename);
     1799}
     1800
     1801FIO_Histo2D::FIO_Histo2D(const Histo2D & obj)
     1802{
     1803dobj = new Histo2D(obj);
     1804ownobj=true;
     1805}
     1806
     1807FIO_Histo2D::FIO_Histo2D(Histo2D * obj)
     1808{
     1809dobj = obj;
     1810ownobj=false;
     1811}
     1812
     1813FIO_Histo2D::~FIO_Histo2D()
     1814{
     1815if (ownobj && dobj) delete dobj;
     1816}
     1817
     1818AnyDataObj* FIO_Histo2D::DataObj()
     1819{
     1820return(dobj);
     1821}
     1822
     1823void FIO_Histo2D::ReadSelf(PInPersist& is)
    18041824{
    18051825char strg[256];
    1806 int j;
     1826
     1827if(dobj==NULL) dobj=new Histo2D;
     1828  else         dobj->Delete();
     1829
    18071830float min,max;
    18081831Histo* h;
     1832int_4 errok, projx, projy, nslix, nsliy, nbanx, nbany;
     1833
     1834// Lecture entete
     1835is.GetLine(strg, 255);
     1836is.GetLine(strg, 255);
     1837is.GetLine(strg, 255);
     1838is.GetLine(strg, 255);
     1839is.GetLine(strg, 255);
     1840is.GetLine(strg, 255);
     1841
     1842// Lecture variables de definitions
     1843is.Get(dobj->nx);
     1844is.Get(dobj->ny);
     1845is.Get(dobj->nxy);
     1846is.Get(errok);
     1847is.Get(dobj->nEntries);
     1848is.Get(dobj->nHist);
     1849
     1850is.Get(dobj->xmin);
     1851is.Get(dobj->xmax);
     1852is.Get(dobj->ymin);
     1853is.Get(dobj->ymax);
     1854is.Get(dobj->wbinx);
     1855is.Get(dobj->wbiny);
     1856
     1857is.Get(&(dobj->over[0][0]),9);
     1858
     1859is.Get(projx);
     1860is.Get(projy);
     1861is.Get(nslix);
     1862is.Get(nsliy);
     1863is.Get(nbanx);
     1864is.Get(nbany);
     1865
     1866// Lecture histo2D
     1867dobj->data = new float[dobj->nxy];
     1868is.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
     1872if(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
     1879if(projx) {
     1880  is.GetLine(strg, 255);
     1881  dobj->SetProjX();
     1882  FIO_Histo fio_h(dobj->hprojx);
     1883  fio_h.Read(is);
     1884}
     1885if(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
     1893if(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}
     1900if(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
     1909if( 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}
     1921if( 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
     1934return;
     1935}
     1936
     1937void FIO_Histo2D::WriteSelf(POutPersist& os) const
     1938{
     1939if (dobj == NULL)   return;
     1940char strg[256];
    18091941
    18101942// 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();
     1943int_4 errok = (dobj->err2) ? 1 : 0;
     1944int_4 projx = (dobj->hprojx) ? 1 : 0;
     1945int_4 projy = (dobj->hprojy) ? 1 : 0;
     1946int_4 nslix = dobj->NSliX();
     1947int_4 nsliy = dobj->NSliY();
     1948int_4 nbanx = dobj->NBandX();
     1949int_4 nbany = dobj->NBandY();
    18181950
    18191951// 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);
     1952sprintf(strg,"nx=%d  ny=%d  nxy=%d errok=%1d"
     1953       ,dobj->nx,dobj->ny,dobj->nxy,errok);
     1954os.PutLine(strg);
     1955sprintf(strg,"nHist=%g nEntries=%d",dobj->nHist,dobj->nEntries);
     1956os.PutLine(strg);
     1957sprintf(strg,"wbinx=%g wbiny=%g",dobj->wbinx,dobj->wbiny);
     1958os.PutLine(strg);
     1959sprintf(strg,"xmin=%g xmax=%g ymin=%g ymax=%g"
     1960       ,dobj->xmin,dobj->xmax,dobj->ymin,dobj->ymax);
     1961os.PutLine(strg);
    18281962sprintf(strg,"projx/y=%d %d nbandx/y=%d %d nbslix/y=%d %d"
    18291963       ,projx,projy,nbanx,nbany,nslix,nsliy);
    1830 s.PutLine(strg);
     1964os.PutLine(strg);
    18311965sprintf(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]);
     1969os.PutLine(strg);
    18361970
    18371971// 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);
     1972os.Put(dobj->nx);
     1973os.Put(dobj->ny);
     1974os.Put(dobj->nxy);
     1975os.Put(errok);
     1976os.Put(dobj->nEntries);
     1977os.Put(dobj->nHist);
     1978
     1979os.Put(dobj->xmin);
     1980os.Put(dobj->xmax);
     1981os.Put(dobj->ymin);
     1982os.Put(dobj->ymax);
     1983os.Put(dobj->wbinx);
     1984os.Put(dobj->wbiny);
     1985
     1986os.Put(&(dobj->over[0][0]),9);
     1987
     1988os.Put(projx);
     1989os.Put(projy);
     1990os.Put(nslix);
     1991os.Put(nsliy);
     1992os.Put(nbanx);
     1993os.Put(nbany);
    18601994
    18611995// 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 
     1996sprintf(strg,"Histo2D: Tableau des donnees %d = %d * %d"
     1997       ,dobj->nxy,dobj->nx,dobj->ny);
     1998os.PutLine(strg);
     1999{for(int j=0;j<dobj->ny;j++) os.Put(dobj->data+j*dobj->nx,dobj->nx);}
    18662000
    18672001// Ecriture erreurs
    18682002if(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);
    18722007}
    18732008
     
    18752010if(projx) {
    18762011  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);
    18792014}
    18802015if(projy) {
    18812016  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);
    18842019}
    18852020
     
    18872022if(nslix>0) {
    18882023  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);
    18932028  }
    18942029}
    18952030if(nsliy>0) {
    18962031  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);
    19012036  }
    19022037}
     
    19052040if( nbanx>0 ) {
    19062041  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);
    19182051  }
    19192052}
    19202053if( nbany>0 ) {
    19212054  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);
    19332064  }
    19342065}
     
    19362067return;
    19372068}
    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 entete
    1954 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 definitions
    1963 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 histo2D
    1987 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 erreurs
    1992 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 projections
    1999 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 slices
    2011 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 bandes
    2025 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  
    1515
    1616#include "peida.h"
     17#include "utils.h"
    1718#include "histos.h"
    18 #include "utils.h"
    19 #include "ppersist.h"
    20 
     19
     20namespace PlanckDPC {
    2121
    2222class GeneralFit;
    2323
    24 
    25 class Histo2D : public PPersist {
    26 
     24class Histo2D : public AnyDataObj {
     25  friend class FIO_Histo2D;
    2726public:
    28   enum {classId = ClassId_Histo2D };
    2927
    3028  // CREATOR / DESTRUCTOR
     
    3331  Histo2D(const Histo2D& h);
    3432  Histo2D();
    35   Histo2D(char *flnm);
    36 
    3733  virtual  ~Histo2D();
    3834
     
    125121  // Fit
    126122  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);
    129125
    130126  // Print et Display ASCII
     
    175171  void           ShowSli(int lp = 0);
    176172
    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 
    183173#ifndef __DECCXX
    184174protected:
     
    224214};
    225215
     216/////////////////////////////////////////////////////////////////////////
     217// Classe pour la gestion de persistance
     218class FIO_Histo2D : public  PPersist  {
     219public:
     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); }
     227protected :
     228  virtual void ReadSelf(PInPersist&);           
     229  virtual void WriteSelf(POutPersist&) const; 
     230  Histo2D * dobj;
     231  bool ownobj;
     232};
     233
     234} // Fin du namespace
     235
    226236#endif // HISTOS2_SEEN
  • trunk/SophyaLib/NTools/integ.h

    r244 r307  
    33// integ.h
    44//
    5 // $Id: integ.h,v 1.2 1999-04-22 16:18:40 ansari Exp $
     5// $Id: integ.h,v 1.3 1999-05-19 15:58:01 ansari Exp $
    66//
    77
     
    1616#endif
    1717
    18 class GeneralFunction;
     18namespace PlanckDPC {class GeneralFunction;}
    1919
    2020class Integrator EXC_AWARE {
  • trunk/SophyaLib/NTools/matrix.cc

    r288 r307  
    1 // $Id: matrix.cc,v 1.3 1999-05-03 16:55:21 ansari Exp $
     1// $Id: matrix.cc,v 1.4 1999-05-19 15:58:02 ansari Exp $
    22
    33#include "machdefs.h"
     
    983983//////////////////////////////////////////////////////////
    984984//++
    985 Matrix* Matrix::FitResidus(GeneralFit& gfit)
     985Matrix Matrix::FitResidus(GeneralFit& gfit
     986               ,double xorg,double yorg,double dx,double dy)
    986987//
    987988//      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{
     993if(NCol()<=0||NRows()<=0)
     994  throw(SzMismatchError("Matrix::FitResidus: size mismatch\n"));
    992995GeneralFunction* f = gfit.GetFunction();
    993 if(f==NULL) return NULL;
     996if(f==NULL)
     997  throw(NullPtrError("Matrix::FitResidus: NULL pointer\n"));
    994998Vector par = gfit.GetParm();
    995 Matrix* m = new Matrix(*this);
     999Matrix m(*this);
    9961000for(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());
    9991003}
    10001004return m;
     
    10021006
    10031007//++
    1004 Matrix* Matrix::FitFunction(GeneralFit& gfit)
     1008Matrix Matrix::FitFunction(GeneralFit& gfit
     1009               ,double xorg,double yorg,double dx,double dy)
    10051010//
    10061011//      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{
     1016if(NCol()<=0||NRows()<=0)
     1017  throw(SzMismatchError("Matrix::FitFunction: size mismatch\n"));
    10111018GeneralFunction* f = gfit.GetFunction();
    1012 if(f==NULL) return NULL;
     1019if(f==NULL)
     1020  throw(NullPtrError("Matrix::FitFunction: NULL pointer\n"));
    10131021Vector par = gfit.GetParm();
    1014 Matrix* m = new Matrix(*this);
     1022Matrix m(*this);
    10151023for(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());
    10181026}
    10191027return m;
  • trunk/SophyaLib/NTools/matrix.h

    r304 r307  
    1111#include "ppersist.h"
    1212
    13 class GeneralFit;
    14 namespace PlanckDPC {template <class T> class TMatrix;}
     13namespace PlanckDPC {
     14  class GeneralFit;
     15  template <class T> class TMatrix;
     16}
    1517
    1618// <summary> Operations matricielles </summary>
     
    146148
    147149  // 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.);
    150154
    151155protected:
  • trunk/SophyaLib/NTools/outilsinit.cc

    r278 r307  
    3535  PPRegister(Poly2);
    3636  PPRegister(ObjFileIO<DVList>);
    37   PPRegister(Histo);
    38   PPRegister(Histo2D);
    39   PPRegister(HProf);
     37  //PPRegister(Histo);
     38  //PPRegister(Histo2D);
     39  //PPRegister(HProf);
    4040  PPRegister(NTuple);
    41   PPRegister(GeneralFitData);
     41  //PPRegister(GeneralFitData);
    4242
    4343  PPRegister(RzImage);
  • trunk/SophyaLib/NTools/rzimage.h

    r220 r307  
    1515#include "dvlist.h"
    1616
    17 class GeneralFit;
     17namespace PlanckDPC {class GeneralFit;}
    1818
    1919// Flags de verifications sur les indices
  • trunk/SophyaLib/NTools/tmatrix.h

    r304 r307  
    1212#include "ndatablock.h"
    1313
     14namespace PlanckDPC {
     15
    1416class GeneralFit;
    15 
    16 namespace PlanckDPC {
    17 
    1817template <class T> class TVector;
    1918template <class T> class TMatrixRC;
  • trunk/SophyaLib/NTools/tvector.h

    r306 r307  
    55
    66#include "tmatrix.h"
    7 class GeneralFit;
    87
    98namespace PlanckDPC {
     9
     10class GeneralFit;
    1011
    1112template <class T>
Note: See TracChangeset for help on using the changeset viewer.