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

Last change on this file since 3057 was 3057, checked in by cmv, 19 years ago
  • changement nom variables internes Histo...Histo2D
  • re-arrangement CreateOrResize et operator=
  • protection dans methodes (VMIN etc..) pour Histo 1d+2d vides

cmv 13/8/2006

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