CLHEP  2.4.7.2
C++ Class Library for High Energy Physics
SphericalHarmonicCoefficientSet.icc
Go to the documentation of this file.
1 #include <vector>
2 #include "CLHEP/GenericFunctions/ClebschGordanCoefficientSet.hh"
3 #include <stdexcept>
4 namespace Genfun {
5 
7 
8  public:
9 
10  std::vector<std::vector<std::complex<double> > > data;
11 
12  };
13 
14  inline
15  SphericalHarmonicCoefficientSet::SphericalHarmonicCoefficientSet(unsigned int LMAX):c(new Clockwork()){
16  for (unsigned int l=0;l<=LMAX;l++) {
17  std::vector<std::complex<double> > theMs;
18  for (int m=-l; m<=int(l);m++) {
19  theMs.push_back(std::complex<double> (0.0));
20  }
21  c->data.push_back(theMs);
22  }
23  }
24 
25  inline
26  SphericalHarmonicCoefficientSet::~SphericalHarmonicCoefficientSet(){
27  delete c;
28  }
29 
30  inline
31  SphericalHarmonicCoefficientSet::SphericalHarmonicCoefficientSet(const SphericalHarmonicCoefficientSet & right):
32  c(new Clockwork(*right.c))
33  {
34  }
35 
36  inline
37  unsigned int SphericalHarmonicCoefficientSet::getLMax() const {
38  return c->data.size()-1;
39  }
40 
41  inline
42  const std::complex<double> &SphericalHarmonicCoefficientSet:: operator () (unsigned int l, int m) const {
43  return c->data[l][m+l];
44  }
45 
46  inline
47  std::complex<double> & SphericalHarmonicCoefficientSet::operator () (unsigned int l, int m) {
48  return c->data[l][m+l];
49  }
50 
51  inline
52  std::ostream & operator << ( std::ostream & o, const SphericalHarmonicCoefficientSet & c)
53  {
54  for (unsigned int l=0;l<=c.getLMax();l++) {
55  for (int m=-l;m<=int(l);m++) {
56  o << "l=" << l << " m=" ;
57  if (m==0) o << " ";
58  if (m>0 ) o << "+";
59  o << m << " mag: " << c(l,m) << std::endl;
60  }
61  o << std::endl;
62  }
63  return o;
64  }
65 
66  inline
67  SphericalHarmonicCoefficientSet & SphericalHarmonicCoefficientSet::operator= (const SphericalHarmonicCoefficientSet & source ){
68  if (this!=&source) {
69  delete c;
70  c = new Clockwork(*source.c);
71  }
72  return *this;
73  }
74 
75 
76 
77 
78  inline
79  SphericalHarmonicCoefficientSet & SphericalHarmonicCoefficientSet::operator*= (const std::complex<double> & s ){
80  unsigned int LMAX=getLMax();
81  for (unsigned int l=0;l<=LMAX;l++) {
82  for (int m=-l;m<=int(l);m++) {
83  operator()(l,m)*=s;
84  }
85  }
86  return *this;
87  }
88 
89 
90  inline
91  SphericalHarmonicCoefficientSet & SphericalHarmonicCoefficientSet::operator+= (const SphericalHarmonicCoefficientSet & source ){
92  unsigned int LMAX=getLMax();
93  for (unsigned int l=0;l<=LMAX;l++) {
94  for (int m=-l;m<=int(l);m++) {
95  operator()(l,m)+=source(l,m);
96  }
97  }
98  return *this;
99  }
100 
101 
102  inline
103  SphericalHarmonicCoefficientSet & SphericalHarmonicCoefficientSet::operator-= (const SphericalHarmonicCoefficientSet & source ){
104  unsigned int LMAX=getLMax();
105  for (unsigned int l=0;l<=LMAX;l++) {
106  for (int m=-l;m<=int(l);m++) {
107  operator()(l,m)-=source(l,m);
108  }
109  }
110  return *this;
111  }
112 
113 
114 
115  inline
116  std::complex<double> dot(const SphericalHarmonicCoefficientSet &a,
117  const SphericalHarmonicCoefficientSet &b) {
118 
119  std::complex<double> result=0.0;
120  if (a.getLMax()!=b.getLMax()) throw std::runtime_error ("function dot: SphericalHarmonicCoefficientSets of different dimension");
121 
122  for (unsigned int l=0;l<=a.getLMax();l++) {
123  for (int m=-l;m<=int(l);m++) {
124  result += a(l,m)*conj(b(l,m));
125  }
126  }
127  return result;
128  }
129 
130  inline SphericalHarmonicCoefficientSet squareExpansionCoefficients(const SphericalHarmonicCoefficientSet & coefficientsA) {
131  unsigned int LMAX=coefficientsA.getLMax();
132  SphericalHarmonicCoefficientSet coefficientsASq(2*LMAX);
133  static ClebschGordanCoefficientSet clebschGordan;
134  for (unsigned int L=0;L<=2*LMAX;L++) {
135  for (int M=-L; M<=int(L); M++) {
136  coefficientsASq(L,M)=0.0;
137  for (unsigned int l1=0;l1<=LMAX;l1++) {
138  for (unsigned int l2=0;l2<=LMAX;l2++) {
139  for (int m1=-l1;m1<=int(l1);m1++) {
140  for (int m2=-l2;m2<=int(l2);m2++) {
141  if (m1-m2==M) {
142  if (((l1+l2) >= L) && abs(l1-l2) <= int(L)) {
143  coefficientsASq(L,M) += (coefficientsA(l1,m1)*
144  conj(coefficientsA(l2,m2))*
145  (m2%2 ? -1.0:1.0) *
146  sqrt((2*l1+1)*(2*l2+1)/(4*M_PI*(2*L+1)))*
147  clebschGordan(l1,l2,0,0,L,0)*clebschGordan(l1,l2,m1,-m2,L,M));
148  }
149  }
150  }
151  }
152  }
153  }
154  }
155  }
156  return coefficientsASq;
157  }
158 
159 }
std::vector< std::vector< std::complex< double > > > data
SphericalHarmonicCoefficientSet squareExpansionCoefficients(const SphericalHarmonicCoefficientSet &coefficientsA)
std::complex< double > dot(const SphericalHarmonicCoefficientSet &a, const SphericalHarmonicCoefficientSet &b)
std::ostream & operator<<(std::ostream &o, const LegendreCoefficientSet &c)
Definition: Airy.icc:9