Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:14

0001 #ifndef Geom_Cylinder_H
0002 #define Geom_Cylinder_H
0003 
0004 /** \class Cylinder
0005  *
0006  *  A Cylinder.
0007  *
0008  *  \warning Surfaces are reference counted, so only ReferenceCountingPointer
0009  *  should be used to point to them. For this reason, they should be 
0010  *  using the static build() methods. 
0011  *  (The normal constructor will become private in the future).
0012  *
0013  */
0014 
0015 #include "DataFormats/GeometrySurface/interface/Surface.h"
0016 #include "DataFormats/GeometrySurface/interface/Plane.h"
0017 #include "DataFormats/GeometrySurface/interface/SimpleCylinderBounds.h"
0018 
0019 class Cylinder final : public Surface {
0020 public:
0021   template <typename... Args>
0022   Cylinder(Scalar radius, Args&&... args) : Surface(std::forward<Args>(args)...), theRadius(radius) {}
0023 
0024   Cylinder(const PositionType& pos, const RotationType& rot, SimpleCylinderBounds const& bounds)
0025       : Surface(pos, rot, bounds.clone()), theRadius(computeRadius(bounds)) {}
0026 
0027   // average Rmin Rmax...
0028   static float computeRadius(Bounds const& bounds) { return 0.5f * (bounds.width() - bounds.thickness()); }
0029 
0030   typedef ReferenceCountingPointer<Cylinder> CylinderPointer;
0031   typedef ConstReferenceCountingPointer<Cylinder> ConstCylinderPointer;
0032   typedef ReferenceCountingPointer<Cylinder> BoundCylinderPointer;
0033   typedef ConstReferenceCountingPointer<Cylinder> ConstBoundCylinderPointer;
0034 
0035   /// Construct a cylinder with the specified radius.
0036   /// The reference frame is defined by pos and rot;
0037   /// the cylinder axis is parallel to the local Z axis.
0038   /*
0039   template<typename... Args>
0040   static CylinderPointer build(Args&& ... args) {
0041     return CylinderPointer(new Cylinder(std::forward<Args>(args)...));
0042   }
0043   */
0044 
0045   static CylinderPointer build(const PositionType& pos,
0046                                const RotationType& rot,
0047                                Scalar radius,
0048                                Bounds* bounds = nullptr) {
0049     return CylinderPointer(new Cylinder(radius, pos, rot, bounds));
0050   }
0051 
0052   static CylinderPointer build(Scalar radius,
0053                                const PositionType& pos,
0054                                const RotationType& rot,
0055                                Bounds* bounds = nullptr) {
0056     return CylinderPointer(new Cylinder(radius, pos, rot, bounds));
0057   }
0058 
0059   ~Cylinder() override {}
0060 
0061   // -- Extension of Surface interface for cylinder
0062 
0063   /// Radius of the cylinder
0064   Scalar radius() const { return theRadius; }
0065 
0066   // -- Implementation of Surface interface
0067 
0068   using Surface::side;
0069   Side side(const LocalPoint& p, Scalar toler) const override;
0070 
0071   /// tangent plane to surface from global point
0072   ConstReferenceCountingPointer<TangentPlane> tangentPlane(const GlobalPoint&) const override;
0073   /// tangent plane to surface from local point
0074   ConstReferenceCountingPointer<TangentPlane> tangentPlane(const LocalPoint&) const override;
0075 
0076   /// tangent plane to surface from global point
0077   Plane fastTangent(const GlobalPoint& aPoint) const {
0078     GlobalVector yPlane(rotation().z());
0079     GlobalVector xPlane(yPlane.cross(aPoint - position()));
0080     return Plane(aPoint, RotationType(xPlane, yPlane));
0081   }
0082 
0083   /// tangent plane to surface from local point
0084   Plane fastTangent(const LocalPoint& aPoint) const { return fastTangent(toGlobal(aPoint)); }
0085 
0086 private:
0087   Scalar theRadius;
0088 };
0089 
0090 #endif