00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "G4CachedMagneticField.hh"
00032
00033 G4CachedMagneticField::G4CachedMagneticField(G4MagneticField *pMagField,
00034 G4double distance)
00035 : G4MagneticField(),
00036 fLastLocation(DBL_MAX,DBL_MAX,DBL_MAX),
00037 fLastValue(DBL_MAX,DBL_MAX,DBL_MAX),
00038 fCountCalls(0), fCountEvaluations(0)
00039 {
00040 fpMagneticField= pMagField;
00041 fDistanceConst= distance;
00042
00043
00044 this->ClearCounts();
00045 }
00046
00047 G4CachedMagneticField::~G4CachedMagneticField()
00048 {
00049 }
00050
00051 void
00052 G4CachedMagneticField::ReportStatistics()
00053 {
00054 G4cout << " Cached field: " << G4endl
00055 << " Number of calls: " << fCountCalls << G4endl
00056 << " Number of evaluations : " << fCountEvaluations << G4endl;
00057 }
00058
00059 G4CachedMagneticField::G4CachedMagneticField(const G4CachedMagneticField &rightCMF)
00060 : G4MagneticField()
00061 {
00062 fpMagneticField= rightCMF.fpMagneticField;
00063 fDistanceConst = rightCMF.fDistanceConst;
00064 fLastLocation = rightCMF.fLastLocation;
00065 fLastValue = rightCMF.fLastValue;
00066 this->ClearCounts();
00067 }
00068
00069 G4CachedMagneticField& G4CachedMagneticField::operator = (const G4CachedMagneticField &p)
00070 {
00071 if (&p == this) return *this; *this = p; return *this;
00072 }
00073
00074 void
00075 G4CachedMagneticField::GetFieldValue( const G4double Point[4],
00076 G4double *Bfield ) const
00077 {
00078 G4ThreeVector newLocation( Point[0], Point[1], Point[2] );
00079
00080
00081
00082 G4double distSq= (newLocation-fLastLocation).mag2();
00083 fCountCalls++;
00084 if( distSq < fDistanceConst*fDistanceConst ) {
00085 Bfield[0] = fLastValue.x();
00086 Bfield[1] = fLastValue.y();
00087 Bfield[2] = fLastValue.z();
00088 }else{
00089
00090 fpMagneticField->GetFieldValue( Point, Bfield );
00091
00092 fCountEvaluations++;
00093
00094 fLastLocation= G4ThreeVector( Point[0], Point[1], Point[2] );
00095
00096 fLastValue= G4ThreeVector( Bfield[0], Bfield[1], Bfield[2] );
00097 }
00098 }