Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-27 08:49:44

0001 // This file is part of VecGeom and is distributed under the
0002 // conditions in the file LICENSE.txt in the top directory.
0003 // For the full list of authors see CONTRIBUTORS.txt and `git log`.
0004 
0005 /// Declaration of the unplaced parallelepiped shape.
0006 /// @file volumes/UnplacedParallelepiped.h
0007 /// @author: Johannes de Fine Licht, Mihaela Gheata
0008 
0009 #ifndef VECGEOM_VOLUMES_UNPLACEDPARALLELEPIPED_H_
0010 #define VECGEOM_VOLUMES_UNPLACEDPARALLELEPIPED_H_
0011 
0012 #include "VecGeom/base/Cuda.h"
0013 #include "VecGeom/base/AlignedBase.h"
0014 #include "VecGeom/base/Vector3D.h"
0015 #include "VecGeom/volumes/UnplacedVolume.h"
0016 #include "ParallelepipedStruct.h"
0017 #include "VecGeom/volumes/kernel/ParallelepipedImplementation.h"
0018 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0019 
0020 namespace vecgeom {
0021 
0022 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedParallelepiped;);
0023 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedParallelepiped);
0024 
0025 inline namespace VECGEOM_IMPL_NAMESPACE {
0026 
0027 /// Class for parallelepiped shape primitive.
0028 ///
0029 /// Parallepiped is a `skewed' box with half lengths dx, dy, dz.
0030 /// Angles theta & phi are the polar and azimuthal angles of the line
0031 /// joining centres of the faces at +/- dz.
0032 /// Angle alpha is formed by the y-axis and the line joining
0033 /// centres of the faces at +/- dy.
0034 
0035 class UnplacedParallelepiped : public UnplacedVolumeImplHelper<ParallelepipedImplementation>, public AlignedBase {
0036 
0037 private:
0038   ParallelepipedStruct<Precision> fPara; ///< The parallelepiped structure
0039 
0040 public:
0041   using Kernel = ParallelepipedImplementation;
0042 
0043   /// Constructor from a vector of dimensions and three angles
0044   /// @param dim 3D vector with dx, dy, dz
0045   /// @param alpha Angle between y-axis and the line joining centres of the faces at +/- dy
0046   /// @param theta Polar angle
0047   /// @param phi Azimuthal angle
0048   VECCORE_ATT_HOST_DEVICE
0049   UnplacedParallelepiped(Vector3D<Precision> const &dimensions, const Precision alpha, const Precision theta,
0050                          const Precision phi)
0051       : fPara(dimensions, alpha, theta, phi)
0052   {
0053     fGlobalConvexity = true;
0054     ComputeBBox();
0055   }
0056 
0057   /// Constructor from three dimensions and three angles
0058   /// @param dx Half length in x
0059   /// @param dy Half length in y
0060   /// @param dz Half length in z
0061   /// @param alpha Angle between y-axis and the line joining centres of the faces at +/- dy
0062   /// @param theta Polar angle
0063   /// @param phi Azimuthal angle
0064   VECCORE_ATT_HOST_DEVICE
0065   UnplacedParallelepiped(const Precision dx, const Precision dy, const Precision dz, const Precision alpha,
0066                          const Precision theta, const Precision phi)
0067       : fPara(dx, dy, dz, alpha, theta, phi)
0068   {
0069     fGlobalConvexity = true;
0070     ComputeBBox();
0071   }
0072 
0073   /// Default constructor
0074   VECCORE_ATT_HOST_DEVICE
0075   UnplacedParallelepiped() : fPara(0., 0., 0., 0., 0., 0.) { fGlobalConvexity = true; }
0076 
0077   VECCORE_ATT_HOST_DEVICE
0078   VECGEOM_FORCE_INLINE
0079   virtual ESolidType GetType() const override { return ESolidType::parallelepiped; }
0080 
0081   /// Getter for the structure storing parallepiped data.
0082   VECCORE_ATT_HOST_DEVICE
0083   ParallelepipedStruct<Precision> const &GetStruct() const { return fPara; }
0084 
0085   /// Getter for parallelepiped dimensions
0086   VECCORE_ATT_HOST_DEVICE
0087   Vector3D<Precision> const &GetDimensions() const { return fPara.fDimensions; }
0088 
0089   /// Getter for parallelepiped normals
0090   VECCORE_ATT_HOST_DEVICE
0091   Vector3D<Precision> const &GetNormal(int i) const { return fPara.fNormals[i]; }
0092 
0093   /// Getter for dx
0094   VECCORE_ATT_HOST_DEVICE
0095   Precision GetX() const { return fPara.fDimensions[0]; }
0096 
0097   /// Getter for dy
0098   VECCORE_ATT_HOST_DEVICE
0099   Precision GetY() const { return fPara.fDimensions[1]; }
0100 
0101   /// Getter for dz
0102   VECCORE_ATT_HOST_DEVICE
0103   Precision GetZ() const { return fPara.fDimensions[2]; }
0104 
0105   /// Getter for alpha
0106   VECCORE_ATT_HOST_DEVICE
0107   Precision GetAlpha() const { return fPara.fAlpha; }
0108 
0109   /// Getter for theta
0110   VECCORE_ATT_HOST_DEVICE
0111   Precision GetTheta() const { return fPara.fTheta; }
0112 
0113   /// Getter for phi
0114   VECCORE_ATT_HOST_DEVICE
0115   Precision GetPhi() const { return fPara.fPhi; }
0116 
0117   /// Getter for tan(alpha)
0118   VECCORE_ATT_HOST_DEVICE
0119   Precision GetTanAlpha() const { return fPara.fTanAlpha; }
0120 
0121   /// Getter for tan(th)*sin(phi)
0122   VECCORE_ATT_HOST_DEVICE
0123   Precision GetTanThetaSinPhi() const { return fPara.fTanThetaSinPhi; }
0124 
0125   /// Getter for tan(th)*cos(phi)
0126   VECCORE_ATT_HOST_DEVICE
0127   Precision GetTanThetaCosPhi() const { return fPara.fTanThetaCosPhi; }
0128 
0129   /// Getter for scale factor fCtx
0130   VECCORE_ATT_HOST_DEVICE
0131   Precision GetCtx() const { return fPara.fCtx; }
0132 
0133   /// Getter for scale factor fCty
0134   VECCORE_ATT_HOST_DEVICE
0135   Precision GetCty() const { return fPara.fCty; }
0136 
0137   /// Setter for dimensions in x, y, z
0138   /// @param dimension Vector with length in x, y, z
0139   VECCORE_ATT_HOST_DEVICE
0140   void SetDimensions(Vector3D<Precision> const &dimensions) { fPara.fDimensions = dimensions; }
0141 
0142   /// Setter for dimensions in x, y, z
0143   /// @param dx Half length in x
0144   /// @param dy Half length in y
0145   /// @param dz Half length in z
0146   VECCORE_ATT_HOST_DEVICE
0147   void SetDimensions(const Precision dx, const Precision dy, const Precision dz) { fPara.fDimensions.Set(dx, dy, dz); }
0148 
0149   /// Setter for alpha
0150   /// @param alpha Angle between y-axis and the line joining centres of the faces at +/- dy
0151   VECCORE_ATT_HOST_DEVICE
0152   void SetAlpha(const Precision alpha) { fPara.SetAlpha(alpha); }
0153 
0154   /// Setter for theta
0155   /// @param theta Polar angle
0156   VECCORE_ATT_HOST_DEVICE
0157   void SetTheta(const Precision theta) { fPara.SetTheta(theta); }
0158 
0159   /// Setter for phi
0160   /// @param phi Azimuthal angle
0161   VECCORE_ATT_HOST_DEVICE
0162   void SetPhi(const Precision phi) { fPara.SetPhi(phi); }
0163 
0164   /// Setter for theta and phi
0165   /// @param theta Polar angle
0166   /// @param phi Azimuthal angle
0167   VECCORE_ATT_HOST_DEVICE
0168   void SetThetaAndPhi(const Precision theta, const Precision phi) { fPara.SetThetaAndPhi(theta, phi); }
0169 
0170   virtual int MemorySize() const final { return sizeof(*this); }
0171 
0172   VECCORE_ATT_HOST_DEVICE
0173   virtual void Print() const final;
0174 
0175   virtual void Print(std::ostream &os) const final;
0176 
0177 #ifndef VECCORE_CUDA
0178   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0179 #endif
0180   VECCORE_ATT_HOST_DEVICE
0181   void Extent(Vector3D<Precision> &, Vector3D<Precision> &) const override;
0182 
0183   /// Implementation of capacity computation
0184   Precision volume() const { return 8.0 * fPara.fDimensions[0] * fPara.fDimensions[1] * fPara.fDimensions[2]; }
0185 
0186   Precision Capacity() const override { return volume(); }
0187 
0188   Vector3D<Precision> SamplePointOnSurface() const override;
0189 
0190   Precision SurfaceArea() const override { return 2. * (fPara.fAreas[0] + fPara.fAreas[1] + fPara.fAreas[2]); }
0191 
0192   VECCORE_ATT_HOST_DEVICE
0193   virtual bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override
0194   {
0195     bool valid;
0196     normal = ParallelepipedImplementation::NormalKernel(fPara, point, valid);
0197     return valid;
0198   }
0199 
0200   /// Get the solid type as string.
0201   /// @return Name of the solid type
0202   std::string GetEntityType() const { return "parallelepiped"; }
0203 
0204   /// Templated factory for creating a placed volume
0205 #ifdef VECCORE_CUDA
0206   VECCORE_ATT_DEVICE
0207 #endif
0208   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0209 #ifdef VECCORE_CUDA
0210                                const int id, const int copy_no, const int child_id,
0211 #endif
0212                                VPlacedVolume *const placement = NULL);
0213 
0214 #ifdef VECGEOM_CUDA_INTERFACE
0215   virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedParallelepiped>::SizeOf(); }
0216   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0217   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0218 #endif
0219 
0220 #ifdef VECCORE_CUDA
0221   VECCORE_ATT_DEVICE
0222 #endif
0223   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0224                                            Transformation3D const *const transformation,
0225 #ifdef VECCORE_CUDA
0226                                            const int id, const int copy_no, const int child_id,
0227 #endif
0228                                            VPlacedVolume *const placement = NULL) const final;
0229 };
0230 } // namespace VECGEOM_IMPL_NAMESPACE
0231 } // namespace vecgeom
0232 
0233 #endif // VECGEOM_VOLUMES_UNPLACEDPARALLELEPIPED_H_