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