Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ErrorCylSurfaceTarget.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// G4ErrorCylSurfaceTarget class implementation
27//
28// Created: P.Arce, September 2004
29// --------------------------------------------------------------------
30
33
34#ifdef G4VERBOSE
35#include "G4ErrorPropagatorData.hh" // for verbosity checking
36#endif
37
38#include "geomdefs.hh"
39#include "G4Normal3D.hh"
40#include "G4Plane3D.hh"
41
42//---------------------------------------------------------------------
43
46 const G4ThreeVector& trans,
47 const G4RotationMatrix& rotm )
48 : fradius(radius)
49{
51
52 ftransform = G4AffineTransform( rotm.inverse(), -trans );
53#ifdef G4VERBOSE
55 {
56 Dump( " $$$ creating G4ErrorCylSurfaceTarget ");
57 }
58#endif
59}
60
61//---------------------------------------------------------------------
62
65 const G4AffineTransform& trans )
66 : fradius(radius), ftransform(trans.Inverse())
67{
69
70#ifdef G4VERBOSE
72 {
73 Dump( " $$$ creating G4ErrorCylSurfaceTarget ");
74 }
75#endif
76}
77
78//---------------------------------------------------------------------
79
82 const G4ThreeVector& dir ) const
83{
84 if( dir.mag() == 0. )
85 {
86 G4Exception("G4ErrorCylSurfaceTarget::GetDistanceFromPoint()",
87 "GeomMgt0003", FatalException, "Direction is zero !");
88 }
89
90 //----- Get intersection point
91 G4ThreeVector localPoint = ftransform.TransformPoint( point );
92 G4ThreeVector localDir = ftransform.TransformAxis( dir );
93 G4ThreeVector inters = IntersectLocal(localPoint, localDir);
94
95 G4double dist = (localPoint-inters).mag();
96
97#ifdef G4VERBOSE
99 {
100 G4cout << " G4ErrorCylSurfaceTarget::GetDistanceFromPoint():" << G4endl
101 << " Global point " << point << " dir " << dir << G4endl
102 << " Intersection " << inters << G4endl
103 << " Distance " << dist << G4endl;
104 Dump( " CylSurface: " );
105 }
106#endif
107
108 return dist;
109}
110
111
112//---------------------------------------------------------------------
113
115GetDistanceFromPoint( const G4ThreeVector& point ) const
116{
117 G4ThreeVector localPoint = ftransform.TransformPoint( point );
118
119#ifdef G4VERBOSE
121 {
122 G4cout << " G4ErrorCylSurfaceTarget::GetDistanceFromPoint:" << G4endl
123 << " Global point " << point << G4endl
124 << " Distance " << fradius - localPoint.perp() << G4endl;
125 Dump( " CylSurface: " );
126 }
127#endif
128
129 return fradius - localPoint.perp();
130}
131
132//---------------------------------------------------------------------
133
135IntersectLocal( const G4ThreeVector& localPoint,
136 const G4ThreeVector& localDir ) const
137{
138 G4double eqa = localDir.x()*localDir.x()+localDir.y()*localDir.y();
139 G4double eqb = 2*(localPoint.x()*localDir.x()+localPoint.y()*localDir.y());
140 G4double eqc = -fradius*fradius+localPoint.x()*localPoint.x()
141 +localPoint.y()*localPoint.y();
142 G4int inside = (localPoint.perp() > fradius) ? -1 : 1;
143 G4double lambda;
144
145 if( eqa*inside > 0. )
146 {
147 lambda = (-eqb + std::sqrt(eqb*eqb-4*eqa*eqc) ) / (2.*eqa);
148 }
149 else if( eqa*inside < 0. )
150 {
151 lambda = (-eqb - std::sqrt(eqb*eqb-4*eqa*eqc) ) / (2.*eqa);
152 }
153 else
154 {
155 if( eqb != 0. )
156 {
157 lambda = -eqc/eqb;
158 }
159 else
160 {
161 std::ostringstream message;
162 message << "Intersection not possible !" << G4endl
163 << " Point: " << localPoint << ", direction: "
164 << localDir;
165 Dump( " CylSurface: " );
166 G4Exception("G4ErrorCylSurfaceTarget::IntersectLocal()",
167 "GeomMgt1002", JustWarning, message);
168 lambda = kInfinity;
169 }
170 }
171
172 G4ThreeVector inters = localPoint + lambda*localDir/localDir.mag();
173
174#ifdef G4VERBOSE
175 if(G4ErrorPropagatorData::verbose() >= 4 ) {
176 G4cout << " G4ErrorCylSurfaceTarget::IntersectLocal " << inters << " "
177 << inters.perp() << " localPoint " << localPoint << " localDir "
178 << localDir << G4endl;
179 }
180#endif
181
182 return inters;
183}
184
185//---------------------------------------------------------------------
186
188GetTangentPlane( const G4ThreeVector& point ) const
189{
190 G4ThreeVector localPoint = ftransform.TransformPoint( point );
191
192 // check that point is at cylinder surface
193 //
194 if( std::fabs( localPoint.perp() - fradius )
196 {
197 std::ostringstream message;
198 message << "Local point not at surface !" << G4endl
199 << " Point: " << point << ", local: " << localPoint
200 << G4endl
201 << " is not at surface, but far away by: "
202 << localPoint.perp() - fradius << " !";
203 G4Exception("G4ErrorCylSurfaceTarget::GetTangentPlane()",
204 "GeomMgt1002", JustWarning, message);
205 }
206
207 G4Normal3D normal = localPoint - ftransform.NetTranslation();
208
209 return G4Plane3D( normal, point );
210}
211
212
213//---------------------------------------------------------------------
214
216{
217 G4cout << msg << " radius " << fradius
218 << " centre " << ftransform.NetTranslation()
219 << " rotation " << ftransform.NetRotation() << G4endl;
220}
@ G4ErrorTarget_CylindricalSurface
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
HepGeom::Plane3D< G4double > G4Plane3D
Definition: G4Plane3D.hh:34
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
double x() const
double y() const
double mag() const
double perp() const
HepRotation inverse() const
G4ThreeVector NetTranslation() const
G4RotationMatrix NetRotation() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4ThreeVector TransformAxis(const G4ThreeVector &axis) const
virtual G4Plane3D GetTangentPlane(const G4ThreeVector &point) const
G4ErrorCylSurfaceTarget(const G4double &radius, const G4ThreeVector &trans=G4ThreeVector(), const G4RotationMatrix &rotm=G4RotationMatrix())
virtual G4ThreeVector IntersectLocal(const G4ThreeVector &point, const G4ThreeVector &direc) const
virtual void Dump(const G4String &msg) const
virtual G4double GetDistanceFromPoint(const G4ThreeVector &point, const G4ThreeVector &direc) const
G4ErrorTargetType theType
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()