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