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: G4ErrorCylSurfaceTarget.cc,v 1.4 2007/06/20 12:50:48 arce Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // -------------------------------------------------------------------- |
---|
32 | // GEANT 4 class implementation file |
---|
33 | // -------------------------------------------------------------------- |
---|
34 | |
---|
35 | #include "G4ErrorCylSurfaceTarget.hh" |
---|
36 | #include "G4GeometryTolerance.hh" |
---|
37 | |
---|
38 | #ifdef G4VERBOSE |
---|
39 | #include "G4ErrorPropagatorData.hh" //for verbosity checking |
---|
40 | #endif |
---|
41 | |
---|
42 | #include "geomdefs.hh" |
---|
43 | #include "G4Plane3D.hh" |
---|
44 | |
---|
45 | //--------------------------------------------------------------------- |
---|
46 | |
---|
47 | G4ErrorCylSurfaceTarget:: |
---|
48 | G4ErrorCylSurfaceTarget( const G4double& radius, |
---|
49 | const G4ThreeVector& trans, |
---|
50 | const G4RotationMatrix& rotm ) |
---|
51 | : fradius(radius) |
---|
52 | { |
---|
53 | theType = G4ErrorTarget_CylindricalSurface; |
---|
54 | |
---|
55 | ftransform = G4AffineTransform( rotm.inverse(), -trans ); |
---|
56 | #ifdef G4VERBOSE |
---|
57 | if(G4ErrorPropagatorData::verbose() >= 2 ) { |
---|
58 | Dump( " $$$ creating G4ErrorCylSurfaceTarget "); |
---|
59 | } |
---|
60 | #endif |
---|
61 | } |
---|
62 | |
---|
63 | //--------------------------------------------------------------------- |
---|
64 | |
---|
65 | G4ErrorCylSurfaceTarget:: |
---|
66 | G4ErrorCylSurfaceTarget( const G4double& radius, |
---|
67 | const G4AffineTransform& trans ) |
---|
68 | : fradius(radius), ftransform(trans.Inverse()) |
---|
69 | { |
---|
70 | theType = G4ErrorTarget_CylindricalSurface; |
---|
71 | |
---|
72 | #ifdef G4VERBOSE |
---|
73 | if(G4ErrorPropagatorData::verbose() >= 2 ) |
---|
74 | { |
---|
75 | Dump( " $$$ creating G4ErrorCylSurfaceTarget "); |
---|
76 | } |
---|
77 | #endif |
---|
78 | } |
---|
79 | |
---|
80 | //--------------------------------------------------------------------- |
---|
81 | |
---|
82 | G4ErrorCylSurfaceTarget::~G4ErrorCylSurfaceTarget() |
---|
83 | { |
---|
84 | } |
---|
85 | |
---|
86 | //--------------------------------------------------------------------- |
---|
87 | |
---|
88 | G4double G4ErrorCylSurfaceTarget:: |
---|
89 | GetDistanceFromPoint( const G4ThreeVector& point, |
---|
90 | const G4ThreeVector& dir ) const |
---|
91 | { |
---|
92 | if( dir.mag() == 0. ) |
---|
93 | { |
---|
94 | G4Exception("G4ErrorCylSurfaceTarget::GetDistanceFromPoint()", |
---|
95 | "InvalidSetup", FatalException, "Direction is zero !"); |
---|
96 | } |
---|
97 | |
---|
98 | //----- Get intersection point |
---|
99 | G4ThreeVector localPoint = ftransform.TransformPoint( point ); |
---|
100 | G4ThreeVector localDir = ftransform.TransformAxis( dir ); |
---|
101 | G4ThreeVector inters = IntersectLocal(localPoint, localDir); |
---|
102 | |
---|
103 | G4double dist = (localPoint-inters).mag(); |
---|
104 | |
---|
105 | #ifdef G4VERBOSE |
---|
106 | if(G4ErrorPropagatorData::verbose() >= 3 ) |
---|
107 | { |
---|
108 | G4cout << " G4ErrorCylSurfaceTarget::GetDistanceFromPoint():" << G4endl |
---|
109 | << " Global point " << point << " dir " << dir << G4endl |
---|
110 | << " Intersection " << inters << G4endl |
---|
111 | << " Distance " << dist << G4endl; |
---|
112 | Dump( " CylSurface: " ); |
---|
113 | } |
---|
114 | #endif |
---|
115 | |
---|
116 | return dist; |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | //--------------------------------------------------------------------- |
---|
121 | |
---|
122 | G4double G4ErrorCylSurfaceTarget:: |
---|
123 | GetDistanceFromPoint( const G4ThreeVector& point ) const |
---|
124 | { |
---|
125 | G4ThreeVector localPoint = ftransform.TransformPoint( point ); |
---|
126 | |
---|
127 | #ifdef G4VERBOSE |
---|
128 | if(G4ErrorPropagatorData::verbose() >= 3 ) |
---|
129 | { |
---|
130 | G4cout << " G4ErrorCylSurfaceTarget::GetDistanceFromPoint:" << G4endl |
---|
131 | << " Global point " << point << G4endl |
---|
132 | << " Distance " << fradius - localPoint.perp() << G4endl; |
---|
133 | Dump( " CylSurface: " ); |
---|
134 | } |
---|
135 | #endif |
---|
136 | |
---|
137 | return fradius - localPoint.perp(); |
---|
138 | } |
---|
139 | |
---|
140 | //--------------------------------------------------------------------- |
---|
141 | |
---|
142 | G4ThreeVector G4ErrorCylSurfaceTarget:: |
---|
143 | IntersectLocal( const G4ThreeVector& localPoint, |
---|
144 | const G4ThreeVector& localDir ) const |
---|
145 | { |
---|
146 | G4double eqa = localDir.x()*localDir.x()+localDir.y()*localDir.y(); |
---|
147 | G4double eqb = 2*(localPoint.x()*localDir.x()+localPoint.y()*localDir.y()); |
---|
148 | G4double eqc = -fradius*fradius+localPoint.x()*localPoint.x() |
---|
149 | +localPoint.y()*localPoint.y(); |
---|
150 | G4int inside = (localPoint.perp() > fradius) ? -1 : 1; |
---|
151 | G4double lambda; |
---|
152 | |
---|
153 | if( eqa*inside > 0. ) |
---|
154 | { |
---|
155 | lambda = (-eqb + std::sqrt(eqb*eqb-4*eqa*eqc) ) / (2.*eqa); |
---|
156 | } |
---|
157 | else if( eqa*inside < 0. ) |
---|
158 | { |
---|
159 | lambda = (-eqb - std::sqrt(eqb*eqb-4*eqa*eqc) ) / (2.*eqa); |
---|
160 | } |
---|
161 | else |
---|
162 | { |
---|
163 | if( eqb != 0. ) |
---|
164 | { |
---|
165 | lambda = -eqc/eqb; |
---|
166 | } |
---|
167 | else |
---|
168 | { |
---|
169 | G4cerr << "WARNING - G4ErrorCylSurfaceTarget::IntersectLocal()" << G4endl |
---|
170 | << " Point: " << localPoint << ", direction: " |
---|
171 | << localDir << G4endl; |
---|
172 | Dump( " CylSurface: " ); |
---|
173 | G4Exception("G4ErrorCylSurfaceTarget::IntersectLocal()", |
---|
174 | "IllegalCondition", |
---|
175 | JustWarning, "Intersection not possible !"); |
---|
176 | lambda = kInfinity; |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | G4ThreeVector inters = localPoint + lambda*localDir/localDir.mag(); |
---|
181 | |
---|
182 | #ifdef G4VERBOSE |
---|
183 | if(G4ErrorPropagatorData::verbose() >= 4 ) { |
---|
184 | G4cout << " G4ErrorCylSurfaceTarget::IntersectLocal " << inters << " " << inters.perp() << " localPoint " << localPoint << " localDir " << localDir << G4endl; |
---|
185 | } |
---|
186 | #endif |
---|
187 | |
---|
188 | return inters; |
---|
189 | } |
---|
190 | |
---|
191 | //--------------------------------------------------------------------- |
---|
192 | |
---|
193 | G4Plane3D G4ErrorCylSurfaceTarget:: |
---|
194 | GetTangentPlane( const G4ThreeVector& point ) const |
---|
195 | { |
---|
196 | G4ThreeVector localPoint = ftransform.TransformPoint( point ); |
---|
197 | |
---|
198 | // check that point is at cylinder surface |
---|
199 | // |
---|
200 | if( std::fabs( localPoint.perp() - fradius ) |
---|
201 | > 1000.*G4GeometryTolerance::GetInstance()->GetSurfaceTolerance() ) |
---|
202 | { |
---|
203 | G4cerr << "WARNING - G4ErrorCylSurfaceTarget::GetTangentPlane()" << G4endl |
---|
204 | << " Point: " << point << ", local: " << localPoint |
---|
205 | << G4endl |
---|
206 | << " is not at surface, but far away by: " |
---|
207 | << localPoint.perp() - fradius << " !" << G4endl; |
---|
208 | G4Exception("G4ErrorCylSurfaceTarget::GetTangentPlane()", |
---|
209 | "IllegalCondition", JustWarning, |
---|
210 | "Local point not at surface !"); |
---|
211 | } |
---|
212 | |
---|
213 | G4Normal3D normal = localPoint - ftransform.NetTranslation(); |
---|
214 | |
---|
215 | return G4Plane3D( normal, point ); |
---|
216 | } |
---|
217 | |
---|
218 | |
---|
219 | //--------------------------------------------------------------------- |
---|
220 | |
---|
221 | void G4ErrorCylSurfaceTarget::Dump( const G4String& msg ) const |
---|
222 | { |
---|
223 | G4cout << msg << " radius " << fradius |
---|
224 | << " centre " << ftransform.NetTranslation() |
---|
225 | << " rotation " << ftransform.NetRotation() << G4endl; |
---|
226 | } |
---|