[2615] | 1 | #include "sopnamsp.h"
|
---|
[2603] | 2 | #include "machdefs.h"
|
---|
| 3 | #include <string.h>
|
---|
| 4 | #include <stdio.h>
|
---|
| 5 | #include <math.h>
|
---|
| 6 | #include "histinit.h"
|
---|
| 7 | #include "histerr.h"
|
---|
| 8 | #include "perrors.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)
|
---|
[3049] | 19 | : Histo(), mNData(NULL), mCorrel(0)
|
---|
[2603] | 20 | {
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | /********* Methode *********/
|
---|
| 24 | /*! Constructeur d'un histo de nBin bins allant de xMin a xMax */
|
---|
| 25 | HistoErr::HistoErr(r_8 xMin, r_8 xMax, int_4 nBin)
|
---|
[3049] | 26 | : Histo(xMin,xMax,nBin), mNData(NULL), mCorrel(0)
|
---|
[2603] | 27 | {
|
---|
| 28 | this->Errors();
|
---|
[2608] | 29 | allocate_mNData(nBin);
|
---|
| 30 | Zero();
|
---|
[2603] | 31 | }
|
---|
| 32 |
|
---|
| 33 | /********* Methode *********/
|
---|
| 34 | /*! Constructeur par copie */
|
---|
| 35 | HistoErr::HistoErr(const HistoErr& H)
|
---|
[3049] | 36 | : Histo(H), mNData(NULL), mCorrel(H.mCorrel)
|
---|
[2603] | 37 | {
|
---|
[2608] | 38 | allocate_mNData(H.mBins);
|
---|
[2626] | 39 | if(mBins>0) memcpy(mNData,H.mNData,mBins*sizeof(r_8));
|
---|
[2603] | 40 | }
|
---|
| 41 |
|
---|
| 42 | /********* Methode *********/
|
---|
| 43 | /*! Destructeur */
|
---|
| 44 | HistoErr::~HistoErr(void)
|
---|
| 45 | {
|
---|
[2619] | 46 | Delete();
|
---|
[2603] | 47 | }
|
---|
[2619] | 48 |
|
---|
[2608] | 49 | /********* Methode *********/
|
---|
| 50 | /*! Allocation du tableau mNData */
|
---|
| 51 | void HistoErr::allocate_mNData(int nbin)
|
---|
| 52 | {
|
---|
| 53 | if(nbin<=0) return;
|
---|
| 54 | if(mNData) {delete [] mNData; mNData=NULL;}
|
---|
[2626] | 55 | mNData = new r_8[nbin];
|
---|
[2608] | 56 | }
|
---|
[2603] | 57 |
|
---|
| 58 | /********* Methode *********/
|
---|
[2619] | 59 | /*! Delete des tableaux */
|
---|
| 60 | void HistoErr::Delete(void)
|
---|
| 61 | {
|
---|
| 62 | Histo::Delete();
|
---|
| 63 | if(mNData) {delete [] mNData; mNData=NULL;}
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /********* Methode *********/
|
---|
[2603] | 67 | /*!
|
---|
| 68 | Remise a zero
|
---|
| 69 | */
|
---|
| 70 | void HistoErr::Zero(void)
|
---|
| 71 | {
|
---|
| 72 | Histo::Zero();
|
---|
[2626] | 73 | if(mNData) memset(mNData,0,mBins*sizeof(r_8));
|
---|
[3049] | 74 | mCorrel = 0;
|
---|
[2603] | 75 | }
|
---|
| 76 |
|
---|
| 77 | /********* Methode *********/
|
---|
| 78 | /*!
|
---|
[2604] | 79 | Remplissage du contenu de l'histo pour le bin numBin poids w et l'erreur e
|
---|
| 80 | */
|
---|
[2626] | 81 | void HistoErr::SetBin(int_4 numBin, r_8 w, r_8 e, r_8 nb)
|
---|
[2604] | 82 | {
|
---|
| 83 | Histo::SetBin(numBin,w);
|
---|
| 84 | Histo::SetErr2(numBin,e*e);
|
---|
| 85 | SetNentB(numBin,nb);
|
---|
| 86 | return;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /********* Methode *********/
|
---|
| 90 | /*!
|
---|
| 91 | Remplissage nombre d'entrees pour le bin numBin
|
---|
| 92 | */
|
---|
[2626] | 93 | void HistoErr::SetNentB(int_4 numBin, r_8 nb)
|
---|
[2604] | 94 | {
|
---|
| 95 | if(numBin>=0 && numBin<mBins) mNData[numBin] = nb;
|
---|
| 96 | return;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /*!
|
---|
[2603] | 100 | Remplissage d'un tableau avec les nombres d'entrees dans le bin de l'histo
|
---|
| 101 | */
|
---|
[2626] | 102 | void HistoErr::GetNBin(TVector<r_8>& v) const
|
---|
[2603] | 103 | {
|
---|
| 104 | v.Realloc(mBins);
|
---|
| 105 | for(int_4 i=0;i<mBins;i++) v(i) = mNData[i];
|
---|
| 106 | return;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /********* Methode *********/
|
---|
| 110 | /*!
|
---|
| 111 | Remplissage du nombre d'entrees dans les bins de l'histo avec les valeurs d'un vecteur
|
---|
| 112 | */
|
---|
[2626] | 113 | void HistoErr::PutNBin(TVector<r_8> &v)
|
---|
[2603] | 114 | {
|
---|
[2604] | 115 | int_4 n = (v.NElts()<mBins) ? v.NElts(): mBins;
|
---|
| 116 | if(n>0) for(int_4 i=0;i<n;i++) mNData[i] = v(i);
|
---|
[2603] | 117 | return;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[2608] | 120 | /********* Methode *********/
|
---|
| 121 | /*!
|
---|
[2604] | 122 | Compute the correlation histogram.
|
---|
| 123 | Each bin content is divided by the number of entries in that bin.
|
---|
| 124 | Each squared error is divided by the number of entries in that bin.
|
---|
[2622] | 125 | The number of entries by bin is NOT set to 1 (calling ToCorrel
|
---|
| 126 | many time will change the histogram !)
|
---|
[2604] | 127 | */
|
---|
| 128 | void HistoErr::ToCorrel(void)
|
---|
| 129 | {
|
---|
| 130 | if(mBins<1) return;
|
---|
[3049] | 131 | mCorrel++;
|
---|
[2604] | 132 | for(int_4 i=0;i<mBins;i++) {
|
---|
[2627] | 133 | if(mNData[i]<1.) continue;
|
---|
[2626] | 134 | mData[i] /= mNData[i];
|
---|
| 135 | mErr2[i] /= mNData[i];
|
---|
[2604] | 136 | }
|
---|
| 137 | return;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[2619] | 140 | /********* Methode *********/
|
---|
| 141 | /*!
|
---|
[2819] | 142 | Recompute back the original HistoErr before ToCorrel action
|
---|
| 143 | */
|
---|
| 144 | void HistoErr::FromCorrel(void)
|
---|
| 145 | {
|
---|
| 146 | if(mBins<1) return;
|
---|
[3049] | 147 | mCorrel--;
|
---|
[2819] | 148 | for(int_4 i=0;i<mBins;i++) {
|
---|
| 149 | if(mNData[i]<1.) continue;
|
---|
| 150 | mData[i] *= mNData[i];
|
---|
| 151 | mErr2[i] *= mNData[i];
|
---|
| 152 | }
|
---|
| 153 | return;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | /********* Methode *********/
|
---|
| 157 | /*!
|
---|
[2628] | 158 | Fill the histogram with an other histogram
|
---|
| 159 | */
|
---|
| 160 | void HistoErr::FillFrHErr(HistoErr& hfrom)
|
---|
| 161 | {
|
---|
| 162 | if(mBins<=0) return;
|
---|
| 163 | if(hfrom.mBins<=0) return;
|
---|
| 164 |
|
---|
| 165 | Zero();
|
---|
| 166 |
|
---|
| 167 | for(int_4 i=0;i<hfrom.mBins;i++) {
|
---|
| 168 | int numBin = FindBin(hfrom.BinCenter(i));
|
---|
| 169 | if(numBin<0) mUnder += hfrom.mData[i];
|
---|
| 170 | else if(numBin>=mBins) mOver += hfrom.mData[i];
|
---|
| 171 | else {
|
---|
| 172 | mData[numBin] += hfrom.mData[i];
|
---|
| 173 | mNData[numBin] += hfrom.mNData[i];
|
---|
| 174 | mErr2[numBin] += hfrom.mErr2[i];
|
---|
| 175 | nHist += hfrom.mData[i];
|
---|
| 176 | nEntries++;
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
[3049] | 179 | mCorrel = hfrom.mCorrel;
|
---|
[2628] | 180 |
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | /********* Methode *********/
|
---|
| 184 | /*!
|
---|
[2619] | 185 | Operateur egal HistoErr = HistoErr
|
---|
| 186 | */
|
---|
| 187 | HistoErr& HistoErr::operator = (const HistoErr& h)
|
---|
| 188 | {
|
---|
| 189 | if(this==&h) return *this;
|
---|
| 190 | Delete();
|
---|
| 191 | if(h.mBins<=0) return *this;
|
---|
| 192 |
|
---|
| 193 | // Copy the "Histo" part
|
---|
| 194 | (Histo)(*this) = Histo::operator=(h);
|
---|
| 195 | // Copy the "entries by bin" table
|
---|
| 196 | allocate_mNData(h.mBins);
|
---|
[2626] | 197 | memcpy(mNData,h.mNData,mBins*sizeof(r_8));
|
---|
[3049] | 198 | mCorrel = h.mCorrel;
|
---|
[2619] | 199 |
|
---|
| 200 | return *this;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[2603] | 203 | ///////////////////////////////////////////////////////////
|
---|
| 204 | // --------------------------------------------------------
|
---|
| 205 | // Les objets delegues pour la gestion de persistance
|
---|
| 206 | // --------------------------------------------------------
|
---|
| 207 | ///////////////////////////////////////////////////////////
|
---|
| 208 |
|
---|
| 209 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
| 210 | void ObjFileIO<HistoErr>::ReadSelf(PInPersist& is)
|
---|
| 211 | {
|
---|
[2608] | 212 | string strg;
|
---|
[2603] | 213 |
|
---|
| 214 | if(dobj==NULL) dobj=new HistoErr;
|
---|
| 215 | else dobj->Delete();
|
---|
| 216 |
|
---|
| 217 | // Lecture entete
|
---|
[2608] | 218 | is.GetStr(strg);
|
---|
[2603] | 219 |
|
---|
[3049] | 220 | // Nombre d'appels a ToCorrel/FromCorrel
|
---|
| 221 | is.Get(dobj->mCorrel);
|
---|
| 222 |
|
---|
[2603] | 223 | // Lecture des donnees HistoErr
|
---|
| 224 | is.Get(dobj->mBins);
|
---|
[2608] | 225 | dobj->allocate_mNData(dobj->mBins);
|
---|
[2603] | 226 | is.Get(dobj->mNData, dobj->mBins);
|
---|
| 227 |
|
---|
| 228 | // Lecture de l'histogramme
|
---|
| 229 | is >> (Histo&)(*dobj);
|
---|
| 230 |
|
---|
| 231 | return;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
| 235 | void ObjFileIO<HistoErr>::WriteSelf(POutPersist& os) const
|
---|
| 236 | {
|
---|
| 237 | if(dobj == NULL) return;
|
---|
[2608] | 238 | string strg;
|
---|
[2603] | 239 |
|
---|
[3049] | 240 | // Ecriture entete
|
---|
[2608] | 241 | strg = "HistErr";
|
---|
| 242 | os.PutStr(strg);
|
---|
[2603] | 243 |
|
---|
[3049] | 244 | // Nombre d'appels a ToCorrel/FromCorrel
|
---|
| 245 | os.Put(dobj->mCorrel);
|
---|
| 246 |
|
---|
[2603] | 247 | // Ecriture des valeurs
|
---|
| 248 | os.Put(dobj->mBins);
|
---|
| 249 |
|
---|
| 250 | // Ecriture des donnees HistoErr nombre d entree par bin
|
---|
| 251 | os.Put(dobj->mNData, dobj->mBins);
|
---|
| 252 |
|
---|
| 253 | // Ecriture de l'histogramme
|
---|
| 254 | os << (Histo&)(*dobj);
|
---|
| 255 |
|
---|
| 256 | return;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 260 | #pragma define_template ObjFileIO<HistoErr>
|
---|
| 261 | #endif
|
---|
| 262 |
|
---|
| 263 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[2868] | 264 | template class SOPHYA::ObjFileIO<HistoErr>;
|
---|
[2603] | 265 | #endif
|
---|