| [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: testG4ParameterisedSolid1.cc,v 1.13 2006/06/29 18:58:43 gunter Exp $
|
|---|
| [1347] | 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $
|
|---|
| [1316] | 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | //
|
|---|
| 32 | // Define geometry with parameterised volumes that parameterise solid type
|
|---|
| 33 | //
|
|---|
| 34 | // Test the Navigation in this geometry
|
|---|
| 35 | // (which also include rotations as well as translations).
|
|---|
| 36 | //
|
|---|
| 37 |
|
|---|
| 38 | #include <assert.h>
|
|---|
| 39 | #include "G4ios.hh"
|
|---|
| 40 | #include "ApproxEqual.hh"
|
|---|
| 41 |
|
|---|
| 42 | // Global defs
|
|---|
| 43 | #include "globals.hh"
|
|---|
| 44 |
|
|---|
| 45 | #include "G4LogicalVolume.hh"
|
|---|
| 46 | #include "G4VPhysicalVolume.hh"
|
|---|
| 47 | #include "G4PVPlacement.hh"
|
|---|
| 48 | #include "G4PVParameterised.hh"
|
|---|
| 49 | #include "G4VPVParameterisation.hh"
|
|---|
| 50 | #include "G4Box.hh"
|
|---|
| 51 | #include "G4Sphere.hh"
|
|---|
| 52 |
|
|---|
| 53 | #include "G4GeometryManager.hh"
|
|---|
| 54 |
|
|---|
| 55 | #include "G4RotationMatrix.hh"
|
|---|
| 56 | #include "G4ThreeVector.hh"
|
|---|
| 57 |
|
|---|
| 58 | // Sample Parameterisation
|
|---|
| 59 | class BoxesAndSpheres : public G4VPVParameterisation
|
|---|
| 60 | {
|
|---|
| 61 | public:
|
|---|
| 62 | BoxesAndSpheres(G4double twistAngle, G4int noBoxes, G4int noSpheres)
|
|---|
| 63 | {
|
|---|
| 64 | fRotationVec= new G4RotationMatrix();
|
|---|
| 65 | fTwistAngle= twistAngle;
|
|---|
| 66 | fNumBoxes= noBoxes;
|
|---|
| 67 | fNumSpheres= noSpheres;
|
|---|
| 68 | fBox= new G4Box("Test Box",10.,10.,10.);
|
|---|
| 69 | fSphere= new G4Sphere("Test Sphere",0.,1.,0*deg,180*deg,0*deg,90*deg);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | virtual ~BoxesAndSpheres()
|
|---|
| 73 | {
|
|---|
| 74 | // delete fRotationVec;
|
|---|
| 75 | // delete fBox;
|
|---|
| 76 | // delete fSphere;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | G4double GetTwistAngle() { return fTwistAngle; }
|
|---|
| 80 | void SetTwistAngle(G4double newAngle ) { fTwistAngle= newAngle; }
|
|---|
| 81 |
|
|---|
| 82 | virtual G4VSolid* ComputeSolid(const G4int n,
|
|---|
| 83 | G4VPhysicalVolume*)
|
|---|
| 84 | {
|
|---|
| 85 | G4VSolid* mySolid=0;
|
|---|
| 86 | if( n < fNumBoxes ) {
|
|---|
| 87 | if( n >= 0 ) {
|
|---|
| 88 | mySolid = fBox;
|
|---|
| 89 | }else{
|
|---|
| 90 | G4Exception(" Your Boxes+Spheres replica number was out of range");
|
|---|
| 91 | }
|
|---|
| 92 | }else{
|
|---|
| 93 | if( n < fNumBoxes + fNumSpheres ) {
|
|---|
| 94 | mySolid = fSphere;
|
|---|
| 95 | }else{
|
|---|
| 96 | G4Exception(" Your Boxes+Spheres replica number was out of range");
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 | return mySolid;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | virtual void ComputeTransformation(const G4int n,
|
|---|
| 103 | G4VPhysicalVolume* pRep) const
|
|---|
| 104 | {
|
|---|
| 105 | pRep->SetTranslation(G4ThreeVector(n*100*mm,0.,0.));
|
|---|
| 106 | *fRotationVec = G4RotationMatrix(); // Unit matrix
|
|---|
| 107 | fRotationVec->rotateZ( n * fTwistAngle );
|
|---|
| 108 | pRep->SetRotation( fRotationVec );
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | virtual void ComputeDimensions(G4Box &pBox,
|
|---|
| 112 | const G4int,
|
|---|
| 113 | const G4VPhysicalVolume*) const
|
|---|
| 114 | {
|
|---|
| 115 | if( &pBox != fBox ){
|
|---|
| 116 | G4cerr << " Got another Box in ComputeDimensions(G4Box, , )" << G4endl;
|
|---|
| 117 | }
|
|---|
| 118 | pBox.SetXHalfLength(10*mm);
|
|---|
| 119 | pBox.SetYHalfLength(10*mm);
|
|---|
| 120 | pBox.SetZHalfLength(10*mm);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | virtual void ComputeDimensions(G4Sphere &pSphere,
|
|---|
| 124 | const G4int n,
|
|---|
| 125 | const G4VPhysicalVolume*) const
|
|---|
| 126 | {
|
|---|
| 127 | if( &pSphere != fSphere )
|
|---|
| 128 | {
|
|---|
| 129 | G4cerr << " Got another sphere in ComputeDimensions(G4Sphere, , )"
|
|---|
| 130 | << G4endl;
|
|---|
| 131 | }
|
|---|
| 132 | G4int nrad= std::min(5, n-fNumBoxes+1);
|
|---|
| 133 | pSphere.SetInsideRadius( nrad * 5. * mm);
|
|---|
| 134 | pSphere.SetOuterRadius ( nrad * 10. * mm);
|
|---|
| 135 | pSphere.SetStartPhiAngle (0.);
|
|---|
| 136 | pSphere.SetDeltaPhiAngle (2*pi);
|
|---|
| 137 | pSphere.SetStartThetaAngle(0);
|
|---|
| 138 | pSphere.SetDeltaThetaAngle(pi);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | virtual void ComputeDimensions(G4Tubs &,
|
|---|
| 142 | const G4int ,
|
|---|
| 143 | const G4VPhysicalVolume*) const {}
|
|---|
| 144 | virtual void ComputeDimensions(G4Trd &,
|
|---|
| 145 | const G4int,
|
|---|
| 146 | const G4VPhysicalVolume*) const {}
|
|---|
| 147 | virtual void ComputeDimensions(G4Cons &,
|
|---|
| 148 | const G4int ,
|
|---|
| 149 | const G4VPhysicalVolume*) const {}
|
|---|
| 150 | virtual void ComputeDimensions(G4Trap &,
|
|---|
| 151 | const G4int ,
|
|---|
| 152 | const G4VPhysicalVolume*) const {}
|
|---|
| 153 | virtual void ComputeDimensions(G4Hype &,
|
|---|
| 154 | const G4int ,
|
|---|
| 155 | const G4VPhysicalVolume*) const {}
|
|---|
| 156 | virtual void ComputeDimensions(G4Orb &,
|
|---|
| 157 | const G4int ,
|
|---|
| 158 | const G4VPhysicalVolume*) const {}
|
|---|
| 159 | virtual void ComputeDimensions(G4Torus &,
|
|---|
| 160 | const G4int ,
|
|---|
| 161 | const G4VPhysicalVolume*) const {}
|
|---|
| 162 | virtual void ComputeDimensions(G4Para &,
|
|---|
| 163 | const G4int ,
|
|---|
| 164 | const G4VPhysicalVolume*) const {}
|
|---|
| 165 | virtual void ComputeDimensions(G4Polycone &,
|
|---|
| 166 | const G4int ,
|
|---|
| 167 | const G4VPhysicalVolume*) const {}
|
|---|
| 168 | virtual void ComputeDimensions(G4Polyhedra &,
|
|---|
| 169 | const G4int ,
|
|---|
| 170 | const G4VPhysicalVolume*) const {}
|
|---|
| 171 | private:
|
|---|
| 172 | G4RotationMatrix *fRotationVec;
|
|---|
| 173 | G4double fTwistAngle;
|
|---|
| 174 | G4int fNumBoxes;
|
|---|
| 175 | G4int fNumSpheres;
|
|---|
| 176 | G4Box* fBox;
|
|---|
| 177 | G4Sphere* fSphere;
|
|---|
| 178 | };
|
|---|
| 179 |
|
|---|
| 180 | G4double angle1= 15.0*deg; // pi/180. ;
|
|---|
| 181 | BoxesAndSpheres myParam(angle1,3,4);
|
|---|
| 182 |
|
|---|
| 183 | // Build simple geometry:
|
|---|
| 184 | // 4 small cubes (G4Boxes) are positioned inside a larger cuboid
|
|---|
| 185 | G4VPhysicalVolume* BuildGeometry()
|
|---|
| 186 | {
|
|---|
| 187 |
|
|---|
| 188 | // The world volume
|
|---|
| 189 | //
|
|---|
| 190 | G4Box *myBigBox= new G4Box ("Big Cube", 1000*mm, 1000*mm, 1000*mm);
|
|---|
| 191 |
|
|---|
| 192 | G4LogicalVolume *worldLog=new G4LogicalVolume(myBigBox,0,
|
|---|
| 193 | "World",0,0,0);
|
|---|
| 194 | // Logical with no material,field,
|
|---|
| 195 | // sensitive detector or user limits
|
|---|
| 196 |
|
|---|
| 197 | G4PVPlacement *worldPhys=new G4PVPlacement(0,G4ThreeVector(0,0,0),
|
|---|
| 198 | "World",worldLog,
|
|---|
| 199 | 0,false,0);
|
|---|
| 200 | // Note: no mother pointer set
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 | // A set of boxes
|
|---|
| 204 | G4Box *myBox=new G4Box("cube",10,10,10);
|
|---|
| 205 | G4LogicalVolume *boxLog=new G4LogicalVolume(myBox,0,
|
|---|
| 206 | "Rotating Box",0,0,0);
|
|---|
| 207 |
|
|---|
| 208 | // G4PVParameterised *paramP=
|
|---|
| 209 | new G4PVParameterised("Rotating Block Or Sphere",
|
|---|
| 210 | boxLog,
|
|---|
| 211 | worldPhys, //OR worldLog,
|
|---|
| 212 | kXAxis,
|
|---|
| 213 | 7,
|
|---|
| 214 | &myParam);
|
|---|
| 215 | // Copies 0, 1 & 2 will exist
|
|---|
| 216 |
|
|---|
| 217 | return worldPhys;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | //
|
|---|
| 221 | // Test LocateGlobalPointAndSetup
|
|---|
| 222 | //
|
|---|
| 223 | G4bool testG4Navigator1(G4VPhysicalVolume *pTopNode)
|
|---|
| 224 | {
|
|---|
| 225 | MyNavigator myNav;
|
|---|
| 226 | G4VPhysicalVolume *located;
|
|---|
| 227 | myNav.SetWorldVolume(pTopNode);
|
|---|
| 228 |
|
|---|
| 229 | assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0),0,false));
|
|---|
| 230 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(100,100,100),0,false);
|
|---|
| 231 | assert(located->GetName()=="World");
|
|---|
| 232 |
|
|---|
| 233 | assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0)));
|
|---|
| 234 |
|
|---|
| 235 | //
|
|---|
| 236 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,-5,-5),0,false);
|
|---|
| 237 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 238 | assert(located->GetCopyNo()== 0);
|
|---|
| 239 | assert(ApproxEqual(myNav.CurrentLocalCoordinate(),G4ThreeVector(0,-5,-5)));
|
|---|
| 240 | G4cout << " Local coords = " << myNav.CurrentLocalCoordinate() << G4endl;
|
|---|
| 241 |
|
|---|
| 242 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(100,0,5));
|
|---|
| 243 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 244 | assert(located->GetCopyNo()== 1);
|
|---|
| 245 | assert(ApproxEqual(myNav.CurrentLocalCoordinate(),
|
|---|
| 246 | G4ThreeVector(0. ,0., 5)));
|
|---|
| 247 |
|
|---|
| 248 | // Check that the rotation is correct
|
|---|
| 249 | //
|
|---|
| 250 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(105,0,0));
|
|---|
| 251 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 252 | assert(located->GetCopyNo()== 1);
|
|---|
| 253 | #if 0
|
|---|
| 254 | // G4cout << " Local coords = " << myNav.GetCurrentLocalCoordinate() << G4endl;
|
|---|
| 255 | G4ThreeVector ExpectedPosition(5*std::cos(angle1),-5.*std::sin(angle1),0.);
|
|---|
| 256 | G4cout << " Expected = " << ExpectedPosition << G4endl;
|
|---|
| 257 | assert(ApproxEqual(myNav.CurrentLocalCoordinate(),ExpectedPosition ));
|
|---|
| 258 | if(!ApproxEqual(myNav.CurrentLocalCoordinate(),ExpectedPosition ))
|
|---|
| 259 | {
|
|---|
| 260 | G4cout << " Error: The coordinates do not match " << G4endl;
|
|---|
| 261 | }
|
|---|
| 262 | #endif
|
|---|
| 263 |
|
|---|
| 264 | // Check that outside point causes stack to unwind
|
|---|
| 265 | assert(!myNav.LocateGlobalPointAndSetup(G4ThreeVector(kInfinity,0,0)));
|
|---|
| 266 |
|
|---|
| 267 | // Check parameterised volumes
|
|---|
| 268 |
|
|---|
| 269 | // Replication 0
|
|---|
| 270 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(5,0,5));
|
|---|
| 271 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 272 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Box");
|
|---|
| 273 | assert(located->GetCopyNo()== 0);
|
|---|
| 274 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,15,15));
|
|---|
| 275 | assert(located->GetName()=="World");
|
|---|
| 276 |
|
|---|
| 277 | // Replication 1
|
|---|
| 278 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(105,0,5));
|
|---|
| 279 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 280 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Box");
|
|---|
| 281 | assert(located->GetCopyNo()== 1);
|
|---|
| 282 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-17));
|
|---|
| 283 | assert(located->GetName()=="World");
|
|---|
| 284 |
|
|---|
| 285 | // Replication 2
|
|---|
| 286 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(205,0,5));
|
|---|
| 287 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 288 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Box");
|
|---|
| 289 | assert(located->GetCopyNo()== 2);
|
|---|
| 290 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(15,15,-18));
|
|---|
| 291 | assert(located->GetName()=="World");
|
|---|
| 292 |
|
|---|
| 293 | // Replication 3
|
|---|
| 294 | // Sphere 1, radii: inner/outer= 5 to 10
|
|---|
| 295 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(307.5,0.0,0.0));
|
|---|
| 296 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 297 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Sphere");
|
|---|
| 298 | assert(located->GetCopyNo()== 3);
|
|---|
| 299 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(315,15,-18));
|
|---|
| 300 | assert(located->GetName()=="World");
|
|---|
| 301 |
|
|---|
| 302 | // Replication 4
|
|---|
| 303 | // Sphere 2, radii: inner/outer= 10 to 20
|
|---|
| 304 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(410.,10.,10.));
|
|---|
| 305 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 306 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Sphere");
|
|---|
| 307 | assert(located->GetCopyNo()== 4);
|
|---|
| 308 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(315,15,-18));
|
|---|
| 309 | assert(located->GetName()=="World");
|
|---|
| 310 |
|
|---|
| 311 | // Replication 5
|
|---|
| 312 | // Sphere 3, radii: inner/outer= 15 to 30
|
|---|
| 313 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(510.0,10.0,10.0));
|
|---|
| 314 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 315 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Sphere");
|
|---|
| 316 | assert(located->GetCopyNo()== 5);
|
|---|
| 317 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(500,35,-10));
|
|---|
| 318 | assert(located->GetName()=="World");
|
|---|
| 319 |
|
|---|
| 320 | // Replication 6
|
|---|
| 321 | // Sphere 4, radii: inner/outer= 20 to 40
|
|---|
| 322 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(622.5,22.5,22.5));
|
|---|
| 323 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 324 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Sphere");
|
|---|
| 325 | assert(located->GetCopyNo()== 6);
|
|---|
| 326 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(600,45,-10));
|
|---|
| 327 | assert(located->GetName()=="World");
|
|---|
| 328 |
|
|---|
| 329 | return true;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 | //
|
|---|
| 334 | // Test Stepping
|
|---|
| 335 | //
|
|---|
| 336 | G4bool testG4Navigator2(G4VPhysicalVolume *pTopNode)
|
|---|
| 337 | {
|
|---|
| 338 | MyNavigator myNav;
|
|---|
| 339 | G4VPhysicalVolume *located;
|
|---|
| 340 | G4double Step,physStep,safety;
|
|---|
| 341 | G4ThreeVector xHat(1,0,0),yHat(0,1,0),zHat(0,0,1);
|
|---|
| 342 | G4ThreeVector mxHat(-1,0,0),myHat(0,-1,0),mzHat(0,0,-1);
|
|---|
| 343 |
|
|---|
| 344 | myNav.SetWorldVolume(pTopNode);
|
|---|
| 345 |
|
|---|
| 346 | //
|
|---|
| 347 | // Test location & Step computation
|
|---|
| 348 | //
|
|---|
| 349 | G4ThreeVector StartPoint(-50*mm,0,-5*mm);
|
|---|
| 350 | located=myNav.LocateGlobalPointAndSetup( StartPoint );
|
|---|
| 351 | assert(located->GetName()=="World");
|
|---|
| 352 | physStep=kInfinity;
|
|---|
| 353 | Step=myNav.ComputeStep( StartPoint, mxHat,physStep,safety); // -x dir
|
|---|
| 354 | assert(ApproxEqual(Step,950*mm));
|
|---|
| 355 | // assert(ApproxEqual(safety,40*mm));
|
|---|
| 356 | // assert(safety>=0);
|
|---|
| 357 |
|
|---|
| 358 | StartPoint= G4ThreeVector(-15*mm,0,-5*mm);
|
|---|
| 359 | located=myNav.LocateGlobalPointAndSetup( StartPoint );
|
|---|
| 360 | assert(located->GetName()=="World");
|
|---|
| 361 | physStep=kInfinity;
|
|---|
| 362 | Step=myNav.ComputeStep( StartPoint,xHat,physStep,safety); // +x dir
|
|---|
| 363 | assert(ApproxEqual(Step,5));
|
|---|
| 364 | // assert(ApproxEqual(safety,5));
|
|---|
| 365 | assert(safety>=0);
|
|---|
| 366 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 367 | G4ThreeVector EndPoint = StartPoint + Step * xHat;
|
|---|
| 368 | located=myNav.LocateGlobalPointAndSetup(EndPoint,0,true);
|
|---|
| 369 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 370 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Box");
|
|---|
| 371 | assert(located->GetCopyNo()== 0);
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0,-40));
|
|---|
| 375 | assert(located->GetName()=="World");
|
|---|
| 376 | physStep=kInfinity;
|
|---|
| 377 | Step=myNav.ComputeStep(G4ThreeVector(0,0,-40),zHat,physStep,safety); // +z
|
|---|
| 378 | assert(ApproxEqual(Step,30));
|
|---|
| 379 | assert(safety>=0);
|
|---|
| 380 | // Now locate the endpoint
|
|---|
| 381 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 382 | EndPoint = StartPoint + Step * xHat;
|
|---|
| 383 | located=myNav.LocateGlobalPointAndSetup(EndPoint,0,true);
|
|---|
| 384 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 385 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Box");
|
|---|
| 386 | assert(located->GetCopyNo()== 0);
|
|---|
| 387 |
|
|---|
| 388 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(0,0, 40));
|
|---|
| 389 | assert(located->GetName()=="World");
|
|---|
| 390 | physStep=kInfinity;
|
|---|
| 391 | Step=myNav.ComputeStep(G4ThreeVector(0,0,40),mzHat,physStep,safety);
|
|---|
| 392 | assert(ApproxEqual(Step,30));
|
|---|
| 393 | // assert(ApproxEqual(safety,5));
|
|---|
| 394 | assert(safety>=0);
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 | //
|
|---|
| 398 | // Test moving through series of volumes
|
|---|
| 399 | //
|
|---|
| 400 | StartPoint= G4ThreeVector(-20,0,0);
|
|---|
| 401 | located=myNav.LocateGlobalPointAndSetup(G4ThreeVector(-20,0,0));
|
|---|
| 402 | assert(located->GetName()=="World");
|
|---|
| 403 |
|
|---|
| 404 | // Replication 0 block
|
|---|
| 405 | //
|
|---|
| 406 | physStep=kInfinity;
|
|---|
| 407 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 408 | assert(ApproxEqual(Step,10));
|
|---|
| 409 | EndPoint= StartPoint + Step * xHat; // Should be -10, 0, 0
|
|---|
| 410 | assert( ApproxEqual( EndPoint, G4ThreeVector(-10,0,0) ) );
|
|---|
| 411 | assert(safety<=10);
|
|---|
| 412 |
|
|---|
| 413 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 414 | located=myNav.LocateGlobalPointAndSetup(EndPoint) ;
|
|---|
| 415 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 416 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Box");
|
|---|
| 417 | assert(located->GetCopyNo()== 0);
|
|---|
| 418 | Step=myNav.ComputeStep(EndPoint,xHat,physStep,safety); // +x
|
|---|
| 419 | assert(ApproxEqual(Step,20));
|
|---|
| 420 | assert(ApproxEqual(safety,0));
|
|---|
| 421 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 422 | EndPoint += Step * xHat; // Should be +10, 0, 0
|
|---|
| 423 | assert(ApproxEqual( EndPoint, G4ThreeVector(10,0,0) ));
|
|---|
| 424 | located=myNav.LocateGlobalPointAndSetup( EndPoint );
|
|---|
| 425 | assert(located->GetName()=="World");
|
|---|
| 426 |
|
|---|
| 427 | // Replication 1 block
|
|---|
| 428 | //
|
|---|
| 429 | StartPoint= EndPoint;
|
|---|
| 430 | physStep=kInfinity;
|
|---|
| 431 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 432 | assert(ApproxEqual(Step,90.-10./std::cos(angle1)));
|
|---|
| 433 | EndPoint= StartPoint + Step * xHat; // Should be near 90, 0, 0
|
|---|
| 434 | assert(safety==0.);
|
|---|
| 435 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 436 | located=myNav.LocateGlobalPointAndSetup(EndPoint) ;
|
|---|
| 437 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 438 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Box");
|
|---|
| 439 | assert(located->GetCopyNo()== 1);
|
|---|
| 440 |
|
|---|
| 441 | StartPoint= EndPoint;
|
|---|
| 442 | physStep=kInfinity;
|
|---|
| 443 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 444 | assert(ApproxEqual(Step,20./std::cos(angle1)));
|
|---|
| 445 | assert(ApproxEqual(safety,0));
|
|---|
| 446 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 447 | EndPoint += Step * xHat; // Should be near 110, 0, 0
|
|---|
| 448 | assert(ApproxEqual(EndPoint,G4ThreeVector(100.+10./std::cos(angle1),0,0)));
|
|---|
| 449 | located=myNav.LocateGlobalPointAndSetup( EndPoint );
|
|---|
| 450 | assert(located->GetName()=="World");
|
|---|
| 451 |
|
|---|
| 452 | // Replication 2 block
|
|---|
| 453 | //
|
|---|
| 454 | StartPoint= EndPoint;
|
|---|
| 455 | physStep=kInfinity;
|
|---|
| 456 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 457 | assert(ApproxEqual(Step,100.-10.*(1./std::cos(angle1)+1./std::cos(2.*angle1))));
|
|---|
| 458 | EndPoint= StartPoint + Step * xHat; // Should near 0, 190, 0
|
|---|
| 459 | assert(safety<=Step);
|
|---|
| 460 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 461 | located=myNav.LocateGlobalPointAndSetup(EndPoint);
|
|---|
| 462 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 463 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Box");
|
|---|
| 464 | assert(located->GetCopyNo()== 2);
|
|---|
| 465 |
|
|---|
| 466 | StartPoint= EndPoint;
|
|---|
| 467 | physStep=kInfinity;
|
|---|
| 468 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 469 | assert(ApproxEqual(Step,20./std::cos(2.*angle1)));
|
|---|
| 470 | assert(ApproxEqual(safety,0));
|
|---|
| 471 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 472 | EndPoint += Step * xHat; // Should be near 210, 0, 0
|
|---|
| 473 | assert(ApproxEqual(EndPoint,G4ThreeVector(200.+10./std::cos(2.*angle1),0,0)));
|
|---|
| 474 | located=myNav.LocateGlobalPointAndSetup( EndPoint );
|
|---|
| 475 | assert(located->GetName()=="World");
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 | // Replication 3 : sphere #1
|
|---|
| 479 | //
|
|---|
| 480 | StartPoint= EndPoint;
|
|---|
| 481 | physStep=kInfinity;
|
|---|
| 482 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 483 | assert(ApproxEqual(Step,(100.-10./std::cos(2.*angle1)-10.)*mm));
|
|---|
| 484 | EndPoint= StartPoint + Step * xHat; // Should be 290, 0, 0
|
|---|
| 485 | assert(ApproxEqual(EndPoint,G4ThreeVector(290.*mm,0,0)));
|
|---|
| 486 | assert(safety==0.); // Started from a surface
|
|---|
| 487 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 488 | located=myNav.LocateGlobalPointAndSetup(EndPoint);
|
|---|
| 489 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 490 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Sphere");
|
|---|
| 491 | assert(located->GetCopyNo()== 3);
|
|---|
| 492 |
|
|---|
| 493 | StartPoint= EndPoint;
|
|---|
| 494 | physStep=kInfinity;
|
|---|
| 495 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 496 | assert(ApproxEqual(Step,5.));
|
|---|
| 497 | assert(ApproxEqual(safety,0.));
|
|---|
| 498 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 499 | EndPoint += Step * xHat; // Should be near 295, 0, 0
|
|---|
| 500 | assert(ApproxEqual(EndPoint,G4ThreeVector(295*mm,0,0)));
|
|---|
| 501 | // Now Hit inner surface of spherical shell
|
|---|
| 502 | located=myNav.LocateGlobalPointAndSetup( EndPoint );
|
|---|
| 503 | assert(located->GetName()=="World");
|
|---|
| 504 |
|
|---|
| 505 | // Cross "empty" inner sphere
|
|---|
| 506 | //
|
|---|
| 507 | StartPoint= EndPoint;
|
|---|
| 508 | physStep=kInfinity;
|
|---|
| 509 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 510 | assert(ApproxEqual(Step,(10.*mm)));
|
|---|
| 511 | EndPoint= StartPoint + Step * xHat; // Should be 290, 0, 0
|
|---|
| 512 | assert(ApproxEqual(EndPoint,G4ThreeVector(305.*mm,0,0)));
|
|---|
| 513 | assert(ApproxEqual(safety,0.)); // Started from a surface
|
|---|
| 514 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 515 | located=myNav.LocateGlobalPointAndSetup(EndPoint);
|
|---|
| 516 | assert(located->GetName()=="Rotating Block Or Sphere");
|
|---|
| 517 | assert(located->GetLogicalVolume()->GetSolid()->GetName()=="Test Sphere");
|
|---|
| 518 | assert(located->GetCopyNo()== 3);
|
|---|
| 519 |
|
|---|
| 520 | // Now Hit outer surface of spherical shell
|
|---|
| 521 | StartPoint= EndPoint;
|
|---|
| 522 | physStep=kInfinity;
|
|---|
| 523 | Step=myNav.ComputeStep(StartPoint,xHat,physStep,safety);
|
|---|
| 524 | assert(ApproxEqual(Step,5.));
|
|---|
| 525 | assert(ApproxEqual(safety,0.));
|
|---|
| 526 | myNav.SetGeometricallyLimitedStep();
|
|---|
| 527 | EndPoint += Step * xHat; // Should be near 310, 0, 0
|
|---|
| 528 | assert(ApproxEqual(EndPoint,G4ThreeVector(310*mm,0,0)));
|
|---|
| 529 | located=myNav.LocateGlobalPointAndSetup( EndPoint );
|
|---|
| 530 | assert(located->GetName()=="World");
|
|---|
| 531 |
|
|---|
| 532 | // Continue the test later ...
|
|---|
| 533 |
|
|---|
| 534 | return true;
|
|---|
| 535 | }
|
|---|
| 536 |
|
|---|
| 537 | int main()
|
|---|
| 538 | {
|
|---|
| 539 | G4VPhysicalVolume *myTopNode;
|
|---|
| 540 | myTopNode=BuildGeometry(); // Build the geometry
|
|---|
| 541 | G4GeometryManager::GetInstance()->CloseGeometry(false);
|
|---|
| 542 | testG4Navigator1(myTopNode);
|
|---|
| 543 | testG4Navigator2(myTopNode);
|
|---|
| 544 | // Repeat tests but with full voxels
|
|---|
| 545 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 546 | G4GeometryManager::GetInstance()->CloseGeometry(true);
|
|---|
| 547 | testG4Navigator1(myTopNode);
|
|---|
| 548 | testG4Navigator2(myTopNode);
|
|---|
| 549 |
|
|---|
| 550 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 551 | return 0;
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|