[2603] | 1 | #ifndef HISTERR_SEEN
|
---|
| 2 | #define HISTERR_SEEN
|
---|
| 3 |
|
---|
| 4 | #include "objfio.h"
|
---|
| 5 | #include <iostream>
|
---|
| 6 | #include <stdio.h>
|
---|
[3123] | 7 | #include "tvector.h"
|
---|
[2603] | 8 |
|
---|
| 9 | namespace SOPHYA {
|
---|
| 10 |
|
---|
[3049] | 11 | // Forward class declaration for Fits handler
|
---|
| 12 | template <class T> class FitsHandler;
|
---|
| 13 |
|
---|
[3123] | 14 |
|
---|
| 15 | //! 1 dimensions histograms with errors given by user
|
---|
| 16 | class HistoErr : public AnyDataObj {
|
---|
[2603] | 17 | friend class ObjFileIO<HistoErr>;
|
---|
[3123] | 18 | friend class FitsHandler<HistoErr>;
|
---|
[2603] | 19 | public:
|
---|
| 20 |
|
---|
[3123] | 21 | //! Create or destroy
|
---|
[2603] | 22 | HistoErr(void);
|
---|
[3123] | 23 | HistoErr(r_8 xmin,r_8 xmax,int_4 nx);
|
---|
[2603] | 24 | HistoErr(const HistoErr& H);
|
---|
| 25 | virtual ~HistoErr(void);
|
---|
| 26 |
|
---|
[3123] | 27 | //! Updating or Setting
|
---|
| 28 | void ReCenterBin(void);
|
---|
[2603] | 29 | void Zero(void);
|
---|
[3123] | 30 |
|
---|
| 31 | //! Getting Info
|
---|
| 32 | int_4 NBins(void) {return nx_;}
|
---|
| 33 | r_8 XMin(void) {return xmin_;}
|
---|
| 34 | r_8 XMax(void) {return xmax_;}
|
---|
| 35 | r_8 BinWidth(void) {return dx_;}
|
---|
| 36 |
|
---|
| 37 | //! Retourne le contenu du bin
|
---|
| 38 | inline r_8 operator()(int_4 i) const
|
---|
| 39 | {
|
---|
| 40 | if(i<0 || i>=nx_) return 0.;
|
---|
| 41 | return data_(i);
|
---|
| 42 | }
|
---|
| 43 | inline r_8& operator()(int_4 i)
|
---|
| 44 | {
|
---|
| 45 | return data_(i);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | //! Retourne le nombre l'erreur au carre dans le bin
|
---|
| 49 | inline r_8 Error2(int_4 i) const
|
---|
| 50 | {
|
---|
| 51 | if(i<0 || i>=nx_) return 0.;
|
---|
| 52 | return err2_(i);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | //! Retourne le nombre d'entree dans le bin
|
---|
| 56 | inline r_8 NEntBin(int_4 i) const
|
---|
| 57 | {
|
---|
| 58 | if(i<0 || i>=nx_) return 0.;
|
---|
| 59 | return ndata_(i);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i.
|
---|
| 63 | inline r_8 BinLowEdge(int_4 i) const {return xmin_ + i*dx_;}
|
---|
| 64 | //! Retourne l'abscisse et l'ordonnee du centre du bin i.
|
---|
| 65 | inline r_8 BinCenter(int_4 i) const {return xmin_ + (i+0.5)*dx_;}
|
---|
| 66 | //! Retourne l'abscisse et l'ordonnee du coin superieur du bin i.
|
---|
| 67 | inline r_8 BinHighEdge(int_4 i) const {return xmin_ + (i+1)*dx_;}
|
---|
| 68 | //! Retourne les numeros du bin contenant l'abscisse et l'ordonnee x,y.
|
---|
| 69 | inline int_4 FindBin(r_8 x) const {return (int_4)floor((x-xmin_)/dx_);}
|
---|
| 70 |
|
---|
[2603] | 71 | //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e
|
---|
[2630] | 72 | inline void Add(r_8 x, r_8 w, r_8 e)
|
---|
[3123] | 73 | {
|
---|
| 74 | int_4 i = FindBin(x);
|
---|
| 75 | if(i<0 || i>=nx_) return;
|
---|
| 76 | data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e;
|
---|
| 77 | }
|
---|
[2630] | 78 | inline void Add(r_8 x, r_8 w) {Add(x,w,1.);}
|
---|
| 79 | inline void Add(r_8 x) {Add(x,1.,1.);}
|
---|
[2603] | 80 |
|
---|
[3123] | 81 | //! Addition du contenu de l'histo pour le bin i poids w et l'erreur e
|
---|
| 82 | inline void AddBin(int_4 i, r_8 w, r_8 e)
|
---|
| 83 | {
|
---|
| 84 | if(i<0 || i>=nx_) return;
|
---|
| 85 | data_(i) += w; ndata_(i) += 1.; err2_(i) += e*e;
|
---|
| 86 | }
|
---|
| 87 | inline void AddBin(int_4 i, r_8 w) {AddBin(i,w,1.);}
|
---|
| 88 | inline void AddBin(int_4 i) {AddBin(i,1.,1.);}
|
---|
[2603] | 89 |
|
---|
[3123] | 90 | //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e
|
---|
| 91 | inline void SetBin(int_4 i, r_8 w, r_8 e, r_8 nb)
|
---|
| 92 | {
|
---|
| 93 | if(i<0 || i>=nx_) return;
|
---|
| 94 | data_(i) = w;
|
---|
| 95 | err2_(i) = e*e;
|
---|
| 96 | ndata_(i) = nb;
|
---|
| 97 | }
|
---|
| 98 | inline void SetBin(int_4 i, r_8 w, r_8 e) {SetBin(i,w,e,1.);}
|
---|
| 99 | inline void SetBin(int_4 i, r_8 w) {SetBin(i,w,1.,1.);}
|
---|
| 100 | inline void SetBin(int_4 i) {SetBin(i,1.,1.,1.);}
|
---|
| 101 | //! remplissage de l'erreur carree pour le bin i
|
---|
| 102 | void SetErr2(int_4 i, r_8 e2)
|
---|
| 103 | {
|
---|
| 104 | if(i<0 || i>=nx_) return;
|
---|
| 105 | err2_(i) = e2;
|
---|
| 106 | }
|
---|
| 107 | //! remplissage nombre d'entrees pour le bin i
|
---|
| 108 | void SetNentB(int_4 i, r_8 nb)
|
---|
| 109 | {
|
---|
| 110 | if(i<0 || i>=nx_) return;
|
---|
| 111 | ndata_(i) = nb;
|
---|
| 112 | }
|
---|
[2603] | 113 |
|
---|
[2608] | 114 | //! Compute the correlation histogram
|
---|
[2604] | 115 | void ToCorrel(void);
|
---|
[2819] | 116 | void FromCorrel(void);
|
---|
[3049] | 117 | int_4 NCorrel(void) {return mCorrel;}
|
---|
[3118] | 118 | void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
|
---|
[2604] | 119 |
|
---|
[2628] | 120 | //! Fill an histogram with an histogram
|
---|
| 121 | void FillFrHErr(HistoErr& hfrom);
|
---|
| 122 |
|
---|
[3123] | 123 | //! Recuperation des matrices elementaires
|
---|
| 124 | inline void GetData(TVector<r_8>& data) {data = data_;}
|
---|
| 125 | inline void GetError2(TVector<r_8>& err2) {err2 = err2_;}
|
---|
| 126 | inline void GetNData(TVector<r_8>& ndata) {ndata = ndata_;}
|
---|
| 127 |
|
---|
[2619] | 128 | // Operators
|
---|
| 129 | HistoErr& operator = (const HistoErr& h);
|
---|
| 130 |
|
---|
[3053] | 131 | // Print
|
---|
| 132 | virtual void Show(ostream& os) const;
|
---|
| 133 | inline void Show() const { Show(cout); }
|
---|
| 134 |
|
---|
[2603] | 135 | protected:
|
---|
[3123] | 136 | void CreateOrResize(r_8 xmin,r_8 xmax,int_4 nx);
|
---|
[2619] | 137 |
|
---|
[3123] | 138 | r_4 xmin_,xmax_,dx_;
|
---|
| 139 | int_4 nx_;
|
---|
| 140 | TVector<r_8> data_;
|
---|
| 141 | TVector<r_8> err2_;
|
---|
| 142 | TVector<r_8> ndata_;
|
---|
[3049] | 143 | int_4 mCorrel; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
|
---|
[2603] | 144 | };
|
---|
| 145 |
|
---|
[3053] | 146 | /*! Prints histogram information on stream \b s (h.Show(s)) */
|
---|
| 147 | inline ostream& operator << (ostream& s, HistoErr const & h)
|
---|
| 148 | { h.Show(s); return(s); }
|
---|
| 149 |
|
---|
[2603] | 150 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
|
---|
| 151 | \brief Persistance management */
|
---|
| 152 | inline POutPersist& operator << (POutPersist& os, HistoErr & obj)
|
---|
| 153 | { ObjFileIO<HistoErr> fio(&obj); fio.Write(os); return(os); }
|
---|
| 154 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
|
---|
| 155 | \brief Persistance management */
|
---|
| 156 | inline PInPersist& operator >> (PInPersist& is, HistoErr & obj)
|
---|
| 157 | { ObjFileIO<HistoErr> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
| 158 |
|
---|
| 159 | } // Fin du namespace
|
---|
| 160 |
|
---|
| 161 | #endif // HISTERR_SEEN
|
---|