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

Last change on this file since 2603 was 2507, checked in by ansari, 22 years ago

Remplacement THROW par throw et suppression END_CONSTRUCTOR - Reza 15/03/2004

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