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