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

Last change on this file since 2745 was 2741, checked in by cmv, 20 years ago

suite nouvelle structure et iostream.h -> iostearm cmv 20/05/05

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