G4INCLThreeVector.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // INCL++ intra-nuclear cascade model
00027 // Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
00028 // Davide Mancusi, CEA
00029 // Alain Boudard, CEA
00030 // Sylvie Leray, CEA
00031 // Joseph Cugnon, University of Liege
00032 //
00033 #define INCLXX_IN_GEANT4_MODE 1
00034 
00035 #include "globals.hh"
00036 
00037 /*
00038  * ThreeVector.hh
00039  *
00040  *  \date 4 June 2009
00041  * \author Pekka Kaitaniemi
00042  */
00043 
00044 #ifndef G4INCLThreeVector_hh
00045 #define G4INCLThreeVector_hh 1
00046 
00047 #include <string>
00048 #include <sstream>
00049 #include <cmath>
00050 
00051 namespace G4INCL {
00052 
00053   class ThreeVector {
00054     public:
00055       ThreeVector()
00056         :x(0.0), y(0.0), z(0.0)
00057       {}
00058 
00059       ThreeVector(G4double ax, G4double ay, G4double az)
00060         :x(ax), y(ay), z(az)
00061       {}
00062 
00063       inline G4double getX() const { return x; }
00064       inline G4double getY() const { return y; }
00065       inline G4double getZ() const { return z; }
00066 
00067       inline G4double perp() const { return std::sqrt(x*x + y*y); }
00068       inline G4double perp2() const { return x*x + y*y; }
00072       inline G4double mag() const { return std::sqrt(x*x + y*y + z*z); }
00073 
00077       inline G4double mag2() const { return (x*x + y*y + z*z); }
00078 
00082       inline G4double theta() const {
00083         return x == 0.0 && y == 0.0 && z == 0.0 ? 0.0 : std::atan2(perp(),z);
00084       }
00085 
00089       inline G4double phi() const {
00090         return x == 0.0 && y == 0.0 ? 0.0 : std::atan2(y,x);
00091       }
00092 
00096       inline G4double dot(const ThreeVector &v) const {
00097         return (x*v.x + y*v.y + z*v.z);
00098       }
00099 
00103       ThreeVector vector(const ThreeVector &v) const {
00104         return ThreeVector(
00105             y*v.z - z*v.y,
00106             z*v.x - x*v.z,
00107             x*v.y - y*v.x
00108             );
00109       }
00110 
00112       inline void setX(G4double ax) { x =  ax; }
00113 
00115       inline void setY(G4double ay) { y =  ay; }
00116 
00118       inline void setZ(G4double az) { z =  az; }
00119 
00120       inline void operator+= (const ThreeVector &v) {
00121         x += v.x;
00122         y += v.y;
00123         z += v.z;
00124       }
00125 
00127       inline ThreeVector operator- () const {
00128         return ThreeVector(-x,-y,-z);
00129       }
00130 
00131       inline void operator-= (const ThreeVector &v) {
00132         x -= v.x;
00133         y -= v.y;
00134         z -= v.z;
00135       }
00136 
00137       template<typename T>
00138         inline void operator*= (const T c) {
00139           x *= c;
00140           y *= c;
00141           z *= c;
00142         }
00143 
00144       template<typename T>
00145         inline void operator/= (const T c) {
00146           x /= c;
00147           y /= c;
00148           z /= c;
00149         }
00150 
00151       inline ThreeVector operator- (const ThreeVector &v) const {
00152         return ThreeVector(x-v.x, y-v.y, z-v.z);
00153       }
00154 
00155       inline ThreeVector operator+ (const ThreeVector &v) const {
00156         return ThreeVector(x+v.x, y+v.y, z+v.z);
00157       }
00158 
00162       inline ThreeVector operator/ (const G4double C) const {
00163         return ThreeVector(x/C, y/C, z/C);
00164       }
00165 
00166       inline ThreeVector operator* (const G4double C) const {
00167         return ThreeVector(x*C, y*C, z*C);
00168       }
00169 
00175       inline void rotate(const G4double angle, const ThreeVector &axis) {
00176         // Use Rodrigues' formula
00177         const G4double cos = std::cos(angle);
00178         const G4double sin = std::sin(angle);
00179         (*this) = (*this) * cos + axis.vector(*this) * sin + axis * (axis.dot(*this)*(1.-cos));
00180       }
00181 
00182       std::string print() const {
00183         std::stringstream ss;
00184         ss <<"(x = " << x << "   y = " << y << "   z = " << z <<")";
00185         return ss.str();
00186       }
00187 
00188       std::string dump() const {
00189         std::stringstream ss;
00190         ss <<"(vector3 " << x << " " << y << " " << z << ")";
00191         return ss.str();
00192       }
00193 
00194     private:
00195       G4double x, y, z; //> Vector components
00196   };
00197 
00198 }
00199 
00200 #endif

Generated on Mon May 27 17:48:37 2013 for Geant4 by  doxygen 1.4.7