Changeset 3057 in Sophya for trunk/SophyaLib/HiStats/histos.cc
- Timestamp:
- Aug 13, 2006, 12:41:09 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/HiStats/histos.cc
r3053 r3057 1 1 // 2 // $Id: histos.cc,v 1.2 3 2006-08-12 17:29:29cmv Exp $2 // $Id: histos.cc,v 1.24 2006-08-12 22:41:08 cmv Exp $ 3 3 // 4 4 … … 70 70 { 71 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));} 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)); 75 77 mBins = nBin; 76 78 mMin = xMin; mMax = xMax; … … 142 144 { 143 145 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)); 149 150 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; 159 152 return *this; 160 153 } … … 532 525 int_4 Histo::IMax() const 533 526 { 527 if(mBins<=0) return 0; 534 528 int_4 imx=0; 535 529 if(mBins==1) return imx; … … 546 540 int_4 Histo::IMin() const 547 541 { 542 if(mBins<=0) return 0; 548 543 int_4 imx=0; 549 544 if(mBins==1) return imx; … … 560 555 r_8 Histo::VMax() const 561 556 { 557 if(mBins<=0) return 0.; 562 558 r_8 mx=mData[0]; 563 559 if(mBins==1) return mx; … … 572 568 r_8 Histo::VMin() const 573 569 { 570 if(mBins<=0) return 0.; 574 571 r_8 mx=mData[0]; 575 572 if(mBins==1) return mx; … … 584 581 r_8 Histo::Mean() const 585 582 { 583 if(mBins<=0) return 0.; 586 584 r_8 n = 0; 587 585 r_8 sx = 0; … … 600 598 r_8 Histo::Sigma() const 601 599 { 600 if(mBins<=0) return 0.; 602 601 r_8 n = 0; 603 602 r_8 sx = 0; … … 622 621 r_8 Histo::MeanLH(int_4 il,int_4 ih) const 623 622 { 623 if(mBins<=0) return 0.; 624 624 if( ih < il ) { il = 0; ih = mBins-1; } 625 625 if( il < 0 ) il = 0; … … 641 641 r_8 Histo::SigmaLH(int_4 il,int_4 ih) const 642 642 { 643 if(mBins<=0) return 0.; 643 644 if( ih < il ) { il = 0; ih = mBins - 1; } 644 645 if( il < 0 ) il = 0; … … 665 666 r_8 Histo::Mean(r_8 x0, r_8 dx) const 666 667 { 668 if(mBins<=0) return 0.; 667 669 r_8 sdata = 0; 668 670 r_8 sx = 0; … … 685 687 r_8 Histo::Sigma(r_8 x0, r_8 dx) const 686 688 { 689 if(mBins<=0) return 0.; 687 690 r_8 sx = 0; 688 691 r_8 sx2= 0; … … 708 711 r_8 Histo::CleanedMean(r_8& sigma) const 709 712 { 713 if(mBins<=0) return 0.; 710 714 if (!nHist) return 0; 711 715 // on fait ca de facon bete, on pourra raffiner apres... … … 728 732 r_8 Histo::CleanedMean() const 729 733 { 734 if(mBins<=0) return 0.; 730 735 if (!nHist) return 0; 731 736 r_8 s=0; … … 739 744 int_4 Histo::BinNonNul() const 740 745 { 746 if(mBins<=0) return -1; 741 747 int_4 non=0; 742 748 for (int_4 i=0;i<mBins;i++) if( mData[i] != 0. ) non++; … … 763 769 int_4 Histo::BinPercent(r_8 per) const 764 770 { 771 if(mBins<=0) return -1; 765 772 r_8 n = nHist*per; 766 773 r_8 s = 0.; … … 789 796 int_4 Histo::BinPercent(r_8 x,r_8 per,int_4& imin,int_4& imax) const 790 797 { 798 if(mBins<=0) return -3; 791 799 imin = imax = -1; 792 800 if( per <= 0. ) return -1; … … 926 934 int_4 Histo::MaxiLocal(r_8& maxi,int_4& imax,r_8& maxn,int_4& imaxn) const 927 935 { 936 if(mBins<=0) return -1; 928 937 int_4 nml = 0; 929 938 imax = imaxn = -1; … … 964 973 r_8 Histo::FitMax(int_4 degree, r_8 frac, int_4 debug) const 965 974 { 975 if(mBins<=0) return mMin; 966 976 if (degree < 2 || degree > 3) degree = 3; 967 977 if (frac <= 0. || frac >= 1.) frac = 0.5; … … 1099 1109 r_8 Histo::FindWidth(r_8 frac, int_4 debug) const 1100 1110 { 1111 if(mBins<=0) return 0; 1101 1112 r_8 xmax = BinCenter( IMax() ); 1102 1113 return FindWidth(xmax,frac,debug); … … 1110 1121 r_8 Histo::FindWidth(r_8 xmax,r_8 frac, int_4 debug) const 1111 1122 { 1123 if(mBins<=0) return 0; 1112 1124 if (frac <= 0 || frac >= 1.) frac = 0.5; 1113 1125 … … 1205 1217 int_4 Histo::EstimeMax(int_4& im,r_8& xm,int_4 SzPav) const 1206 1218 { 1219 if(mBins<=0) return -1; 1207 1220 xm = 0; 1208 1221 if( SzPav <= 0 ) return -1; … … 1237 1250 void Histo::EstimeWidthS(r_8 frac,r_8& widthG,r_8& widthD) const 1238 1251 { 1252 if(mBins<=0) {frac=0.; return;} 1239 1253 int_4 i; 1240 1254 widthG = widthD = -1.; … … 1308 1322 { 1309 1323 1324 if(mBins<=0) return; 1310 1325 if( il > ih ) { il = 0; ih = mBins-1; } 1311 1326 if( il < 0 ) il = 0; … … 1490 1505 1491 1506 // Lecture des donnees Histo 1D 1492 dobj->mData = new r_8[dobj->mBins];1493 1507 is.GetLine(strg, 255); 1508 if(dobj->mBins>0) dobj->mData = new r_8[dobj->mBins]; 1494 1509 is.Get(dobj->mData, dobj->mBins); 1495 1510 … … 1497 1512 if(errok) { 1498 1513 is.GetLine(strg, 255); 1499 dobj->mErr2 = new r_8[dobj->mBins];1514 if(dobj->mBins>0) dobj->mErr2 = new r_8[dobj->mBins]; 1500 1515 is.Get(dobj->mErr2, dobj->mBins); 1501 1516 }
Note:
See TracChangeset
for help on using the changeset viewer.