File indexing completed on 2024-04-06 12:22:35
0001 #include "MagneticField/VolumeGeometry/interface/MagCylinder.h"
0002 #include "MagneticField/VolumeGeometry/interface/MagExceptions.h"
0003 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
0004
0005 MagCylinder::MagCylinder(const PositionType& pos,
0006 const RotationType& rot,
0007 const std::vector<VolumeSide>& faces,
0008 const MagneticFieldProvider<float>* mfp)
0009 : MagVolume(pos, rot, mfp), theFaces(faces), theZmin(0.), theZmax(0.), theInnerR(0.), theOuterR(0.) {
0010 using SurfaceOrientation::GlobalFace;
0011
0012 unsigned int def = 0;
0013 for (std::vector<VolumeSide>::const_iterator i = faces.begin(); i != faces.end(); ++i) {
0014 if (i->globalFace() == SurfaceOrientation::zminus) {
0015 theZmin = MagVolume::toLocal(i->surface().position()).z();
0016 ++def;
0017 } else if (i->globalFace() == SurfaceOrientation::zplus) {
0018 theZmax = MagVolume::toLocal(i->surface().position()).z();
0019 ++def;
0020 } else if (i->globalFace() == SurfaceOrientation::outer || i->globalFace() == SurfaceOrientation::inner) {
0021 const Cylinder* cyl = dynamic_cast<const Cylinder*>(&(i->surface()));
0022 if (cyl == nullptr) {
0023 throw MagGeometryError("MagCylinder inner/outer surface is not a cylinder");
0024 }
0025 if (i->globalFace() == SurfaceOrientation::outer)
0026 theOuterR = cyl->radius();
0027 else
0028 theInnerR = cyl->radius();
0029 ++def;
0030 }
0031 }
0032 if (def != faces.size()) {
0033 throw MagGeometryError("MagCylinder constructed with wrong number/type of faces");
0034 }
0035 setNominalValue();
0036 }
0037
0038 bool MagCylinder::inside(const GlobalPoint& gp, double tolerance) const { return inside(toLocal(gp), tolerance); }
0039
0040 bool MagCylinder::inside(const LocalPoint& lp, double tolerance) const {
0041 Scalar r(lp.perp());
0042 return lp.z() > theZmin - tolerance && lp.z() < theZmax + tolerance && r > theInnerR - tolerance &&
0043 r < theOuterR + tolerance;
0044 }