#include "machdefs.h" #include #include #include #include "perrors.h" #include "fioarr.h" #include "histerr.h" namespace SOPHYA { /*! \class HistoErr \ingroup HiStats Classe d'histogrammes 1D avec erreurs donnees par l'utilisateur */ /********* Methode *********/ /*! Constructeur par defaut */ HistoErr::HistoErr(void) : xmin_(1.), xmax_(-1.), dx_(0.), nx_(0), mMean(0) { } /********* Methode *********/ /*! Constructeur d'un histo */ HistoErr::HistoErr(r_8 xmin,r_8 xmax,int_4 nx) { CreateOrResize(xmin,xmax,nx); } /********* Methode *********/ /*! Constructeur par copie */ HistoErr::HistoErr(const HistoErr& H) : xmin_(1.), xmax_(-1.), dx_(0.), nx_(0), mMean(0) { if(H.nx_<=0) return; CreateOrResize(H.xmin_,H.xmax_,H.nx_); data_ = H.data_; err2_ = H.err2_; ndata_ = H.ndata_; mMean = H.mMean; } /********* Methode *********/ /*! Destructeur */ HistoErr::~HistoErr(void) { mMean = 0; } /********* Methode *********/ /*! Gestion de l'allocation */ void HistoErr::CreateOrResize(r_8 xmin,r_8 xmax,int_4 nx) { xmin_ = xmin; xmax_ = xmax; nx_ = nx; dx_=0.; if(nx_>0) { data_.ReSize(nx_); data_ = 0.; err2_.ReSize(nx_); err2_ = 0.; ndata_.ReSize(nx_); ndata_ = 0.; dx_ = (xmax_-xmin_)/nx_; } mMean = 0; } /********* Methode *********/ /*! Remise a zero */ void HistoErr::Zero(void) { if(nx_<=0) return; data_ = 0.; err2_ = 0.; ndata_ = 0.; mMean = 0; } /********* Methode *********/ /*! Recompute XMin and XMax so that the CENTER of the first bin is exactly XMin and the CENTER of the last bin is exactly XMax. Remember that otherwise XMin is the beginning of the first bin and XMax is the end of the last bin WARNING: number of bins is kept, bin width is changed */ void HistoErr::ReCenterBin(void) { if(nx_<=1) return; double dx = (xmax_-xmin_)/(nx_-1); xmin_ -= dx/2.; xmax_ += dx/2.; dx_ = (xmax_-xmin_)/nx_; } /********* Methode *********/ /*! Recompute XMin and XMax so that the CENTER of the first bin is exactly XMin and the CENTER of the last bin is exactly XMax. Remember that otherwise XMin is the beginning of the first bin and XMax is the end of the last bin WARNING: bin width is kept, number of bins is increased by 1 */ void HistoErr::ReCenterBinW(void) { if(nx_<=1) return; CreateOrResize(xmin_-dx_/2.,xmax_+dx_/2.,nx_+1); } /********* Methode *********/ /*! Compute the mean histogram. Each bin content is divided by the number of entries in the bin. Each squared error is divided by the number of entries in the bin. The number of entries by bin is NOT set to 1 (calling ToMean many time will change the histogram !) */ void HistoErr::ToMean(void) { if(nx_<1) return; mMean++; for(int_4 i=0;i=nx_) continue; data_(ii) += hfrom.data_(ii); err2_(ii) += hfrom.err2_(ii); ndata_(ii) += hfrom.ndata_(ii); } mMean = hfrom.mMean; } /********* Methode *********/ /*! Return the sum of bin value */ double HistoErr::Sum(void) { double s = 0.; for(int_4 i=0;i , pour SGI-CC en particulier */ void ObjFileIO::ReadSelf(PInPersist& is) { string strg; if(dobj==NULL) dobj = new HistoErr; // Lecture entete is.GetStr(strg); // Nombre d'appels a ToMean/FromMean is.Get(dobj->mMean); // Lecture des parametres HistoErr is.Get(dobj->xmin_); is.Get(dobj->xmax_); is.Get(dobj->nx_); is.Get(dobj->dx_); // Lecture des donnees if(dobj->nx_>0) { is >> dobj->data_; is >> dobj->err2_; is >> dobj->ndata_; } return; } DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ void ObjFileIO::WriteSelf(POutPersist& os) const { if(dobj == NULL) return; string strg; // Ecriture entete strg = "HistErr"; os.PutStr(strg); // Nombre d'appels a ToMean/FromMean os.Put(dobj->mMean); // Ecriture des parametres HistoErr os.Put(dobj->xmin_); os.Put(dobj->xmax_); os.Put(dobj->nx_); os.Put(dobj->dx_); // Ecriture des donnees if(dobj->nx_>0) { os << dobj->data_; os << dobj->err2_; os << dobj->ndata_; } return; } #ifdef __CXX_PRAGMA_TEMPLATES__ #pragma define_template ObjFileIO #endif #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) template class ObjFileIO; #endif } // FIN namespace SOPHYA