Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-03 09:09:49

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4TwistTubsHypeSide
0027 //
0028 // Class description:
0029 //
0030 // Class describing a hyperbolic boundary surface for a cylinder.
0031 
0032 // Author: Kotoyo Hoshina (Chiba University), 01.08.2002 - Created.
0033 //         Oliver Link (CERN), 13.11.2003 - Integration in Geant4
0034 //               from original version in Jupiter-2.5.02 application.
0035 // --------------------------------------------------------------------
0036 #ifndef G4TWISTTUBSHYPESIDE_HH
0037 #define G4TWISTTUBSHYPESIDE_HH
0038 
0039 #include "G4VTwistSurface.hh"
0040 #include "G4Integrator.hh"
0041 #include "G4SimpleIntegration.hh"
0042 
0043 /**
0044  * @brief G4TwistTubsHypeSide describes hyperbolic boundary surface
0045  * for a cylinder.
0046  */
0047 
0048 class G4TwistTubsHypeSide : public G4VTwistSurface
0049 {
0050   public:
0051                        
0052     /**
0053      * Constructs a cylinder hyperbolic boundary surface, given its parameters.
0054      *  @param[in] name The surface name.
0055      *  @param[in] rot Rotation: 0.5*(phi-width segment).
0056      *  @param[in] tlate Translation.
0057      *  @param[in] handedness Orientation: R-hand = 1, L-hand = -1.
0058      *  @param[in] kappa Kappa=tan(TwistAngle/2)/fZHalfLen.
0059      *  @param[in] tanstereo Tangent of the stereo angle.
0060      *  @param[in] r0 Radius at z = 0.
0061      *  @param[in] axis0 Phi axis.
0062      *  @param[in] axis1 Z axis.
0063      *  @param[in] axis0min Minimum in Phi.
0064      *  @param[in] axis1min Minimum in Z.
0065      *  @param[in] axis0max Maximum in Phi.
0066      *  @param[in] axis1max Maximum in Z.
0067      */
0068     G4TwistTubsHypeSide(const G4String& name,
0069                         const G4RotationMatrix& rot,  // 0.5*(phi-width segment)
0070                         const G4ThreeVector& tlate,
0071                         const G4int handedness,   // R-hand = 1, L-hand = -1
0072                         const G4double kappa,     // tan(TwistAngle/2)/fZHalfLen
0073                         const G4double tanstereo, // tan(stereo angle)
0074                         const G4double r0,        // radius at z = 0
0075                         const EAxis axis0 = kPhi,
0076                         const EAxis axis1 = kZAxis,
0077                               G4double axis0min = -kInfinity,
0078                               G4double axis1min = -kInfinity,
0079                               G4double axis0max = kInfinity,
0080                               G4double axis1max = kInfinity); 
0081                              
0082     /**
0083      * Alternative Construct for a cylinder hyperbolic boundary surface.
0084      *  @param[in] name The surface name.
0085      *  @param[in] EndInnerRadius Inner-hype radius at z=0.
0086      *  @param[in] EndOuterRadius Outer-hype radius at z=0.
0087      *  @param[in] DPhi Phi angle.
0088      *  @param[in] EndPhi Total Phi.
0089      *  @param[in] EndZ Z length.
0090      *  @param[in] InnerRadius Inner radius.
0091      *  @param[in] OuterRadius Outer radius.
0092      *  @param[in] Kappa Kappa=tan(TwistAngle/2)/fZHalfLen.
0093      *  @param[in] TanInnerStereo Tangent inner stereo angle.
0094      *  @param[in] TanOuterStereo Tangent outer stereo angle.
0095      *  @param[in] handedness Orientation: R-hand = 1, L-hand = -1.
0096      */
0097    G4TwistTubsHypeSide(const G4String&  name,
0098                              G4double   EndInnerRadius[2],
0099                              G4double   EndOuterRadius[2],
0100                              G4double   DPhi,
0101                              G4double   EndPhi[2],
0102                              G4double   EndZ[2], 
0103                              G4double   InnerRadius,
0104                              G4double   OuterRadius,
0105                              G4double   Kappa,
0106                              G4double   TanInnerStereo,
0107                              G4double   TanOuterStereo,
0108                              G4int      handedness) ;
0109 
0110     /**
0111      * Default destructor.
0112      */
0113     ~G4TwistTubsHypeSide() override = default;
0114 
0115     /**
0116      * Returns the distance to surface, given point 'gp' and direction 'gv'.
0117      *  @param[in] gp The point from where computing the distance.
0118      *  @param[in] gv The direction along which computing the distance.
0119      *  @param[out] gxx Vector of global points based on number of solutions.
0120      *  @param[out] distance The distance vector based on number of solutions.
0121      *  @param[out] areacode The location vector based on number of solutions.
0122      *  @param[out] isvalid Validity vector based on number of solutions.
0123      *  @param[in] validate Adopted validation criteria.
0124      *  @returns The number of solutions.
0125      */
0126     G4int DistanceToSurface(const G4ThreeVector& gp,
0127                             const G4ThreeVector& gv,
0128                                   G4ThreeVector  gxx[],
0129                                   G4double       distance[],
0130                                   G4int          areacode[],
0131                                   G4bool         isvalid[],
0132                             EValidate validate = kValidateWithTol) override;
0133                                                    
0134     /**
0135      * Returns the safety distance to surface, given point 'gp'.
0136      *  @param[in] gp The point from where computing the safety distance.
0137      *  @param[out] gxx Vector of global points based on number of solutions.
0138      *  @param[out] distance The distance vector based on number of solutions.
0139      *  @param[out] areacode The location vector based on number of solutions.
0140      *  @returns The number of solutions.
0141      */
0142     G4int DistanceToSurface(const G4ThreeVector& gp,
0143                                   G4ThreeVector  gxx[],
0144                                   G4double       distance[],
0145                                   G4int          areacode[]) override;
0146  
0147     /**
0148      * Returns a normal vector at a surface (or very close to the surface)
0149      * point at 'p'.
0150      *  @param[in] p The point where computing the normal.
0151      *  @param[in] isGlobal If true, it returns the normal in global coordinates.
0152      *  @returns The normal vector.
0153      */
0154     G4ThreeVector GetNormal(const G4ThreeVector& p,
0155                                   G4bool isGlobal = false) override ;
0156 
0157     /**
0158      * Returns if point at 'gp' is inside surface.
0159      */
0160     EInside Inside(const G4ThreeVector& gp) ;
0161 
0162     /**
0163      * Gets Rho at p.z() on Hyperbolic Surface.
0164      */
0165     inline G4double GetRhoAtPZ(const G4ThreeVector& p,
0166                                      G4bool isglobal = false) const ;
0167 
0168     /**
0169      * Fake default constructor for usage restricted to direct object
0170      * persistency for clients requiring preallocation of memory for
0171      * persistifiable objects.
0172      */
0173     G4TwistTubsHypeSide(__void__&);
0174 
0175   private:
0176 
0177     /**
0178      * Returns point on surface given 'phi' and 'z'.
0179      */
0180     inline G4ThreeVector SurfacePoint(G4double phi, G4double z,
0181                                       G4bool isGlobal = false) override ;  
0182 
0183     /**
0184      * Internal accessors.
0185      */
0186     inline G4double GetBoundaryMin(G4double phi) override ;
0187     inline G4double GetBoundaryMax(G4double phi) override ;
0188     inline G4double GetSurfaceArea() override ;
0189     void GetFacets( G4int m, G4int n, G4double xyz[][3],
0190                     G4int faces[][4], G4int iside ) override ;
0191     
0192     /**
0193      * Returns the area code for point 'xx' using or not surface tolerance.
0194      */
0195     G4int GetAreaCode(const G4ThreeVector& xx, 
0196                             G4bool withTol = true) override;
0197     G4int GetAreaCodeInPhi(const G4ThreeVector& xx, 
0198                                  G4bool withTol = true);
0199 
0200     /**
0201      * Setters.
0202      */
0203     void SetCorners() override;
0204     void SetCorners(G4double EndInnerRadius[2],
0205                     G4double EndOuterRadius[2],
0206                     G4double DPhi,
0207                     G4double EndPhi[2],
0208                     G4double EndZ[2]);
0209     void SetBoundaries() override;
0210 
0211   private:
0212    
0213     G4double fKappa;        // std::tan(TwistedAngle/2)/HalfLenZ;
0214     G4double fTanStereo;    // std::tan(StereoAngle)
0215     G4double fTan2Stereo;   // std::tan(StereoAngle)**2
0216     G4double fR0;           // radius at z = 0
0217     G4double fR02;          // radius**2 at z = 0
0218     G4double fDPhi ;        // segment
0219 
0220     class Insidetype
0221     {
0222       public:
0223 
0224         G4ThreeVector gp;
0225         EInside       inside;
0226     };
0227     Insidetype fInside;
0228 };
0229 
0230 //========================================================
0231 // inline functions
0232 //========================================================
0233 
0234 inline
0235 G4double G4TwistTubsHypeSide::GetRhoAtPZ(const G4ThreeVector& p,
0236                                                G4bool isglobal) const 
0237 {
0238   // Get Rho at p.z() on Hyperbolic Surface.
0239   G4ThreeVector tmpp;
0240   if (isglobal) { tmpp = fRot.inverse()*p - fTrans; }
0241   else          { tmpp = p; }
0242 
0243   return std::sqrt(fR02 + tmpp.z() * tmpp.z() * fTan2Stereo); 
0244 }
0245 
0246 inline
0247 G4ThreeVector G4TwistTubsHypeSide::
0248 SurfacePoint(G4double phi , G4double z , G4bool isGlobal)
0249 {
0250   G4double rho = std::sqrt(fR02 + z * z * fTan2Stereo) ;
0251 
0252   G4ThreeVector SurfPoint (rho*std::cos(phi), rho*std::sin(phi), z) ;
0253 
0254   if (isGlobal) { return (fRot * SurfPoint + fTrans); }
0255   return SurfPoint;
0256 }
0257 
0258 inline
0259 G4double G4TwistTubsHypeSide::GetBoundaryMin(G4double z)
0260 {
0261   G4ThreeVector ptmp(0,0,z) ;  // temporary point with z Komponent only
0262   G4ThreeVector lowerlimit;    // lower phi-boundary limit at z = ptmp.z()
0263   lowerlimit = GetBoundaryAtPZ(sAxis0 & sAxisMin, ptmp);
0264   return  std::atan2( lowerlimit.y(), lowerlimit.x() ) ;  
0265 }
0266 
0267 inline
0268 G4double G4TwistTubsHypeSide::GetBoundaryMax(G4double z )
0269 {
0270   G4ThreeVector ptmp(0,0,z) ;  // temporary point with z Komponent only
0271   G4ThreeVector upperlimit;    // upper phi-boundary limit at z = ptmp.z()
0272   upperlimit = GetBoundaryAtPZ(sAxis0 & sAxisMax, ptmp);
0273   return   std::atan2( upperlimit.y(), upperlimit.x() ) ;
0274 }
0275 
0276 inline
0277 G4double G4TwistTubsHypeSide::GetSurfaceArea()
0278 {
0279   // approximation with tube surface
0280 
0281   return ( fAxisMax[1] - fAxisMin[1] ) * fR0 * fDPhi ;
0282 }
0283 
0284 #endif