source: Sophya/trunk/SophyaLib/HiStats/histos2.h@ 2195

Last change on this file since 2195 was 1413, checked in by ansari, 25 years ago

Methode Show et operateur << pour Histos - Reza 20/2/2001

File size: 11.5 KB
RevLine 
[763]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
20namespace SOPHYA {
21
[926]22//! 2 dimensions histograms
[763]23class Histo2D : public AnyDataObj {
24 friend class ObjFileIO<Histo2D>;
25public:
26
27 // CREATOR / DESTRUCTOR
[1092]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);
[763]30 Histo2D(const Histo2D& h);
31 Histo2D();
[1092]32 virtual ~Histo2D();
[763]33
34 // OPTIONS
[1092]35 void Errors();
[763]36
37 // UPDATING
[1092]38 void Zero();
39 void Add(r_8 x, r_8 y, r_8 w = 1.);
[763]40
41 // Operators
42 Histo2D& operator = (const Histo2D& h);
[1092]43 Histo2D& operator *= (r_8 b);
44 Histo2D& operator /= (r_8 b);
45 Histo2D& operator += (r_8 b);
46 Histo2D& operator -= (r_8 b);
[763]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
[1109]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;
[1092]58 void PutValue(TMatrix<r_8>& v, int_4 ierr=0);
59 void PutValueAdd(TMatrix<r_8>& v, int_4 ierr=0);
[943]60 void PutError2(TMatrix<r_8>& v);
61 void PutError2Add(TMatrix<r_8>& v);
62 void PutError(TMatrix<r_8>& v);
[763]63
64 // INLINES
[914]65 //! Retourne l'abscisse minimum.
[1092]66 inline r_8 XMin() const {return mXmin;}
[914]67 //! Retourne l'abscisse maximum.
[1092]68 inline r_8 XMax() const {return mXmax;}
[914]69 //! Retourne l'ordonnee minimum.
[1092]70 inline r_8 YMin() const {return mYmin;}
[914]71 //! Retourne l'ordonnee maximum.
[1092]72 inline r_8 YMax() const {return mYmax;}
[914]73 //! Retourne le nombre de bins selon X.
[1092]74 inline int_4 NBinX() const {return mNx;}
[914]75 //! Retourne le nombre de bins selon Y.
[1092]76 inline int_4 NBinY() const {return mNy;}
[914]77 //! Retourne la largeur du bin selon X.
[1092]78 inline r_8 WBinX() const {return mWBinx;}
[914]79 //! Retourne la largeur du bin selon Y.
[1092]80 inline r_8 WBinY() const {return mWBiny;}
[914]81 //! Retourne le pointeur sur le tableaux des contenus.
[1092]82 inline r_8* Bins() const {return mData;}
[914]83 //! Retourne le contenu du bin i,j.
[1092]84 inline r_8 operator()(int_4 i,int_4 j) const {return mData[j*mNx+i];}
[914]85 //! Remplit le contenu du bin i,j.
[1092]86 inline r_8& operator()(int_4 i,int_4 j) {return mData[j*mNx+i];}
[914]87 //! retourne "true" si il y a des erreurs stoquees
[1109]88 inline bool HasErrors() const { if(mErr2) return true; else return false;}
[914]89 //! Retourne l'erreur du bin i,j.
[1092]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.;}
[914]94 //! Remplit l'erreur au carre du bin i,j.
[1092]95 inline r_8 Error2(int_4 i,int_4 j) const
96 {if(mErr2) return mErr2[j*mNx+i]; else return 0.;}
[914]97 //! Remplit l'erreur au carre du bin i,j.
[1092]98 inline r_8& Error2(int_4 i,int_4 j) {return mErr2[j*mNx+i];}
[914]99 //! Retourne la somme ponderee.
[1092]100 inline r_8 NData() const {return nHist;}
[914]101 //! Retourne le nombre d'entrees.
[1092]102 inline int_4 NEntries() const {return nEntries;}
[914]103 //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i,j.
[1109]104 inline void BinLowEdge(int_4 i,int_4 j,r_8& x,r_8& y) const
[1092]105 {x = mXmin + i*mWBinx; y = mYmin + j*mWBiny;}
106 //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i,j.
[1109]107 inline void BinLowEdge(int_4 i,int_4 j,r_4& xf,r_4& yf) const
[1092]108 {r_8 x,y; BinLowEdge(i,j,x,y); xf=x; yf=y;}
[914]109 //! Retourne l'abscisse et l'ordonnee du centre du bin i,j.
[1109]110 inline void BinCenter(int_4 i,int_4 j,r_8& x,r_8& y) const
[1092]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.
[1109]113 inline void BinCenter(int_4 i,int_4 j,r_4& xf,r_4& yf) const
[1092]114 {r_8 x,y; BinCenter(i,j,x,y); xf=x; yf=y;}
[914]115 //! Retourne l'abscisse et l'ordonnee du coin superieur du bin i,j.
[1109]116 inline void BinHighEdge(int_4 i,int_4 j,r_8& x,r_8& y) const
[1092]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.
[1109]119 inline void BinHighEdge(int_4 i,int_4 j,r_4& xf,r_4& yf) const
[1092]120 {r_8 x,y; BinHighEdge(i,j,x,y); xf=x; yf=y;}
[914]121 //! Retourne les numeros du bin contenant l'abscisse et l'ordonnee x,y.
[1109]122 inline void FindBin(r_8 x,r_8 y,int_4& i,int_4& j) const
[1092]123 {i=(int_4) floor((x-mXmin)/mWBinx); j=(int_4) floor((y-mYmin)/mWBiny);}
[763]124
125 // Info, statistique et calculs sur les histogrammes
[1092]126 r_8 NOver(int_4 i=-1,int_4 j=-1) const;
127 int_4 BinNonNul() const;
128 int_4 ErrNonNul() const;
[1109]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;
[1092]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
[1109]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;
[1092]136 int_4 FindMax(int_4& im,int_4& jm,int_4 SzPav = 3,r_8 Dz = 0.
[1109]137 ,int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
[763]138
139 // Print et Display ASCII
[1413]140 virtual void Show(ostream& os) const;
141 inline void PrintStatus() const { Show(cout); }
142
[1092]143 void Print(r_8 min=1.,r_8 max=-1.
[1109]144 ,int_4 il=1,int_4 ih= -1,int_4 jl=1,int_4 jh= -1) const;
[763]145
146 // PROJECTIONS
[1092]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();
[914]156 //! Retourne le pointeur sur l'histo 1D de la projection selon X.
[1092]157 inline Histo* HProjX() const {return mHprojx;}
[914]158 //! Retourne le pointeur sur l'histo 1D de la projection selon Y.
[1092]159 inline Histo* HProjY() const {return mHprojy;}
[1109]160 void ShowProj() const;
[763]161
162 // BANDES
[914]163 //! Retourne le nombre de bandes selon X
[1092]164 inline int_4 NBandX() const {return mLBandx.size();}
[914]165 //! Retourne le nombre de bandes selon Y
[1092]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;
[1109]177 void ShowBand(int_4 lp = 0) const;
[763]178
179 // SLICES
[914]180 //! Retourne le nombre de slices selon X
[1092]181 inline int_4 NSliX() const {return mLSlix.size();}
[914]182 //! Retourne le nombre de slices selon Y
[1092]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;
[1109]192 void ShowSli(int_4 lp = 0) const;
[763]193
194#ifndef __DECCXX
195protected:
196#endif
[914]197 //! structure de definition des bandes
[763]198 struct bande_slice {
[1092]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
[763]203 STRUCTCOMP(bande_slice)
204 };
205#ifdef __DECCXX
206protected:
207#endif
208
209 void Delete();
210
[1092]211 r_8* mData; //!< donnees
212 r_8* mErr2; //!< erreurs carrees
[763]213
[1092]214 r_8 mOver[3][3]; //!< overflow table
215 r_8 nHist; //!< somme ponderee des entrees
216 int_4 nEntries; //!< nombre d'entrees
[763]217
[1092]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
[763]227
[1092]228 bande_slice mB_s;
[763]229
[1092]230 Histo* mHprojx; //!< pointer sur Histo des proj X
231 Histo* mHprojy; //!< pointer sur Histo des proj Y
[763]232
[1092]233 list<bande_slice> mLBandx; //!< liste des bandes selon X
234 list<bande_slice> mLBandy; //!< liste des bandes selon Y
[763]235
[1092]236 list<bande_slice> mLSlix; //!< liste des slices selon X
237 list<bande_slice> mLSliy; //!< liste des slices selon Y
[763]238
239};
240
[1413]241/*! Prints histogram information on stream \b s (h.Show(s)) */
242inline ostream& operator << (ostream& s, Histo2D const & h)
243 { h.Show(s); return(s); }
244
[763]245/////////////////////////////////////////////////////////////////////////
246// Classe pour la gestion de persistance
247
[958]248/*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo2D)
249 \brief Persistance management */
[763]250inline POutPersist& operator << (POutPersist& os, Histo2D & obj)
251{ ObjFileIO<Histo2D> fio(&obj); fio.Write(os); return(os); }
[958]252/*! \ingroup HiStats \fn operator<<(POuttPersist&,Histo2D)
253 \brief Persistance management */
[763]254inline 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
[1092]260/*! \ingroup HiStats \fn operator*(const Histo2D&,r_8)
[1053]261 \brief Operateur H2 = H1 * b */
[1092]262inline Histo2D operator * (const Histo2D& a, r_8 b)
[1053]263{
264 Histo2D result(a);
265 return (result *= b);
266}
267
[1092]268/*! \ingroup HiStats \fn operator*(r_8,const Histo2D&)
[1053]269 \brief Operateur H2 = b * H1 */
[1092]270inline Histo2D operator * (r_8 b, const Histo2D& a)
[1053]271{
272 Histo2D result(a);
273 return (result *= b);
274}
275
[1092]276/*! \ingroup HiStats \fn operator/(const Histo2D&,r_8)
[1053]277 \brief Operateur H2 = H1 / b */
[1092]278inline Histo2D operator / (const Histo2D& a, r_8 b)
[1053]279{
280 Histo2D result(a);
281 return (result /= b);
282}
283
[1092]284/*! \ingroup HiStats \fn operator+(const Histo2D&,r_8)
[1053]285 \brief Operateur H2 = H1 + b */
[1092]286inline Histo2D operator + (const Histo2D& a, r_8 b)
[1053]287{
288 Histo2D result(a);
289 return (result += b);
290}
291
[1092]292/*! \ingroup HiStats \fn operator+(r_8,const Histo2D&)
[1053]293 \brief Operateur H2 = b + H1 */
[1092]294inline Histo2D operator + (r_8 b, const Histo2D& a)
[1053]295{
296 Histo2D result(a);
297 return (result += b);
298}
299
[1092]300/*! \ingroup HiStats \fn operator-(const Histo2D&,r_8)
[1053]301 \brief Operateur H2 = H1 - b */
[1092]302inline Histo2D operator - (const Histo2D& a, r_8 b)
[1053]303{
304 Histo2D result(a);
305 return (result -= b);
306}
307
[1092]308/*! \ingroup HiStats \fn operator-(r_8,const Histo2D&)
[1053]309 \brief Operateur H2 = b - H1 */
[1092]310inline Histo2D operator - (r_8 b, const Histo2D& a)
[1053]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
320inline Histo2D operator + (const Histo2D& a, const Histo2D& b)
321{
322if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
323Histo2D c(a);
324return (c += b);
325}
326
327/*! \ingroup HiStats \fn operator-(const Histo2D&,const Histo2D&)
328 \brief Operateur H = H1 - H2 */
329inline Histo2D operator - (const Histo2D& a, const Histo2D& b)
330{
331if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
332Histo2D c(a);
333return (c -= b);
334}
335
336/*! \ingroup HiStats \fn operator*(const Histo2D&,const Histo2D&)
337 \brief Operateur H = H1 * H2 */
338inline Histo2D operator * (const Histo2D& a, const Histo2D& b)
339{
340if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
341Histo2D c(a);
342return (c *= b);
343}
344
345/*! \ingroup HiStats \fn operator/(const Histo2D&,const Histo2D&)
346 \brief Operateur H = H1 / H2 */
347inline Histo2D operator / (const Histo2D& a, const Histo2D& b)
348{
349if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr);
350Histo2D c(a);
351return (c /= b);
352}
353
[763]354} // Fin du namespace
355
356#endif // HISTOS2_SEEN
Note: See TracBrowser for help on using the repository browser.