G4CachedMagneticField.cc

Go to the documentation of this file.
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.cc 69786 2013-05-15 09:38:51Z gcosmo $
00028 //
00029 // --------------------------------------------------------------------
00030 
00031 #include "G4CachedMagneticField.hh"
00032 
00033 G4CachedMagneticField::G4CachedMagneticField(G4MagneticField *pMagField, 
00034                                              G4double         distance)
00035   : G4MagneticField(), 
00036     fLastLocation(DBL_MAX,DBL_MAX,DBL_MAX),
00037     fLastValue(DBL_MAX,DBL_MAX,DBL_MAX),
00038     fCountCalls(0),  fCountEvaluations(0)
00039 {
00040   fpMagneticField=     pMagField;
00041   fDistanceConst= distance;
00042 
00043   // G4cout << " Cached-B-Field constructor> Distance = " << distance << G4endl;
00044   this->ClearCounts(); 
00045 }
00046 
00047 G4CachedMagneticField::~G4CachedMagneticField()
00048 {
00049 }
00050 
00051 void
00052 G4CachedMagneticField::ReportStatistics()
00053 {
00054   G4cout << " Cached field: " << G4endl
00055          << "   Number of calls:        " << fCountCalls << G4endl
00056          << "   Number of evaluations : " << fCountEvaluations << G4endl;                     
00057 }
00058 
00059 G4CachedMagneticField::G4CachedMagneticField(const G4CachedMagneticField &rightCMF)
00060   : G4MagneticField()
00061 {
00062   fpMagneticField=      rightCMF.fpMagneticField;
00063   fDistanceConst = rightCMF.fDistanceConst;
00064   fLastLocation  = rightCMF.fLastLocation;
00065   fLastValue     = rightCMF.fLastValue;
00066   this->ClearCounts(); 
00067 }
00068 
00069 G4CachedMagneticField& G4CachedMagneticField::operator = (const G4CachedMagneticField &p)
00070 {
00071   if (&p == this) return *this; *this = p; return *this;
00072 }
00073 
00074 void
00075 G4CachedMagneticField::GetFieldValue( const G4double Point[4],
00076                                             G4double *Bfield ) const
00077 {
00078   G4ThreeVector newLocation( Point[0], Point[1], Point[2] );
00079 
00080   // G4cout << "Cache-B-field called at " << newLocation << G4endl;
00081 
00082   G4double      distSq= (newLocation-fLastLocation).mag2();
00083   fCountCalls++;
00084   if( distSq < fDistanceConst*fDistanceConst ) { 
00085      Bfield[0] = fLastValue.x();
00086      Bfield[1] = fLastValue.y();
00087      Bfield[2] = fLastValue.z();
00088   }else{
00089      // G4CachedMagneticField* thisNonC= const_cast<G4CachedMagneticField*>(this);
00090      fpMagneticField->GetFieldValue( Point, Bfield );
00091      // G4cout << " Evaluating. " << G4endl;
00092      fCountEvaluations++;
00093      // thisNonC->
00094      fLastLocation= G4ThreeVector( Point[0],  Point[1],  Point[2] );
00095      // thisNonC->
00096      fLastValue=    G4ThreeVector( Bfield[0], Bfield[1], Bfield[2] );
00097   }
00098 }

Generated on Mon May 27 17:47:48 2013 for Geant4 by  doxygen 1.4.7