ROOT logo
// @(#)root/unuran:$Id: TUnuranDiscrDist.cxx 20882 2007-11-19 11:31:26Z rdm $
// Authors: L. Moneta, J. Leydold Wed Feb 28 2007 

/**********************************************************************
 *                                                                    *
 * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
 *                                                                    *
 *                                                                    *
 **********************************************************************/

// Implementation file for class TUnuranDiscrDist

#include "TUnuranDiscrDist.h"

#include "TF1.h"

#include <cassert>


TUnuranDiscrDist::TUnuranDiscrDist (TF1 * func) : 
   fPmf(func), 
   fCdf(0), 
   fXmin(1), 
   fXmax(-1), 
   fMode(0), 
   fSum(0),
   fHasDomain(0),
   fHasMode(0),
   fHasSum(0)
{
   //Constructor from a TF1 objects
} 


TUnuranDiscrDist::TUnuranDiscrDist(const TUnuranDiscrDist & rhs) :
   TUnuranBaseDist()
{
   // Implementation of copy ctor using aassignment operator
   operator=(rhs);
}

TUnuranDiscrDist & TUnuranDiscrDist::operator = (const TUnuranDiscrDist &rhs) 
{
   // Implementation of assignment operator (copy only the funciton pointer not the function itself)
   if (this == &rhs) return *this;  // time saving self-test
   fPVec = rhs.fPVec;
   fPmf  = rhs.fPmf;
   fCdf  = rhs.fCdf;
   fXmin = rhs.fXmin;
   fXmax = rhs.fXmax;
   fMode = rhs.fMode;
   fSum  = rhs.fSum;
   fHasDomain = rhs.fHasDomain;
   fHasMode   = rhs.fHasMode;
   fHasSum    = rhs.fHasSum;
   return *this;
}



double TUnuranDiscrDist::Pmf ( int x) const {  
   // evaluate the distribution 
   if (!fPmf) { 
      if (x < static_cast<int>(fPVec.size()) || x >= static_cast<int>(fPVec.size()) ) return 0; 
      return fPVec[x]; 
   }
   fX[0] = x; 
   fPmf->InitArgs(fX,(double*)0);
   return fPmf->EvalPar(fX); 
}

double TUnuranDiscrDist::Cdf ( int x) const {  
   // evaluate the cumulative distribution 
   // otherwise evaluate from the sum of the probabilities 
   assert(fCdf != 0); 
   fX[0] = x; 
   fCdf->InitArgs(fX,(double*)0);
   return fCdf->EvalPar(fX);
//naive numerical estimation is too slow  
//    double cdf = 0; 
//    int i0 = ( fHasDomain) ? fXmin : 0; 
//    for (int i = i0; i <= x; ++i) 
//       cdf += Pmf(i); 
//    return cdf; 
}





 TUnuranDiscrDist.cxx:1
 TUnuranDiscrDist.cxx:2
 TUnuranDiscrDist.cxx:3
 TUnuranDiscrDist.cxx:4
 TUnuranDiscrDist.cxx:5
 TUnuranDiscrDist.cxx:6
 TUnuranDiscrDist.cxx:7
 TUnuranDiscrDist.cxx:8
 TUnuranDiscrDist.cxx:9
 TUnuranDiscrDist.cxx:10
 TUnuranDiscrDist.cxx:11
 TUnuranDiscrDist.cxx:12
 TUnuranDiscrDist.cxx:13
 TUnuranDiscrDist.cxx:14
 TUnuranDiscrDist.cxx:15
 TUnuranDiscrDist.cxx:16
 TUnuranDiscrDist.cxx:17
 TUnuranDiscrDist.cxx:18
 TUnuranDiscrDist.cxx:19
 TUnuranDiscrDist.cxx:20
 TUnuranDiscrDist.cxx:21
 TUnuranDiscrDist.cxx:22
 TUnuranDiscrDist.cxx:23
 TUnuranDiscrDist.cxx:24
 TUnuranDiscrDist.cxx:25
 TUnuranDiscrDist.cxx:26
 TUnuranDiscrDist.cxx:27
 TUnuranDiscrDist.cxx:28
 TUnuranDiscrDist.cxx:29
 TUnuranDiscrDist.cxx:30
 TUnuranDiscrDist.cxx:31
 TUnuranDiscrDist.cxx:32
 TUnuranDiscrDist.cxx:33
 TUnuranDiscrDist.cxx:34
 TUnuranDiscrDist.cxx:35
 TUnuranDiscrDist.cxx:36
 TUnuranDiscrDist.cxx:37
 TUnuranDiscrDist.cxx:38
 TUnuranDiscrDist.cxx:39
 TUnuranDiscrDist.cxx:40
 TUnuranDiscrDist.cxx:41
 TUnuranDiscrDist.cxx:42
 TUnuranDiscrDist.cxx:43
 TUnuranDiscrDist.cxx:44
 TUnuranDiscrDist.cxx:45
 TUnuranDiscrDist.cxx:46
 TUnuranDiscrDist.cxx:47
 TUnuranDiscrDist.cxx:48
 TUnuranDiscrDist.cxx:49
 TUnuranDiscrDist.cxx:50
 TUnuranDiscrDist.cxx:51
 TUnuranDiscrDist.cxx:52
 TUnuranDiscrDist.cxx:53
 TUnuranDiscrDist.cxx:54
 TUnuranDiscrDist.cxx:55
 TUnuranDiscrDist.cxx:56
 TUnuranDiscrDist.cxx:57
 TUnuranDiscrDist.cxx:58
 TUnuranDiscrDist.cxx:59
 TUnuranDiscrDist.cxx:60
 TUnuranDiscrDist.cxx:61
 TUnuranDiscrDist.cxx:62
 TUnuranDiscrDist.cxx:63
 TUnuranDiscrDist.cxx:64
 TUnuranDiscrDist.cxx:65
 TUnuranDiscrDist.cxx:66
 TUnuranDiscrDist.cxx:67
 TUnuranDiscrDist.cxx:68
 TUnuranDiscrDist.cxx:69
 TUnuranDiscrDist.cxx:70
 TUnuranDiscrDist.cxx:71
 TUnuranDiscrDist.cxx:72
 TUnuranDiscrDist.cxx:73
 TUnuranDiscrDist.cxx:74
 TUnuranDiscrDist.cxx:75
 TUnuranDiscrDist.cxx:76
 TUnuranDiscrDist.cxx:77
 TUnuranDiscrDist.cxx:78
 TUnuranDiscrDist.cxx:79
 TUnuranDiscrDist.cxx:80
 TUnuranDiscrDist.cxx:81
 TUnuranDiscrDist.cxx:82
 TUnuranDiscrDist.cxx:83
 TUnuranDiscrDist.cxx:84
 TUnuranDiscrDist.cxx:85
 TUnuranDiscrDist.cxx:86
 TUnuranDiscrDist.cxx:87
 TUnuranDiscrDist.cxx:88
 TUnuranDiscrDist.cxx:89
 TUnuranDiscrDist.cxx:90