Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4CachedMagneticField.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
16#include "TG4G3Units.h"
17#include "TG4Globals.h"
18
19#include <TVirtualMC.h>
20#include <TVirtualMCApplication.h>
21
22//_____________________________________________________________________________
24 TVirtualMagField* magField, G4double constDistance)
25 : TG4MagneticField(magField),
26 fLastLocation(),
27 fLastValue(),
28 fCallsCounter(0),
29 fEvaluationsCounter(0),
30 fConstDistanceSquare(constDistance * constDistance)
31{
33}
34
35//_____________________________________________________________________________
40
41//
42// public methods
43//
44
45//_____________________________________________________________________________
47 const G4double point[3], G4double* bfield) const
48{
50
51 G4ThreeVector newLocation(point[0], point[1], point[2]);
52 G4double distSq = (newLocation - fLastLocation).mag2();
54
55 // Use cached value if within the constant distance
56 if (distSq < fConstDistanceSquare) {
57 bfield[0] = fLastValue.x();
58 bfield[1] = fLastValue.y();
59 bfield[2] = fLastValue.z();
60 return;
61 }
62
63 // New evaluation
64 // Set units
65 const G4double g3point[3] = { point[0] * TG4G3Units::InverseLength(),
66 point[1] * TG4G3Units::InverseLength(), point[2] * TG4G3Units::InverseLength() };
67
68 // Call user field
69 fVirtualMagField->Field(g3point, bfield);
70
71 // Set units
72 for (G4int i = 0; i < 3; i++) bfield[i] = bfield[i] * TG4G3Units::Field();
73
74 // Update counter and cache new values
76 fLastLocation = newLocation;
77 fLastValue = G4ThreeVector(bfield[0], bfield[1], bfield[2]);
78}
79
80// //_____________________________________________________________________________
81// void TG4CachedMagneticField::Update(const TG4FieldParameters& parameters)
82// {
83// /// Update field with new field parameters
84
85// // Update parameters in base class
86// // TG4MagneticField::Update(parameters);
87
88// // Const distance square
89// fConstDistanceSquare
90// = parameters.GetConstDistance()*parameters.GetConstDistance();
91// }
92
93//_____________________________________________________________________________
95{
98 G4cout << "TG4CachedMagneticField: " << G4endl
99 << " Number of calls: " << fCallsCounter << G4endl
100 << " Number of evaluations : " << fEvaluationsCounter << G4endl;
101 }
102}
103
104//_____________________________________________________________________________
106{
108 fConstDistanceSquare = value * value;
109}
110
111//_____________________________________________________________________________
Definition of the TG4CachedMagneticField class.
Definition of the TG4G3Units class.
Definition of the TG4Globals class and basic container types.
virtual void PrintStatistics() const
G4ThreeVector fLastValue
The last evaluated value.
G4int fEvaluationsCounter
The counter of field value evaluations in GetFieldValue()
void SetConstDistance(G4double value)
virtual void GetFieldValue(const G4double point[3], G4double *bfield) const
G4double fConstDistanceSquare
The square of the distance within which the field is considered constant.
G4int fCallsCounter
The counter of calls to GetFieldValue()
G4ThreeVector fLastLocation
The last evaluated location.
TG4CachedMagneticField(TVirtualMagField *magField, G4double constDistance)
static G4double Field()
Definition TG4G3Units.h:129
static G4double InverseLength()
Definition TG4G3Units.h:135
The magnetic field defined via TVirtualMagField.
TVirtualMagField * fVirtualMagField
The associated TGeo magnetic field.