source: Sophya/trunk/SophyaLib/HiStats/hist2err.h@ 3123

Last change on this file since 3123 was 3123, checked in by cmv, 19 years ago

modif HistoErr Histo2DErr cmv 10/01/07

File size: 5.4 KB
RevLine 
[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
9namespace SOPHYA {
10
[3123]11// Forward class declaration for Fits handler
12template <class T> class FitsHandler;
13
[3121]14//! 2 dimensions histograms with errors given by user
15class Histo2DErr : public AnyDataObj {
16 friend class ObjFileIO<Histo2DErr>;
[3123]17 friend class FitsHandler<Histo2DErr>;
[3121]18public:
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 }
59
60 //! Retourne le nombre d'entree dans le bin
61 inline r_8 NEntBin(int_4 i,int_4 j) const
62 {
63 if(i<0 || i>=nx_ || j<0 || j>=ny_) return 0.;
64 return ndata_(i,j);
65 }
66
67 //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i,j.
68 inline void BinLowEdge(int_4 i,int_4 j,r_8& x,r_8& y) const
69 {x = xmin_ + i*dx_; y = ymin_ + j*dy_;}
70 //! Retourne l'abscisse et l'ordonnee du centre du bin i,j.
71 inline void BinCenter(int_4 i,int_4 j,r_8& x,r_8& y) const
72 {x = xmin_ + (i+0.5)*dx_; y = ymin_ + (j+0.5)*dy_;}
73 //! Retourne l'abscisse et l'ordonnee du coin superieur du bin i,j.
74 inline void BinHighEdge(int_4 i,int_4 j,r_8& x,r_8& y) const
75 {x = xmin_ + (i+1)*dx_; y = ymin_ + (j+1)*dy_;}
76 //! Retourne les numeros du bin contenant l'abscisse et l'ordonnee x,y.
77 inline void FindBin(r_8 x,r_8 y,int_4& i,int_4& j) const
78 {i=(int_4) floor((x-xmin_)/dx_); j=(int_4) floor((y-ymin_)/dy_);}
79
80 //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e
81 inline void Add(r_8 x, r_8 y, r_8 w, r_8 e)
82 {
83 int_4 i,j; FindBin(x,y,i,j);
84 if(i<0 || i>=nx_ || j<0 || j>=ny_) return;
85 data_(i,j) += w; ndata_(i,j) += 1.; err2_(i,j) += e*e;
86 }
87 inline void Add(r_8 x,r_8 y, r_8 w) {Add(x,y,w,1.);}
88 inline void Add(r_8 x,r_8 y) {Add(x,y,1.,1.);}
89
90 //! Addition du contenu de l'histo pour le bin numBin poids w et l'erreur e
91 inline void AddBin(int_4 i,int_4 j, r_8 w, r_8 e)
92 {
93 if(i<0 || i>=nx_ || j<0 || j>=ny_) return;
94 data_(i,j) += w; ndata_(i,j) += 1.; err2_(i,j) += e*e;
95 }
96 inline void AddBin(int_4 i,int_4 j, r_8 w) {AddBin(i,j,w,1.);}
97 inline void AddBin(int_4 i,int_4 j) {AddBin(i,j,1.,1.);}
98
[3123]99 //! remplissage contenu de l'histo pour le bin i poids w et l'erreur e
[3121]100 inline void SetBin(int_4 i,int_4 j, r_8 w, r_8 e, r_8 nb)
101 {
102 if(i<0 || i>=nx_ || j<0 || j>=ny_) return;
103 data_(i,j) = w;
104 err2_(i,j) = e*e;
105 ndata_(i,j) = nb;
106 }
107 inline void SetBin(int_4 i,int_4 j, r_8 w, r_8 e) {SetBin(i,j,w,e,1.);}
108 inline void SetBin(int_4 i,int_4 j, r_8 w) {SetBin(i,j,w,1.,1.);}
109 inline void SetBin(int_4 i,int_4 j) {SetBin(i,j,1.,1.,1.);}
[3123]110 //! remplissage de l'erreur carree pour le bin i
111 void SetErr2(int_4 i,int_4 j, r_8 e2)
112 {
113 if(i<0 || i>=nx_) return;
114 err2_(i,j) = e2;
115 }
116 //! remplissage nombre d'entrees pour le bin i
[3121]117 void SetNentB(int_4 i,int_4 j, r_8 nb)
118 {
119 if(i<0 || i>=nx_ || j<0 || j>=ny_) return;
120 ndata_(i,j) = nb;
121 }
122
123 //! Compute the correlation histogram
124 void ToCorrel(void);
125 void FromCorrel(void);
126 int_4 NCorrel(void) {return mCorrel;}
127 void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
128
129 //! Fill an histogram with an histogram
130 void FillFrHErr(Histo2DErr& hfrom);
131
132 //! Recuperation des matrices elementaires
133 inline void GetData(TMatrix<r_8>& data) {data = data_;}
134 inline void GetError2(TMatrix<r_8>& err2) {err2 = err2_;}
135 inline void GetNData(TMatrix<r_8>& ndata) {ndata = ndata_;}
136
137 // Operators
138 Histo2DErr& operator = (const Histo2DErr& h);
139
140 // Print
141 virtual void Show(ostream& os) const;
142 inline void Show() const { Show(cout); }
143
144protected:
145 void CreateOrResize(r_8 xmin,r_8 xmax,int_4 nx,r_8 ymin,r_8 ymax,int_4 ny);
146
147 r_4 xmin_,xmax_,dx_,ymin_,ymax_,dy_;
148 int_4 nx_,ny_;
149 TMatrix<r_8> data_;
150 TMatrix<r_8> err2_;
151 TMatrix<r_8> ndata_;
152 int_4 mCorrel; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
153};
154
155/*! Prints histogram information on stream \b s (h.Show(s)) */
156inline ostream& operator << (ostream& s, Histo2DErr const & h)
157 { h.Show(s); return(s); }
158
159/*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo2DErr)
160 \brief Persistance management */
161inline POutPersist& operator << (POutPersist& os, Histo2DErr & obj)
162{ ObjFileIO<Histo2DErr> fio(&obj); fio.Write(os); return(os); }
163/*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo2DErr)
164 \brief Persistance management */
165inline PInPersist& operator >> (PInPersist& is, Histo2DErr & obj)
166{ ObjFileIO<Histo2DErr> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
167
168} // Fin du namespace
169
170#endif // HIST2ERR_SEEN
Note: See TracBrowser for help on using the repository browser.