source: trunk/source/geometry/solids/CSG/test/testSurfaceNormal.cc@ 1350

Last change on this file since 1350 was 1316, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 34.7 KB
Line 
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// Test File for tracking functions on a solid surface
28//
29// o Basic asserts on each function +
30// awkward cases for tracking / geom algorithms
31//
32// o Add tests on dicovering bugs in G4Sphere.cc...
33//
34// History:
35//
36// 09.05.05 V.Grichine SurfaceNormal for tubs, cons, sphere, torus, box
37// 11.11.04 V.Grichine creation for box
38//
39
40#include "G4ios.hh"
41#include <assert.h>
42#include <cmath>
43#include "globals.hh"
44#include "geomdefs.hh"
45#include "Randomize.hh"
46#include "G4Timer.hh"
47
48#include "ApproxEqual.hh"
49#include "G4GeometryTolerance.hh"
50
51#include "G4ThreeVector.hh"
52#include "G4RotationMatrix.hh"
53#include "G4AffineTransform.hh"
54#include "G4VoxelLimits.hh"
55
56#include "G4Box.hh"
57#include "G4Orb.hh"
58#include "G4Tubs.hh"
59#include "G4Sphere.hh"
60#include "G4Cons.hh"
61#include "G4Hype.hh"
62#include "G4Para.hh"
63#include "G4Torus.hh"
64#include "G4Trd.hh"
65
66
67
68///////////////////////////////////////////////////////////////////////////
69//
70//
71
72
73//const G4double kApproxEqualTolerance = kCarTolerance;
74
75// Return true if the double check is approximately equal to target
76//
77// Process:
78//
79// Return true is difference < kApproxEqualTolerance
80
81//G4bool ApproxEqual(const G4double check,const G4double target)
82//{
83// return (std::fabs(check-target)<kApproxEqualTolerance) ? true : false ;
84//}
85
86// Return true if the 3vector check is approximately equal to target
87//G4bool ApproxEqual(const G4ThreeVector& check, const G4ThreeVector& target)
88//{
89// return (ApproxEqual(check.x(),target.x())&&
90// ApproxEqual(check.y(),target.y())&&
91// ApproxEqual(check.z(),target.z()))? true : false;
92//}
93
94
95
96
97///////////////////////////////////////////////////////////////////
98//
99// Dave's auxiliary function
100
101const G4String OutputInside(const EInside a)
102{
103 switch(a)
104 {
105 case kInside: return "Inside";
106 case kOutside: return "Outside";
107 case kSurface: return "Surface";
108 }
109 return "????";
110}
111
112
113/////////////////////////////////////////////////////////////////////////////
114//
115// Random unit direction vector
116
117G4ThreeVector GetRandomUnitVector()
118{
119 G4double cosTheta, sinTheta, phi, vx, vy, vz;
120
121 cosTheta = -1. + 2.*G4UniformRand();
122 if( cosTheta > 1.) cosTheta = 1.;
123 if( cosTheta < -1.) cosTheta = -1.;
124 sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
125
126 phi = 2*pi*G4UniformRand();
127
128 vx = sinTheta*std::cos(phi);
129 vy = sinTheta*std::sin(phi);
130 vz = cosTheta;
131
132 return G4ThreeVector(vx,vy,vz);
133}
134
135/////////////////////////////////////////////////////////////////////////////
136//
137// Random vector on box surface
138
139G4ThreeVector GetVectorOnBox( G4Box& box )
140{
141 G4double rand, a, b, c, px, py, pz;
142 G4double part = 1./6.;
143
144 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
145
146 a = box.GetXHalfLength();
147 b = box.GetYHalfLength();
148 c = box.GetZHalfLength();
149
150 rand = G4UniformRand();
151
152 if ( rand < part )
153 {
154 px = -a - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
155 py = -b - 0.5*kCarTolerance + (2.*b + kCarTolerance)*G4UniformRand();
156 pz = -c - 0.5*kCarTolerance + (2.*c + kCarTolerance)*G4UniformRand();
157 }
158 else if ( rand < 2*part )
159 {
160 px = a - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
161 py = -b - 0.5*kCarTolerance + (2.*b + kCarTolerance)*G4UniformRand();
162 pz = -c - 0.5*kCarTolerance + (2.*c + kCarTolerance)*G4UniformRand();
163 }
164 else if ( rand < 3*part )
165 {
166 px = -a - 0.5*kCarTolerance + (2.*a + kCarTolerance)*G4UniformRand();
167 py = -b - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
168 pz = -c - 0.5*kCarTolerance + (2.*c + kCarTolerance)*G4UniformRand();
169 }
170 else if ( rand < 4*part )
171 {
172 px = -a - 0.5*kCarTolerance + (2.*a + kCarTolerance)*G4UniformRand();
173 py = b - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
174 pz = -c - 0.5*kCarTolerance + (2.*c + kCarTolerance)*G4UniformRand();
175 }
176 else if ( rand < 5*part )
177 {
178 px = -a - 0.5*kCarTolerance + (2.*a + kCarTolerance)*G4UniformRand();
179 py = -b - 0.5*kCarTolerance + (2.*b + kCarTolerance)*G4UniformRand();
180 pz = -c - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
181 }
182 else
183 {
184 px = -a - 0.5*kCarTolerance + (2.*a + kCarTolerance)*G4UniformRand();
185 py = -b - 0.5*kCarTolerance + (2.*b + kCarTolerance)*G4UniformRand();
186 pz = c - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
187 }
188
189 return G4ThreeVector(px,py,pz);
190}
191
192/////////////////////////////////////////////////////////////////////////////
193//
194// Random vector on orb surface
195
196G4ThreeVector GetVectorOnOrb(G4Orb& orb)
197{
198 G4double cosTheta, sinTheta, phi, radius, px, py, pz;
199
200 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
201
202 radius = orb.GetRadius();
203 radius += -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
204
205 cosTheta = -1. + 2.*G4UniformRand();
206 if( cosTheta > 1.) cosTheta = 1.;
207 if( cosTheta < -1.) cosTheta = -1.;
208 sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
209
210 phi = 2*pi*G4UniformRand();
211
212 px = radius*sinTheta*std::cos(phi);
213 py = radius*sinTheta*std::sin(phi);
214 pz = radius*cosTheta;
215
216 return G4ThreeVector(px,py,pz);
217}
218
219/////////////////////////////////////////////////////////////////////////////
220//
221// Random vector on sphere surface
222
223G4ThreeVector GetVectorOnSphere(G4Sphere& sphere)
224{
225 G4double cosTheta, sinTheta, phi, radius, px, py, pz;
226 G4double part = 1./6.;
227 G4double rand = G4UniformRand();
228
229 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
230 G4double kAngTolerance = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
231
232 G4double pRmin = sphere.GetInsideRadius();
233 G4double pRmax = sphere.GetOuterRadius();
234 G4double phi1 = sphere.GetStartPhiAngle();
235 G4double phi2 = phi1 + sphere.GetDeltaPhiAngle();
236 G4double theta1 = sphere.GetStartThetaAngle();
237 G4double theta2 = theta1 + sphere.GetDeltaThetaAngle();
238
239 if ( rand < part ) // Rmax
240 {
241 radius = pRmax -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
242
243 cosTheta = std::cos(theta2+0.5*kAngTolerance) +
244 (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
245 if( cosTheta > 1.) cosTheta = 1.;
246 if( cosTheta < -1.) cosTheta = -1.;
247 sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
248
249 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
250 }
251 else if ( rand < 2*part ) // Rmin
252 {
253 radius = pRmin -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
254
255 cosTheta = std::cos(theta2+0.5*kAngTolerance) +
256 (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
257 if( cosTheta > 1.) cosTheta = 1.;
258 if( cosTheta < -1.) cosTheta = -1.;
259 sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
260
261 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
262 }
263 else if ( rand < 3*part ) // phi1
264 {
265 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
266
267 cosTheta = std::cos(theta2+0.5*kAngTolerance) +
268 (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
269 if( cosTheta > 1.) cosTheta = 1.;
270 if( cosTheta < -1.) cosTheta = -1.;
271 sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
272
273 phi = phi1 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
274 }
275 else if ( rand < 4*part ) // phi2
276 {
277 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
278
279 cosTheta = std::cos(theta2+0.5*kAngTolerance) +
280 (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
281 if( cosTheta > 1.) cosTheta = 1.;
282 if( cosTheta < -1.) cosTheta = -1.;
283 sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
284
285 phi = phi2 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
286 }
287 else if ( rand < 5*part ) // theta1
288 {
289 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
290
291 cosTheta = std::cos(theta1+0.5*kAngTolerance) +
292 (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta1+0.5*kAngTolerance))*G4UniformRand();
293 if( cosTheta > 1.) cosTheta = 1.;
294 if( cosTheta < -1.) cosTheta = -1.;
295 sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
296
297 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
298 }
299 else // theta2
300 {
301 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
302
303 cosTheta = std::cos(theta2+0.5*kAngTolerance) +
304 (std::cos(theta2-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
305 if( cosTheta > 1.) cosTheta = 1.;
306 if( cosTheta < -1.) cosTheta = -1.;
307 sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
308
309 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
310 }
311
312 px = radius*sinTheta*std::cos(phi);
313 py = radius*sinTheta*std::sin(phi);
314 pz = radius*cosTheta;
315
316 return G4ThreeVector(px,py,pz);
317}
318
319/////////////////////////////////////////////////////////////////////////////
320//
321// Random vector on tubs surface
322
323G4ThreeVector GetVectorOnTubs(G4Tubs& tubs)
324{
325 G4double phi, radius, px, py, pz;
326 G4double part = 1./6.;
327 G4double rand = G4UniformRand();
328
329 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
330 G4double kAngTolerance = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
331
332 G4double pRmin = tubs.GetInnerRadius ();
333 G4double pRmax = tubs.GetOuterRadius ();
334 G4double tubsZ = tubs.GetZHalfLength ();
335 G4double phi1 = tubs.GetStartPhiAngle ();
336 G4double phi2 = phi1 + tubs.GetDeltaPhiAngle ();
337
338
339 if ( rand < part ) // Rmax
340 {
341 radius = pRmax -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
342 pz = -tubsZ - 0.5*kCarTolerance + (2*tubsZ + kCarTolerance)*G4UniformRand();
343 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
344 }
345 else if ( rand < 2*part ) // Rmin
346 {
347 radius = pRmin -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
348 pz = -tubsZ - 0.5*kCarTolerance + (2*tubsZ + kCarTolerance)*G4UniformRand();
349 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
350 }
351 else if ( rand < 3*part ) // phi1
352 {
353 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
354 pz = -tubsZ - 0.5*kCarTolerance + (2*tubsZ + kCarTolerance)*G4UniformRand();
355 phi = phi1 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
356 }
357 else if ( rand < 4*part ) // phi2
358 {
359 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
360 pz = -tubsZ - 0.5*kCarTolerance + (2*tubsZ + kCarTolerance)*G4UniformRand();
361 phi = phi2 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
362 }
363 else if ( rand < 5*part ) // -fZ
364 {
365 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
366
367 pz = -tubsZ - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
368
369 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
370 }
371 else // fZ
372 {
373 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
374 pz = tubsZ - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
375 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
376 }
377
378 px = radius*std::cos(phi);
379 py = radius*std::sin(phi);
380
381 return G4ThreeVector(px,py,pz);
382}
383
384/////////////////////////////////////////////////////////////////////////////
385//
386// Random vector on cons surface
387
388G4ThreeVector GetVectorOnCons(G4Cons& cons)
389{
390 G4double phi, pRmin, pRmax, radius, px, py, pz;
391 G4double part = 1./6.;
392 G4double rand = G4UniformRand();
393
394 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
395 G4double kAngTolerance = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
396
397 G4double pRmin1 = cons.GetInnerRadiusMinusZ ();
398 G4double pRmax1 = cons.GetOuterRadiusMinusZ ();
399 G4double pRmin2 = cons.GetInnerRadiusPlusZ ();
400 G4double pRmax2 = cons.GetOuterRadiusPlusZ ();
401 G4double consZ = cons.GetZHalfLength ();
402 G4double phi1 = cons.GetStartPhiAngle ();
403 G4double phi2 = phi1 + cons.GetDeltaPhiAngle ();
404 G4double tgMin = (pRmin2 - pRmin1)/(2.*consZ);
405 G4double tgMax = (pRmax2 - pRmax1)/(2.*consZ);
406
407 if ( rand < part ) // Rmax
408 {
409 pz = -consZ - 0.5*kCarTolerance + (2*consZ + kCarTolerance)*G4UniformRand();
410 pRmax = pRmax1 + tgMax*(pz+consZ);
411 radius = pRmax -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
412 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
413 }
414 else if ( rand < 2*part ) // Rmin
415 {
416 pz = -consZ - 0.5*kCarTolerance + (2*consZ + kCarTolerance)*G4UniformRand();
417 pRmin = pRmin1 + tgMin*(pz+consZ);
418 radius = pRmin -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
419 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
420 }
421 else if ( rand < 3*part ) // phi1
422 {
423 pz = -consZ - 0.5*kCarTolerance + (2*consZ + kCarTolerance)*G4UniformRand();
424 pRmax = pRmax1 + tgMax*(pz+consZ);
425 pRmin = pRmin1 + tgMin*(pz+consZ);
426 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
427 phi = phi1 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
428 }
429 else if ( rand < 4*part ) // phi2
430 {
431 pz = -consZ - 0.5*kCarTolerance + (2*consZ + kCarTolerance)*G4UniformRand();
432 pRmax = pRmax1 + tgMax*(pz+consZ);
433 pRmin = pRmin1 + tgMin*(pz+consZ);
434 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
435 phi = phi2 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
436 }
437 else if ( rand < 5*part ) // -fZ
438 {
439 pz = -consZ - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
440 radius = pRmin1 - 0.5*kCarTolerance + (pRmax1-pRmin1+kCarTolerance)*G4UniformRand();
441 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
442 }
443 else // fZ
444 {
445 pz = consZ - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
446 radius = pRmin2 - 0.5*kCarTolerance + (pRmax2-pRmin2+kCarTolerance)*G4UniformRand();
447 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
448 }
449
450 px = radius*std::cos(phi);
451 py = radius*std::sin(phi);
452
453 return G4ThreeVector(px,py,pz);
454}
455
456/////////////////////////////////////////////////////////////////////////////
457//
458// Random vector on torus surface
459
460G4ThreeVector GetVectorOnTorus(G4Torus& torus)
461{
462 G4double phi, radius, alpha, px, py, pz;
463 G4double part = 1./4.;
464 G4double rand = G4UniformRand();
465
466 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
467 G4double kAngTolerance = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
468
469 G4double pRmin = torus.GetRmin();
470 G4double pRmax = torus.GetRmax();
471 G4double pRtor = torus.GetRtor();
472 G4double phi1 = torus.GetSPhi();
473 G4double phi2 = phi1 + torus.GetDPhi ();
474
475
476 if ( rand < part ) // Rmax
477 {
478 radius = pRmax -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
479 alpha = twopi*G4UniformRand();
480 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
481 }
482 else if ( rand < 2*part ) // Rmin
483 {
484 radius = pRmin -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
485 alpha = twopi*G4UniformRand();
486 phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
487 }
488 else if ( rand < 3*part ) // phi1
489 {
490 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
491 alpha = twopi*G4UniformRand();
492 // pz = -pRtor - 0.5*kCarTolerance + (2*pRtor + kCarTolerance)*G4UniformRand();
493 phi = phi1 -0.5*kAngTolerance + (kAngTolerance)*G4UniformRand();
494 }
495 else // phi2
496 {
497 radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
498 alpha = twopi*G4UniformRand();
499 phi = phi2 -0.5*kAngTolerance + (kAngTolerance)*G4UniformRand();
500 }
501 px = (pRtor+radius*std::cos(alpha))*std::cos(phi);
502 py = (pRtor+radius*std::cos(alpha))*std::sin(phi);
503 pz = radius*std::sin(alpha);
504
505 return G4ThreeVector(px,py,pz);
506}
507
508enum Esolid {kBox, kOrb, kSphere, kCons, kTubs, kTorus, kPara, kTrapezoid, kTrd};
509
510
511//////////////////////////////////////////////////////////////////////
512//
513// Main executable function
514
515int main(int argc, char** argv)
516{
517 G4int test_one_solid( Esolid, int, int );
518
519 G4int no_points = 1000;
520 G4int dirs_per_point = 10000;
521
522 G4cout << "Usage: testDistanceAccuracy [ no_surface_points ] [ no_directions_each ]"
523 << G4endl << G4endl;
524
525 G4int points_in = 0, dirs_in = 0;
526
527 if( argc >= 2 ) points_in = atoi(argv[1]);
528 if( argc >= 3 ) dirs_in = atoi(argv[2]);
529
530
531 if( points_in > 0 ) { no_points= points_in; }
532 if( dirs_in > 0 ) { dirs_per_point = dirs_in; }
533
534G4cout << "Testing each solid with " << no_points << " surface points and "
535 << dirs_per_point << " directions each. " << G4endl;
536
537 Esolid useCase;
538
539 /*
540 G4cout<< "To test Box." << G4endl;
541 test_one_solid( useCase= kBox, no_points, dirs_per_point );
542 */
543
544 G4cout<< "To test Tubs." << G4endl;
545 test_one_solid( useCase= kTubs, no_points, dirs_per_point );
546
547 /*
548 G4cout<< "To test Sphere." << G4endl;
549 test_one_solid( useCase= kSphere, no_points, dirs_per_point );
550
551 G4cout<< "To test Orb." << G4endl;
552 test_one_solid( useCase= kOrb, no_points, dirs_per_point );
553
554 G4cout<< "To test Cons." << G4endl;
555 test_one_solid( useCase= kCons, no_points, dirs_per_point );
556
557 G4cout<< "To test Para." << G4endl;
558 test_one_solid( useCase= kPara, no_points, dirs_per_point );
559
560 G4cout<< "To test Trapezoid." << G4endl;
561 test_one_solid( useCase= kTrapezoid, no_points, dirs_per_point );
562
563 G4cout<< "To test Trd." << G4endl;
564 test_one_solid( useCase= kTrd, no_points, dirs_per_point );
565 */
566
567 return 0;
568}
569
570//////////////////////////////////////////////////////////////////
571//
572// Test one solid selected with statistics in main
573
574int test_one_solid ( Esolid useCase, int num_points, int directions_per_point )
575{
576 G4int i,j;
577 G4int iMax = num_points, jMax = directions_per_point;
578 G4int iCheck=iMax/10;
579
580 G4double distIn, distOut;
581 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
582
583 G4double Rtor = 100 ;
584 G4double Rmax = Rtor*0.9 ;
585 G4double Rmin = Rtor*0.1 ;
586
587
588 EInside surfaceP;
589
590 G4ThreeVector norm,*pNorm;
591 G4bool *pgoodNorm, goodNorm, calcNorm = true;
592 G4Timer timer;
593
594
595 pNorm=&norm;
596 pgoodNorm=&goodNorm;
597
598 G4cout.precision(20);
599
600 // Boxes for test
601
602 G4Box b1("Test Box #1",20,30,40);
603 G4Box b2("Test Box #2",10,10,10);
604 G4Box box3("BABAR Box",0.14999999999999999,
605 24.707000000000001,
606 22.699999999999999) ;
607
608 // orbs for test
609
610 G4Orb o1("Solid G4Orb",50);
611 G4Orb o10("s10",0.018*mm);
612 // G4Orb* solidO1= new G4Orb("O1", 2.7*cm);
613
614
615 // spheres for test
616
617 // G4Sphere s5("Patch (phi/theta seg)",45,50,-pi/4,halfpi,pi/4,halfpi);
618 // G4Sphere s5("Patch (phi/theta seg)",45,50,-pi/4.,pi/4.,pi/4,pi/4.);
619
620 // G4Sphere s5("Patch (phi/theta seg)",45,50,-pi/4.,pi/4.,pi/2,pi/4.);
621 // G4Sphere s5("Patch (phi/theta seg)",45,50,pi/4.,pi/4.,pi/2,pi/4.);
622 G4Sphere s5("Patch (phi/theta seg)",45,50,pi/4.,pi/8.,pi/4,pi/8.);
623
624 G4Sphere s6("John example",300,500,0,5.76,0,pi) ;
625 G4Sphere s7("sphere7",1400.,1550.,0.022321428571428572,0.014642857142857141,
626 1.5631177553663251,0.014642857142857141 );
627 G4Sphere s8("sphere",278.746*mm, 280.0*mm, 0.0*degree, 360.0*degree,
628 0.0*degree, 90.0*degree);
629
630 G4Sphere b216("b216", 1400.0, 1550.0,
631 0.022321428571428572,
632 0.014642857142857141,
633 1.578117755366325,
634 0.014642857142867141);
635
636 G4Sphere s9("s9",0*mm,410*mm,0*degree,360*degree,90*degree,90*degree);
637
638 G4Sphere b402("b402", 475*mm, 480*mm,
639 0*degree,360*degree,17.8*degree,144.4*degree);
640
641
642 G4Sphere s10("s10",0*mm,0.018*mm,0*degree,360*degree,0*degree,180*degree);
643
644
645 G4Sphere s11("s11",5000000.*mm,
646 3700000000.*mm,
647 0*degree,360*degree,0*degree,180*degree);
648
649
650 G4Sphere sAlex("sAlex",500.*mm,
651 501.*mm,
652 0*degree,360*degree,0*degree,180*degree);
653
654 G4Sphere sLHCB("sLHCB",8600*mm, 8606*mm,
655 -1.699135525184141*degree,
656 3.398271050368263*degree,88.52855940538514*degree,2.942881189229715*degree );
657
658 G4Sphere spAroundX("SpAroundX", 10.*mm, 1000.*mm, -1.0*degree,
659 2.0*degree,
660 0.*degree, 180.0*degree );
661
662
663 // G4Tubs t4("Hole Sector #4",45*mm,50*mm,50*mm,halfpi,halfpi);
664 // G4Tubs t4("Hole Sector #4",45*mm,50*mm,50*mm,-halfpi,halfpi);
665 G4Tubs t4("Hole Sector #4",45*mm,50*mm,50*mm,pi/4.,pi/8.);
666
667 G4Cons c4("Hollow Cut Cone",50,100,50,200,50,-pi/6,pi/3);
668 G4Cons c5("Hollow Cut Cone",25,50,75,150,50,0,3*halfpi);
669
670 G4Torus torus1("torus1",10.,15.,20.,0.,3*halfpi);
671 G4Torus tor2("Hole cutted Torus #2",Rmin,Rmax,Rtor,pi/4,halfpi);
672 G4Torus torn2("tn2",Rmin,Rmax,Rtor,halfpi,halfpi);
673 G4Torus torn3("tn3",Rmin,Rmax,Rtor,halfpi,3*halfpi);
674
675
676 // Check of some use cases shown zero-zero problems
677
678 G4ThreeVector pCheck, vCheck;
679
680 // pCheck = G4ThreeVector( 41.418613476008794, -16.893662525384702, 4.9094423552800466 );
681 // vCheck = G4ThreeVector( 0.34553222148699703, 0.91172822040596313, 0.22216916084289551 );
682 // distIn = s5.DistanceToIn(pCheck,vCheck);
683 // distOut = s5.DistanceToOut(pCheck,vCheck,calcNorm,pgoodNorm,pNorm);
684
685 // pCheck = G4ThreeVector( 43.169180219772784, -11.564259048580507, 5.2621090605480623 );
686 // surfaceP = s5.Inside(pCheck);
687
688 pCheck = G4ThreeVector( -51.189087930597751, -17.382942686173514, -45.939946175080983 );
689 vCheck = G4ThreeVector( 0.44410267104120671, -0.88563345532911941, -0.13574314117431641 );
690 distIn = c5.DistanceToIn(pCheck,vCheck);
691 distOut = c5.DistanceToOut(pCheck,vCheck,calcNorm,pgoodNorm,pNorm);
692
693 pCheck = G4ThreeVector(-41.407491890396564, -31.155805955816909, -48.18046093035241 );
694 vCheck = G4ThreeVector(0.79040557001853884, -0.52472467107317944, -0.31610608100891113 );
695 distIn = c5.DistanceToIn(pCheck,vCheck);
696 distOut = c5.DistanceToOut(pCheck,vCheck,calcNorm,pgoodNorm,pNorm);
697
698 pCheck = G4ThreeVector(-66.68328490196707, -47.460245099793099, -18.151754141035401 );
699 vCheck = G4ThreeVector(-0.066679791594195931, 0.88577693677046576, -0.45929622650146484 );
700 distIn = c5.DistanceToIn(pCheck,vCheck);
701 distOut = c5.DistanceToOut(pCheck,vCheck,calcNorm,pgoodNorm,pNorm);
702
703
704#ifdef NDEBUG
705 G4Exception("FAIL: *** Assertions must be compiled in! ***");
706#endif
707
708
709 // Check box tracking function
710
711 switch (useCase)
712 {
713
714 case kBox:
715 G4cout<<"Testing G4Box:"<<G4endl<<G4endl;
716 for(i=0;i<iMax;i++)
717 {
718 G4ThreeVector p = GetVectorOnBox(b1);
719
720 surfaceP = b1.Inside(p);
721 if(surfaceP != kSurface)
722 {
723 G4cout<<"p is out of surface: "<<G4endl;
724 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl<<G4endl;
725
726 }
727 else
728 {
729 for(j=0;j<jMax;j++)
730 {
731 G4ThreeVector v = GetRandomUnitVector();
732
733 distIn = b1.DistanceToIn(p,v);
734 distOut = b1.DistanceToOut(p,v,calcNorm,pgoodNorm,pNorm);
735
736 if( distIn < kCarTolerance && distOut < kCarTolerance )
737 {
738 G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
739 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
740 G4cout<<"location p: "<<G4endl;
741 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
742 G4cout<<" direction v: "<<G4endl;
743 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
744 }
745 else if(distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance)
746 {
747 G4cout<<" distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance"<<G4endl;
748 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
749 G4cout<<"location p: "<<G4endl;
750 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
751 G4cout<<" direction v: "<<G4endl;
752 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
753 }
754 }
755 }
756 }
757 break;
758
759 case kOrb:
760 G4cout<<"Testing G4Orb:"<<G4endl<<G4endl;
761 for(i=0;i<iMax;i++)
762 {
763 G4ThreeVector p = GetVectorOnOrb(o1);
764
765 surfaceP = o1.Inside(p);
766 if(surfaceP != kSurface)
767 {
768 G4cout<<"p is out of surface: "<<G4endl;
769 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl<<G4endl;
770
771 }
772 else
773 {
774 for(j=0;j<jMax;j++)
775 {
776 G4ThreeVector v = GetRandomUnitVector();
777
778 distIn = o1.DistanceToIn(p,v);
779 distOut = o1.DistanceToOut(p,v,calcNorm,pgoodNorm,pNorm);
780
781 if( distIn < kCarTolerance && distOut < kCarTolerance )
782 {
783 G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
784 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
785 G4cout<<"location p: "<<G4endl;
786 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
787 G4cout<<" direction v: "<<G4endl;
788 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
789 }
790 else if(distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance)
791 {
792 G4cout<<" distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance"<<G4endl;
793 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
794 G4cout<<"location p: "<<G4endl;
795 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
796 G4cout<<" direction v: "<<G4endl;
797 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
798 }
799 }
800 }
801 }
802 break;
803
804 case kSphere:
805 G4cout<<"Testing all cutted G4Sphere:"<<G4endl<<G4endl;
806
807 timer.Start();
808
809 for(i=0;i<iMax;i++)
810 {
811 if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
812 G4ThreeVector p = GetVectorOnSphere(s5);
813 surfaceP = s5.Inside(p);
814 if(surfaceP != kSurface)
815 {
816 G4cout<<"p is out of surface: "<<G4endl;
817 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl<<G4endl;
818
819 }
820 else
821 {
822 norm = s5.SurfaceNormal(p);
823 /*
824 for(j=0;j<jMax;j++)
825 {
826 G4ThreeVector v = GetRandomUnitVector();
827
828 distIn = s5.DistanceToIn(p,v);
829 distOut = s5.DistanceToOut(p,v,calcNorm,pgoodNorm,pNorm);
830
831 // if( distIn < kCarTolerance && distOut < kCarTolerance )
832 if( distIn == 0. && distOut == 0. )
833 {
834 G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
835 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
836 G4cout<<"location p: "<<G4endl;
837 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
838 G4cout<<" direction v: "<<G4endl;
839 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
840 }
841 else if(distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance)
842 {
843
844 G4cout<<" distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance"<<G4endl;
845 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
846 G4cout<<"location p: "<<G4endl;
847 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
848 G4cout<<" direction v: "<<G4endl;
849 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
850
851 }
852 }
853 */
854 }
855
856 }
857 timer.Stop();
858 G4cout.precision(6);
859 G4cout<<"G4Sphere::SN time = "<<timer.GetUserElapsed()<<" s"<<G4endl;
860
861
862 break;
863
864 case kTubs:
865 G4cout<<"Testing all cutted G4Tubs:"<<G4endl<<G4endl;
866
867 timer.Start();
868
869 for(i=0;i<iMax;i++)
870 {
871 if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
872
873 G4ThreeVector p = GetVectorOnTubs(t4);
874 surfaceP = t4.Inside(p);
875
876 if(surfaceP != kSurface)
877 {
878 // G4cout<<"p is out of surface: "<<G4endl;
879 // G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl<<G4endl;
880 // norm = t4.SurfaceNormal(p);
881
882 }
883 else
884 {
885
886 norm = t4.SurfaceNormal(p);
887
888 /*
889 for(j=0;j<jMax;j++)
890 {
891 G4ThreeVector v = GetRandomUnitVector();
892
893 distIn = t4.DistanceToIn(p,v);
894 distOut = t4.DistanceToOut(p,v,calcNorm,pgoodNorm,pNorm);
895
896 // if( distIn < kCarTolerance && distOut < kCarTolerance )
897 if( distIn == 0. && distOut == 0. )
898 {
899 G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
900 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
901 G4cout<<"location p: "<<G4endl;
902 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
903 G4cout<<" direction v: "<<G4endl;
904 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
905 }
906 else if(distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance)
907 {
908
909 G4cout<<" distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance"<<G4endl;
910 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
911 G4cout<<"location p: "<<G4endl;
912 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
913 G4cout<<" direction v: "<<G4endl;
914 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
915
916 }
917 }
918 */
919 }
920 }
921 timer.Stop();
922 G4cout.precision(6);
923 G4cout<<"G4Tubs::SN time = "<<timer.GetUserElapsed()<<" s"<<G4endl;
924
925 break;
926
927 case kCons:
928 G4cout<<"Testing all cutted G4Cons:"<<G4endl<<G4endl;
929 timer.Start();
930 for(i=0;i<iMax;i++)
931 {
932 if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
933 G4ThreeVector p = GetVectorOnCons(c5);
934 surfaceP = c5.Inside(p);
935 if(surfaceP != kSurface)
936 {
937 G4cout<<"p is out of surface: "<<G4endl;
938 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl<<G4endl;
939
940 }
941 else
942 {
943 norm = c5.SurfaceNormal(p);
944 /*
945 for(j=0;j<jMax;j++)
946 {
947 G4ThreeVector v = GetRandomUnitVector();
948
949 distIn = c5.DistanceToIn(p,v);
950 distOut = c5.DistanceToOut(p,v,calcNorm,pgoodNorm,pNorm);
951
952 // if( distIn < kCarTolerance && distOut < kCarTolerance )
953 if( distIn == 0. && distOut == 0. )
954 {
955 G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
956 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
957 G4cout<<"location p: "<<G4endl;
958 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
959 G4cout<<" direction v: "<<G4endl;
960 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
961 }
962 else if(distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance)
963 {
964
965 G4cout<<" distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance"<<G4endl;
966 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
967 G4cout<<"location p: "<<G4endl;
968 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
969 G4cout<<" direction v: "<<G4endl;
970 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
971
972 }
973 }
974 */
975 }
976 }
977 timer.Stop();
978 G4cout.precision(6);
979 G4cout<<"G4Cons::SN time = "<<timer.GetUserElapsed()<<" s"<<G4endl;
980
981 break;
982 case kTorus:
983 G4cout<<"Testing all cutted G4Torus:"<<G4endl<<G4endl;
984 timer.Start();
985 for(i=0;i<iMax;i++)
986 {
987 if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
988 G4ThreeVector p = GetVectorOnTorus(torus1);
989 surfaceP = torus1.Inside(p);
990 if(surfaceP != kSurface)
991 {
992 G4cout<<"p is out of surface: "<<G4endl;
993 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl<<G4endl;
994
995 }
996 else
997 {
998 norm=torus1.SurfaceNormal(p);
999 /*
1000 for(j=0;j<jMax;j++)
1001 {
1002 G4ThreeVector v = GetRandomUnitVector();
1003
1004 distIn = torus1.DistanceToIn(p,v);
1005 distOut = torus1.DistanceToOut(p,v,calcNorm,pgoodNorm,pNorm);
1006
1007 // if( distIn < kCarTolerance && distOut < kCarTolerance )
1008 if( distIn == 0. && distOut == 0. )
1009 {
1010 G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
1011 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
1012 G4cout<<"location p: "<<G4endl;
1013 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
1014 G4cout<<" direction v: "<<G4endl;
1015 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
1016 }
1017 else if(distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance)
1018 {
1019
1020 G4cout<<" distIn > 100000*kCarTolerance && distOut > 100*kCarTolerance"<<G4endl;
1021 G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
1022 G4cout<<"location p: "<<G4endl;
1023 G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
1024 G4cout<<" direction v: "<<G4endl;
1025 G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
1026
1027 }
1028 }
1029 */
1030 }
1031 }
1032 timer.Stop();
1033 G4cout.precision(6);
1034 G4cout<<"G4Torus::SN time = "<<timer.GetUserElapsed()<<" s"<<G4endl;
1035 break;
1036
1037 default:
1038 break;
1039 }
1040 return 0;
1041}
1042
Note: See TracBrowser for help on using the repository browser.