source: trunk/source/geometry/navigation/test/testG4NestedParameterisedNav.cc@ 1349

Last change on this file since 1349 was 1347, checked in by garnier, 15 years ago

geant4 tag 9.4

File size: 23.8 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// $Id: testG4NestedParameterisedNav.cc,v 1.6 2006/06/29 18:37:30 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30//
31// Locate & Step within simple boxlike geometry, both
32// with and without voxels. Parameterised volumes are included.
33
34#include <assert.h>
35#include "ApproxEqual.hh"
36
37// Global defs
38#include "globals.hh"
39
40#include "G4Navigator.hh"
41
42#include "G4LogicalVolume.hh"
43#include "G4VPhysicalVolume.hh"
44#include "G4PVPlacement.hh"
45#include "G4PVParameterised.hh"
46#include "G4VPVParameterisation.hh"
47#include "G4VNestedParameterisation.hh"
48
49#include "G4Box.hh"
50
51#include "G4GeometryManager.hh"
52
53#include "G4RotationMatrix.hh"
54#include "G4ThreeVector.hh"
55
56#include "G4Material.hh"
57#include "G4Element.hh"
58
59G4Material *darkMaterial, *brightMaterial, *defaultMaterial; // Chessboard
60
61// Sample First level Parameterisation -- host to nested 2nd
62class XTopParam: public G4VPVParameterisation
63{
64 public:
65 XTopParam( G4int numRowsX, G4double xFullWidth, G4double yFullWidth, G4double zFullWidth)
66 : fNumRows(numRowsX),
67 fXfullWidth(xFullWidth),
68 fYfullWidth(yFullWidth),
69 fZfullWidth(zFullWidth) {} ;
70
71 virtual void ComputeTransformation(const G4int n,
72 G4VPhysicalVolume* pRep) const
73 {
74 // G4cout << " Transf for n= " << n << " Offset x= "
75 // << (n-((fNumRows-1.0)/2.))*fXfullWidth << G4endl;
76 pRep->SetTranslation(G4ThreeVector( (n-((fNumRows-1.0)/2.))*fXfullWidth, 0., 0.) );
77 }
78
79 virtual void ComputeDimensions(G4Box &pBox,
80 const G4int,
81 const G4VPhysicalVolume*) const
82 {
83 pBox.SetXHalfLength(fXfullWidth*0.5);
84 pBox.SetYHalfLength(fYfullWidth*0.5);
85 pBox.SetZHalfLength(fZfullWidth*0.5);
86 }
87
88 virtual void ComputeDimensions(G4Tubs &, const G4int ,
89 const G4VPhysicalVolume*) const {}
90 virtual void ComputeDimensions(G4Trd &, const G4int,
91 const G4VPhysicalVolume*) const {}
92 virtual void ComputeDimensions(G4Cons &, const G4int ,
93 const G4VPhysicalVolume*) const {}
94 virtual void ComputeDimensions(G4Trap &, const G4int ,
95 const G4VPhysicalVolume*) const {}
96 virtual void ComputeDimensions(G4Hype &, const G4int ,
97 const G4VPhysicalVolume*) const {}
98 virtual void ComputeDimensions(G4Orb &, const G4int ,
99 const G4VPhysicalVolume*) const {}
100 virtual void ComputeDimensions(G4Sphere &, const G4int ,
101 const G4VPhysicalVolume*) const {}
102 virtual void ComputeDimensions(G4Torus &, const G4int ,
103 const G4VPhysicalVolume*) const {}
104 virtual void ComputeDimensions(G4Para &, const G4int ,
105 const G4VPhysicalVolume*) const {}
106 virtual void ComputeDimensions(G4Polycone &, const G4int ,
107 const G4VPhysicalVolume*) const {}
108 virtual void ComputeDimensions(G4Polyhedra &, const G4int ,
109 const G4VPhysicalVolume*) const {}
110
111 private:
112 G4int fNumRows;
113 G4double fXfullWidth, fYfullWidth, fZfullWidth;
114
115} ;
116
117// Sample Nested Parameterisation
118class YSecondNestedParam: public G4VNestedParameterisation
119{
120 //
121 // This parameterisation is nested inside another
122 // It creates boxes in a checker-board manner
123 // with different sizes on the odd-even diagonals.
124 //
125public:
126 YSecondNestedParam( G4int numCols, G4double ySliceHalfSize, G4double xBoxHalfWidth, G4double zBoxHalfWidth )
127 : fNumCols( numCols ) ,
128 fYBoxHalfWidth(ySliceHalfSize),
129 fYFullBoxWidth(ySliceHalfSize*2.0),
130 fXBoxHalfWidth(xBoxHalfWidth),
131 fZBoxHalfWidth(zBoxHalfWidth)
132 {}
133
134 virtual void ComputeTransformation(const G4int n,
135 G4VPhysicalVolume* pRep) const
136 {
137 pRep->SetTranslation(G4ThreeVector(0.,
138 (n-((fNumCols-1)/2.))*fYFullBoxWidth,
139 0.) );
140 pRep->SetRotation(0);
141 }
142
143 virtual G4Material* ComputeMaterial(G4VPhysicalVolume *currentVol,
144 const G4int no_lev,
145 const G4VTouchable *parentTouch)
146 {
147 G4Material *material;
148
149 if( parentTouch == 0) {
150 G4Exception( "YSecondNestedParam::ComputeMaterial()",
151 "Null parent TouchHist", FatalException,
152 " Null pointer as parent touchable pointer. " );
153 }
154
155 // Get the information about the parent volume
156 G4int no_parent= parentTouch->GetReplicaNumber();
157
158 // Rule: Odd ones are one material, even ones are another
159 G4int num, odd;
160 num= no_lev + no_parent;
161 odd= ( num % 2 );
162
163 if( odd == 1 ) {
164 material= darkMaterial;
165 } else {
166 material= brightMaterial;
167 }
168 G4LogicalVolume* currentLogVol= currentVol->GetLogicalVolume();
169 currentLogVol->SetMaterial( material );
170
171 return material;
172 }
173
174 G4int GetNumberOfMaterials() const { return 2; }
175
176 G4Material* GetMaterial(G4int idx) const
177 {
178 G4Material *mat;
179 if (idx % 2 == 0){
180 mat= darkMaterial;
181 }else{
182 mat= brightMaterial;
183 }
184 return mat;
185 }
186
187 virtual void ComputeDimensions(G4Box &pBox,
188 const G4int,
189 const G4VPhysicalVolume*) const
190 {
191 pBox.SetXHalfLength(fXBoxHalfWidth);
192 pBox.SetYHalfLength(fYBoxHalfWidth);
193 pBox.SetZHalfLength(fZBoxHalfWidth);
194 }
195 virtual void ComputeDimensions(G4Tubs &,
196 const G4int ,
197 const G4VPhysicalVolume*) const {}
198 virtual void ComputeDimensions(G4Trd &,
199 const G4int,
200 const G4VPhysicalVolume*) const {}
201 virtual void ComputeDimensions(G4Cons &,
202 const G4int ,
203 const G4VPhysicalVolume*) const {}
204 virtual void ComputeDimensions(G4Trap &,
205 const G4int ,
206 const G4VPhysicalVolume*) const {}
207 virtual void ComputeDimensions(G4Hype &,
208 const G4int ,
209 const G4VPhysicalVolume*) const {}
210 virtual void ComputeDimensions(G4Orb &,
211 const G4int ,
212 const G4VPhysicalVolume*) const {}
213 virtual void ComputeDimensions(G4Sphere &,
214 const G4int ,
215 const G4VPhysicalVolume*) const {}
216 virtual void ComputeDimensions(G4Torus &,
217 const G4int ,
218 const G4VPhysicalVolume*) const {}
219 virtual void ComputeDimensions(G4Para &,
220 const G4int ,
221 const G4VPhysicalVolume*) const {}
222 virtual void ComputeDimensions(G4Polycone &,
223 const G4int ,
224 const G4VPhysicalVolume*) const {}
225 virtual void ComputeDimensions(G4Polyhedra &,
226 const G4int ,
227 const G4VPhysicalVolume*) const {}
228
229private:
230 G4int fNumCols;
231 G4double fYBoxHalfWidth, fYFullBoxWidth;
232 G4double fXBoxHalfWidth, fZBoxHalfWidth;
233
234} ; // level2NestedParam;
235
236// Build simple geometry:
237// 4 small cubes + 1 slab (all G4Boxes) are positioned inside a larger cuboid
238G4VPhysicalVolume* BuildGeometry()
239{
240 // Materials
241 // --------------------------------
242 // for use in world and parameterisation
243 G4double a, fractionmass, density;
244 G4int z, ncomponents;
245
246 G4Element* N = new G4Element("Nitrogen", "N", z=7, a= 14.01*g/mole);
247 G4Element* O = new G4Element("Oxygen" , "O", z=8, a= 16.00*g/mole);
248
249 G4Material* Air =
250 new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
251 Air->AddElement(N, fractionmass=0.7);
252 Air->AddElement(O, fractionmass=0.3);
253
254 //Lead
255 G4Material* Pb =
256 new G4Material("Lead", z=82, a= 207.19*g/mole, density= 11.35*g/cm3);
257 G4Material* Al =
258 new G4Material("Aluminium", z=13, a=26.98*g/mole, density=2.700*g/cm3);
259
260 // Define standard materials
261 darkMaterial= Pb;
262 brightMaterial= Al;
263 defaultMaterial= Air;
264
265 // Solids
266 // --------------------------------
267 G4Box *myWorldBox= new G4Box ("WorldBox",1000.*cm,1000.*cm,1000.*cm);
268 G4Box *myTopBox=new G4Box("cube",100.*cm,100.*cm,100.*cm);
269
270 G4LogicalVolume *worldLog=new G4LogicalVolume(myWorldBox,defaultMaterial,
271 "World",0,0,0);
272 // Logical with no material,field,
273 // sensitive detector or user limits
274
275 G4PVPlacement *worldPhys=new G4PVPlacement(0,G4ThreeVector(0,0,0),
276 "World",worldLog,
277 0,false,0);
278 // Note: no mother pointer set
279
280 G4LogicalVolume *topLog=new G4LogicalVolume(myTopBox,defaultMaterial,
281 "Level0 Top-LV"); // ,0,0,0);
282
283
284 // Place two 'Top' Boxes in world
285 // ------------------------------
286 new G4PVPlacement(0, G4ThreeVector(-250.*cm, 0., 0.),
287 "Top 1-pv", topLog, worldPhys, false, 0);
288
289 new G4PVPlacement(0, G4ThreeVector( 250.*cm, 0., 0.),
290 "Top 2-pv", topLog, worldPhys, false, 1);
291
292
293 // Place slabs inside Top Box
294 // --------------------------
295 G4int numSlabs= 10;
296 G4double xTopHalfWidth=100.*cm, yTopHalfWidth=100.*cm, zTopHalfWidth=100.*cm;
297 G4double xSlabHalfWidth= xTopHalfWidth / numSlabs;
298 G4double ySlabHalfWidth= yTopHalfWidth;
299 G4double zSlabHalfWidth= zTopHalfWidth;
300
301 G4Box *mySlab= new G4Box("slab", xSlabHalfWidth, yTopHalfWidth, zTopHalfWidth);
302 // Original: 10.0*cm, 100.*cm, 100.*cm);
303 G4LogicalVolume *slabLog=new G4LogicalVolume(mySlab,defaultMaterial,
304 "Level1 Slab-LV"); // ,0,0,0);
305
306 XTopParam* pFirstLevelParam =
307 new XTopParam( numSlabs, xSlabHalfWidth*2., yTopHalfWidth*2., zTopHalfWidth*2. );
308
309 // G4PVParameterised *paramLevelOnePhys=
310 new G4PVParameterised("Slab Blocks in X",
311 slabLog,
312 topLog,
313 kXAxis,
314 numSlabs,
315 pFirstLevelParam);
316
317 // Place inner-boxes inside Slabs Box
318 // ----------------------------------
319
320 G4int numBoxesY= 10;
321
322 // G4double xBoxHalfWidth==100.*cm, yBoxHalfWidth=100.*cm, zBoxHalfWidth=100.*cm;
323
324 G4double xBoxHalfWidth= xSlabHalfWidth;
325 G4double yBoxHalfWidth= ySlabHalfWidth / numBoxesY;
326 G4double zBoxHalfWidth= zSlabHalfWidth;
327 G4Box *mySmallestBox=new G4Box("Smallest Box",
328 // 10.*cm, 10.*cm, 100.*cm);
329 xBoxHalfWidth, yBoxHalfWidth, zBoxHalfWidth);
330 G4LogicalVolume *variLog=new G4LogicalVolume(mySmallestBox,defaultMaterial,
331 "Level2 Smallest Box-LV");
332 G4VNestedParameterisation* pSecondLevelParam =
333 new YSecondNestedParam( numBoxesY, yBoxHalfWidth, xBoxHalfWidth, zBoxHalfWidth);
334
335 // G4PVParameterised *paramLevelTwoPhys=
336 new G4PVParameterised("Level 2 blocks in y",
337 variLog,
338 slabLog,
339 kYAxis,
340 numBoxesY,
341 pSecondLevelParam);
342
343 G4cout << " Slab dimensions (half-width) are: " << G4endl
344 << " x= " << xSlabHalfWidth/cm << " cm "
345 << " y= " << ySlabHalfWidth/cm << " cm "
346 << " z= " << zSlabHalfWidth/cm << " cm " << G4endl << G4endl;
347
348 G4cout << " Box dimensions (half-width) are: " << G4endl
349 << " x= " << xBoxHalfWidth/cm << " cm "
350 << " y= " << yBoxHalfWidth/cm << " cm "
351 << " z= " << zBoxHalfWidth/cm << " cm " << G4endl << G4endl;
352
353
354 // Other volumes
355 G4Box *myMediumBox=new G4Box("Med Box", 25.*cm,25.*cm,25.*cm);
356 G4LogicalVolume *medLog=new G4LogicalVolume(myMediumBox,Al,
357 "medBox-LV"); // ,0,0,0);
358 new G4PVPlacement(0, G4ThreeVector(-500.*cm, 500.*cm, 0.),
359 "Target-X+Y", medLog, worldPhys, false, 1);
360 new G4PVPlacement(0, G4ThreeVector( 500.*cm, -500.*cm, 0.),
361 "Target+X-Y", medLog, worldPhys, false, 1);
362
363 return worldPhys;
364}
365
366//
367// Test LocateGlobalPointAndSetup
368//
369G4bool testG4Navigator1(G4VPhysicalVolume *pTopNode)
370{
371 MyNavigator myNav;
372 G4VPhysicalVolume *located;
373 myNav.SetWorldVolume(pTopNode);
374 G4int copyNo= -1;
375
376#ifdef ALL_TESTS
377 assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0),0,false));
378 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,0),0,false);
379 assert(located->GetName()=="World");
380
381 assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0)));
382
383// Check relative search that causes backup one level and then search down:
384// Nonrel' finds Target 3, then rel' with point in Target 5 finds Target 5
385 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(151.*cm,0,-10),0,false);
386 assert(located->GetName()=="Level 2 blocks in y");
387
388 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(500.*cm,-510.*cm,0));
389 assert(located->GetName()=="Target+X-Y");
390 assert(ApproxEqual(myNav.CurrentLocalCoordinate(),G4ThreeVector(0.,-10.*cm,0.)));
391// Check that outside point causes stack to unwind
392 assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0)));
393// Check parameterised volumes
394// ---------------------------------------------------------
395// Replication 0
396 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-340.*cm,-95.*cm,-2.5*cm));
397 assert(located->GetName()=="Level 2 blocks in y");
398 copyNo= located->GetCopyNo();
399 // G4cout << " Located ( -340.*cm, -95.*cm, -2.5*cm ) in "
400 // << located->GetName() << " copy no " << copyNo << G4endl;
401 assert(located->GetCopyNo() == 0 );
402 // Mother copy/replica number should be 0
403
404 // Center of volume should be at ( -340 cm, -90 cm, 0 )
405 G4ThreeVector localCoords ( 0.*cm,-5.*cm, -2.5*cm );
406 // G4cout << " Local coordinates: " << G4endl
407 // << " Expected " << localCoords << G4endl
408 // << " Obtained " << myNav.CurrentLocalCoordinate() << G4endl;
409 assert(ApproxEqual(myNav.CurrentLocalCoordinate(), localCoords ));
410 // G4ThreeVector(0.*cm,-5.*cm,-2.5*cm)));
411 assert(located->GetLogicalVolume()->GetMaterial()==brightMaterial);
412
413 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(500.*cm,-510.*cm,0));
414 assert(located->GetName()=="Target+X-Y");
415
416
417// Replication 1
418 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-340.*cm,-75.*cm,-2.5*cm));
419 assert(located->GetName()=="Level 2 blocks in y");
420 // copyNo= located->GetCopyNo();
421 assert(located->GetCopyNo() == 1 );
422 // Mother copy/replica number should be 0
423 //
424 assert(ApproxEqual(myNav.CurrentLocalCoordinate(),
425 G4ThreeVector(0.0*cm,-5.*cm,-2.5*cm)));
426 assert(located->GetLogicalVolume()->GetMaterial()==darkMaterial);
427
428 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(500.*cm,-510.*cm,0));
429 assert(located->GetName()=="Target+X-Y");
430
431// Replication 2
432 /// ....
433#endif
434
435 // Forward part
436
437 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector( 280.*cm, 75.*cm, 25.*cm));
438 // Position inside Top Box is +30 cm, 75 cm, 25 cm
439 // Box extent: -100 cm to +100 cm in X, cut in 10 slabs
440 // Slab number(X): #6, local position +0 cm, 75 cm, 25 cm
441 // Slab extent: -10 cm to +10 cm in X, -100 cm to 100 cm in Y, Z
442 // Slice number(Y, from 10): #8, local position: 0 cm, 5 cm, 25 cm.
443
444 copyNo= located->GetCopyNo();
445 G4cout << " Located ( 280.*cm, 75.*cm, 25.*cm ) in '"
446 << located->GetName() << "' copy no " << copyNo << G4endl;
447 G4cout << " Local coordinates " << myNav.CurrentLocalCoordinate() << G4endl;
448 G4cout << G4endl;
449 assert(located->GetName()=="Level 2 blocks in y");
450 assert(located->GetCopyNo() == 8 );
451 // Mother copy/replica number should be 0
452 //
453 assert(ApproxEqual(myNav.CurrentLocalCoordinate(),
454 G4ThreeVector(0.0*cm, 5.*cm, 25.*cm)));
455 assert(located->GetLogicalVolume()->GetMaterial()==brightMaterial);
456
457 /*---------------------------------------------------------------------------
458 G4PhysicalTouchable *locPT= dynamic_cast<G4PhysicalTouchable*>(located);
459 if( locPT != 0 ){
460 G4VPhysicalVolume *parent= locPT->GetParentTouchable()->GetVolume();
461 G4cout << " ** Parent volume " << locPT << G4endl
462 << " Expected '" << "Slab Blocks in X" << "'" << G4endl
463 << " Obtained '" << parent->GetName() << "' copy no " << parent->GetCopyNo()
464 << G4endl;
465 assert(parent->GetCopyNo() == 6 );
466
467 G4VPhysicalVolume *parent2= locPT->GetParentTouchable()->GetVolume(1);
468 if( parent2 != 0){
469 G4cout << " **** Parent 2 volume " << locPT << G4endl
470 << " Expected " << "Top 2-pv" << G4endl
471 << " Obtained " << parent2->GetName() << " copy no " << parent2->GetCopyNo()
472 << G4endl;
473 assert(parent2->GetName()=="Top 2-pv");
474 }
475 }
476 *****************************************************************************/
477
478 return true;
479}
480
481
482//
483// Test Stepping
484//
485G4bool testG4Navigator2(G4VPhysicalVolume *pTopNode)
486{
487 MyNavigator myNav;
488 G4VPhysicalVolume *located;
489 G4double Step,physStep,safety;
490 G4ThreeVector xHat(1,0,0),yHat(0,1,0),zHat(0,0,1);
491 G4ThreeVector mxHat(-1,0,0),myHat(0,-1,0),mzHat(0,0,-1);
492
493 myNav.SetWorldVolume(pTopNode);
494
495//
496// Test location & Step computation
497//
498 G4ThreeVector startXm4( -400.*cm, 0., -10.*cm );
499 located=myNav.LocateGlobalPointAndSetup( startXm4 );
500 assert(located->GetName()=="World");
501 physStep=kInfinity;
502 Step=myNav.ComputeStep( startXm4, xHat, physStep, safety);
503 assert(ApproxEqual(Step, 50.*cm));
504// assert(ApproxEqual(safety,5));
505 assert(safety>=0);
506
507 G4ThreeVector startXm1( -100.*cm, 0., -10.*cm );
508 located=myNav.LocateGlobalPointAndSetup(startXm1);
509 assert(located->GetName()=="World");
510 physStep=kInfinity;
511 Step=myNav.ComputeStep( startXm1, mxHat, physStep, safety);
512 assert(ApproxEqual(Step,50.*cm));
513 assert(ApproxEqual(safety,50.*cm));
514 // assert(safety>=0);
515
516 G4ThreeVector newPoint = startXm1 + Step * mxHat;
517 myNav.SetGeometricallyLimitedStep();
518 located=myNav.LocateGlobalPointAndSetup(newPoint,0,true);
519 assert(located->GetName()=="Level 2 blocks in y");
520
521 return true;
522
523 // The following tests depend on physical touchables -- obsolete
524 //
525 /**********************************************************************
526 G4PhysicalTouchable *locPT= dynamic_cast<G4PhysicalTouchable*>(located);
527 G4VPhysicalVolume *parent= locPT->GetParentTouchable()->GetVolume();
528
529 G4VPhysicalVolume *parent2= locPT->GetParentTouchable()->GetVolume(1);
530 G4cout << " Parent 2 volume " << locPT << G4endl
531 << " Expected " << "Top 1-pv" << G4endl
532 << " Obtained " << parent2->GetName() << " copy no " << parent->GetCopyNo()
533 << G4endl;
534
535 assert(parent2->GetName()=="Top 1-pv");
536 ***********************************************************************/
537
538 G4cerr << " Testing in TestNavigator2() is ending line " << __LINE__
539 << " for the time being. " << G4endl;
540 return true;
541// ------------------------------------------------------------------
542 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-10));
543 assert(located->GetName()=="World");
544 physStep=kInfinity;
545 Step=myNav.ComputeStep(G4ThreeVector(0,0,-10),zHat,physStep,safety);
546 assert(ApproxEqual(Step,30));
547// assert(ApproxEqual(safety,5));
548 assert(safety>=0);
549
550 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-10));
551 assert(located->GetName()=="World");
552 physStep=kInfinity;
553 Step=myNav.ComputeStep(G4ThreeVector(0,0,-10),mzHat,physStep,safety);
554 assert(ApproxEqual(Step,10));
555// assert(ApproxEqual(safety,5));
556 assert(safety>=0);
557
558
559//
560// Test stepping through common boundaries
561//
562 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-7,7,-20));
563 assert(located->GetName()=="Target 1");
564 physStep=kInfinity;
565 Step=myNav.ComputeStep(G4ThreeVector(-7,7,-20),zHat,physStep,safety);
566 assert(ApproxEqual(Step,20));
567 assert(ApproxEqual(safety,0));
568 myNav.SetGeometricallyLimitedStep();
569 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-7,7,0));
570 assert(located->GetName()=="Target 4");
571 Step=myNav.ComputeStep(G4ThreeVector(-7,7,0),zHat,physStep,safety);
572 assert(ApproxEqual(Step,20));
573 assert(ApproxEqual(safety,0));
574 myNav.SetGeometricallyLimitedStep();
575 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-7,7,20));
576 assert(!located);
577
578//
579// Test mother limited Step
580//
581 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-25,0,10));
582 assert(located->GetName()=="World");
583 physStep=kInfinity;
584 Step=myNav.ComputeStep(G4ThreeVector(-25,0,10),xHat,physStep,safety);
585 assert(ApproxEqual(Step,50));
586 assert(ApproxEqual(safety,0));
587
588//
589// Test stepping through parameterised volumes
590//
591 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-25,-10),0,false);
592 assert(located->GetName()=="Target 3");
593 physStep=kInfinity;
594 Step=myNav.ComputeStep(G4ThreeVector(15,-25,-10),yHat,physStep,safety);
595 assert(ApproxEqual(Step,5));
596 assert(ApproxEqual(safety,0));
597 myNav.SetGeometricallyLimitedStep();
598 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-20,-10));
599 assert(located->GetName()=="Vari' Blocks");
600 Step=myNav.ComputeStep(G4ThreeVector(15,-20,-10),yHat,physStep,safety);
601 assert(ApproxEqual(Step,10));
602 assert(ApproxEqual(safety,0));
603 myNav.SetGeometricallyLimitedStep();
604 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-10,-10));
605 assert(located->GetName()=="Target 3");
606 Step=myNav.ComputeStep(G4ThreeVector(15,-10,-10),yHat,physStep,safety);
607 assert(ApproxEqual(Step,4));
608 assert(ApproxEqual(safety,0));
609 myNav.SetGeometricallyLimitedStep();
610 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-6,-10));
611 assert(located->GetName()=="Vari' Blocks");
612 Step=myNav.ComputeStep(G4ThreeVector(15,-6,-10),yHat,physStep,safety);
613 assert(ApproxEqual(Step,12));
614 assert(ApproxEqual(safety,0));
615 myNav.SetGeometricallyLimitedStep();
616 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,6,-10));
617 assert(located->GetName()=="Target 3");
618 Step=myNav.ComputeStep(G4ThreeVector(15,6,-10),yHat,physStep,safety);
619 assert(ApproxEqual(Step,2));
620 assert(ApproxEqual(safety,0));
621 myNav.SetGeometricallyLimitedStep();
622 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,8,-10));
623 assert(located->GetName()=="Vari' Blocks");
624 Step=myNav.ComputeStep(G4ThreeVector(15,8,-10),yHat,physStep,safety);
625 assert(ApproxEqual(Step,14));
626 assert(ApproxEqual(safety,0));
627 myNav.SetGeometricallyLimitedStep();
628 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,22,-10));
629 assert(located->GetName()=="Target 3");
630 Step=myNav.ComputeStep(G4ThreeVector(15,22,-10),yHat,physStep,safety);
631 assert(ApproxEqual(Step,3));
632 assert(ApproxEqual(safety,0));
633 myNav.SetGeometricallyLimitedStep();
634 located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,25,-10));
635 assert(!located);
636
637 return true;
638}
639
640int main()
641{
642 G4VPhysicalVolume *myTopNode;
643 myTopNode=BuildGeometry(); // Build the geometry
644 G4GeometryManager::GetInstance()->CloseGeometry(false);
645 testG4Navigator1(myTopNode);
646 testG4Navigator2(myTopNode);
647// Repeat tests but with full voxels
648 G4GeometryManager::GetInstance()->OpenGeometry();
649 G4GeometryManager::GetInstance()->CloseGeometry(true);
650 testG4Navigator1(myTopNode);
651 testG4Navigator2(myTopNode);
652
653 G4GeometryManager::GetInstance()->OpenGeometry();
654 // Must end with geometry open
655
656 return 0;
657}
Note: See TracBrowser for help on using the repository browser.