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