Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-30 09:16:13

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   VECCORE_ATT_HOST_DEVICE
0084   VECGEOM_FORCE_INLINE
0085   virtual ESolidType GetType() const override { return ESolidType::trd; }
0086 
0087   /// Getter for the structure storing Trd data
0088   VECCORE_ATT_HOST_DEVICE
0089   TrdStruct<Precision> const &GetStruct() const { return fTrd; }
0090 
0091   /// Setter for all parameters
0092   /// @param x1 Half-length along x at the surface positioned at -dz
0093   /// @param x2 Half-length along x at the surface positioned at +dz
0094   /// @param y1 Half-length along y at the surface positioned at -dz
0095   /// @param y2 Half-length along y at the surface positioned at +dz
0096   /// @param z Half-length along z axis
0097   VECCORE_ATT_HOST_DEVICE
0098   void SetAllParameters(Precision x1, Precision x2, Precision y1, Precision y2, Precision z)
0099   {
0100     fTrd.SetAllParameters(x1, x2, y1, y2, z);
0101   }
0102 
0103   /// Setter for half-length along x at -dz
0104   VECCORE_ATT_HOST_DEVICE
0105   void SetXHalfLength1(Precision arg)
0106   {
0107     fTrd.fDX1 = arg;
0108     fTrd.CalculateCached();
0109   }
0110 
0111   /// Setter for half-length along x at +dz
0112   VECCORE_ATT_HOST_DEVICE
0113   void SetXHalfLength2(Precision arg)
0114   {
0115     fTrd.fDX2 = arg;
0116     fTrd.CalculateCached();
0117   }
0118 
0119   /// Setter for half-length along y at -dz
0120   VECCORE_ATT_HOST_DEVICE
0121   void SetYHalfLength1(Precision arg)
0122   {
0123     fTrd.fDY1 = arg;
0124     fTrd.CalculateCached();
0125   }
0126 
0127   /// Setter for half-length along y at +dz
0128   VECCORE_ATT_HOST_DEVICE
0129   void SetYHalfLength2(Precision arg)
0130   {
0131     fTrd.fDY2 = arg;
0132     fTrd.CalculateCached();
0133   }
0134 
0135   /// Setter for half-length along z
0136   VECCORE_ATT_HOST_DEVICE
0137   void SetZHalfLength(Precision arg)
0138   {
0139     fTrd.fDZ = arg;
0140     fTrd.CalculateCached();
0141   }
0142 
0143   /// Getter for half-length along x at -dz
0144   VECCORE_ATT_HOST_DEVICE
0145   VECGEOM_FORCE_INLINE
0146   Precision dx1() const { return fTrd.fDX1; }
0147 
0148   /// Getter for half-length along x at +dz
0149   VECCORE_ATT_HOST_DEVICE
0150   VECGEOM_FORCE_INLINE
0151   Precision dx2() const { return fTrd.fDX2; }
0152 
0153   /// Getter for half-length along y at -dz
0154   VECCORE_ATT_HOST_DEVICE
0155   VECGEOM_FORCE_INLINE
0156   Precision dy1() const { return fTrd.fDY1; }
0157 
0158   /// Getter for half-length along y at +dz
0159   VECCORE_ATT_HOST_DEVICE
0160   VECGEOM_FORCE_INLINE
0161   Precision dy2() const { return fTrd.fDY2; }
0162 
0163   /// Getter for half-length along z
0164   VECCORE_ATT_HOST_DEVICE
0165   VECGEOM_FORCE_INLINE
0166   Precision dz() const { return fTrd.fDZ; }
0167 
0168   /// Return difference between half-legths along x at +dz and -dz
0169   VECCORE_ATT_HOST_DEVICE
0170   VECGEOM_FORCE_INLINE
0171   Precision x2minusx1() const { return fTrd.fX2minusX1; }
0172 
0173   /// Return difference between half-legths along y at +dz and -dz
0174   VECCORE_ATT_HOST_DEVICE
0175   VECGEOM_FORCE_INLINE
0176   Precision y2minusy1() const { return fTrd.fY2minusY1; }
0177 
0178   /// Return half-length along x at z = 0
0179   VECCORE_ATT_HOST_DEVICE
0180   VECGEOM_FORCE_INLINE
0181   Precision halfx1plusx2() const { return fTrd.fHalfX1plusX2; }
0182 
0183   /// Return half-length along y at z = 0
0184   VECCORE_ATT_HOST_DEVICE
0185   VECGEOM_FORCE_INLINE
0186   Precision halfy1plusy2() const { return fTrd.fHalfY1plusY2; }
0187 
0188   /// Return tangent of inclination angle along x
0189   VECCORE_ATT_HOST_DEVICE
0190   VECGEOM_FORCE_INLINE
0191   Precision fx() const { return fTrd.fFx; }
0192 
0193   /// Return tangent of inclination angle along x
0194   VECCORE_ATT_HOST_DEVICE
0195   VECGEOM_FORCE_INLINE
0196   Precision fy() const { return fTrd.fFy; }
0197 
0198   /// Return absolute value of cosine of inclination angle along x
0199   VECCORE_ATT_HOST_DEVICE
0200   VECGEOM_FORCE_INLINE
0201   Precision calfx() const { return fTrd.fCalfX; }
0202 
0203   /// Return absolute value of cosine of inclination angle along y
0204   VECCORE_ATT_HOST_DEVICE
0205   VECGEOM_FORCE_INLINE
0206   Precision calfy() const { return fTrd.fCalfY; }
0207 
0208   /// Return corrected tolerance for Inside checks on x
0209   VECCORE_ATT_HOST_DEVICE
0210   VECGEOM_FORCE_INLINE
0211   Precision ToleranceX() const { return fTrd.fToleranceX; }
0212 
0213   /// Return corrected tolerance for Inside checks on y
0214   VECCORE_ATT_HOST_DEVICE
0215   VECGEOM_FORCE_INLINE
0216   Precision ToleranceY() const { return fTrd.fToleranceY; }
0217 
0218   // virtual int MemorySize() const final { return sizeof(*this); }
0219   virtual int MemorySize() const override { return sizeof(*this); }
0220 
0221   VECCORE_ATT_HOST_DEVICE
0222   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override
0223   {
0224     aMin = Vector3D<Precision>(-Max(fTrd.fDX1, fTrd.fDX2), -Max(fTrd.fDY1, fTrd.fDY2), -fTrd.fDZ);
0225     aMax = Vector3D<Precision>(Max(fTrd.fDX1, fTrd.fDX2), Max(fTrd.fDY1, fTrd.fDY2), fTrd.fDZ);
0226   }
0227 
0228   // Computes capacity of the shape in [length^3]
0229   Precision Capacity() const override;
0230 
0231   // Computes surface are in [length^2]
0232   Precision SurfaceArea() const override;
0233 
0234   Vector3D<Precision> SamplePointOnSurface() const override;
0235 
0236   /// Return area of face at +x
0237   Precision GetPlusXArea() const { return 2 * fTrd.fDZ * (fTrd.fDY1 + fTrd.fDY2) * fTrd.fSecxz; }
0238 
0239   /// Return area of face at -x
0240   Precision GetMinusXArea() const { return GetPlusXArea(); }
0241 
0242   /// Return area of face at +y
0243   Precision GetPlusYArea() const { return 2 * fTrd.fDZ * (fTrd.fDX1 + fTrd.fDX2) * fTrd.fSecyz; }
0244 
0245   /// Return area of face at -y
0246   Precision GetMinusYArea() const { return GetPlusYArea(); }
0247 
0248   /// Return area of face at +z
0249   Precision GetPlusZArea() const { return 4 * fTrd.fDX2 * fTrd.fDY2; }
0250 
0251   /// Return area of face at -z
0252   Precision GetMinusZArea() const { return 4 * fTrd.fDX1 * fTrd.fDY1; }
0253 
0254   /// Select surface for sampling point
0255   int ChooseSurface() const;
0256 
0257   VECCORE_ATT_HOST_DEVICE
0258   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0259 
0260   VECCORE_ATT_HOST_DEVICE
0261   virtual void Print() const final;
0262 
0263   virtual void Print(std::ostream &os) const final;
0264 
0265 #ifndef VECCORE_CUDA
0266   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0267 #endif
0268 
0269   /// Get the solid type as string
0270   /// @return Name of the solid type
0271   std::string GetEntityType() const { return "Trd"; }
0272 
0273 #ifdef VECGEOM_CUDA_INTERFACE
0274   virtual size_t DeviceSizeOf() const override
0275   {
0276     return DevicePtr<cuda::SUnplacedTrd<cuda::TrdTypes::UniversalTrd>>::SizeOf();
0277   }
0278 
0279   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0280   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0281 #endif
0282 
0283   std::ostream &StreamInfo(std::ostream &os) const;
0284 
0285 #ifndef VECCORE_CUDA
0286 #ifdef VECGEOM_ROOT
0287   TGeoShape const *ConvertToRoot(char const *label) const;
0288 #endif
0289 
0290 #ifdef VECGEOM_GEANT4
0291   G4VSolid const *ConvertToGeant4(char const *label) const;
0292 #endif
0293 #endif
0294 };
0295 
0296 template <>
0297 struct Maker<UnplacedTrd> {
0298   template <typename... ArgTypes>
0299   static UnplacedTrd *MakeInstance(const Precision x1, const Precision x2, const Precision y1, const Precision y2,
0300                                    const Precision z);
0301   template <typename... ArgTypes>
0302   static UnplacedTrd *MakeInstance(const Precision x1, const Precision x2, const Precision y1, const Precision z);
0303 };
0304 
0305 template <typename TrdType = TrdTypes::UniversalTrd>
0306 class SUnplacedTrd : public UnplacedVolumeImplHelper<TrdImplementation<TrdType>, UnplacedTrd>, public AlignedBase {
0307 public:
0308   using Kernel     = TrdImplementation<TrdType>;
0309   using BaseType_t = UnplacedVolumeImplHelper<TrdImplementation<TrdType>, UnplacedTrd>;
0310   using BaseType_t::BaseType_t;
0311 
0312   VECCORE_ATT_DEVICE
0313   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0314 #ifdef VECCORE_CUDA
0315                                const int id, const int copy_no, const int child_id,
0316 #endif
0317                                VPlacedVolume *const placement = NULL);
0318 
0319 #ifndef VECCORE_CUDA
0320   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0321                                            Transformation3D const *const transformation,
0322                                            VPlacedVolume *const placement = NULL) const override
0323   {
0324     return VolumeFactory::CreateByTransformation<SUnplacedTrd<TrdType>>(volume, transformation, placement);
0325   }
0326 
0327 #else
0328   VECCORE_ATT_DEVICE
0329   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0330                                            Transformation3D const *const transformation, 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, id, copy_no, child_id,
0335                                                                         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_