Geant4  10.00.p03
G4EnclosingCylinder.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
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. *
10 // * *
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. *
17 // * *
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 // ********************************************************************
25 //
26 //
27 // $Id: G4EnclosingCylinder.cc 66356 2012-12-18 09:02:32Z gcosmo $
28 //
29 //
30 // --------------------------------------------------------------------
31 // GEANT 4 class source file
32 //
33 //
34 // G4EnclosingCylinder.cc
35 //
36 // Implementation of a utility class for a quick check of geometry.
37 //
38 // --------------------------------------------------------------------
39 
40 #include "G4EnclosingCylinder.hh"
41 #include "G4PhysicalConstants.hh"
42 #include "G4ReduciblePolygon.hh"
43 #include "G4GeometryTolerance.hh"
44 
45 //
46 // Constructor
47 //
49  G4bool thePhiIsOpen,
50  G4double theStartPhi,
51  G4double theTotalPhi )
52  : startPhi(theStartPhi), totalPhi(theTotalPhi),
53  rx1(0.), ry1(0.), dx1(0.), dy1(0.),
54  rx2(0.), ry2(0.), dx2(0.), dy2(0.),
55  concave(theTotalPhi > pi)
56 {
57  //
58  // Obtain largest r and smallest and largest z
59  //
60  radius = rz->Amax();
61  zHi = rz->Bmax();
62  zLo = rz->Bmin();
63 
66  //
67  // Save phi info
68  //
69  phiIsOpen = thePhiIsOpen;
70  if ( phiIsOpen )
71  {
72  rx1 = std::cos(startPhi);
73  ry1 = std::sin(startPhi);
74  dx1 = +ry1*10*kCarTolerance;
75  dy1 = -rx1*10*kCarTolerance;
76 
77  rx2 = std::cos(startPhi+totalPhi);
78  ry2 = std::sin(startPhi+totalPhi);
79  dx2 = -ry2*10*kCarTolerance;
80  dy2 = +rx2*10*kCarTolerance;
81  }
82 
83  //
84  // Add safety
85  //
86  radius += 10*kCarTolerance;
87  zLo -= 10*kCarTolerance;
88  zHi += 10*kCarTolerance;
89 }
90 
91 //
92 // Fake default constructor - sets only member data and allocates memory
93 // for usage restricted to object persistency.
94 //
96 : radius(0.), zLo(0.), zHi(0.), phiIsOpen(0.), startPhi(0.), totalPhi(0.),
97  rx1(0.), ry1(0.), dx1(0.), dy1(0.), rx2(0.), ry2(0.), dx2(0.), dy2(0.),
98  concave(false)
99 {
100 }
101 
102 //
103 // Destructor
104 //
106 {
107 }
108 
109 
110 //
111 // Outside
112 //
113 // Decide very rapidly if the point is outside the cylinder
114 //
115 // If one is not certain, return false
116 //
118 {
119  if (p.perp() > radius) return true;
120  if (p.z() < zLo) return true;
121  if (p.z() > zHi) return true;
122 
123  if (phiIsOpen)
124  {
125  if (concave)
126  {
127  if ( ((p.x()-dx1)*ry1 - (p.y()-dy1)*rx1) < 0) return false;
128  if ( ((p.x()-dx2)*ry2 - (p.y()-dy2)*rx2) > 0) return false;
129  }
130  else
131  {
132  if ( ((p.x()-dx1)*ry1 - (p.y()-dy1)*rx1) > 0) return true;
133  if ( ((p.x()-dx2)*ry2 - (p.y()-dy2)*rx2) < 0) return true;
134  }
135  }
136 
137  return false;
138 }
139 
140 
141 //
142 // Misses
143 //
144 // Decide very rapidly if the trajectory is going to miss the cylinder
145 //
146 // If one is not sure, return false
147 //
149  const G4ThreeVector &v ) const
150 {
151  if (!MustBeOutside(p)) return false;
152 
153  G4double cross = p.x()*v.y() - p.y()*v.x();
154  if (cross > radius) return true;
155 
156  if (p.perp() > radius)
157  {
158  G4double dot = p.x()*v.x() + p.y()*v.y();
159  if (dot > 0) return true;
160  }
161 
162  return false;
163 }
G4double Amax() const
CLHEP::Hep3Vector G4ThreeVector
const G4double pi
G4double GetSurfaceTolerance() const
G4bool MustBeOutside(const G4ThreeVector &p) const
G4EnclosingCylinder(const G4ReduciblePolygon *rz, G4bool phiIsOpen, G4double startPhi, G4double totalPhi)
G4double Bmax() const
bool G4bool
Definition: G4Types.hh:79
G4double Bmin() const
double G4double
Definition: G4Types.hh:76
G4bool ShouldMiss(const G4ThreeVector &p, const G4ThreeVector &v) const
static G4GeometryTolerance * GetInstance()