Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:15

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 SIMDUnplacedVolumeImplHelper<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   /// Getter for the structure storing parallepiped data.
0078   VECCORE_ATT_HOST_DEVICE
0079   ParallelepipedStruct<Precision> const &GetStruct() const { return fPara; }
0080 
0081   /// Getter for parallelepiped dimensions
0082   VECCORE_ATT_HOST_DEVICE
0083   Vector3D<Precision> const &GetDimensions() const { return fPara.fDimensions; }
0084 
0085   /// Getter for parallelepiped normals
0086   VECCORE_ATT_HOST_DEVICE
0087   Vector3D<Precision> const &GetNormal(int i) const { return fPara.fNormals[i]; }
0088 
0089   /// Getter for dx
0090   VECCORE_ATT_HOST_DEVICE
0091   Precision GetX() const { return fPara.fDimensions[0]; }
0092 
0093   /// Getter for dy
0094   VECCORE_ATT_HOST_DEVICE
0095   Precision GetY() const { return fPara.fDimensions[1]; }
0096 
0097   /// Getter for dz
0098   VECCORE_ATT_HOST_DEVICE
0099   Precision GetZ() const { return fPara.fDimensions[2]; }
0100 
0101   /// Getter for alpha
0102   VECCORE_ATT_HOST_DEVICE
0103   Precision GetAlpha() const { return fPara.fAlpha; }
0104 
0105   /// Getter for theta
0106   VECCORE_ATT_HOST_DEVICE
0107   Precision GetTheta() const { return fPara.fTheta; }
0108 
0109   /// Getter for phi
0110   VECCORE_ATT_HOST_DEVICE
0111   Precision GetPhi() const { return fPara.fPhi; }
0112 
0113   /// Getter for tan(alpha)
0114   VECCORE_ATT_HOST_DEVICE
0115   Precision GetTanAlpha() const { return fPara.fTanAlpha; }
0116 
0117   /// Getter for tan(th)*sin(phi)
0118   VECCORE_ATT_HOST_DEVICE
0119   Precision GetTanThetaSinPhi() const { return fPara.fTanThetaSinPhi; }
0120 
0121   /// Getter for tan(th)*cos(phi)
0122   VECCORE_ATT_HOST_DEVICE
0123   Precision GetTanThetaCosPhi() const { return fPara.fTanThetaCosPhi; }
0124 
0125   /// Getter for scale factor fCtx
0126   VECCORE_ATT_HOST_DEVICE
0127   Precision GetCtx() const { return fPara.fCtx; }
0128 
0129   /// Getter for scale factor fCty
0130   VECCORE_ATT_HOST_DEVICE
0131   Precision GetCty() const { return fPara.fCty; }
0132 
0133   /// Setter for dimensions in x, y, z
0134   /// @param dimension Vector with length in x, y, z
0135   VECCORE_ATT_HOST_DEVICE
0136   void SetDimensions(Vector3D<Precision> const &dimensions) { fPara.fDimensions = dimensions; }
0137 
0138   /// Setter for dimensions in x, y, z
0139   /// @param dx Half length in x
0140   /// @param dy Half length in y
0141   /// @param dz Half length in z
0142   VECCORE_ATT_HOST_DEVICE
0143   void SetDimensions(const Precision dx, const Precision dy, const Precision dz) { fPara.fDimensions.Set(dx, dy, dz); }
0144 
0145   /// Setter for alpha
0146   /// @param alpha Angle between y-axis and the line joining centres of the faces at +/- dy
0147   VECCORE_ATT_HOST_DEVICE
0148   void SetAlpha(const Precision alpha) { fPara.SetAlpha(alpha); }
0149 
0150   /// Setter for theta
0151   /// @param theta Polar angle
0152   VECCORE_ATT_HOST_DEVICE
0153   void SetTheta(const Precision theta) { fPara.SetTheta(theta); }
0154 
0155   /// Setter for phi
0156   /// @param phi Azimuthal angle
0157   VECCORE_ATT_HOST_DEVICE
0158   void SetPhi(const Precision phi) { fPara.SetPhi(phi); }
0159 
0160   /// Setter for theta and phi
0161   /// @param theta Polar angle
0162   /// @param phi Azimuthal angle
0163   VECCORE_ATT_HOST_DEVICE
0164   void SetThetaAndPhi(const Precision theta, const Precision phi) { fPara.SetThetaAndPhi(theta, phi); }
0165 
0166   virtual int MemorySize() const final { return sizeof(*this); }
0167 
0168   VECCORE_ATT_HOST_DEVICE
0169   virtual void Print() const final;
0170 
0171   virtual void Print(std::ostream &os) const final;
0172 
0173 #ifndef VECCORE_CUDA
0174   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0175 #endif
0176   VECCORE_ATT_HOST_DEVICE
0177   void Extent(Vector3D<Precision> &, Vector3D<Precision> &) const override;
0178 
0179   /// Implementation of capacity computation
0180   Precision volume() const { return 8.0 * fPara.fDimensions[0] * fPara.fDimensions[1] * fPara.fDimensions[2]; }
0181 
0182   Precision Capacity() const override { return volume(); }
0183 
0184   Vector3D<Precision> SamplePointOnSurface() const override;
0185 
0186   Precision SurfaceArea() const override { return 2. * (fPara.fAreas[0] + fPara.fAreas[1] + fPara.fAreas[2]); }
0187 
0188   VECCORE_ATT_HOST_DEVICE
0189   virtual bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override
0190   {
0191     bool valid;
0192     normal = ParallelepipedImplementation::NormalKernel(fPara, point, valid);
0193     return valid;
0194   }
0195 
0196   /// Get the solid type as string.
0197   /// @return Name of the solid type
0198   std::string GetEntityType() const { return "parallelepiped"; }
0199 
0200   /// Templated factory for creating a placed volume
0201   template <TranslationCode transCodeT, RotationCode rotCodeT>
0202 #ifdef VECCORE_CUDA
0203   VECCORE_ATT_DEVICE
0204 #endif
0205       static VPlacedVolume *
0206       Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0207 #ifdef VECCORE_CUDA
0208              const int id, const int copy_no, const int child_id,
0209 #endif
0210              VPlacedVolume *const placement = NULL);
0211 
0212 #ifdef VECGEOM_CUDA_INTERFACE
0213   virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedParallelepiped>::SizeOf(); }
0214   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0215   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0216 #endif
0217 
0218 #ifdef VECCORE_CUDA
0219   VECCORE_ATT_DEVICE
0220 #endif
0221   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0222                                            Transformation3D const *const transformation,
0223                                            const TranslationCode trans_code, const RotationCode rot_code,
0224 #ifdef VECCORE_CUDA
0225                                            const int id, const int copy_no, const int child_id,
0226 #endif
0227                                            VPlacedVolume *const placement = NULL) const final;
0228 };
0229 } // namespace VECGEOM_IMPL_NAMESPACE
0230 } // namespace vecgeom
0231 
0232 #endif // VECGEOM_VOLUMES_UNPLACEDPARALLELEPIPED_H_