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

Last change on this file since 3053 was 3053, checked in by cmv, 19 years ago

correction bug + addaptation pour ecriture fits cmv 12/8/2006

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