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

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

Creation classe Histo2DErr cmv 21/12/06

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