Back to home page

EIC code displayed by LXR

 
 

    


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

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 Trd shape
0006 /// @file volumes/UnplacedTrd.h
0007 /// @author Georgios Bitzes
0008 
0009 #ifndef VECGEOM_VOLUMES_UNPLACEDTRD_H_
0010 #define VECGEOM_VOLUMES_UNPLACEDTRD_H_
0011 
0012 #include "VecGeom/base/Cuda.h"
0013 #include "VecGeom/base/Global.h"
0014 #include "VecGeom/base/AlignedBase.h"
0015 #include "VecGeom/volumes/UnplacedVolume.h"
0016 #include "TrdStruct.h"
0017 #include "VecGeom/volumes/kernel/TrdImplementation.h"
0018 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0019 
0020 namespace vecgeom {
0021 
0022 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedTrd;);
0023 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedTrd);
0024 VECGEOM_DEVICE_DECLARE_CONV_TEMPLATE(class, SUnplacedTrd, typename);
0025 
0026 inline namespace VECGEOM_IMPL_NAMESPACE {
0027 
0028 /// Class for the Trd shape primitive
0029 ///
0030 /// Trd is a trapezoid with x and y dimensions varying along z:
0031 /// - bases at z = -dz and z = +dz are rectangles
0032 /// - lateral surface consists of four isosceles trapeziums
0033 class UnplacedTrd : public VUnplacedVolume {
0034 private:
0035   TrdStruct<Precision> fTrd; ///< Structure with trapezoid parameters
0036 
0037 public:
0038   /// Default constructor
0039   VECCORE_ATT_HOST_DEVICE
0040   UnplacedTrd() : fTrd()
0041   {
0042     fGlobalConvexity = true;
0043     ComputeBBox();
0044   }
0045 
0046   /// Constructor, special case where Trd is a box
0047   /// @param x Half-length in x
0048   /// @param y Half-length in y
0049   /// @param z Half-length in z
0050   VECCORE_ATT_HOST_DEVICE
0051   UnplacedTrd(const Precision x, const Precision y, const Precision z) : fTrd(x, y, z)
0052   {
0053     fGlobalConvexity = true;
0054     ComputeBBox();
0055   }
0056 
0057   /// Constructor, special case where y dimension remains constant
0058   /// @param x1 Half-length along x at the surface positioned at -dz
0059   /// @param x2 Half-length along x at the surface positioned at +dz
0060   /// @param y Half-length in y
0061   /// @param z Half-length in z
0062   VECCORE_ATT_HOST_DEVICE
0063   UnplacedTrd(const Precision x1, const Precision x2, const Precision y, const Precision z) : fTrd(x1, x2, y, z)
0064   {
0065     fGlobalConvexity = true;
0066     ComputeBBox();
0067   }
0068 
0069   /// Constructor
0070   /// @param x1 Half-length along x at the surface positioned at -dz
0071   /// @param x2 Half-length along x at the surface positioned at +dz
0072   /// @param y1 Half-length along y at the surface positioned at -dz
0073   /// @param y2 Half-length along y at the surface positioned at +dz
0074   /// @param z Half-length along z axis
0075   VECCORE_ATT_HOST_DEVICE
0076   UnplacedTrd(const Precision x1, const Precision x2, const Precision y1, const Precision y2, const Precision z)
0077       : fTrd(x1, x2, y1, y2, z)
0078   {
0079     fGlobalConvexity = true;
0080     ComputeBBox();
0081   }
0082 
0083   /// Getter for the structure storing Trd data
0084   VECCORE_ATT_HOST_DEVICE
0085   TrdStruct<Precision> const &GetStruct() const { return fTrd; }
0086 
0087   /// Setter for all parameters
0088   /// @param x1 Half-length along x at the surface positioned at -dz
0089   /// @param x2 Half-length along x at the surface positioned at +dz
0090   /// @param y1 Half-length along y at the surface positioned at -dz
0091   /// @param y2 Half-length along y at the surface positioned at +dz
0092   /// @param z Half-length along z axis
0093   VECCORE_ATT_HOST_DEVICE
0094   void SetAllParameters(Precision x1, Precision x2, Precision y1, Precision y2, Precision z)
0095   {
0096     fTrd.SetAllParameters(x1, x2, y1, y2, z);
0097   }
0098 
0099   /// Setter for half-length along x at -dz
0100   VECCORE_ATT_HOST_DEVICE
0101   void SetXHalfLength1(Precision arg)
0102   {
0103     fTrd.fDX1 = arg;
0104     fTrd.CalculateCached();
0105   }
0106 
0107   /// Setter for half-length along x at +dz
0108   VECCORE_ATT_HOST_DEVICE
0109   void SetXHalfLength2(Precision arg)
0110   {
0111     fTrd.fDX2 = arg;
0112     fTrd.CalculateCached();
0113   }
0114 
0115   /// Setter for half-length along y at -dz
0116   VECCORE_ATT_HOST_DEVICE
0117   void SetYHalfLength1(Precision arg)
0118   {
0119     fTrd.fDY1 = arg;
0120     fTrd.CalculateCached();
0121   }
0122 
0123   /// Setter for half-length along y at +dz
0124   VECCORE_ATT_HOST_DEVICE
0125   void SetYHalfLength2(Precision arg)
0126   {
0127     fTrd.fDY2 = arg;
0128     fTrd.CalculateCached();
0129   }
0130 
0131   /// Setter for half-length along z
0132   VECCORE_ATT_HOST_DEVICE
0133   void SetZHalfLength(Precision arg)
0134   {
0135     fTrd.fDZ = arg;
0136     fTrd.CalculateCached();
0137   }
0138 
0139   /// Getter for half-length along x at -dz
0140   VECCORE_ATT_HOST_DEVICE
0141   VECGEOM_FORCE_INLINE
0142   Precision dx1() const { return fTrd.fDX1; }
0143 
0144   /// Getter for half-length along x at +dz
0145   VECCORE_ATT_HOST_DEVICE
0146   VECGEOM_FORCE_INLINE
0147   Precision dx2() const { return fTrd.fDX2; }
0148 
0149   /// Getter for half-length along y at -dz
0150   VECCORE_ATT_HOST_DEVICE
0151   VECGEOM_FORCE_INLINE
0152   Precision dy1() const { return fTrd.fDY1; }
0153 
0154   /// Getter for half-length along y at +dz
0155   VECCORE_ATT_HOST_DEVICE
0156   VECGEOM_FORCE_INLINE
0157   Precision dy2() const { return fTrd.fDY2; }
0158 
0159   /// Getter for half-length along z
0160   VECCORE_ATT_HOST_DEVICE
0161   VECGEOM_FORCE_INLINE
0162   Precision dz() const { return fTrd.fDZ; }
0163 
0164   /// Return difference between half-legths along x at +dz and -dz
0165   VECCORE_ATT_HOST_DEVICE
0166   VECGEOM_FORCE_INLINE
0167   Precision x2minusx1() const { return fTrd.fX2minusX1; }
0168 
0169   /// Return difference between half-legths along y at +dz and -dz
0170   VECCORE_ATT_HOST_DEVICE
0171   VECGEOM_FORCE_INLINE
0172   Precision y2minusy1() const { return fTrd.fY2minusY1; }
0173 
0174   /// Return half-length along x at z = 0
0175   VECCORE_ATT_HOST_DEVICE
0176   VECGEOM_FORCE_INLINE
0177   Precision halfx1plusx2() const { return fTrd.fHalfX1plusX2; }
0178 
0179   /// Return half-length along y at z = 0
0180   VECCORE_ATT_HOST_DEVICE
0181   VECGEOM_FORCE_INLINE
0182   Precision halfy1plusy2() const { return fTrd.fHalfY1plusY2; }
0183 
0184   /// Return tangent of inclination angle along x
0185   VECCORE_ATT_HOST_DEVICE
0186   VECGEOM_FORCE_INLINE
0187   Precision fx() const { return fTrd.fFx; }
0188 
0189   /// Return tangent of inclination angle along x
0190   VECCORE_ATT_HOST_DEVICE
0191   VECGEOM_FORCE_INLINE
0192   Precision fy() const { return fTrd.fFy; }
0193 
0194   /// Return absolute value of cosine of inclination angle along x
0195   VECCORE_ATT_HOST_DEVICE
0196   VECGEOM_FORCE_INLINE
0197   Precision calfx() const { return fTrd.fCalfX; }
0198 
0199   /// Return absolute value of cosine of inclination angle along y
0200   VECCORE_ATT_HOST_DEVICE
0201   VECGEOM_FORCE_INLINE
0202   Precision calfy() const { return fTrd.fCalfY; }
0203 
0204   /// Return corrected tolerance for Inside checks on x
0205   VECCORE_ATT_HOST_DEVICE
0206   VECGEOM_FORCE_INLINE
0207   Precision ToleranceX() const { return fTrd.fToleranceX; }
0208 
0209   /// Return corrected tolerance for Inside checks on y
0210   VECCORE_ATT_HOST_DEVICE
0211   VECGEOM_FORCE_INLINE
0212   Precision ToleranceY() const { return fTrd.fToleranceY; }
0213 
0214   // virtual int MemorySize() const final { return sizeof(*this); }
0215   virtual int MemorySize() const override { return sizeof(*this); }
0216 
0217   VECCORE_ATT_HOST_DEVICE
0218   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override
0219   {
0220     aMin = Vector3D<Precision>(-Max(fTrd.fDX1, fTrd.fDX2), -Max(fTrd.fDY1, fTrd.fDY2), -fTrd.fDZ);
0221     aMax = Vector3D<Precision>(Max(fTrd.fDX1, fTrd.fDX2), Max(fTrd.fDY1, fTrd.fDY2), fTrd.fDZ);
0222   }
0223 
0224   // Computes capacity of the shape in [length^3]
0225   Precision Capacity() const override;
0226 
0227   // Computes surface are in [length^2]
0228   Precision SurfaceArea() const override;
0229 
0230   Vector3D<Precision> SamplePointOnSurface() const override;
0231 
0232   /// Return area of face at +x
0233   Precision GetPlusXArea() const { return 2 * fTrd.fDZ * (fTrd.fDY1 + fTrd.fDY2) * fTrd.fSecxz; }
0234 
0235   /// Return area of face at -x
0236   Precision GetMinusXArea() const { return GetPlusXArea(); }
0237 
0238   /// Return area of face at +y
0239   Precision GetPlusYArea() const { return 2 * fTrd.fDZ * (fTrd.fDX1 + fTrd.fDX2) * fTrd.fSecyz; }
0240 
0241   /// Return area of face at -y
0242   Precision GetMinusYArea() const { return GetPlusYArea(); }
0243 
0244   /// Return area of face at +z
0245   Precision GetPlusZArea() const { return 4 * fTrd.fDX2 * fTrd.fDY2; }
0246 
0247   /// Return area of face at -z
0248   Precision GetMinusZArea() const { return 4 * fTrd.fDX1 * fTrd.fDY1; }
0249 
0250   /// Select surface for sampling point
0251   int ChooseSurface() const;
0252 
0253   VECCORE_ATT_HOST_DEVICE
0254   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0255 
0256   VECCORE_ATT_HOST_DEVICE
0257   virtual void Print() const final;
0258 
0259   virtual void Print(std::ostream &os) const final;
0260 
0261 #ifndef VECCORE_CUDA
0262   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0263 #endif
0264 
0265   /// Get the solid type as string
0266   /// @return Name of the solid type
0267   std::string GetEntityType() const { return "Trd"; }
0268 
0269 #ifdef VECGEOM_CUDA_INTERFACE
0270   virtual size_t DeviceSizeOf() const override
0271   {
0272     return DevicePtr<cuda::SUnplacedTrd<cuda::TrdTypes::UniversalTrd>>::SizeOf();
0273   }
0274 
0275   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0276   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0277 #endif
0278 
0279   std::ostream &StreamInfo(std::ostream &os) const;
0280 
0281 #ifndef VECCORE_CUDA
0282 #ifdef VECGEOM_ROOT
0283   TGeoShape const *ConvertToRoot(char const *label) const;
0284 #endif
0285 
0286 #ifdef VECGEOM_GEANT4
0287   G4VSolid const *ConvertToGeant4(char const *label) const;
0288 #endif
0289 #endif
0290 };
0291 
0292 template <>
0293 struct Maker<UnplacedTrd> {
0294   template <typename... ArgTypes>
0295   static UnplacedTrd *MakeInstance(const Precision x1, const Precision x2, const Precision y1, const Precision y2,
0296                                    const Precision z);
0297   template <typename... ArgTypes>
0298   static UnplacedTrd *MakeInstance(const Precision x1, const Precision x2, const Precision y1, const Precision z);
0299 };
0300 
0301 template <typename TrdType = TrdTypes::UniversalTrd>
0302 class SUnplacedTrd : public SIMDUnplacedVolumeImplHelper<TrdImplementation<TrdType>, UnplacedTrd>, public AlignedBase {
0303 public:
0304   using Kernel     = TrdImplementation<TrdType>;
0305   using BaseType_t = SIMDUnplacedVolumeImplHelper<TrdImplementation<TrdType>, UnplacedTrd>;
0306   using BaseType_t::BaseType_t;
0307 
0308   template <TranslationCode transCodeT, RotationCode rotCodeT>
0309   VECCORE_ATT_DEVICE
0310   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0311 #ifdef VECCORE_CUDA
0312                                const int id, const int copy_no, const int child_id,
0313 #endif
0314                                VPlacedVolume *const placement = NULL);
0315 
0316 #ifndef VECCORE_CUDA
0317   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0318                                            Transformation3D const *const transformation,
0319                                            const TranslationCode trans_code, const RotationCode rot_code,
0320                                            VPlacedVolume *const placement = NULL) const override
0321   {
0322     return VolumeFactory::CreateByTransformation<SUnplacedTrd<TrdType>>(volume, transformation, trans_code, rot_code,
0323                                                                         placement);
0324   }
0325 
0326 #else
0327   VECCORE_ATT_DEVICE
0328   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0329                                            Transformation3D const *const transformation,
0330                                            const TranslationCode trans_code, const RotationCode rot_code, const int id,
0331                                            const int copy_no, const int child_id,
0332                                            VPlacedVolume *const placement = NULL) const override
0333   {
0334     return VolumeFactory::CreateByTransformation<SUnplacedTrd<TrdType>>(volume, transformation, trans_code, rot_code,
0335                                                                         id, copy_no, child_id, placement);
0336   }
0337 #endif
0338 };
0339 
0340 using GenericUnplacedTrd = SUnplacedTrd<TrdTypes::UniversalTrd>;
0341 
0342 } // namespace VECGEOM_IMPL_NAMESPACE
0343 } // namespace vecgeom
0344 
0345 #include "VecGeom/volumes/SpecializedTrd.h"
0346 
0347 #endif // VECGEOM_VOLUMES_UNPLACEDTRD_H_