19#include "FieldManager.h"
38void FieldManager::getFieldVal(
const double& posX,
const double& posY,
const double& posZ,
double& Bx,
double& By,
double& Bz){
44 static int last_read_i = 0;
45 static int last_written_i = 0;
48 static const double epsilon = 0.001;
52 static int notUsed = 0;
56 if (fabs(
cache_[i].posX - posX) < epsilon &&
57 fabs(
cache_[i].posY - posY) < epsilon &&
58 fabs(
cache_[i].posZ - posZ) < epsilon) {
64 std::cout<<
"used the cache! " <<
double(used)/(used + notUsed) <<
"\n";
69 }
while (i != last_read_i);
71 last_read_i = last_written_i = (last_written_i + 1) %
n_buckets_;
84 std::cout<<
"did NOT use the cache! \n";
90 return field_->
get(posX, posY, posZ, Bx, By, Bz);
virtual TVector3 get(const TVector3 &position) const =0
Get the magneticField [kGauss] at position.
static unsigned int n_buckets_
TVector3 getFieldVal(const TVector3 &position)
This does NOT use the cache!
static fieldCache * cache_
static FieldManager * instance_
static AbsBField * field_
void useCache(bool opt=true, unsigned int nBuckets=8)
Cache last lookup positions, and use stored field values if a lookup at (almost) the same position is...
integer, parameter double