Geant4-11
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 "G4Plane3D.hh"
40
41//---------------------------------------------------------------------
42
45 const G4ThreeVector& trans,
46 const G4RotationMatrix& rotm )
47 : fradius(radius)
48{
50
51 ftransform = G4AffineTransform( rotm.inverse(), -trans );
52#ifdef G4VERBOSE
54 {
55 Dump( " $$$ creating G4ErrorCylSurfaceTarget ");
56 }
57#endif
58}
59
60//---------------------------------------------------------------------
61
64 const G4AffineTransform& trans )
65 : fradius(radius), ftransform(trans.Inverse())
66{
68
69#ifdef G4VERBOSE
71 {
72 Dump( " $$$ creating G4ErrorCylSurfaceTarget ");
73 }
74#endif
75}
76
77//---------------------------------------------------------------------
78
81 const G4ThreeVector& dir ) const
82{
83 if( dir.mag() == 0. )
84 {
85 G4Exception("G4ErrorCylSurfaceTarget::GetDistanceFromPoint()",
86 "GeomMgt0003", FatalException, "Direction is zero !");
87 }
88
89 //----- Get intersection point
90 G4ThreeVector localPoint = ftransform.TransformPoint( point );
91 G4ThreeVector localDir = ftransform.TransformAxis( dir );
92 G4ThreeVector inters = IntersectLocal(localPoint, localDir);
93
94 G4double dist = (localPoint-inters).mag();
95
96#ifdef G4VERBOSE
98 {
99 G4cout << " G4ErrorCylSurfaceTarget::GetDistanceFromPoint():" << G4endl
100 << " Global point " << point << " dir " << dir << G4endl
101 << " Intersection " << inters << G4endl
102 << " Distance " << dist << G4endl;
103 Dump( " CylSurface: " );
104 }
105#endif
106
107 return dist;
108}
109
110
111//---------------------------------------------------------------------
112
114GetDistanceFromPoint( const G4ThreeVector& point ) const
115{
116 G4ThreeVector localPoint = ftransform.TransformPoint( point );
117
118#ifdef G4VERBOSE
120 {
121 G4cout << " G4ErrorCylSurfaceTarget::GetDistanceFromPoint:" << G4endl
122 << " Global point " << point << G4endl
123 << " Distance " << fradius - localPoint.perp() << G4endl;
124 Dump( " CylSurface: " );
125 }
126#endif
127
128 return fradius - localPoint.perp();
129}
130
131//---------------------------------------------------------------------
132
134IntersectLocal( const G4ThreeVector& localPoint,
135 const G4ThreeVector& localDir ) const
136{
137 G4double eqa = localDir.x()*localDir.x()+localDir.y()*localDir.y();
138 G4double eqb = 2*(localPoint.x()*localDir.x()+localPoint.y()*localDir.y());
139 G4double eqc = -fradius*fradius+localPoint.x()*localPoint.x()
140 +localPoint.y()*localPoint.y();
141 G4int inside = (localPoint.perp() > fradius) ? -1 : 1;
143
144 if( eqa*inside > 0. )
145 {
146 lambda = (-eqb + std::sqrt(eqb*eqb-4*eqa*eqc) ) / (2.*eqa);
147 }
148 else if( eqa*inside < 0. )
149 {
150 lambda = (-eqb - std::sqrt(eqb*eqb-4*eqa*eqc) ) / (2.*eqa);
151 }
152 else
153 {
154 if( eqb != 0. )
155 {
156 lambda = -eqc/eqb;
157 }
158 else
159 {
160 std::ostringstream message;
161 message << "Intersection not possible !" << G4endl
162 << " Point: " << localPoint << ", direction: "
163 << localDir;
164 Dump( " CylSurface: " );
165 G4Exception("G4ErrorCylSurfaceTarget::IntersectLocal()",
166 "GeomMgt1002", JustWarning, message);
168 }
169 }
170
171 G4ThreeVector inters = localPoint + lambda*localDir/localDir.mag();
172
173#ifdef G4VERBOSE
174 if(G4ErrorPropagatorData::verbose() >= 4 ) {
175 G4cout << " G4ErrorCylSurfaceTarget::IntersectLocal " << inters << " "
176 << inters.perp() << " localPoint " << localPoint << " localDir "
177 << localDir << G4endl;
178 }
179#endif
180
181 return inters;
182}
183
184//---------------------------------------------------------------------
185
187GetTangentPlane( const G4ThreeVector& point ) const
188{
189 G4ThreeVector localPoint = ftransform.TransformPoint( point );
190
191 // check that point is at cylinder surface
192 //
193 if( std::fabs( localPoint.perp() - fradius )
195 {
196 std::ostringstream message;
197 message << "Local point not at surface !" << G4endl
198 << " Point: " << point << ", local: " << localPoint
199 << G4endl
200 << " is not at surface, but far away by: "
201 << localPoint.perp() - fradius << " !";
202 G4Exception("G4ErrorCylSurfaceTarget::GetTangentPlane()",
203 "GeomMgt1002", JustWarning, message);
204 }
205
207
208 return G4Plane3D( normal, point );
209}
210
211
212//---------------------------------------------------------------------
213
215{
216 G4cout << msg << " radius " << fradius
217 << " centre " << ftransform.NetTranslation()
218 << " rotation " << ftransform.NetRotation() << G4endl;
219}
@ G4ErrorTarget_CylindricalSurface
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
HepGeom::Plane3D< G4double > G4Plane3D
Definition: G4Plane3D.hh:36
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()
static const G4double kInfinity
Definition: geomdefs.hh:41
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:79