File indexing completed on 2026-09-30 09:16:13
0001
0002
0003
0004
0005
0006
0007
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
0029
0030
0031
0032
0033 class UnplacedTrd : public VUnplacedVolume {
0034 private:
0035 TrdStruct<Precision> fTrd;
0036
0037 public:
0038
0039 VECCORE_ATT_HOST_DEVICE
0040 UnplacedTrd() : fTrd()
0041 {
0042 fGlobalConvexity = true;
0043 ComputeBBox();
0044 }
0045
0046
0047
0048
0049
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
0058
0059
0060
0061
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
0070
0071
0072
0073
0074
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
0088 VECCORE_ATT_HOST_DEVICE
0089 TrdStruct<Precision> const &GetStruct() const { return fTrd; }
0090
0091
0092
0093
0094
0095
0096
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
0104 VECCORE_ATT_HOST_DEVICE
0105 void SetXHalfLength1(Precision arg)
0106 {
0107 fTrd.fDX1 = arg;
0108 fTrd.CalculateCached();
0109 }
0110
0111
0112 VECCORE_ATT_HOST_DEVICE
0113 void SetXHalfLength2(Precision arg)
0114 {
0115 fTrd.fDX2 = arg;
0116 fTrd.CalculateCached();
0117 }
0118
0119
0120 VECCORE_ATT_HOST_DEVICE
0121 void SetYHalfLength1(Precision arg)
0122 {
0123 fTrd.fDY1 = arg;
0124 fTrd.CalculateCached();
0125 }
0126
0127
0128 VECCORE_ATT_HOST_DEVICE
0129 void SetYHalfLength2(Precision arg)
0130 {
0131 fTrd.fDY2 = arg;
0132 fTrd.CalculateCached();
0133 }
0134
0135
0136 VECCORE_ATT_HOST_DEVICE
0137 void SetZHalfLength(Precision arg)
0138 {
0139 fTrd.fDZ = arg;
0140 fTrd.CalculateCached();
0141 }
0142
0143
0144 VECCORE_ATT_HOST_DEVICE
0145 VECGEOM_FORCE_INLINE
0146 Precision dx1() const { return fTrd.fDX1; }
0147
0148
0149 VECCORE_ATT_HOST_DEVICE
0150 VECGEOM_FORCE_INLINE
0151 Precision dx2() const { return fTrd.fDX2; }
0152
0153
0154 VECCORE_ATT_HOST_DEVICE
0155 VECGEOM_FORCE_INLINE
0156 Precision dy1() const { return fTrd.fDY1; }
0157
0158
0159 VECCORE_ATT_HOST_DEVICE
0160 VECGEOM_FORCE_INLINE
0161 Precision dy2() const { return fTrd.fDY2; }
0162
0163
0164 VECCORE_ATT_HOST_DEVICE
0165 VECGEOM_FORCE_INLINE
0166 Precision dz() const { return fTrd.fDZ; }
0167
0168
0169 VECCORE_ATT_HOST_DEVICE
0170 VECGEOM_FORCE_INLINE
0171 Precision x2minusx1() const { return fTrd.fX2minusX1; }
0172
0173
0174 VECCORE_ATT_HOST_DEVICE
0175 VECGEOM_FORCE_INLINE
0176 Precision y2minusy1() const { return fTrd.fY2minusY1; }
0177
0178
0179 VECCORE_ATT_HOST_DEVICE
0180 VECGEOM_FORCE_INLINE
0181 Precision halfx1plusx2() const { return fTrd.fHalfX1plusX2; }
0182
0183
0184 VECCORE_ATT_HOST_DEVICE
0185 VECGEOM_FORCE_INLINE
0186 Precision halfy1plusy2() const { return fTrd.fHalfY1plusY2; }
0187
0188
0189 VECCORE_ATT_HOST_DEVICE
0190 VECGEOM_FORCE_INLINE
0191 Precision fx() const { return fTrd.fFx; }
0192
0193
0194 VECCORE_ATT_HOST_DEVICE
0195 VECGEOM_FORCE_INLINE
0196 Precision fy() const { return fTrd.fFy; }
0197
0198
0199 VECCORE_ATT_HOST_DEVICE
0200 VECGEOM_FORCE_INLINE
0201 Precision calfx() const { return fTrd.fCalfX; }
0202
0203
0204 VECCORE_ATT_HOST_DEVICE
0205 VECGEOM_FORCE_INLINE
0206 Precision calfy() const { return fTrd.fCalfY; }
0207
0208
0209 VECCORE_ATT_HOST_DEVICE
0210 VECGEOM_FORCE_INLINE
0211 Precision ToleranceX() const { return fTrd.fToleranceX; }
0212
0213
0214 VECCORE_ATT_HOST_DEVICE
0215 VECGEOM_FORCE_INLINE
0216 Precision ToleranceY() const { return fTrd.fToleranceY; }
0217
0218
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
0229 Precision Capacity() const override;
0230
0231
0232 Precision SurfaceArea() const override;
0233
0234 Vector3D<Precision> SamplePointOnSurface() const override;
0235
0236
0237 Precision GetPlusXArea() const { return 2 * fTrd.fDZ * (fTrd.fDY1 + fTrd.fDY2) * fTrd.fSecxz; }
0238
0239
0240 Precision GetMinusXArea() const { return GetPlusXArea(); }
0241
0242
0243 Precision GetPlusYArea() const { return 2 * fTrd.fDZ * (fTrd.fDX1 + fTrd.fDX2) * fTrd.fSecyz; }
0244
0245
0246 Precision GetMinusYArea() const { return GetPlusYArea(); }
0247
0248
0249 Precision GetPlusZArea() const { return 4 * fTrd.fDX2 * fTrd.fDY2; }
0250
0251
0252 Precision GetMinusZArea() const { return 4 * fTrd.fDX1 * fTrd.fDY1; }
0253
0254
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
0270
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 }
0343 }
0344
0345 #include "VecGeom/volumes/SpecializedTrd.h"
0346
0347 #endif