27 std::atomic<int> instanceCounter(0);
28 thread_local
int localInstance = 0;
29 thread_local
MagVolume const* lastVolume =
nullptr;
33 const std::vector<MagBLayer*>& tbl,
34 const std::vector<MagESector*>& tes,
35 const std::vector<MagVolume6Faces*>& tbv,
36 const std::vector<MagVolume6Faces*>& tev)
44 const std::vector<MagBLayer const*>& tbl,
45 const std::vector<MagESector const*>& tes,
46 const std::vector<MagVolume6Faces const*>& tbv,
47 const std::vector<MagVolume6Faces const*>& tev)
48 : me_(++instanceCounter),
53 cacheLastVolume(
true),
54 geometryVersion(geomVersion) {
55 vector<double> rBorders;
57 for (vector<MagBLayer const*>::const_iterator ilay =
theBLayers.begin(); ilay !=
theBLayers.end(); ++ilay) {
58 LogTrace(
"MagGeoBuilder") <<
" Barrel layer at " << (*ilay)->minR() << endl;
60 rBorders.push_back((*ilay)->minR() * (*ilay)->minR());
66 for (vector<MagESector const*>::const_iterator isec =
theESectors.begin(); isec !=
theESectors.end(); ++isec) {
67 LogTrace(
"MagGeoBuilder") <<
" Endcap sector at " << (*isec)->minPhi() << endl;
79 switch (geomVersion >= 120812 ? 0 : (geomVersion >= 90812 ? 1 : 2)) {
103 LogTrace(
"MagGeometry_cache") <<
"*** In MagGeometry ctor: me_=" <<
me_ <<
" instanceCounter=" << instanceCounter
113 for (vector<MagBLayer const*>::const_iterator ilay =
theBLayers.begin(); ilay !=
theBLayers.end(); ++ilay) {
117 for (vector<MagESector const*>::const_iterator ilay =
theESectors.begin(); ilay !=
theESectors.end(); ++ilay) {
134 LogWarning(
"MagneticField") <<
"Input value invalid (not a number): " << gp << endl;
137 LogWarning(
"MagneticField") <<
"MagGeometry::fieldInTesla: failed to find volume for " << gp << endl;
149 if ((*
v) ==
nullptr) {
150 LogError(
"MagGeometry") << endl <<
"***ERROR: MagGeometry::findVolume: MagVolume for barrel not set" << endl;
157 if ((*v)->inside(gp, tolerance)) {
165 if ((*
v) ==
nullptr) {
166 LogError(
"MagGeometry") << endl <<
"***ERROR: MagGeometry::findVolume: MagVolume for endcap not set" << endl;
173 if ((*v)->inside(gp, tolerance)) {
186 if (
me_ != localInstance) {
187 LogTrace(
"MagGeometry_cache") <<
"*** In MagGeometry::findVolume resetting cache: me=" <<
me_
188 <<
" localInstance=" << localInstance << endl;
190 lastVolume =
nullptr;
193 if (lastVolume !=
nullptr && lastVolume->inside(gp)) {
199 double aRsq = gp.
perp2();
203 for (
int bin1 = bin; bin1 >=
max(0, bin - 3); --bin1) {
205 result =
theBLayers[bin1]->findVolume(gp, tolerance);
206 LogTrace(
"MagGeometry") <<
"***In blayer " << bin1 - bin <<
" " << (result ==
nullptr ?
" failed " :
" OK ")
208 if (result !=
nullptr)
216 LogTrace(
"MagGeometry") <<
"Trying endcap sector at phi " <<
theESectors[
bin]->minPhi() <<
" " << phi << endl;
218 LogTrace(
"MagGeometry") <<
"***In guessed esector " << (result ==
nullptr ?
" failed " :
" OK ") << endl;
223 if (result ==
nullptr && tolerance < 0.0001) {
227 LogTrace(
"MagGeometry") <<
"Increasing the tolerance to 0.03" << endl;
238 double aZ = fabs(gp.
z());
239 double aRsq = gp.
perp2();
Surface::GlobalVector GlobalVector
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
constexpr bool isNotFinite(T x)
Geom::Phi< T > phi() const
~MagGeometry()
Destructor.
Log< level::Error, false > LogError
bool inBarrel(const GlobalPoint &gp) const
MagVolume const * findVolume(const GlobalPoint &gp, double tolerance=0.) const
Find a volume.
std::vector< MagESector const * > theESectors
PeriodicBinFinderInPhi< float > const * theEndcapBinFinder
MagVolume const * findVolume1(const GlobalPoint &gp, double tolerance=0.) const
std::vector< MagBLayer const * > theBLayers
std::vector< MagVolume6Faces const * > theBVolumes
LocalVector fieldInTesla(const LocalPoint &lp) const
GlobalVector fieldInTesla(const GlobalPoint &gp) const
Return field vector at the specified global point.
MagGeometry(int geomVersion, const std::vector< MagBLayer * > &, const std::vector< MagESector * > &, const std::vector< MagVolume6Faces * > &, const std::vector< MagVolume6Faces * > &)
Constructor.
std::vector< MagVolume6Faces const * > theEVolumes
Log< level::Warning, false > LogWarning
int binIndex(T R) const override
MagBinFinders::GeneralBinFinderInR< double > const * theBarrelBinFinder