Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:29

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // INCL++ intra-nuclear cascade model
0027 // Alain Boudard, CEA-Saclay, France
0028 // Joseph Cugnon, University of Liege, Belgium
0029 // Jean-Christophe David, CEA-Saclay, France
0030 // Pekka Kaitaniemi, CEA-Saclay, France, and Helsinki Institute of Physics, Finland
0031 // Sylvie Leray, CEA-Saclay, France
0032 // Davide Mancusi, CEA-Saclay, France
0033 //
0034 #define INCLXX_IN_GEANT4_MODE 1
0035 
0036 #include "globals.hh"
0037 
0038 /*
0039  * ThreeVector.hh
0040  *
0041  *  \date 4 June 2009
0042  * \author Pekka Kaitaniemi
0043  */
0044 
0045 #ifndef G4INCLThreeVector_hh
0046 #define G4INCLThreeVector_hh 1
0047 
0048 #include <string>
0049 #include <sstream>
0050 #include <cmath>
0051 
0052 namespace G4INCL {
0053 
0054   class ThreeVector {
0055     public:
0056       ThreeVector()
0057         :x(0.0), y(0.0), z(0.0)
0058       {}
0059 
0060       ThreeVector(G4double ax, G4double ay, G4double az)
0061         :x(ax), y(ay), z(az)
0062       {}
0063 
0064       inline G4double getX() const { return x; }
0065       inline G4double getY() const { return y; }
0066       inline G4double getZ() const { return z; }
0067 
0068       inline G4double perp() const { return std::sqrt(x*x + y*y); }
0069       inline G4double perp2() const { return x*x + y*y; }
0070       /**
0071        * Get the length of the vector.
0072        */
0073       inline G4double mag() const { return std::sqrt(x*x + y*y + z*z); }
0074 
0075       /**
0076        * Get the square of the length.
0077        */
0078       inline G4double mag2() const { return (x*x + y*y + z*z); }
0079 
0080       /**
0081        * Theta angle
0082        */
0083       inline G4double theta() const {
0084         return x == 0.0 && y == 0.0 && z == 0.0 ? 0.0 : std::atan2(perp(),z);
0085       }
0086 
0087       /**
0088        * Phi angle
0089        */
0090       inline G4double phi() const {
0091         return x == 0.0 && y == 0.0 ? 0.0 : std::atan2(y,x);
0092       }
0093 
0094       /**
0095        * Dot product.
0096        */
0097       inline G4double dot(const ThreeVector &v) const {
0098         return (x*v.x + y*v.y + z*v.z);
0099       }
0100 
0101       /**
0102        * Vector product.
0103        */
0104       ThreeVector vector(const ThreeVector &v) const {
0105         return ThreeVector(
0106             y*v.z - z*v.y,
0107             z*v.x - x*v.z,
0108             x*v.y - y*v.x
0109             );
0110       }
0111 
0112       /// \brief Set the x coordinate
0113       inline void setX(G4double ax) { x =  ax; }
0114 
0115       /// \brief Set the y coordinate
0116       inline void setY(G4double ay) { y =  ay; }
0117 
0118       /// \brief Set the z coordinate
0119       inline void setZ(G4double az) { z =  az; }
0120 
0121       /// \brief Set all the coordinates
0122       inline void set(const G4double ax, const G4double ay, const G4double az) { x=ax; y=ay; z=az; }
0123 
0124       inline void operator+= (const ThreeVector &v) {
0125         x += v.x;
0126         y += v.y;
0127         z += v.z;
0128       }
0129 
0130       /// \brief Unary minus operator
0131       inline ThreeVector operator- () const {
0132         return ThreeVector(-x,-y,-z);
0133       }
0134 
0135       inline void operator-= (const ThreeVector &v) {
0136         x -= v.x;
0137         y -= v.y;
0138         z -= v.z;
0139       }
0140 
0141       template<typename T>
0142         inline void operator*= (const T &c) {
0143           x *= c;
0144           y *= c;
0145           z *= c;
0146         }
0147 
0148       template<typename T>
0149         inline void operator/= (const T &c) {
0150           const G4double oneOverC = 1./c;
0151           this->operator*=(oneOverC);
0152         }
0153 
0154       inline ThreeVector operator- (const ThreeVector &v) const {
0155         return ThreeVector(x-v.x, y-v.y, z-v.z);
0156       }
0157 
0158       inline ThreeVector operator+ (const ThreeVector &v) const {
0159         return ThreeVector(x+v.x, y+v.y, z+v.z);
0160       }
0161 
0162       /**
0163        * Divides all components of the vector with a constant number.
0164        */
0165       inline ThreeVector operator/ (const G4double C) const {
0166         const G4double oneOverC = 1./C;
0167         return ThreeVector(x*oneOverC, y*oneOverC, z*oneOverC);
0168       }
0169 
0170       inline ThreeVector operator* (const G4double C) const {
0171         return ThreeVector(x*C, y*C, z*C);
0172       }
0173 
0174       /** \brief Rotate the vector by a given angle around a given axis
0175        *
0176        * \param angle the rotation angle
0177        * \param axis the rotation axis, which must be a unit vector
0178        */
0179       inline void rotate(const G4double angle, const ThreeVector &axis) {
0180         // Use Rodrigues' formula
0181         const G4double cos = std::cos(angle);
0182         const G4double sin = std::sin(angle);
0183         (*this) = (*this) * cos + axis.vector(*this) * sin + axis * (axis.dot(*this)*(1.-cos));
0184       }
0185 
0186       /** \brief Return a vector orthogonal to this
0187        *
0188        * Simple algorithm from Hughes and Moeller, J. Graphics Tools 4 (1999)
0189        * 33.
0190        */
0191       ThreeVector anyOrthogonal() const {
0192         if(x<=y && x<=z)
0193           return ThreeVector(0., -z, y);
0194         else if(y<=x && y<=z)
0195           return ThreeVector(-z, 0., x);
0196         else
0197           return ThreeVector(-y, x, 0.);
0198       }
0199 
0200       std::string print() const {
0201         std::stringstream ss;
0202         ss <<"(x = " << x << "   y = " << y << "   z = " << z <<")";
0203         return ss.str();
0204       }
0205 
0206       std::string dump() const {
0207         std::stringstream ss;
0208         ss <<"(vector3 " << x << " " << y << " " << z << ")";
0209         return ss.str();
0210       }
0211 
0212     private:
0213       G4double x, y, z; //> Vector components
0214   };
0215 
0216 }
0217 
0218 #endif