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

Last change on this file since 2117 was 1783, checked in by aubourg, 24 years ago

pour compilation darwin (MacOS X 10.1.1)

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