diff --git a/MagneticField/MagFieldElements/MagFieldElements/AtlasFieldCache.h b/MagneticField/MagFieldElements/MagFieldElements/AtlasFieldCache.h index 7161f00aa43e7ba006901611d7d98baeba860185..5878c8b06909df9c91a11c89caa93b9b3854f27f 100644 --- a/MagneticField/MagFieldElements/MagFieldElements/AtlasFieldCache.h +++ b/MagneticField/MagFieldElements/MagFieldElements/AtlasFieldCache.h @@ -23,7 +23,6 @@ #include "MagFieldElements/BFieldMeshZR.h" #include "MagFieldElements/BFieldZone.h" -#include <iostream> #include <memory> namespace MagField { diff --git a/MagneticField/MagFieldElements/MagFieldElements/BFieldMeshZR.h b/MagneticField/MagFieldElements/MagFieldElements/BFieldMeshZR.h index b79841a62b3f3f510298d69a0adad48ab901afb4..1d78885d5312afeb2396a2459d0a2ed4a72d4980 100644 --- a/MagneticField/MagFieldElements/MagFieldElements/BFieldMeshZR.h +++ b/MagneticField/MagFieldElements/MagFieldElements/BFieldMeshZR.h @@ -2,73 +2,63 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -// -// BFieldMeshZR.h -// -// A 2-dim z-r mesh inside the solenoid field map -// -// Masahiro Morii, Harvard University -// +/* + * BFieldMeshZR.h + * + * A 2-dim z-r mesh inside the solenoid field map + * + * Masahiro Morii, Harvard University + * + * AthenaMT : RD Schaffer , Christos Anastopoulos + */ #ifndef BFIELDMESHZR_H #define BFIELDMESHZR_H #include "MagFieldElements/BFieldCacheZR.h" #include "MagFieldElements/BFieldVectorZR.h" +#include <array> #include <cmath> #include <vector> -#include <array> class BFieldMeshZR { public: // constructor - BFieldMeshZR(double zmin, double zmax, double rmin, double rmax) - { - m_min = { zmin, rmin }; - m_max = { zmax, rmax }; - } + BFieldMeshZR(double zmin, double zmax, double rmin, double rmax); // allocate space to vectors - void reserve(int nz, int nr) - { - m_mesh[0].reserve(nz); - m_mesh[1].reserve(nr); - m_field.reserve(nz * nr); - } + void reserve(int nz, int nr); // add elements to vectors - void appendMesh(int i, double mesh) { m_mesh[i].push_back(mesh); } - void appendField(const BFieldVectorZR& field) { m_field.push_back(field); } + void appendMesh(int i, double mesh); + void appendField(const BFieldVectorZR& field); // build LUT void buildLUT(); // test if a point is inside this zone - inline bool inside(double z, double r) const - { - return (z >= zmin() && z <= zmax() && r >= rmin() && r <= rmax()); - } + bool inside(double z, double r) const; // find the bin inline void getCache(double z, double r, BFieldCacheZR& cache, double scaleFactor = 1.0) const; // accessors - double min(size_t i) const { return m_min[i]; } - double max(size_t i) const { return m_max[i]; } - double zmin() const { return m_min[0]; } - double zmax() const { return m_max[0]; } - double rmin() const { return m_min[1]; } - double rmax() const { return m_max[1]; } - unsigned nmesh(size_t i) const { return m_mesh[i].size(); } - double mesh(size_t i, size_t j) const { return m_mesh[i][j]; } - unsigned nfield() const { return m_field.size(); } - const BFieldVectorZR& field(size_t i) const { return m_field[i]; } + double min(size_t i) const; + double max(size_t i) const; + double zmin() const; + double zmax() const; + double rmin() const; + double rmax() const; + unsigned nmesh(size_t i) const; + double mesh(size_t i, size_t j) const; + unsigned nfield() const; + const BFieldVectorZR& field(size_t i) const; int memSize() const; private: - std::array<double,2> m_min; - std::array<double,2> m_max; - std::array<std::vector<double>,2> m_mesh; + std::array<double, 2> m_min; + std::array<double, 2> m_max; + std::array<std::vector<double>, 2> m_mesh; std::vector<BFieldVectorZR> m_field; // look-up table and related variables - std::array<std::vector<int>,2> m_LUT; + std::array<std::vector<int>, 2> m_LUT; std::array<double, 2> m_invUnit; // inverse unit size in the LUT int m_zoff; }; diff --git a/MagneticField/MagFieldElements/MagFieldElements/BFieldMeshZR.icc b/MagneticField/MagFieldElements/MagFieldElements/BFieldMeshZR.icc index 781dbf7dc885eef916b3f8c87d55c4da9b8d454e..1b76cf8b1dee79300de6ca089fd736c41efe4b60 100644 --- a/MagneticField/MagFieldElements/MagFieldElements/BFieldMeshZR.icc +++ b/MagneticField/MagFieldElements/MagFieldElements/BFieldMeshZR.icc @@ -36,3 +36,89 @@ BFieldMeshZR::getCache(double z, cache.setField(3, m_field[im0 + m_zoff + 1], scaleFactor); } +inline BFieldMeshZR::BFieldMeshZR(double zmin, + double zmax, + double rmin, + double rmax) +{ + m_min = { zmin, rmin }; + m_max = { zmax, rmax }; +} + +inline void +BFieldMeshZR::reserve(int nz, int nr) +{ + m_mesh[0].reserve(nz); + m_mesh[1].reserve(nr); + m_field.reserve(nz * nr); +} +// add elements to vectors +inline void +BFieldMeshZR::appendMesh(int i, double mesh) +{ + m_mesh[i].push_back(mesh); +} +inline void +BFieldMeshZR::appendField(const BFieldVectorZR& field) +{ + m_field.push_back(field); +} + +// test if a point is inside this zone +inline bool +BFieldMeshZR::inside(double z, double r) const +{ + return (z >= zmin() && z <= zmax() && r >= rmin() && r <= rmax()); +} + +inline double +BFieldMeshZR::min(size_t i) const +{ + return m_min[i]; +} +inline double +BFieldMeshZR::max(size_t i) const +{ + return m_max[i]; +} +inline double +BFieldMeshZR::zmin() const +{ + return m_min[0]; +} +inline double +BFieldMeshZR::zmax() const +{ + return m_max[0]; +} +inline double +BFieldMeshZR::rmin() const +{ + return m_min[1]; +} +inline double +BFieldMeshZR::rmax() const +{ + return m_max[1]; +} +inline unsigned +BFieldMeshZR::nmesh(size_t i) const +{ + return m_mesh[i].size(); +} +inline double +BFieldMeshZR::mesh(size_t i, size_t j) const +{ + return m_mesh[i][j]; +} +inline unsigned +BFieldMeshZR::nfield() const +{ + return m_field.size(); +} +inline const BFieldVectorZR& +BFieldMeshZR::field(size_t i) const +{ + return m_field[i]; +} + diff --git a/MagneticField/MagFieldElements/MagFieldElements/BFieldZone.h b/MagneticField/MagFieldElements/MagFieldElements/BFieldZone.h index 57fbb3ea62338aefee086f46ac501fa3e69da6ee..888e3f8d059a56fdba94c138a94b79fced504544 100644 --- a/MagneticField/MagFieldElements/MagFieldElements/BFieldZone.h +++ b/MagneticField/MagFieldElements/MagFieldElements/BFieldZone.h @@ -29,12 +29,7 @@ public: double rmax, double phimin, double phimax, - double scale) - : BFieldMesh<short>(zmin, zmax, rmin, rmax, phimin, phimax, scale) - , m_id(id) - { - ; - } + double scale); // add elements to vectors void appendCond(const BFieldCond& cond); // compute Biot-Savart magnetic field and add to B[3] @@ -45,10 +40,10 @@ public: // Scaling is done in cachec void scaleField(double factor); // accessors - int id() const { return m_id; } - unsigned ncond() const { return m_cond.size(); } - const BFieldCond& cond(int i) const { return m_cond[i]; } - const std::vector<BFieldCond>* condVector() const { return &m_cond; } + int id() const; + unsigned ncond() const; + const BFieldCond& cond(int i) const; + const std::vector<BFieldCond>* condVector() const; int memSize() const; // adjust the min/max edges to a new value void adjustMin(int i, double x); diff --git a/MagneticField/MagFieldElements/MagFieldElements/BFieldZone.icc b/MagneticField/MagFieldElements/MagFieldElements/BFieldZone.icc index 071400e3729dfef1ee7ac92c3d500d1653f4fa56..ddb5022730ae8913d9cdcbe186f528d46e80aa14 100644 --- a/MagneticField/MagFieldElements/MagFieldElements/BFieldZone.icc +++ b/MagneticField/MagFieldElements/MagFieldElements/BFieldZone.icc @@ -1,6 +1,19 @@ /* Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ + +inline BFieldZone::BFieldZone(int id, + double zmin, + double zmax, + double rmin, + double rmax, + double phimin, + double phimax, + double scale) + : BFieldMesh<short>(zmin, zmax, rmin, rmax, phimin, phimax, scale) + , m_id(id) +{} + inline void BFieldZone::appendCond(const BFieldCond& cond) { @@ -26,6 +39,30 @@ BFieldZone::addBiotSavart(const double* ATH_RESTRICT xyz, } } +inline int +BFieldZone::id() const +{ + return m_id; +} + +inline unsigned +BFieldZone::ncond() const +{ + return m_cond.size(); +} + +inline const BFieldCond& +BFieldZone::cond(int i) const +{ + return m_cond[i]; +} + +inline const std::vector<BFieldCond>* +BFieldZone::condVector() const +{ + return &m_cond; +} + inline int BFieldZone::memSize() const { diff --git a/MagneticField/MagFieldElements/src/AtlasFieldCache.cxx b/MagneticField/MagFieldElements/src/AtlasFieldCache.cxx index a3927c4553d7ae0b388b047d33bfab7aad991839..d9e66122f27f8f1197470b4413577fbe188586f3 100644 --- a/MagneticField/MagFieldElements/src/AtlasFieldCache.cxx +++ b/MagneticField/MagFieldElements/src/AtlasFieldCache.cxx @@ -11,6 +11,9 @@ // #include "MagFieldElements/AtlasFieldCache.h" +#include <cmath> +#include <iostream> + void MagField::AtlasFieldCache::getField(const double* ATH_RESTRICT xyz, double* ATH_RESTRICT bxyz, @@ -89,7 +92,7 @@ MagField::AtlasFieldCache::getFieldZR(const double* ATH_RESTRICT xyz, const double x = xyz[0]; const double y = xyz[1]; const double z = xyz[2]; - const double r = sqrt(x * x + y * y); + const double r = std::sqrt(x * x + y * y); // test if the cache was initialized and the ZR cache is valid for current // position diff --git a/MagneticField/MagFieldElements/src/AtlasFieldMap.cxx b/MagneticField/MagFieldElements/src/AtlasFieldMap.cxx index 1956e5f35d9b4311074d600f804fad890b729498..d1f928528cd028487eaf0df143f9039f55ee1b4b 100644 --- a/MagneticField/MagFieldElements/src/AtlasFieldMap.cxx +++ b/MagneticField/MagFieldElements/src/AtlasFieldMap.cxx @@ -89,46 +89,30 @@ MagField::AtlasFieldMap::initializeMap(TFile* rootfile, // } int id; double zmin; - double zmax; - double rmin; - double rmax; - double phimin; - double phimax; double bscale; int ncond; bool* finite; double* p1x; - double* p1y; - double* p1z; - double* p2x; - double* p2y; - double* p2z; double* curr; int nmeshz; - int nmeshr; - int nmeshphi; double* meshz; - double* meshr; - double* meshphi; int nfield; short* fieldz; - short* fieldr; - short* fieldphi; // define the fixed-sized branches first tree->SetBranchAddress("id", &id);