Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes
G4CachedMagneticField Class Reference

#include <G4CachedMagneticField.hh>

Inheritance diagram for G4CachedMagneticField:
G4MagneticField G4ElectroMagneticField G4Field

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 G4CachedMagneticFieldClone () 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
 

Detailed Description

Definition at line 47 of file G4CachedMagneticField.hh.

Constructor & Destructor Documentation

G4CachedMagneticField::G4CachedMagneticField ( G4MagneticField pMagField,
G4double  distanceConst 
)

Definition at line 33 of file G4CachedMagneticField.cc.

References ClearCounts().

Referenced by Clone().

35  : G4MagneticField(),
36  fLastLocation(DBL_MAX,DBL_MAX,DBL_MAX),
37  fLastValue(DBL_MAX,DBL_MAX,DBL_MAX),
39 {
40  fpMagneticField= pMagField;
41  fDistanceConst= distance;
42 
43  // G4cout << " Cached-B-Field constructor> Distance = " << distance << G4endl;
44  this->ClearCounts();
45 }
#define DBL_MAX
Definition: templates.hh:83
G4CachedMagneticField::~G4CachedMagneticField ( )
virtual

Definition at line 58 of file G4CachedMagneticField.cc.

59 {
60 }
G4CachedMagneticField::G4CachedMagneticField ( const G4CachedMagneticField r)

Definition at line 70 of file G4CachedMagneticField.cc.

References ClearCounts().

71  : G4MagneticField()
72 {
73  fpMagneticField= rightCMF.fpMagneticField;
74  fDistanceConst = rightCMF.fDistanceConst;
75  fLastLocation = rightCMF.fLastLocation;
76  fLastValue = rightCMF.fLastValue;
77  this->ClearCounts();
78 }

Member Function Documentation

void G4CachedMagneticField::ClearCounts ( )
inline
G4CachedMagneticField * G4CachedMagneticField::Clone ( ) const
virtual

Reimplemented from G4Field.

Definition at line 47 of file G4CachedMagneticField.cc.

References G4Field::Clone(), and G4CachedMagneticField().

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

Definition at line 62 of file G4CachedMagneticField.hh.

62 { return fDistanceConst; }
G4int G4CachedMagneticField::GetCountCalls ( ) const
inline

Definition at line 65 of file G4CachedMagneticField.hh.

References fCountCalls.

65 { return fCountCalls; }
G4int G4CachedMagneticField::GetCountEvaluations ( ) const
inline

Definition at line 66 of file G4CachedMagneticField.hh.

References fCountEvaluations.

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

Implements G4MagneticField.

Definition at line 86 of file G4CachedMagneticField.cc.

References fCountCalls, fCountEvaluations, G4MagneticField::GetFieldValue(), CLHEP::Hep3Vector::x(), CLHEP::Hep3Vector::y(), and CLHEP::Hep3Vector::z().

88 {
89  G4ThreeVector newLocation( Point[0], Point[1], Point[2] );
90 
91  // G4cout << "Cache-B-field called at " << newLocation << G4endl;
92 
93  G4double distSq= (newLocation-fLastLocation).mag2();
94  fCountCalls++;
95  if( distSq < fDistanceConst*fDistanceConst ) {
96  Bfield[0] = fLastValue.x();
97  Bfield[1] = fLastValue.y();
98  Bfield[2] = fLastValue.z();
99  }else{
100  // G4CachedMagneticField* thisNonC= const_cast<G4CachedMagneticField*>(this);
101  fpMagneticField->GetFieldValue( Point, Bfield );
102  // G4cout << " Evaluating. " << G4endl;
104  // thisNonC->
105  fLastLocation= G4ThreeVector( Point[0], Point[1], Point[2] );
106  // thisNonC->
107  fLastValue= G4ThreeVector( Bfield[0], Bfield[1], Bfield[2] );
108  }
109 }
CLHEP::Hep3Vector G4ThreeVector
double x() const
virtual void GetFieldValue(const G4double Point[4], G4double *Bfield) const =0
double z() const
double y() const
double G4double
Definition: G4Types.hh:76
G4CachedMagneticField & G4CachedMagneticField::operator= ( const G4CachedMagneticField p)

Definition at line 80 of file G4CachedMagneticField.cc.

81 {
82  if (&p == this) return *this; *this = p; return *this;
83 }
const char * p
Definition: xmltok.h:285
void G4CachedMagneticField::ReportStatistics ( )

Definition at line 63 of file G4CachedMagneticField.cc.

References fCountCalls, fCountEvaluations, G4cout, and G4endl.

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
void G4CachedMagneticField::SetConstDistance ( G4double  dist)
inline

Definition at line 63 of file G4CachedMagneticField.hh.

63 { fDistanceConst= dist;}

Field Documentation

G4int G4CachedMagneticField::fCountCalls
mutableprotected
G4int G4CachedMagneticField::fCountEvaluations
mutableprotected

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