Changeset 1092 in Sophya for trunk/SophyaLib/NTools


Ignore:
Timestamp:
Jul 26, 2000, 3:15:52 PM (25 years ago)
Author:
ansari
Message:

Histos/Hprof/Histo2D en r_8 cmv 26/7/00

Location:
trunk/SophyaLib/NTools
Files:
3 edited

Legend:

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

    r490 r1092  
    55// LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
    66
    7 // $Id: cimage.cc,v 1.5 1999-10-21 15:25:42 ansari Exp $       
     7// $Id: cimage.cc,v 1.6 2000-07-26 13:15:29 ansari Exp $       
    88
    99
     
    723723// redimensionnement de l'histo pour avoir une bonne signification stat.
    724724for(;;) {
    725   float max1,max2;
    726   int imax1,imax2;
     725  r_8 max1,max2;
     726  int_4 imax1,imax2;
    727727  rc = H.MaxiLocal(max1,imax1,max2,imax2);
    728728  float rap = 1.;
     
    742742
    743743TRY {
    744   xbmax = H.FitMax(2,0.5f,deb-2);
     744  xbmax = H.FitMax(2,0.5,deb-2);
    745745  if(deb>1) cout<<"H.FitMax = "<<xbmax<<endl;
    746746} CATCHALL {
     
    750750
    751751TRY {
    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;
    756757  if(deb>1) cout<<"H.FindWidth = "<<sgbmax<<" (droit="<<sdroit<<")"<<endl;
    757758} CATCHALL {
  • trunk/SophyaLib/NTools/perandom.cc

    r244 r1092  
    1515
    1616//++
    17 FunRan::FunRan(FunRan::Func f, float xMin, float xMax, int nBin)
     17FunRan::FunRan(FunRan::Func f, r_8 xMin, r_8 xMax, int_4 nBin)
    1818//
    1919//      Createur.
     
    2222{
    2323  (*this)(0) = f(BinLowEdge(0));
    24   for(int i=1; i<nBin; i++)
     24  for(int_4 i=1; i<nBin; i++)
    2525    (*this)(i) = (*this)(i-1) + f(BinLowEdge(i));
    2626   
    27   for(int j=0; j<nBin; j++)
     27  for(int_4 j=0; j<nBin; j++)
    2828    (*this)(j) /= (*this)(nBin-1);
    2929  END_CONSTRUCTOR
     
    3131
    3232//++
    33 FunRan::FunRan(double *tab, int nBin)
    34 //
    35 //      Createur.
    36 //--
    37 : Histo(0, (float)(nBin), nBin)
     33FunRan::FunRan(r_8 *tab, int_4 nBin)
     34//
     35//      Createur.
     36//--
     37: Histo(0, (r_8)(nBin), nBin)
    3838{
    3939  (*this)(0) = tab[0];
    40   for(int i=1; i<nBin; i++)
     40  for(int_4 i=1; i<nBin; i++)
    4141    (*this)(i) = (*this)(i-1) + tab[i];
    4242
     
    4646  }
    4747
    48   for(int j=0; j<nBin; j++)
     48  for(int_4 j=0; j<nBin; j++)
    4949    (*this)(j) /= (*this)(nBin-1);
    5050  END_CONSTRUCTOR
    5151}
    5252
    53 FunRan::FunRan(double *tab, int nBin, float xMin, float xMax)
     53FunRan::FunRan(r_8 *tab, int_4 nBin, r_8 xMin, r_8 xMax)
    5454: Histo(xMin, xMax, nBin)
    5555{
    5656  (*this)(0) = tab[0];
    57   for(int i=1; i<nBin; i++)
     57  for(int_4 i=1; i<nBin; i++)
    5858    (*this)(i) = (*this)(i-1) + tab[i];
    5959
     
    6363  }
    6464
    65   for(int j=0; j<nBin; j++)
     65  for(int_4 j=0; j<nBin; j++)
    6666    (*this)(j) /= (*this)(nBin-1);
    6767  END_CONSTRUCTOR
     
    6969
    7070//++
    71 int FunRan::BinRandom()
     71int_4 FunRan::BinRandom()
    7272//
    7373//      Tirage avec retour du numero de bin.
    7474//--
    7575{
    76   double z=drand01();
     76  r_8 z=drand01();
    7777  if (z <= 0) return 0;
    78   if (z >= 1) return bins-1;
     78  if (z >= 1) return mBins-1;
    7979 
    8080  // 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++)
    8383    if (z < (*this)(iBin)) break;
    8484
     
    8787
    8888//++
    89 double FunRan::Random()
     89r_8 FunRan::Random()
    9090//
    9191//      Tirage avec retour abscisse du bin interpole.
    9292//--
    9393{
    94   double z=drand01();
    95   if (z <= 0) return min;
    96   if (z >= 1) return max;
     94  r_8 z=drand01();
     95  if (z <= 0) return mMin;
     96  if (z >= 1) return mMax;
    9797  // cas z <= tab[0]
    9898  if (z <= (*this)(0)) {
    99     double t = min + binWidth/(*this)(0) * z;
     99    r_8 t = mMin + binWidth/(*this)(0) * z;
    100100    return t;
    101101  }
    102102
    103103  // 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++)
    106106    if (z < (*this)(iBin)) break;
    107107
    108108  // interpolation pour trouver la valeur du tirage aleatoire
    109   double t1 = (*this)(iBin-1);
    110   double x1 = BinLowEdge(iBin-1);
    111   double t2 = (*this)(iBin);
    112   double x2 = x1 + binWidth;
    113   double t = x1 + (x2-x1) / (t2-t1) * (z-t1);
    114   if (t < min) t = min;
    115   if (t > max) 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;
    116116  return(t);
    117117}
     
    129129
    130130//++
    131 FunRan2D::FunRan2D(double *tab, int nBinX, int nBinY)
     131FunRan2D::FunRan2D(r_8 *tab, int_4 nBinX, int_4 nBinY)
    132132//
    133133//      Createur.
     
    135135{
    136136  // 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++) {
    139139     tabX[i] = 0;
    140      for (int j=0; j<nBinY; j++) {
     140     for (int_4 j=0; j<nBinY; j++) {
    141141       tabX[i] += tab[i*nBinY +j];
    142142     }
     
    147147   ranY = new(FunRan*[nBinX]);
    148148   
    149    for (int k=0; k<nBinX; k++)
     149   for (int_4 k=0; k<nBinX; k++)
    150150      ranY[k] = new FunRan(tab + nBinY*k, nBinY);
    151151   
     
    155155
    156156//++
    157 FunRan2D::FunRan2D(double **tab, int nBinX, int nBinY)
     157FunRan2D::FunRan2D(r_8 **tab, int_4 nBinX, int_4 nBinY)
    158158//
    159159//      Createur.
     
    161161{
    162162  // 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++) {
    165165     tabX[i] = 0;
    166      for (int j=0; j<nBinY; j++) {
     166     for (int_4 j=0; j<nBinY; j++) {
    167167       tabX[i] += tab[i][j];
    168168     }
     
    172172   ranY = new(FunRan*[nBinX]);
    173173   
    174    for (int k=0; k<nBinX; k++)
     174   for (int_4 k=0; k<nBinX; k++)
    175175    if (tabX[k] != 0)
    176176      ranY[k] = new FunRan(tab[k], nBinY);
     
    184184FunRan2D::~FunRan2D()
    185185{
    186   for (int i=nx-1; i>=0; i--)
     186  for (int_4 i=nx-1; i>=0; i--)
    187187    delete ranY[i];
    188188   
     
    193193
    194194//++
    195 void FunRan2D::BinRandom(int& x, int& y)
     195void FunRan2D::BinRandom(int_4& x, int_4& y)
    196196//
    197197//      Tirage avec retour du numeros de bin.
     
    204204
    205205//++
    206 void FunRan2D::Random(double& x, double& y)
     206void FunRan2D::Random(r_8& x, r_8& y)
    207207//
    208208//      Tirage avec retour abscisse et ordonnee
     
    211211{
    212212  x = ranX->Random();
    213   int i = int(ceil(x));
     213  int_4 i = int_4(ceil(x));
    214214  //  FAILNIL(ranY[i]);  Ne compile pas $CHECK$ Reza 22/04/99
    215215  y = ranY[i]->Random();
  • trunk/SophyaLib/NTools/perandom.h

    r244 r1092  
    1313class FunRan : public Histo {
    1414public:
    15   typedef double (*Func)(double);
    16   FunRan(Func f, float xMin=0.0, float xMax=1.0, int nBin=100);
    17   FunRan(double *tab, int nBin);
    18   FunRan(double *tab, int nBin, float xMin, float xMax);
    19   void IFunRan(double *tab, int nBin);
    20   double Random(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);
    2222};
    2323
    2424class FunRan2D EXC_AWARE {
    2525public:
    26 //  typedef double (*Func)(double, double);
    27 //  FunRan2D(Func f, float xMin=0.0, float xMax=1.0, int nBinX=100,
    28 //                   float yMin=0.0, float yMax=1.0, int nBinY=100);
    29   FunRan2D(double *tab, int nBinX, int nBinY);
    30   FunRan2D(double **tab, int nBinX, int nBinY);
     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);
    3131  ~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);
    3434private:
    3535  FunRan* ranX;
    3636  FunRan** ranY;
    37   int nx;
     37  int_4 nx;
    3838};
    3939
Note: See TracChangeset for help on using the changeset viewer.