Changeset 307 in Sophya for trunk/SophyaLib/NTools/histos.cc
- Timestamp:
- May 19, 1999, 5:58:06 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/histos.cc
r244 r307 1 1 // 2 // $Id: histos.cc,v 1. 2 1999-04-22 16:18:36ansari Exp $2 // $Id: histos.cc,v 1.3 1999-05-19 15:57:59 ansari Exp $ 3 3 // 4 4 … … 14 14 #include "generalfit.h" 15 15 16 using namespace PlanckDPC; 17 16 18 //++ 17 19 // Class Histo … … 50 52 { 51 53 Zero(); 52 END_CONSTRUCTOR53 }54 55 /********* Methode *********/56 //++57 Histo::Histo(char *flnm)58 //59 //--60 : data(NULL), err2(NULL),61 under(0), over(0), nHist(0), nEntries(0),62 bins(0), min(0), max(0), binWidth(0)63 {64 PInPersist s(flnm);65 Read(s);66 54 END_CONSTRUCTOR 67 55 } … … 379 367 //-- 380 368 { 381 if (b. bins!=a.bins) THROW(sizeMismatchErr);369 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 382 370 Histo c(a); 383 371 return (c += b); … … 389 377 //-- 390 378 { 391 if (b. bins!=a.bins) THROW(sizeMismatchErr);379 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 392 380 Histo c(a); 393 381 return (c -= b); … … 399 387 //-- 400 388 { 401 if (b. bins!=a.bins) THROW(sizeMismatchErr);389 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 402 390 Histo c(a); 403 391 return (c *= b); … … 409 397 //-- 410 398 { 411 if (b. bins!=a.bins) THROW(sizeMismatchErr);399 if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr); 412 400 Histo c(a); 413 401 return (c /= b); … … 1446 1434 1447 1435 //++ 1448 Histo *Histo::FitResidus(GeneralFit& gfit)1436 Histo Histo::FitResidus(GeneralFit& gfit) 1449 1437 // 1450 1438 // Retourne une classe contenant les residus du fit ``gfit''. 1451 1439 //-- 1452 1440 { 1453 if(NBins()<=0) return NULL; 1441 if(NBins()<=0) 1442 throw(SzMismatchError("Histo::FitResidus: size mismatch\n")); 1454 1443 GeneralFunction* f = gfit.GetFunction(); 1455 if(f==NULL) return NULL; 1444 if(f==NULL) 1445 throw(NullPtrError("Histo::FitResidus: NULL pointer\n")); 1456 1446 Vector par = gfit.GetParm(); 1457 Histo * h = new Histo(*this);1447 Histo h(*this); 1458 1448 for(int i=0;i<NBins();i++) { 1459 1449 double x = (double) BinCenter(i); 1460 (*h)(i) -= (float) f->Value(&x,par.Data());1450 h(i) -= (float) f->Value(&x,par.Data()); 1461 1451 } 1462 1452 return h; … … 1464 1454 1465 1455 //++ 1466 Histo *Histo::FitFunction(GeneralFit& gfit)1456 Histo Histo::FitFunction(GeneralFit& gfit) 1467 1457 // 1468 1458 // Retourne une classe contenant la fonction du fit ``gfit''. 1469 1459 //-- 1470 1460 { 1471 if(NBins()<=0) return NULL; 1461 if(NBins()<=0) 1462 throw(SzMismatchError("Histo::FitFunction: size mismatch\n")); 1472 1463 GeneralFunction* f = gfit.GetFunction(); 1473 if(f==NULL) return NULL; 1464 if(f==NULL) 1465 throw(NullPtrError("Histo::FitFunction: NULL pointer\n")); 1474 1466 Vector par = gfit.GetParm(); 1475 Histo * h = new Histo(*this);1467 Histo h(*this); 1476 1468 for(int i=0;i<NBins();i++) { 1477 1469 double x = (double) BinCenter(i); 1478 (*h)(i) = (float) f->Value(&x,par.Data());1470 h(i) = (float) f->Value(&x,par.Data()); 1479 1471 } 1480 1472 return h; … … 1662 1654 Histo::PrintF(stdout, hdyn, hmin, hmax, pflag, il, ih); 1663 1655 } 1664 1665 1666 /********* Methode *********/ 1667 //++ 1668 void Histo::WriteSelf(POutPersist& s) const 1669 // 1670 // Ecriture ppersist 1671 //-- 1656 1657 1658 // Rappel des inlines functions pour commentaires 1659 //++ 1660 // inline float XMin() const 1661 // Retourne l'abscisse minimum 1662 //-- 1663 //++ 1664 // inline float XMax() const 1665 // Retourne l'abscisse maximum 1666 //-- 1667 //++ 1668 // inline int NBins() const 1669 // Retourne le nombre de bins 1670 //-- 1671 //++ 1672 // inline float BinWidth() const 1673 // Retourne la largeur du bin 1674 //-- 1675 //++ 1676 // inline float* Bins() const 1677 // Retourne le pointeur sur le tableaux des contenus 1678 //-- 1679 //++ 1680 // inline float operator()(int i) const 1681 // Retourne le contenu du bin i 1682 //-- 1683 //++ 1684 // inline float& operator()(int i) 1685 // Remplit le contenu du bin i 1686 //-- 1687 //++ 1688 // inline float Error(int i) const 1689 // Retourne l'erreur du bin i 1690 //-- 1691 //++ 1692 // inline double Error2(int i) const 1693 // Retourne l'erreur au carre du bin i 1694 //-- 1695 //++ 1696 // inline double& Error2(int i) 1697 // Remplit l'erreur au carre du bin i 1698 //-- 1699 //++ 1700 // inline float NData() const 1701 // Retourne la somme ponderee 1702 //-- 1703 //++ 1704 // inline float NEntries() 1705 // Retourne le nombre d'entrees 1706 //-- 1707 //++ 1708 // inline float NOver() const 1709 // Retourne le nombre d'overflow 1710 //-- 1711 //++ 1712 // inline float NUnder() const 1713 // Retourne le nombre d'underflow 1714 //-- 1715 //++ 1716 // inline float BinLowEdge(int i) const 1717 // Retourne l'abscisse du bord inferieur du bin i 1718 //-- 1719 //++ 1720 // inline float BinCenter(int i) const 1721 // Retourne l'abscisse du centre du bin i 1722 //-- 1723 //++ 1724 // inline float BinHighEdge(int i) const 1725 // Retourne l'abscisse du bord superieur du bin i 1726 //-- 1727 //++ 1728 // inline int FindBin(float x) const 1729 // Retourne le numero du bin contenant l'abscisse x 1730 //-- 1731 1732 1733 /////////////////////////////////////////////////////////// 1734 // -------------------------------------------------------- 1735 // Les objets delegues pour la gestion de persistance 1736 // -------------------------------------------------------- 1737 /////////////////////////////////////////////////////////// 1738 1739 FIO_Histo::FIO_Histo() 1740 { 1741 dobj=new Histo; 1742 ownobj=true; 1743 } 1744 1745 FIO_Histo::FIO_Histo(string const & filename) 1746 { 1747 dobj=new Histo; 1748 ownobj=true; 1749 Read(filename); 1750 } 1751 1752 FIO_Histo::FIO_Histo(const Histo & obj) 1753 { 1754 dobj = new Histo(obj); 1755 ownobj=true; 1756 } 1757 1758 FIO_Histo::FIO_Histo(Histo * obj) 1759 { 1760 dobj = obj; 1761 ownobj=false; 1762 } 1763 1764 FIO_Histo::~FIO_Histo() 1765 { 1766 if (ownobj && dobj) delete dobj; 1767 } 1768 1769 AnyDataObj* FIO_Histo::DataObj() 1770 { 1771 return(dobj); 1772 } 1773 1774 void FIO_Histo::ReadSelf(PInPersist& is) 1672 1775 { 1673 1776 char strg[256]; 1674 1777 1778 if(dobj==NULL) dobj=new Histo; 1779 else dobj->Delete(); 1780 1781 // Lecture entete 1782 is.GetLine(strg, 255); 1783 is.GetLine(strg, 255); 1784 is.GetLine(strg, 255); 1785 1786 // Lecture des valeurs 1787 is.Get(dobj->bins); 1788 is.Get(dobj->nEntries); 1789 int_4 errok; 1790 is.Get(errok); 1791 1792 is.Get(dobj->binWidth); 1793 is.Get(dobj->min); 1794 is.Get(dobj->max); 1795 is.Get(dobj->under); 1796 is.Get(dobj->over); 1797 1798 is.Get(dobj->nHist); 1799 1800 // Lecture des donnees Histo 1D 1801 dobj->data = new float[dobj->bins]; 1802 is.GetLine(strg, 255); 1803 is.Get(dobj->data, dobj->bins); 1804 1805 // Lecture des erreurs 1806 if(errok) { 1807 is.GetLine(strg, 255); 1808 dobj->err2 = new double[dobj->bins]; 1809 is.Get(dobj->err2, dobj->bins); 1810 } 1811 1812 return; 1813 } 1814 1815 void FIO_Histo::WriteSelf(POutPersist& os) const 1816 { 1817 if (dobj == NULL) return; 1818 char strg[256]; 1819 1675 1820 // Que faut-il ecrire? 1676 int errok = ( err2) ? 1 : 0;1821 int errok = (dobj->err2) ? 1 : 0; 1677 1822 1678 1823 // Ecriture entete pour identifier facilement 1679 sprintf(strg,"bins=%6d NEnt=%15d errok=%1d", bins,nEntries,errok);1680 s.PutLine(strg);1681 sprintf(strg,"binw=%g min=%g max=%g", binWidth,min,max);1682 s.PutLine(strg);1683 sprintf(strg, "under=%g over=%g nHist=%g", under,over,nHist);1684 s.PutLine(strg);1824 sprintf(strg,"bins=%6d NEnt=%15d errok=%1d",dobj->bins,dobj->nEntries,errok); 1825 os.PutLine(strg); 1826 sprintf(strg,"binw=%g min=%g max=%g",dobj->binWidth,dobj->min,dobj->max); 1827 os.PutLine(strg); 1828 sprintf(strg, "under=%g over=%g nHist=%g",dobj->under,dobj->over,dobj->nHist); 1829 os.PutLine(strg); 1685 1830 1686 1831 // Ecriture des valeurs 1687 s.PutI4(bins);1688 s.PutI4(nEntries);1689 s.PutI4(errok);1690 1691 s.PutR4(binWidth);1692 s.PutR4(min);1693 s.PutR4(max);1694 s.PutR4(under);1695 s.PutR4(over);1696 1697 s.PutR8(nHist);1832 os.Put(dobj->bins); 1833 os.Put(dobj->nEntries); 1834 os.Put(errok); 1835 1836 os.Put(dobj->binWidth); 1837 os.Put(dobj->min); 1838 os.Put(dobj->max); 1839 os.Put(dobj->under); 1840 os.Put(dobj->over); 1841 1842 os.Put(dobj->nHist); 1698 1843 1699 1844 // Ecriture des donnees Histo 1D 1700 sprintf(strg,"Histo: Tableau des donnees %d", bins);1701 s.PutLine(strg);1702 s.PutR4s(data,bins);1845 sprintf(strg,"Histo: Tableau des donnees %d",dobj->bins); 1846 os.PutLine(strg); 1847 os.Put(dobj->data, dobj->bins); 1703 1848 1704 1849 // Ecriture des erreurs 1705 1850 if(errok) { 1706 sprintf(strg,"Histo: Tableau des erreurs %d", bins);1707 s.PutLine(strg);1708 s.PutR8s(err2,bins);1851 sprintf(strg,"Histo: Tableau des erreurs %d",dobj->bins); 1852 os.PutLine(strg); 1853 os.Put(dobj->err2, dobj->bins); 1709 1854 } 1710 1855 1711 1856 return; 1712 1857 } 1713 1714 /********* Methode *********/1715 //++1716 void Histo::ReadSelf(PInPersist& s)1717 //1718 // Lecture ppersist1719 //--1720 {1721 char strg[256];1722 1723 Delete();1724 1725 // Lecture entete1726 s.GetLine(strg, 255);1727 s.GetLine(strg, 255);1728 s.GetLine(strg, 255);1729 1730 // Lecture des valeurs1731 s.GetI4(bins);1732 s.GetI4(nEntries);1733 int_4 errok;1734 s.GetI4(errok);1735 1736 s.GetR4(binWidth);1737 s.GetR4(min);1738 s.GetR4(max);1739 s.GetR4(under);1740 s.GetR4(over);1741 1742 s.GetR8(nHist);1743 1744 // Lecture des donnees Histo 1D1745 data = new float[bins];1746 s.GetLine(strg, 255);1747 s.GetR4s(data, bins);1748 1749 // Lecture des erreurs1750 if(errok) {1751 s.GetLine(strg, 255);1752 err2 = new double[bins];1753 s.GetR8s(err2, bins);1754 }1755 1756 return;1757 }1758 1759 1760 1761 // Rappel des inlines functions pour commentaires1762 //++1763 // inline float XMin() const1764 // Retourne l'abscisse minimum1765 //--1766 //++1767 // inline float XMax() const1768 // Retourne l'abscisse maximum1769 //--1770 //++1771 // inline int NBins() const1772 // Retourne le nombre de bins1773 //--1774 //++1775 // inline float BinWidth() const1776 // Retourne la largeur du bin1777 //--1778 //++1779 // inline float* Bins() const1780 // Retourne le pointeur sur le tableaux des contenus1781 //--1782 //++1783 // inline float operator()(int i) const1784 // Retourne le contenu du bin i1785 //--1786 //++1787 // inline float& operator()(int i)1788 // Remplit le contenu du bin i1789 //--1790 //++1791 // inline float Error(int i) const1792 // Retourne l'erreur du bin i1793 //--1794 //++1795 // inline double Error2(int i) const1796 // Retourne l'erreur au carre du bin i1797 //--1798 //++1799 // inline double& Error2(int i)1800 // Remplit l'erreur au carre du bin i1801 //--1802 //++1803 // inline float NData() const1804 // Retourne la somme ponderee1805 //--1806 //++1807 // inline float NEntries()1808 // Retourne le nombre d'entrees1809 //--1810 //++1811 // inline float NOver() const1812 // Retourne le nombre d'overflow1813 //--1814 //++1815 // inline float NUnder() const1816 // Retourne le nombre d'underflow1817 //--1818 //++1819 // inline float BinLowEdge(int i) const1820 // Retourne l'abscisse du bord inferieur du bin i1821 //--1822 //++1823 // inline float BinCenter(int i) const1824 // Retourne l'abscisse du centre du bin i1825 //--1826 //++1827 // inline float BinHighEdge(int i) const1828 // Retourne l'abscisse du bord superieur du bin i1829 //--1830 //++1831 // inline int FindBin(float x) const1832 // Retourne le numero du bin contenant l'abscisse x1833 //--
Note:
See TracChangeset
for help on using the changeset viewer.