source: Sophya/trunk/SophyaLib/HiStats/histerr.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: 4.6 KB
Line 
1#ifndef HISTERR_SEEN
2#define HISTERR_SEEN
3
4#include "objfio.h"
5#include <iostream>
6#include <stdio.h>
7#include "tvector.h"
8
9namespace SOPHYA {
10
11// Forward class declaration for Fits handler
12template <class T> class FitsHandler;
13
14
15//! 1 dimensions histograms with errors given by user
16class HistoErr : public AnyDataObj {
17 friend class ObjFileIO<HistoErr>;
18 friend class FitsHandler<HistoErr>;
19public:
20
21 //! Create or destroy
22 HistoErr(void);
23 HistoErr(r_8 xmin,r_8 xmax,int_4 nx);
24 HistoErr(const HistoErr& H);
25 virtual ~HistoErr(void);
26
27 //! Updating or Setting
28 void ReCenterBin(void);
29 void Zero(void);
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
71 //! Addition du contenu de l'histo pour abscisse x poids w et l'erreur e
72 inline void Add(r_8 x, r_8 w, r_8 e)
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 }
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.);}
80
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.);}
89
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 }
113
114 //! Compute the correlation histogram
115 void ToCorrel(void);
116 void FromCorrel(void);
117 int_4 NCorrel(void) {return mCorrel;}
118 void SetCorrel(int_4 mcorrel) {mCorrel = mcorrel;}
119
120 //! Fill an histogram with an histogram
121 void FillFrHErr(HistoErr& hfrom);
122
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
128 // Operators
129 HistoErr& operator = (const HistoErr& h);
130
131 // Print
132 virtual void Show(ostream& os) const;
133 inline void Show() const { Show(cout); }
134
135protected:
136 void CreateOrResize(r_8 xmin,r_8 xmax,int_4 nx);
137
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_;
143 int_4 mCorrel; //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
144};
145
146/*! Prints histogram information on stream \b s (h.Show(s)) */
147inline ostream& operator << (ostream& s, HistoErr const & h)
148 { h.Show(s); return(s); }
149
150/*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
151 \brief Persistance management */
152inline 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 */
156inline 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
Note: See TracBrowser for help on using the repository browser.