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