Changeset 307 in Sophya for trunk/SophyaLib/NTools/histos2.cc
- Timestamp:
- May 19, 1999, 5:58:06 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/histos2.cc
r244 r307 16 16 #include "generalfit.h" 17 17 18 using namespace PlanckDPC; 19 18 20 //++ 19 21 // Class Histo2D … … 132 134 for(int i=0;i<3;i++) for(int j=0;j<3;j++) over[i][j]=0.; 133 135 b_s.H = NULL; 134 END_CONSTRUCTOR135 }136 137 //++138 Histo2D::Histo2D(char *flnm)139 //140 // Constructeur par lecture d'un fichier ppersist.141 //--142 : data(NULL), err2(NULL)143 , nHist(0), nEntries(0)144 , nx(0), ny(0), nxy(0)145 , xmin(0), xmax(0), ymin(0), ymax(0)146 , wbinx(0), wbiny(0)147 , hprojx(NULL), hprojy(NULL)148 {149 b_s.H = NULL;150 PInPersist s(flnm);151 Read(s);152 136 END_CONSTRUCTOR 153 137 } … … 582 566 //-- 583 567 { 584 if (b. nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);568 if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr); 585 569 Histo2D c(a); 586 570 return (c += b); … … 592 576 //-- 593 577 { 594 if (b. nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);578 if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr); 595 579 Histo2D c(a); 596 580 return (c -= b); … … 602 586 //-- 603 587 { 604 if (b. nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);588 if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr); 605 589 Histo2D c(a); 606 590 return (c *= b); … … 612 596 //-- 613 597 { 614 if (b. nx!=a.nx || b.ny!=a.ny) THROW(sizeMismatchErr);598 if (b.NBinX()!=a.NBinX() || b.NBinY()!=a.NBinY()) THROW(sizeMismatchErr); 615 599 Histo2D c(a); 616 600 return (c /= b); … … 1113 1097 1114 1098 //++ 1115 Histo2D *Histo2D::FitResidus(GeneralFit& gfit)1099 Histo2D Histo2D::FitResidus(GeneralFit& gfit) 1116 1100 // 1117 1101 // Retourne une classe contenant les residus du fit ``gfit''. 1118 1102 //-- 1119 1103 { 1120 if(NBinX()<=0 || NBinY()<=0) return NULL; 1104 if(NBinX()<=0 || NBinY()<=0) 1105 throw(SzMismatchError("Histo2D::FitResidus: size mismatch\n")); 1121 1106 GeneralFunction* f = gfit.GetFunction(); 1122 if(f==NULL) return NULL; 1107 if(f==NULL) 1108 throw(NullPtrError("Histo2D::FitResidus: NULL pointer\n")); 1123 1109 Vector par = gfit.GetParm(); 1124 Histo2D * h2 = new Histo2D(*this);1110 Histo2D h2(*this); 1125 1111 for(int i=0;i<NBinX();i++) for(int j=0;j<NBinY();j++) { 1126 1112 float xc,yc; 1127 1113 BinCenter(i,j,xc,yc); 1128 1114 double x[2] = {(double)xc,(double)yc}; 1129 (*h2)(i,j) -= (float) f->Value(x,par.Data());1115 h2(i,j) -= (float) f->Value(x,par.Data()); 1130 1116 } 1131 1117 return h2; … … 1133 1119 1134 1120 //++ 1135 Histo2D *Histo2D::FitFunction(GeneralFit& gfit)1121 Histo2D Histo2D::FitFunction(GeneralFit& gfit) 1136 1122 // 1137 1123 // Retourne une classe contenant la fonction du fit ``gfit''. 1138 1124 //-- 1139 1125 { 1140 if(NBinX()<=0 || NBinY()<=0) return NULL; 1126 if(NBinX()<=0 || NBinY()<=0) 1127 throw(SzMismatchError("Histo2D::FitFunction: size mismatch\n")); 1141 1128 GeneralFunction* f = gfit.GetFunction(); 1142 if(f==NULL) return NULL; 1129 if(f==NULL) 1130 throw(NullPtrError("Histo2D::FitFunction: NULL pointer\n")); 1143 1131 Vector par = gfit.GetParm(); 1144 Histo2D * h2 = new Histo2D(*this);1132 Histo2D h2(*this); 1145 1133 for(int i=0;i<NBinX();i++) for(int j=0;j<NBinY();j++) { 1146 1134 float xc,yc; 1147 1135 BinCenter(i,j,xc,yc); 1148 1136 double x[2] = {(double)xc,(double)yc}; 1149 (*h2)(i,j) = (float) f->Value(x,par.Data());1137 h2(i,j) = (float) f->Value(x,par.Data()); 1150 1138 } 1151 1139 return h2; … … 1792 1780 1793 1781 1794 /////////////////////////////////////////////////////////////////// 1795 //++ 1796 // Titre Methodes pour ecriture ppersist 1797 //-- 1798 1799 //++ 1800 void Histo2D::WriteSelf(POutPersist& s) const 1801 // 1802 // Ecriture fichier de type ppersist. 1803 //-- 1782 /////////////////////////////////////////////////////////// 1783 // -------------------------------------------------------- 1784 // Les objets delegues pour la gestion de persistance 1785 // -------------------------------------------------------- 1786 /////////////////////////////////////////////////////////// 1787 1788 FIO_Histo2D::FIO_Histo2D() 1789 { 1790 dobj=new Histo2D; 1791 ownobj=true; 1792 } 1793 1794 FIO_Histo2D::FIO_Histo2D(string const & filename) 1795 { 1796 dobj=new Histo2D; 1797 ownobj=true; 1798 Read(filename); 1799 } 1800 1801 FIO_Histo2D::FIO_Histo2D(const Histo2D & obj) 1802 { 1803 dobj = new Histo2D(obj); 1804 ownobj=true; 1805 } 1806 1807 FIO_Histo2D::FIO_Histo2D(Histo2D * obj) 1808 { 1809 dobj = obj; 1810 ownobj=false; 1811 } 1812 1813 FIO_Histo2D::~FIO_Histo2D() 1814 { 1815 if (ownobj && dobj) delete dobj; 1816 } 1817 1818 AnyDataObj* FIO_Histo2D::DataObj() 1819 { 1820 return(dobj); 1821 } 1822 1823 void FIO_Histo2D::ReadSelf(PInPersist& is) 1804 1824 { 1805 1825 char strg[256]; 1806 int j; 1826 1827 if(dobj==NULL) dobj=new Histo2D; 1828 else dobj->Delete(); 1829 1807 1830 float min,max; 1808 1831 Histo* h; 1832 int_4 errok, projx, projy, nslix, nsliy, nbanx, nbany; 1833 1834 // Lecture entete 1835 is.GetLine(strg, 255); 1836 is.GetLine(strg, 255); 1837 is.GetLine(strg, 255); 1838 is.GetLine(strg, 255); 1839 is.GetLine(strg, 255); 1840 is.GetLine(strg, 255); 1841 1842 // Lecture variables de definitions 1843 is.Get(dobj->nx); 1844 is.Get(dobj->ny); 1845 is.Get(dobj->nxy); 1846 is.Get(errok); 1847 is.Get(dobj->nEntries); 1848 is.Get(dobj->nHist); 1849 1850 is.Get(dobj->xmin); 1851 is.Get(dobj->xmax); 1852 is.Get(dobj->ymin); 1853 is.Get(dobj->ymax); 1854 is.Get(dobj->wbinx); 1855 is.Get(dobj->wbiny); 1856 1857 is.Get(&(dobj->over[0][0]),9); 1858 1859 is.Get(projx); 1860 is.Get(projy); 1861 is.Get(nslix); 1862 is.Get(nsliy); 1863 is.Get(nbanx); 1864 is.Get(nbany); 1865 1866 // Lecture histo2D 1867 dobj->data = new float[dobj->nxy]; 1868 is.GetLine(strg, 255); 1869 {for(int j=0;j<dobj->ny;j++) is.Get(dobj->data+j*dobj->nx,dobj->nx);} 1870 1871 // Lecture erreurs 1872 if(errok) { 1873 is.GetLine(strg, 255); 1874 dobj->err2 = new double[dobj->nxy]; 1875 for(int j=0;j<dobj->ny;j++) is.Get(dobj->err2+j*dobj->nx,dobj->nx); 1876 } 1877 1878 // Lecture des projections 1879 if(projx) { 1880 is.GetLine(strg, 255); 1881 dobj->SetProjX(); 1882 FIO_Histo fio_h(dobj->hprojx); 1883 fio_h.Read(is); 1884 } 1885 if(projy) { 1886 is.GetLine(strg, 255); 1887 dobj->SetProjY(); 1888 FIO_Histo fio_h(dobj->hprojy); 1889 fio_h.Read(is); 1890 } 1891 1892 // Lecture des slices 1893 if(nslix>0) { 1894 is.GetLine(strg, 255); 1895 dobj->SetSliX(nslix); 1896 DBASSERT (nslix==dobj->NSliX()); 1897 for(int j=0;j<dobj->NSliX();j++) 1898 {FIO_Histo fio_h(dobj->HSliX(j)); fio_h.Read(is);} 1899 } 1900 if(nsliy>0) { 1901 is.GetLine(strg, 255); 1902 dobj->SetSliY(nsliy); 1903 DBASSERT (nsliy==dobj->NSliY()); 1904 for(int j=0;j<dobj->NSliY();j++) 1905 {FIO_Histo fio_h(dobj->HSliY(j)); fio_h.Read(is);} 1906 } 1907 1908 // Lecture des bandes 1909 if( nbanx>0 ) { 1910 is.GetLine(strg, 255); 1911 {for(int j=0; j<nbanx; j++) { 1912 is.Get(min); is.Get(max); 1913 dobj->SetBandX(min,max); 1914 }} 1915 DBASSERT (nbanx==dobj->NBandX()); 1916 {for(int j=0; j<dobj->NBandX(); j++) { 1917 FIO_Histo fio_h(dobj->HBandX(j)); 1918 fio_h.Read(is); 1919 }} 1920 } 1921 if( nbany>0 ) { 1922 is.GetLine(strg, 255); 1923 {for(int j=0; j<nbany; j++) { 1924 is.Get(min); is.Get(max); 1925 dobj->SetBandY(min,max); 1926 }} 1927 DBASSERT (nbany==dobj->NBandY()); 1928 {for(int j=0; j<dobj->NBandY(); j++) { 1929 FIO_Histo fio_h(dobj->HBandY(j)); 1930 fio_h.Read(is); 1931 }} 1932 } 1933 1934 return; 1935 } 1936 1937 void FIO_Histo2D::WriteSelf(POutPersist& os) const 1938 { 1939 if (dobj == NULL) return; 1940 char strg[256]; 1809 1941 1810 1942 // Que faut-il ecrire? 1811 int_4 errok = ( err2) ? 1 : 0;1812 int_4 projx = ( hprojx) ? 1 : 0;1813 int_4 projy = ( hprojy) ? 1 : 0;1814 int_4 nslix = NSliX();1815 int_4 nsliy = NSliY();1816 int_4 nbanx = NBandX();1817 int_4 nbany = NBandY();1943 int_4 errok = (dobj->err2) ? 1 : 0; 1944 int_4 projx = (dobj->hprojx) ? 1 : 0; 1945 int_4 projy = (dobj->hprojy) ? 1 : 0; 1946 int_4 nslix = dobj->NSliX(); 1947 int_4 nsliy = dobj->NSliY(); 1948 int_4 nbanx = dobj->NBandX(); 1949 int_4 nbany = dobj->NBandY(); 1818 1950 1819 1951 // Ecriture entete pour identifier facilement 1820 sprintf(strg,"nx=%d ny=%d nxy=%d errok=%1d",nx,ny,nxy,errok); 1821 s.PutLine(strg); 1822 sprintf(strg,"nHist=%g nEntries=%d",nHist,nEntries); 1823 s.PutLine(strg); 1824 sprintf(strg,"wbinx=%g wbiny=%g",wbinx,wbiny); 1825 s.PutLine(strg); 1826 sprintf(strg,"xmin=%g xmax=%g ymin=%g ymax=%g",xmin,xmax,ymin,ymax); 1827 s.PutLine(strg); 1952 sprintf(strg,"nx=%d ny=%d nxy=%d errok=%1d" 1953 ,dobj->nx,dobj->ny,dobj->nxy,errok); 1954 os.PutLine(strg); 1955 sprintf(strg,"nHist=%g nEntries=%d",dobj->nHist,dobj->nEntries); 1956 os.PutLine(strg); 1957 sprintf(strg,"wbinx=%g wbiny=%g",dobj->wbinx,dobj->wbiny); 1958 os.PutLine(strg); 1959 sprintf(strg,"xmin=%g xmax=%g ymin=%g ymax=%g" 1960 ,dobj->xmin,dobj->xmax,dobj->ymin,dobj->ymax); 1961 os.PutLine(strg); 1828 1962 sprintf(strg,"projx/y=%d %d nbandx/y=%d %d nbslix/y=%d %d" 1829 1963 ,projx,projy,nbanx,nbany,nslix,nsliy); 1830 s.PutLine(strg);1964 os.PutLine(strg); 1831 1965 sprintf(strg,"over %g %g %g %g %g %g %g %g %g" 1832 , over[0][0],over[0][1],over[0][2]1833 , over[1][0],over[1][1],over[1][2]1834 , over[2][0],over[2][1],over[2][2]);1835 s.PutLine(strg);1966 ,dobj->over[0][0],dobj->over[0][1],dobj->over[0][2] 1967 ,dobj->over[1][0],dobj->over[1][1],dobj->over[1][2] 1968 ,dobj->over[2][0],dobj->over[2][1],dobj->over[2][2]); 1969 os.PutLine(strg); 1836 1970 1837 1971 // Ecriture variables de definitions 1838 s.PutI4(nx);1839 s.PutI4(ny);1840 s.PutI4(nxy);1841 s.PutI4(errok);1842 s.PutI4(nEntries);1843 s.PutR8(nHist);1844 1845 s.PutR4(xmin);1846 s.PutR4(xmax);1847 s.PutR4(ymin);1848 s.PutR4(ymax);1849 s.PutR4(wbinx);1850 s.PutR4(wbiny);1851 1852 s.PutR4s(&over[0][0],9);1853 1854 s.PutI4(projx);1855 s.PutI4(projy);1856 s.PutI4(nslix);1857 s.PutI4(nsliy);1858 s.PutI4(nbanx);1859 s.PutI4(nbany);1972 os.Put(dobj->nx); 1973 os.Put(dobj->ny); 1974 os.Put(dobj->nxy); 1975 os.Put(errok); 1976 os.Put(dobj->nEntries); 1977 os.Put(dobj->nHist); 1978 1979 os.Put(dobj->xmin); 1980 os.Put(dobj->xmax); 1981 os.Put(dobj->ymin); 1982 os.Put(dobj->ymax); 1983 os.Put(dobj->wbinx); 1984 os.Put(dobj->wbiny); 1985 1986 os.Put(&(dobj->over[0][0]),9); 1987 1988 os.Put(projx); 1989 os.Put(projy); 1990 os.Put(nslix); 1991 os.Put(nsliy); 1992 os.Put(nbanx); 1993 os.Put(nbany); 1860 1994 1861 1995 // Ecriture histo2D 1862 sprintf(strg,"Histo2D: Tableau des donnees %d = %d * %d" ,nxy,nx,ny);1863 s.PutLine(strg);1864 for(j=0;j<ny;j++) s.PutR4s(data+j*nx,nx);1865 1996 sprintf(strg,"Histo2D: Tableau des donnees %d = %d * %d" 1997 ,dobj->nxy,dobj->nx,dobj->ny); 1998 os.PutLine(strg); 1999 {for(int j=0;j<dobj->ny;j++) os.Put(dobj->data+j*dobj->nx,dobj->nx);} 1866 2000 1867 2001 // Ecriture erreurs 1868 2002 if(errok) { 1869 sprintf(strg,"Histo2D: Tableau des erreurs %d = %d * %d",nxy,nx,ny); 1870 s.PutLine(strg); 1871 for(j=0;j<ny;j++) s.PutR8s(err2+j*nx,nx); 2003 sprintf(strg,"Histo2D: Tableau des erreurs %d = %d * %d" 2004 ,dobj->nxy,dobj->nx,dobj->ny); 2005 os.PutLine(strg); 2006 for(int j=0;j<dobj->ny;j++) os.Put(dobj->err2+j*dobj->nx,dobj->nx); 1872 2007 } 1873 2008 … … 1875 2010 if(projx) { 1876 2011 sprintf(strg,"Histo2D: Projection X"); 1877 s.PutLine(strg);1878 hprojx->Write(s);2012 os.PutLine(strg); 2013 FIO_Histo fio_h(dobj->hprojx); fio_h.Write(os); 1879 2014 } 1880 2015 if(projy) { 1881 2016 sprintf(strg,"Histo2D: Projection Y"); 1882 s.PutLine(strg);1883 hprojy->Write(s);2017 os.PutLine(strg); 2018 FIO_Histo fio_h(dobj->hprojy); fio_h.Write(os); 1884 2019 } 1885 2020 … … 1887 2022 if(nslix>0) { 1888 2023 sprintf(strg,"Histo2D: Slices X %d",nslix); 1889 s.PutLine(strg);1890 for( j=0;j<nslix;j++) {1891 h =HSliX(j);1892 h->Write(s);2024 os.PutLine(strg); 2025 for(int j=0;j<nslix;j++) { 2026 Histo* h = dobj->HSliX(j); 2027 FIO_Histo fio_h(h); fio_h.Write(os); 1893 2028 } 1894 2029 } 1895 2030 if(nsliy>0) { 1896 2031 sprintf(strg,"Histo2D: Slices Y %d",nsliy); 1897 s.PutLine(strg);1898 for( j=0;j<nsliy;j++) {1899 h =HSliY(j);1900 h->Write(s);2032 os.PutLine(strg); 2033 for(int j=0;j<nsliy;j++) { 2034 Histo* h = dobj->HSliY(j); 2035 FIO_Histo fio_h(h); fio_h.Write(os); 1901 2036 } 1902 2037 } … … 1905 2040 if( nbanx>0 ) { 1906 2041 sprintf(strg,"Histo2D: Bandes X %d",nbanx); 1907 s.PutLine(strg); 1908 list<bande_slice>::const_iterator it; 1909 for(it = lbandx.begin(); it != lbandx.end(); it++) { 1910 min = (*it).min; 1911 max = (*it).max; 1912 s.PutR4(min); 1913 s.PutR4(max); 1914 } 1915 for(it = lbandx.begin(); it != lbandx.end(); it++) { 1916 h = (*it).H; 1917 h->Write(s); 2042 os.PutLine(strg); 2043 list<Histo2D::bande_slice>::const_iterator it; 2044 for(it = dobj->lbandx.begin(); it != dobj->lbandx.end(); it++) { 2045 float min = (*it).min; float max = (*it).max; 2046 os.Put(min); os.Put(max); 2047 } 2048 for(it = dobj->lbandx.begin(); it != dobj->lbandx.end(); it++) { 2049 Histo* h = (*it).H; 2050 FIO_Histo fio_h(h); fio_h.Write(os); 1918 2051 } 1919 2052 } 1920 2053 if( nbany>0 ) { 1921 2054 sprintf(strg,"Histo2D: Bandes Y %d",nbany); 1922 s.PutLine(strg); 1923 list<bande_slice>::const_iterator it; 1924 for(it = lbandy.begin(); it != lbandy.end(); it++) { 1925 min = (*it).min; 1926 max = (*it).max; 1927 s.PutR4(min); 1928 s.PutR4(max); 1929 } 1930 for(it = lbandy.begin(); it != lbandy.end(); it++) { 1931 h = (*it).H; 1932 h->Write(s); 2055 os.PutLine(strg); 2056 list<Histo2D::bande_slice>::const_iterator it; 2057 for(it = dobj->lbandy.begin(); it != dobj->lbandy.end(); it++) { 2058 float min = (*it).min; float max = (*it).max; 2059 os.Put(min); os.Put(max); 2060 } 2061 for(it = dobj->lbandy.begin(); it != dobj->lbandy.end(); it++) { 2062 Histo* h = (*it).H; 2063 FIO_Histo fio_h(h); fio_h.Write(os); 1933 2064 } 1934 2065 } … … 1936 2067 return; 1937 2068 } 1938 1939 //++1940 void Histo2D::ReadSelf(PInPersist& s)1941 //1942 // Lecture fichier de type ppersist.1943 //--1944 {1945 Delete();1946 1947 int j;1948 float min,max;1949 Histo* h;1950 char strg[256];1951 int_4 errok, projx, projy, nslix, nsliy, nbanx, nbany;1952 1953 // Lecture entete1954 s.GetLine(strg, 255);1955 s.GetLine(strg, 255);1956 s.GetLine(strg, 255);1957 s.GetLine(strg, 255);1958 s.GetLine(strg, 255);1959 s.GetLine(strg, 255);1960 1961 1962 // Lecture variables de definitions1963 s.GetI4(nx);1964 s.GetI4(ny);1965 s.GetI4(nxy);1966 s.GetI4(errok);1967 s.GetI4(nEntries);1968 s.GetR8(nHist);1969 1970 s.GetR4(xmin);1971 s.GetR4(xmax);1972 s.GetR4(ymin);1973 s.GetR4(ymax);1974 s.GetR4(wbinx);1975 s.GetR4(wbiny);1976 1977 s.GetR4s(&over[0][0],9);1978 1979 s.GetI4(projx);1980 s.GetI4(projy);1981 s.GetI4(nslix);1982 s.GetI4(nsliy);1983 s.GetI4(nbanx);1984 s.GetI4(nbany);1985 1986 // Lecture histo2D1987 data = new float[nxy];1988 s.GetLine(strg, 255);1989 for(j=0;j<ny;j++) s.GetR4s(data+j*nx,nx);1990 1991 // Lecture erreurs1992 if(errok) {1993 s.GetLine(strg, 255);1994 err2 = new double[nxy];1995 for(j=0;j<ny;j++) s.GetR8s(err2+j*nx,nx);1996 }1997 1998 // Lecture des projections1999 if(projx) {2000 s.GetLine(strg, 255);2001 SetProjX();2002 hprojx->Read(s);2003 }2004 if(projy) {2005 s.GetLine(strg, 255);2006 SetProjY();2007 hprojy->Read(s);2008 }2009 2010 // Lecture des slices2011 if(nslix>0) {2012 s.GetLine(strg, 255);2013 SetSliX(nslix);2014 DBASSERT (nslix==NSliX());2015 for(j=0;j<NSliX();j++) HSliX(j)->Read(s);2016 }2017 if(nsliy>0) {2018 s.GetLine(strg, 255);2019 SetSliY(nsliy);2020 DBASSERT (nsliy==NSliY());2021 for(j=0;j<NSliY();j++) HSliY(j)->Read(s);2022 }2023 2024 // Lecture des bandes2025 if( nbanx>0 ) {2026 s.GetLine(strg, 255);2027 for( j=0; j<nbanx; j++) {2028 s.GetR4(min);2029 s.GetR4(max);2030 SetBandX(min,max);2031 }2032 DBASSERT (nbanx==NBandX());2033 for( j=0; j<NBandX(); j++) {2034 h = HBandX(j);2035 h->Read(s);2036 }2037 }2038 if( nbany>0 ) {2039 s.GetLine(strg, 255);2040 for( j=0; j<nbany; j++) {2041 s.GetR4(min);2042 s.GetR4(max);2043 SetBandY(min,max);2044 }2045 DBASSERT (nbany==NBandY());2046 for( j=0; j<NBandY(); j++) {2047 h = HBandY(j);2048 h->Read(s);2049 }2050 }2051 2052 return;2053 }
Note:
See TracChangeset
for help on using the changeset viewer.