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

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

cmv 13/8/2006

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