ROOT  6.06/09
Reference Guide
RooComplex.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooComplex.h,v 1.13 2007/05/11 09:11:30 verkerke Exp $
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 #ifndef ROO_COMPLEX
17 #define ROO_COMPLEX
18 
19 #if !defined(ROO_MATH) && !defined(ROO_COMPLEX_CXX) && !defined(__CINT__) && !defined(__CLING__) && \
20  !defined(R__DICTIONARY_FILENAME)
21 #warning "RooComplex is deprecated, use std::complex instead!"
22 #endif
23 
24 #include <math.h>
25 #include "Rtypes.h"
26 #include "Riosfwd.h"
27 #include <complex>
28 
29 // This is a bare-bones complex class adapted from the CINT complex.h header,
30 // and introduced to support the complex error function in RooMath. The main
31 // changes with respect to the CINT header are to avoid defining global
32 // functions (at the cost of not supporting implicit casts on the first
33 // argument) and adding const declarations where appropriate.
34 
35 class RooComplex {
36 public:
37 
38  inline RooComplex(std::complex<Double_t> c) : _re(c.real()), _im(c.imag()) { }
39 
40  inline RooComplex(Double_t a=0, Double_t b=0) : _re(a), _im(b) { warn(); }
41  virtual ~RooComplex() { }
42  inline RooComplex& operator=(const RooComplex& other) {
43  warn();
44  if (&other==this) return *this ;
45  this->_re= other._re;
46  this->_im= other._im;
47  return(*this);
48  }
49  // unary operators
50  inline RooComplex operator-() const {
51  return RooComplex(-_re,-_im);
52  }
53  // binary operators
54  inline RooComplex operator+(const RooComplex& other) const {
55  return RooComplex(this->_re + other._re, this->_im + other._im);
56  }
57  inline RooComplex operator-(const RooComplex& other) const {
58  return RooComplex(this->_re - other._re, this->_im - other._im);
59  }
60  inline RooComplex operator*(const RooComplex& other) const {
61  return RooComplex(this->_re*other._re - this->_im*other._im,
62  this->_re*other._im + this->_im*other._re);
63  }
64  inline RooComplex operator/(const RooComplex& other) const {
65  Double_t x(other.abs2());
66  return RooComplex((this->_re*other._re + this->_im*other._im)/x,
67  (this->_im*other._re - this->_re*other._im)/x);
68  }
69  inline RooComplex operator*(const Double_t& other) const {
70  return RooComplex(this->_re*other,this->_im*other);
71  }
72 
73 
74  inline Bool_t operator==(const RooComplex& other) const {
75  return (_re==other._re && _im==other._im) ;
76  }
77 
78  // unary functions
79  inline Double_t re() const {
80  return _re;
81  }
82  inline Double_t im() const {
83  return _im;
84  }
85  inline Double_t abs() const {
87  }
88  inline Double_t abs2() const {
89  return _re*_re + _im*_im;
90  }
91  inline RooComplex exp() const {
92  Double_t mag(::exp(_re));
93  return RooComplex(mag*cos(_im),mag*sin(_im));
94  }
95  inline RooComplex conj() const {
96  return RooComplex(_re,-_im);
97  }
98  inline RooComplex sqrt() const {
99  Double_t arg=atan2(_im,_re)*0.5;
100  Double_t mag=::sqrt(::sqrt(_re*_re + _im*_im));
101  return RooComplex(mag*cos(arg),mag*sin(arg));
102  }
103  // ouptput formatting
104  void Print() const;
105 private:
107 
108  void warn() const;
109 
110  ClassDef(RooComplex,0) // a non-persistent bare-bones complex class
111 };
112 
113 // output formatting
114 std::ostream& operator<<(std::ostream& os, const RooComplex& z);
115 
116 #endif
std::ostream & operator<<(std::ostream &os, const RooComplex &z)
Definition: RooComplex.cxx:51
RooComplex(std::complex< Double_t > c)
Definition: RooComplex.h:38
RooComplex exp() const
Definition: RooComplex.h:91
Double_t re() const
Definition: RooComplex.h:79
RooComplex operator-(const RooComplex &other) const
Definition: RooComplex.h:57
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
double cos(double)
double sqrt(double)
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
double sin(double)
RooComplex & operator=(const RooComplex &other)
Definition: RooComplex.h:42
RooComplex operator+(const RooComplex &other) const
Definition: RooComplex.h:54
Double_t _im
Definition: RooComplex.h:106
Bool_t operator==(const RooComplex &other) const
Definition: RooComplex.h:74
RooComplex operator*(const RooComplex &other) const
Definition: RooComplex.h:60
RooComplex(Double_t a=0, Double_t b=0)
Definition: RooComplex.h:40
double Double_t
Definition: RtypesCore.h:55
double atan2(double, double)
Double_t im() const
Definition: RooComplex.h:82
Double_t abs2() const
Definition: RooComplex.h:88
Double_t _re
Definition: RooComplex.h:106
void warn() const
RooComplex conj() const
Definition: RooComplex.h:95
RooComplex sqrt() const
Definition: RooComplex.h:98
Double_t abs() const
Definition: RooComplex.h:85
virtual ~RooComplex()
Definition: RooComplex.h:41
RooComplex operator-() const
Definition: RooComplex.h:50
RooComplex operator*(const Double_t &other) const
Definition: RooComplex.h:69
RooComplex operator/(const RooComplex &other) const
Definition: RooComplex.h:64
void Print() const
WVE Solaric CC5.0 complains about this.
Definition: RooComplex.cxx:47