Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: G4CachedMagneticField.cc 69786 2013-05-15 09:38:51Z gcosmo $
28 //
29 // --------------------------------------------------------------------
30 
31 #include "G4CachedMagneticField.hh"
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 
51 void
53 {
54  G4cout << " Cached field: " << G4endl
55  << " Number of calls: " << fCountCalls << G4endl
56  << " Number of evaluations : " << fCountEvaluations << G4endl;
57 }
58 
60  : G4MagneticField()
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 
74 void
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();
83  fCountCalls++;
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 }