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