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

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

les friend operator ne marche plus ? passage en inline cmv 30/06/00

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