Changeset 3053 in Sophya for trunk/SophyaLib/HiStats


Ignore:
Timestamp:
Aug 12, 2006, 7:29:29 PM (19 years ago)
Author:
cmv
Message:

correction bug + addaptation pour ecriture fits cmv 12/8/2006

Location:
trunk/SophyaLib/HiStats
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/HiStats/hisprof.cc

    r2868 r3053  
    1818*/
    1919HProf::HProf()
    20 : Histo()
    21 , SumY(NULL), SumY2(NULL), SumW(NULL), Ok(false), YMin(1.), YMax(-1.), Opt(0)
     20: Histo(), mSumY(NULL), mSumY2(NULL), mSumW(NULL)
     21, Ok(false), YMin(1.), YMax(-1.), Opt(0)
    2222{
    2323}
     
    3232*/
    3333HProf::HProf(r_8 xMin, r_8 xMax, int_4 nBin, r_8 yMin, r_8 yMax)
    34 : Histo(xMin,xMax,nBin)
    35 , SumY( (nBin>0) ? new r_8[nBin] : NULL)
    36 , SumY2((nBin>0) ? new r_8[nBin] : NULL)
    37 , SumW( (nBin>0) ? new r_8[nBin] : NULL)
    38 , Ok(false), YMin(yMin), YMax(yMax), Opt(0)
    39 {
    40   Histo::Errors();
    41   Zero();
     34: Histo(), mSumY(NULL), mSumY2(NULL), mSumW(NULL)
     35{
     36  CreateOrResize(xMin,xMax,nBin,yMin,yMax);
    4237}
    4338
     
    4742*/
    4843HProf::HProf(r_4 xMin, r_4 xMax, int_4 nBin, r_4 yMin, r_4 yMax)
    49 : Histo((r_8)xMin,(r_8)xMax,nBin)
    50 , SumY( (nBin>0) ? new r_8[nBin] : NULL)
    51 , SumY2((nBin>0) ? new r_8[nBin] : NULL)
    52 , SumW( (nBin>0) ? new r_8[nBin] : NULL)
    53 , Ok(false), YMin((r_8)yMin), YMax((r_8)yMax), Opt(0)
    54 {
    55   Histo::Errors();
    56   Zero();
     44: Histo(), mSumY(NULL), mSumY2(NULL), mSumW(NULL)
     45{
     46  CreateOrResize((r_8)xMin,(r_8)xMax,nBin,(r_8)yMin,(r_8)yMax);
    5747}
    5848
     
    6353HProf::HProf(const HProf& H)
    6454: Histo(H)
    65 , SumY((H.mBins>0)  ? new r_8[H.mBins] : NULL)
    66 , SumY2((H.mBins>0) ? new r_8[H.mBins] : NULL)
    67 , SumW((H.mBins>0)  ? new r_8[H.mBins] : NULL)
     55, mSumY((H.mBins>0)  ? new r_8[H.mBins] : NULL)
     56, mSumY2((H.mBins>0) ? new r_8[H.mBins] : NULL)
     57, mSumW((H.mBins>0)  ? new r_8[H.mBins] : NULL)
    6858, Ok(H.Ok), YMin(H.YMin), YMax(H.YMax), Opt(H.Opt)
    6959{
    7060  if(mBins>0) {
    71     memcpy(SumY,  H.SumY,  mBins*sizeof(r_8));
    72     memcpy(SumY2, H.SumY2, mBins*sizeof(r_8));
    73     memcpy(SumW,  H.SumW,  mBins*sizeof(r_8));
     61    memcpy(mSumY,  H.mSumY,  mBins*sizeof(r_8));
     62    memcpy(mSumY2, H.mSumY2, mBins*sizeof(r_8));
     63    memcpy(mSumW,  H.mSumW,  mBins*sizeof(r_8));
    7464  }
    7565  UpdateHisto();
     
    7868/********* Methode *********/
    7969/*!
     70  allocation
     71*/
     72void HProf::CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin, r_8 yMin, r_8 yMax)
     73{
     74  //cout<<"HProf::CreateOrResize()"<<endl;
     75  Histo::CreateOrResize(xMin,xMax,nBin);
     76  Histo::Errors();
     77  if(mSumY !=NULL) {delete[] mSumY;  mSumY = NULL;}
     78  if(mSumY2!=NULL) {delete[] mSumY2; mSumY2= NULL;}
     79  if(mSumW !=NULL) {delete[] mSumW;  mSumW = NULL;}
     80  if(nBin>0) {
     81    mSumY  = new r_8[nBin]; memset(mSumY, 0, nBin*sizeof(r_8));
     82    mSumY2 = new r_8[nBin]; memset(mSumY2,0, nBin*sizeof(r_8));
     83    mSumW  = new r_8[nBin]; memset(mSumW, 0, nBin*sizeof(r_8));
     84  }
     85  YMin = yMin; YMax = yMax;
     86  Ok = false;
     87  Opt = 0;
     88}
     89
     90/********* Methode *********/
     91/*!
    8092  Des-allocation
    8193*/
    8294void HProf::Delete()
    8395{
    84   if( SumY  != NULL ) { delete[] SumY;  SumY = NULL;}
    85   if( SumY2 != NULL ) { delete[] SumY2; SumY2 = NULL;}
    86   if( SumW  != NULL ) { delete[] SumW;  SumW = NULL;}
     96  //cout<<"HProf::Delete()"<<endl;
     97  Histo::Delete();
     98  if(mSumY != NULL) {delete[] mSumY;  mSumY = NULL;}
     99  if(mSumY2!= NULL) {delete[] mSumY2; mSumY2 = NULL;}
     100  if(mSumW != NULL) {delete[] mSumW;  mSumW = NULL;}
    87101  Ok = false;
    88102}
     
    94108HProf::~HProf()
    95109{
    96 Delete();
     110  Delete();
    97111}
    98112
     
    112126void HProf::Zero()
    113127{
    114   memset(SumY,  0, mBins*sizeof(r_8));
    115   memset(SumY2, 0, mBins*sizeof(r_8));
    116   memset(SumW,  0, mBins*sizeof(r_8));
     128  Histo::Zero();
     129  memset(mSumY,  0, mBins*sizeof(r_8));
     130  memset(mSumY2, 0, mBins*sizeof(r_8));
     131  memset(mSumW,  0, mBins*sizeof(r_8));
    117132  Ok = false;
    118   Histo::Zero();
    119133}
    120134
     
    158172r_8 m,e2;
    159173if(mBins>0) for(int_4 i=0;i<mBins;i++) {
    160   if(SumW[i]<=0.) {
     174  if(mSumW[i]<=0.) {
    161175    m = e2 = 0.;
    162176  } else {
    163     m  = SumY[i]/SumW[i];
    164     e2 = SumY2[i]/SumW[i] - m*m;
    165     if(Opt) e2 /= SumW[i];
     177    m  = mSumY[i]/mSumW[i];
     178    e2 = mSumY2[i]/mSumW[i] - m*m;
     179    if(Opt) e2 /= mSumW[i];
    166180  }
    167181  mData[i] = m;
     
    187201  else {
    188202    Ok = false;
    189     SumY[numBin]  += y*w;
    190     SumY2[numBin] += y*y*w;
    191     SumW[numBin]  += w;
     203    mSumY[numBin]  += y*w;
     204    mSumY2[numBin] += y*y*w;
     205    mSumW[numBin]  += w;
    192206    nHist += w;
    193207    nEntries++;
     
    206220  else {
    207221    Ok = false;
    208     SumY[numBin]  += y*w;
    209     SumY2[numBin] += y*y*w;
    210     SumW[numBin]  += w;
     222    mSumY[numBin]  += y*w;
     223    mSumY2[numBin] += y*y*w;
     224    mSumW[numBin]  += w;
    211225    nHist += w;
    212226    nEntries++;
     
    224238Histo *hthis = (Histo *) this;
    225239*hthis = (Histo) h;
    226 if(!SumY)  SumY  = new r_8[mBins];
    227 if(!SumY2) SumY2 = new r_8[mBins];
    228 if(!SumW)  SumW  = new r_8[mBins];
    229 memcpy(SumY,  h.SumY,  mBins*sizeof(r_8));
    230 memcpy(SumY2, h.SumY2, mBins*sizeof(r_8));
    231 memcpy(SumW,  h.SumW,  mBins*sizeof(r_8));
     240if(!mSumY)  mSumY  = new r_8[mBins];
     241if(!mSumY2) mSumY2 = new r_8[mBins];
     242if(!mSumW)  mSumW  = new r_8[mBins];
     243memcpy(mSumY,  h.mSumY,  mBins*sizeof(r_8));
     244memcpy(mSumY2, h.mSumY2, mBins*sizeof(r_8));
     245memcpy(mSumW,  h.mSumW,  mBins*sizeof(r_8));
    232246Ok = h.Ok;
    233247YMin = h.YMin;
     
    252266*hthis += (Histo) a;
    253267if(mBins>0) for(int_4 i=0;i<mBins;i++) {
    254   SumY[i]  += a.SumY[i];
    255   SumY2[i] += a.SumY2[i];
    256   SumW[i]  += a.SumW[i];
     268  mSumY[i]  += a.mSumY[i];
     269  mSumY2[i] += a.mSumY2[i];
     270  mSumW[i]  += a.mSumW[i];
    257271}
    258272updatehisto();
     
    279293  // Le nombre de bins est il plus grand ??
    280294  if( mBins > binold ) {
    281     delete [] SumY;  SumY  = new r_8[nbinew]; memset(SumY, 0,mBins*sizeof(r_8));
    282     delete [] SumY2; SumY2 = new r_8[nbinew]; memset(SumY2,0,mBins*sizeof(r_8));
    283     delete [] SumW;  SumW  = new r_8[nbinew]; memset(SumW, 0,mBins*sizeof(r_8));
     295    delete [] mSumY;  mSumY  = new r_8[nbinew]; memset(mSumY, 0,mBins*sizeof(r_8));
     296    delete [] mSumY2; mSumY2 = new r_8[nbinew]; memset(mSumY2,0,mBins*sizeof(r_8));
     297    delete [] mSumW;  mSumW  = new r_8[nbinew]; memset(mSumW, 0,mBins*sizeof(r_8));
    284298  }
    285299
     
    294308    r_8 wY = 0., wY2 = 0., wW = 0.;
    295309    if( ima == imi ) {
    296       wY  = H.SumY[imi]  * binWidth/H.binWidth;
    297       wY2 = H.SumY2[imi] * binWidth/H.binWidth;
    298       wW  = H.SumW[imi]  * binWidth/H.binWidth;
     310      wY  = H.mSumY[imi]  * binWidth/H.binWidth;
     311      wY2 = H.mSumY2[imi] * binWidth/H.binWidth;
     312      wW  = H.mSumW[imi]  * binWidth/H.binWidth;
    299313    } else {
    300       wY  += H.SumY[imi]  * (H.BinHighEdge(imi)-xmi)/H.binWidth;
    301       wY  += H.SumY[ima]  * (xma -H.BinLowEdge(ima))/H.binWidth;
    302       wY2 += H.SumY2[imi] * (H.BinHighEdge(imi)-xmi)/H.binWidth;
    303       wY2 += H.SumY2[ima] * (xma -H.BinLowEdge(ima))/H.binWidth;
    304       wW  += H.SumW[imi]  * (H.BinHighEdge(imi)-xmi)/H.binWidth;
    305       wW  += H.SumW[ima]  * (xma -H.BinLowEdge(ima))/H.binWidth;
     314      wY  += H.mSumY[imi]  * (H.BinHighEdge(imi)-xmi)/H.binWidth;
     315      wY  += H.mSumY[ima]  * (xma -H.BinLowEdge(ima))/H.binWidth;
     316      wY2 += H.mSumY2[imi] * (H.BinHighEdge(imi)-xmi)/H.binWidth;
     317      wY2 += H.mSumY2[ima] * (xma -H.BinLowEdge(ima))/H.binWidth;
     318      wW  += H.mSumW[imi]  * (H.BinHighEdge(imi)-xmi)/H.binWidth;
     319      wW  += H.mSumW[ima]  * (xma -H.BinLowEdge(ima))/H.binWidth;
    306320      if(ima>imi+1) for(int_4 ii=imi+1;ii<ima;ii++)
    307         {wY += H.SumY[ii]; wY2 += H.SumY2[ii]; wW += H.SumW[ii];}
     321        {wY += H.mSumY[ii]; wY2 += H.mSumY2[ii]; wW += H.mSumW[ii];}
    308322    }
    309     SumY[i] += wY; SumY2[i] += wY2; SumW[i] += wW;
    310   }
    311   // On synchronise les tableaux Sum?? et l'Histogramme
     323    mSumY[i] += wY; mSumY2[i] += wY2; mSumW[i] += wW;
     324  }
     325  // On synchronise les tableaux mSum?? et l'Histogramme
    312326  updatehisto();
    313327}
     
    317331  UpdateHisto();
    318332  Histo::Show(os);
     333  os <<"       ymin="<<YMin<<" ymax="<<YMax<<"  opt="<<Opt<< endl;
    319334}
    320335
     
    346361// Lecture des donnees propres a l'histogramme de profil.
    347362is.GetLine(strg,255);
    348 dobj->SumY  = new r_8[dobj->mBins];
    349 dobj->SumY2 = new r_8[dobj->mBins];
    350 dobj->SumW  = new r_8[dobj->mBins];
    351 is.Get(dobj->SumY,  dobj->mBins);
    352 is.Get(dobj->SumY2, dobj->mBins);
    353 is.Get(dobj->SumW,  dobj->mBins);
     363dobj->mSumY  = new r_8[dobj->mBins];
     364dobj->mSumY2 = new r_8[dobj->mBins];
     365dobj->mSumW  = new r_8[dobj->mBins];
     366is.Get(dobj->mSumY,  dobj->mBins);
     367is.Get(dobj->mSumY2, dobj->mBins);
     368is.Get(dobj->mSumW,  dobj->mBins);
    354369
    355370// Lecture de l'histogramme
    356371is >> (Histo&)(*dobj);
     372
    357373return;
    358374}
     
    379395sprintf(strg,"HProf: SumY SumY2 SumW");
    380396os.PutLine(strg);
    381 os.Put(dobj->SumY,  dobj->mBins);
    382 os.Put(dobj->SumY2, dobj->mBins);
    383 os.Put(dobj->SumW,  dobj->mBins);
     397os.Put(dobj->mSumY,  dobj->mBins);
     398os.Put(dobj->mSumY2, dobj->mBins);
     399os.Put(dobj->mSumW,  dobj->mBins);
    384400
    385401// Ecriture de l'histogramme
    386 // FIO_Histo fio_h((Histo&)*dobj);
    387 // fio_h.Write(os);
    388402os << (Histo&)(*dobj);
    389403
  • trunk/SophyaLib/HiStats/hisprof.h

    r3049 r3053  
    5656               {UpdateHisto();
    5757                return (mErr2[i]>0.) ? sqrt(mErr2[i]) : 0.;}
     58  //! Retourne le carre de la dispersion/erreur du bin i
     59  inline r_8 SumW(int_4 i) const {return mSumW[i];}
    5860
    5961  // Operators
     
    6567
    6668  virtual void Show(ostream& os) const;
     69  inline  void Show() const { Show(cout); }
    6770  //! Print, voir detail dans Histo::Print
    6871  inline void Print(int_4 dyn=100,r_8 hmin=1.,r_8 hmax=-1.
     
    7174
    7275protected:
     76  void CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin, r_8 yMin=1., r_8 yMax=-1.);
    7377  void Delete();
    7478  void updatehisto() const;
    7579
    76   r_8*         SumY;  //!< somme
    77   r_8*         SumY2; //!< somme des carres
    78   r_8*         SumW;  //!< somme des poids
     80  r_8*         mSumY;  //!< somme
     81  r_8*         mSumY2; //!< somme des carres
     82  r_8*         mSumW;  //!< somme des poids
    7983  mutable bool Ok;    //!< true if update fait
    8084  r_8          YMin;  //!< limite minimum Y pour somme
     
    8387};
    8488
     89/*! Prints histogram information on stream \b s (h.Show(s)) */
     90inline ostream& operator << (ostream& s, HProf const & h)
     91  {  h.Show(s);  return(s);  }
    8592
    8693/*! \ingroup HiStats \fn operator<<(POuttPersist&, HProf)
  • trunk/SophyaLib/HiStats/histerr.cc

    r3049 r3053  
    1717/*! Constructeur par defaut */
    1818HistoErr::HistoErr(void)
    19   : Histo(), mNData(NULL), mCorrel(0)
     19: Histo(), mNData(NULL), mCorrel(0)
    2020{
    2121}
     
    2424/*! Constructeur d'un histo de nBin bins allant de xMin a xMax */
    2525HistoErr::HistoErr(r_8 xMin, r_8 xMax, int_4 nBin)
    26 : Histo(xMin,xMax,nBin), mNData(NULL), mCorrel(0)
    27 {
    28  this->Errors();
    29  allocate_mNData(nBin);
    30  Zero();
     26: Histo(), mNData(NULL)
     27{
     28  CreateOrResize(xMin,xMax,nBin);
    3129}
    3230
     
    3432/*! Constructeur par copie */
    3533HistoErr::HistoErr(const HistoErr& H)
    36 : Histo(H), mNData(NULL), mCorrel(H.mCorrel)
    37 {
    38  allocate_mNData(H.mBins);
    39  if(mBins>0) memcpy(mNData,H.mNData,mBins*sizeof(r_8));
     34: Histo(H), mNData((H.mBins>0)? new r_8[H.mBins] : NULL), mCorrel(H.mCorrel)
     35{
     36 if(mNData>0) memcpy(mNData,H.mNData,mBins*sizeof(r_8));
    4037}
    4138
     
    4845
    4946/********* Methode *********/
     47/*! Gestion de l'allocation */
     48void HistoErr::CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin)
     49{
     50  //cout<<"HistoErr::CreateOrResize()"<<endl;
     51  Histo::CreateOrResize(xMin,xMax,nBin);
     52  Histo::Errors();
     53  allocate_mNData(nBin);
     54  mCorrel = 0;
     55}
     56
     57/********* Methode *********/
    5058/*! Allocation du tableau mNData */
    5159void HistoErr::allocate_mNData(int nbin)
    5260{
    53  if(nbin<=0) return;
    54  if(mNData) {delete [] mNData; mNData=NULL;}
    55  mNData = new r_8[nbin];
     61  if(mNData) {delete [] mNData; mNData=NULL;}
     62  if(nbin<=0) return;
     63  mNData = new r_8[nbin];
     64  memset(mNData,0,nbin*sizeof(r_8));
    5665}
    5766
     
    6069void HistoErr::Delete(void)
    6170{
    62  Histo::Delete();
    63  if(mNData) {delete [] mNData; mNData=NULL;}
     71  //cout<<"HistoErr::Delete()"<<endl;
     72  Histo::Delete();
     73  if(mNData) {delete [] mNData; mNData=NULL;}
     74  mCorrel = 0;
    6475}
    6576
     
    7081void HistoErr::Zero(void)
    7182{
    72  Histo::Zero();
    73  if(mNData) memset(mNData,0,mBins*sizeof(r_8));
    74  mCorrel = 0;
     83  Histo::Zero();
     84  if(mNData) memset(mNData,0,mBins*sizeof(r_8));
     85  mCorrel = 0;
    7586}
    7687
     
    201212}
    202213
     214/********* Methode *********/
     215/*!
     216  Print info
     217*/
     218void HistoErr::Show(ostream & os) const
     219{
     220  Histo::Show(os);
     221  os <<"       ncorrel="<<mCorrel<< endl;
     222}
     223
    203224///////////////////////////////////////////////////////////
    204225// --------------------------------------------------------
  • trunk/SophyaLib/HiStats/histerr.h

    r3049 r3053  
    7878  HistoErr& operator = (const HistoErr& h);
    7979
     80  // Print
     81  virtual void Show(ostream& os) const;
     82  inline  void Show() const { Show(cout); }
     83
    8084protected:
    8185  void allocate_mNData(int nbin);
     86  void CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin);
    8287  void Delete(void);
    8388
     
    8590  int_4 mCorrel;  //!< Nombre d'appels a ToCorrel(+1) ou FromCorrel(-1)
    8691};
     92
     93/*! Prints histogram information on stream \b s (h.Show(s)) */
     94inline ostream& operator << (ostream& s, HistoErr const & h)
     95  {  h.Show(s);  return(s);  }
    8796
    8897/*! \ingroup HiStats \fn operator<<(POuttPersist&,HistoErr)
  • trunk/SophyaLib/HiStats/histos.cc

    r3044 r3053  
    11//
    2 // $Id: histos.cc,v 1.22 2006-08-07 17:38:47 cmv Exp $
     2// $Id: histos.cc,v 1.23 2006-08-12 17:29:29 cmv Exp $
    33//
    44
     
    2222/*! Constructeur par defaut */
    2323Histo::Histo()
    24 : mData(NULL), mErr2(NULL),
    25   mUnder(0), mOver(0), nHist(0), nEntries(0),
    26   mBins(0), mMin(0), mMax(0),
    27   binWidth(0)
     24: mData(NULL), mErr2(NULL)
     25,  mUnder(0.), mOver(0.), nHist(0.), nEntries(0)
     26,  mBins(0), mMin(0.), mMax(0.), binWidth(0.)
    2827{
    2928}
     
    3231/*! Constructeur d'un histo de nBin bins allant de xMin a xMax */
    3332Histo::Histo(r_8 xMin, r_8 xMax, int_4 nBin)
    34 : mData((nBin>0) ? new r_8[nBin] : NULL),
    35   mErr2(NULL),
    36   mUnder(0), mOver(0), nHist(0), nEntries(0),
    37   mBins(nBin), mMin(xMin), mMax(xMax),
    38   binWidth((nBin>0) ? (mMax-mMin)/nBin : 0)
    39 {
    40   Zero();
     33: mData(NULL), mErr2(NULL)
     34{
     35  CreateOrResize(xMin,xMax,nBin);
    4136}
    4237
     
    4439/*! Constructeur d'un histo de nBin bins allant de xMin a xMax */
    4540Histo::Histo(r_4 xMin, r_4 xMax, int_4 nBin)
    46 : mData((nBin>0) ? new r_8[nBin] : NULL),
    47   mErr2(NULL),
    48   mUnder(0), mOver(0), nHist(0), nEntries(0),
    49   mBins(nBin), mMin((r_8)xMin), mMax((r_8)xMax),
    50   binWidth((nBin>0) ? (mMax-mMin)/nBin : 0)
    51 {
    52   Zero();
     41: mData(NULL), mErr2(NULL)
     42{
     43  CreateOrResize((r_8)xMin,(r_8)xMax,nBin);
    5344}
    5445
     
    6859
    6960/********* Methode *********/
     61/*! Destructeur */
     62Histo::~Histo()
     63{
     64  Delete();
     65}
     66
     67/********* Methode *********/
     68/*! Gestion de l'allocation */
     69void Histo::CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin)
     70{
     71  //cout<<"Histo::CreateOrResize()"<<endl;
     72  if(mData != NULL) {delete[] mData; mData = NULL;}
     73  if(mErr2 != NULL) {delete[] mErr2; mErr2 = NULL;}
     74  if(nBin>0) {mData = new r_8[nBin]; memset(mData,0,nBin*sizeof(r_8));}
     75  mBins = nBin;
     76  mMin = xMin; mMax = xMax;
     77  binWidth = (nBin>0) ? (mMax-mMin)/nBin : 0.;
     78  mUnder = mOver = nHist = 0.;
     79  nEntries = 0;
     80}
     81
     82/********* Methode *********/
    7083/*! Gestion de la des-allocation */
    7184void Histo::Delete()
    7285{
    73   if( mData != NULL ) { delete[] mData; mData = NULL;}
    74   if( mErr2 != NULL ) { delete[] mErr2; mErr2 = NULL;}
    75   mUnder = mOver = mMin = mMax = binWidth= 0.;
    76   nHist = 0.;
    77   mBins = 0;
    78   nEntries = 0;
    79 }
    80 
    81 /********* Methode *********/
    82 /*! Destructeur */
    83 Histo::~Histo()
    84 {
    85 Delete();
     86 //cout<<"Histo::Delete()"<<endl;
     87 if(mData != NULL) {delete[] mData; mData = NULL;}
     88 if(mErr2 != NULL) {delete[] mErr2; mErr2 = NULL;}
     89 mUnder = mOver = mMin = mMax = binWidth = nHist = 0.;
     90 mBins = 0;
     91 nEntries = 0;
    8692}
    8793
     
    94100  if(mBins<=0 || mData==NULL) return;
    95101  memset(mData,0,mBins*sizeof(r_8));
    96   mUnder = mOver = 0;
    97   nHist = 0;
     102  if(mErr2) memset(mErr2,0, mBins*sizeof(r_8));
     103  mUnder = mOver = nHist = 0;
    98104  nEntries = 0;
    99   if(mErr2) memset(mErr2, 0, mBins*sizeof(r_8));
    100105}
    101106
     
    106111void Histo::Errors()
    107112{
     113 if(mErr2 != NULL) {delete[] mErr2; mErr2 = NULL;}
    108114 if(mBins<=0) return;
    109  if(mErr2==NULL) mErr2 = new r_8[mBins];
     115 mErr2 = new r_8[mBins];
    110116 memset(mErr2,0,mBins*sizeof(r_8));
    111117}
     
    141147  mData = new r_8[h.mBins];
    142148  if(h.mErr2) mErr2 = new r_8[h.mBins];
    143   mUnder = h.mUnder;
    144   mOver = h.mOver;
     149  mUnder = h.mUnder; mOver = h.mOver;
    145150  nHist = h.nHist;
    146151  nEntries = h.nEntries;
    147152  mBins = h.mBins;
    148   mMin = h.mMin;
    149   mMax = h.mMax;
     153  mMin = h.mMin; mMax = h.mMax;
    150154  binWidth = h.binWidth;
    151155 
  • trunk/SophyaLib/HiStats/histos.h

    r3049 r3053  
    11// This may look like C code, but it is really -*- C++ -*-
    22//
    3 // $Id: histos.h,v 1.22 2006-08-11 16:10:13 cmv Exp $
     3// $Id: histos.h,v 1.23 2006-08-12 17:29:29 cmv Exp $
    44//
    55
     
    158158 
    159159protected:
    160   void Delete();
     160  void CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin);
     161  void Delete(void); // Ne pas passer en "virtual"
    161162
    162163  r_8*   mData;    //!< donnees
  • trunk/SophyaLib/HiStats/histos2.cc

    r2868 r3053  
    3939
    4040///////////////////////////////////////////////////////////////////
     41
     42/*!
     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
    4155/*!
    4256  Createur d'un histogramme 2D ayant nxBin,nyBin bins
     
    4458*/
    4559Histo2D::Histo2D(r_8 xMin,r_8 xMax,int_4 nxBin,r_8 yMin,r_8 yMax,int_4 nyBin)
    46       : mData(new r_8[nxBin*nyBin]), mErr2(NULL)
    47       , nHist(0), nEntries(0)
    48       , mNx(nxBin), mNy(nyBin), mNxy(nxBin*nyBin)
    49       , mXmin(xMin), mXmax(xMax), mYmin(yMin), mYmax(yMax)
    50       , mWBinx((xMax - xMin)/nxBin), mWBiny((yMax - yMin)/nyBin)
    51       , mHprojx(NULL), mHprojy(NULL)
    52 {
    53 ASSERT(nxBin>0 && nyBin>0 && xMin<xMax && yMin<yMax);
    54 for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
    55 Zero();
    56 mB_s.H = NULL;
     60: mData(NULL), mErr2(NULL), mHprojx(NULL), mHprojy(NULL)
     61{
     62  CreateOrResize(xMin,xMax,nxBin,yMin,yMax,nyBin);
    5763}
    5864
     
    6268*/
    6369Histo2D::Histo2D(r_4 xMin,r_4 xMax,int_4 nxBin,r_4 yMin,r_4 yMax,int_4 nyBin)
    64       : mData(new r_8[nxBin*nyBin]), mErr2(NULL)
    65       , nHist(0), nEntries(0)
    66       , mNx(nxBin), mNy(nyBin), mNxy(nxBin*nyBin)
    67       , mXmin((r_8)xMin), mXmax((r_8)xMax), mYmin((r_8)yMin), mYmax((r_8)yMax)
    68       , mWBinx((xMax - xMin)/nxBin), mWBiny((yMax - yMin)/nyBin)
    69       , mHprojx(NULL), mHprojy(NULL)
    70 {
    71 ASSERT(nxBin>0 && nyBin>0 && xMin<xMax && yMin<yMax);
    72 for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
    73 Zero();
    74 mB_s.H = NULL;
     70: mData(NULL), mErr2(NULL), mHprojx(NULL), mHprojy(NULL)
     71{
     72  CreateOrResize((r_8)xMin,(r_8)xMax,nxBin,(r_8)yMin,(r_8)yMax,nyBin);
    7573}
    7674
     
    142140
    143141/*!
    144   Constructeur par defaut.
    145 */
    146 Histo2D::Histo2D()
    147       : mData(NULL), mErr2(NULL)
    148       , nHist(0), nEntries(0)
    149       , mNx(0), mNy(0), mNxy(0)
    150       , mXmin(0), mXmax(0), mYmin(0), mYmax(0)
    151       , mWBinx(0), mWBiny(0)
    152       , mHprojx(NULL), mHprojy(NULL)
    153 {
    154 for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
    155 mB_s.H = NULL;
    156 }
    157 
    158 ///////////////////////////////////////////////////////////////////
     142  Destructeur.
     143*/
     144Histo2D::~Histo2D()
     145{
     146  Delete();
     147}
     148
     149///////////////////////////////////////////////////////////////////
     150/*!
     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{
     155 int_8 n = nxBin*nyBin;
     156 if(mData!=NULL) {delete[] mData; mData = NULL;}
     157 if(n>0) {mData = new r_8[n]; memset(mData, 0, n*sizeof(r_8));}
     158 mNx = nxBin; mNy = nyBin; mNxy = nxBin*nyBin;
     159 mXmin = xMin; mXmax = xMax; mYmin = yMin; mYmax = yMax;
     160 mWBinx = (nxBin>0) ? (xMax - xMin)/nxBin: 0.;
     161 mWBiny = (nyBin>0) ? (yMax - yMin)/nyBin: 0.;
     162 nHist = 0; nEntries = 0;
     163 for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
     164 mB_s.H = NULL;
     165}
     166
    159167/*!
    160168  Desallocation de la place de l'histogramme (fct privee).
     
    163171{
    164172  if( mData != NULL ) { delete[] mData; mData = NULL;}
    165 
    166173  if( mErr2 != NULL ) { delete[] mErr2; mErr2 = NULL;}
    167174
     
    180187  mWBinx = 0; mWBiny = 0;
    181188  for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
    182   mB_s.H = NULL;
    183 }
    184 
    185 /*!
    186   Destructeur.
    187 */
    188 Histo2D::~Histo2D()
    189 {
    190 Delete();
     189  mB_s.H = NULL;  // Ne pas faire de delete!
    191190}
    192191
     
    219218void Histo2D::Errors()
    220219{
    221  if( mNxy > 0 ) {
    222    if(mErr2==NULL) mErr2 = new r_8[mNxy];
    223    memset(mErr2, 0, mNxy*sizeof(r_8));
    224  }
     220 if(mErr2!=NULL) {delete[] mErr2; mErr2 = NULL;}
     221 if(mNxy <= 0) return;
     222 mErr2 = new r_8[mNxy];
     223 memset(mErr2,0,mNxy*sizeof(r_8));
    225224}
    226225
  • trunk/SophyaLib/HiStats/histos2.h

    r3049 r3053  
    143143  // Print et Display ASCII
    144144  virtual void Show(ostream& os) const;
     145  inline  void Show() const { Show(cout); }
    145146  inline void  PrintStatus() const { Show(cout); }
    146147 
     
    211212#endif
    212213
    213   void Delete();
     214  void CreateOrResize(r_8 xMin,r_8 xMax,int_4 nxBin,r_8 yMin,r_8 yMax,int_4 nyBin);
     215  void Delete(void);
    214216
    215217  r_8*        mData; //!< donnees
  • trunk/SophyaLib/HiStats/smakefile

    r3007 r3053  
    1212 
    1313$(SOPHYAOBJP)basedtable.o: basedtable.cc basedtable.h \
    14   $(SOPHYAINCP)machdefs.h ntupintf.h \
    15   $(SOPHYAINCP)dvlist.h \
     14  $(SOPHYAINCP)machdefs.h \
     15  ntupintf.h $(SOPHYAINCP)dvlist.h \
    1616  $(SOPHYAINCP)objfio.h \
    1717  $(SOPHYAINCP)machdefs.h \
     
    4040 
    4141$(SOPHYAOBJP)datatable.o: datatable.cc datatable.h basedtable.h \
    42   $(SOPHYAINCP)machdefs.h ntupintf.h \
    43   $(SOPHYAINCP)dvlist.h \
     42  $(SOPHYAINCP)machdefs.h \
     43  ntupintf.h $(SOPHYAINCP)dvlist.h \
    4444  $(SOPHYAINCP)objfio.h \
    4545  $(SOPHYAINCP)machdefs.h \
     
    7373 
    7474$(SOPHYAOBJP)fio_dtable.o: fio_dtable.cc datatable.h basedtable.h \
    75   $(SOPHYAINCP)machdefs.h ntupintf.h \
    76   $(SOPHYAINCP)dvlist.h \
    77   $(SOPHYAINCP)objfio.h \
    78   $(SOPHYAINCP)machdefs.h \
    79   $(SOPHYAINCP)anydataobj.h \
    80   $(SOPHYAINCP)ppersist.h \
    81   $(SOPHYAINCP)pexceptions.h \
    82   $(SOPHYAINCP)gnumd5.h \
    83   $(SOPHYAINCP)ppfbinstream.h \
    84   $(SOPHYAINCP)rawstream.h \
    85   $(SOPHYAINCP)ppfnametag.h \
    86   $(SOPHYAINCP)mutyv.h \
    87   $(SOPHYAINCP)timestamp.h \
    88   $(SOPHYAINCP)segdatablock.h \
    89   $(SOPHYAINCP)tvector.h \
    90   $(SOPHYAINCP)tmatrix.h \
    91   $(SOPHYAINCP)tarray.h \
    92   $(SOPHYAINCP)basarr.h \
    93   $(SOPHYAINCP)dvlist.h \
    94   $(SOPHYAINCP)ndatablock.h \
    95   $(SOPHYAINCP)utilarr.h \
    96   $(SOPHYAINCP)tmatrix_tsnl.h \
    97   $(SOPHYAINCP)tvector_tsnl.h \
    98   $(SOPHYAINCP)objfio.h swppfdtable.h \
     75  $(SOPHYAINCP)machdefs.h \
     76  ntupintf.h $(SOPHYAINCP)dvlist.h \
     77  $(SOPHYAINCP)objfio.h \
     78  $(SOPHYAINCP)machdefs.h \
     79  $(SOPHYAINCP)anydataobj.h \
     80  $(SOPHYAINCP)ppersist.h \
     81  $(SOPHYAINCP)pexceptions.h \
     82  $(SOPHYAINCP)gnumd5.h \
     83  $(SOPHYAINCP)ppfbinstream.h \
     84  $(SOPHYAINCP)rawstream.h \
     85  $(SOPHYAINCP)ppfnametag.h \
     86  $(SOPHYAINCP)mutyv.h \
     87  $(SOPHYAINCP)timestamp.h \
     88  $(SOPHYAINCP)segdatablock.h \
     89  $(SOPHYAINCP)tvector.h \
     90  $(SOPHYAINCP)tmatrix.h \
     91  $(SOPHYAINCP)tarray.h \
     92  $(SOPHYAINCP)basarr.h \
     93  $(SOPHYAINCP)dvlist.h \
     94  $(SOPHYAINCP)ndatablock.h \
     95  $(SOPHYAINCP)utilarr.h \
     96  $(SOPHYAINCP)tmatrix_tsnl.h \
     97  $(SOPHYAINCP)tvector_tsnl.h \
     98  $(SOPHYAINCP)objfio.h \
     99  swppfdtable.h \
    99100  $(SOPHYAINCP)swsegdb.h \
    100101  $(SOPHYAINCP)segdatablock.h \
     
    109110$(SOPHYAOBJP)hisprof.o: hisprof.cc \
    110111  $(SOPHYAINCP)sopnamsp.h \
    111   $(SOPHYAINCP)machdefs.h hisprof.h \
    112   $(SOPHYAINCP)peida.h \
     112  $(SOPHYAINCP)machdefs.h \
     113  hisprof.h $(SOPHYAINCP)peida.h \
    113114  $(SOPHYAINCP)machdefs.h \
    114115  $(SOPHYAINCP)utils.h \
     
    142143$(SOPHYAOBJP)histerr.o: histerr.cc \
    143144  $(SOPHYAINCP)sopnamsp.h \
    144   $(SOPHYAINCP)machdefs.h histinit.h \
     145  $(SOPHYAINCP)machdefs.h \
     146  histinit.h \
    145147  $(SOPHYAINCP)ntoolsinit.h \
    146148  $(SOPHYAINCP)tarrinit.h \
    147149  $(SOPHYAINCP)sophyainit.h \
    148   $(SOPHYAINCP)machdefs.h histerr.h \
    149   $(SOPHYAINCP)objfio.h \
    150   $(SOPHYAINCP)anydataobj.h \
    151   $(SOPHYAINCP)ppersist.h \
    152   $(SOPHYAINCP)pexceptions.h \
    153   $(SOPHYAINCP)gnumd5.h \
    154   $(SOPHYAINCP)ppfbinstream.h \
    155   $(SOPHYAINCP)rawstream.h \
    156   $(SOPHYAINCP)ppfnametag.h histos.h \
    157   $(SOPHYAINCP)peida.h \
     150  $(SOPHYAINCP)machdefs.h \
     151  histerr.h $(SOPHYAINCP)objfio.h \
     152  $(SOPHYAINCP)anydataobj.h \
     153  $(SOPHYAINCP)ppersist.h \
     154  $(SOPHYAINCP)pexceptions.h \
     155  $(SOPHYAINCP)gnumd5.h \
     156  $(SOPHYAINCP)ppfbinstream.h \
     157  $(SOPHYAINCP)rawstream.h \
     158  $(SOPHYAINCP)ppfnametag.h \
     159  histos.h $(SOPHYAINCP)peida.h \
    158160  $(SOPHYAINCP)utils.h \
    159161  $(SOPHYAINCP)perrors.h \
     
    178180$(SOPHYAOBJP)histinit.o: histinit.cc \
    179181  $(SOPHYAINCP)sopnamsp.h \
    180   $(SOPHYAINCP)machdefs.h histinit.h \
     182  $(SOPHYAINCP)machdefs.h \
     183  histinit.h \
    181184  $(SOPHYAINCP)ntoolsinit.h \
    182185  $(SOPHYAINCP)tarrinit.h \
     
    208211  $(SOPHYAINCP)tvector_tsnl.h \
    209212  $(SOPHYAINCP)ppersist.h \
    210   $(SOPHYAINCP)anydataobj.h histos2.h \
    211   $(SOPHYAINCP)utils.h hisprof.h histerr.h \
    212   ntuple.h ntupintf.h $(SOPHYAINCP)dvlist.h \
    213   xntuple.h datatable.h basedtable.h \
    214   $(SOPHYAINCP)segdatablock.h swppfdtable.h \
     213  $(SOPHYAINCP)anydataobj.h \
     214  histos2.h $(SOPHYAINCP)utils.h \
     215  hisprof.h histerr.h ntuple.h ntupintf.h \
     216  $(SOPHYAINCP)dvlist.h xntuple.h \
     217  datatable.h basedtable.h \
     218  $(SOPHYAINCP)segdatablock.h \
     219  swppfdtable.h \
    215220  $(SOPHYAINCP)swsegdb.h \
    216221  $(SOPHYAINCP)segdatablock.h \
     
    222227$(SOPHYAOBJP)histos2.o: histos2.cc \
    223228  $(SOPHYAINCP)sopnamsp.h \
    224   $(SOPHYAINCP)machdefs.h histos2.h \
    225   $(SOPHYAINCP)peida.h \
     229  $(SOPHYAINCP)machdefs.h \
     230  histos2.h $(SOPHYAINCP)peida.h \
    226231  $(SOPHYAINCP)machdefs.h \
    227232  $(SOPHYAINCP)utils.h \
     
    253258        $(CXXCOMPILE) $(CXXTEMPFLG) -o $@  histos2.cc
    254259 
    255 $(SOPHYAOBJP)histos.o: histos.cc $(SOPHYAINCP)sopnamsp.h \
     260$(SOPHYAOBJP)histos.o: histos.cc \
     261  $(SOPHYAINCP)sopnamsp.h \
    256262  $(SOPHYAINCP)machdefs.h histos.h \
    257263  $(SOPHYAINCP)objfio.h \
     
    290296 
    291297$(SOPHYAOBJP)ntupintf.o: ntupintf.cc \
    292   $(SOPHYAINCP)sopnamsp.h ntupintf.h \
     298  $(SOPHYAINCP)sopnamsp.h \
     299  ntupintf.h \
    293300  $(SOPHYAINCP)machdefs.h \
    294301  $(SOPHYAINCP)pexceptions.h \
     
    296303        $(CXXCOMPILE) $(CXXTEMPFLG) -o $@  ntupintf.cc
    297304 
    298 $(SOPHYAOBJP)ntuple.o: ntuple.cc $(SOPHYAINCP)sopnamsp.h \
     305$(SOPHYAOBJP)ntuple.o: ntuple.cc \
     306  $(SOPHYAINCP)sopnamsp.h \
    299307  $(SOPHYAINCP)strutil.h \
    300308  $(SOPHYAINCP)perrors.h \
     
    307315  $(SOPHYAINCP)ppfbinstream.h \
    308316  $(SOPHYAINCP)rawstream.h \
    309   $(SOPHYAINCP)ppfnametag.h ntupintf.h \
     317  $(SOPHYAINCP)ppfnametag.h \
     318  ntupintf.h \
    310319  $(SOPHYAINCP)machdefs.h \
    311320  $(SOPHYAINCP)ppersist.h \
     
    317326 
    318327$(SOPHYAOBJP)proxtuple.o: proxtuple.cc \
    319   $(SOPHYAINCP)sopnamsp.h proxtuple.h \
    320   ntuple.h $(SOPHYAINCP)objfio.h \
    321   $(SOPHYAINCP)machdefs.h \
    322   $(SOPHYAINCP)anydataobj.h \
    323   $(SOPHYAINCP)ppersist.h \
    324   $(SOPHYAINCP)pexceptions.h \
    325   $(SOPHYAINCP)gnumd5.h \
    326   $(SOPHYAINCP)ppfbinstream.h \
    327   $(SOPHYAINCP)rawstream.h \
    328   $(SOPHYAINCP)ppfnametag.h ntupintf.h \
     328  $(SOPHYAINCP)sopnamsp.h \
     329  proxtuple.h ntuple.h \
     330  $(SOPHYAINCP)objfio.h \
     331  $(SOPHYAINCP)machdefs.h \
     332  $(SOPHYAINCP)anydataobj.h \
     333  $(SOPHYAINCP)ppersist.h \
     334  $(SOPHYAINCP)pexceptions.h \
     335  $(SOPHYAINCP)gnumd5.h \
     336  $(SOPHYAINCP)ppfbinstream.h \
     337  $(SOPHYAINCP)rawstream.h \
     338  $(SOPHYAINCP)ppfnametag.h \
     339  ntupintf.h \
    329340  $(SOPHYAINCP)machdefs.h \
    330341  $(SOPHYAINCP)ppersist.h \
     
    336347 
    337348$(SOPHYAOBJP)swppfdtable.o: swppfdtable.cc swppfdtable.h basedtable.h \
    338   $(SOPHYAINCP)machdefs.h ntupintf.h \
    339   $(SOPHYAINCP)dvlist.h \
     349  $(SOPHYAINCP)machdefs.h \
     350  ntupintf.h $(SOPHYAINCP)dvlist.h \
    340351  $(SOPHYAINCP)objfio.h \
    341352  $(SOPHYAINCP)machdefs.h \
     
    380391  $(SOPHYAINCP)ppersist.h \
    381392  $(SOPHYAINCP)perrors.h xntuple.h \
    382   $(SOPHYAINCP)machdefs.h ntupintf.h \
    383   $(SOPHYAINCP)dvlist.h \
     393  $(SOPHYAINCP)machdefs.h \
     394  ntupintf.h $(SOPHYAINCP)dvlist.h \
    384395  $(SOPHYAINCP)objfio.h \
    385396  $(SOPHYAINCP)anydataobj.h \
Note: See TracChangeset for help on using the changeset viewer.