Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-25 08:38:07

0001 /*
0002  * UnplacedCone.h
0003  *
0004  *  Created on: May 14, 2014
0005  *      Author: swenzel
0006  */
0007 
0008 #ifndef VECGEOM_VOLUMES_UNPLACEDCONE_H_
0009 #define VECGEOM_VOLUMES_UNPLACEDCONE_H_
0010 
0011 #include "VecGeom/base/Cuda.h"
0012 #include "VecGeom/base/Global.h"
0013 #include "VecGeom/base/AlignedBase.h"
0014 #include "VecGeom/volumes/UnplacedVolume.h"
0015 #include "VecGeom/volumes/ConeStruct.h"
0016 #include "VecGeom/volumes/kernel/ConeImplementation.h"
0017 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0018 
0019 namespace vecgeom {
0020 
0021 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedCone;);
0022 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedCone);
0023 VECGEOM_DEVICE_DECLARE_CONV_TEMPLATE(class, SUnplacedCone, typename);
0024 
0025 inline namespace VECGEOM_IMPL_NAMESPACE {
0026 
0027 /**
0028  * Class representing an unplaced cone; Encapsulated parameters of a cone and
0029  * functions that do not depend on how the cone is placed in a reference frame
0030  *
0031  * The unplaced cone is represented by the following parameters
0032  *
0033  * Member Data:
0034  *
0035  * fCone.fDz half length in z direction;  ( the cone has height 2*fDz )
0036  * fCone.fRmin1  inside radius at  -fDz ( in internal coordinate system )
0037  * fCone.fRmin2  inside radius at  +fDz
0038  * fCone.fRmax1  outside radius at -fDz
0039  * fCone.fRmax2  outside radius at +fDz
0040  * fCone.fSPhi starting angle of the segment in radians
0041  * fCone.fDPhi delta angle of the segment in radians
0042  */
0043 class UnplacedCone : public VUnplacedVolume {
0044 
0045 private:
0046   // cone parameters
0047   ConeStruct<Precision> fCone;
0048 
0049 public:
0050   VECCORE_ATT_HOST_DEVICE
0051   UnplacedCone(Precision rmin1, Precision rmax1, Precision rmin2, Precision rmax2, Precision dz, Precision phimin,
0052                Precision deltaphi)
0053       : fCone(rmin1, rmax1, rmin2, rmax2, dz, phimin, deltaphi)
0054   {
0055     DetectConvexity();
0056     ComputeBBox();
0057   }
0058 
0059   // Constructor needed by specialization when Cone becomes Tube
0060   UnplacedCone(Precision rmin, Precision rmax, Precision dz, Precision phimin, Precision deltaphi)
0061       : fCone(rmin, rmax, rmin, rmax, dz, phimin, deltaphi)
0062   {
0063     DetectConvexity();
0064     ComputeBBox();
0065   }
0066 
0067   VECCORE_ATT_HOST_DEVICE
0068   VECGEOM_FORCE_INLINE
0069   virtual ESolidType GetType() const override { return ESolidType::cone; }
0070 
0071   VECCORE_ATT_HOST_DEVICE
0072   ConeStruct<Precision> const &GetStruct() const { return fCone; }
0073 
0074   VECCORE_ATT_HOST_DEVICE
0075   Precision GetInvSecRMax() const { return fCone.fInvSecRMax; }
0076 
0077   VECCORE_ATT_HOST_DEVICE
0078   Precision GetInvSecRMin() const { return fCone.fInvSecRMin; }
0079 
0080   VECCORE_ATT_HOST_DEVICE
0081   Precision GetTolIz() const { return fCone.fTolIz; }
0082   VECCORE_ATT_HOST_DEVICE
0083   Precision GetTolOz() const { return fCone.fTolOz; }
0084 
0085   VECCORE_ATT_HOST_DEVICE
0086   Precision GetSqRmin1() const { return fCone.fSqRmin1; }
0087   VECCORE_ATT_HOST_DEVICE
0088   Precision GetSqRmin2() const { return fCone.fSqRmin2; }
0089   VECCORE_ATT_HOST_DEVICE
0090   Precision GetSqRmax1() const { return fCone.fSqRmax1; }
0091   VECCORE_ATT_HOST_DEVICE
0092   Precision GetSqRmax2() const { return fCone.fSqRmax2; }
0093   VECCORE_ATT_HOST_DEVICE
0094   Precision GetTanRmax() const { return fCone.fTanRMax; }
0095   VECCORE_ATT_HOST_DEVICE
0096   Precision GetTanRmin() const { return fCone.fTanRMin; }
0097   VECCORE_ATT_HOST_DEVICE
0098   Precision GetSecRmax() const { return fCone.fSecRMax; }
0099   VECCORE_ATT_HOST_DEVICE
0100   Precision GetSecRmin() const { return fCone.fSecRMin; }
0101   VECCORE_ATT_HOST_DEVICE
0102   Precision GetZNormInner() const { return fCone.fZNormInner; }
0103   VECCORE_ATT_HOST_DEVICE
0104   Precision GetZNormOuter() const { return fCone.fZNormOuter; }
0105   VECCORE_ATT_HOST_DEVICE
0106   Precision GetInnerConeApex() const { return fCone.fInnerConeApex; }
0107   VECCORE_ATT_HOST_DEVICE
0108   Precision GetTInner() const { return fCone.fTanInnerApexAngle; }
0109   VECCORE_ATT_HOST_DEVICE
0110   Precision GetOuterConeApex() const { return fCone.fOuterConeApex; }
0111   VECCORE_ATT_HOST_DEVICE
0112   Precision GetTOuter() const { return fCone.fTanOuterApexAngle; }
0113 
0114   VECCORE_ATT_HOST_DEVICE
0115   void DetectConvexity();
0116   VECCORE_ATT_HOST_DEVICE
0117   Precision GetRmin1() const { return fCone.fRmin1; }
0118   VECCORE_ATT_HOST_DEVICE
0119   Precision GetRmax1() const { return fCone.fOriginalRmax1; }
0120   VECCORE_ATT_HOST_DEVICE
0121   Precision GetRmin2() const { return fCone.fRmin2; }
0122   VECCORE_ATT_HOST_DEVICE
0123   Precision GetRmax2() const { return fCone.fOriginalRmax2; }
0124   VECCORE_ATT_HOST_DEVICE
0125   Precision GetDz() const { return fCone.fDz; }
0126   VECCORE_ATT_HOST_DEVICE
0127   Precision GetSPhi() const { return fCone.fSPhi; }
0128   VECCORE_ATT_HOST_DEVICE
0129   Precision GetDPhi() const { return fCone.fDPhi; }
0130   VECCORE_ATT_HOST_DEVICE
0131   Precision GetInnerSlope() const { return fCone.fInnerSlope; }
0132   VECCORE_ATT_HOST_DEVICE
0133   Precision GetOuterSlope() const { return fCone.fOuterSlope; }
0134   VECCORE_ATT_HOST_DEVICE
0135   Precision GetInnerOffset() const { return fCone.fInnerOffset; }
0136   VECCORE_ATT_HOST_DEVICE
0137   Precision GetOuterOffset() const { return fCone.fOuterOffset; }
0138   VECCORE_ATT_HOST_DEVICE
0139   Precision GetAlongPhi1X() const { return fCone.fAlongPhi1x; }
0140   VECCORE_ATT_HOST_DEVICE
0141   Precision GetAlongPhi1Y() const { return fCone.fAlongPhi1y; }
0142   VECCORE_ATT_HOST_DEVICE
0143   Precision GetAlongPhi2X() const { return fCone.fAlongPhi2x; }
0144   VECCORE_ATT_HOST_DEVICE
0145   Precision GetAlongPhi2Y() const { return fCone.fAlongPhi2y; }
0146   VECCORE_ATT_HOST_DEVICE
0147   evolution::Wedge const &GetWedge() const { return fCone.fPhiWedge; }
0148 
0149   VECCORE_ATT_HOST_DEVICE
0150   void SetAndCheckSPhiAngle(Precision sPhi);
0151 
0152   VECCORE_ATT_HOST_DEVICE
0153   void SetAndCheckDPhiAngle(Precision dPhi);
0154 
0155   void SetRmin1(Precision const &arg)
0156   {
0157     fCone.fRmin1 = arg;
0158     fCone.CalculateCached();
0159   }
0160   void SetRmax1(Precision const &arg)
0161   {
0162     fCone.fRmax1 = arg;
0163     fCone.CalculateCached();
0164   }
0165   void SetRmin2(Precision const &arg)
0166   {
0167     fCone.fRmin2 = arg;
0168     fCone.CalculateCached();
0169   }
0170   void SetRmax2(Precision const &arg)
0171   {
0172     fCone.fRmax2 = arg;
0173     fCone.CalculateCached();
0174   }
0175   void SetDz(Precision const &arg)
0176   {
0177     fCone.fDz = arg;
0178     fCone.CalculateCached();
0179   }
0180   void SetSPhi(Precision const &arg)
0181   {
0182     fCone.fSPhi = arg;
0183     fCone.SetAndCheckSPhiAngle(fCone.fSPhi);
0184     DetectConvexity();
0185   }
0186   void SetDPhi(Precision const &arg)
0187   {
0188     fCone.fDPhi = arg;
0189     fCone.SetAndCheckDPhiAngle(fCone.fDPhi);
0190     DetectConvexity();
0191   }
0192 
0193   VECCORE_ATT_HOST_DEVICE
0194   bool IsFullPhi() const { return fCone.fDPhi == kTwoPi; }
0195 
0196   virtual int MemorySize() const override { return sizeof(*this); }
0197 
0198   VECCORE_ATT_HOST_DEVICE
0199   virtual void Print() const final;
0200   virtual void Print(std::ostream &os) const final;
0201 
0202   std::string GetEntityType() const { return "Cone"; }
0203   std::ostream &StreamInfo(std::ostream &os) const;
0204 
0205 #ifndef VECCORE_CUDA
0206   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0207 #endif
0208 
0209   VECCORE_ATT_DEVICE
0210   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0211 #ifdef VECCORE_CUDA
0212                                const int id, const int copy_no, const int child_id,
0213 #endif
0214                                VPlacedVolume *const placement = NULL);
0215 
0216 #ifdef VECGEOM_CUDA_INTERFACE
0217   virtual size_t DeviceSizeOf() const override
0218   {
0219     return DevicePtr<cuda::SUnplacedCone<cuda::ConeTypes::UniversalCone>>::SizeOf();
0220   }
0221   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0222   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0223 #endif
0224 
0225   Precision Capacity() const override
0226   {
0227     return (fCone.fDz * fCone.fDPhi / 3.) *
0228            (fCone.fRmax1 * fCone.fRmax1 + fCone.fRmax2 * fCone.fRmax2 + fCone.fRmax1 * fCone.fRmax2 -
0229             fCone.fRmin1 * fCone.fRmin1 - fCone.fRmin2 * fCone.fRmin2 - fCone.fRmin1 * fCone.fRmin2);
0230   }
0231 
0232   Precision SurfaceArea() const override
0233   {
0234     Precision mmin, mmax, dmin, dmax;
0235     mmin = (fCone.fRmin1 + fCone.fRmin2) * 0.5;
0236     mmax = (fCone.fRmax1 + fCone.fRmax2) * 0.5;
0237     dmin = (fCone.fRmin2 - fCone.fRmin1);
0238     dmax = (fCone.fRmax2 - fCone.fRmax1);
0239 
0240     return fCone.fDPhi * (mmin * std::sqrt(dmin * dmin + 4 * fCone.fDz * fCone.fDz) +
0241                           mmax * std::sqrt(dmax * dmax + 4 * fCone.fDz * fCone.fDz) +
0242                           0.5 * (fCone.fRmax1 * fCone.fRmax1 - fCone.fRmin1 * fCone.fRmin1 +
0243                                  fCone.fRmax2 * fCone.fRmax2 - fCone.fRmin2 * fCone.fRmin2));
0244   }
0245 
0246   VECCORE_ATT_HOST_DEVICE
0247   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override;
0248 
0249   VECCORE_ATT_HOST_DEVICE
0250   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0251 
0252   Vector3D<Precision> SamplePointOnSurface() const override;
0253 
0254   // Helper funtion to detect edge points
0255   template <bool top>
0256   bool IsOnZPlane(Vector3D<Precision> const &point) const;
0257   template <bool start>
0258   bool IsOnPhiWedge(Vector3D<Precision> const &point) const;
0259   template <bool inner>
0260   bool IsOnConicalSurface(Vector3D<Precision> const &point) const;
0261   template <bool inner>
0262   Precision GetRadiusOfConeAtPoint(Precision const pointZ) const;
0263 
0264   bool IsOnEdge(Vector3D<Precision> &point) const;
0265 
0266 #ifndef VECCORE_CUDA
0267 #ifdef VECGEOM_ROOT
0268   TGeoShape const *ConvertToRoot(char const *label) const;
0269 #endif
0270 
0271 #ifdef VECGEOM_GEANT4
0272   G4VSolid const *ConvertToGeant4(char const *label) const;
0273 #endif
0274 #endif
0275 };
0276 
0277 template <>
0278 struct Maker<UnplacedCone> {
0279   template <typename... ArgTypes>
0280   static UnplacedCone *MakeInstance(Precision const &_rmin1, Precision const &_rmax1, Precision const &_rmin2,
0281                                     Precision const &_rmax2, Precision const &_dz, Precision const &_phimin,
0282                                     Precision const &_deltaphi);
0283 };
0284 
0285 // this class finishes the implementation
0286 
0287 template <typename ConeType = ConeTypes::UniversalCone>
0288 class SUnplacedCone : public UnplacedVolumeImplHelper<ConeImplementation<ConeType>, UnplacedCone>,
0289                       public vecgeom::AlignedBase {
0290 public:
0291   using Kernel     = ConeImplementation<ConeType>;
0292   using BaseType_t = UnplacedVolumeImplHelper<ConeImplementation<ConeType>, UnplacedCone>;
0293   using BaseType_t::BaseType_t;
0294 
0295   VECCORE_ATT_DEVICE
0296   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0297 #ifdef VECCORE_CUDA
0298                                const int id, const int copy_no, const int child_id,
0299 #endif
0300                                VPlacedVolume *const placement = NULL);
0301 
0302 #ifndef VECCORE_CUDA
0303   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0304                                            Transformation3D const *const transformation,
0305                                            VPlacedVolume *const placement = NULL) const override
0306   {
0307     return VolumeFactory::CreateByTransformation<SUnplacedCone<ConeType>>(volume, transformation, placement);
0308   }
0309 
0310 #else
0311   VECCORE_ATT_DEVICE
0312   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0313                                            Transformation3D const *const transformation, const int id,
0314                                            const int copy_no, const int child_id,
0315                                            VPlacedVolume *const placement = NULL) const override
0316   {
0317     return VolumeFactory::CreateByTransformation<SUnplacedCone<ConeType>>(volume, transformation, id, copy_no, child_id,
0318                                                                           placement);
0319   }
0320 #endif
0321 };
0322 
0323 using GenericUnplacedCone = SUnplacedCone<ConeTypes::UniversalCone>;
0324 
0325 } // namespace VECGEOM_IMPL_NAMESPACE
0326 } // namespace vecgeom
0327 
0328 // we include this header here because SpecializedCone
0329 // implements the Create function of SUnplacedCone<> (and to avoid a circular dependency)
0330 #include "VecGeom/volumes/SpecializedCone.h"
0331 
0332 #endif // VECGEOM_VOLUMES_UNPLACEDCONE_H_