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