#include "sopnamsp.h" #include "machdefs.h" #include #include #include #include "perrors.h" #include "fioarr.h" #include "histerr.h" /*! \class SOPHYA::HistoErr \ingroup HiStats Classe d'histogrammes 1D avec erreurs donnees par l'utilisateur */ /********* Methode *********/ /*! Constructeur par defaut */ HistoErr::HistoErr(void) : xmin_(1.), xmax_(-1.), nx_(0), dx_(0.) , mCorrel(0) { } /********* Methode *********/ /*! Constructeur d'un histo */ HistoErr::HistoErr(r_8 xmin,r_8 xmax,int_4 nx) : mCorrel(0) { CreateOrResize(xmin,xmax,nx); } /********* Methode *********/ /*! Constructeur par copie */ HistoErr::HistoErr(const HistoErr& H) : mCorrel(H.mCorrel) { if(H.nx_<=0) return; CreateOrResize(H.xmin_,H.xmax_,H.nx_); data_ = H.data_; err2_ = H.err2_; ndata_ = H.ndata_; } /********* Methode *********/ /*! Destructeur */ HistoErr::~HistoErr(void) { mCorrel = 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_; } mCorrel = 0; } /********* Methode *********/ /*! Remise a zero */ void HistoErr::Zero(void) { if(nx_<=0) return; data_ = 0.; err2_ = 0.; ndata_ = 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 */ 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 *********/ /*! Compute the correlation histogram. Each bin content is divided by the number of entries in that bin. Each squared error is divided by the number of entries in that bin. The number of entries by bin is NOT set to 1 (calling ToCorrel many time will change the histogram !) */ void HistoErr::ToCorrel(void) { if(nx_<1) return; mCorrel++; for(int_4 i=0;i=nx_) continue; data_(ii) += hfrom.data_(ii); err2_(ii) += hfrom.err2_(ii); ndata_(ii) += hfrom.ndata_(ii); } mCorrel = hfrom.mCorrel; } /********* Methode *********/ /*! Operateur egal HistoErr = HistoErr */ HistoErr& HistoErr::operator = (const HistoErr& h) { if(this==&h) return *this; CreateOrResize(h.xmin_,h.xmax_,h.nx_); data_ = h.data_; err2_ = h.err2_; ndata_ = h.ndata_; mCorrel = h.mCorrel; return *this; } /********* Methode *********/ /*! Operateur de multiplication par une constante */ HistoErr& HistoErr::operator *= (r_8 b) { r_8 b2 = b*b; for(int_4 i=0;imCorrel); // 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 SOPHYA::ObjFileIO; #endif