Changeset 1092 in Sophya for trunk/SophyaLib/NTools/perandom.cc


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.