Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TUniformMagneticField.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4TUniformMagneticField
27//
28// Class description:
29//
30// Templated version of G4UniformMagneticField.
31
32// Author: Josh Xie (CERN, Google Summer of Code 2014), June 2014
33// Supervisors: Sandro Wenzel, John Apostolakis (CERN)
34// --------------------------------------------------------------------
35#ifndef G4TUniformMagneticField_HH
36#define G4TUniformMagneticField_HH
37
38#include "G4Types.hh"
39#include "G4ThreeVector.hh"
40#include "G4MagneticField.hh"
41
42/**
43 * @brief G4TUniformMagneticField is a templated version of
44 * G4UniformMagneticField.
45 */
46
48{
49 public:
50
52 // A field with value equal to FieldVector.
53 {
54 fFieldComponents[0] = FieldVector.x();
55 fFieldComponents[1] = FieldVector.y();
56 fFieldComponents[2] = FieldVector.z();
57 }
58
59
61 G4double vTheta,
62 G4double vPhi )
63 {
64 if ( (vField<0) || (vTheta<0) || (vTheta>pi) || (vPhi<0) || (vPhi>twopi) )
65 {
66 G4Exception("G4TUniformMagneticField::G4TUniformMagneticField()",
67 "GeomField0002", FatalException, "Invalid parameters.") ;
68 }
69 fFieldComponents[0] = vField*std::sin(vTheta)*std::cos(vPhi) ;
70 fFieldComponents[1] = vField*std::sin(vTheta)*std::sin(vPhi) ;
71 fFieldComponents[2] = vField*std::cos(vTheta) ;
72 }
73
74 virtual ~G4TUniformMagneticField() = default;
75
78 {
79 for (G4int i=0; i<3; ++i)
80 fFieldComponents[i] = p.fFieldComponents[i];
81 }
82
84 // Copy constructor and assignment operator.
85 {
86 if (&p == this) return *this;
87 for (G4int i=0; i<3; ++i)
88 fFieldComponents[i] = p.fFieldComponents[i];
89 return *this;
90 }
91
92 inline void GetFieldValue(const G4double yTrack[4],
93 G4double *B) const
94 {
95 B[0]= fFieldComponents[0] ;
96 B[1]= fFieldComponents[1] ;
97 B[2]= fFieldComponents[2] ;
98 }
99
100 void SetFieldValue(const G4ThreeVector& newFieldVector)
101 {
102 fFieldComponents[0] = newFieldVector.x();
103 fFieldComponents[1] = newFieldVector.y();
104 fFieldComponents[2] = newFieldVector.z();
105 }
106
108 {
109 G4ThreeVector B(fFieldComponents[0],
110 fFieldComponents[1],
111 fFieldComponents[2]);
112 return B;
113 }
114 // Return the field value
115
117 {
118 return new G4TUniformMagneticField( G4ThreeVector(this->fFieldComponents[0],
119 this->fFieldComponents[1],
120 this->fFieldComponents[2]) );
121 }
122
123 private:
124
125 G4double fFieldComponents[3] ;
126};
127
128#endif
G4double B(G4double temperature)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
double z() const
double x() const
double y() const
G4TUniformMagneticField(const G4ThreeVector &FieldVector)
G4TUniformMagneticField & operator=(const G4TUniformMagneticField &p)
virtual ~G4TUniformMagneticField()=default
G4TUniformMagneticField(G4double vField, G4double vTheta, G4double vPhi)
void GetFieldValue(const G4double yTrack[4], G4double *B) const
G4TUniformMagneticField(const G4TUniformMagneticField &p)
void SetFieldValue(const G4ThreeVector &newFieldVector)
virtual G4TUniformMagneticField * Clone() const
G4ThreeVector GetConstantFieldValue() const