Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CachedMagneticField.cc
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//
27// $Id$
28//
29// --------------------------------------------------------------------
30
32
34 G4double distance)
35 : G4MagneticField(),
36 fLastLocation(DBL_MAX,DBL_MAX,DBL_MAX),
37 fLastValue(DBL_MAX,DBL_MAX,DBL_MAX),
38 fCountCalls(0), fCountEvaluations(0)
39{
40 fpMagneticField= pMagField;
41 fDistanceConst= distance;
42
43 // G4cout << " Cached-B-Field constructor> Distance = " << distance << G4endl;
44 this->ClearCounts();
45}
46
48{
49}
50
51void
53{
54 G4cout << " Cached field: " << G4endl
55 << " Number of calls: " << fCountCalls << G4endl
56 << " Number of evaluations : " << fCountEvaluations << G4endl;
57}
58
61{
62 fpMagneticField= rightCMF.fpMagneticField;
63 fDistanceConst = rightCMF.fDistanceConst;
64 fLastLocation = rightCMF.fLastLocation;
65 fLastValue = rightCMF.fLastValue;
66 this->ClearCounts();
67}
68
70{
71 if (&p == this) return *this; *this = p; return *this;
72}
73
74void
76 G4double *Bfield ) const
77{
78 G4ThreeVector newLocation( Point[0], Point[1], Point[2] );
79
80 // G4cout << "Cache-B-field called at " << newLocation << G4endl;
81
82 G4double distSq= (newLocation-fLastLocation).mag2();
84 if( distSq < fDistanceConst*fDistanceConst ) {
85 Bfield[0] = fLastValue.x();
86 Bfield[1] = fLastValue.y();
87 Bfield[2] = fLastValue.z();
88 }else{
89 // G4CachedMagneticField* thisNonC= const_cast<G4CachedMagneticField*>(this);
90 fpMagneticField->GetFieldValue( Point, Bfield );
91 // G4cout << " Evaluating. " << G4endl;
93 // thisNonC->
94 fLastLocation= G4ThreeVector( Point[0], Point[1], Point[2] );
95 // thisNonC->
96 fLastValue= G4ThreeVector( Bfield[0], Bfield[1], Bfield[2] );
97 }
98}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:64
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
double z() const
double x() const
double y() const
virtual void GetFieldValue(const G4double Point[4], G4double *Bfield) const
G4CachedMagneticField(G4MagneticField *, G4double distanceConst)
G4CachedMagneticField & operator=(const G4CachedMagneticField &p)
virtual void GetFieldValue(const G4double Point[4], G4double *Bfield) const =0
#define DBL_MAX
Definition: templates.hh:83