source: trunk/source/geometry/volumes/test/testG4Touchables.cc

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

geant4 tag 9.4

File size: 9.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: testG4Touchables.cc,v 1.10 2006/06/29 18:58:56 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30//
31// Test file for G4TouchableHistory/G4GRSVolume/G4GRSSolid
32// Paul Kent August 1996
33
34#include "ApproxEqual.hh"
35#include "G4ThreeVector.hh"
36
37#include "G4GRSVolume.hh"
38#include "G4GRSSolid.hh"
39#include "G4TouchableHistory.hh"
40
41#include "G4GeometryManager.hh"
42
43#include "G4PVPlacement.hh"
44#include "G4PVParameterised.hh"
45#include "G4PVReplica.hh"
46#include "G4LogicalVolume.hh"
47#include "G4Box.hh"
48
49// Sample Parameterisation
50class G4LinScale : public G4VPVParameterisation
51{
52 virtual void ComputeTransformation(const G4int n,
53 G4VPhysicalVolume *pRep) const
54 {
55 pRep->SetTranslation(G4ThreeVector(n*4-2,n*4-2,n*4-2));
56 }
57
58 virtual void ComputeDimensions(G4Box &pBox,
59 const G4int n,
60 const G4VPhysicalVolume *) const
61 {
62 pBox.SetXHalfLength(n+1);
63 pBox.SetYHalfLength(n+1);
64 pBox.SetZHalfLength(n+1);
65 }
66
67 virtual void ComputeDimensions(G4Tubs &,
68 const G4int ,
69 const G4VPhysicalVolume*) const {}
70 virtual void ComputeDimensions(G4Trd &,
71 const G4int,
72 const G4VPhysicalVolume*) const {}
73 virtual void ComputeDimensions(G4Cons &,
74 const G4int ,
75 const G4VPhysicalVolume*) const {}
76 virtual void ComputeDimensions(G4Trap &,
77 const G4int ,
78 const G4VPhysicalVolume*) const {}
79 virtual void ComputeDimensions(G4Hype &,
80 const G4int ,
81 const G4VPhysicalVolume*) const {}
82 virtual void ComputeDimensions(G4Orb &,
83 const G4int ,
84 const G4VPhysicalVolume*) const {}
85 virtual void ComputeDimensions(G4Sphere &,
86 const G4int ,
87 const G4VPhysicalVolume*) const {}
88 virtual void ComputeDimensions(G4Torus &,
89 const G4int ,
90 const G4VPhysicalVolume*) const {}
91 virtual void ComputeDimensions(G4Para &,
92 const G4int ,
93 const G4VPhysicalVolume*) const {}
94 virtual void ComputeDimensions(G4Polycone &,
95 const G4int ,
96 const G4VPhysicalVolume*) const {}
97 virtual void ComputeDimensions(G4Polyhedra &,
98 const G4int ,
99 const G4VPhysicalVolume*) const {}
100};
101
102G4LinScale myParam;
103
104G4VPhysicalVolume* BuildGeometry()
105{
106 G4Box *worldBox=new G4Box("WorldBox",1000,1000,1000);
107 G4Box *posBox=new G4Box("PosBox",10,10,10);
108 G4Box *posBoxSlice=new G4Box("PosBoxSlice",10,10,2);
109 G4Box *paramBox=new G4Box("ParamBox",1,1,1);
110
111 G4LogicalVolume *worldLog=new G4LogicalVolume(worldBox,0,
112 "WorldLog",0,0,0);
113 G4LogicalVolume *posLog=new G4LogicalVolume(posBox,0,
114 "PosLog",0,0,0);
115 G4LogicalVolume *pos2Log=new G4LogicalVolume(posBox,0,
116 "Pos2Log",0,0,0);
117 G4LogicalVolume *pos3Log=new G4LogicalVolume(posBox,0,
118 "Pos3Log",0,0,0);
119 G4LogicalVolume *pos4Log=new G4LogicalVolume(posBox,0,
120 "Pos4Log",0,0,0);
121 G4LogicalVolume *posSliceLog=new G4LogicalVolume(posBoxSlice,0,
122 "PosSliceLog",0,0,0);
123 G4LogicalVolume *paramLog=new G4LogicalVolume(paramBox,0,
124 "ParamLog",0,0,0);
125
126 G4PVPlacement *worldPhys=new G4PVPlacement(0,G4ThreeVector(0,0,0),
127 "WorldPhys",worldLog,0,false,0);
128 G4PVPlacement *posPhys1=new G4PVPlacement(0,G4ThreeVector(10,11,12),
129 "PosPhys1",posLog,worldPhys,
130 false,0);
131// G4PVPlacement *posPhys2=
132 new G4PVPlacement(0,G4ThreeVector(0,0,0),
133 "PosPhys2",pos2Log,posPhys1,
134 false,0);
135 G4PVPlacement *posPhys3=new G4PVPlacement(0,G4ThreeVector(-10,-11,-12),
136 "PosPhys3",pos3Log,worldPhys,
137 false,0);
138 G4PVPlacement *posPhys4=new G4PVPlacement(0,G4ThreeVector(10,0,0),
139 "PosPhys4",pos4Log,worldPhys,
140 false,0);
141// G4PVReplica *repPhys=
142 new G4PVReplica("RepPhys",posSliceLog,posPhys3,
143 kZAxis,5,4);
144
145// G4PVParameterised *paramPhys=
146 new G4PVParameterised("ParamPhys",
147 paramLog,
148 posPhys4,
149 kXAxis,2,&myParam);
150 return worldPhys;
151}
152
153
154G4bool testGRSVolume(MyNavigator& nav)
155{
156 G4ThreeVector pos;
157
158 pos=G4ThreeVector(11,12,13);
159 nav.LocateGlobalPointAndSetup(pos);
160 G4GRSVolume *touch=nav.CreateGRSVolume();
161 assert(touch);
162 assert(touch->GetVolume()->GetName()=="PosPhys2");
163 assert(touch->GetSolid()->GetName()=="PosBox");
164 assert(ApproxEqual(touch->GetTranslation(),G4ThreeVector(10,11,12)));
165 assert(!touch->GetRotation()||touch->GetRotation()->isIdentity());
166 delete touch;
167 return true;
168}
169
170G4bool testGRSSolid(MyNavigator& nav)
171{
172 G4ThreeVector pos;
173
174 pos=G4ThreeVector(11,12,13);
175 nav.LocateGlobalPointAndSetup(pos);
176 G4GRSSolid *touch=nav.CreateGRSSolid();
177 assert(touch);
178 assert(touch->GetSolid()->GetName()=="PosBox");
179 assert(ApproxEqual(touch->GetTranslation(),G4ThreeVector(10,11,12)));
180 assert(!touch->GetRotation()||touch->GetRotation()->isIdentity());
181 delete touch;
182 return true;
183}
184
185G4bool testTouchableHistory(MyNavigator& nav)
186{
187 G4ThreeVector pos(11,12,13),pos2(9,-1,-1);
188 G4VPhysicalVolume *pvol;
189
190 pvol=nav.LocateGlobalPointAndSetup(pos);
191 assert(pvol->GetName()=="PosPhys2");
192 assert(pvol->GetMotherLogical()->GetName()=="PosLog");
193
194 G4TouchableHistoryHandle touch=nav.CreateTouchableHistory();
195 assert(touch);
196 assert(touch->GetVolume()->GetName()=="PosPhys2");
197 assert(touch->GetSolid()->GetName()=="PosBox");
198 assert(ApproxEqual(touch->GetTranslation(),G4ThreeVector(10,11,12)));
199 assert(!touch->GetRotation()||touch->GetRotation()->isIdentity());
200 assert(touch->GetHistory()->GetDepth()==2);
201
202 pvol=nav.LocateGlobalPointAndSetup(-pos);
203 assert(pvol->GetName()=="RepPhys");
204 assert(pvol->GetMotherLogical()->GetName()=="Pos3Log");
205 assert(ApproxEqual(nav.CurrentLocalCoordinate(),G4ThreeVector(-1,-1,-1)));
206
207 G4TouchableHistoryHandle touch2=nav.CreateTouchableHistory();
208 assert(touch2);
209 assert(touch2->GetVolume()->GetName()=="RepPhys");
210 assert(touch2->GetSolid()->GetName()=="PosBoxSlice");
211 assert(ApproxEqual(touch2->GetTranslation(),G4ThreeVector(-10,-11,-12)));
212 assert(!touch2->GetRotation()||touch2->GetRotation()->isIdentity());
213 assert(touch2->GetHistory()->GetDepth()==2);
214
215 pvol=nav.LocateGlobalPointAndSetup(pos2);
216 assert(pvol->GetName()=="ParamPhys");
217 assert(pvol->GetMotherLogical()->GetName()=="Pos4Log");
218 assert(ApproxEqual(nav.CurrentLocalCoordinate(),G4ThreeVector(1,1,1)));
219
220 G4TouchableHistoryHandle touch3=nav.CreateTouchableHistory();
221 // Relocate to another parameterised volume causing modification of
222 // physical volume + solid
223 pvol=nav.LocateGlobalPointAndSetup(pos2+G4ThreeVector(2,2,2));
224 assert(touch3);
225 assert(touch3->GetVolume()->GetName()=="ParamPhys");
226 assert(touch3->GetSolid()->GetName()=="ParamBox");
227 assert(ApproxEqual(touch3->GetTranslation(),G4ThreeVector(8,-2,-2)));
228 assert(!touch3->GetRotation()||touch3->GetRotation()->isIdentity());
229 assert(touch3->GetHistory()->GetDepth()==2);
230
231 G4ThreeVector dir(0.0, 1., 0.);
232
233 pvol=nav.ResetHierarchyAndLocate(pos, dir, *((G4TouchableHistory*)touch()));
234 assert(ApproxEqual(nav.CurrentLocalCoordinate(),G4ThreeVector(1,1,1)));
235 assert(pvol->GetName()=="PosPhys2");
236 assert(pvol->GetMotherLogical()->GetName()=="PosLog");
237 assert(ApproxEqual(nav.GetNetTranslation(),G4ThreeVector(10,11,12)));
238
239 pvol=nav.ResetHierarchyAndLocate(-pos, dir, *((G4TouchableHistory*)touch2()));
240 assert(ApproxEqual(nav.CurrentLocalCoordinate(),G4ThreeVector(-1,-1,-1)));
241 assert(pvol->GetName()=="RepPhys");
242 assert(pvol->GetMotherLogical()->GetName()=="Pos3Log");
243 assert(ApproxEqual(nav.GetNetTranslation(),G4ThreeVector(-10,-11,-12)));
244
245 pvol=nav.ResetHierarchyAndLocate(pos2, dir, *((G4TouchableHistory*)touch3()));
246 assert(pvol->GetName()=="ParamPhys");
247 assert(pvol->GetMotherLogical()->GetName()=="Pos4Log");
248 assert(ApproxEqual(nav.GetNetTranslation(),G4ThreeVector(8,-2,-2)));
249
250 //delete touch;
251 //delete touch2;
252 //delete touch3;
253 return true;
254}
255
256int main()
257{
258 G4VPhysicalVolume *myTopNode=BuildGeometry();
259 G4GeometryManager::GetInstance()->CloseGeometry(false);
260 MyNavigator nav;
261 nav.SetWorldVolume(myTopNode);
262
263 assert(testGRSVolume(nav));
264 assert(testGRSSolid(nav));
265 assert(testTouchableHistory(nav));
266
267 G4GeometryManager::GetInstance()->OpenGeometry();
268 return EXIT_SUCCESS;
269}
Note: See TracBrowser for help on using the repository browser.