Back to home page

EIC code displayed by LXR

 
 

    


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

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   ConeStruct<Precision> const &GetStruct() const { return fCone; }
0069 
0070   VECCORE_ATT_HOST_DEVICE
0071   Precision GetInvSecRMax() const { return fCone.fInvSecRMax; }
0072 
0073   VECCORE_ATT_HOST_DEVICE
0074   Precision GetInvSecRMin() const { return fCone.fInvSecRMin; }
0075 
0076   VECCORE_ATT_HOST_DEVICE
0077   Precision GetTolIz() const { return fCone.fTolIz; }
0078   VECCORE_ATT_HOST_DEVICE
0079   Precision GetTolOz() const { return fCone.fTolOz; }
0080 
0081   VECCORE_ATT_HOST_DEVICE
0082   Precision GetConeTolerane() const { return fCone.fConeTolerance; }
0083   VECCORE_ATT_HOST_DEVICE
0084   Precision GetSqRmin1() const { return fCone.fSqRmin1; }
0085   VECCORE_ATT_HOST_DEVICE
0086   Precision GetSqRmin2() const { return fCone.fSqRmin2; }
0087   VECCORE_ATT_HOST_DEVICE
0088   Precision GetSqRmax1() const { return fCone.fSqRmax1; }
0089   VECCORE_ATT_HOST_DEVICE
0090   Precision GetSqRmax2() const { return fCone.fSqRmax2; }
0091   VECCORE_ATT_HOST_DEVICE
0092   Precision GetTanRmax() const { return fCone.fTanRMax; }
0093   VECCORE_ATT_HOST_DEVICE
0094   Precision GetTanRmin() const { return fCone.fTanRMin; }
0095   VECCORE_ATT_HOST_DEVICE
0096   Precision GetSecRmax() const { return fCone.fSecRMax; }
0097   VECCORE_ATT_HOST_DEVICE
0098   Precision GetSecRmin() const { return fCone.fSecRMin; }
0099   VECCORE_ATT_HOST_DEVICE
0100   Precision GetZNormInner() const { return fCone.fZNormInner; }
0101   VECCORE_ATT_HOST_DEVICE
0102   Precision GetZNormOuter() const { return fCone.fZNormOuter; }
0103   VECCORE_ATT_HOST_DEVICE
0104   Precision GetInnerConeApex() const { return fCone.fInnerConeApex; }
0105   VECCORE_ATT_HOST_DEVICE
0106   Precision GetTInner() const { return fCone.fTanInnerApexAngle; }
0107   VECCORE_ATT_HOST_DEVICE
0108   Precision GetOuterConeApex() const { return fCone.fOuterConeApex; }
0109   VECCORE_ATT_HOST_DEVICE
0110   Precision GetTOuter() const { return fCone.fTanOuterApexAngle; }
0111 
0112   VECCORE_ATT_HOST_DEVICE
0113   void DetectConvexity();
0114   VECCORE_ATT_HOST_DEVICE
0115   Precision GetRmin1() const { return fCone.fRmin1; }
0116   VECCORE_ATT_HOST_DEVICE
0117   Precision GetRmax1() const { return fCone.fRmax1; }
0118   VECCORE_ATT_HOST_DEVICE
0119   Precision GetRmin2() const { return fCone.fRmin2; }
0120   VECCORE_ATT_HOST_DEVICE
0121   Precision GetRmax2() const { return fCone.fRmax2; }
0122   VECCORE_ATT_HOST_DEVICE
0123   Precision GetDz() const { return fCone.fDz; }
0124   VECCORE_ATT_HOST_DEVICE
0125   Precision GetSPhi() const { return fCone.fSPhi; }
0126   VECCORE_ATT_HOST_DEVICE
0127   Precision GetDPhi() const { return fCone.fDPhi; }
0128   VECCORE_ATT_HOST_DEVICE
0129   Precision GetInnerSlope() const { return fCone.fInnerSlope; }
0130   VECCORE_ATT_HOST_DEVICE
0131   Precision GetOuterSlope() const { return fCone.fOuterSlope; }
0132   VECCORE_ATT_HOST_DEVICE
0133   Precision GetInnerOffset() const { return fCone.fInnerOffset; }
0134   VECCORE_ATT_HOST_DEVICE
0135   Precision GetOuterOffset() const { return fCone.fOuterOffset; }
0136   VECCORE_ATT_HOST_DEVICE
0137   Precision GetAlongPhi1X() const { return fCone.fAlongPhi1x; }
0138   VECCORE_ATT_HOST_DEVICE
0139   Precision GetAlongPhi1Y() const { return fCone.fAlongPhi1y; }
0140   VECCORE_ATT_HOST_DEVICE
0141   Precision GetAlongPhi2X() const { return fCone.fAlongPhi2x; }
0142   VECCORE_ATT_HOST_DEVICE
0143   Precision GetAlongPhi2Y() const { return fCone.fAlongPhi2y; }
0144   VECCORE_ATT_HOST_DEVICE
0145   evolution::Wedge const &GetWedge() const { return fCone.fPhiWedge; }
0146 
0147   VECCORE_ATT_HOST_DEVICE
0148   void SetAndCheckSPhiAngle(Precision sPhi);
0149 
0150   VECCORE_ATT_HOST_DEVICE
0151   void SetAndCheckDPhiAngle(Precision dPhi);
0152 
0153   void SetRmin1(Precision const &arg)
0154   {
0155     fCone.fRmin1 = arg;
0156     fCone.CalculateCached();
0157   }
0158   void SetRmax1(Precision const &arg)
0159   {
0160     fCone.fRmax1 = arg;
0161     fCone.CalculateCached();
0162   }
0163   void SetRmin2(Precision const &arg)
0164   {
0165     fCone.fRmin2 = arg;
0166     fCone.CalculateCached();
0167   }
0168   void SetRmax2(Precision const &arg)
0169   {
0170     fCone.fRmax2 = arg;
0171     fCone.CalculateCached();
0172   }
0173   void SetDz(Precision const &arg)
0174   {
0175     fCone.fDz = arg;
0176     fCone.CalculateCached();
0177   }
0178   void SetSPhi(Precision const &arg)
0179   {
0180     fCone.fSPhi = arg;
0181     fCone.SetAndCheckSPhiAngle(fCone.fSPhi);
0182     DetectConvexity();
0183   }
0184   void SetDPhi(Precision const &arg)
0185   {
0186     fCone.fDPhi = arg;
0187     fCone.SetAndCheckDPhiAngle(fCone.fDPhi);
0188     DetectConvexity();
0189   }
0190 
0191   VECCORE_ATT_HOST_DEVICE
0192   bool IsFullPhi() const { return fCone.fDPhi == kTwoPi; }
0193 
0194   virtual int MemorySize() const override { return sizeof(*this); }
0195 
0196   VECCORE_ATT_HOST_DEVICE
0197   virtual void Print() const final;
0198   virtual void Print(std::ostream &os) const final;
0199 
0200   std::string GetEntityType() const { return "Cone"; }
0201   std::ostream &StreamInfo(std::ostream &os) const;
0202 
0203 #ifndef VECCORE_CUDA
0204   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0205 #endif
0206 
0207   template <TranslationCode transCodeT, RotationCode rotCodeT>
0208   VECCORE_ATT_DEVICE
0209   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0210 #ifdef VECCORE_CUDA
0211                                const int id, const int copy_no, const int child_id,
0212 #endif
0213                                VPlacedVolume *const placement = NULL);
0214 
0215 #ifdef VECGEOM_CUDA_INTERFACE
0216   virtual size_t DeviceSizeOf() const override
0217   {
0218     return DevicePtr<cuda::SUnplacedCone<cuda::ConeTypes::UniversalCone>>::SizeOf();
0219   }
0220   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0221   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0222 #endif
0223 
0224   Precision Capacity() const override
0225   {
0226     return (fCone.fDz * fCone.fDPhi / 3.) *
0227            (fCone.fRmax1 * fCone.fRmax1 + fCone.fRmax2 * fCone.fRmax2 + fCone.fRmax1 * fCone.fRmax2 -
0228             fCone.fRmin1 * fCone.fRmin1 - fCone.fRmin2 * fCone.fRmin2 - fCone.fRmin1 * fCone.fRmin2);
0229   }
0230 
0231   Precision SurfaceArea() const override
0232   {
0233     Precision mmin, mmax, dmin, dmax;
0234     mmin = (fCone.fRmin1 + fCone.fRmin2) * 0.5;
0235     mmax = (fCone.fRmax1 + fCone.fRmax2) * 0.5;
0236     dmin = (fCone.fRmin2 - fCone.fRmin1);
0237     dmax = (fCone.fRmax2 - fCone.fRmax1);
0238 
0239     return fCone.fDPhi * (mmin * std::sqrt(dmin * dmin + 4 * fCone.fDz * fCone.fDz) +
0240                           mmax * std::sqrt(dmax * dmax + 4 * fCone.fDz * fCone.fDz) +
0241                           0.5 * (fCone.fRmax1 * fCone.fRmax1 - fCone.fRmin1 * fCone.fRmin1 +
0242                                  fCone.fRmax2 * fCone.fRmax2 - fCone.fRmin2 * fCone.fRmin2));
0243   }
0244 
0245   VECCORE_ATT_HOST_DEVICE
0246   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override;
0247 
0248   VECCORE_ATT_HOST_DEVICE
0249   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0250 
0251   Vector3D<Precision> SamplePointOnSurface() const override;
0252 
0253   // Helper funtion to detect edge points
0254   template <bool top>
0255   bool IsOnZPlane(Vector3D<Precision> const &point) const;
0256   template <bool start>
0257   bool IsOnPhiWedge(Vector3D<Precision> const &point) const;
0258   template <bool inner>
0259   bool IsOnConicalSurface(Vector3D<Precision> const &point) const;
0260   template <bool inner>
0261   Precision GetRadiusOfConeAtPoint(Precision const pointZ) const;
0262 
0263   bool IsOnEdge(Vector3D<Precision> &point) const;
0264 
0265 #ifndef VECCORE_CUDA
0266 #ifdef VECGEOM_ROOT
0267   TGeoShape const *ConvertToRoot(char const *label) const;
0268 #endif
0269 
0270 #ifdef VECGEOM_GEANT4
0271   G4VSolid const *ConvertToGeant4(char const *label) const;
0272 #endif
0273 #endif
0274 };
0275 
0276 template <>
0277 struct Maker<UnplacedCone> {
0278   template <typename... ArgTypes>
0279   static UnplacedCone *MakeInstance(Precision const &_rmin1, Precision const &_rmax1, Precision const &_rmin2,
0280                                     Precision const &_rmax2, Precision const &_dz, Precision const &_phimin,
0281                                     Precision const &_deltaphi);
0282 };
0283 
0284 // this class finishes the implementation
0285 
0286 template <typename ConeType = ConeTypes::UniversalCone>
0287 class SUnplacedCone : public SIMDUnplacedVolumeImplHelper<ConeImplementation<ConeType>, UnplacedCone>,
0288                       public vecgeom::AlignedBase {
0289 public:
0290   using Kernel     = ConeImplementation<ConeType>;
0291   using BaseType_t = SIMDUnplacedVolumeImplHelper<ConeImplementation<ConeType>, UnplacedCone>;
0292   using BaseType_t::BaseType_t;
0293 
0294   template <TranslationCode transCodeT, RotationCode rotCodeT>
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                                            const TranslationCode trans_code, const RotationCode rot_code,
0306                                            VPlacedVolume *const placement = NULL) const override
0307   {
0308     return VolumeFactory::CreateByTransformation<SUnplacedCone<ConeType>>(volume, transformation, trans_code, rot_code,
0309                                                                           placement);
0310   }
0311 
0312 #else
0313   VECCORE_ATT_DEVICE
0314   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0315                                            Transformation3D const *const transformation,
0316                                            const TranslationCode trans_code, const RotationCode rot_code, const int id,
0317                                            const int copy_no, const int child_id,
0318                                            VPlacedVolume *const placement = NULL) const override
0319   {
0320     return VolumeFactory::CreateByTransformation<SUnplacedCone<ConeType>>(volume, transformation, trans_code, rot_code,
0321                                                                           id, copy_no, child_id, placement);
0322   }
0323 #endif
0324 };
0325 
0326 using GenericUnplacedCone = SUnplacedCone<ConeTypes::UniversalCone>;
0327 
0328 } // namespace VECGEOM_IMPL_NAMESPACE
0329 } // namespace vecgeom
0330 
0331 // we include this header here because SpecializedCone
0332 // implements the Create function of SUnplacedCone<> (and to avoid a circular dependency)
0333 #include "VecGeom/volumes/SpecializedCone.h"
0334 
0335 #endif // VECGEOM_VOLUMES_UNPLACEDCONE_H_