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