source: trunk/source/geometry/magneticfield/src/G4CachedMagneticField.cc @ 1274

Last change on this file since 1274 was 1274, checked in by garnier, 14 years ago

update...

File size: 3.9 KB
Line 
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,v 1.1 2009/11/05 11:06:13 japost Exp $
28// GEANT4 tag $Name:  $
29//
30// --------------------------------------------------------------------
31
32#include "G4CachedMagneticField.hh"
33
34G4CachedMagneticField::G4CachedMagneticField(G4MagneticField *pMagField, 
35                                             G4double         distance)
36  : G4MagneticField(), 
37    fLastLocation(DBL_MAX,DBL_MAX,DBL_MAX),
38    fLastValue(DBL_MAX,DBL_MAX,DBL_MAX),
39    fCountCalls(0),  fCountEvaluations(0)
40{
41  fpMagneticField=     pMagField;
42  fDistanceConst= distance;
43
44  // G4cout << " Cached-B-Field constructor> Distance = " << distance << G4endl;
45  this->ClearCounts(); 
46}
47
48G4CachedMagneticField::~G4CachedMagneticField()
49{
50}
51
52void
53G4CachedMagneticField::ReportStatistics()
54{
55  G4cout << " Cached field: " << this << G4endl
56         << "   Number of calls:        " << fCountCalls << G4endl
57         << "   Number of evaluations : " << fCountEvaluations << G4endl;                     
58}
59
60G4CachedMagneticField::G4CachedMagneticField(const G4CachedMagneticField &rightCMF)
61  : G4MagneticField()
62{
63  fpMagneticField=      rightCMF.fpMagneticField;
64  fDistanceConst = rightCMF.fDistanceConst;
65  fLastLocation  = rightCMF.fLastLocation;
66  fLastValue     = rightCMF.fLastValue;
67  this->ClearCounts(); 
68}
69
70G4CachedMagneticField& G4CachedMagneticField::operator = (const G4CachedMagneticField &p)
71{
72  if (&p == this) return *this; *this = p; return *this;
73}
74
75void
76G4CachedMagneticField::GetFieldValue( const G4double Point[4],
77                                            G4double *Bfield ) const
78{
79  G4ThreeVector newLocation( Point[0], Point[1], Point[2] );
80
81  // G4cout << "Cache-B-field called at " << newLocation << G4endl;
82
83  G4double      distSq= (newLocation-fLastLocation).mag2();
84  fCountCalls++;
85  if( distSq < fDistanceConst*fDistanceConst ) { 
86     Bfield[0] = fLastValue.x();
87     Bfield[1] = fLastValue.y();
88     Bfield[2] = fLastValue.z();
89  }else{
90     // G4CachedMagneticField* thisNonC= const_cast<G4CachedMagneticField*>(this);
91     fpMagneticField->GetFieldValue( Point, Bfield );
92     // G4cout << " Evaluating. " << G4endl;
93     fCountEvaluations++;
94     // thisNonC->
95     fLastLocation= G4ThreeVector( Point[0],  Point[1],  Point[2] );
96     // thisNonC->
97     fLastValue=    G4ThreeVector( Bfield[0], Bfield[1], Bfield[2] );
98  }
99}
Note: See TracBrowser for help on using the repository browser.