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