CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

AssociatedLegendre.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: AssociatedLegendre.cc,v 1.3 2003/09/06 14:04:14 boudreau Exp $
00003 #include "CLHEP/GenericFunctions/AssociatedLegendre.hh"
00004 #include "CLHEP/GenericFunctions/Variable.hh"
00005 #include "CLHEP/GenericFunctions/Power.hh"
00006 #include <assert.h>
00007 
00008 namespace Genfun {
00009 FUNCTION_OBJECT_IMP(AssociatedLegendre)
00010 
00011 // This is the product n (n-2) (n-4)... 
00012 inline double dfactorial (int n) {
00013   if (n<=1) return 1.0;
00014   else return n*dfactorial(n-2);
00015 }
00016 //
00017 AssociatedLegendre::AssociatedLegendre(unsigned int l, unsigned int m):
00018   _l(l),
00019   _m(m)
00020 {
00021   assert(m<=l);
00022   create();
00023 }
00024 
00025 AssociatedLegendre::~AssociatedLegendre() {
00026   delete _function;
00027 }
00028 
00029 AssociatedLegendre::AssociatedLegendre(const AssociatedLegendre & right):
00030 _l(right._l),
00031 _m(right._m)
00032 {
00033   create();
00034 }
00035 
00036 double AssociatedLegendre::operator() (double x) const {
00037   return (*_function)(x);
00038 }
00039 
00040 unsigned int AssociatedLegendre::l() const {
00041   return _l;
00042 }
00043 
00044 unsigned int AssociatedLegendre::m() const {
00045   return _m;
00046 }
00047 
00048 
00049 void AssociatedLegendre::create() {
00050   Variable     x;
00051   if (_l==_m) {
00052     Power powerMOverTwo(_m/2.0),PowerM(_m);
00053     _function = (PowerM(-1)*dfactorial(2*_m-1)*powerMOverTwo((1-x)*(1+x))).clone();
00054   }
00055   else if (_l==_m+1) {
00056     _function = (x*(2*_m+1)*AssociatedLegendre(_m,_m)).clone();
00057   }
00058   else {
00059     _function = ((1.0/(_l-_m)) * (x*(2*_l-1)*AssociatedLegendre(_l-1,_m) -(_l+_m-1)*AssociatedLegendre(_l-2,_m))).clone();
00060   }
00061 }
00062 } // namespace Genfun

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7