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.9 2004/02/09 14:43:10 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-06-00-patch-01 $ >> 26 // >> 27 // >> 28 // Class for creation of uniform Magnetic Field >> 29 // >> 30 // 30.1.97 V.Grichine >> 31 // 29 // ------------------------------------------- 32 // ------------------------------------------------------------------- 30 33 31 #include "G4UniformMagField.hh" 34 #include "G4UniformMagField.hh" 32 #include "G4PhysicalConstants.hh" << 33 35 34 G4UniformMagField::G4UniformMagField(const G4T 36 G4UniformMagField::G4UniformMagField(const G4ThreeVector& FieldVector ) 35 { 37 { 36 fFieldComponents[0] = FieldVector.x(); << 38 fFieldComponents[0] = FieldVector.x(); 37 fFieldComponents[1] = FieldVector.y(); << 39 fFieldComponents[1] = FieldVector.y(); 38 fFieldComponents[2] = FieldVector.z(); << 40 fFieldComponents[2] = FieldVector.z(); 39 } 41 } 40 42 41 G4UniformMagField::~G4UniformMagField() = defa << 43 void 42 << 44 G4UniformMagField::SetFieldValue(const G4ThreeVector& newFieldVector ) 43 G4UniformMagField::G4UniformMagField (const G4 << 44 : G4MagneticField(p) << 45 { 45 { 46 for (auto i=0; i<3; ++i) << 46 fFieldComponents[0] = newFieldVector.x(); 47 { << 47 fFieldComponents[1] = newFieldVector.y(); 48 fFieldComponents[i] = p.fFieldComponents[ << 48 fFieldComponents[2] = newFieldVector.z(); 49 } << 50 } 49 } 51 << 50 52 G4UniformMagField& G4UniformMagField::operator << 51 G4UniformMagField::G4UniformMagField(G4double vField, >> 52 G4double vTheta, >> 53 G4double vPhi ) 53 { 54 { 54 if (&p == this) { return *this;} << 55 if(vField >= 0 && 55 G4MagneticField::operator=(p); << 56 vTheta >= 0 && vTheta <= pi && 56 for (auto i=0; i<3; ++i) << 57 vPhi >= 0 && vPhi <= twopi) 57 { 58 { 58 fFieldComponents[i] = p.fFieldComponents[ << 59 fFieldComponents[0] = vField*sin(vTheta)*cos(vPhi) ; >> 60 fFieldComponents[1] = vField*sin(vTheta)*sin(vPhi) ; >> 61 fFieldComponents[2] = vField*cos(vTheta) ; >> 62 } >> 63 else >> 64 { >> 65 G4Exception("G4UniformMagField::G4UniformMagField()", >> 66 "WrongArgumentValue", FatalException, "Invalid parameters.") ; 59 } 67 } 60 return *this; << 61 } 68 } 62 69 63 G4Field* G4UniformMagField::Clone() const << 70 G4UniformMagField::~G4UniformMagField() 64 { 71 { 65 return new G4UniformMagField( G4ThreeVector << 66 << 67 << 68 } 72 } 69 73 70 void << 74 G4UniformMagField::G4UniformMagField (const G4UniformMagField &p) 71 G4UniformMagField::SetFieldValue(const G4Three << 75 : G4MagneticField(p) 72 { 76 { 73 fFieldComponents[0] = newFieldVector.x(); << 77 for (G4int i=0; i<3; i++) 74 fFieldComponents[1] = newFieldVector.y(); << 78 fFieldComponents[i] = p.fFieldComponents[i]; 75 fFieldComponents[2] = newFieldVector.z(); << 76 } 79 } 77 << 80 78 G4UniformMagField::G4UniformMagField(G4double << 81 G4UniformMagField& G4UniformMagField::operator = (const G4UniformMagField &p) 79 G4double << 80 G4double << 81 { 82 { 82 if ( (vField<0) || (vTheta<0) || (vTheta>pi << 83 if (&p == this) return *this; 83 { << 84 for (G4int i=0; i<3; i++) 84 std::ostringstream msg; << 85 fFieldComponents[i] = p.fFieldComponents[i]; 85 msg << "ERROR in G4UniformMagField::G4Un << 86 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 } 87 } 110 88 111 // ------------------------------------------- 89 // ------------------------------------------------------------------------ 112 90 113 void G4UniformMagField::GetFieldValue (const G 91 void G4UniformMagField::GetFieldValue (const G4double [4], 114 G << 92 G4double *B ) const 115 { 93 { 116 B[0]= fFieldComponents[0]; << 94 B[0]= fFieldComponents[0] ; 117 B[1]= fFieldComponents[1]; << 95 B[1]= fFieldComponents[1] ; 118 B[2]= fFieldComponents[2]; << 96 B[2]= fFieldComponents[2] ; 119 } 97 } 120 98 121 G4ThreeVector G4UniformMagField::GetConstantFi 99 G4ThreeVector G4UniformMagField::GetConstantFieldValue() const 122 { 100 { 123 G4ThreeVector B(fFieldComponents[0], 101 G4ThreeVector B(fFieldComponents[0], 124 fFieldComponents[1], 102 fFieldComponents[1], 125 fFieldComponents[2]); 103 fFieldComponents[2]); 126 return B; << 104 return B; 127 } 105 } 128 106