| [1316] | 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: testG4Navigator3.cc,v 1.5 2006/06/29 18:37:21 gunter Exp $
|
|---|
| [1347] | 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $
|
|---|
| [1316] | 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | //
|
|---|
| 32 | // Locate & Step within simple rotated boxlike geometry, both
|
|---|
| 33 | // with and without voxels.
|
|---|
| 34 |
|
|---|
| 35 | #include <assert.h>
|
|---|
| 36 | #include "ApproxEqual.hh"
|
|---|
| 37 |
|
|---|
| 38 | // Global defs
|
|---|
| 39 | #include "globals.hh"
|
|---|
| 40 |
|
|---|
| 41 | #include "G4Navigator.hh"
|
|---|
| 42 |
|
|---|
| 43 | #include "G4LogicalVolume.hh"
|
|---|
| 44 | #include "G4VPhysicalVolume.hh"
|
|---|
| 45 | #include "G4PVPlacement.hh"
|
|---|
| 46 | // #include "G4PVParameterised.hh"
|
|---|
| 47 | #include "G4VPVParameterisation.hh"
|
|---|
| 48 | #include "G4Box.hh"
|
|---|
| 49 |
|
|---|
| 50 | #include "G4GeometryManager.hh"
|
|---|
| 51 | #include "G4PhysicalVolumeStore.hh"
|
|---|
| 52 |
|
|---|
| 53 | #include "G4RotationMatrix.hh"
|
|---|
| 54 | #include "G4ThreeVector.hh"
|
|---|
| 55 |
|
|---|
| 56 | G4VPhysicalVolume* BuildGeometry()
|
|---|
| 57 | {
|
|---|
| 58 |
|
|---|
| 59 | G4Box *myBigBox= new G4Box ("cube",50,50,50);
|
|---|
| 60 | G4Box *myCuboid=new G4Box("cuboid",5,10,15);
|
|---|
| 61 | G4LogicalVolume *worldLog=new G4LogicalVolume(myBigBox,0,
|
|---|
| 62 | "World",0,0,0);
|
|---|
| 63 | // Logical with no material,field,
|
|---|
| 64 | // sensitive detector or user limits
|
|---|
| 65 |
|
|---|
| 66 | G4PVPlacement *worldPhys=new G4PVPlacement(0,G4ThreeVector(0,0,0),
|
|---|
| 67 | "World",worldLog,
|
|---|
| 68 | 0,false,0);
|
|---|
| 69 | // Note: no mother pointer set
|
|---|
| 70 |
|
|---|
| 71 | G4LogicalVolume *cubLog=new G4LogicalVolume(myCuboid,0,
|
|---|
| 72 | "Crystal Box",0,0,0);
|
|---|
| 73 |
|
|---|
| 74 | G4RotationMatrix *rot1=new G4RotationMatrix();
|
|---|
| 75 | rot1->rotateZ(pi*0.5);
|
|---|
| 76 | // G4PVPlacement *cubPhys1=
|
|---|
| 77 | new G4PVPlacement(rot1,G4ThreeVector(0,0,10),
|
|---|
| 78 | "Target 1",cubLog,
|
|---|
| 79 | worldPhys,false,0);
|
|---|
| 80 |
|
|---|
| 81 | G4RotationMatrix *rot2=new G4RotationMatrix();
|
|---|
| 82 | rot2->rotateX(pi*0.5);
|
|---|
| 83 | // G4PVPlacement *cubPhys2=
|
|---|
| 84 | new G4PVPlacement(rot2,G4ThreeVector(-30,0,10),
|
|---|
| 85 | "Target 2",cubLog,
|
|---|
| 86 | worldPhys,false,0);
|
|---|
| 87 | G4RotationMatrix *rot3=new G4RotationMatrix();
|
|---|
| 88 | rot3->rotateY(pi*0.5);
|
|---|
| 89 | // G4PVPlacement *cubPhys3=
|
|---|
| 90 | new G4PVPlacement(rot3,G4ThreeVector(30,0,10),
|
|---|
| 91 | "Target 3",cubLog,
|
|---|
| 92 | worldPhys,false,0);
|
|---|
| 93 | return worldPhys;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 | //
|
|---|
| 98 | // Test LocateGlobalPointAndSetup
|
|---|
| 99 | //
|
|---|
| 100 | G4bool testG4NavigatorLocate(G4VPhysicalVolume *pTopNode)
|
|---|
| 101 | {
|
|---|
| 102 | MyNavigator myNav;
|
|---|
| 103 | G4VPhysicalVolume *located;
|
|---|
| 104 | myNav.SetWorldVolume(pTopNode);
|
|---|
| 105 |
|
|---|
| 106 | assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0),0,false));
|
|---|
| 107 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,10),0,false);
|
|---|
| 108 | assert(located->GetName()=="Target 1");
|
|---|
| 109 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(10,0,10),0,false);
|
|---|
| 110 | assert(located->GetName()=="Target 1");
|
|---|
| 111 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,10,10),0,false);
|
|---|
| 112 | assert(located->GetName()=="World");
|
|---|
| 113 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,5,10),0,false);
|
|---|
| 114 | assert(located->GetName()=="Target 1");
|
|---|
| 115 |
|
|---|
| 116 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-30,0,10),0,false);
|
|---|
| 117 | assert(located->GetName()=="Target 2");
|
|---|
| 118 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-30,10,25),0,false);
|
|---|
| 119 | assert(located->GetName()=="World");
|
|---|
| 120 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-35,15,20),0,false);
|
|---|
| 121 | assert(located->GetName()=="Target 2");
|
|---|
| 122 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-25,-15,0),0,false);
|
|---|
| 123 | assert(located->GetName()=="Target 2");
|
|---|
| 124 |
|
|---|
| 125 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(30,0,10),0,false);
|
|---|
| 126 | assert(located->GetName()=="Target 3");
|
|---|
| 127 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(30,15,15),0,false);
|
|---|
| 128 | assert(located->GetName()=="World");
|
|---|
| 129 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,10,15),0,false);
|
|---|
| 130 | assert(located->GetName()=="Target 3");
|
|---|
| 131 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(45,-10,5),0,false);
|
|---|
| 132 | assert(located->GetName()=="Target 3");
|
|---|
| 133 |
|
|---|
| 134 | return true;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | //
|
|---|
| 138 | // Test ComputeStep
|
|---|
| 139 | //
|
|---|
| 140 | G4bool testG4NavigatorSteps(G4VPhysicalVolume *pTopNode)
|
|---|
| 141 | {
|
|---|
| 142 | MyNavigator myNav;
|
|---|
| 143 | G4VPhysicalVolume *located;
|
|---|
| 144 | G4double Step,physStep,safety;
|
|---|
| 145 | G4ThreeVector pos,dir,origin,xHat(1,0,0),yHat(0,1,0),zHat(0,0,1);
|
|---|
| 146 | G4ThreeVector mxHat(-1,0,0),myHat(0,-1,0),mzHat(0,0,-1);
|
|---|
| 147 | myNav.SetWorldVolume(pTopNode);
|
|---|
| 148 |
|
|---|
| 149 | pos=G4ThreeVector(0,0,10);
|
|---|
| 150 | dir=xHat;
|
|---|
| 151 | located=myNav.LocateGlobalPointAndSetup(pos,0,false);
|
|---|
| 152 | assert(located->GetName()=="Target 1");
|
|---|
| 153 | physStep=kInfinity;
|
|---|
| 154 | Step=myNav.ComputeStep(pos,dir,physStep,safety);
|
|---|
| 155 | assert(ApproxEqual(Step,10));
|
|---|
| 156 | pos+=Step*dir;
|
|---|
| 157 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 158 |
|
|---|
| 159 | located=myNav.LocateGlobalPointAndSetup(pos);
|
|---|
| 160 | assert(located->GetName()=="World");
|
|---|
| 161 | Step=myNav.ComputeStep(pos,dir,physStep,safety);
|
|---|
| 162 | assert(ApproxEqual(Step,5));
|
|---|
| 163 | pos+=Step*dir;
|
|---|
| 164 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 165 | located=myNav.LocateGlobalPointAndSetup(pos);
|
|---|
| 166 | assert(located->GetName()=="Target 3");
|
|---|
| 167 | Step=myNav.ComputeStep(pos,dir,physStep,safety);
|
|---|
| 168 | assert(ApproxEqual(Step,30));
|
|---|
| 169 | pos+=Step*dir;
|
|---|
| 170 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 171 | located=myNav.LocateGlobalPointAndSetup(pos);
|
|---|
| 172 | assert(located->GetName()=="World");
|
|---|
| 173 | Step=myNav.ComputeStep(pos,dir,physStep,safety);
|
|---|
| 174 | assert(ApproxEqual(Step,5));
|
|---|
| 175 | pos+=Step*dir;
|
|---|
| 176 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 177 | located=myNav.LocateGlobalPointAndSetup(pos);
|
|---|
| 178 | assert(located==0);
|
|---|
| 179 | return true;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | int main()
|
|---|
| 183 | {
|
|---|
| 184 | G4VPhysicalVolume *myTopNode;
|
|---|
| 185 | myTopNode=BuildGeometry(); // Build the geometry
|
|---|
| 186 | G4GeometryManager::GetInstance()->CloseGeometry(false);
|
|---|
| 187 | testG4NavigatorLocate(myTopNode);
|
|---|
| 188 | testG4NavigatorSteps(myTopNode);
|
|---|
| 189 | // Repeat tests but with full voxels
|
|---|
| 190 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 191 | G4GeometryManager::GetInstance()->CloseGeometry(true);
|
|---|
| 192 | testG4NavigatorLocate(myTopNode);
|
|---|
| 193 | testG4NavigatorSteps(myTopNode);
|
|---|
| 194 |
|
|---|
| 195 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 196 | G4PhysicalVolumeStore *ps=G4PhysicalVolumeStore::GetInstance();
|
|---|
| 197 | for (G4int i=ps->size()-1;i>=0;i--)
|
|---|
| 198 | {
|
|---|
| 199 | // Delete any rotation matrices
|
|---|
| 200 | delete (*ps)[i]->GetRotation();
|
|---|
| 201 | }
|
|---|
| 202 | return 0;
|
|---|
| 203 | }
|
|---|