source: trunk/source/geometry/navigation/test/testG4Navigator5.cc @ 1347

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

geant4 tag 9.4

File size: 17.6 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: testG4Navigator5.cc,v 1.6 2006/06/29 18:37:26 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30//
31// Locate & Step within replicated geometry (without full voxels)
32// consisting of tubes (replicated in r,phi...)     P.Kent August 96
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 "G4PVReplica.hh"
46#include "G4Box.hh"
47#include "G4Tubs.hh"
48
49#include "G4GeometryManager.hh"
50
51#include "G4RotationMatrix.hh"
52#include "G4ThreeVector.hh"
53
54G4VPhysicalVolume* BuildGeometry()
55{
56
57    G4Box *worldBox= new G4Box ("cube",50,50,50);
58    G4Tubs *fullTube= new G4Tubs("tube",0,10,10,0,2*pi);
59    G4Tubs *fullTubeSlice= new G4Tubs("tube slice",0,2,10,0,2*pi);
60
61    G4Tubs *hollowTube= new G4Tubs("hollow tube",2,8,10,0,2*pi);
62    G4Tubs *hollowTubeSlice= new G4Tubs("hollow tube slice",2,4,10,0,2*pi);
63
64    G4Tubs *hphiTube= new G4Tubs("phi tube",2,8,10,-pi*0.5,pi);
65    G4Tubs *hphiTubeSlice= new G4Tubs("phi tube slice",2,8,10,0,pi*0.25);
66
67
68    G4Tubs *allTube= new G4Tubs("all tube",2,10,10,0,2*pi);
69    G4Tubs *allTubeZSlice= new G4Tubs("all tube z slice",2,10,2,0,2*pi);
70    G4Tubs *allTubeZRSlice=new G4Tubs("all tube zr slice",2,6,2,0,2*pi);
71    G4Tubs *allTubeZRPSlice=new G4Tubs("all tube zrp slice",2,6,
72                                       2,-pi*0.25,pi*0.5);
73
74
75    G4LogicalVolume *worldLog=new G4LogicalVolume(worldBox,0,
76                                                  "World",0,0,0);
77    // Logical with no field,sensitive detector or user limits
78   
79    G4PVPlacement *worldPhys=new G4PVPlacement(0,G4ThreeVector(0,0,0),
80                                               "World",worldLog,
81                                               0,false,0);
82    // Note: no mother pointer set
83   
84
85    // Full (solid) Tube containing r replicas
86    G4LogicalVolume *fullTubeLog=new G4LogicalVolume(fullTube,
87                                                     0,
88                                                     "Container",
89                                                     0,0,0);
90    G4PVPlacement *fullTubePhys=new G4PVPlacement(0,G4ThreeVector(0,0,35),
91                                                  "Container",
92                                                  fullTubeLog,
93                                                  worldPhys,false,0);
94    G4LogicalVolume *fullTubeSliceLog=new G4LogicalVolume(fullTubeSlice,
95                                                          0,
96                                                          "Slice",
97                                                          0,0,0);
98//  G4PVReplica *fullTubeSlicePhys=
99                          new G4PVReplica("TubeSlice",
100                                          fullTubeSliceLog,fullTubePhys,
101                                          kRho,5,2,0);
102
103
104    // hollow Tube containing r replicas
105    G4LogicalVolume *hollowTubeLog=new G4LogicalVolume(hollowTube,
106                                                       0,
107                                                       "Container",
108                                                       0,0,0);
109    G4PVPlacement *hollowTubePhys=new G4PVPlacement(0,G4ThreeVector(0,0,-35),
110                                                    "Container",
111                                                    hollowTubeLog,
112                                                    worldPhys,false,0);
113
114    G4LogicalVolume *hollowTubeSliceLog=new G4LogicalVolume(hollowTubeSlice,
115                                                            0,
116                                                            "Slice",
117                                                            0,0,0);
118//  G4PVReplica *hollowTubeSlicePhys=
119                          new G4PVReplica("HollowTubeSlice",
120                                          hollowTubeSliceLog,hollowTubePhys,
121                                          kRho,3,2,2);
122
123
124    // Hollow Tube containing phi replicas
125    G4LogicalVolume *hphiTubeLog=new G4LogicalVolume(hphiTube,
126                                                     0,
127                                                     "Container",
128                                                     0,0,0);
129    G4PVPlacement *hphiTubePhys=new G4PVPlacement(0,G4ThreeVector(35,0,0),
130                                                  "Container",
131                                                  hphiTubeLog,
132                                                  worldPhys,false,0);
133
134    G4LogicalVolume *hphiTubeSliceLog=new G4LogicalVolume(hphiTubeSlice,
135                                                          0,
136                                                          "Slice",
137                                                          0,0,0);
138//  G4PVReplica *hphiTubeSlicePhys=
139                          new G4PVReplica("hphiTubeSlice",
140                                          hphiTubeSliceLog,hphiTubePhys,
141                                          kPhi,4,pi*0.25,-pi*0.5);
142
143    // Tube replicated along z, then r then phi (!)
144
145    G4LogicalVolume *allTubeLog=new G4LogicalVolume(allTube,
146                                                    0,
147                                                    "Container",
148                                                    0,0,0);
149    G4PVPlacement *allTubePhys=new G4PVPlacement(0,G4ThreeVector(0,35,0),
150                                                 "Container",
151                                                 allTubeLog,
152                                                 worldPhys,false,0);
153
154    G4LogicalVolume *allTubeZSliceLog=new G4LogicalVolume(allTubeZSlice,
155                                                          0,
156                                                          "Slice",
157                                                          0,0,0);
158    G4PVReplica *allTubeZSlicePhys=new G4PVReplica("allTubeZSlice",
159                                                   allTubeZSliceLog,
160                                                   allTubePhys,
161                                                   kZAxis,5,4);
162
163    G4LogicalVolume *allTubeZRSliceLog=new G4LogicalVolume(allTubeZRSlice,
164                                                           0,
165                                                           "Slice",
166                                                           0,0,0);
167    G4PVReplica *allTubeZRSlicePhys=new G4PVReplica("allTubeZRSlice",
168                                                    allTubeZRSliceLog,
169                                                    allTubeZSlicePhys,
170                                                    kRho,2,4,2);
171
172    G4LogicalVolume *allTubeZRPSliceLog=new G4LogicalVolume(allTubeZRPSlice,
173                                                            0,
174                                                            "Slice",
175                                                            0,0,0);
176//  G4PVReplica *allTubeZRPSlicePhys=
177                                     new G4PVReplica("allTubeZRPSlice",
178                                                     allTubeZRPSliceLog,
179                                                     allTubeZRSlicePhys,
180                                                     kPhi,4,pi*0.5,-pi*0.25);
181
182
183    return worldPhys;
184}
185
186
187//
188// Test LocateGlobalPointAndSetup
189//
190G4bool testG4NavigatorLocate(G4VPhysicalVolume *pTopNode)
191{
192    MyNavigator myNav;
193    G4VPhysicalVolume *located;
194    myNav.SetWorldVolume(pTopNode);
195
196    assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0),0,false));
197    located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(50,50,50),0,false);
198    assert(located->GetName()=="World");
199    located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,35),0,false);
200    assert(located->GetName()=="TubeSlice");
201    assert(ApproxEqual(myNav.CurrentLocalCoordinate(),
202                       G4ThreeVector(0,0,0)));
203    located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-35),0,false);
204    assert(located->GetName()=="World");
205    located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(4,0,-35),0,false);
206    assert(located->GetName()=="HollowTubeSlice");
207    assert(ApproxEqual(myNav.CurrentLocalCoordinate(),
208                       G4ThreeVector(4,0,0)));
209    located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(37,0.5,0),0,false);
210    assert(located->GetName()=="hphiTubeSlice");
211
212    located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(3,35,0),0,false);
213    assert(located->GetName()=="allTubeZRPSlice");
214    assert(ApproxEqual(myNav.CurrentLocalCoordinate(),
215                       G4ThreeVector(3,0,0)));
216   
217    return true;
218}
219
220//
221// Test ComputeStep
222//
223G4bool testG4NavigatorSteps(G4VPhysicalVolume *pTopNode)
224{
225    MyNavigator myNav;
226    G4VPhysicalVolume *located;
227    G4double Step,physStep,safety;
228    G4ThreeVector pos,dir,origin,xHat(1,0,0),yHat(0,1,0),zHat(0,0,1);
229    G4ThreeVector mxHat(-1,0,0),myHat(0,-1,0),mzHat(0,0,-1);
230    myNav.SetWorldVolume(pTopNode);
231
232    pos=G4ThreeVector(0,0,49);
233    dir=mzHat;
234    physStep=kInfinity;
235    located=myNav.LocateGlobalPointAndSetup(pos);
236    assert(located->GetName()=="World");
237    Step=myNav.ComputeStep(pos,dir,physStep,safety);
238    assert(ApproxEqual(Step,4));
239    assert(ApproxEqual(safety,1));
240    pos+=Step*dir;
241    myNav.SetGeometricallyLimitedStep();
242    located=myNav.LocateGlobalPointAndSetup(pos);
243    assert(located->GetName()=="TubeSlice");
244    Step=myNav.ComputeStep(pos,dir,physStep,safety);
245    assert(ApproxEqual(Step,20));
246    assert(safety==0);
247    Step=10;
248    pos+=Step*dir;
249    located=myNav.LocateGlobalPointAndSetup(pos);
250    assert(located->GetName()=="TubeSlice");
251    Step=myNav.ComputeStep(pos,dir,physStep,safety);
252    assert(ApproxEqual(Step,10));
253    assert(ApproxEqual(safety,2));
254
255    pos=G4ThreeVector(-10,-10,35);
256    dir=(xHat+yHat).unit();
257    physStep=kInfinity;
258    located=myNav.LocateGlobalPointAndSetup(pos);
259    assert(located->GetName()=="World");
260    Step=myNav.ComputeStep(pos,dir,physStep,safety);
261    assert(ApproxEqual(Step,std::sqrt(200.)-10.));
262    assert(ApproxEqual(safety,std::sqrt(200.)-10.));
263    pos+=Step*dir;
264    myNav.SetGeometricallyLimitedStep();
265    located=myNav.LocateGlobalPointAndSetup(pos);
266    assert(located->GetName()=="TubeSlice");
267    Step=myNav.ComputeStep(pos,dir,physStep,safety);
268    assert(ApproxEqual(Step,2));
269    assert(ApproxEqual(safety,0));
270    pos+=Step*dir;
271    myNav.SetGeometricallyLimitedStep();
272    located=myNav.LocateGlobalPointAndSetup(pos);
273    assert(located->GetName()=="TubeSlice");
274    Step=myNav.ComputeStep(pos,dir,physStep,safety);
275    assert(ApproxEqual(Step,2));
276    assert(ApproxEqual(safety,0));
277    pos+=Step*dir;
278    myNav.SetGeometricallyLimitedStep();
279    located=myNav.LocateGlobalPointAndSetup(pos);
280    assert(located->GetName()=="TubeSlice");
281    Step=myNav.ComputeStep(pos,dir,physStep,safety);
282    assert(ApproxEqual(Step,2));
283    assert(ApproxEqual(safety,0));
284    pos+=Step*dir;
285    myNav.SetGeometricallyLimitedStep();
286    located=myNav.LocateGlobalPointAndSetup(pos);
287    assert(located->GetName()=="TubeSlice");
288    Step=myNav.ComputeStep(pos,dir,physStep,safety);
289    assert(ApproxEqual(Step,2));
290    assert(ApproxEqual(safety,0));
291    pos+=Step*dir;
292    myNav.SetGeometricallyLimitedStep();
293    located=myNav.LocateGlobalPointAndSetup(pos);
294    assert(located->GetName()=="TubeSlice");
295    Step=myNav.ComputeStep(pos,dir,physStep,safety);
296    assert(ApproxEqual(Step,4));
297    assert(ApproxEqual(safety,0));
298    pos+=Step*dir;
299    myNav.SetGeometricallyLimitedStep();
300    located=myNav.LocateGlobalPointAndSetup(pos);
301    assert(located->GetName()=="TubeSlice");
302    Step=myNav.ComputeStep(pos,dir,physStep,safety);
303    assert(ApproxEqual(Step,2));
304    assert(ApproxEqual(safety,0));
305    pos+=Step*dir;
306    myNav.SetGeometricallyLimitedStep();
307    located=myNav.LocateGlobalPointAndSetup(pos);
308    assert(located->GetName()=="TubeSlice");
309    Step=myNav.ComputeStep(pos,dir,physStep,safety);
310    assert(ApproxEqual(Step,2));
311    assert(ApproxEqual(safety,0));
312    pos+=Step*dir;
313    myNav.SetGeometricallyLimitedStep();
314    located=myNav.LocateGlobalPointAndSetup(pos);
315    assert(located->GetName()=="TubeSlice");
316    Step=myNav.ComputeStep(pos,dir,physStep,safety);
317    assert(ApproxEqual(Step,2));
318    assert(ApproxEqual(safety,0));
319    pos+=Step*dir;
320    myNav.SetGeometricallyLimitedStep();
321    located=myNav.LocateGlobalPointAndSetup(pos);
322    assert(located->GetName()=="TubeSlice");
323    Step=myNav.ComputeStep(pos,dir,physStep,safety);
324    assert(ApproxEqual(Step,2));
325    assert(ApproxEqual(safety,0));
326    pos+=Step*dir;
327    myNav.SetGeometricallyLimitedStep();
328    located=myNav.LocateGlobalPointAndSetup(pos);
329    assert(located->GetName()=="World");
330 
331
332
333    pos=G4ThreeVector(10,10,-35);
334    dir=(mxHat+myHat).unit();
335    physStep=kInfinity;
336    located=myNav.LocateGlobalPointAndSetup(pos);
337    assert(located->GetName()=="World");
338    Step=myNav.ComputeStep(pos,dir,physStep,safety);
339    assert(ApproxEqual(Step,std::sqrt(200.)-8.));
340    assert(ApproxEqual(safety,std::sqrt(200.)-8.));
341    pos+=Step*dir;
342    myNav.SetGeometricallyLimitedStep();
343    located=myNav.LocateGlobalPointAndSetup(pos);
344    assert(located->GetName()=="HollowTubeSlice");
345    Step=myNav.ComputeStep(pos,dir,physStep,safety);
346    assert(ApproxEqual(Step,2));
347    assert(ApproxEqual(safety,0));
348    pos+=Step*dir;
349    myNav.SetGeometricallyLimitedStep();
350    located=myNav.LocateGlobalPointAndSetup(pos);
351    assert(located->GetName()=="HollowTubeSlice");
352    Step=myNav.ComputeStep(pos,dir,physStep,safety);
353    assert(ApproxEqual(Step,2));
354    assert(ApproxEqual(safety,0));
355    pos+=Step*dir;
356    myNav.SetGeometricallyLimitedStep();
357    located=myNav.LocateGlobalPointAndSetup(pos);
358    assert(located->GetName()=="HollowTubeSlice");
359    Step=myNav.ComputeStep(pos,dir,physStep,safety);
360    assert(ApproxEqual(Step,2));
361    assert(ApproxEqual(safety,0));
362    pos+=Step*dir;
363    myNav.SetGeometricallyLimitedStep();
364    located=myNav.LocateGlobalPointAndSetup(pos);
365    assert(located->GetName()=="World");
366    Step=myNav.ComputeStep(pos,dir,physStep,safety);
367    assert(ApproxEqual(Step,4));
368    assert(ApproxEqual(safety,0));
369    pos+=Step*dir;
370    myNav.SetGeometricallyLimitedStep();
371    located=myNav.LocateGlobalPointAndSetup(pos);
372    assert(located->GetName()=="HollowTubeSlice");
373    Step=myNav.ComputeStep(pos,dir,physStep,safety);
374    assert(ApproxEqual(Step,2));
375    assert(ApproxEqual(safety,0));
376    pos+=Step*dir;
377    myNav.SetGeometricallyLimitedStep();
378    located=myNav.LocateGlobalPointAndSetup(pos);
379    assert(located->GetName()=="HollowTubeSlice");
380    Step=myNav.ComputeStep(pos,dir,physStep,safety);
381    assert(ApproxEqual(Step,2));
382    assert(ApproxEqual(safety,0));
383    pos+=Step*dir;
384    myNav.SetGeometricallyLimitedStep();
385    located=myNav.LocateGlobalPointAndSetup(pos);
386    assert(located->GetName()=="HollowTubeSlice");
387    Step=myNav.ComputeStep(pos,dir,physStep,safety);
388    assert(ApproxEqual(Step,2));
389    assert(ApproxEqual(safety,0));
390    pos+=Step*dir;
391    myNav.SetGeometricallyLimitedStep();
392    located=myNav.LocateGlobalPointAndSetup(pos);
393    assert(located->GetName()=="World");
394 
395
396
397    pos=G4ThreeVector(39,-10,0);
398    dir=yHat;
399    physStep=kInfinity;
400    located=myNav.LocateGlobalPointAndSetup(pos);
401    assert(located->GetName()=="World");
402    Step=myNav.ComputeStep(pos,dir,physStep,safety);
403    assert(ApproxEqual(Step,10.-std::sqrt(48.)));
404    assert(ApproxEqual(safety,std::sqrt(116.)-8.));
405    pos+=Step*dir;
406    myNav.SetGeometricallyLimitedStep();
407    located=myNav.LocateGlobalPointAndSetup(pos);
408    assert(located->GetName()=="hphiTubeSlice");
409    Step=myNav.ComputeStep(pos,dir,physStep,safety);
410    assert(ApproxEqual(Step,std::sqrt(48.)-4.));
411    assert(ApproxEqual(safety,0));
412    pos+=Step*dir;
413    myNav.SetGeometricallyLimitedStep();
414    located=myNav.LocateGlobalPointAndSetup(pos);
415    assert(located->GetName()=="hphiTubeSlice");
416    Step=myNav.ComputeStep(pos,dir,physStep,safety);
417    assert(ApproxEqual(Step,4));
418    assert(ApproxEqual(safety,0));
419    pos+=Step*dir;
420    myNav.SetGeometricallyLimitedStep();
421    located=myNav.LocateGlobalPointAndSetup(pos);
422    assert(located->GetName()=="hphiTubeSlice");
423    Step=myNav.ComputeStep(pos,dir,physStep,safety);
424    assert(ApproxEqual(Step,4));
425    assert(ApproxEqual(safety,0));
426    pos+=Step*dir;
427    myNav.SetGeometricallyLimitedStep();
428    located=myNav.LocateGlobalPointAndSetup(pos);
429    assert(located->GetName()=="hphiTubeSlice");
430    Step=myNav.ComputeStep(pos,dir,physStep,safety);
431    assert(ApproxEqual(Step,std::sqrt(48.)-4.));
432    assert(ApproxEqual(safety,0));
433    pos+=Step*dir;
434    myNav.SetGeometricallyLimitedStep();
435    located=myNav.LocateGlobalPointAndSetup(pos);
436    assert(located->GetName()=="World");
437
438
439    pos=G4ThreeVector(12,35,0);
440    dir=mxHat;
441    physStep=kInfinity;
442    located=myNav.LocateGlobalPointAndSetup(pos);
443    assert(located->GetName()=="World");
444    Step=myNav.ComputeStep(pos,dir,physStep,safety);
445    assert(ApproxEqual(Step,2));
446    assert(ApproxEqual(safety,2));
447    pos+=Step*dir;
448    myNav.SetGeometricallyLimitedStep();
449    located=myNav.LocateGlobalPointAndSetup(pos);
450    assert(located->GetName()=="allTubeZRPSlice");
451    Step=myNav.ComputeStep(pos,dir,physStep,safety);
452    assert(ApproxEqual(Step,4));
453    assert(ApproxEqual(safety,0));
454    pos+=Step*dir;
455    myNav.SetGeometricallyLimitedStep();
456    located=myNav.LocateGlobalPointAndSetup(pos);
457    assert(located->GetName()=="allTubeZRPSlice");
458    Step=myNav.ComputeStep(pos,dir,physStep,safety);
459    assert(ApproxEqual(Step,4));
460    assert(ApproxEqual(safety,0));
461    Step=2;
462    pos+=Step*dir;
463    located=myNav.LocateGlobalPointAndSetup(pos);
464    assert(located->GetName()=="allTubeZRPSlice");
465    dir=zHat;
466    Step=myNav.ComputeStep(pos,dir,physStep,safety);
467    assert(ApproxEqual(Step,2));
468    assert(ApproxEqual(safety,2));
469    pos+=Step*dir;
470    myNav.SetGeometricallyLimitedStep();
471    located=myNav.LocateGlobalPointAndSetup(pos);
472    assert(located->GetName()=="allTubeZRPSlice");
473    Step=myNav.ComputeStep(pos,dir,physStep,safety);
474    assert(ApproxEqual(Step,4));
475    assert(ApproxEqual(safety,0));
476    pos+=Step*dir;
477    myNav.SetGeometricallyLimitedStep();
478    located=myNav.LocateGlobalPointAndSetup(pos);
479    assert(located->GetName()=="allTubeZRPSlice");
480    Step=myNav.ComputeStep(pos,dir,physStep,safety);
481    assert(ApproxEqual(Step,4));
482    assert(ApproxEqual(safety,0));
483    pos+=Step*dir;
484    myNav.SetGeometricallyLimitedStep();
485    located=myNav.LocateGlobalPointAndSetup(pos);
486    assert(located->GetName()=="World");
487 
488    return true;
489}
490
491int main()
492{
493    G4VPhysicalVolume *myTopNode;
494    myTopNode=BuildGeometry();  // Build the geometry
495    G4GeometryManager::GetInstance()->CloseGeometry(false);
496    testG4NavigatorLocate(myTopNode);
497    testG4NavigatorSteps(myTopNode);
498
499    G4GeometryManager::GetInstance()->OpenGeometry();
500    return 0;
501}
Note: See TracBrowser for help on using the repository browser.