CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 #include "CLHEP/GenericFunctions/ClebschGordanCoefficientSet.hh" 00002 #include <iostream> 00003 #include <cmath> 00004 #include <stdexcept> 00005 inline double factorial (int N) { 00006 double retVal(1.0); 00007 for (int i=2;i<=N;i++) retVal*=i; 00008 return retVal; 00009 } 00010 00011 00012 namespace Genfun { 00013 double ClebschGordanCoefficientSet::calcCoefficient(int l1, int l2, int L, int xm1, int xm2, int M) { 00014 00015 if (xm1+xm2!=M) return 0; 00016 double F1=sqrt((2*L+1)*factorial(L+l1-l2)*factorial(L-l1+l2)*factorial(l1+l2-L)/factorial(l1+l2+L+1)); 00017 double F2=sqrt(factorial(L+M)*factorial(L-M)*factorial(l1-xm1)*factorial(l1+xm1)*factorial(l2-xm2) 00018 *factorial(l2+xm2)); 00019 double F3=0.0; 00020 int max=0; 00021 max = std::max(max,l2+xm2); 00022 max = std::max(max,l1-xm1); 00023 max = std::max(max,l1+l2-L); 00024 // max = std::max(max,l2-L-xm1); 00025 // max = std::max(max,l1+xm2-L); 00026 for (int k=0;k<=max;k++) { 00027 double term = factorial(k); 00028 bool skipTerm=false; 00029 { 00030 int T=l1 + l2 -L -k; 00031 if (T>=0) term *= factorial(T); else skipTerm=true; 00032 } 00033 if (!skipTerm) 00034 { 00035 int T=l1-xm1-k; 00036 if (T>=0) term *= factorial(T); else skipTerm=true; 00037 } 00038 if (!skipTerm) 00039 { 00040 int T=l2+xm2-k; 00041 if (T>=0) term *= factorial(T); else skipTerm=true; 00042 } 00043 if (!skipTerm) 00044 { 00045 int T=L-l2+xm1+k; 00046 if (T>=0) term *= factorial(T); else skipTerm=true; 00047 } 00048 if (!skipTerm) 00049 { 00050 int T=L-l1-xm2+k; 00051 if (T>=0) term *= factorial(T); else skipTerm=true; 00052 } 00053 if (!skipTerm) F3+= ((k%2) ? -1:1)/term; 00054 } 00055 00056 00057 return F1*F2*F3; 00058 } 00059 }