Changeset 307 in Sophya for trunk/SophyaLib/NTools/histos.cc


Ignore:
Timestamp:
May 19, 1999, 5:58:06 PM (26 years ago)
Author:
ansari
Message:

FIO_... + grosses modifs cmv 19/5/99

File:
1 edited

Legend:

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

    r244 r307  
    11//
    2 // $Id: histos.cc,v 1.2 1999-04-22 16:18:36 ansari Exp $
     2// $Id: histos.cc,v 1.3 1999-05-19 15:57:59 ansari Exp $
    33//
    44
     
    1414#include "generalfit.h"
    1515
     16using namespace PlanckDPC;
     17
    1618//++
    1719// Class        Histo
     
    5052{
    5153  Zero();
    52   END_CONSTRUCTOR
    53 }
    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);
    6654  END_CONSTRUCTOR
    6755}
     
    379367//--
    380368{
    381 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     369if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    382370Histo c(a);
    383371return (c += b);
     
    389377//--
    390378{
    391 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     379if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    392380Histo c(a);
    393381return (c -= b);
     
    399387//--
    400388{
    401 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     389if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    402390Histo c(a);
    403391return (c *= b);
     
    409397//--
    410398{
    411 if (b.bins!=a.bins) THROW(sizeMismatchErr);
     399if (b.NBins()!=a.NBins()) THROW(sizeMismatchErr);
    412400Histo c(a);
    413401return (c /= b);
     
    14461434
    14471435//++
    1448 Histo* Histo::FitResidus(GeneralFit& gfit)
     1436Histo Histo::FitResidus(GeneralFit& gfit)
    14491437//
    14501438//      Retourne une classe contenant les residus du fit ``gfit''.
    14511439//--
    14521440{
    1453 if(NBins()<=0) return NULL;
     1441if(NBins()<=0)
     1442  throw(SzMismatchError("Histo::FitResidus: size mismatch\n"));
    14541443GeneralFunction* f = gfit.GetFunction();
    1455 if(f==NULL) return NULL;
     1444if(f==NULL)
     1445  throw(NullPtrError("Histo::FitResidus: NULL pointer\n"));
    14561446Vector par = gfit.GetParm();
    1457 Histo* h = new Histo(*this);
     1447Histo h(*this);
    14581448for(int i=0;i<NBins();i++) {
    14591449  double x = (double) BinCenter(i);
    1460   (*h)(i) -= (float) f->Value(&x,par.Data());
     1450  h(i) -= (float) f->Value(&x,par.Data());
    14611451}
    14621452return h;
     
    14641454
    14651455//++
    1466 Histo* Histo::FitFunction(GeneralFit& gfit)
     1456Histo Histo::FitFunction(GeneralFit& gfit)
    14671457//
    14681458//      Retourne une classe contenant la fonction du fit ``gfit''.
    14691459//--
    14701460{
    1471 if(NBins()<=0) return NULL;
     1461if(NBins()<=0)
     1462  throw(SzMismatchError("Histo::FitFunction: size mismatch\n"));
    14721463GeneralFunction* f = gfit.GetFunction();
    1473 if(f==NULL) return NULL;
     1464if(f==NULL)
     1465  throw(NullPtrError("Histo::FitFunction: NULL pointer\n"));
    14741466Vector par = gfit.GetParm();
    1475 Histo* h = new Histo(*this);
     1467Histo h(*this);
    14761468for(int i=0;i<NBins();i++) {
    14771469  double x = (double) BinCenter(i);
    1478   (*h)(i) = (float) f->Value(&x,par.Data());
     1470  h(i) = (float) f->Value(&x,par.Data());
    14791471}
    14801472return h;
     
    16621654 Histo::PrintF(stdout, hdyn, hmin, hmax, pflag, il, ih);
    16631655}
    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
     1739FIO_Histo::FIO_Histo()
     1740{
     1741dobj=new Histo;
     1742ownobj=true;
     1743}
     1744
     1745FIO_Histo::FIO_Histo(string const & filename)
     1746{
     1747dobj=new Histo;
     1748ownobj=true;
     1749Read(filename);
     1750}
     1751
     1752FIO_Histo::FIO_Histo(const Histo & obj)
     1753{
     1754dobj = new Histo(obj);
     1755ownobj=true;
     1756}
     1757
     1758FIO_Histo::FIO_Histo(Histo * obj)
     1759{
     1760dobj = obj;
     1761ownobj=false;
     1762}
     1763
     1764FIO_Histo::~FIO_Histo()
     1765{
     1766if (ownobj && dobj) delete dobj;
     1767}
     1768
     1769AnyDataObj* FIO_Histo::DataObj()
     1770{
     1771return(dobj);
     1772}
     1773
     1774void FIO_Histo::ReadSelf(PInPersist& is)
    16721775{
    16731776char strg[256];
    16741777
     1778if(dobj==NULL) dobj=new Histo;
     1779  else         dobj->Delete();
     1780
     1781// Lecture entete
     1782is.GetLine(strg, 255);
     1783is.GetLine(strg, 255);
     1784is.GetLine(strg, 255);
     1785
     1786// Lecture des valeurs
     1787is.Get(dobj->bins);
     1788is.Get(dobj->nEntries);
     1789int_4 errok;
     1790is.Get(errok);
     1791
     1792is.Get(dobj->binWidth);
     1793is.Get(dobj->min);
     1794is.Get(dobj->max);
     1795is.Get(dobj->under);
     1796is.Get(dobj->over);
     1797
     1798is.Get(dobj->nHist);
     1799
     1800// Lecture des donnees Histo 1D
     1801dobj->data = new float[dobj->bins];
     1802is.GetLine(strg, 255);
     1803is.Get(dobj->data, dobj->bins);
     1804
     1805// Lecture des erreurs
     1806if(errok) {
     1807  is.GetLine(strg, 255);
     1808  dobj->err2 = new double[dobj->bins];
     1809  is.Get(dobj->err2, dobj->bins);
     1810}
     1811
     1812return;
     1813}
     1814
     1815void FIO_Histo::WriteSelf(POutPersist& os) const
     1816{
     1817if (dobj == NULL)   return;
     1818char strg[256];
     1819
    16751820// Que faut-il ecrire?
    1676 int errok = (err2) ? 1 : 0;
     1821int errok = (dobj->err2) ? 1 : 0;
    16771822
    16781823// 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);
     1824sprintf(strg,"bins=%6d  NEnt=%15d  errok=%1d",dobj->bins,dobj->nEntries,errok);
     1825os.PutLine(strg);
     1826sprintf(strg,"binw=%g  min=%g max=%g",dobj->binWidth,dobj->min,dobj->max);
     1827os.PutLine(strg);
     1828sprintf(strg, "under=%g over=%g nHist=%g",dobj->under,dobj->over,dobj->nHist);
     1829os.PutLine(strg);
    16851830
    16861831// 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);
     1832os.Put(dobj->bins);
     1833os.Put(dobj->nEntries);
     1834os.Put(errok);
     1835
     1836os.Put(dobj->binWidth);
     1837os.Put(dobj->min);
     1838os.Put(dobj->max);
     1839os.Put(dobj->under);
     1840os.Put(dobj->over);
     1841
     1842os.Put(dobj->nHist);
    16981843
    16991844// Ecriture des donnees Histo 1D
    1700 sprintf(strg,"Histo: Tableau des donnees %d",bins);
    1701 s.PutLine(strg);
    1702 s.PutR4s(data, bins);
     1845sprintf(strg,"Histo: Tableau des donnees %d",dobj->bins);
     1846os.PutLine(strg);
     1847os.Put(dobj->data, dobj->bins);
    17031848
    17041849// Ecriture des erreurs
    17051850if(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);
    17091854}
    17101855
    17111856return;
    17121857}
    1713 
    1714 /********* Methode *********/
    1715 //++
    1716 void  Histo::ReadSelf(PInPersist& s)
    1717 //
    1718 //      Lecture ppersist
    1719 //--
    1720 {
    1721 char strg[256];
    1722 
    1723 Delete();
    1724 
    1725 // Lecture entete
    1726 s.GetLine(strg, 255);
    1727 s.GetLine(strg, 255);
    1728 s.GetLine(strg, 255);
    1729 
    1730 // Lecture des valeurs
    1731 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 1D
    1745 data = new float[bins];
    1746 s.GetLine(strg, 255);
    1747 s.GetR4s(data, bins);
    1748 
    1749 // Lecture des erreurs
    1750 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 commentaires
    1762 //++
    1763 // inline float          XMin() const
    1764 //      Retourne l'abscisse minimum
    1765 //--
    1766 //++
    1767 // inline float          XMax() const
    1768 //      Retourne l'abscisse maximum
    1769 //--
    1770 //++
    1771 // inline int            NBins() const
    1772 //      Retourne le nombre de bins
    1773 //--
    1774 //++
    1775 // inline float          BinWidth() const
    1776 //      Retourne la largeur du bin
    1777 //--
    1778 //++
    1779 // inline float*         Bins() const
    1780 //      Retourne le pointeur sur le tableaux des contenus
    1781 //--
    1782 //++
    1783 // inline float          operator()(int i) const
    1784 //      Retourne le contenu du bin i
    1785 //--
    1786 //++
    1787 // inline float&         operator()(int i)
    1788 //      Remplit le contenu du bin i
    1789 //--
    1790 //++
    1791 // inline float          Error(int i) const
    1792 //      Retourne l'erreur du bin i
    1793 //--
    1794 //++
    1795 // inline double         Error2(int i) const
    1796 //      Retourne l'erreur au carre du bin i
    1797 //--
    1798 //++
    1799 // inline double&        Error2(int i)
    1800 //      Remplit l'erreur au carre du bin i
    1801 //--
    1802 //++
    1803 // inline float          NData() const
    1804 //      Retourne la somme ponderee
    1805 //--
    1806 //++
    1807 // inline float          NEntries()
    1808 //      Retourne le nombre d'entrees
    1809 //--
    1810 //++
    1811 // inline float          NOver() const
    1812 //      Retourne le nombre d'overflow
    1813 //--
    1814 //++
    1815 // inline float          NUnder() const
    1816 //      Retourne le nombre d'underflow
    1817 //--
    1818 //++
    1819 // inline float          BinLowEdge(int i)  const
    1820 //      Retourne l'abscisse du bord inferieur du bin i
    1821 //--
    1822 //++
    1823 // inline float          BinCenter(int i)   const
    1824 //      Retourne l'abscisse du centre du bin i
    1825 //--
    1826 //++
    1827 // inline float          BinHighEdge(int i) const
    1828 //      Retourne l'abscisse du bord superieur du bin i
    1829 //--
    1830 //++
    1831 // inline int            FindBin(float x) const   
    1832 //      Retourne le numero du bin contenant l'abscisse x
    1833 //--
Note: See TracChangeset for help on using the changeset viewer.