RooComplex.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  *    File: $Id: RooComplex.h,v 1.13 2007/05/11 09:11:30 verkerke Exp $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 #ifndef ROO_COMPLEX
00017 #define ROO_COMPLEX
00018 
00019 #include <math.h>
00020 #include "Rtypes.h"
00021 #include "Riosfwd.h"
00022 
00023 // This is a bare-bones complex class adapted from the CINT complex.h header,
00024 // and introduced to support the complex error function in RooMath. The main
00025 // changes with respect to the CINT header are to avoid defining global
00026 // functions (at the cost of not supporting implicit casts on the first
00027 // argument) and adding const declarations where appropriate.
00028 
00029 class RooComplex {
00030 public:
00031   inline RooComplex(Double_t a=0, Double_t b=0) : _re(a), _im(b) { }
00032   virtual ~RooComplex() {} ;
00033   inline RooComplex& operator=(const RooComplex& other) {
00034     if (&other==this) return *this ;
00035     this->_re= other._re;
00036     this->_im= other._im;
00037     return(*this);
00038   }
00039   // unary operators
00040   inline RooComplex operator-() const {
00041     return RooComplex(-_re,-_im);
00042   }
00043   // binary operators
00044   inline RooComplex operator+(const RooComplex& other) const {
00045     return RooComplex(this->_re + other._re, this->_im + other._im);
00046   }
00047   inline RooComplex operator-(const RooComplex& other) const {
00048     return RooComplex(this->_re - other._re, this->_im - other._im);
00049   }
00050   inline RooComplex operator*(const RooComplex& other) const {
00051     return RooComplex(this->_re*other._re - this->_im*other._im,
00052                       this->_re*other._im + this->_im*other._re);
00053   }
00054   inline RooComplex operator/(const RooComplex& other) const {
00055     Double_t x(other.abs2());
00056     return RooComplex((this->_re*other._re + this->_im*other._im)/x,
00057                       (this->_im*other._re - this->_re*other._im)/x);
00058   }
00059   inline RooComplex operator*(const Double_t& other) const {
00060     return RooComplex(this->_re*other,this->_im*other);
00061   }
00062 
00063 
00064   inline Bool_t operator==(const RooComplex& other) const {
00065     return (_re==other._re && _im==other._im) ;
00066   }
00067 
00068   // unary functions
00069   inline Double_t re() const {
00070     return _re;
00071   }
00072   inline Double_t im() const {
00073     return _im;
00074   }
00075   inline Double_t abs() const {
00076     return ::sqrt(_re*_re + _im*_im);
00077   }
00078   inline Double_t abs2() const {
00079     return _re*_re + _im*_im;
00080   }
00081   inline RooComplex exp() const {
00082     Double_t mag(::exp(_re));
00083     return RooComplex(mag*cos(_im),mag*sin(_im));
00084   }
00085   inline RooComplex conj() const {
00086     return RooComplex(_re,-_im);
00087   }
00088   inline RooComplex sqrt() const {
00089     Double_t arg=atan2(_im,_re)*0.5;
00090     Double_t mag=::sqrt(::sqrt(_re*_re + _im*_im));
00091     return RooComplex(mag*cos(arg),mag*sin(arg));
00092   }
00093   // ouptput formatting
00094   void Print() const;
00095 private:
00096   Double_t _re,_im;
00097   ClassDef(RooComplex,0) // a non-persistent bare-bones complex class
00098 };
00099 
00100 // output formatting
00101 ostream& operator<<(ostream& os, const RooComplex& z);
00102 
00103 #endif

Generated on Tue Jul 5 14:26:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1