| 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: testG4Navigator1.cc,v 1.5 2006/06/29 18:37:17 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 "G4Box.hh"
|
|---|
| 48 |
|
|---|
| 49 | #include "G4GeometryManager.hh"
|
|---|
| 50 |
|
|---|
| 51 | #include "G4RotationMatrix.hh"
|
|---|
| 52 | #include "G4ThreeVector.hh"
|
|---|
| 53 |
|
|---|
| 54 | // Sample Paramterisation
|
|---|
| 55 | class G4LinScale : public G4VPVParameterisation
|
|---|
| 56 | {
|
|---|
| 57 | virtual void ComputeTransformation(const G4int n,
|
|---|
| 58 | G4VPhysicalVolume* pRep) const
|
|---|
| 59 | {
|
|---|
| 60 | pRep->SetTranslation(G4ThreeVector(0,(n-1)*15,0));
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | virtual void ComputeDimensions(G4Box &pBox,
|
|---|
| 64 | const G4int n,
|
|---|
| 65 | const G4VPhysicalVolume*) const
|
|---|
| 66 | {
|
|---|
| 67 | pBox.SetXHalfLength(10);
|
|---|
| 68 | pBox.SetYHalfLength(5+n);
|
|---|
| 69 | pBox.SetZHalfLength(5+n);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | virtual void ComputeDimensions(G4Tubs &,
|
|---|
| 73 | const G4int ,
|
|---|
| 74 | const G4VPhysicalVolume*) const {}
|
|---|
| 75 | virtual void ComputeDimensions(G4Trd &,
|
|---|
| 76 | const G4int,
|
|---|
| 77 | const G4VPhysicalVolume*) const {}
|
|---|
| 78 | virtual void ComputeDimensions(G4Cons &,
|
|---|
| 79 | const G4int ,
|
|---|
| 80 | const G4VPhysicalVolume*) const {}
|
|---|
| 81 | virtual void ComputeDimensions(G4Trap &,
|
|---|
| 82 | const G4int ,
|
|---|
| 83 | const G4VPhysicalVolume*) const {}
|
|---|
| 84 | virtual void ComputeDimensions(G4Hype &,
|
|---|
| 85 | const G4int ,
|
|---|
| 86 | const G4VPhysicalVolume*) const {}
|
|---|
| 87 | virtual void ComputeDimensions(G4Orb &,
|
|---|
| 88 | const G4int ,
|
|---|
| 89 | const G4VPhysicalVolume*) const {}
|
|---|
| 90 | virtual void ComputeDimensions(G4Sphere &,
|
|---|
| 91 | const G4int ,
|
|---|
| 92 | const G4VPhysicalVolume*) const {}
|
|---|
| 93 | virtual void ComputeDimensions(G4Torus &,
|
|---|
| 94 | const G4int ,
|
|---|
| 95 | const G4VPhysicalVolume*) const {}
|
|---|
| 96 | virtual void ComputeDimensions(G4Para &,
|
|---|
| 97 | const G4int ,
|
|---|
| 98 | const G4VPhysicalVolume*) const {}
|
|---|
| 99 | virtual void ComputeDimensions(G4Polycone &,
|
|---|
| 100 | const G4int ,
|
|---|
| 101 | const G4VPhysicalVolume*) const {}
|
|---|
| 102 | virtual void ComputeDimensions(G4Polyhedra &,
|
|---|
| 103 | const G4int ,
|
|---|
| 104 | const G4VPhysicalVolume*) const {}
|
|---|
| 105 | };
|
|---|
| 106 | G4LinScale myParam;
|
|---|
| 107 |
|
|---|
| 108 | // Build simple geometry:
|
|---|
| 109 | // 4 small cubes + 1 slab (all G4Boxes) are positioned inside a larger cuboid
|
|---|
| 110 | G4VPhysicalVolume* BuildGeometry()
|
|---|
| 111 | {
|
|---|
| 112 |
|
|---|
| 113 | G4Box *myBigBox= new G4Box ("cuboid",25,25,20);
|
|---|
| 114 | G4Box *myBox=new G4Box("cube",10,10,10);
|
|---|
| 115 | G4Box *mySlab= new G4Box("slab",10,25,10);
|
|---|
| 116 |
|
|---|
| 117 | G4Box *myVariableBox=new G4Box("Variable Box",10,5,5);
|
|---|
| 118 |
|
|---|
| 119 | G4LogicalVolume *worldLog=new G4LogicalVolume(myBigBox,0,
|
|---|
| 120 | "World",0,0,0);
|
|---|
| 121 | // Logical with no material,field,
|
|---|
| 122 | // sensitive detector or user limits
|
|---|
| 123 |
|
|---|
| 124 | G4PVPlacement *worldPhys=new G4PVPlacement(0,G4ThreeVector(0,0,0),
|
|---|
| 125 | "World",worldLog,
|
|---|
| 126 | 0,false,0);
|
|---|
| 127 | // Note: no mother pointer set
|
|---|
| 128 |
|
|---|
| 129 | G4LogicalVolume *boxLog=new G4LogicalVolume(myBox,0,
|
|---|
| 130 | "Crystal Box",0,0,0);
|
|---|
| 131 | G4LogicalVolume *slabLog=new G4LogicalVolume(mySlab,0,
|
|---|
| 132 | "Crystal Slab",0,0,0);
|
|---|
| 133 | // G4PVPlacement *offMXYPhys=
|
|---|
| 134 | new G4PVPlacement(0,G4ThreeVector(-15,15,-10),
|
|---|
| 135 | "Target 1",boxLog,
|
|---|
| 136 | worldPhys,false,0);
|
|---|
| 137 | // G4PVPlacement *offMXMYPhys=
|
|---|
| 138 | new G4PVPlacement(0,G4ThreeVector(-15,-15,-10),
|
|---|
| 139 | "Target 2",boxLog,
|
|---|
| 140 | worldPhys,false,0);
|
|---|
| 141 |
|
|---|
| 142 | G4PVPlacement *offYPhys=new G4PVPlacement(0,G4ThreeVector(15,0,-10),
|
|---|
| 143 | "Target 3",slabLog,
|
|---|
| 144 | worldPhys,false,0);
|
|---|
| 145 |
|
|---|
| 146 | // G4PVPlacement *offYZPhys=
|
|---|
| 147 | new G4PVPlacement(0,G4ThreeVector(0,15,10),
|
|---|
| 148 | "Target 4",boxLog,
|
|---|
| 149 | worldPhys,false,0);
|
|---|
| 150 | // G4PVPlacement *offMYZPhys=
|
|---|
| 151 | new G4PVPlacement(0,G4ThreeVector(0,-15,10),
|
|---|
| 152 | "Target 5",boxLog,
|
|---|
| 153 | worldPhys,false,0);
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 | G4LogicalVolume *variLog=new G4LogicalVolume(myVariableBox,0,
|
|---|
| 157 | "Variable Blocks",0,0,0);
|
|---|
| 158 | // G4PVParameterised *paramPhys=
|
|---|
| 159 | new G4PVParameterised("Vari' Blocks",
|
|---|
| 160 | variLog,
|
|---|
| 161 | offYPhys,
|
|---|
| 162 | kYAxis,
|
|---|
| 163 | 3,
|
|---|
| 164 | &myParam);
|
|---|
| 165 | return worldPhys;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | //
|
|---|
| 169 | // Test LocateGlobalPointAndSetup
|
|---|
| 170 | //
|
|---|
| 171 | G4bool testG4Navigator1(G4VPhysicalVolume *pTopNode)
|
|---|
| 172 | {
|
|---|
| 173 | MyNavigator myNav;
|
|---|
| 174 | G4VPhysicalVolume *located;
|
|---|
| 175 | myNav.SetWorldVolume(pTopNode);
|
|---|
| 176 |
|
|---|
| 177 | assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0),0,false));
|
|---|
| 178 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,0),0,false);
|
|---|
| 179 | assert(located->GetName()=="World");
|
|---|
| 180 |
|
|---|
| 181 | assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0)));
|
|---|
| 182 |
|
|---|
| 183 | // Check relative search that causes backup one level and then search down:
|
|---|
| 184 | // Nonrel' finds Target 3, then rel' with point in Target 5 finds Target 5
|
|---|
| 185 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,0,-10),0,false);
|
|---|
| 186 | assert(located->GetName()=="Vari' Blocks");
|
|---|
| 187 |
|
|---|
| 188 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,-15,20));
|
|---|
| 189 | assert(located->GetName()=="Target 5");
|
|---|
| 190 | assert(ApproxEqual(myNav.CurrentLocalCoordinate(),G4ThreeVector(0,0,10)));
|
|---|
| 191 | // Check that outside point causes stack to unwind
|
|---|
| 192 | assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0)));
|
|---|
| 193 |
|
|---|
| 194 | // Check parameterised volumes
|
|---|
| 195 |
|
|---|
| 196 | // Replication 0
|
|---|
| 197 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-15,-10));
|
|---|
| 198 | assert(located->GetName()=="Vari' Blocks");
|
|---|
| 199 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-15,-16));
|
|---|
| 200 | assert(located->GetName()=="Target 3");
|
|---|
| 201 |
|
|---|
| 202 | // Replication 1
|
|---|
| 203 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,0,-10));
|
|---|
| 204 | assert(located->GetName()=="Vari' Blocks");
|
|---|
| 205 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,0,-17));
|
|---|
| 206 | assert(located->GetName()=="Target 3");
|
|---|
| 207 |
|
|---|
| 208 | // Replication 2
|
|---|
| 209 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,15,-10));
|
|---|
| 210 | assert(located->GetName()=="Vari' Blocks");
|
|---|
| 211 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,15,-18));
|
|---|
| 212 | assert(located->GetName()=="Target 3");
|
|---|
| 213 |
|
|---|
| 214 | return true;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 | //
|
|---|
| 219 | // Test Stepping
|
|---|
| 220 | //
|
|---|
| 221 | G4bool testG4Navigator2(G4VPhysicalVolume *pTopNode)
|
|---|
| 222 | {
|
|---|
| 223 | MyNavigator myNav;
|
|---|
| 224 | G4VPhysicalVolume *located;
|
|---|
| 225 | G4double Step,physStep,safety;
|
|---|
| 226 | G4ThreeVector xHat(1,0,0),yHat(0,1,0),zHat(0,0,1);
|
|---|
| 227 | G4ThreeVector mxHat(-1,0,0),myHat(0,-1,0),mzHat(0,0,-1);
|
|---|
| 228 |
|
|---|
| 229 | myNav.SetWorldVolume(pTopNode);
|
|---|
| 230 |
|
|---|
| 231 | //
|
|---|
| 232 | // Test location & Step computation
|
|---|
| 233 | //
|
|---|
| 234 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-10));
|
|---|
| 235 | assert(located->GetName()=="World");
|
|---|
| 236 | physStep=kInfinity;
|
|---|
| 237 | Step=myNav.ComputeStep(G4ThreeVector(0,0,-10),mxHat,physStep,safety);
|
|---|
| 238 | assert(ApproxEqual(Step,25));
|
|---|
| 239 | // assert(ApproxEqual(safety,5));
|
|---|
| 240 | assert(safety>=0);
|
|---|
| 241 |
|
|---|
| 242 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-10));
|
|---|
| 243 | assert(located->GetName()=="World");
|
|---|
| 244 | physStep=kInfinity;
|
|---|
| 245 | Step=myNav.ComputeStep(G4ThreeVector(0,0,-10),xHat,physStep,safety);
|
|---|
| 246 | assert(ApproxEqual(Step,5));
|
|---|
| 247 | // assert(ApproxEqual(safety,5));
|
|---|
| 248 | assert(safety>=0);
|
|---|
| 249 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 250 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(5,0,-10),0,true);
|
|---|
| 251 | assert(located->GetName()=="Vari' Blocks");
|
|---|
| 252 |
|
|---|
| 253 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-10));
|
|---|
| 254 | assert(located->GetName()=="World");
|
|---|
| 255 | physStep=kInfinity;
|
|---|
| 256 | Step=myNav.ComputeStep(G4ThreeVector(0,0,-10),zHat,physStep,safety);
|
|---|
| 257 | assert(ApproxEqual(Step,30));
|
|---|
| 258 | // assert(ApproxEqual(safety,5));
|
|---|
| 259 | assert(safety>=0);
|
|---|
| 260 |
|
|---|
| 261 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-10));
|
|---|
| 262 | assert(located->GetName()=="World");
|
|---|
| 263 | physStep=kInfinity;
|
|---|
| 264 | Step=myNav.ComputeStep(G4ThreeVector(0,0,-10),mzHat,physStep,safety);
|
|---|
| 265 | assert(ApproxEqual(Step,10));
|
|---|
| 266 | // assert(ApproxEqual(safety,5));
|
|---|
| 267 | assert(safety>=0);
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 | //
|
|---|
| 271 | // Test stepping through common boundaries
|
|---|
| 272 | //
|
|---|
| 273 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-7,7,-20));
|
|---|
| 274 | assert(located->GetName()=="Target 1");
|
|---|
| 275 | physStep=kInfinity;
|
|---|
| 276 | Step=myNav.ComputeStep(G4ThreeVector(-7,7,-20),zHat,physStep,safety);
|
|---|
| 277 | assert(ApproxEqual(Step,20));
|
|---|
| 278 | assert(ApproxEqual(safety,0));
|
|---|
| 279 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 280 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-7,7,0));
|
|---|
| 281 | assert(located->GetName()=="Target 4");
|
|---|
| 282 | Step=myNav.ComputeStep(G4ThreeVector(-7,7,0),zHat,physStep,safety);
|
|---|
| 283 | assert(ApproxEqual(Step,20));
|
|---|
| 284 | assert(ApproxEqual(safety,0));
|
|---|
| 285 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 286 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-7,7,20));
|
|---|
| 287 | assert(!located);
|
|---|
| 288 |
|
|---|
| 289 | //
|
|---|
| 290 | // Test mother limited Step
|
|---|
| 291 | //
|
|---|
| 292 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-25,0,10));
|
|---|
| 293 | assert(located->GetName()=="World");
|
|---|
| 294 | physStep=kInfinity;
|
|---|
| 295 | Step=myNav.ComputeStep(G4ThreeVector(-25,0,10),xHat,physStep,safety);
|
|---|
| 296 | assert(ApproxEqual(Step,50));
|
|---|
| 297 | assert(ApproxEqual(safety,0));
|
|---|
| 298 |
|
|---|
| 299 | //
|
|---|
| 300 | // Test stepping through parameterised volumes
|
|---|
| 301 | //
|
|---|
| 302 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-25,-10),0,false);
|
|---|
| 303 | assert(located->GetName()=="Target 3");
|
|---|
| 304 | physStep=kInfinity;
|
|---|
| 305 | Step=myNav.ComputeStep(G4ThreeVector(15,-25,-10),yHat,physStep,safety);
|
|---|
| 306 | assert(ApproxEqual(Step,5));
|
|---|
| 307 | assert(ApproxEqual(safety,0));
|
|---|
| 308 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 309 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-20,-10));
|
|---|
| 310 | assert(located->GetName()=="Vari' Blocks");
|
|---|
| 311 | Step=myNav.ComputeStep(G4ThreeVector(15,-20,-10),yHat,physStep,safety);
|
|---|
| 312 | assert(ApproxEqual(Step,10));
|
|---|
| 313 | assert(ApproxEqual(safety,0));
|
|---|
| 314 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 315 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-10,-10));
|
|---|
| 316 | assert(located->GetName()=="Target 3");
|
|---|
| 317 | Step=myNav.ComputeStep(G4ThreeVector(15,-10,-10),yHat,physStep,safety);
|
|---|
| 318 | assert(ApproxEqual(Step,4));
|
|---|
| 319 | assert(ApproxEqual(safety,0));
|
|---|
| 320 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 321 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,-6,-10));
|
|---|
| 322 | assert(located->GetName()=="Vari' Blocks");
|
|---|
| 323 | Step=myNav.ComputeStep(G4ThreeVector(15,-6,-10),yHat,physStep,safety);
|
|---|
| 324 | assert(ApproxEqual(Step,12));
|
|---|
| 325 | assert(ApproxEqual(safety,0));
|
|---|
| 326 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 327 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,6,-10));
|
|---|
| 328 | assert(located->GetName()=="Target 3");
|
|---|
| 329 | Step=myNav.ComputeStep(G4ThreeVector(15,6,-10),yHat,physStep,safety);
|
|---|
| 330 | assert(ApproxEqual(Step,2));
|
|---|
| 331 | assert(ApproxEqual(safety,0));
|
|---|
| 332 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 333 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,8,-10));
|
|---|
| 334 | assert(located->GetName()=="Vari' Blocks");
|
|---|
| 335 | Step=myNav.ComputeStep(G4ThreeVector(15,8,-10),yHat,physStep,safety);
|
|---|
| 336 | assert(ApproxEqual(Step,14));
|
|---|
| 337 | assert(ApproxEqual(safety,0));
|
|---|
| 338 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 339 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,22,-10));
|
|---|
| 340 | assert(located->GetName()=="Target 3");
|
|---|
| 341 | Step=myNav.ComputeStep(G4ThreeVector(15,22,-10),yHat,physStep,safety);
|
|---|
| 342 | assert(ApproxEqual(Step,3));
|
|---|
| 343 | assert(ApproxEqual(safety,0));
|
|---|
| 344 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 345 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,25,-10));
|
|---|
| 346 | assert(!located);
|
|---|
| 347 |
|
|---|
| 348 | return true;
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | int main()
|
|---|
| 352 | {
|
|---|
| 353 | G4VPhysicalVolume *myTopNode;
|
|---|
| 354 | myTopNode=BuildGeometry(); // Build the geometry
|
|---|
| 355 | G4GeometryManager::GetInstance()->CloseGeometry(false);
|
|---|
| 356 | testG4Navigator1(myTopNode);
|
|---|
| 357 | testG4Navigator2(myTopNode);
|
|---|
| 358 | // Repeat tests but with full voxels
|
|---|
| 359 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 360 | G4GeometryManager::GetInstance()->CloseGeometry(true);
|
|---|
| 361 | testG4Navigator1(myTopNode);
|
|---|
| 362 | testG4Navigator2(myTopNode);
|
|---|
| 363 |
|
|---|
| 364 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 365 | return 0;
|
|---|
| 366 | }
|
|---|