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: G4BREPSolidPConeTest.cc,v 1.16 2006/06/29 18:43:14 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ |
---|
29 | ////////////////////////////////////////////////////////////////////////// |
---|
30 | // |
---|
31 | // |
---|
32 | // BREP solid test, create by L. Broglia, 20/10/98 |
---|
33 | // modification of old G4Gerep test |
---|
34 | // |
---|
35 | |
---|
36 | #include "G4Timer.hh" |
---|
37 | #include <cmath> |
---|
38 | #include "G4ios.hh" |
---|
39 | #include "G4BREPSolid.hh" |
---|
40 | #include "G4BREPSolidPCone.hh" |
---|
41 | |
---|
42 | #include <fstream> |
---|
43 | #include <iomanip> |
---|
44 | |
---|
45 | void checkNormal( G4BREPSolid* solid, G4ThreeVector& position ) |
---|
46 | { |
---|
47 | G4ThreeVector normal = solid->SurfaceNormal( position ); |
---|
48 | |
---|
49 | G4cout << G4endl |
---|
50 | << "\t\tSurface normal" << G4endl |
---|
51 | << "\t\t--------------" << G4endl |
---|
52 | << "\t\tposition x=" << position.x() |
---|
53 | << " y=" << position.y() |
---|
54 | << " z=" << position.z() << G4endl |
---|
55 | << "\t\tis normX=" << normal.x() |
---|
56 | << " normY=" << normal.y() |
---|
57 | << " normZ=" << normal.z() << G4endl; |
---|
58 | } |
---|
59 | |
---|
60 | void checkSurfInOut( G4BREPSolid* solid, G4ThreeVector& position, G4ThreeVector& direction ) |
---|
61 | { |
---|
62 | G4double d; |
---|
63 | |
---|
64 | G4cout << G4endl |
---|
65 | << "\tTest of In & Out " << solid->GetName() << G4endl |
---|
66 | << "\t--------------------------------------" << G4endl; |
---|
67 | |
---|
68 | d = solid->DistanceToIn( position, direction ); |
---|
69 | G4cout << "\tDistance to in=" << d; |
---|
70 | d = solid->DistanceToIn( position ); |
---|
71 | G4cout << "\tClosest distance to in=" << d <<G4endl; |
---|
72 | |
---|
73 | d = solid->DistanceToOut( position, direction ); |
---|
74 | G4cout << "\tDistance to out=" << d; |
---|
75 | d = solid->DistanceToOut( position ); |
---|
76 | G4cout << "\tClosest distance to out=" << d << G4endl; |
---|
77 | } |
---|
78 | |
---|
79 | void checkSolid( const G4String& where, G4BREPSolid* solid, G4ThreeVector& position, G4ThreeVector& direction, G4double estIn = 0.0, G4double estOut = 0.0 ) |
---|
80 | { |
---|
81 | G4double d; |
---|
82 | |
---|
83 | EInside in = solid->Inside( position ); |
---|
84 | |
---|
85 | G4cout << G4endl |
---|
86 | << where << " of " << solid->GetName() << G4endl |
---|
87 | << "--------------------------------" << G4endl |
---|
88 | << "estimation to in =" << estIn << G4endl |
---|
89 | << "estimation to out =" << estOut << G4endl |
---|
90 | << "direction x=" << direction.x() |
---|
91 | << " y=" << direction.y() |
---|
92 | << " z=" << direction.z() << G4endl |
---|
93 | << "position x=" << position.x() |
---|
94 | << " y=" << position.y() |
---|
95 | << " z=" << position.z(); |
---|
96 | |
---|
97 | if( in == kInside ) { |
---|
98 | G4cout <<" is inside"; |
---|
99 | d = solid->DistanceToOut( position, direction ); |
---|
100 | G4cout<<" distance to out="<<d; |
---|
101 | d = solid->DistanceToOut( position ); |
---|
102 | G4cout<<" closest distance to out="<<d<<G4endl; |
---|
103 | } else if( in == kOutside ) { |
---|
104 | G4cout <<" is outside"; |
---|
105 | d = solid->DistanceToIn( position, direction ); |
---|
106 | G4cout<<" distance to in="<<d; |
---|
107 | d = solid->DistanceToIn( position ); |
---|
108 | G4cout<<" closest distance to in="<<d<<G4endl; |
---|
109 | } else { |
---|
110 | G4cout <<" is on the surface"<<G4endl; |
---|
111 | checkSurfInOut( solid, position, direction ); |
---|
112 | checkNormal( solid, position ); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | int main() |
---|
117 | { |
---|
118 | const G4int noZplanes= 8; |
---|
119 | |
---|
120 | G4double RMINVec[noZplanes] = { 30, 30, 0, 0, 0, 0, 40, 40 }; |
---|
121 | G4double RMAXVec[noZplanes] = { 70, 70, 70, 40, 40, 80, 80, 60 }; |
---|
122 | G4double Z_Values[noZplanes] = { -20, -10, -10, 0, 10, 20, 30, 40 }; |
---|
123 | |
---|
124 | G4double start_angle= 0.0; |
---|
125 | G4double opening_angle= 2*pi; |
---|
126 | |
---|
127 | G4double zstart= Z_Values[0]; |
---|
128 | |
---|
129 | G4cout << "\n======= PCon test ========"; |
---|
130 | |
---|
131 | G4BREPSolidPCone *MyPCone = new G4BREPSolidPCone ("MyPCone", |
---|
132 | start_angle, |
---|
133 | opening_angle, |
---|
134 | noZplanes, |
---|
135 | zstart, |
---|
136 | Z_Values, |
---|
137 | RMINVec, |
---|
138 | RMAXVec ); |
---|
139 | |
---|
140 | G4cout << "\n\nPCone created ! "<<G4endl; |
---|
141 | G4cout << "Variety is G4BREPSolidPolycone"<<G4endl; |
---|
142 | |
---|
143 | G4cout << "Its parameters are: "<<G4endl; |
---|
144 | |
---|
145 | /////////////////////////////////////////////////// |
---|
146 | // Temporary |
---|
147 | for (G4int x = 0; x < noZplanes; x++) |
---|
148 | { |
---|
149 | G4cout << " Z[" << x << "]=" << std::setw(5) << Z_Values[x]; |
---|
150 | G4cout << " Rmin[" << x << "]=" << std::setw(5) << RMINVec[x]; |
---|
151 | G4cout << " Rmax[" << x << "]=" << std::setw(5) << RMAXVec[x]<<G4endl; |
---|
152 | } |
---|
153 | |
---|
154 | G4cout<<" start angle ="<<start_angle<<G4endl; |
---|
155 | G4cout<<" opening angle ="<<opening_angle<<G4endl; |
---|
156 | G4cout<<" zstart =" << zstart << G4endl; |
---|
157 | |
---|
158 | |
---|
159 | // -> Check methods : |
---|
160 | // - Inside |
---|
161 | // - DistanceToIn |
---|
162 | // - DistanceToOut |
---|
163 | |
---|
164 | |
---|
165 | EInside in; |
---|
166 | |
---|
167 | G4cout<<"\n\n=================================================="; |
---|
168 | G4ThreeVector pt(0, -100, 24); |
---|
169 | G4double y; |
---|
170 | for (y = -100; y<=100; y+=10) |
---|
171 | { |
---|
172 | pt.setY(y); |
---|
173 | in = MyPCone->Inside(pt); |
---|
174 | |
---|
175 | G4cout << "\nx=" << pt.x() << " y=" << pt.y() << " z=" << pt.z(); |
---|
176 | |
---|
177 | if( in == kInside ) |
---|
178 | G4cout <<" is inside"; |
---|
179 | else |
---|
180 | if( in == kOutside ) |
---|
181 | G4cout <<" is outside"; |
---|
182 | else |
---|
183 | G4cout <<" is on the surface"; |
---|
184 | } |
---|
185 | |
---|
186 | G4cout<<"\n\n=================================================="; |
---|
187 | G4ThreeVector start( 0, 0, -30); |
---|
188 | G4ThreeVector dir(1, 1, 0); |
---|
189 | G4double d; |
---|
190 | |
---|
191 | G4cout<<"\nPdep is (0, 0, z)"; |
---|
192 | G4cout<<"\nDir is (1, 1, 0)\n"; |
---|
193 | |
---|
194 | G4double z; |
---|
195 | for(z=-30; z<=50; z+=5) |
---|
196 | { |
---|
197 | start.setZ(z); |
---|
198 | |
---|
199 | in = MyPCone->Inside(start); |
---|
200 | G4cout<< "x=" << start.x() << " y=" << start.y() << " z=" << start.z(); |
---|
201 | |
---|
202 | if( in == kInside ) |
---|
203 | { |
---|
204 | G4cout <<" is inside"; |
---|
205 | |
---|
206 | d = MyPCone->DistanceToOut(start, dir); |
---|
207 | G4cout<<" distance to out="<<d; |
---|
208 | d = MyPCone->DistanceToOut(start); |
---|
209 | G4cout<<" closest distance to out="<<d<<G4endl; |
---|
210 | } |
---|
211 | else if( in == kOutside ) |
---|
212 | { |
---|
213 | G4cout <<" is outside"; |
---|
214 | |
---|
215 | d = MyPCone->DistanceToIn(start, dir); |
---|
216 | G4cout<<" distance to in="<<d; |
---|
217 | d = MyPCone->DistanceToIn(start); |
---|
218 | G4cout<<" closest distance to in="<<d<<G4endl; |
---|
219 | } |
---|
220 | else |
---|
221 | G4cout <<" is on the surface"<<G4endl; |
---|
222 | |
---|
223 | } |
---|
224 | |
---|
225 | G4cout<<"\n\n=================================================="; |
---|
226 | G4ThreeVector start2( 0, -100, -30); |
---|
227 | G4ThreeVector dir2(0, 1, 0); |
---|
228 | G4double d2; |
---|
229 | |
---|
230 | G4cout<<"\nPdep is (0, -100, z)"; |
---|
231 | G4cout<<"\nDir is (0, 1, 0)\n"; |
---|
232 | |
---|
233 | for(z=-30; z<=50; z+=5) |
---|
234 | { |
---|
235 | G4cout<<" z="<<z; |
---|
236 | start2.setZ(z); |
---|
237 | d2 = MyPCone->DistanceToIn(start2, dir2); |
---|
238 | G4cout<<" distance to in="<<d2; |
---|
239 | d2 = MyPCone->DistanceToIn(start2); |
---|
240 | G4cout<<" closest distance to in="<<d2<<G4endl; |
---|
241 | } |
---|
242 | |
---|
243 | G4cout<<"\n\n=================================================="; |
---|
244 | G4ThreeVector start3( 0, 0, -50); |
---|
245 | G4ThreeVector dir3(0, 0, 1); |
---|
246 | G4double d3; |
---|
247 | |
---|
248 | G4cout<<"\nPdep is (0, y, -50)"; |
---|
249 | G4cout<<"\nDir is (0, 0, 1)\n"; |
---|
250 | |
---|
251 | for(y=-0; y<=90; y+=5) |
---|
252 | { |
---|
253 | G4cout<<" y="<<y; |
---|
254 | start3.setY(y); |
---|
255 | d3 = MyPCone->DistanceToIn(start3, dir3); |
---|
256 | G4cout<<" distance to in="<<d3<<G4endl; |
---|
257 | } |
---|
258 | |
---|
259 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
260 | // Test due to the bugfix No. 320 |
---|
261 | // Solid setup (only profile of its upper half is shown): |
---|
262 | // |
---|
263 | // +----+ |
---|
264 | // +--+ +--+ |
---|
265 | // +--+ +--+ |
---|
266 | // +----+ |
---|
267 | // |
---|
268 | // -------------- Z axis |
---|
269 | // |
---|
270 | G4double zValTOB[6] = { -2800*mm, -1210*mm, -1210*mm, 1210*mm, 1210*mm, 2800*mm }; |
---|
271 | G4double rMinTOB[6] = { 1160*mm, 1160*mm, 540*mm, 540*mm, 1160*mm, 1160*mm }; |
---|
272 | G4double rMaxTOB[6] = { 1170*mm, 1170*mm, 1182*mm, 1182*mm, 1170*mm, 1170*mm }; |
---|
273 | G4BREPSolidPCone * cmsTOBSolid = new G4BREPSolidPCone( "BREPPolyconeTOBSolid", |
---|
274 | 0.0*rad, twopi*rad, |
---|
275 | 6, zValTOB[0], zValTOB, rMinTOB, |
---|
276 | rMaxTOB ); |
---|
277 | // The critical gun settings |
---|
278 | G4ThreeVector gunPosition( 904.05833958335438*mm, -761.44764667689935*mm, -382.29360686839397*mm ); |
---|
279 | G4ThreeVector gunDirection( -0.32132043849994285, 0.11159991009963287, 0.94037154139624957 ); |
---|
280 | |
---|
281 | checkSolid( "CMS case", cmsTOBSolid, gunPosition, gunDirection ); |
---|
282 | |
---|
283 | G4ThreeVector gp( 541*mm, 0*mm, 1210*mm ); |
---|
284 | G4ThreeVector gd( -0.32132043849994285, 0.11159991009963287, 0.94037154139624957 ); |
---|
285 | |
---|
286 | checkSolid( "surface", cmsTOBSolid, gp, gd ); |
---|
287 | |
---|
288 | G4ThreeVector gpedge( 540*mm, 540*mm, -1210*mm ); |
---|
289 | G4ThreeVector gdedge( -0.32132043849994285, 0.11159991009963287, 0.94037154139624957 ); |
---|
290 | |
---|
291 | checkSolid( "edge", cmsTOBSolid, gpedge, gdedge ); |
---|
292 | |
---|
293 | G4ThreeVector gpin( 540*mm, 540*mm, -1209*mm ); |
---|
294 | G4ThreeVector gdin( -0.32132043849994285, 0.11159991009963287, 0.94037154139624957 ); |
---|
295 | |
---|
296 | checkSolid( "inside", cmsTOBSolid, gpin, gdin ); |
---|
297 | |
---|
298 | G4double zVal1[6] = { -200*mm, -100*mm, -100*mm, 100*mm, 100*mm, 200*mm }; |
---|
299 | G4double rMin1[6] = { 50*mm, 50*mm, 25*mm, 25*mm, 50*mm, 50*mm }; |
---|
300 | // G4double rMin1[6] = { 50*mm, 50*mm, 50*mm, 50*mm, 50*mm, 50*mm }; |
---|
301 | G4double rMax1[6] = { 50*mm, 100*mm, 200*mm, 200*mm, 100*mm, 50*mm }; |
---|
302 | G4BREPSolidPCone* s1 = new G4BREPSolidPCone( "s1", 0.0*rad, twopi*rad, 6, zVal1[0], zVal1, rMin1, rMax1 ); |
---|
303 | |
---|
304 | G4ThreeVector gps1in( 150*mm, 0*mm, 0*mm ); |
---|
305 | G4ThreeVector gds1in( 0, 0, 1 ); |
---|
306 | G4ThreeVector gps1out( 0*mm, 0*mm, 0*mm ); |
---|
307 | G4ThreeVector gds1out( 1, 0, 0 ); |
---|
308 | G4ThreeVector gps1edge( 50*mm, 0*mm, -200*mm ); |
---|
309 | G4ThreeVector gds1edge( 0, 0, 1 ); |
---|
310 | G4ThreeVector gps1surfout( 200*mm, 0*mm, 0*mm ); |
---|
311 | G4ThreeVector gds1surfout( -1, 0, 0 ); |
---|
312 | G4ThreeVector gps1surfin( 0*mm, 25*mm, 0*mm ); |
---|
313 | G4ThreeVector gds1surfin( 0, 1, 0 ); |
---|
314 | G4ThreeVector gps1plansurfleftout( 150*mm, 0*mm, -100*mm ); |
---|
315 | G4ThreeVector gps1plansurfleftin( 30*mm, 0*mm, -100*mm ); |
---|
316 | G4ThreeVector gps1plansurfleftfict( 0*mm, 0*mm, -100*mm ); |
---|
317 | G4ThreeVector gds1plansurfleft( 0, 0, 1 ); |
---|
318 | G4ThreeVector gps1plansurfright( 150*mm, 0*mm, 100*mm ); |
---|
319 | G4ThreeVector gds1plansurfright( 0, 0, -1 ); |
---|
320 | |
---|
321 | checkSolid( "inside", s1, gps1in, gds1in ); |
---|
322 | checkSolid( "outside", s1, gps1out, gds1out ); |
---|
323 | checkSolid( "edge", s1, gps1edge, gds1edge, 0, 400 ); |
---|
324 | checkSolid( "outer surface", s1, gps1surfout, gds1surfout, 0, 100 ); |
---|
325 | checkSolid( "inner surface", s1, gps1surfin, gds1surfin, 0, 175 ); |
---|
326 | checkSolid( "left outer planar surface", s1, gps1plansurfleftout, gds1plansurfleft, 0, 200 ); |
---|
327 | checkSolid( "left outer planar surface inv", s1, gps1plansurfleftout, gds1plansurfright, kInfinity, 0 ); |
---|
328 | checkSolid( "fictious left planar surface", s1, gps1plansurfleftfict, gds1plansurfleft, kInfinity, 25 ); |
---|
329 | checkSolid( "fictious left planar surface inv", s1, gps1plansurfleftfict, gds1plansurfright, kInfinity, 25 ); |
---|
330 | checkSolid( "left inner planar surface", s1, gps1plansurfleftin, gds1plansurfleft, 0, 200 ); |
---|
331 | checkSolid( "left inner planar surface inv", s1, gps1plansurfleftin, gds1plansurfright, kInfinity, 0 ); |
---|
332 | checkSolid( "right planar surface", s1, gps1plansurfright, gds1plansurfright, 0, 200 ); |
---|
333 | checkSolid( "right planar surface inv", s1, gps1plansurfright, gds1plansurfleft, 0 ); |
---|
334 | |
---|
335 | return EXIT_SUCCESS; |
---|
336 | } |
---|
337 | |
---|