Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:14

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 // Implementation of inline methods of G4Tubs
0027 // --------------------------------------------------------------------
0028 
0029 inline
0030 G4double G4Tubs::GetInnerRadius () const
0031 {
0032   return fRMin;
0033 }
0034 
0035 inline
0036 G4double G4Tubs::GetOuterRadius () const
0037 {
0038   return fRMax;
0039 }
0040 
0041 inline
0042 G4double G4Tubs::GetZHalfLength () const
0043 {
0044   return fDz;
0045 }
0046 
0047 inline
0048 G4double G4Tubs::GetStartPhiAngle () const
0049 {
0050   return fSPhi;
0051 }
0052 
0053 inline
0054 G4double G4Tubs::GetDeltaPhiAngle () const
0055 {
0056   return fDPhi;
0057 }
0058 
0059 inline
0060 G4double G4Tubs::GetSinStartPhi () const
0061 {
0062   return sinSPhi;
0063 }
0064 
0065 inline
0066 G4double G4Tubs::GetCosStartPhi () const
0067 {
0068   return cosSPhi;
0069 }
0070 
0071 inline
0072 G4double G4Tubs::GetSinEndPhi () const
0073 {
0074   return sinEPhi;
0075 }
0076 
0077 inline
0078 G4double G4Tubs::GetCosEndPhi () const
0079 {
0080   return cosEPhi;
0081 }
0082 
0083 inline
0084 void G4Tubs::Initialize()
0085 {
0086   fCubicVolume = 0.;
0087   fSurfaceArea = 0.;
0088   fInvRmax= 1.0 / fRMax;
0089   fInvRmin= fRMin > 0. ? 1.0 / fRMin : 0.0;
0090   fRebuildPolyhedron = true;
0091 }
0092 
0093 inline
0094 void G4Tubs::InitializeTrigonometry()
0095 {
0096   G4double hDPhi = 0.5*fDPhi;                       // half delta phi
0097   G4double cPhi  = fSPhi + hDPhi;
0098   G4double ePhi  = fSPhi + fDPhi;
0099 
0100   sinCPhi    = std::sin(cPhi);
0101   cosCPhi    = std::cos(cPhi);
0102   cosHDPhi   = std::cos(hDPhi);
0103   cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
0104   cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
0105   sinSPhi = std::sin(fSPhi);
0106   cosSPhi = std::cos(fSPhi);
0107   sinEPhi = std::sin(ePhi);
0108   cosEPhi = std::cos(ePhi);
0109 }
0110 
0111 inline void G4Tubs::CheckSPhiAngle(G4double sPhi)
0112 {
0113   // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
0114 
0115   if ( sPhi < 0 )
0116   {
0117     fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi);
0118   }
0119   else
0120   {
0121     fSPhi = std::fmod(sPhi,CLHEP::twopi) ;
0122   }
0123   if ( fSPhi+fDPhi > CLHEP::twopi )
0124   {
0125     fSPhi -= CLHEP::twopi ;
0126   }
0127 }
0128 
0129 inline void G4Tubs::CheckDPhiAngle(G4double dPhi)
0130 {
0131   fPhiFullTube = true;
0132   if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 )
0133   {
0134     fDPhi=CLHEP::twopi;
0135     fSPhi=0;
0136   }
0137   else
0138   {
0139     fPhiFullTube = false;
0140     if ( dPhi > 0 )
0141     {
0142       fDPhi = dPhi;
0143     }
0144     else
0145     {
0146       std::ostringstream message;
0147       message << "Invalid dphi." << G4endl
0148               << "Negative or zero delta-Phi (" << dPhi << "), for solid: "
0149               << GetName();
0150       G4Exception("G4Tubs::CheckDPhiAngle()", "GeomSolids0002",
0151                   FatalException, message);
0152     }
0153   }
0154 }
0155 
0156 inline void G4Tubs::CheckPhiAngles(G4double sPhi, G4double dPhi)
0157 {
0158   CheckDPhiAngle(dPhi);
0159   if ( (fDPhi<CLHEP::twopi) && ((sPhi) != 0.0) ) { CheckSPhiAngle(sPhi); }
0160   InitializeTrigonometry();
0161 }
0162 
0163 inline
0164 void G4Tubs::SetInnerRadius (G4double newRMin)
0165 {
0166   if ( newRMin < 0 ) // Check radii
0167   {
0168     std::ostringstream message;
0169     message << "Invalid radii." << G4endl
0170             << "Invalid values for radii in solid " << GetName() << G4endl
0171             << "        newRMin = " << newRMin
0172             << ", fRMax = " << fRMax << G4endl
0173             << "        Negative inner radius!";
0174     G4Exception("G4Tubs::SetInnerRadius()", "GeomSolids0002",
0175                 FatalException, message);
0176   }
0177   fRMin= newRMin;
0178   Initialize();
0179 }
0180 
0181 inline
0182 void G4Tubs::SetOuterRadius (G4double newRMax)
0183 {
0184   if ( newRMax <= 0 ) // Check radii
0185   {
0186     std::ostringstream message;
0187     message << "Invalid radii." << G4endl
0188             << "Invalid values for radii in solid " << GetName() << G4endl
0189             << "        fRMin = " << fRMin
0190             << ", newRMax = " << newRMax << G4endl
0191             << "        Invalid outer radius!";
0192     G4Exception("G4Tubs::SetOuterRadius()", "GeomSolids0002",
0193                 FatalException, message);
0194   }
0195   fRMax= newRMax;
0196   Initialize();
0197 }
0198 
0199 inline
0200 void G4Tubs::SetZHalfLength (G4double newDz)
0201 {
0202   if (newDz<=0) // Check z-len
0203   {
0204     std::ostringstream message;
0205     message << "Invalid Z half-length." << G4endl
0206             << "Negative Z half-length (" << newDz << "), for solid: "
0207             << GetName();
0208     G4Exception("G4Tubs::SetZHalfLength()", "GeomSolids0002",
0209                 FatalException, message);
0210   }
0211   fDz= newDz;
0212   Initialize();
0213 }
0214 
0215 inline
0216 void G4Tubs::SetStartPhiAngle (G4double newSPhi, G4bool compute)
0217 {
0218   // Flag 'compute' can be used to explicitely avoid recomputation of
0219   // trigonometry in case SetDeltaPhiAngle() is invoked afterwards
0220 
0221   CheckSPhiAngle(newSPhi);
0222   fPhiFullTube = false;
0223   if (compute)  { InitializeTrigonometry(); }
0224   Initialize();
0225 }
0226 
0227 inline
0228 void G4Tubs::SetDeltaPhiAngle (G4double newDPhi)
0229 {
0230   CheckPhiAngles(fSPhi, newDPhi);
0231   Initialize();
0232 }
0233 
0234 inline
0235 G4double G4Tubs::GetCubicVolume()
0236 {
0237   if(fCubicVolume != 0.) {;}
0238   else   { fCubicVolume = fDPhi*fDz*(fRMax*fRMax-fRMin*fRMin); }
0239   return fCubicVolume;
0240 }
0241 
0242 inline
0243 G4double G4Tubs::GetSurfaceArea()
0244 {
0245   if(fSurfaceArea != 0.) {;}
0246   else
0247   {
0248     fSurfaceArea = fDPhi*(fRMin+fRMax)*(2*fDz+fRMax-fRMin);
0249     if (!fPhiFullTube)
0250     {
0251       fSurfaceArea = fSurfaceArea + 4*fDz*(fRMax-fRMin);
0252     }
0253   }
0254   return fSurfaceArea;
0255 }
0256 
0257 inline
0258 G4double G4Tubs::FastInverseRxy( const G4ThreeVector& pos,
0259                                        G4double invRad,
0260                                        G4double tolerance ) const
0261 {
0262   G4double rho2 = sqr( pos.x() ) + sqr( pos.y() );
0263   G4bool onSurface = std::fabs( rho2 * invRad * invRad - 1.0 ) < tolerance;
0264   G4double invRho = onSurface ? invRad : 1.0 / std::sqrt(rho2);
0265   return invRho;
0266 }