1 | //
|
---|
2 | // histogrammes 2D cmv 2/8/96
|
---|
3 | //
|
---|
4 |
|
---|
5 | #ifndef HISTOS2_SEEN
|
---|
6 | #define HISTOS2_SEEN
|
---|
7 |
|
---|
8 | #include "machdefs.h"
|
---|
9 | #include <string>
|
---|
10 |
|
---|
11 | #include <list>
|
---|
12 | #if defined(__KCC__)
|
---|
13 | #include <list.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include "peida.h"
|
---|
17 | #include "utils.h"
|
---|
18 | #include "histos.h"
|
---|
19 |
|
---|
20 | namespace SOPHYA {
|
---|
21 |
|
---|
22 | //! 2 dimensions histograms
|
---|
23 | class Histo2D : public AnyDataObj {
|
---|
24 | friend class ObjFileIO<Histo2D>;
|
---|
25 | public:
|
---|
26 |
|
---|
27 | // CREATOR / DESTRUCTOR
|
---|
28 | Histo2D(r_8 xMin,r_8 xMax,int_4 nxBin,r_8 yMin,r_8 yMax,int_4 nyBin);
|
---|
29 | Histo2D(r_4 xMin,r_4 xMax,int_4 nxBin,r_4 yMin,r_4 yMax,int_4 nyBin);
|
---|
30 | Histo2D(const Histo2D& h);
|
---|
31 | Histo2D();
|
---|
32 | virtual ~Histo2D();
|
---|
33 |
|
---|
34 | // OPTIONS
|
---|
35 | void Errors();
|
---|
36 |
|
---|
37 | // UPDATING
|
---|
38 | void Zero();
|
---|
39 | void Add(r_8 x, r_8 y, r_8 w = 1.);
|
---|
40 |
|
---|
41 | // Operators
|
---|
42 | Histo2D& operator = (const Histo2D& h);
|
---|
43 | Histo2D& operator *= (r_8 b);
|
---|
44 | Histo2D& operator /= (r_8 b);
|
---|
45 | Histo2D& operator += (r_8 b);
|
---|
46 | Histo2D& operator -= (r_8 b);
|
---|
47 | Histo2D& operator += (const Histo2D& a);
|
---|
48 | Histo2D& operator -= (const Histo2D& a);
|
---|
49 | Histo2D& operator *= (const Histo2D& a);
|
---|
50 | Histo2D& operator /= (const Histo2D& a);
|
---|
51 |
|
---|
52 | // get/put dans/depuis une matrice / vector
|
---|
53 | void GetXCoor(TVector<r_8>& v) const;
|
---|
54 | void GetValue(TMatrix<r_8> &v) const;
|
---|
55 | void GetYCoor(TVector<r_8>& v) const;
|
---|
56 | void GetError2(TMatrix<r_8>& v) const;
|
---|
57 | void GetError(TMatrix<r_8>& v) const;
|
---|
58 | void PutValue(TMatrix<r_8>& v, int_4 ierr=0);
|
---|
59 | void PutValueAdd(TMatrix<r_8>& v, int_4 ierr=0);
|
---|
60 | void PutError2(TMatrix<r_8>& v);
|
---|
61 | void PutError2Add(TMatrix<r_8>& v);
|
---|
62 | void PutError(TMatrix<r_8>& v);
|
---|
63 |
|
---|
64 | // INLINES
|
---|
65 | //! Retourne l'abscisse minimum.
|
---|
66 | inline r_8 XMin() const {return mXmin;}
|
---|
67 | //! Retourne l'abscisse maximum.
|
---|
68 | inline r_8 XMax() const {return mXmax;}
|
---|
69 | //! Retourne l'ordonnee minimum.
|
---|
70 | inline r_8 YMin() const {return mYmin;}
|
---|
71 | //! Retourne l'ordonnee maximum.
|
---|
72 | inline r_8 YMax() const {return mYmax;}
|
---|
73 | //! Retourne le nombre de bins selon X.
|
---|
74 | inline int_4 NBinX() const {return mNx;}
|
---|
75 | //! Retourne le nombre de bins selon Y.
|
---|
76 | inline int_4 NBinY() const {return mNy;}
|
---|
77 | //! Retourne la largeur du bin selon X.
|
---|
78 | inline r_8 WBinX() const {return mWBinx;}
|
---|
79 | //! Retourne la largeur du bin selon Y.
|
---|
80 | inline r_8 WBinY() const {return mWBiny;}
|
---|
81 | //! Retourne le pointeur sur le tableaux des contenus.
|
---|
82 | inline r_8* Bins() const {return mData;}
|
---|
83 | //! Retourne le contenu du bin i,j.
|
---|
84 | inline r_8 operator()(int_4 i,int_4 j) const {return mData[j*mNx+i];}
|
---|
85 | //! Remplit le contenu du bin i,j.
|
---|
86 | inline r_8& operator()(int_4 i,int_4 j) {return mData[j*mNx+i];}
|
---|
87 | //! retourne "true" si il y a des erreurs stoquees
|
---|
88 | inline bool HasErrors() const { if(mErr2) return true; else return false;}
|
---|
89 | //! Retourne l'erreur du bin i,j.
|
---|
90 | inline r_8 Error(int_4 i,int_4 j) const
|
---|
91 | {if(mErr2)
|
---|
92 | {if(mErr2[j*mNx+i]>0.) return sqrt(mErr2[j*mNx+i]); else return 0.;}
|
---|
93 | else return 0.;}
|
---|
94 | //! Remplit l'erreur au carre du bin i,j.
|
---|
95 | inline r_8 Error2(int_4 i,int_4 j) const
|
---|
96 | {if(mErr2) return mErr2[j*mNx+i]; else return 0.;}
|
---|
97 | //! Remplit l'erreur au carre du bin i,j.
|
---|
98 | inline r_8& Error2(int_4 i,int_4 j) {return mErr2[j*mNx+i];}
|
---|
99 | //! Retourne la somme ponderee.
|
---|
100 | inline r_8 NData() const {return nHist;}
|
---|
101 | //! Retourne le nombre d'entrees.
|
---|
102 | inline int_4 NEntries() const {return nEntries;}
|
---|
103 | //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i,j.
|
---|
104 | inline void BinLowEdge(int_4 i,int_4 j,r_8& x,r_8& y) const
|
---|
105 | {x = mXmin + i*mWBinx; y = mYmin + j*mWBiny;}
|
---|
106 | //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i,j.
|
---|
107 | inline void BinLowEdge(int_4 i,int_4 j,r_4& xf,r_4& yf) const
|
---|
108 | {r_8 x,y; BinLowEdge(i,j,x,y); xf=x; yf=y;}
|
---|
109 | //! Retourne l'abscisse et l'ordonnee du centre du bin i,j.
|
---|
110 | inline void BinCenter(int_4 i,int_4 j,r_8& x,r_8& y) const
|
---|
111 | {x = mXmin + (i+0.5)*mWBinx; y = mYmin + (j+0.5)*mWBiny;}
|
---|
112 | //! Retourne l'abscisse et l'ordonnee du centre du bin i,j.
|
---|
113 | inline void BinCenter(int_4 i,int_4 j,r_4& xf,r_4& yf) const
|
---|
114 | {r_8 x,y; BinCenter(i,j,x,y); xf=x; yf=y;}
|
---|
115 | //! Retourne l'abscisse et l'ordonnee du coin superieur du bin i,j.
|
---|
116 | inline void BinHighEdge(int_4 i,int_4 j,r_8& x,r_8& y) const
|
---|
117 | {x = mXmin + (i+1)*mWBinx; y = mYmin + (j+1)*mWBiny;}
|
---|
118 | //! Retourne l'abscisse et l'ordonnee du coin superieur du bin i,j.
|
---|
119 | inline void BinHighEdge(int_4 i,int_4 j,r_4& xf,r_4& yf) const
|
---|
120 | {r_8 x,y; BinHighEdge(i,j,x,y); xf=x; yf=y;}
|
---|
121 | //! Retourne les numeros du bin contenant l'abscisse et l'ordonnee x,y.
|
---|
122 | inline void FindBin(r_8 x,r_8 y,int_4& i,int_4& j) const
|
---|
123 | {i=(int_4) floor((x-mXmin)/mWBinx); j=(int_4) floor((y-mYmin)/mWBiny);}
|
---|
124 |
|
---|
125 | // Info, statistique et calculs sur les histogrammes
|
---|
126 | r_8 NOver(int_4 i=-1,int_4 j=-1) const;
|
---|
127 | int_4 BinNonNul() const;
|
---|
128 | int_4 ErrNonNul() const;
|
---|
129 | void IJMax(int_4& imax,int_4& jmax,int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
|
---|
130 | void IJMin(int_4& imax,int_4& jmax,int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
|
---|
131 | r_8 VMax(int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
|
---|
132 | r_8 VMin(int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
|
---|
133 | int_4 EstimeMax(r_8& xm,r_8& ym,int_4 SzPav = 3
|
---|
134 | ,int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
|
---|
135 | int_4 EstimeMax(int_4 im,int_4 jm,r_8& xm,r_8& ym,int_4 SzPav = 3) const;
|
---|
136 | int_4 FindMax(int_4& im,int_4& jm,int_4 SzPav = 3,r_8 Dz = 0.
|
---|
137 | ,int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
|
---|
138 |
|
---|
139 | // Print et Display ASCII
|
---|
140 | virtual void Show(ostream& os) const;
|
---|
141 | inline void PrintStatus() const { Show(cout); }
|
---|
142 |
|
---|
143 | void Print(r_8 min=1.,r_8 max=-1.
|
---|
144 | ,int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
|
---|
145 |
|
---|
146 | // PROJECTIONS
|
---|
147 | void SetProjX();
|
---|
148 | void SetProjY();
|
---|
149 | void SetProj();
|
---|
150 | void DelProjX();
|
---|
151 | void DelProjY();
|
---|
152 | void DelProj();
|
---|
153 | void ZeroProjX();
|
---|
154 | void ZeroProjY();
|
---|
155 | void ZeroProj();
|
---|
156 | //! Retourne le pointeur sur l'histo 1D de la projection selon X.
|
---|
157 | inline Histo* HProjX() const {return mHprojx;}
|
---|
158 | //! Retourne le pointeur sur l'histo 1D de la projection selon Y.
|
---|
159 | inline Histo* HProjY() const {return mHprojy;}
|
---|
160 | void ShowProj() const;
|
---|
161 |
|
---|
162 | // BANDES
|
---|
163 | //! Retourne le nombre de bandes selon X
|
---|
164 | inline int_4 NBandX() const {return mLBandx.size();}
|
---|
165 | //! Retourne le nombre de bandes selon Y
|
---|
166 | inline int_4 NBandY() const {return mLBandy.size();}
|
---|
167 | int_4 SetBandX(r_8 ybmin,r_8 ybmax);
|
---|
168 | int_4 SetBandY(r_8 xbmin,r_8 xbmax);
|
---|
169 | void DelBandX();
|
---|
170 | void DelBandY();
|
---|
171 | void ZeroBandX();
|
---|
172 | void ZeroBandY();
|
---|
173 | Histo* HBandX(int_4 n) const;
|
---|
174 | Histo* HBandY(int_4 n) const;
|
---|
175 | void GetBandX(int_4 n,r_8& ybmin,r_8& ybmax) const;
|
---|
176 | void GetBandY(int_4 n,r_8& xbmin,r_8& xbmax) const;
|
---|
177 | void ShowBand(int_4 lp = 0) const;
|
---|
178 |
|
---|
179 | // SLICES
|
---|
180 | //! Retourne le nombre de slices selon X
|
---|
181 | inline int_4 NSliX() const {return mLSlix.size();}
|
---|
182 | //! Retourne le nombre de slices selon Y
|
---|
183 | inline int_4 NSliY() const {return mLSliy.size();}
|
---|
184 | int_4 SetSliX(int_4 nsli);
|
---|
185 | int_4 SetSliY(int_4 nsli);
|
---|
186 | void DelSliX();
|
---|
187 | void DelSliY();
|
---|
188 | void ZeroSliX();
|
---|
189 | void ZeroSliY();
|
---|
190 | Histo* HSliX(int_4 n) const;
|
---|
191 | Histo* HSliY(int_4 n) const;
|
---|
192 | void ShowSli(int_4 lp = 0) const;
|
---|
193 |
|
---|
194 | #ifndef __DECCXX
|
---|
195 | protected:
|
---|
196 | #endif
|
---|
197 | //! structure de definition des bandes
|
---|
198 | struct bande_slice {
|
---|
199 | int_4 num; //!< nombre de bandes
|
---|
200 | r_8 min; //!< limite minimum pour remplir la bande
|
---|
201 | r_8 max; //!< limite maximum pour remplir la bande
|
---|
202 | Histo* H; //!< pointer sur l Histo 1D de la bande
|
---|
203 | STRUCTCOMP(bande_slice)
|
---|
204 | };
|
---|
205 | #ifdef __DECCXX
|
---|
206 | protected:
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | void Delete();
|
---|
210 |
|
---|
211 | r_8* mData; //!< donnees
|
---|
212 | r_8* mErr2; //!< erreurs carrees
|
---|
213 |
|
---|
214 | r_8 mOver[3][3]; //!< overflow table
|
---|
215 | r_8 nHist; //!< somme ponderee des entrees
|
---|
216 | int_4 nEntries; //!< nombre d'entrees
|
---|
217 |
|
---|
218 | int_4 mNx; //!< nombre de bins en X
|
---|
219 | int_4 mNy; //!< nombre de bins en Y
|
---|
220 | int_4 mNxy; //!< nombre de bins total
|
---|
221 | r_8 mXmin; //!< abscisse minimum
|
---|
222 | r_8 mXmax; //!< abscisse maximum
|
---|
223 | r_8 mYmin; //!< ordonnee minimum
|
---|
224 | r_8 mYmax; //!< ordonnee maximum
|
---|
225 | r_8 mWBinx; //!< largeur du bin en X
|
---|
226 | r_8 mWBiny; //!< largeur du bin en Y
|
---|
227 |
|
---|
228 | bande_slice mB_s;
|
---|
229 |
|
---|
230 | Histo* mHprojx; //!< pointer sur Histo des proj X
|
---|
231 | Histo* mHprojy; //!< pointer sur Histo des proj Y
|
---|
232 |
|
---|
233 | list<bande_slice> mLBandx; //!< liste des bandes selon X
|
---|
234 | list<bande_slice> mLBandy; //!< liste des bandes selon Y
|
---|
235 |
|
---|
236 | list<bande_slice> mLSlix; //!< liste des slices selon X
|
---|
237 | list<bande_slice> mLSliy; //!< liste des slices selon Y
|
---|
238 |
|
---|
239 | };
|
---|
240 |
|
---|
241 | /*! Prints histogram information on stream \b s (h.Show(s)) */
|
---|
242 | inline ostream& operator << (ostream& s, Histo2D const & h)
|
---|
243 | { h.Show(s); return(s); }
|
---|
244 |
|
---|
245 | /////////////////////////////////////////////////////////////////////////
|
---|
246 | // Classe pour la gestion de persistance
|
---|
247 |
|
---|
248 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo2D)
|
---|
249 | \brief Persistance management */
|
---|
250 | inline POutPersist& operator << (POutPersist& os, Histo2D & obj)
|
---|
251 | { ObjFileIO<Histo2D> fio(&obj); fio.Write(os); return(os); }
|
---|
252 | /*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo2D)
|
---|
253 | \brief Persistance management */
|
---|
254 | inline PInPersist& operator >> (PInPersist& is, Histo2D & obj)
|
---|
255 | { ObjFileIO<Histo2D> fio(&obj); fio.Read(is); return(is); }
|
---|
256 |
|
---|
257 | // Classe pour la gestion de persistance
|
---|
258 | // ObjFileIO<Histo2D>
|
---|
259 |
|
---|
260 | /*! \ingroup HiStats \fn operator*(const Histo2D&,r_8)
|
---|
261 | \brief Operateur H2 = H1 * b */
|
---|
262 | inline Histo2D operator * (const Histo2D& a, r_8 b)
|
---|
263 | {
|
---|
264 | Histo2D result(a);
|
---|
265 | return (result *= b);
|
---|
266 | }
|
---|
267 |
|
---|
268 | /*! \ingroup HiStats \fn operator*(r_8,const Histo2D&)
|
---|
269 | \brief Operateur H2 = b * H1 */
|
---|
270 | inline Histo2D operator * (r_8 b, const Histo2D& a)
|
---|
271 | {
|
---|
272 | Histo2D result(a);
|
---|
273 | return (result *= b);
|
---|
274 | }
|
---|
275 |
|
---|
276 | /*! \ingroup HiStats \fn operator/(const Histo2D&,r_8)
|
---|
277 | \brief Operateur H2 = H1 / b */
|
---|
278 | inline Histo2D operator / (const Histo2D& a, r_8 b)
|
---|
279 | {
|
---|
280 | Histo2D result(a);
|
---|
281 | return (result /= b);
|
---|
282 | }
|
---|
283 |
|
---|
284 | /*! \ingroup HiStats \fn operator+(const Histo2D&,r_8)
|
---|
285 | \brief Operateur H2 = H1 + b */
|
---|
286 | inline Histo2D operator + (const Histo2D& a, r_8 b)
|
---|
287 | {
|
---|
288 | Histo2D result(a);
|
---|
289 | return (result += b);
|
---|
290 | }
|
---|
291 |
|
---|
292 | /*! \ingroup HiStats \fn operator+(r_8,const Histo2D&)
|
---|
293 | \brief Operateur H2 = b + H1 */
|
---|
294 | inline Histo2D operator + (r_8 b, const Histo2D& a)
|
---|
295 | {
|
---|
296 | Histo2D result(a);
|
---|
297 | return (result += b);
|
---|
298 | }
|
---|
299 |
|
---|
300 | /*! \ingroup HiStats \fn operator-(const Histo2D&,r_8)
|
---|
301 | \brief Operateur H2 = H1 - b */
|
---|
302 | inline Histo2D operator - (const Histo2D& a, r_8 b)
|
---|
303 | {
|
---|
304 | Histo2D result(a);
|
---|
305 | return (result -= b);
|
---|
306 | }
|
---|
307 |
|
---|
308 | /*! \ingroup HiStats \fn operator-(r_8,const Histo2D&)
|
---|
309 | \brief Operateur H2 = b - H1 */
|
---|
310 | inline Histo2D operator - (r_8 b, const Histo2D& a)
|
---|
311 | {
|
---|
312 | Histo2D result(a);
|
---|
313 | result *= -1.;
|
---|
314 | return (result += b);
|
---|
315 | }
|
---|
316 |
|
---|
317 | /*! \ingroup HiStats \fn operator+(const Histo2D&,const Histo2D&)
|
---|
318 | \brief Operateur H = H1 + H2 */
|
---|
319 |
|
---|
320 | inline Histo2D operator + (const Histo2D& a, const Histo2D& b)
|
---|
321 | {
|
---|
322 | if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
|
---|
323 | Histo2D c(a);
|
---|
324 | return (c += b);
|
---|
325 | }
|
---|
326 |
|
---|
327 | /*! \ingroup HiStats \fn operator-(const Histo2D&,const Histo2D&)
|
---|
328 | \brief Operateur H = H1 - H2 */
|
---|
329 | inline Histo2D operator - (const Histo2D& a, const Histo2D& b)
|
---|
330 | {
|
---|
331 | if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
|
---|
332 | Histo2D c(a);
|
---|
333 | return (c -= b);
|
---|
334 | }
|
---|
335 |
|
---|
336 | /*! \ingroup HiStats \fn operator*(const Histo2D&,const Histo2D&)
|
---|
337 | \brief Operateur H = H1 * H2 */
|
---|
338 | inline Histo2D operator * (const Histo2D& a, const Histo2D& b)
|
---|
339 | {
|
---|
340 | if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
|
---|
341 | Histo2D c(a);
|
---|
342 | return (c *= b);
|
---|
343 | }
|
---|
344 |
|
---|
345 | /*! \ingroup HiStats \fn operator/(const Histo2D&,const Histo2D&)
|
---|
346 | \brief Operateur H = H1 / H2 */
|
---|
347 | inline Histo2D operator / (const Histo2D& a, const Histo2D& b)
|
---|
348 | {
|
---|
349 | if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
|
---|
350 | Histo2D c(a);
|
---|
351 | return (c /= b);
|
---|
352 | }
|
---|
353 |
|
---|
354 | } // Fin du namespace
|
---|
355 |
|
---|
356 | #endif // HISTOS2_SEEN
|
---|