Changeset 3057 in Sophya for trunk/SophyaLib/HiStats/histos.cc


Ignore:
Timestamp:
Aug 13, 2006, 12:41:09 AM (19 years ago)
Author:
cmv
Message:
  • 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:
1 edited

Legend:

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

    r3053 r3057  
    11//
    2 // $Id: histos.cc,v 1.23 2006-08-12 17:29:29 cmv Exp $
     2// $Id: histos.cc,v 1.24 2006-08-12 22:41:08 cmv Exp $
    33//
    44
     
    7070{
    7171  //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));}
     72  bool samelen = (nBin==mBins)? true: false;
     73  if(mData!=NULL && !samelen) {delete[] mData; mData = NULL;}
     74  if(mErr2!=NULL) {delete[] mErr2; mErr2 = NULL;} // On des-alloue toujours
     75  if(nBin>0 && mData==NULL) mData = new r_8[nBin];
     76  if(mData) memset(mData,0,nBin*sizeof(r_8));
    7577  mBins = nBin;
    7678  mMin = xMin; mMax = xMax;
     
    142144{
    143145  if(this == &h) return *this;
    144   Delete();
    145   if(h.mBins<=0 || h.mData==NULL) return *this;
    146 
    147   mData = new r_8[h.mBins];
    148   if(h.mErr2) mErr2 = new r_8[h.mBins];
     146  CreateOrResize(h.mMin,h.mMax,h.mBins);
     147  if(h.mErr2) Errors();
     148  if(mData) memcpy(mData,h.mData,mBins*sizeof(r_8));
     149  if(mErr2) memcpy(mErr2,h.mErr2,mBins*sizeof(r_8));
    149150  mUnder = h.mUnder; mOver = h.mOver;
    150   nHist = h.nHist;
    151   nEntries = h.nEntries;
    152   mBins = h.mBins;
    153   mMin = h.mMin; mMax = h.mMax;
    154   binWidth = h.binWidth;
    155  
    156   memcpy(mData,h.mData,mBins*sizeof(r_8));
    157   if(mErr2) memcpy(mErr2,h.mErr2,mBins*sizeof(r_8));
    158 
     151  nHist = h.nHist; nEntries = h.nEntries;
    159152  return *this;
    160153}
     
    532525int_4 Histo::IMax() const
    533526{
     527  if(mBins<=0)  return 0;
    534528  int_4 imx=0;
    535529  if(mBins==1) return imx;
     
    546540int_4 Histo::IMin() const
    547541{
     542  if(mBins<=0)  return 0;
    548543  int_4 imx=0;
    549544  if(mBins==1) return imx;
     
    560555r_8 Histo::VMax() const
    561556{
     557  if(mBins<=0)  return 0.;
    562558  r_8 mx=mData[0];
    563559  if(mBins==1) return mx;
     
    572568r_8 Histo::VMin() const
    573569{
     570  if(mBins<=0)  return 0.;
    574571  r_8 mx=mData[0];
    575572  if(mBins==1) return mx;
     
    584581r_8 Histo::Mean() const
    585582{
     583  if(mBins<=0)  return 0.;
    586584  r_8 n = 0;
    587585  r_8 sx = 0;
     
    600598r_8 Histo::Sigma() const
    601599{
     600  if(mBins<=0)  return 0.;
    602601  r_8 n = 0;
    603602  r_8 sx = 0;
     
    622621r_8 Histo::MeanLH(int_4 il,int_4 ih) const
    623622{
     623  if(mBins<=0)  return 0.;
    624624  if( ih < il ) { il = 0; ih = mBins-1; }
    625625  if( il < 0 ) il = 0;
     
    641641r_8 Histo::SigmaLH(int_4 il,int_4 ih) const
    642642{
     643  if(mBins<=0)  return 0.;
    643644  if( ih < il ) { il = 0; ih = mBins - 1; }
    644645  if( il < 0 ) il = 0;
     
    665666r_8 Histo::Mean(r_8 x0, r_8 dx) const
    666667{
     668  if(mBins<=0)  return 0.;
    667669  r_8 sdata = 0;
    668670  r_8 sx = 0;
     
    685687r_8 Histo::Sigma(r_8 x0, r_8 dx) const
    686688{
     689  if(mBins<=0)  return 0.;
    687690  r_8 sx = 0;
    688691  r_8 sx2= 0;
     
    708711r_8 Histo::CleanedMean(r_8& sigma) const
    709712{
     713  if(mBins<=0)  return 0.;
    710714  if (!nHist) return 0;
    711715  // on fait ca de facon bete, on pourra raffiner apres...
     
    728732r_8 Histo::CleanedMean() const
    729733{
     734  if(mBins<=0)  return 0.;
    730735  if (!nHist) return 0;
    731736  r_8 s=0;
     
    739744int_4 Histo::BinNonNul() const
    740745{
     746if(mBins<=0)  return -1;
    741747int_4 non=0;
    742748for (int_4 i=0;i<mBins;i++) if( mData[i] != 0. ) non++;
     
    763769int_4 Histo::BinPercent(r_8 per) const
    764770{
     771if(mBins<=0)  return -1;
    765772r_8 n = nHist*per;
    766773r_8 s = 0.;
     
    789796int_4 Histo::BinPercent(r_8 x,r_8 per,int_4& imin,int_4& imax) const
    790797{
     798if(mBins<=0)  return -3;
    791799imin = imax = -1;
    792800if( per <= 0. ) return -1;
     
    926934int_4 Histo::MaxiLocal(r_8& maxi,int_4& imax,r_8& maxn,int_4& imaxn) const
    927935{
     936if(mBins<=0)  return -1;
    928937int_4 nml = 0;
    929938imax = imaxn = -1;
     
    964973r_8 Histo::FitMax(int_4 degree, r_8 frac, int_4 debug) const
    965974{
     975  if(mBins<=0)  return mMin;
    966976  if (degree < 2 || degree > 3) degree = 3;
    967977  if (frac <= 0. || frac >= 1.) frac = 0.5;
     
    10991109r_8 Histo::FindWidth(r_8 frac, int_4 debug) const
    11001110{
     1111  if(mBins<=0)  return 0;
    11011112  r_8 xmax = BinCenter( IMax() );
    11021113  return FindWidth(xmax,frac,debug);
     
    11101121r_8 Histo::FindWidth(r_8 xmax,r_8 frac, int_4 debug) const
    11111122{
     1123  if(mBins<=0)  return 0;
    11121124  if (frac <= 0 || frac >= 1.) frac = 0.5;
    11131125
     
    12051217int_4 Histo::EstimeMax(int_4& im,r_8& xm,int_4 SzPav) const
    12061218{
     1219if(mBins<=0)  return -1;
    12071220xm = 0;
    12081221if( SzPav <= 0 ) return -1;
     
    12371250void Histo::EstimeWidthS(r_8 frac,r_8& widthG,r_8& widthD) const
    12381251{
     1252if(mBins<=0) {frac=0.; return;}
    12391253int_4 i;
    12401254widthG = widthD = -1.;
     
    13081322{
    13091323 
     1324 if(mBins<=0) return;
    13101325 if( il > ih ) { il = 0; ih = mBins-1; }
    13111326 if( il < 0 ) il = 0;
     
    14901505
    14911506// Lecture des donnees Histo 1D
    1492 dobj->mData = new r_8[dobj->mBins];
    14931507is.GetLine(strg, 255);
     1508if(dobj->mBins>0) dobj->mData = new r_8[dobj->mBins];
    14941509is.Get(dobj->mData, dobj->mBins);
    14951510
     
    14971512if(errok) {
    14981513  is.GetLine(strg, 255);
    1499   dobj->mErr2 = new r_8[dobj->mBins];
     1514  if(dobj->mBins>0) dobj->mErr2 = new r_8[dobj->mBins];
    15001515  is.Get(dobj->mErr2, dobj->mBins);
    15011516}
Note: See TracChangeset for help on using the changeset viewer.