2 // ********************************************************************
 
    3 // * License and Disclaimer                                           *
 
    5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
 
    6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
 
    7 // * conditions of the Geant4 Software License,  included in the file *
 
    8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
 
    9 // * include a list of copyright holders.                             *
 
   11 // * Neither the authors of this software system, nor their employing *
 
   12 // * institutes,nor the agencies providing financial support for this *
 
   13 // * work  make  any representation or  warranty, express or implied, *
 
   14 // * regarding  this  software system or assume any liability for its *
 
   15 // * use.  Please see the license in the file  LICENSE  and URL above *
 
   16 // * for the full disclaimer and the limitation of liability.         *
 
   18 // * This  code  implementation is the result of  the  scientific and *
 
   19 // * technical work of the GEANT4 collaboration.                      *
 
   20 // * By using,  copying,  modifying or  distributing the software (or *
 
   21 // * any work based  on the software)  you  agree  to acknowledge its *
 
   22 // * use  in  resulting  scientific  publications,  and indicate your *
 
   23 // * acceptance of all terms of the Geant4 Software license.          *
 
   24 // ********************************************************************
 
   27 // $Id: G4Tubs.icc 84622 2014-10-17 09:43:17Z gcosmo $
 
   29 // --------------------------------------------------------------------
 
   30 // GEANT 4 inline definitions file
 
   34 // Implementation of inline methods of G4Tubs
 
   35 // --------------------------------------------------------------------
 
   38 G4double G4Tubs::GetInnerRadius () const
 
   44 G4double G4Tubs::GetOuterRadius () const
 
   50 G4double G4Tubs::GetZHalfLength () const
 
   56 G4double G4Tubs::GetStartPhiAngle () const
 
   62 G4double G4Tubs::GetDeltaPhiAngle () const
 
   68 void G4Tubs::Initialize()
 
   72   fRebuildPolyhedron = true;
 
   76 void G4Tubs::InitializeTrigonometry()
 
   78   G4double hDPhi = 0.5*fDPhi;                       // half delta phi
 
   79   G4double cPhi  = fSPhi + hDPhi; 
 
   80   G4double ePhi  = fSPhi + fDPhi;
 
   82   sinCPhi    = std::sin(cPhi);
 
   83   cosCPhi    = std::cos(cPhi);
 
   84   cosHDPhiIT = std::cos(hDPhi - 0.5*kAngTolerance); // inner/outer tol half dphi
 
   85   cosHDPhiOT = std::cos(hDPhi + 0.5*kAngTolerance);
 
   86   sinSPhi = std::sin(fSPhi);
 
   87   cosSPhi = std::cos(fSPhi);
 
   88   sinEPhi = std::sin(ePhi);
 
   89   cosEPhi = std::cos(ePhi);
 
   92 inline void G4Tubs::CheckSPhiAngle(G4double sPhi)
 
   94   // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
 
   98     fSPhi = CLHEP::twopi - std::fmod(std::fabs(sPhi),CLHEP::twopi);
 
  102     fSPhi = std::fmod(sPhi,CLHEP::twopi) ;
 
  104   if ( fSPhi+fDPhi > CLHEP::twopi )
 
  106     fSPhi -= CLHEP::twopi ;
 
  110 inline void G4Tubs::CheckDPhiAngle(G4double dPhi)
 
  113   if ( dPhi >= CLHEP::twopi-kAngTolerance*0.5 )
 
  120     fPhiFullTube = false;
 
  127       std::ostringstream message;
 
  128       message << "Invalid dphi." << G4endl
 
  129               << "Negative or zero delta-Phi (" << dPhi << "), for solid: "
 
  131       G4Exception("G4Tubs::CheckDPhiAngle()", "GeomSolids0002",
 
  132                   FatalException, message);
 
  137 inline void G4Tubs::CheckPhiAngles(G4double sPhi, G4double dPhi)
 
  139   CheckDPhiAngle(dPhi);
 
  140   if ( (fDPhi<CLHEP::twopi) && (sPhi) ) { CheckSPhiAngle(sPhi); }
 
  141   InitializeTrigonometry();
 
  145 void G4Tubs::SetInnerRadius (G4double newRMin)
 
  147   if ( newRMin < 0 ) // Check radii
 
  149     std::ostringstream message;
 
  150     message << "Invalid radii." << G4endl
 
  151             << "Invalid values for radii in solid " << GetName() << G4endl
 
  152             << "        newRMin = " << newRMin
 
  153             << ", fRMax = " << fRMax << G4endl
 
  154             << "        Negative inner radius!";
 
  155     G4Exception("G4Tubs::SetInnerRadius()", "GeomSolids0002",
 
  156                 FatalException, message);
 
  163 void G4Tubs::SetOuterRadius (G4double newRMax)
 
  165   if ( newRMax <= 0 ) // Check radii
 
  167     std::ostringstream message;
 
  168     message << "Invalid radii." << G4endl
 
  169             << "Invalid values for radii in solid " << GetName() << G4endl
 
  170             << "        fRMin = " << fRMin
 
  171             << ", newRMax = " << newRMax << G4endl
 
  172             << "        Invalid outer radius!";
 
  173     G4Exception("G4Tubs::SetOuterRadius()", "GeomSolids0002",
 
  174                 FatalException, message);
 
  181 void G4Tubs::SetZHalfLength (G4double newDz)
 
  183   if (newDz<=0) // Check z-len
 
  185     std::ostringstream message;
 
  186     message << "Invalid Z half-length." << G4endl
 
  187             << "Negative Z half-length (" << newDz << "), for solid: "
 
  189     G4Exception("G4Tubs::SetZHalfLength()", "GeomSolids0002",
 
  190                 FatalException, message);
 
  197 void G4Tubs::SetStartPhiAngle (G4double newSPhi, G4bool compute)
 
  199   // Flag 'compute' can be used to explicitely avoid recomputation of
 
  200   // trigonometry in case SetDeltaPhiAngle() is invoked afterwards
 
  202   CheckSPhiAngle(newSPhi);
 
  203   fPhiFullTube = false;
 
  204   if (compute)  { InitializeTrigonometry(); }
 
  209 void G4Tubs::SetDeltaPhiAngle (G4double newDPhi)
 
  211   CheckPhiAngles(fSPhi, newDPhi);
 
  215 //  Older names for access functions
 
  218 G4double G4Tubs::GetRMin () const
 
  220   return GetInnerRadius();
 
  224 G4double G4Tubs::GetRMax () const
 
  226   return GetOuterRadius();
 
  230 G4double G4Tubs::GetDz () const
 
  232   return GetZHalfLength()  ;
 
  236 G4double G4Tubs::GetSPhi () const
 
  238   return GetStartPhiAngle();
 
  242 G4double G4Tubs::GetDPhi () const
 
  244   return GetDeltaPhiAngle();
 
  248 G4double G4Tubs::GetCubicVolume()
 
  250   if(fCubicVolume != 0.) {;}
 
  251   else   { fCubicVolume = fDPhi*fDz*(fRMax*fRMax-fRMin*fRMin); }
 
  256 G4double G4Tubs::GetSurfaceArea()
 
  258   if(fSurfaceArea != 0.) {;}
 
  261     fSurfaceArea = fDPhi*(fRMin+fRMax)*(2*fDz+fRMax-fRMin);
 
  264       fSurfaceArea = fSurfaceArea + 4*fDz*(fRMax-fRMin);