File indexing completed on 2025-01-18 10:14:16
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
0084 VECCORE_ATT_HOST_DEVICE
0085 TrdStruct<Precision> const &GetStruct() const { return fTrd; }
0086
0087
0088
0089
0090
0091
0092
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
0100 VECCORE_ATT_HOST_DEVICE
0101 void SetXHalfLength1(Precision arg)
0102 {
0103 fTrd.fDX1 = arg;
0104 fTrd.CalculateCached();
0105 }
0106
0107
0108 VECCORE_ATT_HOST_DEVICE
0109 void SetXHalfLength2(Precision arg)
0110 {
0111 fTrd.fDX2 = arg;
0112 fTrd.CalculateCached();
0113 }
0114
0115
0116 VECCORE_ATT_HOST_DEVICE
0117 void SetYHalfLength1(Precision arg)
0118 {
0119 fTrd.fDY1 = arg;
0120 fTrd.CalculateCached();
0121 }
0122
0123
0124 VECCORE_ATT_HOST_DEVICE
0125 void SetYHalfLength2(Precision arg)
0126 {
0127 fTrd.fDY2 = arg;
0128 fTrd.CalculateCached();
0129 }
0130
0131
0132 VECCORE_ATT_HOST_DEVICE
0133 void SetZHalfLength(Precision arg)
0134 {
0135 fTrd.fDZ = arg;
0136 fTrd.CalculateCached();
0137 }
0138
0139
0140 VECCORE_ATT_HOST_DEVICE
0141 VECGEOM_FORCE_INLINE
0142 Precision dx1() const { return fTrd.fDX1; }
0143
0144
0145 VECCORE_ATT_HOST_DEVICE
0146 VECGEOM_FORCE_INLINE
0147 Precision dx2() const { return fTrd.fDX2; }
0148
0149
0150 VECCORE_ATT_HOST_DEVICE
0151 VECGEOM_FORCE_INLINE
0152 Precision dy1() const { return fTrd.fDY1; }
0153
0154
0155 VECCORE_ATT_HOST_DEVICE
0156 VECGEOM_FORCE_INLINE
0157 Precision dy2() const { return fTrd.fDY2; }
0158
0159
0160 VECCORE_ATT_HOST_DEVICE
0161 VECGEOM_FORCE_INLINE
0162 Precision dz() const { return fTrd.fDZ; }
0163
0164
0165 VECCORE_ATT_HOST_DEVICE
0166 VECGEOM_FORCE_INLINE
0167 Precision x2minusx1() const { return fTrd.fX2minusX1; }
0168
0169
0170 VECCORE_ATT_HOST_DEVICE
0171 VECGEOM_FORCE_INLINE
0172 Precision y2minusy1() const { return fTrd.fY2minusY1; }
0173
0174
0175 VECCORE_ATT_HOST_DEVICE
0176 VECGEOM_FORCE_INLINE
0177 Precision halfx1plusx2() const { return fTrd.fHalfX1plusX2; }
0178
0179
0180 VECCORE_ATT_HOST_DEVICE
0181 VECGEOM_FORCE_INLINE
0182 Precision halfy1plusy2() const { return fTrd.fHalfY1plusY2; }
0183
0184
0185 VECCORE_ATT_HOST_DEVICE
0186 VECGEOM_FORCE_INLINE
0187 Precision fx() const { return fTrd.fFx; }
0188
0189
0190 VECCORE_ATT_HOST_DEVICE
0191 VECGEOM_FORCE_INLINE
0192 Precision fy() const { return fTrd.fFy; }
0193
0194
0195 VECCORE_ATT_HOST_DEVICE
0196 VECGEOM_FORCE_INLINE
0197 Precision calfx() const { return fTrd.fCalfX; }
0198
0199
0200 VECCORE_ATT_HOST_DEVICE
0201 VECGEOM_FORCE_INLINE
0202 Precision calfy() const { return fTrd.fCalfY; }
0203
0204
0205 VECCORE_ATT_HOST_DEVICE
0206 VECGEOM_FORCE_INLINE
0207 Precision ToleranceX() const { return fTrd.fToleranceX; }
0208
0209
0210 VECCORE_ATT_HOST_DEVICE
0211 VECGEOM_FORCE_INLINE
0212 Precision ToleranceY() const { return fTrd.fToleranceY; }
0213
0214
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
0225 Precision Capacity() const override;
0226
0227
0228 Precision SurfaceArea() const override;
0229
0230 Vector3D<Precision> SamplePointOnSurface() const override;
0231
0232
0233 Precision GetPlusXArea() const { return 2 * fTrd.fDZ * (fTrd.fDY1 + fTrd.fDY2) * fTrd.fSecxz; }
0234
0235
0236 Precision GetMinusXArea() const { return GetPlusXArea(); }
0237
0238
0239 Precision GetPlusYArea() const { return 2 * fTrd.fDZ * (fTrd.fDX1 + fTrd.fDX2) * fTrd.fSecyz; }
0240
0241
0242 Precision GetMinusYArea() const { return GetPlusYArea(); }
0243
0244
0245 Precision GetPlusZArea() const { return 4 * fTrd.fDX2 * fTrd.fDY2; }
0246
0247
0248 Precision GetMinusZArea() const { return 4 * fTrd.fDX1 * fTrd.fDY1; }
0249
0250
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
0266
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 }
0343 }
0344
0345 #include "VecGeom/volumes/SpecializedTrd.h"
0346
0347 #endif