Index: trunk/SophyaLib/HiStats/hisprof.cc
===================================================================
--- trunk/SophyaLib/HiStats/hisprof.cc	(revision 2868)
+++ trunk/SophyaLib/HiStats/hisprof.cc	(revision 3053)
@@ -18,6 +18,6 @@
 */
 HProf::HProf()
-: Histo()
-, SumY(NULL), SumY2(NULL), SumW(NULL), Ok(false), YMin(1.), YMax(-1.), Opt(0)
+: Histo(), mSumY(NULL), mSumY2(NULL), mSumW(NULL)
+, Ok(false), YMin(1.), YMax(-1.), Opt(0)
 {
 }
@@ -32,12 +32,7 @@
 */
 HProf::HProf(r_8 xMin, r_8 xMax, int_4 nBin, r_8 yMin, r_8 yMax)
-: Histo(xMin,xMax,nBin)
-, SumY( (nBin>0) ? new r_8[nBin] : NULL)
-, SumY2((nBin>0) ? new r_8[nBin] : NULL)
-, SumW( (nBin>0) ? new r_8[nBin] : NULL)
-, Ok(false), YMin(yMin), YMax(yMax), Opt(0)
-{
-  Histo::Errors();
-  Zero();
+: Histo(), mSumY(NULL), mSumY2(NULL), mSumW(NULL)
+{
+  CreateOrResize(xMin,xMax,nBin,yMin,yMax);
 }
 
@@ -47,12 +42,7 @@
 */
 HProf::HProf(r_4 xMin, r_4 xMax, int_4 nBin, r_4 yMin, r_4 yMax)
-: Histo((r_8)xMin,(r_8)xMax,nBin)
-, SumY( (nBin>0) ? new r_8[nBin] : NULL)
-, SumY2((nBin>0) ? new r_8[nBin] : NULL)
-, SumW( (nBin>0) ? new r_8[nBin] : NULL)
-, Ok(false), YMin((r_8)yMin), YMax((r_8)yMax), Opt(0)
-{
-  Histo::Errors();
-  Zero();
+: Histo(), mSumY(NULL), mSumY2(NULL), mSumW(NULL)
+{
+  CreateOrResize((r_8)xMin,(r_8)xMax,nBin,(r_8)yMin,(r_8)yMax);
 }
 
@@ -63,13 +53,13 @@
 HProf::HProf(const HProf& H)
 : Histo(H)
-, SumY((H.mBins>0)  ? new r_8[H.mBins] : NULL)
-, SumY2((H.mBins>0) ? new r_8[H.mBins] : NULL)
-, SumW((H.mBins>0)  ? new r_8[H.mBins] : NULL)
+, mSumY((H.mBins>0)  ? new r_8[H.mBins] : NULL)
+, mSumY2((H.mBins>0) ? new r_8[H.mBins] : NULL)
+, mSumW((H.mBins>0)  ? new r_8[H.mBins] : NULL)
 , Ok(H.Ok), YMin(H.YMin), YMax(H.YMax), Opt(H.Opt)
 {
   if(mBins>0) {
-    memcpy(SumY,  H.SumY,  mBins*sizeof(r_8));
-    memcpy(SumY2, H.SumY2, mBins*sizeof(r_8));
-    memcpy(SumW,  H.SumW,  mBins*sizeof(r_8));
+    memcpy(mSumY,  H.mSumY,  mBins*sizeof(r_8));
+    memcpy(mSumY2, H.mSumY2, mBins*sizeof(r_8));
+    memcpy(mSumW,  H.mSumW,  mBins*sizeof(r_8));
   }
   UpdateHisto();
@@ -78,11 +68,35 @@
 /********* Methode *********/
 /*!
+  allocation
+*/
+void HProf::CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin, r_8 yMin, r_8 yMax)
+{
+  //cout<<"HProf::CreateOrResize()"<<endl;
+  Histo::CreateOrResize(xMin,xMax,nBin);
+  Histo::Errors();
+  if(mSumY !=NULL) {delete[] mSumY;  mSumY = NULL;}
+  if(mSumY2!=NULL) {delete[] mSumY2; mSumY2= NULL;}
+  if(mSumW !=NULL) {delete[] mSumW;  mSumW = NULL;}
+  if(nBin>0) {
+    mSumY  = new r_8[nBin]; memset(mSumY, 0, nBin*sizeof(r_8));
+    mSumY2 = new r_8[nBin]; memset(mSumY2,0, nBin*sizeof(r_8));
+    mSumW  = new r_8[nBin]; memset(mSumW, 0, nBin*sizeof(r_8));
+  }
+  YMin = yMin; YMax = yMax;
+  Ok = false;
+  Opt = 0;
+}
+
+/********* Methode *********/
+/*!
   Des-allocation
 */
 void HProf::Delete()
 {
-  if( SumY  != NULL ) { delete[] SumY;  SumY = NULL;}
-  if( SumY2 != NULL ) { delete[] SumY2; SumY2 = NULL;}
-  if( SumW  != NULL ) { delete[] SumW;  SumW = NULL;}
+  //cout<<"HProf::Delete()"<<endl;
+  Histo::Delete();
+  if(mSumY != NULL) {delete[] mSumY;  mSumY = NULL;}
+  if(mSumY2!= NULL) {delete[] mSumY2; mSumY2 = NULL;}
+  if(mSumW != NULL) {delete[] mSumW;  mSumW = NULL;}
   Ok = false;
 }
@@ -94,5 +108,5 @@
 HProf::~HProf()
 {
-Delete();
+  Delete();
 }
 
@@ -112,9 +126,9 @@
 void HProf::Zero()
 {
-  memset(SumY,  0, mBins*sizeof(r_8));
-  memset(SumY2, 0, mBins*sizeof(r_8));
-  memset(SumW,  0, mBins*sizeof(r_8));
+  Histo::Zero();
+  memset(mSumY,  0, mBins*sizeof(r_8));
+  memset(mSumY2, 0, mBins*sizeof(r_8));
+  memset(mSumW,  0, mBins*sizeof(r_8));
   Ok = false;
-  Histo::Zero();
 }
 
@@ -158,10 +172,10 @@
 r_8 m,e2;
 if(mBins>0) for(int_4 i=0;i<mBins;i++) {
-  if(SumW[i]<=0.) {
+  if(mSumW[i]<=0.) {
     m = e2 = 0.;
   } else {
-    m  = SumY[i]/SumW[i];
-    e2 = SumY2[i]/SumW[i] - m*m;
-    if(Opt) e2 /= SumW[i];
+    m  = mSumY[i]/mSumW[i];
+    e2 = mSumY2[i]/mSumW[i] - m*m;
+    if(Opt) e2 /= mSumW[i];
   }
   mData[i] = m;
@@ -187,7 +201,7 @@
   else {
     Ok = false;
-    SumY[numBin]  += y*w;
-    SumY2[numBin] += y*y*w;
-    SumW[numBin]  += w;
+    mSumY[numBin]  += y*w;
+    mSumY2[numBin] += y*y*w;
+    mSumW[numBin]  += w;
     nHist += w;
     nEntries++;
@@ -206,7 +220,7 @@
   else {
     Ok = false;
-    SumY[numBin]  += y*w;
-    SumY2[numBin] += y*y*w;
-    SumW[numBin]  += w;
+    mSumY[numBin]  += y*w;
+    mSumY2[numBin] += y*y*w;
+    mSumW[numBin]  += w;
     nHist += w;
     nEntries++;
@@ -224,10 +238,10 @@
 Histo *hthis = (Histo *) this;
 *hthis = (Histo) h;
-if(!SumY)  SumY  = new r_8[mBins];
-if(!SumY2) SumY2 = new r_8[mBins];
-if(!SumW)  SumW  = new r_8[mBins];
-memcpy(SumY,  h.SumY,  mBins*sizeof(r_8));
-memcpy(SumY2, h.SumY2, mBins*sizeof(r_8));
-memcpy(SumW,  h.SumW,  mBins*sizeof(r_8));
+if(!mSumY)  mSumY  = new r_8[mBins];
+if(!mSumY2) mSumY2 = new r_8[mBins];
+if(!mSumW)  mSumW  = new r_8[mBins];
+memcpy(mSumY,  h.mSumY,  mBins*sizeof(r_8));
+memcpy(mSumY2, h.mSumY2, mBins*sizeof(r_8));
+memcpy(mSumW,  h.mSumW,  mBins*sizeof(r_8));
 Ok = h.Ok;
 YMin = h.YMin;
@@ -252,7 +266,7 @@
 *hthis += (Histo) a;
 if(mBins>0) for(int_4 i=0;i<mBins;i++) {
-  SumY[i]  += a.SumY[i];
-  SumY2[i] += a.SumY2[i];
-  SumW[i]  += a.SumW[i];
+  mSumY[i]  += a.mSumY[i];
+  mSumY2[i] += a.mSumY2[i];
+  mSumW[i]  += a.mSumW[i];
 }
 updatehisto();
@@ -279,7 +293,7 @@
   // Le nombre de bins est il plus grand ??
   if( mBins > binold ) {
-    delete [] SumY;  SumY  = new r_8[nbinew]; memset(SumY, 0,mBins*sizeof(r_8));
-    delete [] SumY2; SumY2 = new r_8[nbinew]; memset(SumY2,0,mBins*sizeof(r_8));
-    delete [] SumW;  SumW  = new r_8[nbinew]; memset(SumW, 0,mBins*sizeof(r_8));
+    delete [] mSumY;  mSumY  = new r_8[nbinew]; memset(mSumY, 0,mBins*sizeof(r_8));
+    delete [] mSumY2; mSumY2 = new r_8[nbinew]; memset(mSumY2,0,mBins*sizeof(r_8));
+    delete [] mSumW;  mSumW  = new r_8[nbinew]; memset(mSumW, 0,mBins*sizeof(r_8));
   }
 
@@ -294,20 +308,20 @@
     r_8 wY = 0., wY2 = 0., wW = 0.;
     if( ima == imi ) {
-      wY  = H.SumY[imi]  * binWidth/H.binWidth;
-      wY2 = H.SumY2[imi] * binWidth/H.binWidth;
-      wW  = H.SumW[imi]  * binWidth/H.binWidth;
+      wY  = H.mSumY[imi]  * binWidth/H.binWidth;
+      wY2 = H.mSumY2[imi] * binWidth/H.binWidth;
+      wW  = H.mSumW[imi]  * binWidth/H.binWidth;
     } else {
-      wY  += H.SumY[imi]  * (H.BinHighEdge(imi)-xmi)/H.binWidth;
-      wY  += H.SumY[ima]  * (xma -H.BinLowEdge(ima))/H.binWidth;
-      wY2 += H.SumY2[imi] * (H.BinHighEdge(imi)-xmi)/H.binWidth;
-      wY2 += H.SumY2[ima] * (xma -H.BinLowEdge(ima))/H.binWidth;
-      wW  += H.SumW[imi]  * (H.BinHighEdge(imi)-xmi)/H.binWidth;
-      wW  += H.SumW[ima]  * (xma -H.BinLowEdge(ima))/H.binWidth;
+      wY  += H.mSumY[imi]  * (H.BinHighEdge(imi)-xmi)/H.binWidth;
+      wY  += H.mSumY[ima]  * (xma -H.BinLowEdge(ima))/H.binWidth;
+      wY2 += H.mSumY2[imi] * (H.BinHighEdge(imi)-xmi)/H.binWidth;
+      wY2 += H.mSumY2[ima] * (xma -H.BinLowEdge(ima))/H.binWidth;
+      wW  += H.mSumW[imi]  * (H.BinHighEdge(imi)-xmi)/H.binWidth;
+      wW  += H.mSumW[ima]  * (xma -H.BinLowEdge(ima))/H.binWidth;
       if(ima>imi+1) for(int_4 ii=imi+1;ii<ima;ii++)
-	{wY += H.SumY[ii]; wY2 += H.SumY2[ii]; wW += H.SumW[ii];}
+	{wY += H.mSumY[ii]; wY2 += H.mSumY2[ii]; wW += H.mSumW[ii];}
     }
-    SumY[i] += wY; SumY2[i] += wY2; SumW[i] += wW;
-  }
-  // On synchronise les tableaux Sum?? et l'Histogramme
+    mSumY[i] += wY; mSumY2[i] += wY2; mSumW[i] += wW;
+  }
+  // On synchronise les tableaux mSum?? et l'Histogramme
   updatehisto();
 }
@@ -317,4 +331,5 @@
   UpdateHisto();
   Histo::Show(os);
+  os <<"       ymin="<<YMin<<" ymax="<<YMax<<"  opt="<<Opt<< endl;
 }
 
@@ -346,13 +361,14 @@
 // Lecture des donnees propres a l'histogramme de profil.
 is.GetLine(strg,255);
-dobj->SumY  = new r_8[dobj->mBins];
-dobj->SumY2 = new r_8[dobj->mBins];
-dobj->SumW  = new r_8[dobj->mBins];
-is.Get(dobj->SumY,  dobj->mBins);
-is.Get(dobj->SumY2, dobj->mBins);
-is.Get(dobj->SumW,  dobj->mBins);
+dobj->mSumY  = new r_8[dobj->mBins];
+dobj->mSumY2 = new r_8[dobj->mBins];
+dobj->mSumW  = new r_8[dobj->mBins];
+is.Get(dobj->mSumY,  dobj->mBins);
+is.Get(dobj->mSumY2, dobj->mBins);
+is.Get(dobj->mSumW,  dobj->mBins);
 
 // Lecture de l'histogramme
 is >> (Histo&)(*dobj);
+
 return;
 }
@@ -379,11 +395,9 @@
 sprintf(strg,"HProf: SumY SumY2 SumW");
 os.PutLine(strg);
-os.Put(dobj->SumY,  dobj->mBins);
-os.Put(dobj->SumY2, dobj->mBins);
-os.Put(dobj->SumW,  dobj->mBins);
+os.Put(dobj->mSumY,  dobj->mBins);
+os.Put(dobj->mSumY2, dobj->mBins);
+os.Put(dobj->mSumW,  dobj->mBins);
 
 // Ecriture de l'histogramme
-// FIO_Histo fio_h((Histo&)*dobj);
-// fio_h.Write(os);
 os << (Histo&)(*dobj);
 
