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