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