[2603] | 1 | #ifndef HISTERR_SEEN
|
---|
| 2 | #define HISTERR_SEEN
|
---|
| 3 |
|
---|
| 4 | #include "objfio.h"
|
---|
| 5 | #include <iostream>
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 | #include "histos.h"
|
---|
| 8 |
|
---|
| 9 | namespace SOPHYA {
|
---|
| 10 |
|
---|
[3049] | 11 | // Forward class declaration for Fits handler
|
---|
| 12 | template <class T> class FitsHandler;
|
---|
| 13 |
|
---|
[2603] | 14 | //! 1 dimension histograms with errors given by user
|
---|
| 15 | class HistoErr : public Histo {
|
---|
| 16 | friend class ObjFileIO<HistoErr>;
|
---|
[3049] | 17 | friend class FitsHandler<Histo>;
|
---|
[2603] | 18 | public:
|
---|
| 19 |
|
---|
| 20 | // CREATOR / DESTRUCTOR
|
---|
| 21 | HistoErr(void);
|
---|
| 22 | HistoErr(r_8 xMin, r_8 xMax, int_4 nBin=100);
|
---|
| 23 | HistoErr(const HistoErr& H);
|
---|
| 24 | virtual ~HistoErr(void);
|
---|
| 25 |
|
---|
| 26 | // UPDATING or SETTING
|
---|
| 27 | void Zero(void);
|
---|
| 28 | //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e
|
---|
[2630] | 29 | inline void Add(r_8 x, r_8 w, r_8 e)
|
---|
| 30 | {
|
---|
| 31 | int_4 numBin = (int_4)floor((x-mMin)/binWidth);
|
---|
| 32 | if(numBin<0) mUnder += w;
|
---|
| 33 | else if(numBin>=mBins) mOver += w;
|
---|
| 34 | else {
|
---|
| 35 | mData[numBin] += w; mNData[numBin] += 1.; mErr2[numBin] += e*e;
|
---|
| 36 | nHist += w; nEntries++;
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 | inline void Add(r_8 x, r_8 w) {Add(x,w,1.);}
|
---|
| 40 | inline void Add(r_8 x) {Add(x,1.,1.);}
|
---|
[2603] | 41 | //! Addition du contenu de l'histo pour le bin numBin poids w et l'erreur e
|
---|
[2630] | 42 | inline void AddBin(int_4 numBin, r_8 w, r_8 e)
|
---|
| 43 | {
|
---|
| 44 | if(numBin<0) mUnder += w;
|
---|
| 45 | else if(numBin>=mBins) mOver += w;
|
---|
| 46 | else {
|
---|
| 47 | mData[numBin] += w; mNData[numBin] += 1.; mErr2[numBin] += e*e;
|
---|
| 48 | nHist += w; nEntries++;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | inline void AddBin(int_4 numBin, r_8 w) {AddBin(numBin,w,1.);}
|
---|
| 52 | inline void AddBin(int_4 numBin) {AddBin(numBin,1.,1.);}
|
---|
[2604] | 53 | //! remplissage contenu de l'histo pour le bin numBin poids w et l'erreur e
|
---|
[2630] | 54 | void SetBin(int_4 numBin, r_8 w, r_8 e, r_8 nb);
|
---|
| 55 | inline void SetBin(int_4 numBin, r_8 w, r_8 e) {SetBin(numBin,w,e,1.);}
|
---|
| 56 | inline void SetBin(int_4 numBin, r_8 w) {SetBin(numBin,w,1.,1.);}
|
---|
| 57 | inline void SetBin(int_4 numBin) {SetBin(numBin,1.,1.,1.);}
|
---|
[2604] | 58 | //! remplissage nombre d'entrees pour le bin numBin
|
---|
[2626] | 59 | void SetNentB(int_4 numBin, r_8 nb=1.);
|
---|
[2603] | 60 |
|
---|
| 61 | //! Retourne le nombre d'entree dans le bin
|
---|
[2626] | 62 | inline r_8 NEntBin(int_4 i) const
|
---|
| 63 | {if(mNData) return mNData[i]; else return 0.;}
|
---|
[2603] | 64 |
|
---|
[2608] | 65 | //! get/put from/to a vector
|
---|
[2626] | 66 | void GetNBin(TVector<r_8>& v) const;
|
---|
| 67 | void PutNBin(TVector<r_8>& v);
|
---|
[2603] | 68 |
|
---|
[2608] | 69 | //! Compute the correlation histogram
|
---|
[2604] | 70 | void ToCorrel(void);
|
---|
[2819] | 71 | void FromCorrel(void);
|
---|
[3049] | 72 | int_4 NCorrel(void) {return mCorrel;}
|
---|
[3118] | 73 | void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
|
---|
[2604] | 74 |
|
---|
[2628] | 75 | //! Fill an histogram with an histogram
|
---|
| 76 | void FillFrHErr(HistoErr& hfrom);
|
---|
| 77 |
|
---|
[2619] | 78 | // Operators
|
---|
| 79 | HistoErr& operator = (const HistoErr& h);
|
---|
| 80 |
|
---|
[3053] | 81 | // Print
|
---|
| 82 | virtual void Show(ostream& os) const;
|
---|
| 83 | inline void Show() const { Show(cout); }
|
---|
| 84 |
|
---|
[2603] | 85 | protected:
|
---|
[3053] | 86 | void CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin);
|
---|
[2619] | 87 | void Delete(void);
|
---|
| 88 |
|
---|
[2626] | 89 | r_8* mNData; //!< nombre d'entrees dans chaque bin
|
---|
[3049] | 90 | int_4 mCorrel; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
|
---|
[2603] | 91 | };
|
---|
| 92 |
|
---|
[3053] | 93 | /*! Prints histogram information on stream \b s (h.Show(s)) */
|
---|
| 94 | inline ostream& operator << (ostream& s, HistoErr const & h)
|
---|
| 95 | { h.Show(s); return(s); }
|
---|
| 96 |
|
---|
[2603] | 97 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
|
---|
| 98 | \brief Persistance management */
|
---|
| 99 | inline POutPersist& operator << (POutPersist& os, HistoErr & obj)
|
---|
| 100 | { ObjFileIO<HistoErr> fio(&obj); fio.Write(os); return(os); }
|
---|
| 101 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
|
---|
| 102 | \brief Persistance management */
|
---|
| 103 | inline PInPersist& operator >> (PInPersist& is, HistoErr & obj)
|
---|
| 104 | { ObjFileIO<HistoErr> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
| 105 |
|
---|
| 106 | } // Fin du namespace
|
---|
| 107 |
|
---|
| 108 | #endif // HISTERR_SEEN
|
---|