| [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: testG4Navigator6.cc,v 1.5 2006/06/29 18:37:28 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | //
|
|---|
| 32 | // Create a tubular "calorimeter". Shoot from origin along x & y axes
|
|---|
| 33 | // printing location, steps & safeties. Locate 50^3 points within
|
|---|
| 34 | // calorimeter to check performance of point location logic.
|
|---|
| 35 | //
|
|---|
| 36 | // Arguments: Put `1' or `0' to toggle voxel optimisation on/off
|
|---|
| 37 | // [Default: ON]
|
|---|
| 38 | //
|
|---|
| 39 | // Define G4GEOMETRY_VERBOSE for dump of topmost voxels
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | #include <assert.h>
|
|---|
| 43 | #include "G4ios.hh"
|
|---|
| 44 | #include <stdlib.h>
|
|---|
| 45 |
|
|---|
| 46 | // Global defs
|
|---|
| 47 | #include "globals.hh"
|
|---|
| 48 |
|
|---|
| 49 | #include "G4Timer.hh"
|
|---|
| 50 | #include "ApproxEqual.hh"
|
|---|
| 51 |
|
|---|
| 52 | #include "G4Navigator.hh"
|
|---|
| 53 |
|
|---|
| 54 | #include "G4LogicalVolume.hh"
|
|---|
| 55 | #include "G4VPhysicalVolume.hh"
|
|---|
| 56 | #include "G4PVPlacement.hh"
|
|---|
| 57 | #include "G4Box.hh"
|
|---|
| 58 | #include "G4Tubs.hh"
|
|---|
| 59 |
|
|---|
| 60 | #include "G4GeometryManager.hh"
|
|---|
| 61 |
|
|---|
| 62 | #include "G4RotationMatrix.hh"
|
|---|
| 63 | #include "G4ThreeVector.hh"
|
|---|
| 64 |
|
|---|
| 65 | // Build tubular calorimeter:
|
|---|
| 66 | // An array of interlocking complete tubes, inside a box
|
|---|
| 67 | //
|
|---|
| 68 | // Controlled by:
|
|---|
| 69 | const G4double kTubeHalfHeight = 10;
|
|---|
| 70 | const G4double kTubeRadius = 5;
|
|---|
| 71 | const G4double kTubeNoRow = 10;
|
|---|
| 72 | const G4double kTubeNoColumn = 11; // Should be odd for symmetrical array
|
|---|
| 73 |
|
|---|
| 74 | const G4double kBoxDx=kTubeNoRow*kTubeRadius;
|
|---|
| 75 | const G4double yDelta=2.0*kTubeRadius*std::sin(pi/3.0);
|
|---|
| 76 | const G4double kBoxDy=(kTubeNoColumn-1)*yDelta*0.5+kTubeRadius;
|
|---|
| 77 | const G4double kBoxDz=kTubeHalfHeight;
|
|---|
| 78 |
|
|---|
| 79 | G4VPhysicalVolume* BuildGeometry()
|
|---|
| 80 | {
|
|---|
| 81 | G4double bigXStart=-(kTubeNoRow-1)*kTubeRadius;
|
|---|
| 82 | G4double smallXStart=bigXStart+kTubeRadius;
|
|---|
| 83 |
|
|---|
| 84 | G4double bigYStart=-(kTubeNoColumn-1)*yDelta*0.5;
|
|---|
| 85 | G4double smallYStart=bigYStart+yDelta;
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | G4int row,column;
|
|---|
| 89 |
|
|---|
| 90 | G4Box *calBox = new G4Box ("Cal Box",kBoxDx,kBoxDy,kBoxDz);
|
|---|
| 91 | G4Tubs *calTube = new G4Tubs("Cal Tube",0,kTubeRadius,
|
|---|
| 92 | kTubeHalfHeight,0,360);
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | G4LogicalVolume *myDetectorLog=new G4LogicalVolume(calBox,0,
|
|---|
| 96 | "World",
|
|---|
| 97 | 0,0,0);
|
|---|
| 98 | // Logical with no material,field,
|
|---|
| 99 | // sensitive detector or user limits
|
|---|
| 100 |
|
|---|
| 101 | G4PVPlacement *myDetectorPhys=new G4PVPlacement(0,G4ThreeVector(0,0,0),
|
|---|
| 102 | "World",
|
|---|
| 103 | myDetectorLog,0,false,0);
|
|---|
| 104 | // Note: no mother pointer set
|
|---|
| 105 |
|
|---|
| 106 | G4LogicalVolume *calTubLog=new G4LogicalVolume(calTube,0,
|
|---|
| 107 | "Cal Crystal",
|
|---|
| 108 | 0,0,0);
|
|---|
| 109 |
|
|---|
| 110 | G4String tname("Target");
|
|---|
| 111 | G4int copyNo=0;
|
|---|
| 112 | for (column=0;column<kTubeNoColumn;column+=2)
|
|---|
| 113 | {
|
|---|
| 114 | for (row=0;row<kTubeNoRow;row++)
|
|---|
| 115 | {
|
|---|
| 116 |
|
|---|
| 117 | // G4PVPlacement *calPhys=
|
|---|
| 118 | new G4PVPlacement(
|
|---|
| 119 | 0,G4ThreeVector(bigXStart+row*kTubeRadius*2.0,bigYStart+column*yDelta,0),
|
|---|
| 120 | tname,calTubLog,
|
|---|
| 121 | myDetectorPhys,false,copyNo++);
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | for (column=0;column<kTubeNoColumn-1;column+=2)
|
|---|
| 127 | {
|
|---|
| 128 | for (row=0;row<kTubeNoRow-1;row++)
|
|---|
| 129 | {
|
|---|
| 130 |
|
|---|
| 131 | // G4PVPlacement *calPhys=
|
|---|
| 132 | new G4PVPlacement(
|
|---|
| 133 | 0,G4ThreeVector(smallXStart+row*kTubeRadius*2.0,smallYStart+column*yDelta),
|
|---|
| 134 | tname,calTubLog,
|
|---|
| 135 | myDetectorPhys,false,copyNo++);
|
|---|
| 136 | }
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | return myDetectorPhys;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 | G4bool printShoot(G4VPhysicalVolume *pTopNode,
|
|---|
| 144 | const G4ThreeVector& pLoc,
|
|---|
| 145 | const G4ThreeVector& pVec)
|
|---|
| 146 | {
|
|---|
| 147 | G4double Step=0,safety=0;
|
|---|
| 148 | const G4double physStep=kInfinity;
|
|---|
| 149 | G4VPhysicalVolume *located=0;
|
|---|
| 150 | MyNavigator myNav;
|
|---|
| 151 | myNav.SetWorldVolume(pTopNode);
|
|---|
| 152 |
|
|---|
| 153 | G4ThreeVector partLoc(pLoc);
|
|---|
| 154 | G4cout << "Shooting from " << pLoc << " along " << pVec << G4endl;
|
|---|
| 155 | located=myNav.LocateGlobalPointAndSetup(partLoc);
|
|---|
| 156 | while (located)
|
|---|
| 157 | {
|
|---|
| 158 | Step=myNav.ComputeStep(partLoc,pVec,physStep,safety);
|
|---|
| 159 | G4cout << "Physical Location=" << located->GetName()
|
|---|
| 160 | << " #" << located->GetCopyNo() << G4endl
|
|---|
| 161 | << " Step=" << Step << " Safety=" << safety
|
|---|
| 162 | << " ---->" << G4endl;
|
|---|
| 163 |
|
|---|
| 164 | partLoc+=Step*pVec;
|
|---|
| 165 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 166 | located=myNav.LocateGlobalPointAndSetup(partLoc);
|
|---|
| 167 | }
|
|---|
| 168 | return true;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | G4bool runLocate(G4VPhysicalVolume *pTopNode)
|
|---|
| 172 | {
|
|---|
| 173 | const G4int numLocPerAxis=50;
|
|---|
| 174 | const G4double dxStep=kBoxDx*2.0/numLocPerAxis;
|
|---|
| 175 | const G4double dyStep=kBoxDy*2.0/numLocPerAxis;
|
|---|
| 176 | const G4double dzStep=kBoxDz*2.0/numLocPerAxis;
|
|---|
| 177 |
|
|---|
| 178 | MyNavigator myNav;
|
|---|
| 179 | G4ThreeVector worldPoint;
|
|---|
| 180 | myNav.SetWorldVolume(pTopNode);
|
|---|
| 181 | for (G4double x=-kBoxDx;x<kBoxDx;x+=dxStep)
|
|---|
| 182 | {
|
|---|
| 183 | for (G4double y=-kBoxDy;y<kBoxDy;y+=dyStep)
|
|---|
| 184 | {
|
|---|
| 185 | for (G4double z=-kBoxDz;z<kBoxDz;z+=dzStep)
|
|---|
| 186 | {
|
|---|
| 187 | worldPoint=G4ThreeVector(x,y,z);
|
|---|
| 188 | myNav.LocateGlobalPointAndSetup(worldPoint,0,false);
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | }
|
|---|
| 193 | return true;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | G4bool runAll(G4VPhysicalVolume *pTopNode)
|
|---|
| 197 | {
|
|---|
| 198 | G4cout << "Locating..." << G4endl;
|
|---|
| 199 | runLocate(pTopNode);
|
|---|
| 200 | G4cout << "Done" << G4endl;
|
|---|
| 201 | return true;
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | int main(int argc, char* argv[])
|
|---|
| 205 | {
|
|---|
| 206 | G4bool optimise;
|
|---|
| 207 | G4Timer timer;
|
|---|
| 208 | if (argc==1)
|
|---|
| 209 | {
|
|---|
| 210 | optimise=true;
|
|---|
| 211 | }
|
|---|
| 212 | else if (argc==2)
|
|---|
| 213 | {
|
|---|
| 214 | G4String opt(argv[1]);
|
|---|
| 215 |
|
|---|
| 216 | if (opt=="0")
|
|---|
| 217 | {
|
|---|
| 218 | optimise=false;
|
|---|
| 219 | }
|
|---|
| 220 | else if (opt=="1")
|
|---|
| 221 | {
|
|---|
| 222 | optimise=true;
|
|---|
| 223 | }
|
|---|
| 224 | else
|
|---|
| 225 | {
|
|---|
| 226 | G4cout << "Unknown args" << G4endl;
|
|---|
| 227 | return EXIT_FAILURE;
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|
| 230 | else
|
|---|
| 231 | {
|
|---|
| 232 | G4cout << "Unknown args" << G4endl;
|
|---|
| 233 | return EXIT_FAILURE;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | G4VPhysicalVolume *myTopNode;
|
|---|
| 237 | myTopNode=BuildGeometry(); // Build the geometry
|
|---|
| 238 |
|
|---|
| 239 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 240 |
|
|---|
| 241 | timer.Start();
|
|---|
| 242 | G4GeometryManager::GetInstance()->CloseGeometry(optimise);
|
|---|
| 243 | timer.Stop();
|
|---|
| 244 |
|
|---|
| 245 | //#ifdef G4GEOMETRY_VERBOSE
|
|---|
| 246 | // G4cout << *(G4LogicalVolumeStore::GetInstance()->at(0)->GetVoxelHeader());
|
|---|
| 247 | //#endif
|
|---|
| 248 | if (optimise)
|
|---|
| 249 | {
|
|---|
| 250 | G4cout << "Built voxels ";
|
|---|
| 251 | }
|
|---|
| 252 | else
|
|---|
| 253 | {
|
|---|
| 254 | G4cout << "No voxels ";
|
|---|
| 255 | }
|
|---|
| 256 | G4cout << timer << G4endl;
|
|---|
| 257 |
|
|---|
| 258 | printShoot(myTopNode,
|
|---|
| 259 | G4ThreeVector(-kBoxDx,0,0),
|
|---|
| 260 | G4ThreeVector(1,0,0));
|
|---|
| 261 | printShoot(myTopNode,
|
|---|
| 262 | G4ThreeVector(0,0,0),
|
|---|
| 263 | G4ThreeVector(1/std::sqrt(2.),1/std::sqrt(2.),0));
|
|---|
| 264 | timer.Start();
|
|---|
| 265 | runAll(myTopNode);
|
|---|
| 266 | timer.Stop();
|
|---|
| 267 | G4cout << timer << G4endl;
|
|---|
| 268 |
|
|---|
| 269 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 270 | return EXIT_SUCCESS;
|
|---|
| 271 | }
|
|---|