[763] | 1 | //
|
---|
[3044] | 2 | // $Id: histos.cc,v 1.22 2006-08-07 17:38:47 cmv Exp $
|
---|
[763] | 3 | //
|
---|
| 4 |
|
---|
[2615] | 5 | #include "sopnamsp.h"
|
---|
[763] | 6 | #include "machdefs.h"
|
---|
| 7 | #include <string.h>
|
---|
| 8 | #include <stdio.h>
|
---|
| 9 | #include <math.h>
|
---|
| 10 | #include "histos.h"
|
---|
| 11 | #include "perrors.h"
|
---|
| 12 | #include "poly.h"
|
---|
| 13 | #include "strutil.h"
|
---|
| 14 |
|
---|
[926] | 15 | /*!
|
---|
| 16 | \class SOPHYA::Histo
|
---|
| 17 | \ingroup HiStats
|
---|
| 18 | Classe d'histogrammes 1D
|
---|
| 19 | */
|
---|
| 20 |
|
---|
[763] | 21 | /********* Methode *********/
|
---|
[914] | 22 | /*! Constructeur par defaut */
|
---|
[763] | 23 | Histo::Histo()
|
---|
[1092] | 24 | : mData(NULL), mErr2(NULL),
|
---|
| 25 | mUnder(0), mOver(0), nHist(0), nEntries(0),
|
---|
| 26 | mBins(0), mMin(0), mMax(0),
|
---|
[763] | 27 | binWidth(0)
|
---|
| 28 | {
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | /********* Methode *********/
|
---|
[914] | 32 | /*! Constructeur d'un histo de nBin bins allant de xMin a xMax */
|
---|
[1092] | 33 | Histo::Histo(r_8 xMin, r_8 xMax, int_4 nBin)
|
---|
| 34 | : mData((nBin>0) ? new r_8[nBin] : NULL),
|
---|
| 35 | mErr2(NULL),
|
---|
| 36 | mUnder(0), mOver(0), nHist(0), nEntries(0),
|
---|
| 37 | mBins(nBin), mMin(xMin), mMax(xMax),
|
---|
| 38 | binWidth((nBin>0) ? (mMax-mMin)/nBin : 0)
|
---|
[763] | 39 | {
|
---|
| 40 | Zero();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /********* Methode *********/
|
---|
[1092] | 44 | /*! Constructeur d'un histo de nBin bins allant de xMin a xMax */
|
---|
| 45 | Histo::Histo(r_4 xMin, r_4 xMax, int_4 nBin)
|
---|
| 46 | : mData((nBin>0) ? new r_8[nBin] : NULL),
|
---|
| 47 | mErr2(NULL),
|
---|
| 48 | mUnder(0), mOver(0), nHist(0), nEntries(0),
|
---|
| 49 | mBins(nBin), mMin((r_8)xMin), mMax((r_8)xMax),
|
---|
| 50 | binWidth((nBin>0) ? (mMax-mMin)/nBin : 0)
|
---|
| 51 | {
|
---|
| 52 | Zero();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /********* Methode *********/
|
---|
[914] | 56 | /*! Constructeur par copie */
|
---|
[763] | 57 | Histo::Histo(const Histo& H)
|
---|
[1092] | 58 | : mData((H.mBins>0)? new r_8[H.mBins] : NULL),
|
---|
[2619] | 59 | mErr2((H.mBins>0 && H.mErr2!=NULL)? new r_8[H.mBins]: NULL),
|
---|
[1092] | 60 | mUnder(H.mUnder), mOver(H.mOver), nHist(H.nHist), nEntries(H.nEntries),
|
---|
| 61 | mBins(H.mBins), mMin(H.mMin), mMax(H.mMax),
|
---|
[763] | 62 | binWidth(H.binWidth)
|
---|
| 63 | {
|
---|
[2619] | 64 | if(mBins<=0) return;
|
---|
| 65 | memcpy(mData,H.mData,mBins*sizeof(r_8));
|
---|
| 66 | if(H.mErr2) memcpy(mErr2, H.mErr2, mBins*sizeof(r_8));
|
---|
[763] | 67 | }
|
---|
| 68 |
|
---|
| 69 | /********* Methode *********/
|
---|
[914] | 70 | /*! Gestion de la des-allocation */
|
---|
[763] | 71 | void Histo::Delete()
|
---|
| 72 | {
|
---|
[1092] | 73 | if( mData != NULL ) { delete[] mData; mData = NULL;}
|
---|
| 74 | if( mErr2 != NULL ) { delete[] mErr2; mErr2 = NULL;}
|
---|
| 75 | mUnder = mOver = mMin = mMax = binWidth= 0.;
|
---|
[763] | 76 | nHist = 0.;
|
---|
[2628] | 77 | mBins = 0;
|
---|
| 78 | nEntries = 0;
|
---|
[763] | 79 | }
|
---|
| 80 |
|
---|
| 81 | /********* Methode *********/
|
---|
[914] | 82 | /*! Destructeur */
|
---|
[763] | 83 | Histo::~Histo()
|
---|
| 84 | {
|
---|
| 85 | Delete();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /********* Methode *********/
|
---|
[914] | 89 | /*!
|
---|
| 90 | Remise a zero
|
---|
| 91 | */
|
---|
[763] | 92 | void Histo::Zero()
|
---|
| 93 | {
|
---|
[2619] | 94 | if(mBins<=0 || mData==NULL) return;
|
---|
| 95 | memset(mData,0,mBins*sizeof(r_8));
|
---|
[1092] | 96 | mUnder = mOver = 0;
|
---|
[763] | 97 | nHist = 0;
|
---|
| 98 | nEntries = 0;
|
---|
[2619] | 99 | if(mErr2) memset(mErr2, 0, mBins*sizeof(r_8));
|
---|
[763] | 100 | }
|
---|
| 101 |
|
---|
| 102 | /********* Methode *********/
|
---|
[914] | 103 | /*!
|
---|
| 104 | Pour avoir le calcul des erreurs
|
---|
| 105 | */
|
---|
[763] | 106 | void Histo::Errors()
|
---|
| 107 | {
|
---|
[1092] | 108 | if(mBins<=0) return;
|
---|
| 109 | if(mErr2==NULL) mErr2 = new r_8[mBins];
|
---|
[2619] | 110 | memset(mErr2,0,mBins*sizeof(r_8));
|
---|
[763] | 111 | }
|
---|
| 112 |
|
---|
| 113 | /********* Methode *********/
|
---|
[914] | 114 | /*!
|
---|
[3044] | 115 | Recompute XMin and XMax so that
|
---|
| 116 | the CENTER of the first bin is exactly XMin and
|
---|
| 117 | the CENTER of the last bin is exactly XMax.
|
---|
| 118 | Remember that otherwise
|
---|
| 119 | XMin is the beginning of the first bin
|
---|
| 120 | and XMax is the end of the last bin
|
---|
| 121 | */
|
---|
| 122 | void Histo::ReCenterBin(void)
|
---|
| 123 | {
|
---|
| 124 | if(mBins<=1) return;
|
---|
| 125 | double dx = (mMax-mMin)/(mBins-1);
|
---|
| 126 | mMin -= dx/2.;
|
---|
| 127 | mMax += dx/2.;
|
---|
| 128 | binWidth = (mMax-mMin)/mBins;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /********* Methode *********/
|
---|
| 132 | /*!
|
---|
[1056] | 133 | Operateur egal Histo = Histo
|
---|
[914] | 134 | */
|
---|
[763] | 135 | Histo& Histo::operator = (const Histo& h)
|
---|
| 136 | {
|
---|
| 137 | if(this == &h) return *this;
|
---|
[2619] | 138 | Delete();
|
---|
| 139 | if(h.mBins<=0 || h.mData==NULL) return *this;
|
---|
[763] | 140 |
|
---|
[2619] | 141 | mData = new r_8[h.mBins];
|
---|
| 142 | if(h.mErr2) mErr2 = new r_8[h.mBins];
|
---|
[1092] | 143 | mUnder = h.mUnder;
|
---|
| 144 | mOver = h.mOver;
|
---|
[763] | 145 | nHist = h.nHist;
|
---|
| 146 | nEntries = h.nEntries;
|
---|
[1092] | 147 | mBins = h.mBins;
|
---|
| 148 | mMin = h.mMin;
|
---|
| 149 | mMax = h.mMax;
|
---|
[763] | 150 | binWidth = h.binWidth;
|
---|
| 151 |
|
---|
[2619] | 152 | memcpy(mData,h.mData,mBins*sizeof(r_8));
|
---|
| 153 | if(mErr2) memcpy(mErr2,h.mErr2,mBins*sizeof(r_8));
|
---|
[763] | 154 |
|
---|
| 155 | return *this;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | /********* Methode *********/
|
---|
[914] | 159 | /*!
|
---|
| 160 | Operateur de multiplication par une constante
|
---|
| 161 | */
|
---|
[1092] | 162 | Histo& Histo::operator *= (r_8 b)
|
---|
[763] | 163 | {
|
---|
[1092] | 164 | r_8 b2 = b*b;
|
---|
| 165 | for(int_4 i=0;i<mBins;i++) {
|
---|
| 166 | mData[i] *= b;
|
---|
| 167 | if(mErr2) mErr2[i] *= b2;
|
---|
[763] | 168 | }
|
---|
[1092] | 169 | mUnder *= b;
|
---|
| 170 | mOver *= b;
|
---|
[763] | 171 | nHist *= b;
|
---|
| 172 |
|
---|
| 173 | return *this;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[914] | 176 | /*!
|
---|
| 177 | Operateur de division par une constante
|
---|
| 178 | */
|
---|
[1092] | 179 | Histo& Histo::operator /= (r_8 b)
|
---|
[763] | 180 | {
|
---|
[2507] | 181 | if (b==0.) throw ParmError(PExcLongMessage(""));
|
---|
[1092] | 182 | r_8 b2 = b*b;
|
---|
| 183 | for(int_4 i=0;i<mBins;i++) {
|
---|
| 184 | mData[i] /= b;
|
---|
| 185 | if(mErr2) mErr2[i] /= b2;
|
---|
[763] | 186 | }
|
---|
[1092] | 187 | mUnder /= b;
|
---|
| 188 | mOver /= b;
|
---|
[763] | 189 | nHist /= b;
|
---|
| 190 |
|
---|
| 191 | return *this;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[914] | 194 | /*!
|
---|
| 195 | Operateur d'addition d'une constante
|
---|
| 196 | */
|
---|
[1092] | 197 | Histo& Histo::operator += (r_8 b)
|
---|
[763] | 198 | {
|
---|
[1092] | 199 | for(int_4 i=0;i<mBins;i++) mData[i] += b;
|
---|
| 200 | mUnder += b;
|
---|
| 201 | mOver += b;
|
---|
| 202 | nHist += mBins*b;
|
---|
[763] | 203 |
|
---|
| 204 | return *this;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[914] | 207 | /*!
|
---|
| 208 | Operateur de soustraction d'une constante
|
---|
| 209 | */
|
---|
[1092] | 210 | Histo& Histo::operator -= (r_8 b)
|
---|
[763] | 211 | {
|
---|
[1092] | 212 | for(int_4 i=0;i<mBins;i++) mData[i] -= b;
|
---|
| 213 | mUnder -= b;
|
---|
| 214 | mOver -= b;
|
---|
| 215 | nHist -= mBins*b;
|
---|
[763] | 216 |
|
---|
| 217 | return *this;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | /********* Methode *********/
|
---|
[914] | 221 | /*!
|
---|
| 222 | Operateur H += H1
|
---|
| 223 | */
|
---|
[763] | 224 | Histo& Histo::operator += (const Histo& a)
|
---|
| 225 | {
|
---|
[2507] | 226 | if(mBins!=a.mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[1092] | 227 | for(int_4 i=0;i<mBins;i++) {
|
---|
| 228 | mData[i] += a(i);
|
---|
| 229 | if(mErr2 && a.mErr2) mErr2[i] += a.Error2(i);
|
---|
[763] | 230 | }
|
---|
[1092] | 231 | mUnder += a.mUnder;
|
---|
| 232 | mOver += a.mOver;
|
---|
[763] | 233 | nHist += a.nHist;
|
---|
| 234 | nEntries += a.nEntries;
|
---|
| 235 |
|
---|
| 236 | return *this;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
[914] | 239 | /*!
|
---|
| 240 | Operateur H -= H1
|
---|
| 241 | */
|
---|
[763] | 242 | Histo& Histo::operator -= (const Histo& a)
|
---|
| 243 | {
|
---|
[2507] | 244 | if(mBins!=a.mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[1092] | 245 | for(int_4 i=0;i<mBins;i++) {
|
---|
| 246 | mData[i] -= a(i);
|
---|
| 247 | if(mErr2 && a.mErr2) mErr2[i] += a.Error2(i);
|
---|
[763] | 248 | }
|
---|
[1092] | 249 | mUnder -= a.mUnder;
|
---|
| 250 | mOver -= a.mOver;
|
---|
[763] | 251 | nHist -= a.nHist;
|
---|
| 252 | nEntries += a.nEntries;
|
---|
| 253 |
|
---|
| 254 | return *this;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[914] | 257 | /*!
|
---|
| 258 | Operateur H *= H1
|
---|
| 259 | */
|
---|
[763] | 260 | Histo& Histo::operator *= (const Histo& a)
|
---|
| 261 | {
|
---|
[2507] | 262 | if(mBins!=a.mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[763] | 263 | nHist = 0.;
|
---|
[1092] | 264 | for(int_4 i=0;i<mBins;i++) {
|
---|
| 265 | if(mErr2 && a.mErr2)
|
---|
| 266 | mErr2[i] = a(i)*a(i)*mErr2[i] + mData[i]*mData[i]*a.Error2(i);
|
---|
| 267 | mData[i] *= a(i);
|
---|
| 268 | nHist += mData[i];
|
---|
[763] | 269 | }
|
---|
[1092] | 270 | mUnder *= a.mUnder;
|
---|
| 271 | mOver *= a.mOver;
|
---|
[763] | 272 | nEntries += a.nEntries;
|
---|
| 273 |
|
---|
| 274 | return *this;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[914] | 277 | /*!
|
---|
| 278 | Operateur H /= H1
|
---|
| 279 | */
|
---|
[763] | 280 | Histo& Histo::operator /= (const Histo& a)
|
---|
| 281 | {
|
---|
[2507] | 282 | if(mBins!=a.mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[763] | 283 | nHist = 0.;
|
---|
[1092] | 284 | for(int_4 i=0;i<mBins;i++) {
|
---|
[763] | 285 | if(a(i)==0.) {
|
---|
[1092] | 286 | mData[i]=0.;
|
---|
| 287 | if(mErr2) mErr2[i]=0.;
|
---|
[763] | 288 | continue;
|
---|
| 289 | }
|
---|
[1092] | 290 | if(mErr2 && a.mErr2)
|
---|
| 291 | mErr2[i] = (mErr2[i] + mData[i]/a(i)*mData[i]/a(i)*a.Error2(i))
|
---|
[763] | 292 | /(a(i)*a(i));
|
---|
[1092] | 293 | mData[i] /= a(i);
|
---|
| 294 | nHist += mData[i];
|
---|
[763] | 295 | }
|
---|
[1092] | 296 | if(a.mUnder!=0.) mUnder /= a.mUnder; else mUnder = 0.;
|
---|
| 297 | if(a.mOver!=0.) mOver /= a.mOver; else mOver = 0.;
|
---|
[763] | 298 | nEntries += a.nEntries;
|
---|
| 299 |
|
---|
| 300 | return *this;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | /********* Methode *********/
|
---|
[914] | 304 | /*!
|
---|
| 305 | Remplissage d'un tableau avec la valeur des abscisses
|
---|
| 306 | */
|
---|
[1109] | 307 | void Histo::GetAbsc(TVector<r_8> &v) const
|
---|
[763] | 308 | {
|
---|
[1092] | 309 | v.Realloc(mBins);
|
---|
| 310 | for(int_4 i=0;i<mBins;i++) v(i) = BinLowEdge(i);
|
---|
[763] | 311 | return;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[914] | 314 | /*!
|
---|
| 315 | Remplissage d'un tableau avec la valeur du contenu
|
---|
| 316 | */
|
---|
[1109] | 317 | void Histo::GetValue(TVector<r_8> &v) const
|
---|
[763] | 318 | {
|
---|
[1092] | 319 | v.Realloc(mBins);
|
---|
| 320 | for(int_4 i=0;i<mBins;i++) v(i) = mData[i];
|
---|
[763] | 321 | return;
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[914] | 324 | /*!
|
---|
| 325 | Remplissage d'un tableau avec la valeur des erreurs au carre
|
---|
| 326 | */
|
---|
[1109] | 327 | void Histo::GetError2(TVector<r_8> &v) const
|
---|
[763] | 328 | {
|
---|
[1092] | 329 | v.Realloc(mBins);
|
---|
| 330 | if(!mErr2) {for(int_4 i=0;i<mBins;i++) v(i) = 0.; return;}
|
---|
| 331 | for(int_4 i=0;i<mBins;i++) v(i) = mErr2[i];
|
---|
[763] | 332 | return;
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[914] | 335 | /*!
|
---|
| 336 | Remplissage d'un tableau avec la valeur des erreurs
|
---|
| 337 | */
|
---|
[1109] | 338 | void Histo::GetError(TVector<r_8> &v) const
|
---|
[763] | 339 | {
|
---|
[1092] | 340 | v.Realloc(mBins);
|
---|
| 341 | if(!mErr2) {for(int_4 i=0;i<mBins;i++) v(i) = 0.; return;}
|
---|
| 342 | for(int_4 i=0;i<mBins;i++) v(i) = Error(i);
|
---|
[763] | 343 | return;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | /********* Methode *********/
|
---|
[914] | 347 | /*!
|
---|
| 348 | Remplissage du contenu de l'histo avec les valeurs d'un vecteur
|
---|
| 349 | */
|
---|
[1092] | 350 | void Histo::PutValue(TVector<r_8> &v, int_4 ierr)
|
---|
[763] | 351 | {
|
---|
[2507] | 352 | //if(v.NElts()<(uint_4) mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[1092] | 353 | uint_4 n = (v.NElts()<(uint_4) mBins) ? v.NElts(): (uint_4) mBins;
|
---|
| 354 | if(n>0) for(uint_4 i=0;i<n;i++) {
|
---|
| 355 | mData[i] = v(i);
|
---|
| 356 | if(mErr2&&ierr) mErr2[i] = fabs(v(i));
|
---|
[763] | 357 | }
|
---|
| 358 | return;
|
---|
| 359 | }
|
---|
| 360 |
|
---|
[914] | 361 | /*!
|
---|
| 362 | Addition du contenu de l'histo avec les valeurs d'un vecteur
|
---|
| 363 | */
|
---|
[1092] | 364 | void Histo::PutValueAdd(TVector<r_8> &v, int_4 ierr)
|
---|
[763] | 365 | {
|
---|
[2507] | 366 | //if(v.NElts()<(uint_4) mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[1092] | 367 | uint_4 n = (v.NElts()<(uint_4) mBins) ? v.NElts(): (uint_4) mBins;
|
---|
| 368 | if(n>0) for(uint_4 i=0;i<n;i++) {
|
---|
| 369 | mData[i] += v(i);
|
---|
| 370 | if(mErr2 && ierr) mErr2[i] += fabs(v(i));
|
---|
[763] | 371 | }
|
---|
| 372 | return;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
[914] | 375 | /*!
|
---|
| 376 | Remplissage des erreurs au carre de l'histo avec les valeurs d'un vecteur
|
---|
| 377 | */
|
---|
[943] | 378 | void Histo::PutError2(TVector<r_8> &v)
|
---|
[763] | 379 | {
|
---|
[2507] | 380 | //if(v.NElts()<(uint_4) mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[1092] | 381 | uint_4 n = (v.NElts()<(uint_4) mBins) ? v.NElts(): (uint_4) mBins;
|
---|
[1064] | 382 | if(n>0) {
|
---|
[1092] | 383 | if(!mErr2) Errors();
|
---|
| 384 | for(uint_4 i=0;i<n;i++) mErr2[i] = v(i);
|
---|
[1064] | 385 | }
|
---|
[763] | 386 | return;
|
---|
| 387 | }
|
---|
| 388 |
|
---|
[914] | 389 | /*!
|
---|
| 390 | Addition des erreurs au carre de l'histo avec les valeurs d'un vecteur
|
---|
| 391 | */
|
---|
[943] | 392 | void Histo::PutError2Add(TVector<r_8> &v)
|
---|
[763] | 393 | {
|
---|
[2507] | 394 | //if(v.NElts()<(uint_4) mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[1092] | 395 | uint_4 n = (v.NElts()<(uint_4) mBins) ? v.NElts(): (uint_4) mBins;
|
---|
[1064] | 396 | if(n>0) {
|
---|
[1092] | 397 | if(!mErr2) Errors();
|
---|
| 398 | for(uint_4 i=0;i<n;i++) if(v(i)>0.) mErr2[i] += v(i);
|
---|
[1064] | 399 | }
|
---|
[763] | 400 | return;
|
---|
| 401 | }
|
---|
| 402 |
|
---|
[914] | 403 | /*!
|
---|
| 404 | Remplissage des erreurs de l'histo avec les valeurs d'un vecteur
|
---|
| 405 | */
|
---|
[943] | 406 | void Histo::PutError(TVector<r_8> &v)
|
---|
[763] | 407 | {
|
---|
[2507] | 408 | //if(v.NElts()<(uint_4) mBins) throw SzMismatchError(PExcLongMessage(""));
|
---|
[1092] | 409 | uint_4 n = (v.NElts()<(uint_4) mBins) ? v.NElts(): (uint_4) mBins;
|
---|
[1064] | 410 | if(n>0) {
|
---|
[1092] | 411 | if(!mErr2) Errors();
|
---|
| 412 | for(uint_4 i=0;i<n;i++)
|
---|
| 413 | if(v(i)>0.) mErr2[i]=v(i)*v(i); else mErr2[i]=-v(i)*v(i);
|
---|
[1064] | 414 | }
|
---|
[763] | 415 | return;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | /********* Methode *********/
|
---|
[914] | 419 | /*!
|
---|
| 420 | Addition du contenu de l'histo pour abscisse x poids w
|
---|
| 421 | */
|
---|
[1092] | 422 | void Histo::Add(r_8 x, r_8 w)
|
---|
[763] | 423 | {
|
---|
[1092] | 424 | int_4 numBin = FindBin(x);
|
---|
| 425 | if (numBin<0) mUnder += w;
|
---|
| 426 | else if (numBin>=mBins) mOver += w;
|
---|
[763] | 427 | else {
|
---|
[1092] | 428 | mData[numBin] += w;
|
---|
| 429 | if(mErr2!=NULL) mErr2[numBin] += w*w;
|
---|
[763] | 430 | nHist += w;
|
---|
| 431 | nEntries++;
|
---|
| 432 | }
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 | /********* Methode *********/
|
---|
[914] | 436 | /*!
|
---|
| 437 | Addition du contenu de l'histo bin numBin poids w
|
---|
| 438 | */
|
---|
[1092] | 439 | void Histo::AddBin(int_4 numBin, r_8 w)
|
---|
[763] | 440 | {
|
---|
[1092] | 441 | if (numBin<0) mUnder += w;
|
---|
| 442 | else if (numBin>=mBins) mOver += w;
|
---|
[763] | 443 | else {
|
---|
[1092] | 444 | mData[numBin] += w;
|
---|
| 445 | if(mErr2!=NULL) mErr2[numBin] += w*w;
|
---|
[763] | 446 | nHist += w;
|
---|
| 447 | nEntries++;
|
---|
| 448 | }
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | /********* Methode *********/
|
---|
[914] | 452 | /*!
|
---|
| 453 | Remplissage du contenu de l'histo pour abscisse x poids w
|
---|
| 454 | */
|
---|
[1092] | 455 | void Histo::SetBin(r_8 x, r_8 w)
|
---|
[763] | 456 | {
|
---|
[1092] | 457 | int_4 numBin = FindBin(x);
|
---|
[763] | 458 | SetBin(numBin,w);
|
---|
| 459 | }
|
---|
| 460 |
|
---|
| 461 | /********* Methode *********/
|
---|
[914] | 462 | /*!
|
---|
| 463 | Remplissage du contenu de l'histo pour numBin poids w
|
---|
| 464 | */
|
---|
[1092] | 465 | void Histo::SetBin(int_4 numBin, r_8 w)
|
---|
[763] | 466 | {
|
---|
[1092] | 467 | if (numBin<0) mUnder = w;
|
---|
| 468 | else if (numBin>=mBins) mOver = w;
|
---|
[763] | 469 | else {
|
---|
[1092] | 470 | nHist -= mData[numBin];
|
---|
| 471 | mData[numBin] = w;
|
---|
[763] | 472 | nHist += w;
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | /********* Methode *********/
|
---|
[914] | 477 | /*!
|
---|
| 478 | Remplissage des erreurs au carre pour abscisse x
|
---|
| 479 | */
|
---|
[1092] | 480 | void Histo::SetErr2(r_8 x, r_8 e2)
|
---|
[763] | 481 | {
|
---|
[1092] | 482 | int_4 numBin = FindBin(x);
|
---|
[763] | 483 | SetErr2(numBin,e2);
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | /********* Methode *********/
|
---|
[914] | 487 | /*!
|
---|
| 488 | Remplissage des erreurs au carre pour numBin poids
|
---|
| 489 | */
|
---|
[1092] | 490 | void Histo::SetErr2(int_4 numBin, r_8 e2)
|
---|
[763] | 491 | {
|
---|
[1092] | 492 | if( mErr2==NULL) return;
|
---|
| 493 | if ( numBin<0 || numBin>=mBins ) return;
|
---|
| 494 | mErr2[numBin] = e2;
|
---|
[763] | 495 | }
|
---|
| 496 |
|
---|
| 497 | /********* Methode *********/
|
---|
[914] | 498 | /*!
|
---|
| 499 | Remplissage des erreurs pour abscisse x
|
---|
| 500 | */
|
---|
[1092] | 501 | void Histo::SetErr(r_8 x, r_8 e)
|
---|
[763] | 502 | {
|
---|
[1092] | 503 | SetErr2(x, e*e);
|
---|
[763] | 504 | }
|
---|
| 505 |
|
---|
| 506 | /********* Methode *********/
|
---|
[914] | 507 | /*!
|
---|
| 508 | Remplissage des erreurs pour numBin
|
---|
| 509 | */
|
---|
[1092] | 510 | void Histo::SetErr(int_4 numBin, r_8 e)
|
---|
[763] | 511 | {
|
---|
[1092] | 512 | SetErr2(numBin, e*e);
|
---|
[763] | 513 | }
|
---|
| 514 |
|
---|
| 515 | /********* Methode *********/
|
---|
[914] | 516 | /*!
|
---|
[1135] | 517 | Methode virtuelle de mise a jour - Ne fait rien pour Histo - Voir HProf
|
---|
| 518 | */
|
---|
| 519 | void Histo::UpdateHisto(bool force) const
|
---|
| 520 | {
|
---|
| 521 | return;
|
---|
| 522 | }
|
---|
| 523 |
|
---|
| 524 | /********* Methode *********/
|
---|
| 525 | /*!
|
---|
[914] | 526 | Numero du bin ayant le contenu maximum
|
---|
| 527 | */
|
---|
[1092] | 528 | int_4 Histo::IMax() const
|
---|
[763] | 529 | {
|
---|
[1092] | 530 | int_4 imx=0;
|
---|
| 531 | if(mBins==1) return imx;
|
---|
| 532 | r_8 mx=mData[0];
|
---|
| 533 | for (int_4 i=1; i<mBins; i++)
|
---|
| 534 | if (mData[i]>mx) {imx = i; mx=mData[i];}
|
---|
[763] | 535 | return imx;
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | /********* Methode *********/
|
---|
[914] | 539 | /*!
|
---|
| 540 | Numero du bin ayant le contenu minimum
|
---|
| 541 | */
|
---|
[1092] | 542 | int_4 Histo::IMin() const
|
---|
[763] | 543 | {
|
---|
[1092] | 544 | int_4 imx=0;
|
---|
| 545 | if(mBins==1) return imx;
|
---|
| 546 | r_8 mx=mData[0];
|
---|
| 547 | for (int_4 i=1; i<mBins; i++)
|
---|
| 548 | if (mData[i]<mx) {imx = i; mx=mData[i];}
|
---|
[763] | 549 | return imx;
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | /********* Methode *********/
|
---|
[914] | 553 | /*!
|
---|
| 554 | Valeur le contenu maximum
|
---|
| 555 | */
|
---|
[1092] | 556 | r_8 Histo::VMax() const
|
---|
[763] | 557 | {
|
---|
[1092] | 558 | r_8 mx=mData[0];
|
---|
| 559 | if(mBins==1) return mx;
|
---|
| 560 | for (int_4 i=1;i<mBins;i++) if(mData[i]>mx) mx=mData[i];
|
---|
[763] | 561 | return mx;
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | /********* Methode *********/
|
---|
[914] | 565 | /*!
|
---|
| 566 | Valeur le contenu minimum
|
---|
| 567 | */
|
---|
[1092] | 568 | r_8 Histo::VMin() const
|
---|
[763] | 569 | {
|
---|
[1092] | 570 | r_8 mx=mData[0];
|
---|
| 571 | if(mBins==1) return mx;
|
---|
| 572 | for (int_4 i=1;i<mBins;i++) if(mData[i]<mx) mx=mData[i];
|
---|
[763] | 573 | return mx;
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | /********* Methode *********/
|
---|
[914] | 577 | /*!
|
---|
| 578 | Valeur moyenne
|
---|
| 579 | */
|
---|
[1092] | 580 | r_8 Histo::Mean() const
|
---|
[763] | 581 | {
|
---|
[1092] | 582 | r_8 n = 0;
|
---|
| 583 | r_8 sx = 0;
|
---|
| 584 | for (int_4 i=0; i<mBins; i++) {
|
---|
| 585 | r_8 v = (mData[i]>=0.) ? mData[i] : -mData[i];
|
---|
[763] | 586 | n += v;
|
---|
| 587 | sx += BinCenter(i)*v;
|
---|
| 588 | }
|
---|
[1092] | 589 | if(n>0.) return sx/n; else return mMin;
|
---|
[763] | 590 | }
|
---|
| 591 |
|
---|
| 592 | /********* Methode *********/
|
---|
[914] | 593 | /*!
|
---|
| 594 | Valeur du sigma
|
---|
| 595 | */
|
---|
[1092] | 596 | r_8 Histo::Sigma() const
|
---|
[763] | 597 | {
|
---|
[1092] | 598 | r_8 n = 0;
|
---|
| 599 | r_8 sx = 0;
|
---|
| 600 | r_8 sx2= 0;
|
---|
| 601 | for (int_4 i=0; i<mBins; i++) {
|
---|
| 602 | r_8 v = (mData[i]>=0.) ? mData[i] : -mData[i];
|
---|
[763] | 603 | n += v;
|
---|
| 604 | sx += BinCenter(i)*v;
|
---|
| 605 | sx2+= BinCenter(i)*BinCenter(i)*v;
|
---|
| 606 | }
|
---|
| 607 | // attention a l'erreur d'arrondi si un seul bin rempli!!
|
---|
| 608 | if( n == 0 ) return 0.;
|
---|
| 609 | sx2 = sx2/n - (sx/n)*(sx/n);
|
---|
| 610 | if( sx2>0. ) return sqrt( sx2 );
|
---|
| 611 | else return 0.;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | /********* Methode *********/
|
---|
[914] | 615 | /*!
|
---|
| 616 | Valeur de la moyenne calculee entre les bin il et ih
|
---|
| 617 | */
|
---|
[1092] | 618 | r_8 Histo::MeanLH(int_4 il,int_4 ih) const
|
---|
[763] | 619 | {
|
---|
[1092] | 620 | if( ih < il ) { il = 0; ih = mBins-1; }
|
---|
[763] | 621 | if( il < 0 ) il = 0;
|
---|
[1092] | 622 | if( ih >= mBins ) ih = mBins-1;
|
---|
| 623 | r_8 n = 0;
|
---|
| 624 | r_8 sx = 0;
|
---|
| 625 | for (int_4 i=il; i<=ih; i++) {
|
---|
| 626 | r_8 v = (mData[i]>=0.) ? mData[i] : -mData[i];
|
---|
[763] | 627 | n += v;
|
---|
| 628 | sx += BinCenter(i)*v;
|
---|
| 629 | }
|
---|
| 630 | if(n>0.) return sx/n; else return BinLowEdge(il);
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 | /********* Methode *********/
|
---|
[914] | 634 | /*!
|
---|
| 635 | Valeur de la moyenne calculee entre les bin il et ih
|
---|
| 636 | */
|
---|
[1092] | 637 | r_8 Histo::SigmaLH(int_4 il,int_4 ih) const
|
---|
[763] | 638 | {
|
---|
[1092] | 639 | if( ih < il ) { il = 0; ih = mBins - 1; }
|
---|
[763] | 640 | if( il < 0 ) il = 0;
|
---|
[1092] | 641 | if( ih >= mBins ) ih = mBins - 1;
|
---|
| 642 | r_8 n = 0;
|
---|
| 643 | r_8 sx = 0;
|
---|
| 644 | r_8 sx2= 0;
|
---|
| 645 | for (int_4 i=il; i<=ih; i++) {
|
---|
| 646 | r_8 v = (mData[i]>=0.) ? mData[i] : -mData[i];
|
---|
[763] | 647 | n += v;
|
---|
| 648 | sx += BinCenter(i)*v;
|
---|
| 649 | sx2+= BinCenter(i)*BinCenter(i)*v;
|
---|
| 650 | }
|
---|
| 651 | if( n == 0 ) return 0.;
|
---|
| 652 | sx2 = sx2/n - (sx/n)*(sx/n);
|
---|
| 653 | if( sx2>0. ) return sqrt( sx2 );
|
---|
| 654 | else return 0.;
|
---|
| 655 | }
|
---|
| 656 |
|
---|
| 657 | /********* Methode *********/
|
---|
[914] | 658 | /*!
|
---|
| 659 | Valeur de la moyenne calculee entre x0-dx et x0+dx
|
---|
| 660 | */
|
---|
[1092] | 661 | r_8 Histo::Mean(r_8 x0, r_8 dx) const
|
---|
[763] | 662 | {
|
---|
[1092] | 663 | r_8 sdata = 0;
|
---|
| 664 | r_8 sx = 0;
|
---|
| 665 | int_4 iMin = FindBin(x0-dx);
|
---|
[763] | 666 | if (iMin<0) iMin = 0;
|
---|
[1092] | 667 | int_4 iMax = FindBin(x0+dx);
|
---|
| 668 | if (iMax>mBins) iMax=mBins;
|
---|
| 669 | for (int_4 i=iMin; i<iMax; i++) {
|
---|
| 670 | r_8 v = (mData[i]>=0.) ? mData[i] : -mData[i];
|
---|
[763] | 671 | sx += BinCenter(i)*v;
|
---|
| 672 | sdata += v;
|
---|
| 673 | }
|
---|
[1092] | 674 | if(sdata>0.) return sx/sdata; else return mMin;
|
---|
[763] | 675 | }
|
---|
| 676 |
|
---|
| 677 | /********* Methode *********/
|
---|
[914] | 678 | /*!
|
---|
| 679 | Valeur du sigma calcule entre x0-dx et x0+dx
|
---|
| 680 | */
|
---|
[1092] | 681 | r_8 Histo::Sigma(r_8 x0, r_8 dx) const
|
---|
[763] | 682 | {
|
---|
[1092] | 683 | r_8 sx = 0;
|
---|
| 684 | r_8 sx2= 0;
|
---|
| 685 | r_8 sdata = 0;
|
---|
| 686 | int_4 iMin = FindBin(x0-dx);
|
---|
[763] | 687 | if (iMin<0) iMin = 0;
|
---|
[1092] | 688 | int_4 iMax = FindBin(x0+dx);
|
---|
| 689 | if (iMax>mBins) iMax=mBins;
|
---|
| 690 | for (int_4 i=iMin; i<iMax; i++) {
|
---|
| 691 | r_8 v = (mData[i]>=0.) ? mData[i] : -mData[i];
|
---|
[763] | 692 | sx += BinCenter(i)*v;
|
---|
| 693 | sx2+= BinCenter(i)*BinCenter(i)*v;
|
---|
| 694 | sdata += v;
|
---|
| 695 | }
|
---|
| 696 | if(sdata>0.) return sqrt( sx2/sdata - (sx/sdata)*(sx/sdata) );
|
---|
| 697 | else return 0.;
|
---|
| 698 | }
|
---|
| 699 |
|
---|
| 700 | /********* Methode *********/
|
---|
[914] | 701 | /*!
|
---|
| 702 | Valeur de la moyenne et du sigma nettoyes
|
---|
| 703 | */
|
---|
[1092] | 704 | r_8 Histo::CleanedMean(r_8& sigma) const
|
---|
[763] | 705 | {
|
---|
| 706 | if (!nHist) return 0;
|
---|
| 707 | // on fait ca de facon bete, on pourra raffiner apres...
|
---|
[1092] | 708 | r_8 x0 = Mean();
|
---|
| 709 | r_8 s = Sigma()+binWidth;
|
---|
[763] | 710 |
|
---|
[1092] | 711 | for (int_4 i=0; i<3; i++) {
|
---|
| 712 | r_8 xx0 = Mean(x0,5*s);
|
---|
[763] | 713 | s = Sigma(x0,5*s)+binWidth;
|
---|
| 714 | x0 = xx0;
|
---|
| 715 | }
|
---|
| 716 | sigma = s;
|
---|
| 717 | return x0;
|
---|
| 718 | }
|
---|
| 719 |
|
---|
| 720 | /********* Methode *********/
|
---|
[914] | 721 | /*!
|
---|
| 722 | Valeur de la moyenne nettoyee
|
---|
| 723 | */
|
---|
[1092] | 724 | r_8 Histo::CleanedMean() const
|
---|
[763] | 725 | {
|
---|
| 726 | if (!nHist) return 0;
|
---|
[1092] | 727 | r_8 s=0;
|
---|
[763] | 728 | return CleanedMean(s);
|
---|
| 729 | }
|
---|
| 730 |
|
---|
| 731 | /********* Methode *********/
|
---|
[914] | 732 | /*!
|
---|
| 733 | Retourne le nombre de bins non-nul
|
---|
| 734 | */
|
---|
[1092] | 735 | int_4 Histo::BinNonNul() const
|
---|
[763] | 736 | {
|
---|
[1092] | 737 | int_4 non=0;
|
---|
| 738 | for (int_4 i=0;i<mBins;i++) if( mData[i] != 0. ) non++;
|
---|
[763] | 739 | return non;
|
---|
| 740 | }
|
---|
| 741 |
|
---|
| 742 | /********* Methode *********/
|
---|
[914] | 743 | /*!
|
---|
| 744 | Retourne le nombre de bins ayant une erreur non-nulle
|
---|
| 745 | */
|
---|
[1092] | 746 | int_4 Histo::ErrNonNul() const
|
---|
[763] | 747 | {
|
---|
[1092] | 748 | if(mErr2==NULL) return -1;
|
---|
| 749 | int_4 non=0;
|
---|
| 750 | for (int_4 i=0;i<mBins;i++) if( mErr2[i] != 0. ) non++;
|
---|
[763] | 751 | return non;
|
---|
| 752 | }
|
---|
| 753 |
|
---|
| 754 | /********* Methode *********/
|
---|
[914] | 755 | /*!
|
---|
| 756 | Renvoie le numero de bin tel que il y ait "per" pourcent entrees
|
---|
| 757 | entre le bin 0 et ce bin (y compris le contenu de ce bin).
|
---|
| 758 | */
|
---|
[1092] | 759 | int_4 Histo::BinPercent(r_8 per) const
|
---|
[763] | 760 | {
|
---|
[1092] | 761 | r_8 n = nHist*per;
|
---|
| 762 | r_8 s = 0.;
|
---|
| 763 | int_4 i;
|
---|
| 764 | for(i=0; i<mBins; i++ ) {
|
---|
| 765 | s += mData[i];
|
---|
[763] | 766 | if( s >= n ) break;
|
---|
| 767 | }
|
---|
[1092] | 768 | if( i == mBins ) i = mBins-1;
|
---|
[763] | 769 | return i;
|
---|
| 770 | }
|
---|
| 771 |
|
---|
| 772 | /********* Methode *********/
|
---|
[914] | 773 | /*!
|
---|
| 774 | Renvoie les numeros de bins imin,imax (0=<i<bins) tels que:
|
---|
| 775 | \verbatim
|
---|
| 776 | notons I = bin contenant l'abscisse x
|
---|
| 777 | N1 = nombre d'entrees entre bin 0 et I compris
|
---|
| 778 | N2 = nombre d'entrees entre bin I et bins-1 compris
|
---|
| 779 | imin = bin tel que nombre d'entrees entre imin et I = N1 * per
|
---|
| 780 | imax = bin tel que nombre d'entrees entre I et imax = N2 * per
|
---|
| 781 | Return: <0 si echec
|
---|
[1092] | 782 | mMin(I-imin,imax-I) si ok
|
---|
[914] | 783 | \endverbatim
|
---|
| 784 | */
|
---|
[1144] | 785 | int_4 Histo::BinPercent(r_8 x,r_8 per,int_4& imin,int_4& imax) const
|
---|
[763] | 786 | {
|
---|
| 787 | imin = imax = -1;
|
---|
| 788 | if( per <= 0. ) return -1;
|
---|
| 789 |
|
---|
[1092] | 790 | int_4 I = FindBin(x);
|
---|
| 791 | if( I<0 || I>=mBins ) return -2;
|
---|
[763] | 792 |
|
---|
[1092] | 793 | r_8 N1 = 0.; for(int_4 i=0; i<=I; i++) N1 += mData[i]; N1 *= per;
|
---|
| 794 | r_8 N2 = 0.; {for(int_4 i=I; i<mBins; i++) N2 += mData[i]; N2 *= per;}
|
---|
[763] | 795 |
|
---|
[1092] | 796 | r_8 n = 0.;
|
---|
| 797 | for(imin=I; imin>=0; imin--) { n += mData[imin]; if(n>=N1) break; }
|
---|
[763] | 798 | if( imin<0 ) imin = 0;
|
---|
| 799 | // cout<<"I="<<I<<" imin="<<imin<<" n="<<n<<" N1="<<N1<<endl;
|
---|
| 800 |
|
---|
| 801 | n = 0.;
|
---|
[1092] | 802 | for(imax=I; imax<mBins; imax++) { n += mData[imax]; if(n>=N2) break; }
|
---|
| 803 | if( imax>=mBins ) imax = mBins-1;
|
---|
[763] | 804 | // cout<<"I="<<I<<" imax="<<imax<<" n="<<n<<" N2="<<N2<<endl;
|
---|
| 805 |
|
---|
| 806 | return ( imax-I > I-imin ) ? I-imin : imax-I ;
|
---|
| 807 | }
|
---|
| 808 |
|
---|
| 809 | /********* Methode *********/
|
---|
[914] | 810 | /*!
|
---|
| 811 | Idem precedent mais renvoie xmin et xmax
|
---|
| 812 | */
|
---|
[1109] | 813 | int_4 Histo::BinPercent(r_8 x,r_8 per,r_8& xmin,r_8& xmax) const
|
---|
[763] | 814 | {
|
---|
| 815 | xmin = xmax = 0.;
|
---|
[1092] | 816 | int_4 imin,imax;
|
---|
| 817 | int_4 rc = BinPercent(x,per,imin,imax);
|
---|
[763] | 818 | if( rc >= 0 ) { xmin = BinLowEdge(imin); xmax = BinHighEdge(imax); }
|
---|
| 819 | return rc;
|
---|
| 820 | }
|
---|
| 821 |
|
---|
| 822 | /********* Methode *********/
|
---|
[914] | 823 | /*!
|
---|
| 824 | Remplace l'histogramme par son integrale normalise a norm:
|
---|
| 825 | si norm <= 0 : pas de normalisation, integration seule
|
---|
| 826 | */
|
---|
[1092] | 827 | void Histo::HInteg(r_8 norm)
|
---|
[763] | 828 | {
|
---|
[1092] | 829 | if( mBins <= 0 ) return; // createur par default
|
---|
| 830 | if(mBins>1)
|
---|
| 831 | for(int_4 i=1; i<mBins; i++) {
|
---|
| 832 | mData[i] += mData[i-1];
|
---|
| 833 | if(mErr2!=NULL) mErr2[i] += mErr2[i-1];
|
---|
[763] | 834 | }
|
---|
| 835 | if( norm <= 0. ) return;
|
---|
[1092] | 836 | norm /= mData[mBins-1];
|
---|
| 837 | for(int_4 i=0; i<mBins; i++) {
|
---|
| 838 | mData[i] *= norm;
|
---|
| 839 | if(mErr2!=NULL) mErr2[i] *= norm*norm;
|
---|
[763] | 840 | }
|
---|
| 841 | }
|
---|
| 842 |
|
---|
| 843 | /********* Methode *********/
|
---|
[914] | 844 | /*!
|
---|
| 845 | Remplace l'histogramme par sa derivee
|
---|
| 846 | */
|
---|
[763] | 847 | void Histo::HDeriv()
|
---|
| 848 | {
|
---|
[1092] | 849 | if( mBins <= 0 ) return; // createur par default
|
---|
| 850 | if( mBins <= 1 ) return;
|
---|
| 851 | r_8 *temp = new r_8[mBins];
|
---|
| 852 | memcpy(temp, mData, mBins*sizeof(r_8));
|
---|
| 853 | if(mBins>=3) for(int_4 i=1; i<mBins-1; i++)
|
---|
| 854 | temp[i] = (mData[i+1]-mData[i-1])/(2.*binWidth);
|
---|
| 855 | temp[0] = (mData[1]-mData[0])/binWidth;
|
---|
| 856 | temp[mBins-1] = (mData[mBins-1]-mData[mBins-2])/binWidth;
|
---|
| 857 | memcpy(mData, temp, mBins*sizeof(r_8));
|
---|
[763] | 858 | delete [] temp;
|
---|
| 859 | }
|
---|
| 860 |
|
---|
| 861 | /********* Methode *********/
|
---|
[914] | 862 | /*!
|
---|
| 863 | Pour rebinner l'histogramme sur nbinew bins
|
---|
| 864 | */
|
---|
[1092] | 865 | void Histo::HRebin(int_4 nbinew)
|
---|
[763] | 866 | {
|
---|
[1092] | 867 | if( mBins <= 0 ) return; // createur par default
|
---|
[763] | 868 | if( nbinew <= 0 ) return;
|
---|
| 869 |
|
---|
[1056] | 870 | // memorisation de l'histogramme original
|
---|
[763] | 871 | Histo H(*this);
|
---|
| 872 |
|
---|
| 873 | // Le nombre de bins est il plus grand ??
|
---|
[1092] | 874 | if( nbinew > mBins ) {
|
---|
| 875 | delete [] mData; mData = NULL;
|
---|
| 876 | mData = new r_8[nbinew];
|
---|
| 877 | if( mErr2 != NULL ) {
|
---|
| 878 | delete [] mErr2; mErr2 = NULL;
|
---|
| 879 | mErr2 = new r_8[nbinew];
|
---|
[763] | 880 | }
|
---|
| 881 | }
|
---|
| 882 |
|
---|
| 883 | // remise en forme de this
|
---|
[1092] | 884 | mBins = nbinew;
|
---|
[763] | 885 | this->Zero();
|
---|
[1092] | 886 | binWidth = (mMax-mMin)/mBins;
|
---|
[763] | 887 | // On recopie les parametres qui n'ont pas changes
|
---|
[1092] | 888 | mUnder = H.mUnder;
|
---|
| 889 | mOver = H.mOver;
|
---|
[763] | 890 |
|
---|
| 891 |
|
---|
| 892 | // Remplissage
|
---|
[1092] | 893 | for(int_4 i=0;i<mBins;i++) {
|
---|
| 894 | r_8 xmi = BinLowEdge(i);
|
---|
| 895 | r_8 xma = BinHighEdge(i);
|
---|
| 896 | int_4 imi = H.FindBin(xmi);
|
---|
[763] | 897 | if( imi < 0 ) imi = 0;
|
---|
[1092] | 898 | int_4 ima = H.FindBin(xma);
|
---|
| 899 | if( ima >= H.mBins ) ima = H.mBins-1;
|
---|
| 900 | r_8 w = 0.;
|
---|
[763] | 901 | if( ima == imi ) {
|
---|
| 902 | w = H(imi) * binWidth/H.binWidth;
|
---|
| 903 | } else {
|
---|
| 904 | w += H(imi) * (H.BinHighEdge(imi)-xmi)/H.binWidth;
|
---|
| 905 | w += H(ima) * (xma -H.BinLowEdge(ima))/H.binWidth;
|
---|
| 906 | if( ima > imi+1 )
|
---|
[1092] | 907 | for(int_4 ii=imi+1;ii<ima;ii++) w += H(ii);
|
---|
[763] | 908 | }
|
---|
[1092] | 909 | AddBin(i, w);
|
---|
[763] | 910 | }
|
---|
| 911 |
|
---|
| 912 | }
|
---|
| 913 |
|
---|
| 914 | /********* Methode *********/
|
---|
[914] | 915 | /*!
|
---|
| 916 | Retourne le nombre de maxima locaux, la valeur du maximum (maxi)
|
---|
| 917 | et sa position (imax), ainsi que la valeur du second maximum
|
---|
| 918 | local (maxn) et sa position (imaxn).
|
---|
| 919 | Attention: si un maximum a la meme valeur sur plusieurs bins
|
---|
| 920 | consecutifs, le bin le plus a droite est pris.
|
---|
| 921 | */
|
---|
[1144] | 922 | int_4 Histo::MaxiLocal(r_8& maxi,int_4& imax,r_8& maxn,int_4& imaxn) const
|
---|
[763] | 923 | {
|
---|
[1092] | 924 | int_4 nml = 0;
|
---|
[763] | 925 | imax = imaxn = -1;
|
---|
[1092] | 926 | maxi = maxn = -1.;
|
---|
[763] | 927 |
|
---|
| 928 | bool up = true;
|
---|
| 929 | bool down = false;
|
---|
[1092] | 930 | for(int_4 i=0;i<mBins;i++) {
|
---|
| 931 | if( !up ) if( mData[i] > mData[i-1] ) up = true;
|
---|
[763] | 932 | if( up && !down ) {
|
---|
[1092] | 933 | if( i == mBins-1 ) down=true;
|
---|
| 934 | else if( mData[i] > mData[i+1] ) down=true;
|
---|
[763] | 935 | }
|
---|
| 936 |
|
---|
| 937 | if( up && down ) {
|
---|
| 938 | nml++;
|
---|
| 939 | up = down = false;
|
---|
| 940 | if( imax < 0 ) {
|
---|
[1092] | 941 | imax = i; maxi = mData[i];
|
---|
| 942 | } else if( mData[i] >= maxi ) {
|
---|
[763] | 943 | imaxn = imax; maxn = maxi;
|
---|
[1092] | 944 | imax = i; maxi = mData[i];
|
---|
[763] | 945 | } else {
|
---|
[1092] | 946 | if( imaxn < 0 || mData[i] >= maxn ) { imaxn = i; maxn = mData[i]; }
|
---|
[763] | 947 | }
|
---|
| 948 | }
|
---|
| 949 |
|
---|
| 950 | }
|
---|
| 951 | return nml;
|
---|
| 952 | }
|
---|
| 953 |
|
---|
| 954 | /********* Methode *********/
|
---|
[914] | 955 | /*!
|
---|
| 956 | Fit de la position du maximum de l'histo par un polynome
|
---|
| 957 | de degre `degree' a `frac' pourcent du maximum.
|
---|
| 958 | L'histo est suppose etre remplit de valeurs positives
|
---|
| 959 | */
|
---|
[1092] | 960 | r_8 Histo::FitMax(int_4 degree, r_8 frac, int_4 debug) const
|
---|
[763] | 961 | {
|
---|
| 962 | if (degree < 2 || degree > 3) degree = 3;
|
---|
| 963 | if (frac <= 0. || frac >= 1.) frac = 0.5;
|
---|
| 964 |
|
---|
| 965 | if (debug > 1)
|
---|
| 966 | cout<<"Histo::FitMax : Nb Entrees histo ="<<NEntries()<<endl;
|
---|
| 967 |
|
---|
[2507] | 968 | if (NEntries() < 1) throw ParmError(PExcLongMessage(""));
|
---|
[763] | 969 |
|
---|
[1092] | 970 | int_4 iMax = IMax();
|
---|
| 971 | r_8 hmax = (*this)(iMax);
|
---|
| 972 | r_8 xCenter = BinCenter(iMax);
|
---|
[763] | 973 |
|
---|
| 974 | if(debug>1)
|
---|
| 975 | cout<<"Max histo i="<<iMax<<" x="<<xCenter<<" v="<<hmax<<endl;
|
---|
| 976 |
|
---|
| 977 | /* find limits at frac*hmax */
|
---|
| 978 |
|
---|
[1092] | 979 | r_8 limit = frac*hmax;
|
---|
[763] | 980 |
|
---|
[1092] | 981 | volatile int_4 iLow = iMax;
|
---|
[763] | 982 | while (iLow>0 && (*this)(iLow)>limit) iLow--;
|
---|
| 983 |
|
---|
[1092] | 984 | volatile int_4 iHigh = iMax;
|
---|
[763] | 985 | while (iHigh<NBins()-1 && (*this)(iHigh)>limit) iHigh++;
|
---|
| 986 |
|
---|
[1092] | 987 | int_4 nLowHigh;
|
---|
[763] | 988 | for(;;) {
|
---|
| 989 | nLowHigh = 0;
|
---|
[1092] | 990 | for (int_4 i=iLow; i<=iHigh; i++) if((*this)(i)>0) {
|
---|
| 991 | if(!mErr2) nLowHigh++;
|
---|
[763] | 992 | else if(Error2(i)>0.) nLowHigh++;
|
---|
| 993 | }
|
---|
| 994 | if (debug > 1) cout <<"Limites histo "<<iLow<<" - "<<iHigh
|
---|
| 995 | <<" ("<<nLowHigh<<" non nuls)"<<endl;
|
---|
| 996 | if( nLowHigh >= degree+1 ) break;
|
---|
| 997 | iLow--; iHigh++;
|
---|
| 998 | if(iLow<0 && iHigh>=NBins()) {
|
---|
| 999 | if (debug>1)
|
---|
| 1000 | cout<<"Mode histogramme = "<<xCenter
|
---|
| 1001 | <<" BinCenter("<<iMax<<")"<<endl;
|
---|
| 1002 | return xCenter;
|
---|
| 1003 | }
|
---|
| 1004 | if(iLow < 0 ) iLow = 0;
|
---|
| 1005 | if(iHigh >= NBins()) iHigh = NBins()-1;
|
---|
| 1006 | }
|
---|
| 1007 |
|
---|
[943] | 1008 | TVector<r_8> xFit(nLowHigh);
|
---|
| 1009 | TVector<r_8> yFit(nLowHigh);
|
---|
| 1010 | TVector<r_8> e2Fit(nLowHigh);
|
---|
| 1011 | TVector<r_8> errcoef(1);
|
---|
[1092] | 1012 | int_4 ii = 0;
|
---|
| 1013 | for (int_4 j=iLow; j<=iHigh; j++) {
|
---|
[763] | 1014 | if ((*this)(j)>0) {
|
---|
[1092] | 1015 | if(!mErr2) {
|
---|
[763] | 1016 | xFit(ii) = BinCenter(j)-xCenter;
|
---|
| 1017 | yFit(ii) = (*this)(j);
|
---|
| 1018 | e2Fit(ii) = yFit(ii);
|
---|
| 1019 | ii++;
|
---|
| 1020 | } else if(Error2(j)>0.) {
|
---|
| 1021 | xFit(ii) = BinCenter(j)-xCenter;
|
---|
| 1022 | yFit(ii) = (*this)(j);
|
---|
| 1023 | e2Fit(ii) = Error2(j);
|
---|
| 1024 | ii++;
|
---|
| 1025 | }
|
---|
| 1026 | }
|
---|
| 1027 | }
|
---|
| 1028 | if(debug>4) {
|
---|
[1092] | 1029 | int_4 k;
|
---|
[763] | 1030 | for(k=0;k<nLowHigh;k++) cout<<" "<<xFit(k); cout<<endl;
|
---|
| 1031 | for(k=0;k<nLowHigh;k++) cout<<" "<<yFit(k); cout<<endl;
|
---|
| 1032 | for(k=0;k<nLowHigh;k++) cout<<" "<<e2Fit(k); cout<<endl;
|
---|
| 1033 | }
|
---|
[2507] | 1034 | if( ii != nLowHigh ) throw ParmError(PExcLongMessage(""));
|
---|
[763] | 1035 | Poly pol(degree);
|
---|
| 1036 | TRY {
|
---|
| 1037 | pol.Fit(xFit, yFit, e2Fit, degree, errcoef);
|
---|
| 1038 | if (debug>1) cout << "resultat fit = " << pol << endl;
|
---|
| 1039 | pol.Derivate();
|
---|
| 1040 | } CATCHALL {
|
---|
| 1041 | THROW_SAME;
|
---|
| 1042 | } ENDTRY
|
---|
| 1043 |
|
---|
[1092] | 1044 | int_4 DPolDeg = pol.Degre();
|
---|
| 1045 | r_8 fd = 0.;
|
---|
[763] | 1046 |
|
---|
| 1047 | if (DPolDeg == 0) {
|
---|
| 1048 | // on est dans le cas d'un fit de droite
|
---|
| 1049 | if( pol[0] > 0. ) {
|
---|
| 1050 | // on a fitte une droite de pente >0.
|
---|
| 1051 | fd = xFit(nLowHigh-1) + binWidth/2. + xCenter;
|
---|
| 1052 | } else if( pol[0] < 0. ) {
|
---|
| 1053 | // on a fitte une droite de pente <0.
|
---|
| 1054 | fd = xFit(0) - binWidth/2. + xCenter;
|
---|
| 1055 | } else {
|
---|
| 1056 | // on a fitte une droite de pente =0. (creneau)
|
---|
| 1057 | fd = (xFit(0)+xFit(nLowHigh-1))/2. + xCenter;
|
---|
| 1058 | }
|
---|
| 1059 | } else if (DPolDeg == 1) {
|
---|
| 1060 | // on est dans le cas d'un fit de parabole
|
---|
[1092] | 1061 | r_8 r=0;
|
---|
[2507] | 1062 | if (pol.Root1(r)==0) throw ParmError(PExcLongMessage(""));
|
---|
[763] | 1063 | fd = r + xCenter;
|
---|
| 1064 | } else if (DPolDeg == 2) {
|
---|
| 1065 | // on est dans le cas d'un fit de cubique
|
---|
[1092] | 1066 | r_8 r1=0;
|
---|
| 1067 | r_8 r2=0;
|
---|
[2507] | 1068 | if (pol.Root2(r1,r2) == 0) throw ParmError(PExcLongMessage(""));
|
---|
[763] | 1069 | pol.Derivate();
|
---|
| 1070 | fd = (pol(r1)<0) ? r1 + xCenter : r2 + xCenter;
|
---|
| 1071 | } else {
|
---|
| 1072 | // on est dans un cas non prevu
|
---|
[2507] | 1073 | throw ParmError(PExcLongMessage(""));
|
---|
[763] | 1074 | }
|
---|
| 1075 |
|
---|
[1092] | 1076 | if(fd>mMax) fd = mMax;
|
---|
| 1077 | if(fd<mMin) fd = mMin;
|
---|
[763] | 1078 |
|
---|
| 1079 | if (debug>1)
|
---|
| 1080 | cout << "Mode histogramme = " << fd
|
---|
| 1081 | << " (DerPol.degre =" << DPolDeg
|
---|
| 1082 | << " pol.coeff[0] =" << pol[0]
|
---|
| 1083 | << ")" << endl;
|
---|
| 1084 |
|
---|
| 1085 | return fd;
|
---|
| 1086 | }
|
---|
| 1087 |
|
---|
| 1088 |
|
---|
| 1089 | /********* Methode *********/
|
---|
[914] | 1090 | /*!
|
---|
| 1091 | Calcul de la largeur a frac pourcent du maximum
|
---|
| 1092 | autour du bin du maximum.
|
---|
| 1093 | L'histo est suppose etre remplit de valeurs positives
|
---|
| 1094 | */
|
---|
[1092] | 1095 | r_8 Histo::FindWidth(r_8 frac, int_4 debug) const
|
---|
[763] | 1096 | {
|
---|
[1092] | 1097 | r_8 xmax = BinCenter( IMax() );
|
---|
[763] | 1098 | return FindWidth(xmax,frac,debug);
|
---|
| 1099 | }
|
---|
| 1100 |
|
---|
| 1101 | /********* Methode *********/
|
---|
[914] | 1102 | /*!
|
---|
| 1103 | Calcul de la largeur a frac pourcent de la valeur du bin xmax.
|
---|
| 1104 | L'histo est suppose etre remplit de valeurs positives
|
---|
| 1105 | */
|
---|
[1092] | 1106 | r_8 Histo::FindWidth(r_8 xmax,r_8 frac, int_4 debug) const
|
---|
[763] | 1107 | {
|
---|
| 1108 | if (frac <= 0 || frac >= 1.) frac = 0.5;
|
---|
| 1109 |
|
---|
| 1110 | if (debug > 1)
|
---|
| 1111 | cout << "Histo::FindWidth a " << frac
|
---|
| 1112 | << " de xmax= " << xmax
|
---|
| 1113 | << " , ndata= " << NData()
|
---|
| 1114 | << " , nent= " << NEntries()
|
---|
| 1115 | << " , nbin= " << NBins() << endl;
|
---|
| 1116 |
|
---|
[2507] | 1117 | if (NEntries() < 1) throw ParmError(PExcLongMessage(""));
|
---|
| 1118 | if (NBins() < 3) throw ParmError(PExcLongMessage(""));
|
---|
[763] | 1119 |
|
---|
[1092] | 1120 | int_4 iMax = FindBin(xmax);
|
---|
[2507] | 1121 | if (iMax<0 || iMax>=NBins()) throw ParmError(PExcLongMessage(""));
|
---|
[1092] | 1122 | r_8 hmax = mData[iMax];
|
---|
| 1123 | r_8 limit = frac*hmax;
|
---|
[763] | 1124 | if (debug > 1)
|
---|
| 1125 | cout << " Max histo[" << iMax << "] = " << hmax
|
---|
| 1126 | << ", limite " << limit << endl;
|
---|
| 1127 |
|
---|
[1092] | 1128 | int_4 iLow = iMax;
|
---|
| 1129 | while (iLow>=0 && mData[iLow]>limit) iLow--;
|
---|
[763] | 1130 | if( iLow < 0 ) iLow = 0;
|
---|
| 1131 |
|
---|
[1092] | 1132 | int_4 iHigh = iMax;
|
---|
| 1133 | while (iHigh<NBins() && mData[iHigh]>limit) iHigh++;
|
---|
[763] | 1134 | if( iHigh >=NBins() ) iHigh = NBins()-1;
|
---|
| 1135 |
|
---|
[1092] | 1136 | r_8 xlow = BinCenter(iLow);
|
---|
| 1137 | r_8 ylow = mData[iLow];
|
---|
[763] | 1138 |
|
---|
[1092] | 1139 | r_8 xlow1=xlow, ylow1=ylow;
|
---|
[763] | 1140 | if(iLow+1<NBins()) {
|
---|
| 1141 | xlow1 = BinCenter(iLow+1);
|
---|
[1092] | 1142 | ylow1 = mData[iLow+1];
|
---|
[763] | 1143 | }
|
---|
| 1144 |
|
---|
[1092] | 1145 | r_8 xhigh = BinCenter(iHigh);
|
---|
| 1146 | r_8 yhigh = mData[iHigh];
|
---|
[763] | 1147 |
|
---|
[1092] | 1148 | r_8 xhigh1=xhigh, yhigh1=yhigh;
|
---|
[763] | 1149 | if(iHigh-1>=0) {
|
---|
| 1150 | xhigh1 = BinCenter(iHigh-1);
|
---|
[1092] | 1151 | yhigh1 = mData[iHigh-1];
|
---|
[763] | 1152 | }
|
---|
| 1153 |
|
---|
[1092] | 1154 | r_8 xlpred,xhpred,wd;
|
---|
[763] | 1155 |
|
---|
| 1156 | if(ylow1>ylow) {
|
---|
| 1157 | xlpred = xlow + (xlow1-xlow)/(ylow1-ylow)*(limit-ylow);
|
---|
| 1158 | if(xlpred < xlow) xlpred = xlow;
|
---|
| 1159 | } else xlpred = xlow;
|
---|
| 1160 |
|
---|
| 1161 | if(yhigh1>yhigh) {
|
---|
| 1162 | xhpred = xhigh + (xhigh1-xhigh)/(yhigh1-yhigh)*(limit-yhigh);
|
---|
| 1163 | if(xhpred > xhigh) xhpred = xhigh;
|
---|
| 1164 | } else xhpred = xhigh;
|
---|
| 1165 |
|
---|
| 1166 | wd = xhpred - xlpred;
|
---|
| 1167 |
|
---|
| 1168 | if (debug > 1) {
|
---|
| 1169 | cout << "Limites histo: " << " Width " << wd << endl;
|
---|
| 1170 | cout << " Low: [" << iLow << "]=" << ylow << " pred-> " << xlpred
|
---|
| 1171 | << " - High: [" << iHigh << "]=" << yhigh << " pred-> " << xhpred
|
---|
| 1172 | << endl;
|
---|
| 1173 | }
|
---|
| 1174 |
|
---|
| 1175 | return wd;
|
---|
| 1176 | }
|
---|
| 1177 |
|
---|
| 1178 |
|
---|
| 1179 | /********* Methode *********/
|
---|
[914] | 1180 | /*!
|
---|
| 1181 | Cf suivant mais im est le bin du maximum de l'histo
|
---|
| 1182 | */
|
---|
[1109] | 1183 | int_4 Histo::EstimeMax(r_8& xm,int_4 SzPav) const
|
---|
[763] | 1184 | {
|
---|
[1092] | 1185 | int_4 im = IMax();
|
---|
[763] | 1186 | return EstimeMax(im,xm,SzPav);
|
---|
| 1187 | }
|
---|
| 1188 |
|
---|
| 1189 | /********* Methode *********/
|
---|
[914] | 1190 | /*!
|
---|
| 1191 | Determine l'abscisses du maximum donne par im
|
---|
| 1192 | en moyennant dans un pave SzPav autour du maximum
|
---|
| 1193 | \verbatim
|
---|
| 1194 | Return:
|
---|
| 1195 | 0 = si fit maximum reussi avec SzPav pixels
|
---|
| 1196 | 1 = si fit maximum reussi avec moins que SzPav pixels
|
---|
| 1197 | 2 = si fit maximum echoue et renvoit BinCenter()
|
---|
| 1198 | -1 = si echec: SzPav <= 0 ou im hors limites
|
---|
| 1199 | \endverbatim
|
---|
| 1200 | */
|
---|
[1144] | 1201 | int_4 Histo::EstimeMax(int_4& im,r_8& xm,int_4 SzPav) const
|
---|
[763] | 1202 | {
|
---|
| 1203 | xm = 0;
|
---|
| 1204 | if( SzPav <= 0 ) return -1;
|
---|
[1092] | 1205 | if( im < 0 || im >= mBins ) return -1;
|
---|
[763] | 1206 |
|
---|
| 1207 | if( SzPav%2 == 0 ) SzPav++;
|
---|
| 1208 | SzPav = (SzPav-1)/2;
|
---|
| 1209 |
|
---|
[1092] | 1210 | int_4 rc = 0;
|
---|
| 1211 | r_8 dxm = 0, wx = 0;
|
---|
| 1212 | for(int_4 i=im-SzPav;i<=im+SzPav;i++) {
|
---|
| 1213 | if( i<0 || i>= mBins ) {rc=1; continue;}
|
---|
[763] | 1214 | dxm += BinCenter(i) * (*this)(i);
|
---|
| 1215 | wx += (*this)(i);
|
---|
| 1216 | }
|
---|
| 1217 |
|
---|
| 1218 | if( wx > 0. ) {
|
---|
| 1219 | xm = dxm/wx;
|
---|
| 1220 | return rc;
|
---|
| 1221 | } else {
|
---|
| 1222 | xm = BinCenter(im);
|
---|
| 1223 | return 2;
|
---|
| 1224 | }
|
---|
| 1225 |
|
---|
| 1226 | }
|
---|
| 1227 |
|
---|
| 1228 | /********* Methode *********/
|
---|
[914] | 1229 | /*!
|
---|
| 1230 | Determine la largeur a frac% du maximum a gauche (widthG)
|
---|
| 1231 | et a droite (widthD)
|
---|
| 1232 | */
|
---|
[1109] | 1233 | void Histo::EstimeWidthS(r_8 frac,r_8& widthG,r_8& widthD) const
|
---|
[763] | 1234 | {
|
---|
[1092] | 1235 | int_4 i;
|
---|
[763] | 1236 | widthG = widthD = -1.;
|
---|
[1092] | 1237 | if( mBins<=1 || frac<=0. || frac>=1. ) return;
|
---|
[763] | 1238 |
|
---|
[1092] | 1239 | int_4 imax = 0;
|
---|
| 1240 | r_8 maxi = mData[0];
|
---|
| 1241 | for(i=1;i<mBins;i++) if(mData[i]>maxi) {imax=i; maxi=mData[i];}
|
---|
| 1242 | r_8 xmax = BinCenter(imax);
|
---|
| 1243 | r_8 maxf = maxi * frac;
|
---|
[763] | 1244 |
|
---|
| 1245 | // recherche du sigma a gauche
|
---|
| 1246 | widthG = 0.;
|
---|
[1092] | 1247 | for(i=imax;i>=0;i--) if( mData[i] <= maxf ) break;
|
---|
[763] | 1248 | if(i<0) i=0;
|
---|
| 1249 | if(i<imax) {
|
---|
[1092] | 1250 | if( mData[i+1] != mData[i] ) {
|
---|
[763] | 1251 | widthG = BinCenter(i) + binWidth
|
---|
[1092] | 1252 | * (maxf-mData[i])/(mData[i+1]-mData[i]);
|
---|
[763] | 1253 | widthG = xmax - widthG;
|
---|
| 1254 | } else widthG = xmax - BinCenter(i);
|
---|
| 1255 | }
|
---|
| 1256 |
|
---|
| 1257 | // recherche du sigma a droite
|
---|
| 1258 | widthD = 0.;
|
---|
[1092] | 1259 | for(i=imax;i<mBins;i++) if( mData[i] <= maxf ) break;
|
---|
| 1260 | if(i>=mBins) i=mBins-1;
|
---|
[763] | 1261 | if(i>imax) {
|
---|
[1092] | 1262 | if( mData[i] != mData[i-1] ) {
|
---|
[763] | 1263 | widthD = BinCenter(i) - binWidth
|
---|
[1092] | 1264 | * (maxf-mData[i])/(mData[i-1]-mData[i]);
|
---|
[763] | 1265 | widthD -= xmax;
|
---|
| 1266 | } else widthD = BinCenter(i) - xmax;
|
---|
| 1267 | }
|
---|
| 1268 |
|
---|
| 1269 | }
|
---|
| 1270 |
|
---|
| 1271 | /********* Methode *********/
|
---|
[914] | 1272 | /*!
|
---|
[1201] | 1273 | Impression de l'histogramme
|
---|
[914] | 1274 | \verbatim
|
---|
| 1275 | hdyn = nombre de colonnes pour imprimer les etoiles
|
---|
| 1276 | si =0 alors defaut(100),
|
---|
| 1277 | si <0 pas de print histo seulement infos
|
---|
| 1278 | hmin = minimum de la dynamique
|
---|
| 1279 | hmax = maximum de la dynamique
|
---|
| 1280 | si hmax<=hmin : hmin=VMin() hmax=VMax()
|
---|
| 1281 | si hmax<=hmin et hmin=0 : hmin=0 hmax=VMax()
|
---|
| 1282 | sinon : hmin hmax
|
---|
| 1283 | pflag < 0 : on imprime les informations (nbin,min,...) sans l'histogramme
|
---|
[1092] | 1284 | = 0 : on imprime "BinCenter(i) mData[i]" (note "... ...")
|
---|
[914] | 1285 | bit 0 on : (v=1): numero_bin "... ..."
|
---|
| 1286 | bit 1 on : (v=2): "... ..." erreur
|
---|
| 1287 | \endverbatim
|
---|
| 1288 | */
|
---|
[1413] | 1289 |
|
---|
| 1290 | void Histo::Show(ostream & os) const
|
---|
| 1291 | {
|
---|
| 1292 | os << " Histo::Show "
|
---|
| 1293 | << " nHist=" << nHist << " nEntries=" << nEntries
|
---|
| 1294 | << " mUnder=" << mUnder << " mOver=" << mOver << endl;
|
---|
| 1295 | os << " mBins=" << mBins
|
---|
| 1296 | << " min=" << mMin << " mMax=" << mMax
|
---|
| 1297 | << " binWidth=" << binWidth << endl;
|
---|
| 1298 | os << " mean=" << Mean() << " r.m.s=" << Sigma()
|
---|
| 1299 | << " Errors="<<HasErrors()<< endl;
|
---|
| 1300 | }
|
---|
| 1301 |
|
---|
[1201] | 1302 | void Histo::Print(int_4 hdyn,r_8 hmin, r_8 hmax,int_4 pflag,
|
---|
| 1303 | int_4 il, int_4 ih) const
|
---|
[763] | 1304 | {
|
---|
| 1305 |
|
---|
[1092] | 1306 | if( il > ih ) { il = 0; ih = mBins-1; }
|
---|
[763] | 1307 | if( il < 0 ) il = 0;
|
---|
[1092] | 1308 | if( ih >= mBins ) ih = mBins-1;
|
---|
[763] | 1309 |
|
---|
[1092] | 1310 | r_8 dhmin = hmin;
|
---|
| 1311 | r_8 dhmax = hmax;
|
---|
| 1312 | r_8 hb,hbmn,hbmx;
|
---|
[763] | 1313 |
|
---|
| 1314 | if(hdyn==0) hdyn = 100;
|
---|
| 1315 |
|
---|
[1413] | 1316 | Show(cout);
|
---|
[763] | 1317 |
|
---|
| 1318 | if(hdyn<0 || pflag<0 ) return;
|
---|
| 1319 |
|
---|
[1092] | 1320 | if(dhmax<=dhmin) { if(hmin != 0.) dhmin = VMin(); else dhmin=0.;
|
---|
| 1321 | dhmax = VMax(); }
|
---|
[763] | 1322 | if(dhmin>dhmax) return;
|
---|
| 1323 | if(dhmin==dhmax) {dhmin -= 1.; dhmax += 1.;}
|
---|
[1092] | 1324 | r_8 wb = (dhmax-dhmin) / hdyn;
|
---|
[763] | 1325 |
|
---|
| 1326 | // determination de la position de la valeur zero
|
---|
[1092] | 1327 | int_4 i0 = (int_4)(-dhmin/wb);
|
---|
[763] | 1328 |
|
---|
| 1329 | // si le zero est dans la dynamique,
|
---|
| 1330 | // il doit imperativement etre une limite de bin
|
---|
| 1331 | if( 0 <= i0 && i0 < hdyn ) {
|
---|
| 1332 | hbmn = dhmin + i0*wb;
|
---|
| 1333 | hbmx = hbmn + wb;
|
---|
| 1334 | if( hbmn != 0. ) {
|
---|
| 1335 | hbmn *= -1.;
|
---|
| 1336 | if( hbmn < hbmx ) {
|
---|
| 1337 | // le zero est + pres du bord negatif du bin
|
---|
| 1338 | dhmin += hbmn;
|
---|
| 1339 | dhmax += hbmn;
|
---|
| 1340 | } else {
|
---|
| 1341 | // le zero est + pres du bord positif du bin
|
---|
| 1342 | dhmin -= hbmx;
|
---|
| 1343 | dhmax -= hbmx;
|
---|
| 1344 | }
|
---|
[1092] | 1345 | wb = (dhmax-dhmin) / hdyn;
|
---|
| 1346 | i0 = (int_4)(-dhmin/wb);
|
---|
[763] | 1347 | }
|
---|
| 1348 | }
|
---|
| 1349 |
|
---|
| 1350 | cout <<" bin minimum="<<dhmin<<" bin maximum="<<dhmax
|
---|
| 1351 | <<" binw="<<wb<< endl;
|
---|
| 1352 |
|
---|
| 1353 | char* s = new char[hdyn+1];
|
---|
| 1354 | s[hdyn] = '\0';
|
---|
| 1355 |
|
---|
| 1356 | // premiere ligne
|
---|
[1092] | 1357 | {for(int_4 i=0;i<hdyn;i++) s[i] = '=';}
|
---|
[763] | 1358 | if( 0 <= i0 && i0 < hdyn ) s[i0] = '0';
|
---|
[1201] | 1359 | if(pflag&1) printf("====");
|
---|
| 1360 | printf("======================");
|
---|
| 1361 | if(pflag&2 && mErr2!=NULL) printf("===========");
|
---|
| 1362 | printf("==%s\n",s);
|
---|
[763] | 1363 |
|
---|
| 1364 | // histogramme
|
---|
[1092] | 1365 | {for(int_4 i=il;i<=ih;i++) {
|
---|
| 1366 | for(int_4 k=0;k<hdyn;k++) s[k] = ' ';
|
---|
[763] | 1367 | hb = (*this)(i);
|
---|
| 1368 |
|
---|
| 1369 | //choix du bin (hdyn bin entre [dhmin,dhmax[
|
---|
[1092] | 1370 | int_4 ii = (int_4)( (hb-dhmin)/wb );
|
---|
[763] | 1371 | if(ii<0) ii = 0; else if(ii>=hdyn) ii = hdyn-1;
|
---|
| 1372 |
|
---|
| 1373 | // limite du bin
|
---|
| 1374 | hbmn = dhmin + ii*wb;
|
---|
| 1375 | hbmx = hbmn + wb;
|
---|
| 1376 |
|
---|
| 1377 | // remplissage de s[] en tenant compte des courbes +/-
|
---|
| 1378 | if(i0<0) {
|
---|
| 1379 | // courbe entierement positive
|
---|
[1092] | 1380 | for(int_4 k=0;k<=ii;k++) s[k] = 'X';
|
---|
[763] | 1381 | } else if(i0>=hdyn) {
|
---|
| 1382 | // courbe entierement negative
|
---|
[1092] | 1383 | for(int_4 k=hdyn-1;k>=ii;k--) s[k] = 'X';
|
---|
[763] | 1384 | } else {
|
---|
| 1385 | // courbe positive et negative
|
---|
| 1386 | s[i0] = '|';
|
---|
[1092] | 1387 | if(ii>i0) for(int_4 k=i0+1;k<=ii;k++) s[k] = 'X';
|
---|
| 1388 | else if(ii<i0) for(int_4 k=ii;k<i0;k++) s[k] = 'X';
|
---|
[763] | 1389 | else s[ii] = 'X';
|
---|
| 1390 | }
|
---|
| 1391 |
|
---|
| 1392 | // valeur a mettre dans le bin le plus haut/bas
|
---|
[1092] | 1393 | int_4 ib;
|
---|
| 1394 | if(hb>0.) ib = (int_4)( 10.*(hb-hbmn)/(hbmx-hbmn) );
|
---|
| 1395 | else if(hb<0.) ib = (int_4)( 10.*(hbmx-hb)/(hbmx-hbmn) );
|
---|
[763] | 1396 | else ib = -1;
|
---|
| 1397 | if(ib==-1) s[ii] = '|';
|
---|
| 1398 | else if(ib==0) s[ii] = '.';
|
---|
[1092] | 1399 | else if(ib>0 && ib<10) s[ii] = (char)((int_4) '0' + ib);
|
---|
[763] | 1400 |
|
---|
| 1401 | // traitement des saturations +/-
|
---|
| 1402 | if( hb < dhmin ) s[0] = '*';
|
---|
| 1403 | else if( hb > dhmax ) s[hdyn-1] = '*';
|
---|
| 1404 |
|
---|
[1201] | 1405 | if(pflag&1) printf("%3d ",i);
|
---|
| 1406 | printf("%10.4g %10.4g ",BinCenter(i),hb);
|
---|
| 1407 | if(pflag&2 && mErr2!=NULL) printf("%10.4g ",Error(i));
|
---|
| 1408 | printf("= %s\n",s);
|
---|
[763] | 1409 | }}
|
---|
| 1410 |
|
---|
| 1411 | // derniere ligne
|
---|
[1092] | 1412 | for(int_4 i=0;i<hdyn;i++) s[i] = '=';
|
---|
[763] | 1413 | if( 0 <= i0 && i0 < hdyn ) s[i0] = '0';
|
---|
[1201] | 1414 | if(pflag&1) printf("====");
|
---|
| 1415 | printf("======================");
|
---|
| 1416 | if(pflag&2 && mErr2!=NULL) printf("===========");
|
---|
| 1417 | printf("==%s\n",s);
|
---|
[763] | 1418 |
|
---|
| 1419 | // valeur basse des bins (sur ["ndig-1" digits + signe] = ndig char (>=3))
|
---|
[1092] | 1420 | const int_4 ndig = 7;
|
---|
[763] | 1421 | char sn[2*ndig+10];
|
---|
| 1422 | hb = ( fabs(dhmin) > fabs(dhmax) ) ? fabs(dhmin) : fabs(dhmax);
|
---|
[1092] | 1423 | int_4 n;
|
---|
| 1424 | if( hb > 0. ) n = (int_4)(log10(hb*1.00000001)); else n = 1;
|
---|
| 1425 | r_8 scaledig = pow(10.,(r_8) ndig-2);
|
---|
| 1426 | r_8 expo = scaledig/pow(10.,(r_8) n);
|
---|
[763] | 1427 | // cout <<"n="<<n<<" hb="<<hb<<" scaledig="<<scaledig<<" expo="<<expo<<endl;
|
---|
[1092] | 1428 | for(int_4 k=0;k<ndig;k++) {
|
---|
| 1429 | for(int_4 i=0;i<hdyn;i++) s[i] = ' ';
|
---|
| 1430 | {for(int_4 i=0;i<hdyn;i++) {
|
---|
| 1431 | n = (int_4)( (dhmin + i*wb)*expo );
|
---|
| 1432 | for(int_4 j=0;j<2*ndig+10;j++) sn[j] = ' ';
|
---|
[763] | 1433 | sprintf(sn,"%d%c",n,'\0');
|
---|
| 1434 | strip(sn,'B',' ');
|
---|
| 1435 | // cout <<"n="<<n<<" sn=("<<sn<<") l="<<strlen(sn)<<" k="<<k;
|
---|
[1092] | 1436 | if( (int_4) strlen(sn) > k ) s[i] = sn[k];
|
---|
[763] | 1437 | // cout <<" s=("<<s<<")"<<endl;
|
---|
| 1438 | }}
|
---|
[1201] | 1439 | if(pflag&1) printf(" ");
|
---|
| 1440 | printf(" ");
|
---|
| 1441 | if(pflag&2 && mErr2!=NULL) printf(" ");
|
---|
| 1442 | printf(" %s\n",s);
|
---|
[763] | 1443 | }
|
---|
[1201] | 1444 | printf(" (valeurs a multiplier par %.0e)\n",1./expo);
|
---|
[763] | 1445 |
|
---|
| 1446 | delete[] s;
|
---|
| 1447 | }
|
---|
| 1448 |
|
---|
| 1449 |
|
---|
| 1450 | ///////////////////////////////////////////////////////////
|
---|
| 1451 | // --------------------------------------------------------
|
---|
| 1452 | // Les objets delegues pour la gestion de persistance
|
---|
| 1453 | // --------------------------------------------------------
|
---|
| 1454 | ///////////////////////////////////////////////////////////
|
---|
| 1455 |
|
---|
[2341] | 1456 |
|
---|
| 1457 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[763] | 1458 | void ObjFileIO<Histo>::ReadSelf(PInPersist& is)
|
---|
| 1459 | {
|
---|
| 1460 | char strg[256];
|
---|
| 1461 |
|
---|
| 1462 | if(dobj==NULL) dobj=new Histo;
|
---|
| 1463 | else dobj->Delete();
|
---|
| 1464 |
|
---|
| 1465 | // Lecture entete
|
---|
| 1466 | is.GetLine(strg, 255);
|
---|
[2628] | 1467 | bool nentries_en_8_bytes=false;
|
---|
| 1468 | if(strg[0]=='V' && strg[1]=='_' && strg[2]=='2') nentries_en_8_bytes=true;
|
---|
[763] | 1469 | is.GetLine(strg, 255);
|
---|
| 1470 | is.GetLine(strg, 255);
|
---|
| 1471 |
|
---|
| 1472 | // Lecture des valeurs
|
---|
[1092] | 1473 | is.Get(dobj->mBins);
|
---|
[2628] | 1474 | if(nentries_en_8_bytes) is.Get(dobj->nEntries);
|
---|
| 1475 | else {int_4 dum; is.Get(dum); dobj->nEntries=(uint_8)dum;}
|
---|
[763] | 1476 | int_4 errok;
|
---|
| 1477 | is.Get(errok);
|
---|
| 1478 |
|
---|
| 1479 | is.Get(dobj->binWidth);
|
---|
[1092] | 1480 | is.Get(dobj->mMin);
|
---|
| 1481 | is.Get(dobj->mMax);
|
---|
| 1482 | is.Get(dobj->mUnder);
|
---|
| 1483 | is.Get(dobj->mOver);
|
---|
[763] | 1484 |
|
---|
| 1485 | is.Get(dobj->nHist);
|
---|
| 1486 |
|
---|
| 1487 | // Lecture des donnees Histo 1D
|
---|
[1092] | 1488 | dobj->mData = new r_8[dobj->mBins];
|
---|
[763] | 1489 | is.GetLine(strg, 255);
|
---|
[1092] | 1490 | is.Get(dobj->mData, dobj->mBins);
|
---|
[763] | 1491 |
|
---|
| 1492 | // Lecture des erreurs
|
---|
| 1493 | if(errok) {
|
---|
| 1494 | is.GetLine(strg, 255);
|
---|
[1092] | 1495 | dobj->mErr2 = new r_8[dobj->mBins];
|
---|
| 1496 | is.Get(dobj->mErr2, dobj->mBins);
|
---|
[763] | 1497 | }
|
---|
| 1498 |
|
---|
| 1499 | return;
|
---|
| 1500 | }
|
---|
| 1501 |
|
---|
[2341] | 1502 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[763] | 1503 | void ObjFileIO<Histo>::WriteSelf(POutPersist& os) const
|
---|
| 1504 | {
|
---|
| 1505 | if (dobj == NULL) return;
|
---|
| 1506 | char strg[256];
|
---|
| 1507 |
|
---|
| 1508 | // Que faut-il ecrire?
|
---|
[1092] | 1509 | int_4 errok = (dobj->mErr2) ? 1 : 0;
|
---|
[763] | 1510 |
|
---|
| 1511 | // Ecriture entete pour identifier facilement
|
---|
[2628] | 1512 | sprintf(strg,"V_2 mBins=%6d NEnt=%15d errok=%1d",dobj->mBins,dobj->nEntries,errok);
|
---|
[763] | 1513 | os.PutLine(strg);
|
---|
[1092] | 1514 | sprintf(strg,"binw=%g mMin=%g mMax=%g",dobj->binWidth,dobj->mMin,dobj->mMax);
|
---|
[763] | 1515 | os.PutLine(strg);
|
---|
[1092] | 1516 | sprintf(strg, "mUnder=%g mOver=%g nHist=%g",dobj->mUnder,dobj->mOver,dobj->nHist);
|
---|
[763] | 1517 | os.PutLine(strg);
|
---|
| 1518 |
|
---|
| 1519 | // Ecriture des valeurs
|
---|
[1092] | 1520 | os.Put(dobj->mBins);
|
---|
[763] | 1521 | os.Put(dobj->nEntries);
|
---|
| 1522 | os.Put(errok);
|
---|
| 1523 |
|
---|
| 1524 | os.Put(dobj->binWidth);
|
---|
[1092] | 1525 | os.Put(dobj->mMin);
|
---|
| 1526 | os.Put(dobj->mMax);
|
---|
| 1527 | os.Put(dobj->mUnder);
|
---|
| 1528 | os.Put(dobj->mOver);
|
---|
[763] | 1529 |
|
---|
| 1530 | os.Put(dobj->nHist);
|
---|
| 1531 |
|
---|
| 1532 | // Ecriture des donnees Histo 1D
|
---|
[1092] | 1533 | sprintf(strg,"Histo: Tableau des donnees %d",dobj->mBins);
|
---|
[763] | 1534 | os.PutLine(strg);
|
---|
[1092] | 1535 | os.Put(dobj->mData, dobj->mBins);
|
---|
[763] | 1536 |
|
---|
| 1537 | // Ecriture des erreurs
|
---|
| 1538 | if(errok) {
|
---|
[1092] | 1539 | sprintf(strg,"Histo: Tableau des erreurs %d",dobj->mBins);
|
---|
[763] | 1540 | os.PutLine(strg);
|
---|
[1092] | 1541 | os.Put(dobj->mErr2, dobj->mBins);
|
---|
[763] | 1542 | }
|
---|
| 1543 |
|
---|
| 1544 | return;
|
---|
| 1545 | }
|
---|
| 1546 |
|
---|
| 1547 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 1548 | #pragma define_template ObjFileIO<Histo>
|
---|
| 1549 | #endif
|
---|
| 1550 |
|
---|
| 1551 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[2868] | 1552 | template class SOPHYA::ObjFileIO<Histo>;
|
---|
[763] | 1553 | #endif
|
---|