[2615] | 1 | #include "sopnamsp.h"
|
---|
[2603] | 2 | #include "machdefs.h"
|
---|
| 3 | #include <string.h>
|
---|
| 4 | #include <stdio.h>
|
---|
| 5 | #include <math.h>
|
---|
[3123] | 6 | #include "perrors.h"
|
---|
| 7 | #include "fioarr.h"
|
---|
[2603] | 8 | #include "histerr.h"
|
---|
| 9 |
|
---|
| 10 | /*!
|
---|
| 11 | \class SOPHYA::HistoErr
|
---|
| 12 | \ingroup HiStats
|
---|
| 13 | Classe d'histogrammes 1D avec erreurs donnees par l'utilisateur
|
---|
| 14 | */
|
---|
| 15 |
|
---|
| 16 | /********* Methode *********/
|
---|
| 17 | /*! Constructeur par defaut */
|
---|
| 18 | HistoErr::HistoErr(void)
|
---|
[3123] | 19 | : xmin_(1.), xmax_(-1.), nx_(0), dx_(0.)
|
---|
| 20 | , mCorrel(0)
|
---|
[2603] | 21 | {
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | /********* Methode *********/
|
---|
[3123] | 25 | /*! Constructeur d'un histo */
|
---|
| 26 | HistoErr::HistoErr(r_8 xmin,r_8 xmax,int_4 nx)
|
---|
| 27 | : mCorrel(0)
|
---|
[2603] | 28 | {
|
---|
[3123] | 29 | CreateOrResize(xmin,xmax,nx);
|
---|
[2603] | 30 | }
|
---|
| 31 |
|
---|
| 32 | /********* Methode *********/
|
---|
| 33 | /*! Constructeur par copie */
|
---|
| 34 | HistoErr::HistoErr(const HistoErr& H)
|
---|
[3123] | 35 | : mCorrel(H.mCorrel)
|
---|
[2603] | 36 | {
|
---|
[3123] | 37 | if(H.nx_<=0) return;
|
---|
| 38 | CreateOrResize(H.xmin_,H.xmax_,H.nx_);
|
---|
| 39 | data_ = H.data_;
|
---|
| 40 | err2_ = H.err2_;
|
---|
| 41 | ndata_ = H.ndata_;
|
---|
[2603] | 42 | }
|
---|
| 43 |
|
---|
| 44 | /********* Methode *********/
|
---|
| 45 | /*! Destructeur */
|
---|
| 46 | HistoErr::~HistoErr(void)
|
---|
| 47 | {
|
---|
[3123] | 48 | mCorrel = 0;
|
---|
[2603] | 49 | }
|
---|
[2619] | 50 |
|
---|
[2608] | 51 | /********* Methode *********/
|
---|
[3053] | 52 | /*! Gestion de l'allocation */
|
---|
[3123] | 53 | void HistoErr::CreateOrResize(r_8 xmin,r_8 xmax,int_4 nx)
|
---|
[3053] | 54 | {
|
---|
[3123] | 55 | xmin_ = xmin; xmax_ = xmax; nx_ = nx; dx_=0.;
|
---|
| 56 | if(nx_>0) {
|
---|
| 57 | data_.ReSize(nx_); data_ = 0.;
|
---|
| 58 | err2_.ReSize(nx_); err2_ = 0.;
|
---|
| 59 | ndata_.ReSize(nx_); ndata_ = 0.;
|
---|
| 60 | dx_ = (xmax_-xmin_)/nx_;
|
---|
| 61 | }
|
---|
[3053] | 62 | mCorrel = 0;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | /********* Methode *********/
|
---|
[2603] | 66 | /*!
|
---|
| 67 | Remise a zero
|
---|
| 68 | */
|
---|
| 69 | void HistoErr::Zero(void)
|
---|
| 70 | {
|
---|
[3123] | 71 | if(nx_<=0) return;
|
---|
| 72 | data_ = 0.;
|
---|
| 73 | err2_ = 0.;
|
---|
| 74 | ndata_ = 0.;
|
---|
[2603] | 75 | }
|
---|
| 76 |
|
---|
| 77 | /********* Methode *********/
|
---|
| 78 | /*!
|
---|
[3123] | 79 | Recompute XMin (and XMax so that
|
---|
| 80 | the CENTER of the first bin is exactly XMin and
|
---|
| 81 | the CENTER of the last bin is exactly XMax.
|
---|
| 82 | Remember that otherwise
|
---|
| 83 | XMin is the beginning of the first bin
|
---|
| 84 | and XMax is the end of the last bin
|
---|
[2604] | 85 | */
|
---|
[3123] | 86 | void HistoErr::ReCenterBin(void)
|
---|
[2604] | 87 | {
|
---|
[3123] | 88 | if(nx_<=1) return;
|
---|
| 89 | double dx = (xmax_-xmin_)/(nx_-1);
|
---|
| 90 | xmin_ -= dx/2.;
|
---|
| 91 | xmax_ += dx/2.;
|
---|
| 92 | dx_ = (xmax_-xmin_)/nx_;
|
---|
[2604] | 93 | }
|
---|
| 94 |
|
---|
| 95 | /********* Methode *********/
|
---|
| 96 | /*!
|
---|
| 97 | Compute the correlation histogram.
|
---|
| 98 | Each bin content is divided by the number of entries in that bin.
|
---|
| 99 | Each squared error is divided by the number of entries in that bin.
|
---|
[2622] | 100 | The number of entries by bin is NOT set to 1 (calling ToCorrel
|
---|
| 101 | many time will change the histogram !)
|
---|
[2604] | 102 | */
|
---|
| 103 | void HistoErr::ToCorrel(void)
|
---|
| 104 | {
|
---|
[3123] | 105 | if(nx_<1) return;
|
---|
[3049] | 106 | mCorrel++;
|
---|
[3123] | 107 | for(int_4 i=0;i<nx_;i++) {
|
---|
| 108 | if(ndata_(i)<1.) continue;
|
---|
| 109 | data_(i) /= ndata_(i);
|
---|
| 110 | err2_(i) /= ndata_(i);
|
---|
[2604] | 111 | }
|
---|
| 112 | return;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[2619] | 115 | /********* Methode *********/
|
---|
| 116 | /*!
|
---|
[2819] | 117 | Recompute back the original HistoErr before ToCorrel action
|
---|
| 118 | */
|
---|
| 119 | void HistoErr::FromCorrel(void)
|
---|
| 120 | {
|
---|
[3123] | 121 | if(nx_<1) return;
|
---|
[3049] | 122 | mCorrel--;
|
---|
[3123] | 123 | for(int_4 i=0;i<nx_;i++) {
|
---|
| 124 | if(ndata_(i)<1.) continue;
|
---|
| 125 | data_(i) *= ndata_(i);
|
---|
| 126 | err2_(i) *= ndata_(i);
|
---|
[2819] | 127 | }
|
---|
| 128 | return;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /********* Methode *********/
|
---|
| 132 | /*!
|
---|
[2628] | 133 | Fill the histogram with an other histogram
|
---|
| 134 | */
|
---|
| 135 | void HistoErr::FillFrHErr(HistoErr& hfrom)
|
---|
| 136 | {
|
---|
[3123] | 137 | if(nx_<=0) return;
|
---|
| 138 | if(hfrom.nx_<=0) return;
|
---|
[2628] | 139 |
|
---|
| 140 | Zero();
|
---|
| 141 |
|
---|
[3123] | 142 | for(int_4 i=0;i<hfrom.nx_;i++) {
|
---|
| 143 | r_8 x = hfrom.BinCenter(i);
|
---|
| 144 | int ii = FindBin(x);
|
---|
| 145 | if(ii<0 || ii>=nx_) continue;
|
---|
| 146 | data_(ii) += hfrom.data_(ii);
|
---|
| 147 | err2_(ii) += hfrom.err2_(ii);
|
---|
| 148 | ndata_(ii) += hfrom.ndata_(ii);
|
---|
[2628] | 149 | }
|
---|
[3049] | 150 | mCorrel = hfrom.mCorrel;
|
---|
[2628] | 151 |
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | /********* Methode *********/
|
---|
| 155 | /*!
|
---|
[2619] | 156 | Operateur egal HistoErr = HistoErr
|
---|
| 157 | */
|
---|
| 158 | HistoErr& HistoErr::operator = (const HistoErr& h)
|
---|
| 159 | {
|
---|
| 160 | if(this==&h) return *this;
|
---|
[3123] | 161 | CreateOrResize(h.xmin_,h.xmax_,h.nx_);
|
---|
| 162 | data_ = h.data_;
|
---|
| 163 | err2_ = h.err2_;
|
---|
| 164 | ndata_ = h.ndata_;
|
---|
[3049] | 165 | mCorrel = h.mCorrel;
|
---|
[2619] | 166 | return *this;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
[3053] | 169 | /********* Methode *********/
|
---|
| 170 | /*!
|
---|
| 171 | Print info
|
---|
| 172 | */
|
---|
| 173 | void HistoErr::Show(ostream & os) const
|
---|
| 174 | {
|
---|
[3123] | 175 | os <<"HistoErr(ncorrel="<<mCorrel<<")"<<endl
|
---|
| 176 | <<" nx="<<nx_<<" ["<<xmin_<<","<<xmax_<<"] dx="<<dx_<<endl;
|
---|
[3053] | 177 | }
|
---|
| 178 |
|
---|
[2603] | 179 | ///////////////////////////////////////////////////////////
|
---|
| 180 | // --------------------------------------------------------
|
---|
| 181 | // Les objets delegues pour la gestion de persistance
|
---|
| 182 | // --------------------------------------------------------
|
---|
| 183 | ///////////////////////////////////////////////////////////
|
---|
| 184 |
|
---|
| 185 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
| 186 | void ObjFileIO<HistoErr>::ReadSelf(PInPersist& is)
|
---|
| 187 | {
|
---|
[2608] | 188 | string strg;
|
---|
[2603] | 189 |
|
---|
[3123] | 190 | if(dobj==NULL) dobj = new HistoErr;
|
---|
[2603] | 191 |
|
---|
| 192 | // Lecture entete
|
---|
[2608] | 193 | is.GetStr(strg);
|
---|
[2603] | 194 |
|
---|
[3049] | 195 | // Nombre d'appels a ToCorrel/FromCorrel
|
---|
| 196 | is.Get(dobj->mCorrel);
|
---|
| 197 |
|
---|
[3123] | 198 | // Lecture des parametres HistoErr
|
---|
| 199 | is.Get(dobj->xmin_);
|
---|
| 200 | is.Get(dobj->xmax_);
|
---|
| 201 | is.Get(dobj->nx_);
|
---|
| 202 | is.Get(dobj->dx_);
|
---|
[2603] | 203 |
|
---|
[3123] | 204 | // Lecture des donnees
|
---|
| 205 | if(dobj->nx_>0) {
|
---|
| 206 | is >> dobj->data_;
|
---|
| 207 | is >> dobj->err2_;
|
---|
| 208 | is >> dobj->ndata_;
|
---|
| 209 | }
|
---|
[2603] | 210 |
|
---|
| 211 | return;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
| 215 | void ObjFileIO<HistoErr>::WriteSelf(POutPersist& os) const
|
---|
| 216 | {
|
---|
| 217 | if(dobj == NULL) return;
|
---|
[2608] | 218 | string strg;
|
---|
[2603] | 219 |
|
---|
[3049] | 220 | // Ecriture entete
|
---|
[2608] | 221 | strg = "HistErr";
|
---|
| 222 | os.PutStr(strg);
|
---|
[2603] | 223 |
|
---|
[3049] | 224 | // Nombre d'appels a ToCorrel/FromCorrel
|
---|
| 225 | os.Put(dobj->mCorrel);
|
---|
| 226 |
|
---|
[3123] | 227 | // Ecriture des parametres HistoErr
|
---|
| 228 | os.Put(dobj->xmin_);
|
---|
| 229 | os.Put(dobj->xmax_);
|
---|
| 230 | os.Put(dobj->nx_);
|
---|
| 231 | os.Put(dobj->dx_);
|
---|
[2603] | 232 |
|
---|
[3123] | 233 | // Ecriture des donnees
|
---|
| 234 | if(dobj->nx_>0) {
|
---|
| 235 | os << dobj->data_;
|
---|
| 236 | os << dobj->err2_;
|
---|
| 237 | os << dobj->ndata_;
|
---|
| 238 | }
|
---|
[2603] | 239 |
|
---|
| 240 | return;
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 244 | #pragma define_template ObjFileIO<HistoErr>
|
---|
| 245 | #endif
|
---|
| 246 |
|
---|
| 247 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[2868] | 248 | template class SOPHYA::ObjFileIO<HistoErr>;
|
---|
[2603] | 249 | #endif
|
---|