00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $ Id: G4CachedMagneticField.hh,v 1.0 2009/07/20 18:53:00 japost Exp $ 00028 // GEANT4 tag $Name: not supported by cvs2svn $ 00029 // 00030 // 00031 // class G4CachedMagneticField 00032 // 00033 // Class description: 00034 // 00035 // Caches Magnetic Field value, for field whose evaluation is expensive. 00036 00037 // History: 00038 // - Created. JA, July 20th, 2009. 00039 // -------------------------------------------------------------------- 00040 00041 #ifndef G4CACHED_MAGNETIC_FIELD_DEF 00042 #define G4CACHED_MAGNETIC_FIELD_DEF 00043 00044 #include "G4Types.hh" 00045 #include "G4ThreeVector.hh" 00046 #include "G4MagneticField.hh" 00047 00048 class G4CachedMagneticField : public G4MagneticField 00049 { 00050 public: // with description 00051 00052 G4CachedMagneticField(G4MagneticField *, G4double distanceConst); 00053 virtual ~G4CachedMagneticField(); 00054 // Constructor and destructor. No actions. 00055 00056 G4CachedMagneticField(const G4CachedMagneticField &r); 00057 G4CachedMagneticField& operator = (const G4CachedMagneticField &p); 00058 // Copy constructor & assignment operator. 00059 00060 virtual void GetFieldValue( const G4double Point[4], 00061 G4double *Bfield ) const; 00062 00063 G4double GetConstDistance() const { return fDistanceConst; } 00064 void SetConstDistance( G4double dist ){ fDistanceConst= dist;} 00065 00066 G4int GetCountCalls() const { return fCountCalls; } 00067 G4int GetCountEvaluations() const { return fCountEvaluations; } 00068 void ClearCounts() { fCountCalls = 0; fCountEvaluations=0; } 00069 void ReportStatistics(); 00070 00071 private: 00072 G4MagneticField *fpMagneticField; 00073 // When the field is evaluated within this distance it will not change 00074 G4double fDistanceConst; 00075 // Caching state 00076 mutable G4ThreeVector fLastLocation; 00077 mutable G4ThreeVector fLastValue; 00078 00079 protected: 00080 mutable G4int fCountCalls, fCountEvaluations; 00081 }; 00082 00083 #endif /* G4CACHED_MAGNETIC_FIELD_DEF */