Geant4  10.02.p03
G4CachedMagneticField Class Reference

#include <G4CachedMagneticField.hh>

Inheritance diagram for G4CachedMagneticField:
Collaboration diagram for G4CachedMagneticField:

Public Member Functions

 G4CachedMagneticField (G4MagneticField *, G4double distanceConst)
 
virtual ~G4CachedMagneticField ()
 
 G4CachedMagneticField (const G4CachedMagneticField &r)
 
G4CachedMagneticFieldoperator= (const G4CachedMagneticField &p)
 
virtual void GetFieldValue (const G4double Point[4], G4double *Bfield) const
 
G4double GetConstDistance () const
 
void SetConstDistance (G4double dist)
 
G4int GetCountCalls () const
 
G4int GetCountEvaluations () const
 
void ClearCounts ()
 
void ReportStatistics ()
 
virtual G4FieldClone () const
 
- Public Member Functions inherited from G4MagneticField
 G4MagneticField ()
 
virtual ~G4MagneticField ()
 
 G4MagneticField (const G4MagneticField &r)
 
G4MagneticFieldoperator= (const G4MagneticField &p)
 
G4bool DoesFieldChangeEnergy () const
 
- Public Member Functions inherited from G4ElectroMagneticField
 G4ElectroMagneticField ()
 
virtual ~G4ElectroMagneticField ()
 
 G4ElectroMagneticField (const G4ElectroMagneticField &r)
 
G4ElectroMagneticFieldoperator= (const G4ElectroMagneticField &p)
 
- Public Member Functions inherited from G4Field
 G4Field (G4bool gravityOn=false)
 
 G4Field (const G4Field &)
 
virtual ~G4Field ()
 
G4Fieldoperator= (const G4Field &p)
 
G4bool IsGravityActive () const
 
void SetGravityActive (G4bool OnOffFlag)
 

Protected Attributes

G4int fCountCalls
 
G4int fCountEvaluations
 

Private Attributes

G4MagneticFieldfpMagneticField
 
G4double fDistanceConst
 
G4ThreeVector fLastLocation
 
G4ThreeVector fLastValue
 

Detailed Description

Definition at line 47 of file G4CachedMagneticField.hh.

Constructor & Destructor Documentation

◆ G4CachedMagneticField() [1/2]

G4CachedMagneticField::G4CachedMagneticField ( G4MagneticField pMagField,
G4double  distanceConst 
)

Definition at line 33 of file G4CachedMagneticField.cc.

35  : G4MagneticField(),
39 {
40  fpMagneticField= pMagField;
41  fDistanceConst= distance;
42 
43  // G4cout << " Cached-B-Field constructor> Distance = " << distance << G4endl;
44  this->ClearCounts();
45 }
G4MagneticField * fpMagneticField
#define DBL_MAX
Definition: templates.hh:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~G4CachedMagneticField()

G4CachedMagneticField::~G4CachedMagneticField ( )
virtual

Definition at line 58 of file G4CachedMagneticField.cc.

59 {
60 }

◆ G4CachedMagneticField() [2/2]

G4CachedMagneticField::G4CachedMagneticField ( const G4CachedMagneticField r)

Definition at line 70 of file G4CachedMagneticField.cc.

71  : G4MagneticField(rightCMF)
72 {
73  fpMagneticField= rightCMF.fpMagneticField; // NOTE: sharing pointer here!
74  fDistanceConst = rightCMF.fDistanceConst;
75  fLastLocation = rightCMF.fLastLocation;
76  fLastValue = rightCMF.fLastValue;
77  this->ClearCounts();
78 }
G4MagneticField * fpMagneticField
Here is the call graph for this function:

Member Function Documentation

◆ ClearCounts()

void G4CachedMagneticField::ClearCounts ( )
inline

Definition at line 67 of file G4CachedMagneticField.hh.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clone()

G4Field * G4CachedMagneticField::Clone ( ) const
virtual

Reimplemented from G4Field.

Definition at line 47 of file G4CachedMagneticField.cc.

48 {
49  // Cannot use copy constructor: I need to clone the associated magnetic field
50  G4MagneticField* aF = static_cast<G4MagneticField*>(fpMagneticField->Clone());
52 
53  cloned->fLastLocation = fLastLocation;
54  cloned->fLastValue = fLastValue;
55  return cloned;
56 }
G4MagneticField * fpMagneticField
virtual G4Field * Clone() const
Definition: G4Field.cc:54
G4CachedMagneticField(G4MagneticField *, G4double distanceConst)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetConstDistance()

G4double G4CachedMagneticField::GetConstDistance ( ) const
inline

Definition at line 62 of file G4CachedMagneticField.hh.

62 { return fDistanceConst; }

◆ GetCountCalls()

G4int G4CachedMagneticField::GetCountCalls ( ) const
inline

Definition at line 65 of file G4CachedMagneticField.hh.

◆ GetCountEvaluations()

G4int G4CachedMagneticField::GetCountEvaluations ( ) const
inline

Definition at line 66 of file G4CachedMagneticField.hh.

◆ GetFieldValue()

void G4CachedMagneticField::GetFieldValue ( const G4double  Point[4],
G4double Bfield 
) const
virtual

Implements G4MagneticField.

Definition at line 93 of file G4CachedMagneticField.cc.

95 {
96  G4ThreeVector newLocation( Point[0], Point[1], Point[2] );
97 
98  // G4cout << "Cache-B-field called at " << newLocation << G4endl;
99 
100  G4double distSq= (newLocation-fLastLocation).mag2();
101  fCountCalls++;
102  if( distSq < fDistanceConst*fDistanceConst ) {
103  Bfield[0] = fLastValue.x();
104  Bfield[1] = fLastValue.y();
105  Bfield[2] = fLastValue.z();
106  }else{
107  // G4CachedMagneticField* thisNonC= const_cast<G4CachedMagneticField*>(this);
108  fpMagneticField->GetFieldValue( Point, Bfield );
109  // G4cout << " Evaluating. " << G4endl;
111  // thisNonC->
112  fLastLocation= G4ThreeVector( Point[0], Point[1], Point[2] );
113  // thisNonC->
114  fLastValue= G4ThreeVector( Bfield[0], Bfield[1], Bfield[2] );
115  }
116 }
G4MagneticField * fpMagneticField
CLHEP::Hep3Vector G4ThreeVector
virtual void GetFieldValue(const G4double Point[4], G4double *Bfield) const =0
double x() const
double y() const
double z() const
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:

◆ operator=()

G4CachedMagneticField & G4CachedMagneticField::operator= ( const G4CachedMagneticField p)

Definition at line 80 of file G4CachedMagneticField.cc.

81 {
82  if (&p == this) return *this;
84  fpMagneticField= p.fpMagneticField; // NOTE: sharing pointer here!
88  this->ClearCounts();
89  return *this;
90 }
G4MagneticField * fpMagneticField
G4MagneticField & operator=(const G4MagneticField &p)
Here is the call graph for this function:

◆ ReportStatistics()

void G4CachedMagneticField::ReportStatistics ( )

Definition at line 63 of file G4CachedMagneticField.cc.

64 {
65  G4cout << " Cached field: " << G4endl
66  << " Number of calls: " << fCountCalls << G4endl
67  << " Number of evaluations : " << fCountEvaluations << G4endl;
68 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
Here is the caller graph for this function:

◆ SetConstDistance()

void G4CachedMagneticField::SetConstDistance ( G4double  dist)
inline

Definition at line 63 of file G4CachedMagneticField.hh.

Member Data Documentation

◆ fCountCalls

G4int G4CachedMagneticField::fCountCalls
mutableprotected

Definition at line 81 of file G4CachedMagneticField.hh.

◆ fCountEvaluations

G4int G4CachedMagneticField::fCountEvaluations
mutableprotected

Definition at line 81 of file G4CachedMagneticField.hh.

◆ fDistanceConst

G4double G4CachedMagneticField::fDistanceConst
private

Definition at line 75 of file G4CachedMagneticField.hh.

◆ fLastLocation

G4ThreeVector G4CachedMagneticField::fLastLocation
mutableprivate

Definition at line 77 of file G4CachedMagneticField.hh.

◆ fLastValue

G4ThreeVector G4CachedMagneticField::fLastValue
mutableprivate

Definition at line 78 of file G4CachedMagneticField.hh.

◆ fpMagneticField

G4MagneticField* G4CachedMagneticField::fpMagneticField
private

Definition at line 73 of file G4CachedMagneticField.hh.


The documentation for this class was generated from the following files: