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

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

documentation cmv 13/4/00

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