1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | //
|
---|
3 | // $Id: histos.h,v 1.19 2004-10-13 16:41:33 cmv Exp $
|
---|
4 | //
|
---|
5 |
|
---|
6 | #ifndef HISTOS_SEEN
|
---|
7 | #define HISTOS_SEEN
|
---|
8 |
|
---|
9 | #include "objfio.h"
|
---|
10 | #include <iostream>
|
---|
11 | #include <stdio.h>
|
---|
12 | #include "peida.h"
|
---|
13 | #include "tvector.h"
|
---|
14 | #include "ppersist.h"
|
---|
15 | #include "anydataobj.h"
|
---|
16 |
|
---|
17 | namespace SOPHYA {
|
---|
18 |
|
---|
19 | //! 1 dimension histograms
|
---|
20 | class Histo : public AnyDataObj {
|
---|
21 | friend class ObjFileIO<Histo>;
|
---|
22 | public:
|
---|
23 |
|
---|
24 | // CREATOR / DESTRUCTOR
|
---|
25 | Histo();
|
---|
26 | Histo(r_8 xMin, r_8 xMax, int_4 nBin=100);
|
---|
27 | Histo(r_4 xMin, r_4 xMax, int_4 nBin=100);
|
---|
28 | Histo(const Histo& H);
|
---|
29 | virtual ~Histo();
|
---|
30 |
|
---|
31 | // OPTIONS
|
---|
32 | void Errors();
|
---|
33 |
|
---|
34 | // UPDATING or SETTING
|
---|
35 | void Zero();
|
---|
36 | void Add(r_8 x, r_8 w = 1.);
|
---|
37 | void AddBin(int_4 numBin, r_8 w = 1.);
|
---|
38 | void SetBin(r_8 x, r_8 w = 1.);
|
---|
39 | void SetBin(int_4 numBin, r_8 w = 1.);
|
---|
40 | void SetErr2(r_8 x, r_8 e2);
|
---|
41 | void SetErr2(int_4 numBin, r_8 e2);
|
---|
42 | void SetErr(r_8 x, r_8 e);
|
---|
43 | void SetErr(int_4 numBin, r_8 e);
|
---|
44 | virtual void UpdateHisto(bool force=false) const;
|
---|
45 |
|
---|
46 | // Operators
|
---|
47 | Histo& operator = (const Histo& h);
|
---|
48 | Histo& operator *= (r_8 b);
|
---|
49 | Histo& operator /= (r_8 b);
|
---|
50 | Histo& operator += (r_8 b);
|
---|
51 | Histo& operator -= (r_8 b);
|
---|
52 | Histo& operator += (const Histo& a);
|
---|
53 | Histo& operator -= (const Histo& a);
|
---|
54 | Histo& operator *= (const Histo& a);
|
---|
55 | Histo& operator /= (const Histo& a);
|
---|
56 |
|
---|
57 | // get/put dans/depuis un vector
|
---|
58 | void GetAbsc(TVector<r_8>& v) const;
|
---|
59 | void GetValue(TVector<r_8>& v) const;
|
---|
60 | void GetError2(TVector<r_8>& v) const;
|
---|
61 | void GetError(TVector<r_8>& v) const;
|
---|
62 | void PutValue(TVector<r_8>& v, int_4 ierr=0);
|
---|
63 | void PutValueAdd(TVector<r_8> &v, int_4 ierr=0);
|
---|
64 | void PutError2(TVector<r_8>& v);
|
---|
65 | void PutError2Add(TVector<r_8>& v);
|
---|
66 | void PutError(TVector<r_8>& v);
|
---|
67 |
|
---|
68 | // INLINES
|
---|
69 | //! Retourne l'abscisse minimum
|
---|
70 | inline r_8 XMin() const {return mMin;}
|
---|
71 | //! Retourne l'abscisse maximum
|
---|
72 | inline r_8 XMax() const {return mMax;}
|
---|
73 | //! Retourne le nombre de bins
|
---|
74 | inline int_4 NBins() const {return mBins;}
|
---|
75 | //! Retourne la largeur du bin
|
---|
76 | inline r_8 BinWidth() const {return binWidth;}
|
---|
77 | //! Retourne le pointeur sur le tableaux des contenus
|
---|
78 | inline r_8* Bins() const {return mData;}
|
---|
79 | //! Retourne le contenu du bin i
|
---|
80 | inline r_8 operator()(int_4 i) const {return mData[i];}
|
---|
81 | //! Remplit le contenu du bin i
|
---|
82 | inline r_8& operator()(int_4 i) {return mData[i];}
|
---|
83 | //! retourne "true" si il y a des erreurs stoquees
|
---|
84 | inline bool HasErrors() const
|
---|
85 | {if(mErr2) return true; else return false;}
|
---|
86 | //! Retourne l'erreur du bin i
|
---|
87 | inline r_8 Error(int_4 i) const
|
---|
88 | {if(mErr2) {if(mErr2[i]>0.) return sqrt(mErr2[i]); else return 0.;}
|
---|
89 | else return 0.;}
|
---|
90 | //! Retourne l'erreur au carre du bin i
|
---|
91 | inline r_8 Error2(int_4 i) const
|
---|
92 | {if(mErr2) return mErr2[i]; else return 0.;}
|
---|
93 | //! Remplit l'erreur au carre du bin i
|
---|
94 | inline r_8& Error2(int_4 i) {return mErr2[i];}
|
---|
95 | //! Retourne la somme ponderee
|
---|
96 | inline r_8 NData() const {return nHist;}
|
---|
97 | //! Retourne le nombre d'entrees
|
---|
98 | inline uint_8 NEntries() const {return nEntries;}
|
---|
99 | //! Retourne le nombre d'overflow
|
---|
100 | inline r_8 NOver() const {return mOver;}
|
---|
101 | //! Retourne le nombre d'underflow
|
---|
102 | inline r_8 NUnder() const {return mUnder;}
|
---|
103 |
|
---|
104 | //! Retourne l'abscisse du bord inferieur du bin i
|
---|
105 | inline r_8 BinLowEdge(int_4 i) const {return mMin + i*binWidth;}
|
---|
106 | //! Retourne l'abscisse du centre du bin i
|
---|
107 | inline r_8 BinCenter(int_4 i) const {return mMin + (i+0.5)*binWidth;}
|
---|
108 | //! Retourne l'abscisse du bord superieur du bin i
|
---|
109 | inline r_8 BinHighEdge(int_4 i) const {return mMin + (i+1)*binWidth;}
|
---|
110 | //! Retourne le numero du bin contenant l'abscisse x
|
---|
111 | inline int_4 FindBin(r_8 x) const
|
---|
112 | {return (int_4) floor((x - mMin) / binWidth);}
|
---|
113 |
|
---|
114 | // Info, statistique et calculs sur les histogrammes
|
---|
115 | int_4 BinNonNul() const;
|
---|
116 | int_4 ErrNonNul() const;
|
---|
117 | int_4 IMax() const;
|
---|
118 | int_4 IMin() const;
|
---|
119 | r_8 VMax() const;
|
---|
120 | r_8 VMin() const;
|
---|
121 | r_8 Mean() const;
|
---|
122 | r_8 Sigma() const;
|
---|
123 | r_8 MeanLH(int_4 il,int_4 ih) const;
|
---|
124 | r_8 SigmaLH(int_4 il,int_4 ih) const;
|
---|
125 | r_8 Mean(r_8 x0, r_8 dx) const;
|
---|
126 | r_8 Sigma(r_8 x0, r_8 dx) const;
|
---|
127 | r_8 CleanedMean() const;
|
---|
128 | r_8 CleanedMean(r_8& sigma) const;
|
---|
129 | int_4 BinPercent(r_8 per) const;
|
---|
130 | int_4 BinPercent(r_8 x,r_8 per,int_4& imin,int_4& imax) const;
|
---|
131 | int_4 BinPercent(r_8 x,r_8 per,r_8& xmin,r_8& xmax) const;
|
---|
132 | void HInteg(r_8 norm = 0.);
|
---|
133 | void HDeriv();
|
---|
134 | virtual void HRebin(int_4 nbinew);
|
---|
135 |
|
---|
136 | int_4 MaxiLocal(r_8& maxi,int_4& imax,r_8& maxn,int_4& imaxn) const;
|
---|
137 | r_8 FitMax(int_4 degree=2, r_8 frac=0.5f, int_4 debug=0) const;
|
---|
138 | r_8 FindWidth(r_8 xmax,r_8 frac=0.5f, int_4 debug=0) const;
|
---|
139 | r_8 FindWidth(r_8 frac=0.5f, int_4 debug=0) const;
|
---|
140 | int_4 EstimeMax(r_8& xm,int_4 SzPav = 3) const;
|
---|
141 | int_4 EstimeMax(int_4& im,r_8& xm,int_4 SzPav = 3) const;
|
---|
142 | void EstimeWidthS(r_8 frac,r_8& widthG,r_8& widthD) const;
|
---|
143 |
|
---|
144 | // Print et Display ASCII
|
---|
145 | virtual void Show(ostream& os) const;
|
---|
146 | inline void Show() const { Show(cout); }
|
---|
147 | void Print(int_4 dyn = 100, r_8 hmin = 1., r_8 hmax = -1.,
|
---|
148 | int_4 pflag = 0, int_4 il = 1, int_4 ih = -1) const;
|
---|
149 |
|
---|
150 | protected:
|
---|
151 | void Delete();
|
---|
152 |
|
---|
153 | r_8* mData; //!< donnees
|
---|
154 | r_8* mErr2; //!< erreurs carrees
|
---|
155 | r_8 mUnder; //!< underflow
|
---|
156 | r_8 mOver; //!< overflow
|
---|
157 | r_8 nHist; //!< somme ponderee des entrees
|
---|
158 | uint_8 nEntries; //!< nombre d'entrees
|
---|
159 | int_4 mBins; //!< nombre de bins
|
---|
160 | r_8 mMin; //!< abscisse minimum
|
---|
161 | r_8 mMax; //!< abscisse maximum
|
---|
162 | r_8 binWidth; //!< largeur du bin
|
---|
163 | };
|
---|
164 |
|
---|
165 | /*! Prints histogram information on stream \b s (h.Show(s)) */
|
---|
166 | inline ostream& operator << (ostream& s, Histo const & h)
|
---|
167 | { h.Show(s); return(s); }
|
---|
168 |
|
---|
169 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo)
|
---|
170 | \brief Persistance management */
|
---|
171 | inline POutPersist& operator << (POutPersist& os, Histo & obj)
|
---|
172 | { ObjFileIO<Histo> fio(&obj); fio.Write(os); return(os); }
|
---|
173 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo)
|
---|
174 | \brief Persistance management */
|
---|
175 | inline PInPersist& operator >> (PInPersist& is, Histo & obj)
|
---|
176 | { ObjFileIO<Histo> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
177 |
|
---|
178 | // Classe pour la gestion de persistance
|
---|
179 | // ObjFileIO<Histo>
|
---|
180 |
|
---|
181 | /*! \ingroup HiStats \fn operator*(const Histo&,r_8)
|
---|
182 | \brief Operateur H2 = H1 * b */
|
---|
183 | inline Histo operator * (const Histo& a, r_8 b)
|
---|
184 | {
|
---|
185 | Histo result(a);
|
---|
186 | return (result *= b);
|
---|
187 | }
|
---|
188 |
|
---|
189 | /*! \ingroup HiStats \fn operator*(r_8,const Histo&)
|
---|
190 | \brief Operateur H2 = b * H1 */
|
---|
191 | inline Histo operator * (r_8 b, const Histo& a)
|
---|
192 | {
|
---|
193 | Histo result(a);
|
---|
194 | return (result *= b);
|
---|
195 | }
|
---|
196 |
|
---|
197 | /*! \ingroup HiStats \fn operator/(const Histo&,r_8)
|
---|
198 | \brief Operateur H2 = H1 / b */
|
---|
199 | inline Histo operator / (const Histo& a, r_8 b)
|
---|
200 | {
|
---|
201 | Histo result(a);
|
---|
202 | return (result /= b);
|
---|
203 | }
|
---|
204 |
|
---|
205 | /*! \ingroup HiStats \fn operator+(const Histo&,r_8)
|
---|
206 | \brief Operateur H2 = H1 + b */
|
---|
207 | inline Histo operator + (const Histo& a, r_8 b)
|
---|
208 | {
|
---|
209 | Histo result(a);
|
---|
210 | return (result += b);
|
---|
211 | }
|
---|
212 |
|
---|
213 | /*! \ingroup HiStats \fn operator+(r_8,const Histo&)
|
---|
214 | \brief Operateur H2 = b + H1 */
|
---|
215 | inline Histo operator + (r_8 b, const Histo& a)
|
---|
216 | {
|
---|
217 | Histo result(a);
|
---|
218 | return (result += b);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /*! \ingroup HiStats \fn operator-(const Histo&,r_8)
|
---|
222 | \brief Operateur H2 = H1 - b */
|
---|
223 | inline Histo operator - (const Histo& a, r_8 b)
|
---|
224 | {
|
---|
225 | Histo result(a);
|
---|
226 | return (result -= b);
|
---|
227 | }
|
---|
228 |
|
---|
229 | /*! \ingroup HiStats \fn operator-(r_8,const Histo&)
|
---|
230 | \brief Operateur H2 = b - H1 */
|
---|
231 | inline Histo operator - (r_8 b, const Histo& a)
|
---|
232 | {
|
---|
233 | Histo result(a);
|
---|
234 | result *= -1.;
|
---|
235 | return (result += b);
|
---|
236 | }
|
---|
237 |
|
---|
238 | /*! \ingroup HiStats \fn operator+(const Histo&,const Histo&)
|
---|
239 | \brief Operateur H = H1 + H2 */
|
---|
240 | inline Histo operator + (const Histo& a, const Histo& b)
|
---|
241 | {
|
---|
242 | if (b.NBins()!=a.NBins()) throw SzMismatchError(PExcLongMessage(""));
|
---|
243 | Histo c(a);
|
---|
244 | return (c += b);
|
---|
245 | }
|
---|
246 |
|
---|
247 | /*! \ingroup HiStats \fn operator-(const Histo&,const Histo&)
|
---|
248 | \brief Operateur H = H1 - H2 */
|
---|
249 | inline Histo operator - (const Histo& a, const Histo& b)
|
---|
250 | {
|
---|
251 | if (b.NBins()!=a.NBins()) throw SzMismatchError(PExcLongMessage(""));
|
---|
252 | Histo c(a);
|
---|
253 | return (c -= b);
|
---|
254 | }
|
---|
255 |
|
---|
256 | /*! \ingroup HiStats \fn operator*(const Histo&,const Histo&)
|
---|
257 | \brief Operateur H = H1 * H2 */
|
---|
258 | inline Histo operator * (const Histo& a, const Histo& b)
|
---|
259 | {
|
---|
260 | if (b.NBins()!=a.NBins()) throw SzMismatchError(PExcLongMessage(""));
|
---|
261 | Histo c(a);
|
---|
262 | return (c *= b);
|
---|
263 | }
|
---|
264 |
|
---|
265 | /*! \ingroup HiStats \fn operator/(const Histo&,const Histo&)
|
---|
266 | \brief Operateur H = H1 / H2 */
|
---|
267 | inline Histo operator / (const Histo& a, const Histo& b)
|
---|
268 | {
|
---|
269 | if (b.NBins()!=a.NBins()) throw SzMismatchError(PExcLongMessage(""));
|
---|
270 | Histo c(a);
|
---|
271 | return (c /= b);
|
---|
272 | }
|
---|
273 |
|
---|
274 | } // Fin du namespace
|
---|
275 |
|
---|
276 | #endif // HISTOS_SEEN
|
---|