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