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

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

define module HiStats in Doc cmv 13/4/00

File size: 10.0 KB
Line 
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
22class GeneralFit;
23
24
25/*!
26 \class SOPHYA::Histo2D
27 \ingroup HiStats
28 Classe d'histogrammes 2D
29 \verbatim
30 Remarque sur les indices:
31 H(i,j) -> i = coord x (0<i<nx), j = coord y (0<j<ny)
32 v(ii,jj) -> ii = ligne (0<i<NRows()), jj = colonne (0<i<NCol())
33 On fait une correspondance directe i<->ii et j<->jj
34 ce qui, en representation classique des histos2D et des matrices
35 entraine une inversion x<->y cad une symetrie / diagonale principale
36 H(0,...) represente ^ mais v(0,...) represente
37 |x....... |xxxxxxxx|
38 |x....... |........|
39 |x....... |........|
40 |x....... |........|
41 |x....... |........|
42 --------->
43 colonne no 1 ligne no 1
44 \endverbatim
45*/
46class Histo2D : public AnyDataObj {
47 friend class ObjFileIO<Histo2D>;
48public:
49
50 // CREATOR / DESTRUCTOR
51 Histo2D(float xMin, float xMax, int nxBin
52 ,float yMin, float yMax, int nyBin);
53 Histo2D(const Histo2D& h);
54 Histo2D();
55 virtual ~Histo2D();
56
57 // OPTIONS
58 void Errors();
59
60 // UPDATING
61 void Zero();
62 void Add(float x, float y, float w = 1.);
63
64 // Operators
65 Histo2D& operator = (const Histo2D& h);
66 Histo2D& operator *= (double b);
67 Histo2D& operator /= (double b);
68 Histo2D& operator += (double b);
69 Histo2D& operator -= (double b);
70 friend Histo2D operator * (const Histo2D& a, double b);
71 friend Histo2D operator * (double b, const Histo2D& a);
72 friend Histo2D operator / (const Histo2D& a, double b);
73 friend Histo2D operator + (const Histo2D& a, double b);
74 friend Histo2D operator + (double b, const Histo2D& a);
75 friend Histo2D operator - (const Histo2D& a, double b);
76 friend Histo2D operator - (double b, const Histo2D& a);
77 Histo2D& operator += (const Histo2D& a);
78 Histo2D& operator -= (const Histo2D& a);
79 Histo2D& operator *= (const Histo2D& a);
80 Histo2D& operator /= (const Histo2D& a);
81 friend Histo2D operator + (const Histo2D& a, const Histo2D& b);
82 friend Histo2D operator - (const Histo2D& a, const Histo2D& b);
83 friend Histo2D operator * (const Histo2D& a, const Histo2D& b);
84 friend Histo2D operator / (const Histo2D& a, const Histo2D& b);
85
86 // get/put dans/depuis une matrice / vector
87 void GetXCoor(Vector& v);
88 void GetValue(Matrix &v);
89 void GetYCoor(Vector& v);
90 void GetError2(Matrix& v);
91 void GetError(Matrix& v);
92 void PutValue(Matrix& v, int ierr=0);
93 void PutValueAdd(Matrix& v, int ierr=0);
94 void PutError2(Matrix& v);
95 void PutError2Add(Matrix& v);
96 void PutError(Matrix& v);
97
98 // INLINES
99 //! Retourne l'abscisse minimum.
100 inline float XMin() const {return xmin;}
101 //! Retourne l'abscisse maximum.
102 inline float XMax() const {return xmax;}
103 //! Retourne l'ordonnee minimum.
104 inline float YMin() const {return ymin;}
105 //! Retourne l'ordonnee maximum.
106 inline float YMax() const {return ymax;}
107 //! Retourne le nombre de bins selon X.
108 inline int_4 NBinX() const {return nx;}
109 //! Retourne le nombre de bins selon Y.
110 inline int_4 NBinY() const {return ny;}
111 //! Retourne la largeur du bin selon X.
112 inline float WBinX() const {return wbinx;}
113 //! Retourne la largeur du bin selon Y.
114 inline float WBinY() const {return wbiny;}
115 //! Retourne le pointeur sur le tableaux des contenus.
116 inline float* Bins() const {return data;}
117 //! Retourne le contenu du bin i,j.
118 inline float operator()(int i,int j) const {return data[j*nx+i];}
119 //! Remplit le contenu du bin i,j.
120 inline float& operator()(int i,int j) {return data[j*nx+i];}
121 //! retourne "true" si il y a des erreurs stoquees
122 inline bool HasErrors() { if(err2) return true; else return false;}
123 //! Retourne l'erreur du bin i,j.
124 inline float Error(int i,int j) const
125 {if(err2)
126 {if(err2[j*nx+i]>0.) return sqrt(err2[j*nx+i]); else return 0.;}
127 else return 0.;}
128 //! Remplit l'erreur au carre du bin i,j.
129 inline double Error2(int i,int j) const
130 {if(err2) return err2[j*nx+i]; else return 0.;}
131 //! Remplit l'erreur au carre du bin i,j.
132 inline double& Error2(int i,int j) {return err2[j*nx+i];}
133 //! Retourne la somme ponderee.
134 inline float NData() const {return (float) nHist;}
135 //! Retourne le nombre d'entrees.
136 inline int_4 NEntries() const {return nEntries;}
137 //! Retourne l'abscisse et l'ordonnee du coin inferieur du bin i,j.
138 inline void BinLowEdge(int i,int j,float& x,float& y)
139 {x = xmin + i*wbinx; y = ymin + j*wbiny;}
140 //! Retourne l'abscisse et l'ordonnee du centre du bin i,j.
141 inline void BinCenter(int i,int j,float& x,float& y)
142 {x = xmin + (i+0.5)*wbinx; y = ymin + (j+0.5)*wbiny;}
143 //! Retourne l'abscisse et l'ordonnee du coin superieur du bin i,j.
144 inline void BinHighEdge(int i,int j,float& x,float& y)
145 {x = xmin + (i+1)*wbinx; y = ymin + (j+1)*wbiny;}
146 //! Retourne les numeros du bin contenant l'abscisse et l'ordonnee x,y.
147 inline void FindBin(float x,float y,int& i,int& j)
148 { i = (int) floorf((x - xmin)/wbinx); j = (int) floorf((y - ymin)/wbiny);}
149
150 // Info, statistique et calculs sur les histogrammes
151 float NOver(int i=-1,int j=-1) const;
152 int BinNonNul() const;
153 int ErrNonNul() const;
154 void IJMax(int& imax,int& jmax,int il=1,int ih= -1,int jl=1,int jh= -1);
155 void IJMin(int& imax,int& jmax,int il=1,int ih= -1,int jl=1,int jh= -1);
156 float VMax(int il=1,int ih= -1,int jl=1,int jh= -1) const;
157 float VMin(int il=1,int ih= -1,int jl=1,int jh= -1) const;
158 int EstimeMax(float& xm,float& ym,int SzPav = 3
159 ,int il=1,int ih= -1,int jl=1,int jh= -1);
160 int EstimeMax(int im,int jm,float& xm,float& ym,int SzPav = 3);
161 int FindMax(int& im,int& jm,int SzPav = 3,float Dz = 0.
162 ,int il=1,int ih= -1,int jl=1,int jh= -1);
163
164 // Fit
165 int Fit(GeneralFit& gfit,unsigned short typ_err=0);
166 Histo2D FitResidus(GeneralFit& gfit);
167 Histo2D FitFunction(GeneralFit& gfit);
168
169 // Print et Display ASCII
170 void PrintStatus();
171 void Print(float min=1.,float max=-1.
172 ,int il=1,int ih= -1,int jl=1,int jh= -1);
173
174 // PROJECTIONS
175 void SetProjX();
176 void SetProjY();
177 void SetProj();
178 void DelProjX();
179 void DelProjY();
180 void DelProj();
181 void ZeroProjX();
182 void ZeroProjY();
183 void ZeroProj();
184 //! Retourne le pointeur sur l'histo 1D de la projection selon X.
185 inline Histo* HProjX() const {return hprojx;}
186 //! Retourne le pointeur sur l'histo 1D de la projection selon Y.
187 inline Histo* HProjY() const {return hprojy;}
188 void ShowProj();
189
190 // BANDES
191 //! Retourne le nombre de bandes selon X
192 inline int NBandX() const {return lbandx.size();}
193 //! Retourne le nombre de bandes selon Y
194 inline int NBandY() const {return lbandy.size();}
195 int SetBandX(float ybmin,float ybmax);
196 int SetBandY(float xbmin,float xbmax);
197 void DelBandX();
198 void DelBandY();
199 void ZeroBandX();
200 void ZeroBandY();
201 Histo* HBandX(int n) const;
202 Histo* HBandY(int n) const;
203 void GetBandX(int n,float& ybmin,float& ybmax) const;
204 void GetBandY(int n,float& xbmin,float& xbmax) const;
205 void ShowBand(int lp = 0);
206
207 // SLICES
208 //! Retourne le nombre de slices selon X
209 inline int NSliX() const {return lslix.size();}
210 //! Retourne le nombre de slices selon Y
211 inline int NSliY() const {return lsliy.size();}
212 int SetSliX(int nsli);
213 int SetSliY(int nsli);
214 void DelSliX();
215 void DelSliY();
216 void ZeroSliX();
217 void ZeroSliY();
218 Histo* HSliX(int n) const;
219 Histo* HSliY(int n) const;
220 void ShowSli(int lp = 0);
221
222#ifndef __DECCXX
223protected:
224#endif
225 //! structure de definition des bandes
226 struct bande_slice {
227 int num; //!< nombre de bandes
228 float min; //!< limite minimum pour remplir la bande
229 float max; //!< limite maximum pour remplir la bande
230 Histo* H; //!< pointer sur l Histo 1D de la bande
231 STRUCTCOMP(bande_slice)
232 };
233#ifdef __DECCXX
234protected:
235#endif
236
237 void Delete();
238
239 float* data; //!< donnees
240 double* err2; //!< erreurs carrees
241
242 float over[3][3]; //!< overflow table
243 double nHist; //!< somme ponderee des entrees
244 int_4 nEntries; //!< nombre d'entrees
245
246 int_4 nx; //!< nombre de bins en X
247 int_4 ny; //!< nombre de bins en Y
248 int_4 nxy; //!< nombre de bins total
249 float xmin; //!< abscisse minimum
250 float xmax; //!< abscisse maximum
251 float ymin; //!< ordonnee minimum
252 float ymax; //!< ordonnee maximum
253 float wbinx; //!< largeur du bin en X
254 float wbiny; //!< largeur du bin en Y
255
256 bande_slice b_s;
257
258 Histo* hprojx; //!< pointer sur Histo des proj X
259 Histo* hprojy; //!< pointer sur Histo des proj Y
260
261 list<bande_slice> lbandx; //!< liste des bandes selon X
262 list<bande_slice> lbandy; //!< liste des bandes selon Y
263
264 list<bande_slice> lslix; //!< liste des slices selon X
265 list<bande_slice> lsliy; //!< liste des slices selon Y
266
267};
268
269/////////////////////////////////////////////////////////////////////////
270// Classe pour la gestion de persistance
271
272inline POutPersist& operator << (POutPersist& os, Histo2D & obj)
273{ ObjFileIO<Histo2D> fio(&obj); fio.Write(os); return(os); }
274inline PInPersist& operator >> (PInPersist& is, Histo2D & obj)
275{ ObjFileIO<Histo2D> fio(&obj); fio.Read(is); return(is); }
276
277// Classe pour la gestion de persistance
278// ObjFileIO<Histo2D>
279
280} // Fin du namespace
281
282#endif // HISTOS2_SEEN
Note: See TracBrowser for help on using the repository browser.