Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4UniformMagField implementation << 27 // 23 // 28 // Created: V.Grichine, 30.01.1997 << 24 // $Id: G4UniformMagField.cc,v 1.6 2003/04/02 08:50:39 gcosmo Exp $ 29 // ------------------------------------------- << 25 // GEANT4 tag $Name: geant4-05-02-patch-01 $ 30 << 26 // >> 27 // >> 28 // >> 29 // Class for creation of uniform Magnetic Field >> 30 // >> 31 // 30.1.97 V.Grichine >> 32 // 31 #include "G4UniformMagField.hh" 33 #include "G4UniformMagField.hh" 32 #include "G4PhysicalConstants.hh" << 34 #include "globals.hh" >> 35 #include "geomdefs.hh" 33 36 34 G4UniformMagField::G4UniformMagField(const G4T 37 G4UniformMagField::G4UniformMagField(const G4ThreeVector& FieldVector ) 35 { 38 { 36 fFieldComponents[0] = FieldVector.x(); << 39 fFieldComponents[0] = FieldVector.x(); 37 fFieldComponents[1] = FieldVector.y(); << 40 fFieldComponents[1] = FieldVector.y(); 38 fFieldComponents[2] = FieldVector.z(); << 41 fFieldComponents[2] = FieldVector.z(); 39 } 42 } 40 43 41 G4UniformMagField::~G4UniformMagField() = defa << 44 void 42 << 45 G4UniformMagField::SetFieldValue(const G4ThreeVector& newFieldVector ) 43 G4UniformMagField::G4UniformMagField (const G4 << 44 : G4MagneticField(p) << 45 { 46 { 46 for (auto i=0; i<3; ++i) << 47 fFieldComponents[0] = newFieldVector.x(); 47 { << 48 fFieldComponents[1] = newFieldVector.y(); 48 fFieldComponents[i] = p.fFieldComponents[ << 49 fFieldComponents[2] = newFieldVector.z(); 49 } << 50 } 50 } 51 << 51 52 G4UniformMagField& G4UniformMagField::operator << 52 G4UniformMagField::G4UniformMagField(G4double vField, >> 53 G4double vTheta, >> 54 G4double vPhi ) 53 { 55 { 54 if (&p == this) { return *this;} << 56 if(vField >= 0 && 55 G4MagneticField::operator=(p); << 57 vTheta >= 0 && vTheta <= pi && 56 for (auto i=0; i<3; ++i) << 58 vPhi >= 0 && vPhi <= twopi) 57 { 59 { 58 fFieldComponents[i] = p.fFieldComponents[ << 60 fFieldComponents[0] = vField*sin(vTheta)*cos(vPhi) ; >> 61 fFieldComponents[1] = vField*sin(vTheta)*sin(vPhi) ; >> 62 fFieldComponents[2] = vField*cos(vTheta) ; >> 63 } >> 64 else >> 65 { >> 66 G4Exception("Invalid parameters in G4UniformMagField::G4UniformMagField") ; 59 } 67 } 60 return *this; << 61 } 68 } 62 69 63 G4Field* G4UniformMagField::Clone() const << 70 G4UniformMagField::~G4UniformMagField() 64 { 71 { 65 return new G4UniformMagField( G4ThreeVector << 72 ; 66 << 67 << 68 } 73 } 69 74 70 void << 75 G4UniformMagField::G4UniformMagField (const G4UniformMagField &p) 71 G4UniformMagField::SetFieldValue(const G4Three << 76 : G4MagneticField(p) 72 { 77 { 73 fFieldComponents[0] = newFieldVector.x(); << 78 for (G4int i=0; i<3; i++) 74 fFieldComponents[1] = newFieldVector.y(); << 79 fFieldComponents[i] = p.fFieldComponents[i]; 75 fFieldComponents[2] = newFieldVector.z(); << 76 } 80 } 77 << 81 78 G4UniformMagField::G4UniformMagField(G4double << 82 G4UniformMagField& G4UniformMagField::operator = (const G4UniformMagField &p) 79 G4double << 80 G4double << 81 { 83 { 82 if ( (vField<0) || (vTheta<0) || (vTheta>pi << 84 if (&p == this) return *this; 83 { << 85 for (G4int i=0; i<3; i++) 84 std::ostringstream msg; << 86 fFieldComponents[i] = p.fFieldComponents[i]; 85 msg << "ERROR in G4UniformMagField::G4Un << 87 return *this; 86 << "Invalid parameter(s). " << std:: << 87 msg << " Expected " << std::endl; << 88 << 89 msg << " - Magnitude vField: Value = " < << 90 << " Expected vField > 0 " ; << 91 if ( vField<0) { msg << " <------ Erron << 92 msg << std::endl; << 93 << 94 msg << " - Theta angle: Value = " << vTh << 95 << " Expected between 0 <= theta <= << 96 if ( (vTheta<0) || (vTheta>pi) ) { msg < << 97 << 98 msg << std::endl; << 99 msg << " - Phi angle: Value = " << vPh << 100 << " Expected between 0 <= phi <= << 101 if ( (vPhi<0) || (vPhi>twopi) ) { msg << << 102 << 103 G4Exception("G4UniformMagField::G4Unifor << 104 "GeomField0002", FatalExcept << 105 } << 106 fFieldComponents[0] = vField*std::sin(vThet << 107 fFieldComponents[1] = vField*std::sin(vThet << 108 fFieldComponents[2] = vField*std::cos(vThet << 109 } 88 } 110 89 111 // ------------------------------------------- 90 // ------------------------------------------------------------------------ 112 91 >> 92 113 void G4UniformMagField::GetFieldValue (const G 93 void G4UniformMagField::GetFieldValue (const G4double [4], 114 G << 94 G4double *B ) const 115 { 95 { 116 B[0]= fFieldComponents[0]; << 96 B[0]= fFieldComponents[0] ; 117 B[1]= fFieldComponents[1]; << 97 B[1]= fFieldComponents[1] ; 118 B[2]= fFieldComponents[2]; << 98 B[2]= fFieldComponents[2] ; >> 99 return ; 119 } 100 } 120 101 121 G4ThreeVector G4UniformMagField::GetConstantFi << 122 { << 123 G4ThreeVector B(fFieldComponents[0], << 124 fFieldComponents[1], << 125 fFieldComponents[2]); << 126 return B; << 127 } << 128 102