CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

ClebschGordanCoefficientSet.hh

Go to the documentation of this file.
00001 #ifndef _ClebschGordanCoefficientSet_h_
00002 #define _ClebschGordanCoefficientSet_h_
00003 #include <map>
00004 #include <algorithm>
00005 #include <cmath>
00006 namespace Genfun {
00007 
00008   class ClebschGordanCoefficientSet {
00009 
00010   public:
00011 
00012     double operator () (unsigned int l1, unsigned int l2, int m1, int m2, int L, int M) const; 
00013     
00014   private:
00015 
00016     // Key used to optimize access (look up previously calcuated results).
00017     class Key {
00018 
00019     public:
00020       
00021       inline Key(unsigned int xl1, unsigned int xl2, int xm1, int xm2, unsigned int xL):
00022         l1(xl1),l2(xl2),m1(xm1),m2(xm2),L(xL) {}
00023       
00024       inline bool operator < (const Key & o) const {
00025         if ( l1!=o.l1) return l1<o.l1;
00026         if ( l2!=o.l2) return l2<o.l2;
00027         if ( m1!=o.m1) return m1<o.m1;
00028         if ( m2!=o.m2) return m2<o.m2;
00029         if ( L!=o.L  ) return L<o.L;
00030         return false;
00031       }
00032       
00033       
00034       inline bool operator== (const Key & o) const {
00035         return l1==o.l1 && l2 == o.l2 && m1==o.m1 && m2==o.m2 && L == o.L;
00036       }
00037 
00038     private:
00039       
00040       unsigned int l1;
00041       unsigned     l2;
00042       int          m1;
00043       int          m2;
00044       unsigned int L;
00045       // M=m1+m2;
00046       
00047     };
00048     
00049 
00050     mutable std::map<Key, double> coeff;
00051 
00052     static double calcCoefficient(int l1, int l2, int L, int m1, int m2, int M);
00053 
00054   };
00055 
00056 
00057 
00058 
00059   inline double ClebschGordanCoefficientSet::operator () (unsigned int l1, unsigned int l2, int m1, int m2, int L, int M) const {
00060     if ((m1+m2)!=M) return 0;
00061     
00062     Key key(l1,l2,m1,m2,L);
00063     std::map<Key,double>::iterator i=coeff.find(key),end=coeff.end();
00064     if (i==end) {
00065       double c = calcCoefficient(l1, l2, L, m1, m2,M);
00066       coeff[key]=c;
00067       return c;
00068     }
00069 
00070     return (*i).second;
00071    
00072   }
00073 }
00074 
00075 #endif

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7