G4EnclosingCylinder.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4EnclosingCylinder.cc 67011 2013-01-29 16:17:41Z gcosmo $
00028 //
00029 // 
00030 // --------------------------------------------------------------------
00031 // GEANT 4 class source file
00032 //
00033 //
00034 // G4EnclosingCylinder.cc
00035 //
00036 // Implementation of a utility class for a quick check of geometry.
00037 //
00038 // --------------------------------------------------------------------
00039 
00040 #include "G4EnclosingCylinder.hh"
00041 #include "G4PhysicalConstants.hh"
00042 #include "G4ReduciblePolygon.hh"
00043 #include "G4GeometryTolerance.hh"
00044 
00045 //
00046 // Constructor
00047 //
00048 G4EnclosingCylinder::G4EnclosingCylinder( const G4ReduciblePolygon *rz,
00049                                                 G4bool thePhiIsOpen, 
00050                                                 G4double theStartPhi,
00051                                                 G4double theTotalPhi )
00052   : startPhi(theStartPhi), totalPhi(theTotalPhi),
00053     rx1(0.), ry1(0.), dx1(0.), dy1(0.),
00054     rx2(0.), ry2(0.), dx2(0.), dy2(0.),     
00055     concave(theTotalPhi > pi)
00056 {
00057   //
00058   // Obtain largest r and smallest and largest z
00059   //
00060   radius = rz->Amax();
00061   zHi = rz->Bmax();
00062   zLo = rz->Bmin();
00063 
00064   G4double kCarTolerance = G4GeometryTolerance::GetInstance()
00065                            ->GetSurfaceTolerance();
00066   //
00067   // Save phi info
00068   //
00069   phiIsOpen = thePhiIsOpen;
00070   if ( phiIsOpen )
00071   {    
00072     rx1 = std::cos(startPhi);
00073     ry1 = std::sin(startPhi);
00074     dx1 = +ry1*10*kCarTolerance;
00075     dy1 = -rx1*10*kCarTolerance;
00076     
00077     rx2 = std::cos(startPhi+totalPhi);
00078     ry2 = std::sin(startPhi+totalPhi);
00079     dx2 = -ry2*10*kCarTolerance;
00080     dy2 = +rx2*10*kCarTolerance;
00081   }
00082   
00083   //
00084   // Add safety
00085   //
00086   radius += 10*kCarTolerance;
00087   zLo    -= 10*kCarTolerance;
00088   zHi    += 10*kCarTolerance;
00089 }
00090 
00091 //
00092 // Fake default constructor - sets only member data and allocates memory
00093 //                            for usage restricted to object persistency.
00094 //
00095 G4EnclosingCylinder::G4EnclosingCylinder( __void__& )
00096 : radius(0.), zLo(0.), zHi(0.), phiIsOpen(0.), startPhi(0.), totalPhi(0.),
00097   rx1(0.), ry1(0.), dx1(0.), dy1(0.), rx2(0.), ry2(0.), dx2(0.), dy2(0.),
00098   concave(false)
00099 {
00100 }
00101 
00102 //
00103 // Destructor
00104 //
00105 G4EnclosingCylinder::~G4EnclosingCylinder()
00106 {
00107 }
00108 
00109 
00110 //
00111 // Outside
00112 //
00113 // Decide very rapidly if the point is outside the cylinder
00114 //
00115 // If one is not certain, return false
00116 //
00117 G4bool G4EnclosingCylinder::MustBeOutside( const G4ThreeVector &p ) const
00118 {
00119   if (p.perp() > radius) return true;
00120   if (p.z() < zLo) return true;
00121   if (p.z() > zHi) return true;
00122 
00123   if (phiIsOpen)
00124   {
00125     if (concave)
00126     {
00127       if ( ((p.x()-dx1)*ry1 - (p.y()-dy1)*rx1) < 0) return false;
00128       if ( ((p.x()-dx2)*ry2 - (p.y()-dy2)*rx2) > 0) return false;
00129     }
00130     else
00131     {
00132       if ( ((p.x()-dx1)*ry1 - (p.y()-dy1)*rx1) > 0) return true;
00133       if ( ((p.x()-dx2)*ry2 - (p.y()-dy2)*rx2) < 0) return true;
00134     }
00135   }
00136   
00137   return false;
00138 }
00139     
00140     
00141 //
00142 // Misses
00143 //
00144 // Decide very rapidly if the trajectory is going to miss the cylinder
00145 //
00146 // If one is not sure, return false
00147 //
00148 G4bool G4EnclosingCylinder::ShouldMiss( const G4ThreeVector &p,
00149                                         const G4ThreeVector &v ) const
00150 {
00151   if (!MustBeOutside(p)) return false;
00152   
00153   G4double cross = p.x()*v.y() - p.y()*v.x();
00154   if (cross > radius) return true;
00155   
00156   if (p.perp() > radius)
00157   {
00158     G4double dot = p.x()*v.x() + p.y()*v.y();
00159     if (dot > 0) return true;
00160   }
00161 
00162   return false;
00163 }

Generated on Mon May 27 17:48:09 2013 for Geant4 by  doxygen 1.4.7