Changeset 1092 in Sophya for trunk/SophyaLib/NTools
- Timestamp:
- Jul 26, 2000, 3:15:52 PM (25 years ago)
- Location:
- trunk/SophyaLib/NTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/cimage.cc
r490 r1092 5 5 // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA 6 6 7 // $Id: cimage.cc,v 1. 5 1999-10-21 15:25:42ansari Exp $7 // $Id: cimage.cc,v 1.6 2000-07-26 13:15:29 ansari Exp $ 8 8 9 9 … … 723 723 // redimensionnement de l'histo pour avoir une bonne signification stat. 724 724 for(;;) { 725 floatmax1,max2;726 int imax1,imax2;725 r_8 max1,max2; 726 int_4 imax1,imax2; 727 727 rc = H.MaxiLocal(max1,imax1,max2,imax2); 728 728 float rap = 1.; … … 742 742 743 743 TRY { 744 xbmax = H.FitMax(2,0.5 f,deb-2);744 xbmax = H.FitMax(2,0.5,deb-2); 745 745 if(deb>1) cout<<"H.FitMax = "<<xbmax<<endl; 746 746 } CATCHALL { … … 750 750 751 751 TRY { 752 float sdroit = -2.; 753 H.EstimeWidthS(0.5f,sgbmax,sdroit); 754 if(sgbmax<=0.) sgbmax = H.FindWidth(0.5f,deb-2); 755 sgbmax /= 2.36; 752 r_8 sdroit = -2., dum=sgbmax; 753 H.EstimeWidthS(0.5,dum,sdroit); 754 if(dum<=0.) dum = H.FindWidth(0.5,deb-2); 755 dum /= 2.36; 756 sgbmax = dum; 756 757 if(deb>1) cout<<"H.FindWidth = "<<sgbmax<<" (droit="<<sdroit<<")"<<endl; 757 758 } CATCHALL { -
trunk/SophyaLib/NTools/perandom.cc
r244 r1092 15 15 16 16 //++ 17 FunRan::FunRan(FunRan::Func f, float xMin, float xMax, intnBin)17 FunRan::FunRan(FunRan::Func f, r_8 xMin, r_8 xMax, int_4 nBin) 18 18 // 19 19 // Createur. … … 22 22 { 23 23 (*this)(0) = f(BinLowEdge(0)); 24 for(int i=1; i<nBin; i++)24 for(int_4 i=1; i<nBin; i++) 25 25 (*this)(i) = (*this)(i-1) + f(BinLowEdge(i)); 26 26 27 for(int j=0; j<nBin; j++)27 for(int_4 j=0; j<nBin; j++) 28 28 (*this)(j) /= (*this)(nBin-1); 29 29 END_CONSTRUCTOR … … 31 31 32 32 //++ 33 FunRan::FunRan( double *tab, intnBin)34 // 35 // Createur. 36 //-- 37 : Histo(0, ( float)(nBin), nBin)33 FunRan::FunRan(r_8 *tab, int_4 nBin) 34 // 35 // Createur. 36 //-- 37 : Histo(0, (r_8)(nBin), nBin) 38 38 { 39 39 (*this)(0) = tab[0]; 40 for(int i=1; i<nBin; i++)40 for(int_4 i=1; i<nBin; i++) 41 41 (*this)(i) = (*this)(i-1) + tab[i]; 42 42 … … 46 46 } 47 47 48 for(int j=0; j<nBin; j++)48 for(int_4 j=0; j<nBin; j++) 49 49 (*this)(j) /= (*this)(nBin-1); 50 50 END_CONSTRUCTOR 51 51 } 52 52 53 FunRan::FunRan( double *tab, int nBin, float xMin, floatxMax)53 FunRan::FunRan(r_8 *tab, int_4 nBin, r_8 xMin, r_8 xMax) 54 54 : Histo(xMin, xMax, nBin) 55 55 { 56 56 (*this)(0) = tab[0]; 57 for(int i=1; i<nBin; i++)57 for(int_4 i=1; i<nBin; i++) 58 58 (*this)(i) = (*this)(i-1) + tab[i]; 59 59 … … 63 63 } 64 64 65 for(int j=0; j<nBin; j++)65 for(int_4 j=0; j<nBin; j++) 66 66 (*this)(j) /= (*this)(nBin-1); 67 67 END_CONSTRUCTOR … … 69 69 70 70 //++ 71 int FunRan::BinRandom()71 int_4 FunRan::BinRandom() 72 72 // 73 73 // Tirage avec retour du numero de bin. 74 74 //-- 75 75 { 76 doublez=drand01();76 r_8 z=drand01(); 77 77 if (z <= 0) return 0; 78 if (z >= 1) return bins-1;78 if (z >= 1) return mBins-1; 79 79 80 80 // recherche du premier bin plus grand que z 81 int iBin = 0;82 for (; iBin< bins; iBin++)81 int_4 iBin = 0; 82 for (; iBin<mBins; iBin++) 83 83 if (z < (*this)(iBin)) break; 84 84 … … 87 87 88 88 //++ 89 doubleFunRan::Random()89 r_8 FunRan::Random() 90 90 // 91 91 // Tirage avec retour abscisse du bin interpole. 92 92 //-- 93 93 { 94 doublez=drand01();95 if (z <= 0) return m in;96 if (z >= 1) return m ax;94 r_8 z=drand01(); 95 if (z <= 0) return mMin; 96 if (z >= 1) return mMax; 97 97 // cas z <= tab[0] 98 98 if (z <= (*this)(0)) { 99 double t = min + binWidth/(*this)(0) * z;99 r_8 t = mMin + binWidth/(*this)(0) * z; 100 100 return t; 101 101 } 102 102 103 103 // recherche du premier bin plus grand que z 104 int iBin = 0;105 for (; iBin< bins; iBin++)104 int_4 iBin = 0; 105 for (; iBin<mBins; iBin++) 106 106 if (z < (*this)(iBin)) break; 107 107 108 108 // interpolation pour trouver la valeur du tirage aleatoire 109 doublet1 = (*this)(iBin-1);110 doublex1 = BinLowEdge(iBin-1);111 doublet2 = (*this)(iBin);112 doublex2 = x1 + binWidth;113 doublet = x1 + (x2-x1) / (t2-t1) * (z-t1);114 if (t < m in) t = min;115 if (t > m ax) t = max;109 r_8 t1 = (*this)(iBin-1); 110 r_8 x1 = BinLowEdge(iBin-1); 111 r_8 t2 = (*this)(iBin); 112 r_8 x2 = x1 + binWidth; 113 r_8 t = x1 + (x2-x1) / (t2-t1) * (z-t1); 114 if (t < mMin) t = mMin; 115 if (t > mMax) t = mMax; 116 116 return(t); 117 117 } … … 129 129 130 130 //++ 131 FunRan2D::FunRan2D( double *tab, int nBinX, intnBinY)131 FunRan2D::FunRan2D(r_8 *tab, int_4 nBinX, int_4 nBinY) 132 132 // 133 133 // Createur. … … 135 135 { 136 136 // Tirage en X, somme sur les Y. 137 double* tabX = new double[nBinX];138 for (int i=0; i<nBinX; i++) {137 r_8* tabX = new r_8[nBinX]; 138 for (int_4 i=0; i<nBinX; i++) { 139 139 tabX[i] = 0; 140 for (int j=0; j<nBinY; j++) {140 for (int_4 j=0; j<nBinY; j++) { 141 141 tabX[i] += tab[i*nBinY +j]; 142 142 } … … 147 147 ranY = new(FunRan*[nBinX]); 148 148 149 for (int k=0; k<nBinX; k++)149 for (int_4 k=0; k<nBinX; k++) 150 150 ranY[k] = new FunRan(tab + nBinY*k, nBinY); 151 151 … … 155 155 156 156 //++ 157 FunRan2D::FunRan2D( double **tab, int nBinX, intnBinY)157 FunRan2D::FunRan2D(r_8 **tab, int_4 nBinX, int_4 nBinY) 158 158 // 159 159 // Createur. … … 161 161 { 162 162 // Tirage en X, somme sur les Y. 163 double* tabX = new double[nBinX];164 for (int i=0; i<nBinX; i++) {163 r_8* tabX = new r_8[nBinX]; 164 for (int_4 i=0; i<nBinX; i++) { 165 165 tabX[i] = 0; 166 for (int j=0; j<nBinY; j++) {166 for (int_4 j=0; j<nBinY; j++) { 167 167 tabX[i] += tab[i][j]; 168 168 } … … 172 172 ranY = new(FunRan*[nBinX]); 173 173 174 for (int k=0; k<nBinX; k++)174 for (int_4 k=0; k<nBinX; k++) 175 175 if (tabX[k] != 0) 176 176 ranY[k] = new FunRan(tab[k], nBinY); … … 184 184 FunRan2D::~FunRan2D() 185 185 { 186 for (int i=nx-1; i>=0; i--)186 for (int_4 i=nx-1; i>=0; i--) 187 187 delete ranY[i]; 188 188 … … 193 193 194 194 //++ 195 void FunRan2D::BinRandom(int & x, int& y)195 void FunRan2D::BinRandom(int_4& x, int_4& y) 196 196 // 197 197 // Tirage avec retour du numeros de bin. … … 204 204 205 205 //++ 206 void FunRan2D::Random( double& x, double& y)206 void FunRan2D::Random(r_8& x, r_8& y) 207 207 // 208 208 // Tirage avec retour abscisse et ordonnee … … 211 211 { 212 212 x = ranX->Random(); 213 int i = int(ceil(x));213 int_4 i = int_4(ceil(x)); 214 214 // FAILNIL(ranY[i]); Ne compile pas $CHECK$ Reza 22/04/99 215 215 y = ranY[i]->Random(); -
trunk/SophyaLib/NTools/perandom.h
r244 r1092 13 13 class FunRan : public Histo { 14 14 public: 15 typedef double (*Func)(double);16 FunRan(Func f, float xMin=0.0, float xMax=1.0, intnBin=100);17 FunRan( double *tab, intnBin);18 FunRan( double *tab, int nBin, float xMin, floatxMax);19 void IFunRan( double *tab, intnBin);20 doubleRandom(void);21 int BinRandom(void);15 typedef r_8 (*Func)(r_8); 16 FunRan(Func f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBin=100); 17 FunRan(r_8 *tab, int_4 nBin); 18 FunRan(r_8 *tab, int_4 nBin, r_8 xMin, r_8 xMax); 19 void IFunRan(r_8 *tab, int_4 nBin); 20 r_8 Random(void); 21 int_4 BinRandom(void); 22 22 }; 23 23 24 24 class FunRan2D EXC_AWARE { 25 25 public: 26 // typedef double (*Func)(double, double);27 // FunRan2D(Func f, float xMin=0.0, float xMax=1.0, intnBinX=100,28 // float yMin=0.0, float yMax=1.0, intnBinY=100);29 FunRan2D( double *tab, int nBinX, intnBinY);30 FunRan2D( double **tab, int nBinX, intnBinY);26 // typedef r_8 (*Func)(r_8, r_8); 27 // FunRan2D(Func f, r_8 xMin=0.0, r_8 xMax=1.0, int_4 nBinX=100, 28 // r_8 yMin=0.0, r_8 yMax=1.0, int_4 nBinY=100); 29 FunRan2D(r_8 *tab, int_4 nBinX, int_4 nBinY); 30 FunRan2D(r_8 **tab, int_4 nBinX, int_4 nBinY); 31 31 ~FunRan2D(); 32 void Random( double& x, double& y);33 void BinRandom(int & x, int& y);32 void Random(r_8& x, r_8& y); 33 void BinRandom(int_4& x, int_4& y); 34 34 private: 35 35 FunRan* ranX; 36 36 FunRan** ranY; 37 int nx;37 int_4 nx; 38 38 }; 39 39
Note:
See TracChangeset
for help on using the changeset viewer.