1 | #include "machdefs.h"
|
---|
2 | #include <string.h>
|
---|
3 | #include <new>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include <stdio.h>
|
---|
6 | #ifndef NO_VALUES_H
|
---|
7 | #include <values.h>
|
---|
8 | #endif
|
---|
9 |
|
---|
10 | #include "histos2.h"
|
---|
11 |
|
---|
12 | namespace SOPHYA {
|
---|
13 |
|
---|
14 | /*!
|
---|
15 | \class Histo2D
|
---|
16 | \ingroup HiStats
|
---|
17 | Classe d'histogrammes 2D
|
---|
18 | \verbatim
|
---|
19 | Remarque sur les indices:
|
---|
20 | H(i,j) -> i = coord x (0<i<nx), j = coord y (0<j<ny)
|
---|
21 | v(ii,jj) -> ii = ligne (0<i<NRows()), jj = colonne (0<i<NCol())
|
---|
22 | On fait une correspondance directe i<->ii et j<->jj
|
---|
23 | ce qui, en representation classique des histos2D et des matrices
|
---|
24 | entraine une inversion x<->y cad une symetrie / diagonale principale
|
---|
25 | H(0,...) represente ^ mais v(0,...) represente
|
---|
26 | |x....... |xxxxxxxx|
|
---|
27 | |x....... |........|
|
---|
28 | |x....... |........|
|
---|
29 | |x....... |........|
|
---|
30 | |x....... |........|
|
---|
31 | --------->
|
---|
32 | colonne no 1 ligne no 1
|
---|
33 | \endverbatim
|
---|
34 | */
|
---|
35 |
|
---|
36 | ///////////////////////////////////////////////////////////////////
|
---|
37 |
|
---|
38 | /*!
|
---|
39 | Constructeur par defaut.
|
---|
40 | */
|
---|
41 | Histo2D::Histo2D()
|
---|
42 | : mData(NULL), mErr2(NULL)
|
---|
43 | , nHist(0), nEntries(0)
|
---|
44 | , mNx(0), mNy(0), mNxy(0), mXmin(0), mXmax(0), mYmin(0), mYmax(0), mWBinx(0), mWBiny(0)
|
---|
45 | , mHprojx(NULL), mHprojy(NULL)
|
---|
46 | {
|
---|
47 | for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
|
---|
48 | mB_s.H = NULL;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /*!
|
---|
52 | Createur d'un histogramme 2D ayant nxBin,nyBin bins
|
---|
53 | entre xMin,xMax et yMin,yMax.
|
---|
54 | */
|
---|
55 | Histo2D::Histo2D(r_8 xMin,r_8 xMax,int_4 nxBin,r_8 yMin,r_8 yMax,int_4 nyBin)
|
---|
56 | : mData(NULL), mErr2(NULL), mHprojx(NULL), mHprojy(NULL)
|
---|
57 | {
|
---|
58 | CreateOrResize(xMin,xMax,nxBin,yMin,yMax,nyBin);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /*!
|
---|
62 | Createur d'un histogramme 2D ayant nxBin,nyBin bins
|
---|
63 | entre xMin,xMax et yMin,yMax.
|
---|
64 | */
|
---|
65 | Histo2D::Histo2D(r_4 xMin,r_4 xMax,int_4 nxBin,r_4 yMin,r_4 yMax,int_4 nyBin)
|
---|
66 | : mData(NULL), mErr2(NULL), mHprojx(NULL), mHprojy(NULL)
|
---|
67 | {
|
---|
68 | CreateOrResize((r_8)xMin,(r_8)xMax,nxBin,(r_8)yMin,(r_8)yMax,nyBin);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /*!
|
---|
72 | Constructeur par copie.
|
---|
73 | */
|
---|
74 | Histo2D::Histo2D(const Histo2D& h)
|
---|
75 | {
|
---|
76 | int_4 i,j;
|
---|
77 | mData = new r_8[h.mNxy];
|
---|
78 | memcpy(mData, h.mData, h.mNxy*sizeof(r_8));
|
---|
79 |
|
---|
80 | mErr2 = NULL;
|
---|
81 | if(h.mErr2) {
|
---|
82 | mErr2 = new r_8[h.mNxy];
|
---|
83 | memcpy(mErr2, h.mErr2, h.mNxy*sizeof(r_8));
|
---|
84 | }
|
---|
85 |
|
---|
86 | nHist = h.nHist; nEntries = h.nEntries;
|
---|
87 | for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j]=h.mOver[i][j];
|
---|
88 | mNx = h.mNx; mNy = h.mNy; mNxy = h.mNxy;
|
---|
89 | mXmin = h.mXmin; mXmax = h.mXmax; mYmin = h.mYmin; mYmax = h.mYmax;
|
---|
90 | mWBinx = h.mWBinx; mWBiny = h.mWBiny;
|
---|
91 | mB_s.H = NULL;
|
---|
92 |
|
---|
93 | mHprojx = mHprojy = NULL;
|
---|
94 | if(h.mHprojx) {SetProjX(); *mHprojx = *(h.mHprojx);}
|
---|
95 | if(h.mHprojy) {SetProjY(); *mHprojy = *(h.mHprojy);}
|
---|
96 |
|
---|
97 | int_4 nb; r_8 min,max;
|
---|
98 | nb = h.NSliX();
|
---|
99 | if(nb>0) {SetSliX(nb); for(i=0;i<NSliX();i++) *HSliX(i)=*(h.HSliX(i));}
|
---|
100 | nb = h.NSliY();
|
---|
101 | if(nb>0) {SetSliY(nb); for(i=0;i<NSliY();i++) *HSliY(i)=*(h.HSliY(i));}
|
---|
102 |
|
---|
103 | nb = h.NBandX();
|
---|
104 | if(nb>0) {
|
---|
105 | for(i=0;i<nb;i++)
|
---|
106 | {h.GetBandX(i,min,max); SetBandX(min,max); *HBandX(i)=*(h.HBandX(i));}
|
---|
107 | for(i=0;i<NBandX();i++) *HBandX(i) = *(h.HBandX(i));
|
---|
108 | }
|
---|
109 | nb = h.NBandY();
|
---|
110 | if(nb>0) {
|
---|
111 | for(i=0;i<nb;i++)
|
---|
112 | {h.GetBandY(i,min,max); SetBandY(min,max); *HBandY(i)=*(h.HBandY(i));}
|
---|
113 | for(i=0; i<NBandY();i++) *HBandY(i) = *(h.HBandY(i));
|
---|
114 | }
|
---|
115 |
|
---|
116 | }
|
---|
117 |
|
---|
118 | /*!
|
---|
119 | Destructeur.
|
---|
120 | */
|
---|
121 | Histo2D::~Histo2D()
|
---|
122 | {
|
---|
123 | Delete();
|
---|
124 | }
|
---|
125 |
|
---|
126 | ///////////////////////////////////////////////////////////////////
|
---|
127 | /*!
|
---|
128 | allocation de la place de l'histogramme (fct privee).
|
---|
129 | */
|
---|
130 | void Histo2D::CreateOrResize(r_8 xMin,r_8 xMax,int_4 nxBin,r_8 yMin,r_8 yMax,int_4 nyBin)
|
---|
131 | {
|
---|
132 | int_8 n = nxBin*nyBin;
|
---|
133 | bool samelen = (n==mNx*mNy)? true: false;
|
---|
134 | if(mData!=NULL && !samelen) {delete[] mData; mData=NULL;}
|
---|
135 | if(mErr2!=NULL) {delete[] mErr2; mErr2=NULL;} // On des-alloue toujours
|
---|
136 | if(n>0 && mData==NULL) mData = new r_8[n];
|
---|
137 | if(mData) memset(mData, 0, n*sizeof(r_8));
|
---|
138 | mNx = nxBin; mNy = nyBin; mNxy = nxBin*nyBin;
|
---|
139 | mXmin = xMin; mXmax = xMax; mYmin = yMin; mYmax = yMax;
|
---|
140 | mWBinx = (nxBin>0) ? (xMax - xMin)/nxBin: 0.;
|
---|
141 | mWBiny = (nyBin>0) ? (yMax - yMin)/nyBin: 0.;
|
---|
142 | nHist = 0; nEntries = 0;
|
---|
143 | for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
|
---|
144 | mB_s.H = NULL;
|
---|
145 |
|
---|
146 | DelProjX(); DelProjY();
|
---|
147 | DelBandX(); DelBandY();
|
---|
148 | DelSliX(); DelSliY();
|
---|
149 | }
|
---|
150 |
|
---|
151 | /*!
|
---|
152 | Desallocation de la place de l'histogramme (fct privee).
|
---|
153 | */
|
---|
154 | void Histo2D::Delete()
|
---|
155 | {
|
---|
156 | if( mData != NULL ) { delete[] mData; mData = NULL;}
|
---|
157 | if( mErr2 != NULL ) { delete[] mErr2; mErr2 = NULL;}
|
---|
158 |
|
---|
159 | DelProj();
|
---|
160 | DelBandX(); DelBandY();
|
---|
161 | DelSliX(); DelSliY();
|
---|
162 |
|
---|
163 | nHist = 0;
|
---|
164 | nEntries = 0;
|
---|
165 | mNx = 0; mNy = 0; mNxy = 0;
|
---|
166 | mXmin = 0; mXmax = 0; mYmin = 0; mYmax = 0;
|
---|
167 | mWBinx = 0; mWBiny = 0;
|
---|
168 | for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
|
---|
169 | mB_s.H = NULL; // Ne pas faire de delete!
|
---|
170 | }
|
---|
171 |
|
---|
172 | ///////////////////////////////////////////////////////////////////
|
---|
173 | /*!
|
---|
174 | Remise a zero du contenu, des erreurs et des valeurs.
|
---|
175 | */
|
---|
176 | void Histo2D::Zero()
|
---|
177 | {
|
---|
178 | nHist = nEntries = 0;
|
---|
179 | for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
|
---|
180 | memset(mData, 0, mNxy*sizeof(r_8));
|
---|
181 | memset(mOver, 0, 9*sizeof(r_8));
|
---|
182 |
|
---|
183 | if( mErr2 != NULL ) memset(mErr2, 0, mNxy*sizeof(r_8));
|
---|
184 |
|
---|
185 | ZeroProj();
|
---|
186 |
|
---|
187 | ZeroBandX(); ZeroBandY();
|
---|
188 |
|
---|
189 | ZeroSliX(); ZeroSliY();
|
---|
190 | }
|
---|
191 |
|
---|
192 | ///////////////////////////////////////////////////////////////////
|
---|
193 | /*!
|
---|
194 | Pour avoir le calcul des erreurs.
|
---|
195 | */
|
---|
196 | void Histo2D::Errors()
|
---|
197 | {
|
---|
198 | if(mErr2!=NULL) {delete[] mErr2; mErr2 = NULL;}
|
---|
199 | if(mNxy <= 0) return;
|
---|
200 | mErr2 = new r_8[mNxy];
|
---|
201 | memset(mErr2,0,mNxy*sizeof(r_8));
|
---|
202 | }
|
---|
203 |
|
---|
204 | ///////////////////////////////////////////////////////////////////
|
---|
205 | /*!
|
---|
206 | Recompute XMin (YMin) and XMax (YMax) so that
|
---|
207 | the CENTER of the first bin is exactly XMin (YMin) and
|
---|
208 | the CENTER of the last bin is exactly XMax (YMax).
|
---|
209 | Remember that otherwise
|
---|
210 | XMin (YMin) is the beginning of the first bin
|
---|
211 | and XMax (YMax) is the end of the last bin
|
---|
212 | */
|
---|
213 | void Histo2D::ReCenterBinX(void)
|
---|
214 | {
|
---|
215 | if(mNx<=1) return;
|
---|
216 | double dx = (mXmax-mXmin)/(mNx-1);
|
---|
217 | mXmin -= dx/2.;
|
---|
218 | mXmax += dx/2.;
|
---|
219 | mWBinx = (mXmax-mXmin)/mNx;
|
---|
220 | }
|
---|
221 |
|
---|
222 | void Histo2D::ReCenterBinY(void)
|
---|
223 | {
|
---|
224 | if(mNy<=1) return;
|
---|
225 | double dy = (mYmax-mYmin)/(mNy-1);
|
---|
226 | mYmin -= dy/2.;
|
---|
227 | mYmax += dy/2.;
|
---|
228 | mWBiny = (mYmax-mYmin)/mNy;
|
---|
229 | }
|
---|
230 |
|
---|
231 | void Histo2D::ReCenterBin(void)
|
---|
232 | {
|
---|
233 | ReCenterBinX();
|
---|
234 | ReCenterBinY();
|
---|
235 | }
|
---|
236 |
|
---|
237 |
|
---|
238 | ///////////////////////////////////////////////////////////////////
|
---|
239 | /*!
|
---|
240 | Operateur H2 = H1
|
---|
241 | */
|
---|
242 | Histo2D& Histo2D::operator = (const Histo2D& h)
|
---|
243 | {
|
---|
244 | if(this == &h) return *this;
|
---|
245 | CreateOrResize(h.mXmin,h.mXmax,h.mNx,h.mYmin,h.mYmax,h.mNy);
|
---|
246 | if(h.mErr2) Errors();
|
---|
247 | if(mData) memcpy(mData, h.mData, mNxy*sizeof(r_8));
|
---|
248 | if(mErr2) memcpy(mErr2, h.mErr2, mNxy*sizeof(r_8));
|
---|
249 |
|
---|
250 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) mOver[i][j] = h.mOver[i][j];
|
---|
251 | nHist = h.nHist; nEntries = h.nEntries;
|
---|
252 |
|
---|
253 | if(h.mHprojx) {SetProjX(); *mHprojx = *(h.mHprojx);}
|
---|
254 | if(h.mHprojy) {SetProjY(); *mHprojy = *(h.mHprojy);}
|
---|
255 |
|
---|
256 | int_4 nb;
|
---|
257 | nb = h.NSliX();
|
---|
258 | if(nb>0) {
|
---|
259 | SetSliX(nb);
|
---|
260 | for(int i=0; i<NSliX();i++) *HSliX(i) = *(h.HSliX(i));
|
---|
261 | }
|
---|
262 | nb = h.NSliY();
|
---|
263 | if(nb>0) {
|
---|
264 | SetSliY(nb);
|
---|
265 | for(int i=0; i<NSliY();i++) *HSliY(i) = *(h.HSliY(i));
|
---|
266 | }
|
---|
267 |
|
---|
268 | nb = h.NBandX();
|
---|
269 | if(nb>0) {
|
---|
270 | for(int i=0; i<nb;i++) {
|
---|
271 | r_8 min,max;
|
---|
272 | h.GetBandX(i,min,max);
|
---|
273 | SetBandX(min,max);
|
---|
274 | *HBandX(i) = *(h.HBandX(i));
|
---|
275 | }
|
---|
276 | for(int i=0; i<NBandX();i++) *HBandX(i) = *(h.HBandX(i));
|
---|
277 | }
|
---|
278 | nb = h.NBandY();
|
---|
279 | if(nb>0) {
|
---|
280 | for(int i=0; i<nb;i++) {
|
---|
281 | r_8 min,max;
|
---|
282 | h.GetBandY(i,min,max);
|
---|
283 | SetBandY(min,max);
|
---|
284 | *HBandY(i) = *(h.HBandY(i));
|
---|
285 | }
|
---|
286 | for(int i=0; i<NBandY();i++) *HBandY(i) = *(h.HBandY(i));
|
---|
287 | }
|
---|
288 |
|
---|
289 | return *this;
|
---|
290 | }
|
---|
291 |
|
---|
292 | ///////////////////////////////////////////////////////////////////
|
---|
293 | /*!
|
---|
294 | Operateur H *= b
|
---|
295 | */
|
---|
296 | Histo2D& Histo2D::operator *= (r_8 b)
|
---|
297 | {
|
---|
298 | int_4 i,j;
|
---|
299 | r_8 b2 = b*b;
|
---|
300 | for(i=0;i<mNxy;i++) {
|
---|
301 | mData[i] *= b;
|
---|
302 | if(mErr2) mErr2[i] *= b2;
|
---|
303 | }
|
---|
304 | for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j] *= b;
|
---|
305 | nHist *= b;
|
---|
306 |
|
---|
307 | if(mHprojx) *mHprojx *= b;
|
---|
308 | if(mHprojy) *mHprojy *= b;
|
---|
309 | if(NSliX()>0) for(i=0; i<NSliX();i++) *HSliX(i) *= b;
|
---|
310 | if(NSliY()>0) for(i=0; i<NSliY();i++) *HSliY(i) *= b;
|
---|
311 | if(NBandX()>0) for(i=0; i<NBandX();i++) *HBandX(i) *= b;
|
---|
312 | if(NBandY()>0) for(i=0; i<NBandY();i++) *HBandY(i) *= b;
|
---|
313 |
|
---|
314 | return *this;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /*!
|
---|
318 | Operateur H /= b
|
---|
319 | */
|
---|
320 | Histo2D& Histo2D::operator /= (r_8 b)
|
---|
321 | {
|
---|
322 | int_4 i,j;
|
---|
323 | if (b==0.) throw ParmError("Histo2D::operator / (0) ");
|
---|
324 | r_8 b2 = b*b;
|
---|
325 | for(i=0;i<mNxy;i++) {
|
---|
326 | mData[i] /= b;
|
---|
327 | if(mErr2) mErr2[i] /= b2;
|
---|
328 | }
|
---|
329 | for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j] /= b;
|
---|
330 | nHist /= b;
|
---|
331 |
|
---|
332 | if(mHprojx) *mHprojx /= b;
|
---|
333 | if(mHprojy) *mHprojy /= b;
|
---|
334 | if(NSliX()>0) for(i=0; i<NSliX();i++) *HSliX(i) /= b;
|
---|
335 | if(NSliY()>0) for(i=0; i<NSliY();i++) *HSliY(i) /= b;
|
---|
336 | if(NBandX()>0) for(i=0; i<NBandX();i++) *HBandX(i) /= b;
|
---|
337 | if(NBandY()>0) for(i=0; i<NBandY();i++) *HBandY(i) /= b;
|
---|
338 |
|
---|
339 | return *this;
|
---|
340 | }
|
---|
341 |
|
---|
342 | /*!
|
---|
343 | Operateur H += b
|
---|
344 | */
|
---|
345 | Histo2D& Histo2D::operator += (r_8 b)
|
---|
346 | {
|
---|
347 | int_4 i,j;
|
---|
348 | r_8 min,max;
|
---|
349 | for(i=0;i<mNxy;i++) mData[i] += b;
|
---|
350 | for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j] += b;
|
---|
351 | nHist += mNxy*b;
|
---|
352 |
|
---|
353 | if(mHprojx) *mHprojx += b*mNy;
|
---|
354 | if(mHprojy) *mHprojy += b*mNx;
|
---|
355 | if(NSliX()>0) for(i=0; i<NSliX();i++) *HSliX(i) += b*mNy/NSliX();
|
---|
356 | if(NSliY()>0) for(i=0; i<NSliY();i++) *HSliY(i) += b*mNx/NSliY();
|
---|
357 | if(NBandX()>0) for(i=0; i<NBandX();i++) {
|
---|
358 | GetBandX(i,min,max);
|
---|
359 | *HBandX(i) += b*(max-min)/(mYmax-mYmin)*mNy;
|
---|
360 | }
|
---|
361 | if(NBandY()>0) for(i=0; i<NBandY();i++) {
|
---|
362 | GetBandY(i,min,max);
|
---|
363 | *HBandY(i) += b*(max-min)/(mXmax-mXmin)*mNx;
|
---|
364 | }
|
---|
365 |
|
---|
366 | return *this;
|
---|
367 | }
|
---|
368 |
|
---|
369 | /*!
|
---|
370 | Operateur H -= b
|
---|
371 | */
|
---|
372 | Histo2D& Histo2D::operator -= (r_8 b)
|
---|
373 | {
|
---|
374 | int_4 i,j;
|
---|
375 | r_8 min,max;
|
---|
376 | for(i=0;i<mNxy;i++) mData[i] -= b;
|
---|
377 | for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j] -= b;
|
---|
378 | nHist -= mNxy*b;
|
---|
379 |
|
---|
380 | if(mHprojx) *mHprojx -= b*mNy;
|
---|
381 | if(mHprojy) *mHprojy -= b*mNx;
|
---|
382 | if(NSliX()>0) for(i=0; i<NSliX();i++) *HSliX(i) -= b*mNy/NSliX();
|
---|
383 | if(NSliY()>0) for(i=0; i<NSliY();i++) *HSliY(i) -= b*mNx/NSliY();
|
---|
384 | if(NBandX()>0) for(i=0; i<NBandX();i++) {
|
---|
385 | GetBandX(i,min,max);
|
---|
386 | *HBandX(i) -= b*(max-min)/(mYmax-mYmin)*mNy;
|
---|
387 | }
|
---|
388 | if(NBandY()>0) for(i=0; i<NBandY();i++) {
|
---|
389 | GetBandY(i,min,max);
|
---|
390 | *HBandY(i) -= b*(max-min)/(mXmax-mXmin)*mNx;
|
---|
391 | }
|
---|
392 |
|
---|
393 | return *this;
|
---|
394 | }
|
---|
395 |
|
---|
396 | ///////////////////////////////////////////////////////////////////
|
---|
397 | /*!
|
---|
398 | Operateur H += H1
|
---|
399 | */
|
---|
400 | Histo2D& Histo2D::operator += (const Histo2D& a)
|
---|
401 | {
|
---|
402 | int_4 i,j;
|
---|
403 | if(mNx!=a.mNx || mNy!=a.mNy) throw SzMismatchError("Histo2D::operator += ");
|
---|
404 | for(i=0;i<mNxy;i++) {
|
---|
405 | mData[i] += a.mData[i];
|
---|
406 | if(mErr2 && a.mErr2) mErr2[i] += a.mErr2[i];
|
---|
407 | }
|
---|
408 | for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j] += a.mOver[i][j];
|
---|
409 | nHist += a.nHist;
|
---|
410 | nEntries += a.nEntries;
|
---|
411 |
|
---|
412 | if(mHprojx && a.mHprojx) *mHprojx += *(a.mHprojx);
|
---|
413 | if(mHprojy && a.mHprojy) *mHprojy += *(a.mHprojy);
|
---|
414 | ZeroSliX(); ZeroSliY();
|
---|
415 | ZeroBandX(); ZeroBandY();
|
---|
416 |
|
---|
417 | return *this;
|
---|
418 | }
|
---|
419 |
|
---|
420 | /*!
|
---|
421 | Operateur H -= H1
|
---|
422 | */
|
---|
423 | Histo2D& Histo2D::operator -= (const Histo2D& a)
|
---|
424 | {
|
---|
425 | int_4 i,j;
|
---|
426 | if(mNx!=a.mNx || mNy!=a.mNy) throw SzMismatchError("Histo2D::operator -= ");
|
---|
427 | for(i=0;i<mNxy;i++) {
|
---|
428 | mData[i] -= a.mData[i];
|
---|
429 | if(mErr2 && a.mErr2) mErr2[i] += a.mErr2[i];
|
---|
430 | }
|
---|
431 | for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j] += a.mOver[i][j];
|
---|
432 | nHist -= a.nHist;
|
---|
433 | nEntries += a.nEntries;
|
---|
434 |
|
---|
435 | if(mHprojx && a.mHprojx) *mHprojx -= *(a.mHprojx);
|
---|
436 | if(mHprojy && a.mHprojy) *mHprojy -= *(a.mHprojy);
|
---|
437 | ZeroSliX(); ZeroSliY();
|
---|
438 | ZeroBandX(); ZeroBandY();
|
---|
439 |
|
---|
440 | return *this;
|
---|
441 | }
|
---|
442 |
|
---|
443 | /*!
|
---|
444 | Operateur H *= H1
|
---|
445 | */
|
---|
446 | Histo2D& Histo2D::operator *= (const Histo2D& a)
|
---|
447 | {
|
---|
448 | int_4 i,j;
|
---|
449 | if(mNx!=a.mNx || mNy!=a.mNy) throw SzMismatchError("Histo2D::operator *= ");
|
---|
450 | nHist = 0.;
|
---|
451 | for(i=0;i<mNxy;i++) {
|
---|
452 | if(mErr2 && a.mErr2)
|
---|
453 | mErr2[i] = a.mData[i]*a.mData[i]*mErr2[i] + mData[i]*mData[i]*a.mErr2[i];
|
---|
454 | mData[i] *= a.mData[i];
|
---|
455 | nHist += mData[i];
|
---|
456 | }
|
---|
457 | for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j] *= a.mOver[i][j];
|
---|
458 | nEntries += a.nEntries;
|
---|
459 |
|
---|
460 | if(mHprojx && a.mHprojx) *mHprojx *= *(a.mHprojx);
|
---|
461 | if(mHprojy && a.mHprojy) *mHprojy *= *(a.mHprojy);
|
---|
462 | ZeroSliX(); ZeroSliY();
|
---|
463 | ZeroBandX(); ZeroBandY();
|
---|
464 |
|
---|
465 | return *this;
|
---|
466 | }
|
---|
467 |
|
---|
468 | /*!
|
---|
469 | Operateur H /= H1
|
---|
470 | */
|
---|
471 | Histo2D& Histo2D::operator /= (const Histo2D& a)
|
---|
472 | {
|
---|
473 | int_4 i,j;
|
---|
474 | if(mNx!=a.mNx || mNy!=a.mNy) throw SzMismatchError("Histo2D::operator /= ");
|
---|
475 | nHist = 0.;
|
---|
476 | for(i=0;i<mNxy;i++) {
|
---|
477 | if(a.mData[i]==0.) {
|
---|
478 | mData[i]=0.;
|
---|
479 | if(mErr2) mErr2[i]=0.;
|
---|
480 | continue;
|
---|
481 | }
|
---|
482 | if(mErr2 && a.mErr2)
|
---|
483 | mErr2[i] = (mErr2[i] + mData[i]/a.mData[i]*mData[i]/a.mData[i]*a.mErr2[i])
|
---|
484 | /(a.mData[i]*a.mData[i]);
|
---|
485 | mData[i] /= a.mData[i];
|
---|
486 | nHist += mData[i];
|
---|
487 | }
|
---|
488 | for(i=0;i<3;i++) for(j=0;j<3;j++)
|
---|
489 | if(a.mOver[i][j]!=0.) mOver[i][j] *= a.mOver[i][j]; else mOver[i][j] = 0.;
|
---|
490 | nEntries += a.nEntries;
|
---|
491 |
|
---|
492 | if(mHprojx && a.mHprojx) *mHprojx /= *(a.mHprojx);
|
---|
493 | if(mHprojy && a.mHprojy) *mHprojy /= *(a.mHprojy);
|
---|
494 | ZeroSliX(); ZeroSliY();
|
---|
495 | ZeroBandX(); ZeroBandY();
|
---|
496 |
|
---|
497 | return *this;
|
---|
498 | }
|
---|
499 |
|
---|
500 | ///////////////////////////////////////////////////////////////////
|
---|
501 | /*!
|
---|
502 | Remplissage d'un tableau avec les valeurs des abscisses.
|
---|
503 | */
|
---|
504 | void Histo2D::GetXCoor(TVector<r_8> &v) const
|
---|
505 | {
|
---|
506 | r_8 x,y;
|
---|
507 | v.Realloc(mNx);
|
---|
508 | for(int_4 i=0;i<mNx;i++) {BinLowEdge(i,0,x,y); v(i) = x;}
|
---|
509 | return;
|
---|
510 | }
|
---|
511 |
|
---|
512 | /*!
|
---|
513 | Remplissage d'un tableau avec les valeurs des ordonnees.
|
---|
514 | */
|
---|
515 | void Histo2D::GetYCoor(TVector<r_8> &v) const
|
---|
516 | {
|
---|
517 | r_8 x,y;
|
---|
518 | v.Realloc(mNy);
|
---|
519 | for(int_4 i=0;i<mNy;i++) {BinLowEdge(0,i,x,y); v(i) = y;}
|
---|
520 | return;
|
---|
521 | }
|
---|
522 |
|
---|
523 | /*!
|
---|
524 | Remplissage d'un tableau avec les valeurs du contenu.
|
---|
525 | */
|
---|
526 | void Histo2D::GetValue(TMatrix<r_8> &v) const
|
---|
527 | {
|
---|
528 | v.Realloc(mNx,mNy);
|
---|
529 | for(int_4 i=0;i<mNx;i++)
|
---|
530 | for(int_4 j=0;j<mNy;j++) v(i,j) = (*this)(i,j);
|
---|
531 | return;
|
---|
532 | }
|
---|
533 |
|
---|
534 | /*!
|
---|
535 | Remplissage d'un tableau avec les valeurs du carre des erreurs.
|
---|
536 | */
|
---|
537 | void Histo2D::GetError2(TMatrix<r_8> &v) const
|
---|
538 | {
|
---|
539 | int_4 i,j;
|
---|
540 | v.Realloc(mNx,mNy);
|
---|
541 | if(!mErr2)
|
---|
542 | {for(i=0;i<mNx;i++) for(j=0;j<mNy;j++) v(i,j) = 0.; return;}
|
---|
543 | for(i=0;i<mNx;i++) for(j=0;j<mNy;j++) v(i,j) = Error2(i,j);
|
---|
544 | return;
|
---|
545 | }
|
---|
546 |
|
---|
547 | /*!
|
---|
548 | Remplissage d'un tableau avec les valeurs des erreurs.
|
---|
549 | */
|
---|
550 | void Histo2D::GetError(TMatrix<r_8> &v) const
|
---|
551 | {
|
---|
552 | int_4 i,j;
|
---|
553 | v.Realloc(mNx,mNy);
|
---|
554 | if(!mErr2)
|
---|
555 | {for(i=0;i<mNx;i++) for(j=0;j<mNy;j++) v(i,j) = 0.; return;}
|
---|
556 | for(i=0;i<mNx;i++) for(j=0;j<mNy;j++) v(i,j) = Error(i,j);
|
---|
557 | return;
|
---|
558 | }
|
---|
559 |
|
---|
560 | ///////////////////////////////////////////////////////////////////
|
---|
561 | /*!
|
---|
562 | Remplissage du contenu de l'histo avec les valeurs d'un tableau.
|
---|
563 | */
|
---|
564 | void Histo2D::PutValue(TMatrix<r_8> &v, int_4 ierr)
|
---|
565 | {
|
---|
566 | //if(v.NRows()!=(uint_4)mNx || v.NCol()!=(uint_4)mNy) throw SzMismatchError("Histo2D::PutValue()");
|
---|
567 | uint_4 nnx = (v.NRows()<(uint_4)mNx)? v.NRows(): (uint_4)mNx;
|
---|
568 | uint_4 nny = (v.NCol() <(uint_4)mNy)? v.NCol() : (uint_4)mNy;
|
---|
569 | if(nnx>0 && nny>0) for(uint_4 i=0;i<nnx;i++) for(uint_4 j=0;j<nny;j++) {
|
---|
570 | (*this)(i,j) = v(i,j);
|
---|
571 | if(mErr2 && ierr) Error2(i,j) = fabs(v(i,j));
|
---|
572 | }
|
---|
573 | return;
|
---|
574 | }
|
---|
575 |
|
---|
576 | /*!
|
---|
577 | Addition du contenu de l'histo avec les valeurs d'un tableau.
|
---|
578 | */
|
---|
579 | void Histo2D::PutValueAdd(TMatrix<r_8> &v, int_4 ierr)
|
---|
580 | {
|
---|
581 | //if(v.NRows()!=(uint_4)mNx || v.NCol()!=(uint_4)mNy) throw SzMismatchError("Histo2D::PutValueAdd ");
|
---|
582 | uint_4 nnx = (v.NRows()<(uint_4)mNx)? v.NRows(): (uint_4)mNx;
|
---|
583 | uint_4 nny = (v.NCol() <(uint_4)mNy)? v.NCol() : (uint_4)mNy;
|
---|
584 | if(nnx>0 && nny>0) for(uint_4 i=0;i<nnx;i++) for(uint_4 j=0;j<nny;j++) {
|
---|
585 | (*this)(i,j) += v(i,j);
|
---|
586 | if(mErr2 && ierr) Error2(i,j) += fabs(v(i,j));
|
---|
587 | }
|
---|
588 | return;
|
---|
589 | }
|
---|
590 |
|
---|
591 | /*!
|
---|
592 | Remplissage des erreurs au carre de l'histo
|
---|
593 | avec les valeurs d'un tableau.
|
---|
594 | */
|
---|
595 | void Histo2D::PutError2(TMatrix<r_8> &v)
|
---|
596 | {
|
---|
597 | //if(v.NRows()!=(uint_4)mNx || v.NCol()!=(uint_4)mNy) throw SzMismatchError("Histo2D::PutError2 ");
|
---|
598 | uint_4 nnx = (v.NRows()<(uint_4)mNx)? v.NRows(): (uint_4)mNx;
|
---|
599 | uint_4 nny = (v.NCol() <(uint_4)mNy)? v.NCol() : (uint_4)mNy;
|
---|
600 | if(nnx>0 && nny>0) {
|
---|
601 | if(!mErr2) Errors();
|
---|
602 | for(uint_4 i=0;i<nnx;i++) for(uint_4 j=0;j<nny;j++) Error2(i,j) = v(i,j);
|
---|
603 | }
|
---|
604 | return;
|
---|
605 | }
|
---|
606 |
|
---|
607 | /*!
|
---|
608 | Addition des erreurs au carre de l'histo
|
---|
609 | avec les valeurs d'un tableau.
|
---|
610 | */
|
---|
611 | void Histo2D::PutError2Add(TMatrix<r_8> &v)
|
---|
612 | {
|
---|
613 | //if(v.NRows()!=(uint_4)mNx || v.NCol()!=(uint_4)mNy) throw SzMismatchError("Histo2D::PutError2Add ");
|
---|
614 | uint_4 nnx = (v.NRows()<(uint_4)mNx)? v.NRows(): (uint_4)mNx;
|
---|
615 | uint_4 nny = (v.NCol() <(uint_4)mNy)? v.NCol() : (uint_4)mNy;
|
---|
616 | if(nnx>0 && nny>0) {
|
---|
617 | if(!mErr2) Errors();
|
---|
618 | for(uint_4 i=0;i<nnx;i++) for(uint_4 j=0;j<nny;j++)
|
---|
619 | if(v(i,j)>0.) Error2(i,j) += v(i,j);
|
---|
620 | }
|
---|
621 | return;
|
---|
622 | }
|
---|
623 |
|
---|
624 | /*!
|
---|
625 | Remplissage des erreurs de l'histo avec les valeurs d'un tableau.
|
---|
626 | */
|
---|
627 | void Histo2D::PutError(TMatrix<r_8> &v)
|
---|
628 | {
|
---|
629 | //if(v.NRows()!=(uint_4)mNx || v.NCol()!=(uint_4)mNy) throw SzMismatchError("Histo2D::PutError ");
|
---|
630 | uint_4 nnx = (v.NRows()<(uint_4)mNx)? v.NRows(): (uint_4)mNx;
|
---|
631 | uint_4 nny = (v.NCol() <(uint_4)mNy)? v.NCol() : (uint_4)mNy;
|
---|
632 | if(nnx>0 && nny>0) {
|
---|
633 | if(!mErr2) Errors();
|
---|
634 | for(uint_4 i=0;i<nnx;i++) for(uint_4 j=0;j<nny;j++)
|
---|
635 | if(v(i,j)>0.) Error2(i,j)=v(i,j)*v(i,j); else Error2(i,j)= -v(i,j)*v(i,j);
|
---|
636 | }
|
---|
637 | return;
|
---|
638 | }
|
---|
639 |
|
---|
640 | ///////////////////////////////////////////////////////////////////
|
---|
641 | /********* Methode *********/
|
---|
642 | /*!
|
---|
643 | Addition du contenu de l'histo pour x,y poids w.
|
---|
644 | */
|
---|
645 | void Histo2D::Add(r_8 x, r_8 y, r_8 w)
|
---|
646 | {
|
---|
647 | list<bande_slice>::iterator it;
|
---|
648 | int_4 i,j;
|
---|
649 | FindBin(x,y,i,j);
|
---|
650 |
|
---|
651 | if( mHprojx != NULL ) mHprojx->Add(x,w);
|
---|
652 | if( mHprojy != NULL ) mHprojy->Add(y,w);
|
---|
653 |
|
---|
654 | if(mLBandx.size()>0)
|
---|
655 | for( it = mLBandx.begin(); it != mLBandx.end(); it++)
|
---|
656 | if( (*it).min <= y && y < (*it).max ) (*it).H->Add(x,w);
|
---|
657 |
|
---|
658 | if(mLBandy.size()>0)
|
---|
659 | for( it = mLBandy.begin(); it != mLBandy.end(); it++)
|
---|
660 | if( (*it).min <= x && x < (*it).max ) (*it).H->Add(y,w);
|
---|
661 |
|
---|
662 | if(mLSlix.size()>0)
|
---|
663 | for( it = mLSlix.begin(); it != mLSlix.end(); it++)
|
---|
664 | if( (*it).min <= y && y < (*it).max ) (*it).H->Add(x,w);
|
---|
665 |
|
---|
666 | if(mLSliy.size()>0)
|
---|
667 | for( it = mLSliy.begin(); it != mLSliy.end(); it++)
|
---|
668 | if( (*it).min <= x && x < (*it).max ) (*it).H->Add(y,w);
|
---|
669 |
|
---|
670 | if( i<0 || i>=mNx || j<0 || j>=mNy ) {
|
---|
671 | if(i<0) i=0; else if(i>=mNx) i=2; else i=1;
|
---|
672 | if(j<0) j=0; else if(j>=mNy) j=2; else j=1;
|
---|
673 | mOver[i][j] += w;
|
---|
674 | mOver[1][1] += w;
|
---|
675 | return;
|
---|
676 | }
|
---|
677 |
|
---|
678 | mData[j*mNx+i] += w;
|
---|
679 | if(mErr2!=NULL) mErr2[j*mNx+i] += w*w;
|
---|
680 | nHist += w;
|
---|
681 | nEntries++;
|
---|
682 | }
|
---|
683 |
|
---|
684 | ///////////////////////////////////////////////////////////////////
|
---|
685 | /*!
|
---|
686 | Recherche du bin du maximum dans le pave [il,ih][jl,jh].
|
---|
687 | */
|
---|
688 | void Histo2D::IJMax(int_4& imax,int_4& jmax,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
|
---|
689 | {
|
---|
690 | if(mNxy<=0) {imax = jmax = -1; return;}
|
---|
691 | if( il > ih ) { il = 0; ih = mNx-1; }
|
---|
692 | if( jl > jh ) { jl = 0; jh = mNy-1; }
|
---|
693 | if( il < 0 ) il = 0;
|
---|
694 | if( jl < 0 ) jl = 0;
|
---|
695 | if( ih >= mNx ) ih = mNx-1;
|
---|
696 | if( jh >= mNy ) jh = mNy-1;
|
---|
697 |
|
---|
698 | imax = jmax = 0;
|
---|
699 | if(mNxy==1) return;
|
---|
700 |
|
---|
701 | r_8 mx=(*this)(il,jl);
|
---|
702 | for (int_4 i=il; i<=ih; i++)
|
---|
703 | for (int_4 j=jl; j<=jh; j++)
|
---|
704 | if ((*this)(i,j)>mx) {imax = i; jmax = j; mx=(*this)(i,j);}
|
---|
705 | }
|
---|
706 |
|
---|
707 | /*!
|
---|
708 | Recherche du bin du minimum dans le pave [il,ih][jl,jh].
|
---|
709 | */
|
---|
710 | void Histo2D::IJMin(int_4& imax,int_4& jmax,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
|
---|
711 | {
|
---|
712 | if(mNxy<=0) {imax = jmax = -1; return;}
|
---|
713 | if( il > ih ) { il = 0; ih = mNx-1; }
|
---|
714 | if( jl > jh ) { jl = 0; jh = mNy-1; }
|
---|
715 | if( il < 0 ) il = 0;
|
---|
716 | if( jl < 0 ) jl = 0;
|
---|
717 | if( ih >= mNx ) ih = mNx-1;
|
---|
718 | if( jh >= mNy ) jh = mNy-1;
|
---|
719 |
|
---|
720 | imax = jmax = 0;
|
---|
721 | if(mNxy==1) return;
|
---|
722 |
|
---|
723 | r_8 mx=(*this)(il,jl);
|
---|
724 | for (int_4 i=il; i<=ih; i++)
|
---|
725 | for (int_4 j=jl; j<=jh; j++)
|
---|
726 | if ((*this)(i,j)<mx) {imax = i; jmax = j; mx=(*this)(i,j);}
|
---|
727 | }
|
---|
728 |
|
---|
729 |
|
---|
730 | /*!
|
---|
731 | Recherche du maximum dans le pave [il,ih][jl,jh].
|
---|
732 | */
|
---|
733 | r_8 Histo2D::VMax(int_4 il,int_4 ih,int_4 jl,int_4 jh) const
|
---|
734 | {
|
---|
735 | if(mNxy<=0) return 0.;
|
---|
736 | if( il > ih ) { il = 0; ih = mNx-1; }
|
---|
737 | if( jl > jh ) { jl = 0; jh = mNy-1; }
|
---|
738 | if( il < 0 ) il = 0;
|
---|
739 | if( jl < 0 ) jl = 0;
|
---|
740 | if( ih >= mNx ) ih = mNx-1;
|
---|
741 | if( jh >= mNy ) jh = mNy-1;
|
---|
742 |
|
---|
743 | r_8 mx=(*this)(il,jl);
|
---|
744 | if(mNxy==1) return mx;
|
---|
745 | for (int_4 i=il; i<=ih; i++)
|
---|
746 | for (int_4 j=jl; j<=jh; j++)
|
---|
747 | if ((*this)(i,j)>mx) mx=(*this)(i,j);
|
---|
748 | return mx;
|
---|
749 | }
|
---|
750 |
|
---|
751 | /*!
|
---|
752 | Recherche du minimum dans le pave [il,ih][jl,jh].
|
---|
753 | */
|
---|
754 | r_8 Histo2D::VMin(int_4 il,int_4 ih,int_4 jl,int_4 jh) const
|
---|
755 | {
|
---|
756 | if(mNxy<=0) return 0.;
|
---|
757 | if( il > ih ) { il = 0; ih = mNx-1; }
|
---|
758 | if( jl > jh ) { jl = 0; jh = mNy-1; }
|
---|
759 | if( il < 0 ) il = 0;
|
---|
760 | if( jl < 0 ) jl = 0;
|
---|
761 | if( ih >= mNx ) ih = mNx-1;
|
---|
762 | if( jh >= mNy ) jh = mNy-1;
|
---|
763 |
|
---|
764 | r_8 mx=(*this)(il,jl);
|
---|
765 | if(mNxy==1) return mx;
|
---|
766 | for (int_4 i=il; i<=ih; i++)
|
---|
767 | for (int_4 j=jl; j<=jh; j++)
|
---|
768 | if ((*this)(i,j)<mx) mx=(*this)(i,j);
|
---|
769 | return mx;
|
---|
770 | }
|
---|
771 |
|
---|
772 | ///////////////////////////////////////////////////////////////////
|
---|
773 | /*!
|
---|
774 | Renvoie les under.overflow dans les 8 quadrants.
|
---|
775 | \verbatim
|
---|
776 | mOver[3][3]: 20 | 21 | 22
|
---|
777 | | |
|
---|
778 | --------------
|
---|
779 | | |
|
---|
780 | 10 | 11 | 12 11 = all overflow+underflow
|
---|
781 | | |
|
---|
782 | --------------
|
---|
783 | | |
|
---|
784 | 00 | 01 | 02
|
---|
785 | \endverbatim
|
---|
786 | */
|
---|
787 | r_8 Histo2D::NOver(int_4 i,int_4 j) const
|
---|
788 | {
|
---|
789 | if( i < 0 || i>=3 || j < 0 || j>=3 ) return mOver[1][1];
|
---|
790 | return mOver[i][j];
|
---|
791 | }
|
---|
792 |
|
---|
793 |
|
---|
794 | ///////////////////////////////////////////////////////////////////
|
---|
795 | /*!
|
---|
796 | Retourne le nombre de bins non-nuls.
|
---|
797 | */
|
---|
798 | int_4 Histo2D::BinNonNul() const
|
---|
799 | {
|
---|
800 | if(mNxy<=0) return -1;
|
---|
801 | int_4 non=0;
|
---|
802 | for (int_4 i=0;i<mNxy;i++) if( mData[i] != 0. ) non++;
|
---|
803 | return non;
|
---|
804 | }
|
---|
805 |
|
---|
806 | /*!
|
---|
807 | Retourne le nombre de bins avec erreurs non-nulles.
|
---|
808 | */
|
---|
809 | int_4 Histo2D::ErrNonNul() const
|
---|
810 | {
|
---|
811 | if(mErr2==NULL) return -1;
|
---|
812 | int_4 non=0;
|
---|
813 | for (int_4 i=0;i<mNxy;i++) if( mErr2[i] != 0. ) non++;
|
---|
814 | return non;
|
---|
815 | }
|
---|
816 |
|
---|
817 | ///////////////////////////////////////////////////////////////////
|
---|
818 | /*!
|
---|
819 | Idem EstimeMax(int...) mais retourne x,y.
|
---|
820 | */
|
---|
821 | int_4 Histo2D::EstimeMax(r_8& xm,r_8& ym,int_4 SzPav
|
---|
822 | ,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
|
---|
823 | {
|
---|
824 | int_4 im,jm;
|
---|
825 | IJMax(im,jm,il,ih,jl,jh);
|
---|
826 | return EstimeMax(im,jm,xm,ym,SzPav);
|
---|
827 | }
|
---|
828 |
|
---|
829 | /*!
|
---|
830 | Determine les abscisses et ordonnees du maximum donne par im,jm
|
---|
831 | en moyennant dans un pave SzPav x SzPav autour du maximum.
|
---|
832 | \verbatim
|
---|
833 | Return:
|
---|
834 | 0 = si fit maximum reussi avec SzPav pixels
|
---|
835 | 1 = si fit maximum reussi avec moins que SzPav pixels
|
---|
836 | dans au moins 1 direction
|
---|
837 | 2 = si fit maximum echoue et renvoit BinCenter()
|
---|
838 | -1 = si echec: SzPav <= 0 ou im,jm hors limites
|
---|
839 | \endverbatim
|
---|
840 | */
|
---|
841 | int_4 Histo2D::EstimeMax(int_4 im,int_4 jm,r_8& xm,r_8& ym,int_4 SzPav) const
|
---|
842 | {
|
---|
843 | xm = ym = 0;
|
---|
844 | if( SzPav <= 0 ) return -1;
|
---|
845 | if( im < 0 || im >= mNx ) return -1;
|
---|
846 | if( jm < 0 || jm >= mNy ) return -1;
|
---|
847 |
|
---|
848 | if( SzPav%2 == 0 ) SzPav++;
|
---|
849 | SzPav = (SzPav-1)/2;
|
---|
850 |
|
---|
851 | int_4 rc = 0;
|
---|
852 | r_8 dxm = 0, dym = 0, wx = 0;
|
---|
853 | for(int_4 i=im-SzPav;i<=im+SzPav;i++) {
|
---|
854 | if( i<0 || i>= mNx ) {rc=1; continue;}
|
---|
855 | for(int_4 j=jm-SzPav;j<=jm+SzPav;j++) {
|
---|
856 | if( j<0 || j>= mNy ) {rc=1; continue;}
|
---|
857 | r_8 x,y;
|
---|
858 | BinCenter(i,j,x,y);
|
---|
859 | dxm += x * (*this)(i,j);
|
---|
860 | dym += y * (*this)(i,j);
|
---|
861 | wx += (*this)(i,j);
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | if( wx > 0. ) {
|
---|
866 | xm = dxm/wx;
|
---|
867 | ym = dym/wx;
|
---|
868 | return rc;
|
---|
869 | } else {
|
---|
870 | BinCenter(im,jm,xm,ym);
|
---|
871 | return 2;
|
---|
872 | }
|
---|
873 |
|
---|
874 | }
|
---|
875 |
|
---|
876 | /*!
|
---|
877 | Pour trouver le maximum de l'histogramme en tenant compte
|
---|
878 | des fluctuations.
|
---|
879 | \verbatim
|
---|
880 | Methode:
|
---|
881 | 1-/ On recherche le bin maximum MAX de l'histogramme
|
---|
882 | 2-/ On considere que tous les pixels compris entre [MAX-Dz,MAX]
|
---|
883 | peuvent etre des pixels maxima.
|
---|
884 | 3-/ On identifie le bin maximum en choissisant le pixel du 2-/
|
---|
885 | tel que la somme des pixels dans un pave SzPav x SzPav soit maximale.
|
---|
886 | INPUT:
|
---|
887 | SzPav = taille du pave pour departager
|
---|
888 | Dz = tolerance pour identifier tous les pixels "maximum"
|
---|
889 | OUTPUT:
|
---|
890 | im,jm = pixel maximum trouve
|
---|
891 | RETURN:
|
---|
892 | <0 = Echec
|
---|
893 | >0 = nombre de pixels possibles pour le maximum
|
---|
894 | \endverbatim
|
---|
895 | */
|
---|
896 | int_4 Histo2D::FindMax(int_4& im,int_4& jm,int_4 SzPav,r_8 Dz
|
---|
897 | ,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
|
---|
898 | {
|
---|
899 | if(mNxy<=0) return -1;
|
---|
900 | if( il > ih ) { il = 0; ih = mNx-1; }
|
---|
901 | if( jl > jh ) { jl = 0; jh = mNy-1; }
|
---|
902 | if( il < 0 ) il = 0;
|
---|
903 | if( jl < 0 ) jl = 0;
|
---|
904 | if( ih >= mNx ) ih = mNx-1;
|
---|
905 | if( jh >= mNy ) jh = mNy-1;
|
---|
906 | if( SzPav < 0 ) SzPav = 0;
|
---|
907 | else { if( SzPav%2 == 0 ) SzPav++; SzPav = (SzPav-1)/2;}
|
---|
908 | if( Dz < 0 ) Dz = 0.;
|
---|
909 | r_8 max = VMax(il,ih,jl,jh) - Dz;
|
---|
910 | int_4 nmax = 0;
|
---|
911 | r_8 sumx = -1.e20;
|
---|
912 | for(int_4 i=il;i<=ih;i++) for(int_4 j=jl;j<=jh;j++) {
|
---|
913 | if( (*this)(i,j) < max) continue;
|
---|
914 | nmax++;
|
---|
915 | r_8 sum = 0.;
|
---|
916 | for(int_4 ii=i-SzPav;ii<=i+SzPav;ii++) {
|
---|
917 | if( ii<0 || ii >= mNx ) continue;
|
---|
918 | for(int_4 jj=j-SzPav;jj<=j+SzPav;jj++) {
|
---|
919 | if( jj<0 || jj >= mNy ) continue;
|
---|
920 | sum += (*this)(ii,jj);
|
---|
921 | }
|
---|
922 | }
|
---|
923 | if(nmax==1 || sum>sumx) {im=i; jm=j; sumx=sum;}
|
---|
924 | }
|
---|
925 | if( nmax <= 0 ) { IJMax(im,jm,il,ih,jl,jh); return 1;}
|
---|
926 | return nmax;
|
---|
927 | }
|
---|
928 |
|
---|
929 | ///////////////////////////////////////////////////////////////////
|
---|
930 | /*!
|
---|
931 | Impression des informations sur l'histogramme.
|
---|
932 | */
|
---|
933 | void Histo2D::Show(ostream & os) const
|
---|
934 | {
|
---|
935 | os << "Histo2D::Show nHist=" << nHist << " nEntries=" << nEntries;
|
---|
936 | if(HasErrors()) os << " Errors=Y \n"; else os << " Errors=N\n";
|
---|
937 | os << "mOver: [ " ;
|
---|
938 | for(int j=2; j>=0; j--) {
|
---|
939 | for(int i=0; i<3; i++)
|
---|
940 | os << mOver[j][i] << " " ;
|
---|
941 | if (j != 0) os << "// ";
|
---|
942 | }
|
---|
943 | os << "]\n";
|
---|
944 | os << " nx=" << mNx << " xmin=" << mXmin << " xmax=" << mXmax
|
---|
945 | << " binx=" << mWBinx ;
|
---|
946 | os << " ny=" << mNy << " ymin=" << mYmin << " ymax=" << mYmax
|
---|
947 | << " biny=" << mWBiny << endl;
|
---|
948 |
|
---|
949 | //printf("mOver: [ %g %g %g // %g %g %g // %g %g %g ]\n"
|
---|
950 | // ,mOver[2][0],mOver[2][1],mOver[2][2]
|
---|
951 | // ,mOver[1][0],mOver[1][1],mOver[1][2]
|
---|
952 | // ,mOver[0][0],mOver[0][1],mOver[0][2]);
|
---|
953 | //printf(" nx=%d xmin=%g xmax=%g binx=%g ",mNx,mXmin,mXmax,mWBinx);
|
---|
954 | //printf(" ny=%d ymin=%g ymax=%g biny=%g\n",mNy,mYmin,mYmax,mWBiny);
|
---|
955 | }
|
---|
956 |
|
---|
957 | ///////////////////////////////////////////////////////////////////
|
---|
958 | /*!
|
---|
959 | Impression de l'histogramme sur stdout entre [il,ih] et [jl,jh].
|
---|
960 | \verbatim
|
---|
961 | numero d'index: 00000000001111111111222222222233333
|
---|
962 | 01234567890123456789012345678901234
|
---|
963 | valeur entiere: 00000000001111111111222222222233333
|
---|
964 | 12345678901234567890123456789012345
|
---|
965 | \endverbatim
|
---|
966 | */
|
---|
967 | void Histo2D::Print(r_8 min,r_8 max
|
---|
968 | ,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
|
---|
969 | {
|
---|
970 | if(mNxy<=0) return;
|
---|
971 | int_4 ns = 35;
|
---|
972 | const char *s = "+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
---|
973 |
|
---|
974 | if( il > ih ) { il = 0; ih = mNx-1; }
|
---|
975 | if( jl > jh ) { jl = 0; jh = mNy-1; }
|
---|
976 | if( il < 0 ) il = 0;
|
---|
977 | if( jl < 0 ) jl = 0;
|
---|
978 | if( ih >= mNx ) ih = mNx-1;
|
---|
979 | if( jh >= mNy ) jh = mNy-1;
|
---|
980 |
|
---|
981 | PrintStatus();
|
---|
982 |
|
---|
983 | if( il != 0 || ih != mNx-1 || jl != 0 || jh != mNy-1 ) {
|
---|
984 | r_8 xl,xh,yl,yh;
|
---|
985 | BinLowEdge(il,jl,xl,yl);
|
---|
986 | BinHighEdge(ih,jh,xh,yh);
|
---|
987 | printf(" impression");
|
---|
988 | printf(" en X: %d=[%d,%d] xmin=%g xmax=%g "
|
---|
989 | ,ih-il+1,il,ih,xl,xh);
|
---|
990 | printf(" en Y: %d=[%d,%d] ymin=%g ymax=%g\n"
|
---|
991 | ,jh-jl+1,jl,jh,yl,yh);
|
---|
992 | }
|
---|
993 |
|
---|
994 | if(min >= max) { if(min != 0.) min = VMin(il,ih,jl,jh); else min=0.;
|
---|
995 | max = VMax(il,ih,jl,jh); }
|
---|
996 | if(min>max) return;
|
---|
997 | if(min==max) {min -= 1.; max += 1.;}
|
---|
998 | printf(" min=%g max=%g\n",min,max);
|
---|
999 |
|
---|
1000 | // imprime numero de bin en colonne
|
---|
1001 | printf("\n");
|
---|
1002 | if( mNx-1 >= 100 ) {
|
---|
1003 | printf(" ");
|
---|
1004 | for(int_4 i=il;i<=ih;i++) printf("%1d",(int_4) (i%1000)/100);
|
---|
1005 | printf("\n");
|
---|
1006 | }
|
---|
1007 | if( mNx-1 >= 10 ) {
|
---|
1008 | printf(" ");
|
---|
1009 | for(int_4 i=il;i<=ih;i++) printf("%1d",(int_4) (i%100)/10);
|
---|
1010 | printf("\n");
|
---|
1011 | }
|
---|
1012 | printf(" ");
|
---|
1013 | for(int_4 i=il;i<=ih;i++) printf("%1d",i%10);
|
---|
1014 | printf("\n");
|
---|
1015 | printf(" "); {for(int_4 i=il;i<=ih;i++) printf("-"); printf("\n");}
|
---|
1016 |
|
---|
1017 | // imprime histogramme
|
---|
1018 | for(int_4 j=jh;j>=jl;j--) {
|
---|
1019 | printf("%3d: ",j);
|
---|
1020 | for(int_4 i=il;i<=ih;i++) {
|
---|
1021 | int_4 h;
|
---|
1022 | if( 1<=max-min && max-min<=35 ) h = (int_4)( (*this)(i,j) - min ) - 1;
|
---|
1023 | else h = (int_4)( ((*this)(i,j)-min)/(max-min) * ns ) - 1;
|
---|
1024 | char c;
|
---|
1025 | if(h<0 && (*this)(i,j)>min) c = '.';
|
---|
1026 | else if(h<0) c = ' ';
|
---|
1027 | else if(h>=ns) c = '*';
|
---|
1028 | else c = s[h];
|
---|
1029 | printf("%c",c);
|
---|
1030 | }
|
---|
1031 | printf("\n");
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | // imprime numero de bin en colonne
|
---|
1035 | printf(" "); {for(int_4 i=il;i<=ih;i++) printf("-"); printf("\n");}
|
---|
1036 | if( mNx-1 >= 100 ) {
|
---|
1037 | printf(" ");
|
---|
1038 | for(int_4 i=il;i<=ih;i++) printf("%1d",(int_4) (i%1000)/100);
|
---|
1039 | printf("\n");
|
---|
1040 | }
|
---|
1041 | if( mNx-1 >= 10 ) {
|
---|
1042 | printf(" ");
|
---|
1043 | for(int_4 i=il;i<=ih;i++) printf("%1d",(int_4) (i%100)/10);
|
---|
1044 | printf("\n");
|
---|
1045 | }
|
---|
1046 | printf(" ");
|
---|
1047 | {for(int_4 i=il;i<=ih;i++) printf("%1d",i%10);}
|
---|
1048 | printf("\n");
|
---|
1049 |
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | ///////////////////////////////////////////////////////////////////
|
---|
1053 | // Titre Methodes pour gerer les projections
|
---|
1054 |
|
---|
1055 | /*!
|
---|
1056 | Pour creer la projection X.
|
---|
1057 | */
|
---|
1058 | void Histo2D::SetProjX()
|
---|
1059 | {
|
---|
1060 | if( mHprojx != NULL ) DelProjX();
|
---|
1061 | mHprojx = new Histo(mXmin,mXmax,mNx);
|
---|
1062 | if(mErr2 && mHprojx) mHprojx->Errors();
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | /*!
|
---|
1066 | Pour creer la projection Y.
|
---|
1067 | */
|
---|
1068 | void Histo2D::SetProjY()
|
---|
1069 | {
|
---|
1070 | if( mHprojy != NULL ) DelProjY();
|
---|
1071 | mHprojy = new Histo(mYmin,mYmax,mNy);
|
---|
1072 | if(mErr2 && mHprojy) mHprojy->Errors();
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | /*!
|
---|
1076 | Pour creer les projections X et Y.
|
---|
1077 | */
|
---|
1078 | void Histo2D::SetProj()
|
---|
1079 | {
|
---|
1080 | SetProjX();
|
---|
1081 | SetProjY();
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | /*!
|
---|
1085 | Informations sur les projections.
|
---|
1086 | */
|
---|
1087 | void Histo2D::ShowProj() const
|
---|
1088 | {
|
---|
1089 | if( mHprojx != NULL ) cout << ">>>> Projection X set : "<< mHprojx <<endl;
|
---|
1090 | else cout << ">>>> NO Projection X set"<<endl;
|
---|
1091 | if( mHprojy != NULL ) cout << ">>>> Projection Y set : "<< mHprojy <<endl;
|
---|
1092 | else cout << ">>>> NO Projection Y set"<<endl;
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | /*!
|
---|
1096 | Destruction de l'histogramme de la projection selon X.
|
---|
1097 | */
|
---|
1098 | void Histo2D::DelProjX()
|
---|
1099 | {
|
---|
1100 | if( mHprojx == NULL ) return;
|
---|
1101 | delete mHprojx;
|
---|
1102 | mHprojx = NULL;
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | /*!
|
---|
1106 | Destruction de l'histogramme de la projection selon X.
|
---|
1107 | */
|
---|
1108 | void Histo2D::DelProjY()
|
---|
1109 | {
|
---|
1110 | if( mHprojy == NULL ) return;
|
---|
1111 | delete mHprojy;
|
---|
1112 | mHprojy = NULL;
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | /*!
|
---|
1116 | Destruction des histogrammes des projections selon X et Y.
|
---|
1117 | */
|
---|
1118 | void Histo2D::DelProj()
|
---|
1119 | {
|
---|
1120 | DelProjX();
|
---|
1121 | DelProjY();
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 | /*!
|
---|
1125 | Remise a zero de la projection selon X.
|
---|
1126 | */
|
---|
1127 | void Histo2D::ZeroProjX()
|
---|
1128 | {
|
---|
1129 | if( mHprojx == NULL ) return;
|
---|
1130 | mHprojx->Zero();
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | /*!
|
---|
1134 | Remise a zero de la projection selon Y.
|
---|
1135 | */
|
---|
1136 | void Histo2D::ZeroProjY()
|
---|
1137 | {
|
---|
1138 | if( mHprojy == NULL ) return;
|
---|
1139 | mHprojy->Zero();
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | /*!
|
---|
1143 | Remise a zero des projections selon X et Y.
|
---|
1144 | */
|
---|
1145 | void Histo2D::ZeroProj()
|
---|
1146 | {
|
---|
1147 | ZeroProjX();
|
---|
1148 | ZeroProjY();
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | ///////////////////////////////////////////////////////////////////
|
---|
1152 | // Titre Methodes pour gerer les bandes
|
---|
1153 |
|
---|
1154 | /*!
|
---|
1155 | Pour creer une bande en X entre ybmin et ybmax.
|
---|
1156 | */
|
---|
1157 | int_4 Histo2D::SetBandX(r_8 ybmin,r_8 ybmax)
|
---|
1158 | {
|
---|
1159 | mB_s.num = mLBandx.size();
|
---|
1160 | mB_s.min = ybmin;
|
---|
1161 | mB_s.max = ybmax;
|
---|
1162 | mB_s.H = new Histo(mXmin,mXmax,mNx);
|
---|
1163 | if(mErr2 && mB_s.H) mB_s.H->Errors();
|
---|
1164 | mLBandx.push_back(mB_s);
|
---|
1165 | mB_s.H = NULL;
|
---|
1166 | return mLBandx.size()-1;
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | /*!
|
---|
1170 | Pour creer une bande en Y entre xbmin et xbmax.
|
---|
1171 | */
|
---|
1172 | int_4 Histo2D::SetBandY(r_8 xbmin,r_8 xbmax)
|
---|
1173 | {
|
---|
1174 | mB_s.num = mLBandy.size();
|
---|
1175 | mB_s.min = xbmin;
|
---|
1176 | mB_s.max = xbmax;
|
---|
1177 | mB_s.H = new Histo(mYmin,mYmax,mNy);
|
---|
1178 | if(mErr2 && mB_s.H) mB_s.H->Errors();
|
---|
1179 | mLBandy.push_back(mB_s);
|
---|
1180 | mB_s.H = NULL;
|
---|
1181 | return mLBandy.size()-1;
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | /*!
|
---|
1185 | Destruction des histogrammes des bandes selon X.
|
---|
1186 | */
|
---|
1187 | void Histo2D::DelBandX()
|
---|
1188 | {
|
---|
1189 | if( mLBandx.size() <= 0 ) return;
|
---|
1190 | for(list<bande_slice>::iterator i = mLBandx.begin(); i != mLBandx.end(); i++)
|
---|
1191 | if( (*i).H != NULL ) {delete (*i).H; (*i).H=NULL;}
|
---|
1192 | mLBandx.erase(mLBandx.begin(),mLBandx.end());
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | /*!
|
---|
1196 | Destruction des histogrammes des bandes selon Y.
|
---|
1197 | */
|
---|
1198 | void Histo2D::DelBandY()
|
---|
1199 | {
|
---|
1200 | if( mLBandy.size() <= 0 ) return;
|
---|
1201 | for(list<bande_slice>::iterator i = mLBandy.begin(); i != mLBandy.end(); i++)
|
---|
1202 | if( (*i).H != NULL ) {delete (*i).H; (*i).H=NULL;}
|
---|
1203 | mLBandy.erase(mLBandy.begin(),mLBandy.end());
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | /*!
|
---|
1207 | Remise a zero des bandes selon X.
|
---|
1208 | */
|
---|
1209 | void Histo2D::ZeroBandX()
|
---|
1210 | {
|
---|
1211 | if( mLBandx.size() <= 0 ) return;
|
---|
1212 | list<bande_slice>::iterator i;
|
---|
1213 | for(i = mLBandx.begin(); i != mLBandx.end(); i++)
|
---|
1214 | (*i).H->Zero();
|
---|
1215 | }
|
---|
1216 |
|
---|
1217 | /*!
|
---|
1218 | Remise a zero des bandes selon Y.
|
---|
1219 | */
|
---|
1220 | void Histo2D::ZeroBandY()
|
---|
1221 | {
|
---|
1222 | if( mLBandy.size() <= 0 ) return;
|
---|
1223 | list<bande_slice>::iterator i;
|
---|
1224 | for(i = mLBandy.begin(); i != mLBandy.end(); i++)
|
---|
1225 | (*i).H->Zero();
|
---|
1226 | }
|
---|
1227 |
|
---|
1228 | /*!
|
---|
1229 | Retourne un pointeur sur la bande numero `n' selon X.
|
---|
1230 | */
|
---|
1231 | Histo* Histo2D::HBandX(int_4 n) const
|
---|
1232 | {
|
---|
1233 | if( mLBandx.size() <= 0 || n < 0 || n >= (int_4) mLBandx.size() ) return NULL;
|
---|
1234 | for(list<bande_slice>::const_iterator i = mLBandx.begin(); i != mLBandx.end(); i++)
|
---|
1235 | if( (*i).num == n ) return (*i).H;
|
---|
1236 | return NULL;
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | /*!
|
---|
1240 | Retourne un pointeur sur la bande numero `n' selon Y.
|
---|
1241 | */
|
---|
1242 | Histo* Histo2D::HBandY(int_4 n) const
|
---|
1243 | {
|
---|
1244 | if( mLBandy.size() <= 0 || n < 0 || n >= (int_4) mLBandy.size() ) return NULL;
|
---|
1245 | for(list<bande_slice>::const_iterator i = mLBandy.begin(); i != mLBandy.end(); i++)
|
---|
1246 | if( (*i).num == n ) return (*i).H;
|
---|
1247 | return NULL;
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 | /*!
|
---|
1251 | Retourne les limites de la bande numero `n' selon X.
|
---|
1252 | */
|
---|
1253 | void Histo2D::GetBandX(int_4 n,r_8& ybmin,r_8& ybmax) const
|
---|
1254 | {
|
---|
1255 | ybmin = 0.; ybmax = 0.;
|
---|
1256 | if( mLBandx.size() <= 0 || n < 0 || n >= (int_4) mLBandx.size() ) return;
|
---|
1257 | for(list<bande_slice>::const_iterator i = mLBandx.begin(); i != mLBandx.end(); i++)
|
---|
1258 | if( (*i).num == n ) { ybmin = (*i).min; ybmax = (*i).max; return;}
|
---|
1259 | return;
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 | /*!
|
---|
1263 | Retourne les limites de la bande numero `n' selon Y.
|
---|
1264 | */
|
---|
1265 | void Histo2D::GetBandY(int_4 n,r_8& xbmin,r_8& xbmax) const
|
---|
1266 | {
|
---|
1267 | xbmin = 0.; xbmax = 0.;
|
---|
1268 | if( mLBandy.size() <= 0 || n < 0 || n >= (int_4) mLBandy.size() ) return;
|
---|
1269 | for(list<bande_slice>::const_iterator i = mLBandy.begin(); i != mLBandy.end(); i++)
|
---|
1270 | if( (*i).num == n ) { xbmin = (*i).min; xbmax = (*i).max; return;}
|
---|
1271 | return;
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 | /*!
|
---|
1275 | Informations sur les bandes.
|
---|
1276 | */
|
---|
1277 | void Histo2D::ShowBand(int_4 lp) const
|
---|
1278 | {
|
---|
1279 | cout << ">>>> Nombre de bande X : " << mLBandx.size() << endl;
|
---|
1280 | if( lp>0 && mLBandx.size()>0 ) {
|
---|
1281 | list<bande_slice>::const_iterator i;
|
---|
1282 | for(i = mLBandx.begin(); i != mLBandx.end(); i++) {
|
---|
1283 | cout<<" "<<(*i).num<<" de ymin="<<(*i).min<<" a ymax="<<(*i).max;
|
---|
1284 | if(lp>1) cout << " H=" << (*i).H;
|
---|
1285 | cout << endl;
|
---|
1286 | }
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | cout << ">>>> Nombre de bande Y : " << mLBandy.size() << endl;
|
---|
1290 | if( lp>0 && mLBandy.size()>0 ) {
|
---|
1291 | list<bande_slice>::const_iterator i;
|
---|
1292 | for(i = mLBandy.begin(); i != mLBandy.end(); i++) {
|
---|
1293 | cout<<" "<<(*i).num<<" de xmin="<<(*i).min<<" a xmax="<<(*i).max;
|
---|
1294 | if(lp>1) cout << " H=" << (*i).H;
|
---|
1295 | cout << endl;
|
---|
1296 | }
|
---|
1297 | }
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | ///////////////////////////////////////////////////////////////////
|
---|
1301 | // Titre Methodes pour gerer les bandes equidistantes ou slices
|
---|
1302 |
|
---|
1303 | /*!
|
---|
1304 | Pour creer `nsli' bandes equidistantes selon X.
|
---|
1305 | */
|
---|
1306 | int_4 Histo2D::SetSliX(int_4 nsli)
|
---|
1307 | {
|
---|
1308 | if( nsli <= 0 ) return -1;
|
---|
1309 | if( nsli > mNy ) nsli = mNy;
|
---|
1310 | if( mLSlix.size() > 0 ) DelSliX();
|
---|
1311 | r_8 w = (mYmax-mYmin)/nsli;
|
---|
1312 |
|
---|
1313 | for(int_4 i=0; i<nsli; i++ ) {
|
---|
1314 | mB_s.num = i;
|
---|
1315 | mB_s.min = mYmin + i*w;
|
---|
1316 | mB_s.max = mB_s.min + w;
|
---|
1317 | mB_s.H = new Histo(mXmin,mXmax,mNx);
|
---|
1318 | if(mErr2 && mB_s.H) mB_s.H->Errors();
|
---|
1319 | mLSlix.push_back(mB_s);
|
---|
1320 | mB_s.H = NULL;
|
---|
1321 | }
|
---|
1322 | return (int_4) mLSlix.size();
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | /*!
|
---|
1326 | Pour creer `nsli' bandes equidistantes selon Y.
|
---|
1327 | */
|
---|
1328 | int_4 Histo2D::SetSliY(int_4 nsli)
|
---|
1329 | {
|
---|
1330 | if( nsli <= 0 ) return -1;
|
---|
1331 | if( nsli > mNx ) nsli = mNx;
|
---|
1332 | if( mLSliy.size() > 0 ) DelSliY();
|
---|
1333 | r_8 w = (mXmax-mXmin)/nsli;
|
---|
1334 |
|
---|
1335 | for(int_4 i=0; i<nsli; i++ ) {
|
---|
1336 | mB_s.num = i;
|
---|
1337 | mB_s.min = mXmin + i*w;
|
---|
1338 | mB_s.max = mB_s.min + w;
|
---|
1339 | mB_s.H = new Histo(mYmin,mYmax,mNy);
|
---|
1340 | if(mErr2 && mB_s.H) mB_s.H->Errors();
|
---|
1341 | mLSliy.push_back(mB_s);
|
---|
1342 | mB_s.H = NULL;
|
---|
1343 | }
|
---|
1344 | return (int_4) mLSliy.size();
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | /*!
|
---|
1348 | Destruction des bandes equidistantes selon X.
|
---|
1349 | */
|
---|
1350 | void Histo2D::DelSliX()
|
---|
1351 | {
|
---|
1352 | if( mLSlix.size() <= 0 ) return;
|
---|
1353 | for(list<bande_slice>::iterator i = mLSlix.begin(); i != mLSlix.end(); i++)
|
---|
1354 | if( (*i).H != NULL ) {delete (*i).H; (*i).H=NULL;}
|
---|
1355 | mLSlix.erase(mLSlix.begin(),mLSlix.end());
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | /*!
|
---|
1359 | Destruction des bandes equidistantes selon Y.
|
---|
1360 | */
|
---|
1361 | void Histo2D::DelSliY()
|
---|
1362 | {
|
---|
1363 | if( mLSliy.size() <= 0 ) return;
|
---|
1364 | for(list<bande_slice>::iterator i = mLSliy.begin(); i != mLSliy.end(); i++)
|
---|
1365 | if( (*i).H != NULL ) {delete (*i).H; (*i).H=NULL;}
|
---|
1366 | mLSliy.erase(mLSliy.begin(),mLSliy.end());
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | /*!
|
---|
1370 | Remise a zero des bandes equidistantes selon X.
|
---|
1371 | */
|
---|
1372 | void Histo2D::ZeroSliX()
|
---|
1373 | {
|
---|
1374 | if( mLSlix.size() <= 0 ) return;
|
---|
1375 | list<bande_slice>::iterator i;
|
---|
1376 | for(i = mLSlix.begin(); i != mLSlix.end(); i++)
|
---|
1377 | (*i).H->Zero();
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | /*!
|
---|
1381 | Remise a zero des bandes equidistantes selon Y.
|
---|
1382 | */
|
---|
1383 | void Histo2D::ZeroSliY()
|
---|
1384 | {
|
---|
1385 | if( mLSliy.size() <= 0 ) return;
|
---|
1386 | list<bande_slice>::iterator i;
|
---|
1387 | for(i = mLSliy.begin(); i != mLSliy.end(); i++)
|
---|
1388 | (*i).H->Zero();
|
---|
1389 | }
|
---|
1390 |
|
---|
1391 | /*!
|
---|
1392 | Retourne un pointeur sur la bande equidistante numero `n'
|
---|
1393 | selon X.
|
---|
1394 | */
|
---|
1395 | Histo* Histo2D::HSliX(int_4 n) const
|
---|
1396 | {
|
---|
1397 | if( mLSlix.size() <= 0 || n < 0 || n >= (int_4) mLSlix.size() ) return NULL;
|
---|
1398 | for(list<bande_slice>::const_iterator i = mLSlix.begin(); i != mLSlix.end(); i++)
|
---|
1399 | if( (*i).num == n ) return (*i).H;
|
---|
1400 | return NULL;
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | /*!
|
---|
1404 | Retourne un pointeur sur la bande equidistante numero `n'
|
---|
1405 | selon Y.
|
---|
1406 | */
|
---|
1407 | Histo* Histo2D::HSliY(int_4 n) const
|
---|
1408 | {
|
---|
1409 | if( mLSliy.size() <= 0 || n < 0 || n >= (int_4) mLSliy.size() ) return NULL;
|
---|
1410 | for(list<bande_slice>::const_iterator i = mLSliy.begin(); i != mLSliy.end(); i++)
|
---|
1411 | if( (*i).num == n ) return (*i).H;
|
---|
1412 | return NULL;
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 | /*!
|
---|
1416 | Retourne les limites de la bande equidistante numero `n' selon X.
|
---|
1417 | */
|
---|
1418 | void Histo2D::GetSliX(int_4 n,r_8& ybmin,r_8& ybmax) const
|
---|
1419 | {
|
---|
1420 | ybmin = 0.; ybmax = 0.;
|
---|
1421 | if( mLSlix.size() <= 0 || n < 0 || n >= (int_4) mLSlix.size() ) return;
|
---|
1422 | for(list<bande_slice>::const_iterator i = mLSlix.begin(); i != mLSlix.end(); i++)
|
---|
1423 | if( (*i).num == n ) { ybmin = (*i).min; ybmax = (*i).max; return;}
|
---|
1424 | return;
|
---|
1425 | }
|
---|
1426 |
|
---|
1427 | /*!
|
---|
1428 | Retourne les limites de la bande equidistante numero `n' selon Y.
|
---|
1429 | */
|
---|
1430 | void Histo2D::GetSliY(int_4 n,r_8& xbmin,r_8& xbmax) const
|
---|
1431 | {
|
---|
1432 | xbmin = 0.; xbmax = 0.;
|
---|
1433 | if( mLSliy.size() <= 0 || n < 0 || n >= (int_4) mLSliy.size() ) return;
|
---|
1434 | for(list<bande_slice>::const_iterator i = mLSliy.begin(); i != mLSliy.end(); i++)
|
---|
1435 | if( (*i).num == n ) { xbmin = (*i).min; xbmax = (*i).max; return;}
|
---|
1436 | return;
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 | /*!
|
---|
1440 | Informations sur les bandes equidistantes.
|
---|
1441 | */
|
---|
1442 | void Histo2D::ShowSli(int_4 lp) const
|
---|
1443 | {
|
---|
1444 | list<bande_slice>::const_iterator i;
|
---|
1445 | cout << ">>>> Nombre de slice X : " << mLSlix.size() << endl;
|
---|
1446 | if( lp>0 && mLSlix.size() > 0 )
|
---|
1447 | for(i = mLSlix.begin(); i != mLSlix.end(); i++) {
|
---|
1448 | cout<<" "<<(*i).num<<" de ymin="<<(*i).min<<" a ymax="<<(*i).max;
|
---|
1449 | if(lp>1) cout << " H=" << (*i).H;
|
---|
1450 | cout << endl;
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | cout << ">>>> Nombre de slice Y : " << mLSliy.size() << endl;
|
---|
1454 | if( lp>0 && mLSliy.size()>0 )
|
---|
1455 | for(i = mLSliy.begin(); i != mLSliy.end(); i++) {
|
---|
1456 | cout<<" "<<(*i).num<<" de xmin="<<(*i).min<<" a xmax="<<(*i).max;
|
---|
1457 | if(lp>1) cout << " H=" << (*i).H;
|
---|
1458 | cout << endl;
|
---|
1459 | }
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | ///////////////////////////////////////////////////////////
|
---|
1463 | // --------------------------------------------------------
|
---|
1464 | // Les objets delegues pour la gestion de persistance
|
---|
1465 | // --------------------------------------------------------
|
---|
1466 | ///////////////////////////////////////////////////////////
|
---|
1467 |
|
---|
1468 |
|
---|
1469 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
1470 | void ObjFileIO<Histo2D>::ReadSelf(PInPersist& is)
|
---|
1471 | {
|
---|
1472 | char strg[256];
|
---|
1473 |
|
---|
1474 | if(dobj==NULL) dobj=new Histo2D;
|
---|
1475 | else dobj->Delete();
|
---|
1476 |
|
---|
1477 | r_8 min,max;
|
---|
1478 | int_4 errok, projx, projy, nslix, nsliy, nbanx, nbany;
|
---|
1479 |
|
---|
1480 | // Lecture entete
|
---|
1481 | is.GetLine(strg, 255);
|
---|
1482 | is.GetLine(strg, 255);
|
---|
1483 | is.GetLine(strg, 255);
|
---|
1484 | is.GetLine(strg, 255);
|
---|
1485 | is.GetLine(strg, 255);
|
---|
1486 | is.GetLine(strg, 255);
|
---|
1487 |
|
---|
1488 | // Lecture variables de definitions
|
---|
1489 | is.Get(dobj->mNx);
|
---|
1490 | is.Get(dobj->mNy);
|
---|
1491 | is.Get(dobj->mNxy);
|
---|
1492 | is.Get(errok);
|
---|
1493 | is.Get(dobj->nEntries);
|
---|
1494 | is.Get(dobj->nHist);
|
---|
1495 |
|
---|
1496 | is.Get(dobj->mXmin);
|
---|
1497 | is.Get(dobj->mXmax);
|
---|
1498 | is.Get(dobj->mYmin);
|
---|
1499 | is.Get(dobj->mYmax);
|
---|
1500 | is.Get(dobj->mWBinx);
|
---|
1501 | is.Get(dobj->mWBiny);
|
---|
1502 |
|
---|
1503 | is.Get(&(dobj->mOver[0][0]),9);
|
---|
1504 |
|
---|
1505 | is.Get(projx);
|
---|
1506 | is.Get(projy);
|
---|
1507 | is.Get(nslix);
|
---|
1508 | is.Get(nsliy);
|
---|
1509 | is.Get(nbanx);
|
---|
1510 | is.Get(nbany);
|
---|
1511 |
|
---|
1512 | // Lecture histo2D
|
---|
1513 | dobj->mData = new r_8[dobj->mNxy];
|
---|
1514 | is.GetLine(strg, 255);
|
---|
1515 | {for(int_4 j=0;j<dobj->mNy;j++) is.Get(dobj->mData+j*dobj->mNx,dobj->mNx);}
|
---|
1516 |
|
---|
1517 | // Lecture erreurs
|
---|
1518 | if(errok) {
|
---|
1519 | is.GetLine(strg, 255);
|
---|
1520 | dobj->mErr2 = new r_8[dobj->mNxy];
|
---|
1521 | for(int_4 j=0;j<dobj->mNy;j++) is.Get(dobj->mErr2+j*dobj->mNx,dobj->mNx);
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | // Lecture des projections
|
---|
1525 | if(projx) {
|
---|
1526 | is.GetLine(strg, 255);
|
---|
1527 | dobj->SetProjX();
|
---|
1528 | ObjFileIO<Histo> fio_h(dobj->mHprojx);
|
---|
1529 | fio_h.Read(is);
|
---|
1530 | }
|
---|
1531 | if(projy) {
|
---|
1532 | is.GetLine(strg, 255);
|
---|
1533 | dobj->SetProjY();
|
---|
1534 | ObjFileIO<Histo> fio_h(dobj->mHprojy);
|
---|
1535 | fio_h.Read(is);
|
---|
1536 | }
|
---|
1537 |
|
---|
1538 | // Lecture des slices
|
---|
1539 | if(nslix>0) {
|
---|
1540 | is.GetLine(strg, 255);
|
---|
1541 | dobj->SetSliX(nslix);
|
---|
1542 | ASSERT (nslix==dobj->NSliX());
|
---|
1543 | for(int_4 j=0;j<dobj->NSliX();j++)
|
---|
1544 | {ObjFileIO<Histo> fio_h(dobj->HSliX(j)); fio_h.Read(is);}
|
---|
1545 | }
|
---|
1546 | if(nsliy>0) {
|
---|
1547 | is.GetLine(strg, 255);
|
---|
1548 | dobj->SetSliY(nsliy);
|
---|
1549 | ASSERT (nsliy==dobj->NSliY());
|
---|
1550 | for(int_4 j=0;j<dobj->NSliY();j++)
|
---|
1551 | {ObjFileIO<Histo> fio_h(dobj->HSliY(j)); fio_h.Read(is);}
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | // Lecture des bandes
|
---|
1555 | if( nbanx>0 ) {
|
---|
1556 | is.GetLine(strg, 255);
|
---|
1557 | {for(int_4 j=0; j<nbanx; j++) {
|
---|
1558 | is.Get(min); is.Get(max);
|
---|
1559 | dobj->SetBandX(min,max);
|
---|
1560 | }}
|
---|
1561 | ASSERT (nbanx==dobj->NBandX());
|
---|
1562 | {for(int_4 j=0; j<dobj->NBandX(); j++) {
|
---|
1563 | ObjFileIO<Histo> fio_h(dobj->HBandX(j));
|
---|
1564 | fio_h.Read(is);
|
---|
1565 | }}
|
---|
1566 | }
|
---|
1567 | if( nbany>0 ) {
|
---|
1568 | is.GetLine(strg, 255);
|
---|
1569 | {for(int_4 j=0; j<nbany; j++) {
|
---|
1570 | is.Get(min); is.Get(max);
|
---|
1571 | dobj->SetBandY(min,max);
|
---|
1572 | }}
|
---|
1573 | ASSERT (nbany==dobj->NBandY());
|
---|
1574 | {for(int_4 j=0; j<dobj->NBandY(); j++) {
|
---|
1575 | ObjFileIO<Histo> fio_h(dobj->HBandY(j));
|
---|
1576 | fio_h.Read(is);
|
---|
1577 | }}
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | return;
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
1584 | void ObjFileIO<Histo2D>::WriteSelf(POutPersist& os) const
|
---|
1585 | {
|
---|
1586 | if (dobj == NULL) return;
|
---|
1587 | char strg[256];
|
---|
1588 |
|
---|
1589 | // Que faut-il ecrire?
|
---|
1590 | int_4 errok = (dobj->mErr2) ? 1 : 0;
|
---|
1591 | int_4 projx = (dobj->mHprojx) ? 1 : 0;
|
---|
1592 | int_4 projy = (dobj->mHprojy) ? 1 : 0;
|
---|
1593 | int_4 nslix = dobj->NSliX();
|
---|
1594 | int_4 nsliy = dobj->NSliY();
|
---|
1595 | int_4 nbanx = dobj->NBandX();
|
---|
1596 | int_4 nbany = dobj->NBandY();
|
---|
1597 |
|
---|
1598 | // Ecriture entete pour identifier facilement
|
---|
1599 | sprintf(strg,"nx=%d ny=%d nxy=%d errok=%1d"
|
---|
1600 | ,dobj->mNx,dobj->mNy,dobj->mNxy,errok);
|
---|
1601 | os.PutLine(strg);
|
---|
1602 | sprintf(strg,"nHist=%g nEntries=%d",dobj->nHist,dobj->nEntries);
|
---|
1603 | os.PutLine(strg);
|
---|
1604 | sprintf(strg,"wbinx=%g wbiny=%g",dobj->mWBinx,dobj->mWBiny);
|
---|
1605 | os.PutLine(strg);
|
---|
1606 | sprintf(strg,"xmin=%g xmax=%g ymin=%g ymax=%g"
|
---|
1607 | ,dobj->mXmin,dobj->mXmax,dobj->mYmin,dobj->mYmax);
|
---|
1608 | os.PutLine(strg);
|
---|
1609 | sprintf(strg,"projx/y=%d %d nbandx/y=%d %d nbslix/y=%d %d"
|
---|
1610 | ,projx,projy,nbanx,nbany,nslix,nsliy);
|
---|
1611 | os.PutLine(strg);
|
---|
1612 | sprintf(strg,"mOver %g %g %g %g %g %g %g %g %g"
|
---|
1613 | ,dobj->mOver[0][0],dobj->mOver[0][1],dobj->mOver[0][2]
|
---|
1614 | ,dobj->mOver[1][0],dobj->mOver[1][1],dobj->mOver[1][2]
|
---|
1615 | ,dobj->mOver[2][0],dobj->mOver[2][1],dobj->mOver[2][2]);
|
---|
1616 | os.PutLine(strg);
|
---|
1617 |
|
---|
1618 | // Ecriture variables de definitions
|
---|
1619 | os.Put(dobj->mNx);
|
---|
1620 | os.Put(dobj->mNy);
|
---|
1621 | os.Put(dobj->mNxy);
|
---|
1622 | os.Put(errok);
|
---|
1623 | os.Put(dobj->nEntries);
|
---|
1624 | os.Put(dobj->nHist);
|
---|
1625 |
|
---|
1626 | os.Put(dobj->mXmin);
|
---|
1627 | os.Put(dobj->mXmax);
|
---|
1628 | os.Put(dobj->mYmin);
|
---|
1629 | os.Put(dobj->mYmax);
|
---|
1630 | os.Put(dobj->mWBinx);
|
---|
1631 | os.Put(dobj->mWBiny);
|
---|
1632 |
|
---|
1633 | os.Put(&(dobj->mOver[0][0]),9);
|
---|
1634 |
|
---|
1635 | os.Put(projx);
|
---|
1636 | os.Put(projy);
|
---|
1637 | os.Put(nslix);
|
---|
1638 | os.Put(nsliy);
|
---|
1639 | os.Put(nbanx);
|
---|
1640 | os.Put(nbany);
|
---|
1641 |
|
---|
1642 | // Ecriture histo2D
|
---|
1643 | sprintf(strg,"Histo2D: Tableau des donnees %d = %d * %d"
|
---|
1644 | ,dobj->mNxy,dobj->mNx,dobj->mNy);
|
---|
1645 | os.PutLine(strg);
|
---|
1646 | {for(int_4 j=0;j<dobj->mNy;j++) os.Put(dobj->mData+j*dobj->mNx,dobj->mNx);}
|
---|
1647 |
|
---|
1648 | // Ecriture erreurs
|
---|
1649 | if(errok) {
|
---|
1650 | sprintf(strg,"Histo2D: Tableau des erreurs %d = %d * %d"
|
---|
1651 | ,dobj->mNxy,dobj->mNx,dobj->mNy);
|
---|
1652 | os.PutLine(strg);
|
---|
1653 | for(int_4 j=0;j<dobj->mNy;j++) os.Put(dobj->mErr2+j*dobj->mNx,dobj->mNx);
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 | // Ecriture des projections
|
---|
1657 | if(projx) {
|
---|
1658 | sprintf(strg,"Histo2D: Projection X");
|
---|
1659 | os.PutLine(strg);
|
---|
1660 | ObjFileIO<Histo> fio_h(dobj->mHprojx); fio_h.Write(os);
|
---|
1661 | }
|
---|
1662 | if(projy) {
|
---|
1663 | sprintf(strg,"Histo2D: Projection Y");
|
---|
1664 | os.PutLine(strg);
|
---|
1665 | ObjFileIO<Histo> fio_h(dobj->mHprojy); fio_h.Write(os);
|
---|
1666 | }
|
---|
1667 |
|
---|
1668 | // Ecriture des slices
|
---|
1669 | if(nslix>0) {
|
---|
1670 | sprintf(strg,"Histo2D: Slices X %d",nslix);
|
---|
1671 | os.PutLine(strg);
|
---|
1672 | for(int_4 j=0;j<nslix;j++) {
|
---|
1673 | Histo* h = dobj->HSliX(j);
|
---|
1674 | ObjFileIO<Histo> fio_h(h); fio_h.Write(os);
|
---|
1675 | }
|
---|
1676 | }
|
---|
1677 | if(nsliy>0) {
|
---|
1678 | sprintf(strg,"Histo2D: Slices Y %d",nsliy);
|
---|
1679 | os.PutLine(strg);
|
---|
1680 | for(int_4 j=0;j<nsliy;j++) {
|
---|
1681 | Histo* h = dobj->HSliY(j);
|
---|
1682 | ObjFileIO<Histo> fio_h(h); fio_h.Write(os);
|
---|
1683 | }
|
---|
1684 | }
|
---|
1685 |
|
---|
1686 | // Ecriture des bandes
|
---|
1687 | if( nbanx>0 ) {
|
---|
1688 | sprintf(strg,"Histo2D: Bandes X %d",nbanx);
|
---|
1689 | os.PutLine(strg);
|
---|
1690 | list<Histo2D::bande_slice>::const_iterator it;
|
---|
1691 | for(it = dobj->mLBandx.begin(); it != dobj->mLBandx.end(); it++) {
|
---|
1692 | r_8 min = (*it).min; r_8 max = (*it).max;
|
---|
1693 | os.Put(min); os.Put(max);
|
---|
1694 | }
|
---|
1695 | for(it = dobj->mLBandx.begin(); it != dobj->mLBandx.end(); it++) {
|
---|
1696 | Histo* h = (*it).H;
|
---|
1697 | ObjFileIO<Histo> fio_h(h); fio_h.Write(os);
|
---|
1698 | }
|
---|
1699 | }
|
---|
1700 | if( nbany>0 ) {
|
---|
1701 | sprintf(strg,"Histo2D: Bandes Y %d",nbany);
|
---|
1702 | os.PutLine(strg);
|
---|
1703 | list<Histo2D::bande_slice>::const_iterator it;
|
---|
1704 | for(it = dobj->mLBandy.begin(); it != dobj->mLBandy.end(); it++) {
|
---|
1705 | r_8 min = (*it).min; r_8 max = (*it).max;
|
---|
1706 | os.Put(min); os.Put(max);
|
---|
1707 | }
|
---|
1708 | for(it = dobj->mLBandy.begin(); it != dobj->mLBandy.end(); it++) {
|
---|
1709 | Histo* h = (*it).H;
|
---|
1710 | ObjFileIO<Histo> fio_h(h); fio_h.Write(os);
|
---|
1711 | }
|
---|
1712 | }
|
---|
1713 |
|
---|
1714 | return;
|
---|
1715 | }
|
---|
1716 |
|
---|
1717 |
|
---|
1718 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
1719 | #pragma define_template ObjFileIO<Histo2D>
|
---|
1720 | #endif
|
---|
1721 |
|
---|
1722 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
1723 | template class ObjFileIO<Histo2D>;
|
---|
1724 | #endif
|
---|
1725 |
|
---|
1726 | } // FIN namespace SOPHYA
|
---|