source: Sophya/trunk/SophyaLib/HiStats/histos2.cc@ 3053

Last change on this file since 3053 was 3053, checked in by cmv, 19 years ago

correction bug + addaptation pour ecriture fits cmv 12/8/2006

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