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 // 00027 // $Id: G4UniformMagField.cc 69786 2013-05-15 09:38:51Z gcosmo $ 00028 // 00029 // 00030 // Class for creation of uniform Magnetic Field 00031 // 00032 // 30.1.97 V.Grichine 00033 // 00034 // ------------------------------------------------------------------- 00035 00036 #include "G4UniformMagField.hh" 00037 #include "G4PhysicalConstants.hh" 00038 00039 G4UniformMagField::G4UniformMagField(const G4ThreeVector& FieldVector ) 00040 { 00041 fFieldComponents[0] = FieldVector.x(); 00042 fFieldComponents[1] = FieldVector.y(); 00043 fFieldComponents[2] = FieldVector.z(); 00044 } 00045 00046 void 00047 G4UniformMagField::SetFieldValue(const G4ThreeVector& newFieldVector ) 00048 { 00049 fFieldComponents[0] = newFieldVector.x(); 00050 fFieldComponents[1] = newFieldVector.y(); 00051 fFieldComponents[2] = newFieldVector.z(); 00052 } 00053 00054 G4UniformMagField::G4UniformMagField(G4double vField, 00055 G4double vTheta, 00056 G4double vPhi ) 00057 { 00058 if ( (vField<0) || (vTheta<0) || (vTheta>pi) || (vPhi<0) || (vPhi>twopi) ) 00059 { 00060 G4Exception("G4UniformMagField::G4UniformMagField()", 00061 "GeomField0002", FatalException, "Invalid parameters.") ; 00062 } 00063 fFieldComponents[0] = vField*std::sin(vTheta)*std::cos(vPhi) ; 00064 fFieldComponents[1] = vField*std::sin(vTheta)*std::sin(vPhi) ; 00065 fFieldComponents[2] = vField*std::cos(vTheta) ; 00066 } 00067 00068 G4UniformMagField::~G4UniformMagField() 00069 { 00070 } 00071 00072 G4UniformMagField::G4UniformMagField (const G4UniformMagField &p) 00073 : G4MagneticField(p) 00074 { 00075 for (G4int i=0; i<3; i++) 00076 fFieldComponents[i] = p.fFieldComponents[i]; 00077 } 00078 00079 G4UniformMagField& G4UniformMagField::operator = (const G4UniformMagField &p) 00080 { 00081 if (&p == this) return *this; 00082 for (G4int i=0; i<3; i++) 00083 fFieldComponents[i] = p.fFieldComponents[i]; 00084 return *this; 00085 } 00086 00087 // ------------------------------------------------------------------------ 00088 00089 void G4UniformMagField::GetFieldValue (const G4double [4], 00090 G4double *B ) const 00091 { 00092 B[0]= fFieldComponents[0] ; 00093 B[1]= fFieldComponents[1] ; 00094 B[2]= fFieldComponents[2] ; 00095 } 00096 00097 G4ThreeVector G4UniformMagField::GetConstantFieldValue() const 00098 { 00099 G4ThreeVector B(fFieldComponents[0], 00100 fFieldComponents[1], 00101 fFieldComponents[2]); 00102 return B; 00103 }