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

Last change on this file since 1192 was 1109, checked in by ansari, 25 years ago

on vire FitResidus/Function -> cf objfitter cmv 28/7/00

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