ThePEG  1.8.0
PhysicalQtyComplex.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // PhysicalQtyComplex.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 2006-2011 David Grellscheid, Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef Physical_Qty_Complex_H
10 #define Physical_Qty_Complex_H
11 #include <complex>
12 
17 namespace std {
22  template<int DL, int DE, int DQ>
23  class complex<ThePEG::Qty<0,0,0,DL,DE,DQ> >
24  {
25  public:
27  complex(double r=0.0, double i=0.0)
28  : rawValue_(r,i) {}
29 
31  complex(complex<double> C)
32  : rawValue_(C) {}
33 
38  complex<double> rawValue() const { return rawValue_; }
39 
41  double real() const { return rawValue_.real(); }
42 
44  double imag() const { return rawValue_.imag(); }
45 
47  operator complex<double>() const {
48  return rawValue_;
49  }
50 
52  complex<ThePEG::Qty<0,0,0,DL,DE,DQ> > &
54  rawValue_ += x.rawValue();
55  return *this;
56  }
57 
59  complex<ThePEG::Qty<0,0,0,DL,DE,DQ> > &
61  rawValue_ -= x.rawValue();
62  return *this;
63  }
64 
65  private:
67  complex<double> rawValue_;
68  };
69 }
70 // =========================================
71 
72 namespace ThePEG {
73 
75 
76 // complex qty = complex qty * complex qty
77 template<int L1, int L2, int E1, int E2, int Q1, int Q2,
78  int DL1, int DL2, int DE1, int DE2, int DQ1, int DQ2>
79 inline std::complex<Qty<L1*DL2+L2*DL1,E1*DE2+E2*DE1,Q1*DQ2+Q2*DQ1,
80  DL1*DL2,DE1*DE2,DQ1*DQ2> >
81 operator*(std::complex<Qty<L1,E1,Q1,DL1,DE1,DQ1> > q1,
82  std::complex<Qty<L2,E2,Q2,DL2,DE2,DQ2> > q2) {
83  typedef std::complex<Qty<L1*DL2+L2*DL1,E1*DE2+E2*DE1,Q1*DQ2+Q2*DQ1,
84  DL1*DL2,DE1*DE2,DQ1*DQ2> > RetT;
85  return RetT(q1.real()*q2.real() - q1.imag()*q2.imag(),
86  q1.real()*q2.imag() + q1.imag()*q2.real());
87 }
88 
89 // complex qty = complex qty * complex qty
90 template<int L, int E, int Q, int DL, int DE, int DQ>
91 inline std::complex<Qty<2*L,2*E,2*Q,DL,DE,DQ> >
92 operator*(std::complex<Qty<L,E,Q,DL,DE,DQ> > q1,
93  std::complex<Qty<L,E,Q,DL,DE,DQ> > q2) {
94  typedef std::complex<Qty<2*L,2*E,2*Q,DL,DE,DQ> > RetT;
95  return RetT(q1.real()*q2.real() - q1.imag()*q2.imag(),
96  q1.real()*q2.imag() + q1.imag()*q2.real());
97 }
98 
99 // complex qty = complex double - complex qty
100 template<int DL, int DE, int DQ>
101 inline std::complex<double>
102 operator-(std::complex<double> q1,
103  std::complex<Qty<0,0,0,DL,DE,DQ> > q2) {
104  typedef std::complex<double> RetT;
105  return RetT(q1.real()-q2.real(),q1.imag()-q2.imag());
106 }
107 
108 // complex qty = complex double * complex qty
109 template<int L, int E, int Q, int DL, int DE, int DQ>
110 inline std::complex<Qty<L,E,Q,DL,DE,DQ> >
111 operator*(std::complex<double> q1,
112  std::complex<Qty<L,E,Q,DL,DE,DQ> > q2) {
113  typedef std::complex<Qty<L,E,Q,DL,DE,DQ> > RetT;
114  return RetT(q1.real()*q2.real() - q1.imag()*q2.imag(),
115  q1.real()*q2.imag() + q1.imag()*q2.real());
116 }
117 
118 // complex qty = complex double / complex qty
119 template<int L, int E, int Q, int DL, int DE, int DQ>
120 inline std::complex<Qty<-L,-E,-Q,DL,DE,DQ> >
121 operator/(std::complex<double> q1,
122  std::complex<Qty<L,E,Q,DL,DE,DQ> > q2) {
123  typedef std::complex<Qty<-L,-E,-Q,DL,DE,DQ> > RetT;
124  std::complex<Qty<L,E,Q,DL,DE,DQ> > tmp = q1*conj(q2);
125  Qty<2*L,2*E,2*Q,DL,DE,DQ> norm = (q2*conj(q2)).real();
126  return RetT(tmp.real()/norm,tmp.imag()/norm);
127 }
128 
129 // complex qty = complex double / qty
130 template<int L, int E, int Q, int DL, int DE, int DQ>
131 inline std::complex<Qty<-L,-E,-Q,DL,DE,DQ> >
132 operator/(std::complex<double> q1,
133  Qty<L,E,Q,DL,DE,DQ> q2) {
134  typedef std::complex<Qty<-L,-E,-Q,DL,DE,DQ> > RetT;
135  return RetT(q1.real()/q2,q1.imag()/q2);
136 }
137 
138 // complex qty = complex qty / complex double
139 template<int L, int E, int Q, int DL, int DE, int DQ>
140 inline std::complex<Qty<L,E,Q,DL,DE,DQ> >
141 operator/(std::complex<Qty<L,E,Q,DL,DE,DQ> > q1,
142  std::complex<double> q2) {
143  std::complex<Qty<L,E,Q,DL,DE,DQ> > tmp = q1*conj(q2);
144  double norm = (q2*conj(q2)).real();
145  return std::complex<Qty<L,E,Q,DL,DE,DQ> >(tmp.real()/norm,tmp.imag()/norm);
146 }
147 
148 // complex qty = qty / complex double
149 template<int L, int E, int Q, int DL, int DE, int DQ>
150 inline std::complex<Qty<L,E,Q,DL,DE,DQ> >
151 operator/(Qty<L,E,Q,DL,DE,DQ> q1,
152  std::complex<double> q2) {
153  std::complex<Qty<L,E,Q,DL,DE,DQ> > tmp = q1*conj(q2);
154  double norm = (q2*conj(q2)).real();
155  return std::complex<Qty<L,E,Q,DL,DE,DQ> >(tmp.real()/norm,tmp.imag()/norm);
156 }
157 
158 // complex double = complex qty / complex qty
159 template<int L, int E, int Q, int DL, int DE, int DQ>
160 inline std::complex<double>
161 operator/(std::complex<Qty<L,E,Q,DL,DE,DQ> > q1,
162  std::complex<Qty<L,E,Q,DL,DE,DQ> > q2) {
163  std::complex<Qty<2*L,2*E,2*Q,DL,DE,DQ> > tmp = q1*conj(q2);
164  Qty<2*L,2*E,2*Q,DL,DE,DQ> norm = (q2*conj(q2)).real();
165  return std::complex<double>(tmp.real()/norm,tmp.imag()/norm);
166 }
167 
168 // complex double = qty / complex qty
169 template<int L, int E, int Q, int DL, int DE, int DQ>
170 inline std::complex<double>
171 operator/(Qty<L,E,Q,DL,DE,DQ> q1,
172  std::complex<Qty<L,E,Q,DL,DE,DQ> > q2) {
173  std::complex<Qty<2*L,2*E,2*Q,DL,DE,DQ> > tmp = q1*conj(q2);
174  Qty<2*L,2*E,2*Q,DL,DE,DQ> norm = (q2*conj(q2)).real();
175  return std::complex<double>(tmp.real()/norm,tmp.imag()/norm);
176 }
177 
178 // complex double = complex qty / qty
179 template<int L, int E, int Q, int DL, int DE, int DQ>
180 inline std::complex<double>
181 operator/(std::complex<Qty<L,E,Q,DL,DE,DQ> > q1,
182  Qty<L,E,Q,DL,DE,DQ> q2) {
183  return std::complex<double>(q1.real()/q2,q1.imag()/q2);
184 }
185 
186 // complex qty = complex qty / complex qty
187 template<int L1, int L2, int E1, int E2, int Q1, int Q2,
188  int DL1, int DL2, int DE1, int DE2, int DQ1, int DQ2>
189 inline std::complex<Qty<L1*DL2-L2*DL1,E1*DE2-E2*DE1,Q1*DQ2-Q2*DQ1,DL1*DL2,DE1*DE2,DQ1*DQ2> >
190 operator/(std::complex<Qty<L1,E1,Q1,DL1,DE1,DQ1> > q1,
191  std::complex<Qty<L2,E2,Q2,DL2,DE2,DQ2> > q2) {
192  typedef std::complex<Qty<L1*DL2-L2*DL1,E1*DE2-E2*DE1,Q1*DQ2-Q2*DQ1,
193  DL1*DL2,DE1*DE2,DQ1*DQ2> > RetT;
194  std::complex<Qty<L1*DL2+L2*DL1,E1*DE2+E2*DE1,Q1*DQ2+Q2*DQ1,
195  DL1*DL2,DE1*DE2,DQ1*DQ2> > tmp = q1*conj(q2);
196  Qty<2*L2,2*E2,2*Q2,DL2,DE2,DQ2> norm = (q2*conj(q2)).real();
197  return RetT(tmp.real()/norm,tmp.imag()/norm);
198 }
199 
200 // complex qty = qty / complex qty
201 template<int L1, int L2, int E1, int E2, int Q1, int Q2,
202  int DL1, int DL2, int DE1, int DE2, int DQ1, int DQ2>
203 inline std::complex<Qty<L1*DL2-L2*DL1,E1*DE2-E2*DE1,Q1*DQ2-Q2*DQ1,DL1*DL2,DE1*DE2,DQ1*DQ2> >
204 operator/(Qty<L1,E1,Q1,DL1,DE1,DQ1> q1,
205  std::complex<Qty<L2,E2,Q2,DL2,DE2,DQ2> > q2) {
206  typedef std::complex<Qty<L1*DL2-L2*DL1,E1*DE2-E2*DE1,Q1*DQ2-Q2*DQ1,
207  DL1*DL2,DE1*DE2,DQ1*DQ2> > RetT;
208  std::complex<Qty<L1*DL2+L2*DL1,E1*DE2+E2*DE1,Q1*DQ2+Q2*DQ1,
209  DL1*DL2,DE1*DE2,DQ1*DQ2> > tmp = q1*conj(q2);
210  Qty<2*L2,2*E2,2*Q2,DL2,DE2,DQ2> norm = (q2*conj(q2)).real();
211  return RetT(tmp.real()/norm,tmp.imag()/norm);
212 }
213 
214 // complex qty = complex qty / qty
215 template<int L1, int L2, int E1, int E2, int Q1, int Q2,
216  int DL1, int DL2, int DE1, int DE2, int DQ1, int DQ2>
217 inline std::complex<Qty<L1*DL2-L2*DL1,E1*DE2-E2*DE1,Q1*DQ2-Q2*DQ1,DL1*DL2,DE1*DE2,DQ1*DQ2> >
218 operator/(std::complex<Qty<L1,E1,Q1,DL1,DE1,DQ1> > q1,
219  Qty<L2,E2,Q2,DL2,DE2,DQ2> q2) {
220  typedef std::complex<Qty<L1*DL2-L2*DL1,E1*DE2-E2*DE1,Q1*DQ2-Q2*DQ1,
221  DL1*DL2,DE1*DE2,DQ1*DQ2> > RetT;
222  return RetT(q1.real()/q2,q1.imag()/q2);
223 }
224 
225 
226 // complex qty = complex qty * complex double
227 template<int L, int E, int Q, int DL, int DE, int DQ>
228 inline std::complex<Qty<L,E,Q,DL,DE,DQ> >
229 operator*(std::complex<Qty<L,E,Q,DL,DE,DQ> > q1,
230  std::complex<double> q2) {
231  return q2 * q1;
232 }
233 
234 
235 // complex qty = qty * complex qty
236 template<int L1, int L2, int E1, int E2, int Q1, int Q2,
237  int DL1, int DL2, int DE1, int DE2, int DQ1, int DQ2>
238 inline std::complex<Qty<L1*DL2+L2*DL1,E1*DE2+E2*DE1,Q1*DQ2+Q2*DQ1,
239  DL1*DL2,DE1*DE2,DQ1*DQ2> >
240 operator*(Qty<L1,E1,Q1,DL1,DE1,DQ1> q1,
241  std::complex<Qty<L2,E2,Q2,DL2,DE2,DQ2> > q2) {
242  typedef std::complex<Qty<L1*DL2+L2*DL1,E1*DE2+E2*DE1,Q1*DQ2+Q2*DQ1,
243  DL1*DL2,DE1*DE2,DQ1*DQ2> > RetT;
244  return RetT(q1*q2.real(), q1*q2.imag());
245 }
246 
247 // complex qty = qty * complex qty
248 template<int L, int E, int Q, int DL, int DE, int DQ>
249 inline std::complex<Qty<2*L,2*E,2*Q,DL,DE,DQ> >
250 operator*(Qty<L,E,Q,DL,DE,DQ> q1,
251  std::complex<Qty<L,E,Q,DL,DE,DQ> > q2) {
252  typedef std::complex<Qty<2*L,2*E,2*Q,DL,DE,DQ> > RetT;
253  return RetT(q1*q2.real(), q1*q2.imag());
254 }
255 
256 // complex qty = qty * complex double
257 template<int L, int E, int Q, int DL, int DE, int DQ>
258 inline std::complex<Qty<L,E,Q,DL,DE,DQ> >
259 operator*(Qty<L,E,Q,DL,DE,DQ> q1,
260  std::complex<double> q2) {
261  typedef std::complex<Qty<L,E,Q,DL,DE,DQ> > RetT;
262  return RetT(q1*q2.real(), q1*q2.imag());
263 }
264 
265 // complex qty = complex double * qty
266 template<int L, int E, int Q, int DL, int DE, int DQ>
267 inline std::complex<Qty<L,E,Q,DL,DE,DQ> >
268 operator*(std::complex<double> q1,
269  Qty<L,E,Q,DL,DE,DQ> q2) {
270  return q2 * q1;
271 }
272 
273 
274 // complex qty = complex qty * qty
275 template<int L1, int L2, int E1, int E2, int Q1, int Q2,
276  int DL1, int DL2, int DE1, int DE2, int DQ1, int DQ2>
277 inline std::complex<Qty<L1*DL2+L2*DL1,E1*DE2+E2*DE1,Q1*DQ2+Q2*DQ1,
278  DL1*DL2,DE1*DE2,DQ1*DQ2> >
279 operator*(std::complex<Qty<L1,E1,Q1,DL1,DE1,DQ1> > q1,
280  Qty<L2,E2,Q2,DL2,DE2,DQ2> q2) {
281  return q2 * q1;
282 }
283 
284 // complex qty = complex qty * qty
285 template<int L, int E, int Q, int DL, int DE, int DQ>
286 inline std::complex<Qty<2*L,2*E,2*Q,DL,DE,DQ> >
287 operator*(std::complex<Qty<L,E,Q,DL,DE,DQ> > q1,
288  Qty<L,E,Q,DL,DE,DQ> q2) {
289  return q2 * q1;
290 }
291 
292 // complex qty *= complex double
293 template<int L, int E, int Q, int DL, int DE, int DQ>
294 inline std::complex<Qty<L,E,Q,DL,DE,DQ> > &
295 operator*=(std::complex<Qty<L,E,Q,DL,DE,DQ> > & q1,
296  std::complex<double> q2) {
297  q1 = q1 * q2;
298  return q1;
299 }
300 
301 // complex qty *= double
302 template<int L, int E, int Q, int DL, int DE, int DQ>
303 inline std::complex<Qty<L,E,Q,DL,DE,DQ> > &
304 operator*=(std::complex<Qty<L,E,Q,DL,DE,DQ> > & q1,
305  double q2) {
306  q1 = q1 * q2;
307  return q1;
308 }
309 
310 // complex qty /= complex double
311 template<int L, int E, int Q, int DL, int DE, int DQ>
312 inline std::complex<Qty<L,E,Q,DL,DE,DQ> > &
313 operator/=(std::complex<Qty<L,E,Q,DL,DE,DQ> > & q1,
314  std::complex<double> q2) {
315  q1 = q1 / q2;
316  return q1;
317 }
318 
319 // complex qty /= double
320 template<int L, int E, int Q, int DL, int DE, int DQ>
321 inline std::complex<Qty<L,E,Q,DL,DE,DQ> > &
322 operator/=(std::complex<Qty<L,E,Q,DL,DE,DQ> > & q1,
323  double q2) {
324  q1 = q1 / q2;
325  return q1;
326 }
328 }
329 
330 #endif
complex< double > rawValue_
Internal value of the dimensioned quantity.
STL namespace.
complex< ThePEG::Qty< 0, 0, 0, DL, DE, DQ > > & operator-=(const complex< ThePEG::Qty< 0, 0, 0, DL, DE, DQ > > x)
Subtraction-assignment.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
complex< double > rawValue() const
The internal representation of the dimensionful quantity.
complex(complex< double > C)
Constructor from complex<double>
complex< ThePEG::Qty< 0, 0, 0, DL, DE, DQ > > & operator+=(const complex< ThePEG::Qty< 0, 0, 0, DL, DE, DQ > > x)
Addition-assignment.
Specialization of Qty for <0,0,0> with conversions to double.
Definition: PhysicalQty.h:167
complex(double r=0.0, double i=0.0)
Default constructor.