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