1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | //
|
---|
3 | // $Id: histos.h,v 1.12 2000-07-28 16:29:55 ansari Exp $
|
---|
4 | //
|
---|
5 |
|
---|
6 | #ifndef HISTOS_SEEN
|
---|
7 | #define HISTOS_SEEN
|
---|
8 |
|
---|
9 | #include "objfio.h"
|
---|
10 | #include <iostream.h>
|
---|
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 inline void UpdateHisto() const { return;}
|
---|
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 r_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 | void PrintF(FILE * fp, int_4 dyn = 100, r_8 hmin = 1., r_8 hmax = -1.,
|
---|
146 | int_4 pflag = 0, int_4 il = 1, int_4 ih = -1) const;
|
---|
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 | int_4 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 |
|
---|
166 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo)
|
---|
167 | \brief Persistance management */
|
---|
168 | inline POutPersist& operator << (POutPersist& os, Histo & obj)
|
---|
169 | { ObjFileIO<Histo> fio(&obj); fio.Write(os); return(os); }
|
---|
170 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo)
|
---|
171 | \brief Persistance management */
|
---|
172 | inline PInPersist& operator >> (PInPersist& is, Histo & obj)
|
---|
173 | { ObjFileIO<Histo> fio(&obj); fio.Read(is); return(is); }
|
---|
174 |
|
---|
175 | // Classe pour la gestion de persistance
|
---|
176 | // ObjFileIO<Histo>
|
---|
177 |
|
---|
178 | /*! \ingroup HiStats \fn operator*(const Histo&,r_8)
|
---|
179 | \brief Operateur H2 = H1 * b */
|
---|
180 | inline Histo operator * (const Histo& a, r_8 b)
|
---|
181 | {
|
---|
182 | Histo result(a);
|
---|
183 | return (result *= b);
|
---|
184 | }
|
---|
185 |
|
---|
186 | /*! \ingroup HiStats \fn operator*(r_8,const Histo&)
|
---|
187 | \brief Operateur H2 = b * H1 */
|
---|
188 | inline Histo operator * (r_8 b, const Histo& a)
|
---|
189 | {
|
---|
190 | Histo result(a);
|
---|
191 | return (result *= b);
|
---|
192 | }
|
---|
193 |
|
---|
194 | /*! \ingroup HiStats \fn operator/(const Histo&,r_8)
|
---|
195 | \brief Operateur H2 = H1 / b */
|
---|
196 | inline Histo operator / (const Histo& a, r_8 b)
|
---|
197 | {
|
---|
198 | Histo result(a);
|
---|
199 | return (result /= b);
|
---|
200 | }
|
---|
201 |
|
---|
202 | /*! \ingroup HiStats \fn operator+(const Histo&,r_8)
|
---|
203 | \brief Operateur H2 = H1 + b */
|
---|
204 | inline Histo operator + (const Histo& a, r_8 b)
|
---|
205 | {
|
---|
206 | Histo result(a);
|
---|
207 | return (result += b);
|
---|
208 | }
|
---|
209 |
|
---|
210 | /*! \ingroup HiStats \fn operator+(r_8,const Histo&)
|
---|
211 | \brief Operateur H2 = b + H1 */
|
---|
212 | inline Histo operator + (r_8 b, const Histo& a)
|
---|
213 | {
|
---|
214 | Histo result(a);
|
---|
215 | return (result += b);
|
---|
216 | }
|
---|
217 |
|
---|
218 | /*! \ingroup HiStats \fn operator-(const Histo&,r_8)
|
---|
219 | \brief Operateur H2 = H1 - b */
|
---|
220 | inline Histo operator - (const Histo& a, r_8 b)
|
---|
221 | {
|
---|
222 | Histo result(a);
|
---|
223 | return (result -= b);
|
---|
224 | }
|
---|
225 |
|
---|
226 | /*! \ingroup HiStats \fn operator-(r_8,const Histo&)
|
---|
227 | \brief Operateur H2 = b - H1 */
|
---|
228 | inline Histo operator - (r_8 b, const Histo& a)
|
---|
229 | {
|
---|
230 | Histo result(a);
|
---|
231 | result *= -1.;
|
---|
232 | return (result += b);
|
---|
233 | }
|
---|
234 |
|
---|
235 | /*! \ingroup HiStats \fn operator+(const Histo&,const Histo&)
|
---|
236 | \brief Operateur H = H1 + H2 */
|
---|
237 | inline Histo operator + (const Histo& a, const Histo& b)
|
---|
238 | {
|
---|
239 | if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
|
---|
240 | Histo c(a);
|
---|
241 | return (c += b);
|
---|
242 | }
|
---|
243 |
|
---|
244 | /*! \ingroup HiStats \fn operator-(const Histo&,const Histo&)
|
---|
245 | \brief Operateur H = H1 - H2 */
|
---|
246 | inline Histo operator - (const Histo& a, const Histo& b)
|
---|
247 | {
|
---|
248 | if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
|
---|
249 | Histo c(a);
|
---|
250 | return (c -= b);
|
---|
251 | }
|
---|
252 |
|
---|
253 | /*! \ingroup HiStats \fn operator*(const Histo&,const Histo&)
|
---|
254 | \brief Operateur H = H1 * H2 */
|
---|
255 | inline Histo operator * (const Histo& a, const Histo& b)
|
---|
256 | {
|
---|
257 | if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
|
---|
258 | Histo c(a);
|
---|
259 | return (c *= b);
|
---|
260 | }
|
---|
261 |
|
---|
262 | /*! \ingroup HiStats \fn operator/(const Histo&,const Histo&)
|
---|
263 | \brief Operateur H = H1 / H2 */
|
---|
264 | inline Histo operator / (const Histo& a, const Histo& b)
|
---|
265 | {
|
---|
266 | if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
|
---|
267 | Histo c(a);
|
---|
268 | return (c /= b);
|
---|
269 | }
|
---|
270 |
|
---|
271 | } // Fin du namespace
|
---|
272 |
|
---|
273 | #endif // HISTOS_SEEN
|
---|