[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: testG4Volumes.cc,v 1.10 2006/06/29 18:58:59 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ |
---|
| 29 | // |
---|
| 30 | // |
---|
| 31 | // testG4Volumes Placement and replica/parameterised volumes setup tests |
---|
| 32 | // Ensure asserts are compiled in |
---|
| 33 | |
---|
| 34 | #include <assert.h> |
---|
| 35 | |
---|
| 36 | #include "globals.hh" |
---|
| 37 | |
---|
| 38 | #include "G4LogicalVolumeStore.hh" |
---|
| 39 | #include "G4PhysicalVolumeStore.hh" |
---|
| 40 | #include "G4SolidStore.hh" |
---|
| 41 | |
---|
| 42 | #include "G4LogicalVolume.hh" |
---|
| 43 | #include "G4PVPlacement.hh" |
---|
| 44 | #include "G4PVReplica.hh" |
---|
| 45 | |
---|
| 46 | #include "G4Box.hh" |
---|
| 47 | |
---|
| 48 | #include "G4RotationMatrix.hh" |
---|
| 49 | #include "G4ThreeVector.hh" |
---|
| 50 | |
---|
| 51 | // Test of logical volume, where not related to physical volumes |
---|
| 52 | G4bool testG4LogicalVolume() |
---|
| 53 | { |
---|
| 54 | G4String myName("MySolenoid"); |
---|
| 55 | G4String myName2("red"); |
---|
| 56 | G4Box myBox("cube",10,10,10); |
---|
| 57 | G4Box myBigBox("cuboid",25,20,20); |
---|
| 58 | |
---|
| 59 | G4LogicalVolume myMotherVol(&myBigBox,0,myName,0,0,0); |
---|
| 60 | // Logical with no material,field, |
---|
| 61 | // sensitive detector or user limits |
---|
| 62 | // Check naming |
---|
| 63 | assert(myMotherVol.GetName()==myName); |
---|
| 64 | myMotherVol.SetName(myName2); |
---|
| 65 | assert(myMotherVol.GetName()==myName2); |
---|
| 66 | // Check remaining initialisation |
---|
| 67 | assert(myMotherVol.GetNoDaughters()==0); |
---|
| 68 | assert(myMotherVol.GetSolid()==&myBigBox); |
---|
| 69 | assert(myMotherVol.GetMaterial()==0); |
---|
| 70 | assert(myMotherVol.GetFieldManager()==0); |
---|
| 71 | assert(myMotherVol.GetSensitiveDetector()==0); |
---|
| 72 | assert(myMotherVol.GetUserLimits()==0); |
---|
| 73 | assert(myMotherVol.GetVoxelHeader()==0); |
---|
| 74 | |
---|
| 75 | // Check daughter access functionality |
---|
| 76 | G4LogicalVolume myDaughter(&myBox,0,"block",0,0,0); |
---|
| 77 | G4PVPlacement offsetx(0,G4ThreeVector(-15,0,0), |
---|
| 78 | "Target 1",&myDaughter, |
---|
| 79 | 0,false,0); |
---|
| 80 | // Note: no mother pointer set |
---|
| 81 | G4PVPlacement offsety(0,G4ThreeVector(15,0,0), |
---|
| 82 | "Target 2",&myDaughter, |
---|
| 83 | 0,false,0); |
---|
| 84 | // Note: no mother pointer set |
---|
| 85 | |
---|
| 86 | assert(myMotherVol.GetNoDaughters()==0); |
---|
| 87 | assert(myMotherVol.IsDaughter(&offsetx)==false); |
---|
| 88 | |
---|
| 89 | myMotherVol.AddDaughter(&offsetx); |
---|
| 90 | assert(myMotherVol.GetNoDaughters()==1); |
---|
| 91 | assert(myMotherVol.IsDaughter(&offsetx)==true); |
---|
| 92 | assert(myMotherVol.IsDaughter(&offsety)==false); |
---|
| 93 | assert(myMotherVol.GetDaughter(0)==&offsetx); |
---|
| 94 | myMotherVol.RemoveDaughter(&offsetx); |
---|
| 95 | assert(myMotherVol.GetNoDaughters()==0); |
---|
| 96 | assert(myMotherVol.IsDaughter(&offsetx)==false); |
---|
| 97 | // myMotherVol left unchanged |
---|
| 98 | |
---|
| 99 | return true; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | // Test of simple positioning, where not related to logical volumes |
---|
| 103 | G4bool testG4PVPlacement() |
---|
| 104 | { |
---|
| 105 | G4Box myBox("cube",10,10,10); |
---|
| 106 | G4ThreeVector vmx(-15,0,0); |
---|
| 107 | G4LogicalVolume myDaughter(&myBox,0,"block",0,0,0); |
---|
| 108 | G4PVPlacement offsetx(0,vmx,"Target 1",&myDaughter, |
---|
| 109 | 0,false,0); |
---|
| 110 | |
---|
| 111 | assert(offsetx.GetCopyNo()==0); |
---|
| 112 | assert(offsetx.GetTranslation()==vmx); |
---|
| 113 | assert(offsetx.GetRotation()==0); |
---|
| 114 | assert(offsetx.GetLogicalVolume()==&myDaughter); |
---|
| 115 | assert(offsetx.GetName()=="Target 1"); |
---|
| 116 | assert(offsetx.IsMany()==false); |
---|
| 117 | assert(offsetx.IsReplicated()==false); |
---|
| 118 | |
---|
| 119 | assert(offsetx.GetTranslation()==vmx); |
---|
| 120 | assert(offsetx.GetRotation()==0); |
---|
| 121 | |
---|
| 122 | assert(offsetx.GetFrameRotation()==0); |
---|
| 123 | G4cout << "FrameTranslation=" << offsetx.GetFrameTranslation() |
---|
| 124 | << " - Expected= " << vmx << G4endl; |
---|
| 125 | // assert(offsetx.GetFrameTranslation()==vmx); |
---|
| 126 | |
---|
| 127 | assert(offsetx.GetObjectTranslation()==vmx); |
---|
| 128 | assert(offsetx.GetObjectRotation()->isIdentity()); |
---|
| 129 | assert(offsetx.GetObjectRotationValue().isIdentity()); |
---|
| 130 | |
---|
| 131 | return true; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | // Test of simple replication, where not related to logical volumes |
---|
| 135 | G4bool testG4PVReplica() |
---|
| 136 | { |
---|
| 137 | G4Box myBigBox("Big Cube",1000,1000,1000); |
---|
| 138 | G4LogicalVolume myMotherVol(&myBigBox,0,"Big cube",0,0,0); |
---|
| 139 | // Logical with no material,field, |
---|
| 140 | // sensitive detector or user limits |
---|
| 141 | |
---|
| 142 | G4Box myBox("cube",10,10,10); |
---|
| 143 | G4LogicalVolume myDaughter(&myBox,0,"block",0,0,0); |
---|
| 144 | G4PVReplica replicaX("Target 1",&myDaughter,&myMotherVol, |
---|
| 145 | kXAxis,2,10); |
---|
| 146 | |
---|
| 147 | assert(replicaX.GetLogicalVolume()==&myDaughter); |
---|
| 148 | assert(replicaX.GetName()=="Target 1"); |
---|
| 149 | assert(replicaX.IsMany()==false); |
---|
| 150 | assert(replicaX.GetCopyNo()== (-1)); |
---|
| 151 | assert(replicaX.IsReplicated()==true); |
---|
| 152 | |
---|
| 153 | EAxis axis; |
---|
| 154 | G4double width,offset; |
---|
| 155 | G4int n; |
---|
| 156 | G4bool consuming; |
---|
| 157 | replicaX.GetReplicationData(axis,n,width,offset,consuming); |
---|
| 158 | assert(axis==kXAxis&&n==2&&width==10&&offset==0&&consuming==true); |
---|
| 159 | |
---|
| 160 | return true; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | // Combined test of logical and physical volumes |
---|
| 164 | // 2 small cubes are positioned inside a larger cuboid |
---|
| 165 | // |
---|
| 166 | // Check navigation links, `Store' entries |
---|
| 167 | G4bool testG4Volumes() |
---|
| 168 | { |
---|
| 169 | G4Box myBigBox("cuboid",25,20,20); |
---|
| 170 | G4Box myBox("cube",10,10,10); |
---|
| 171 | |
---|
| 172 | G4LogicalVolume myDetectorLog(&myBigBox,0, |
---|
| 173 | "World",0,0,0); |
---|
| 174 | // Logical with no material,field, |
---|
| 175 | // sensitive detector or user limits |
---|
| 176 | |
---|
| 177 | G4PVPlacement myDetectorPhys(0,G4ThreeVector(0,0,0), |
---|
| 178 | "World",&myDetectorLog, |
---|
| 179 | 0,false,0); |
---|
| 180 | // Note: no mother pointer set |
---|
| 181 | |
---|
| 182 | G4LogicalVolume myDaughterLog(&myBox,0,"block",0,0,0); |
---|
| 183 | G4PVPlacement offXPhys(0,G4ThreeVector(-15,0,0), |
---|
| 184 | "Target 1",&myDaughterLog, |
---|
| 185 | &myDetectorPhys,false,0); |
---|
| 186 | G4PVPlacement offMXPhys(0,G4ThreeVector(15,0,0), |
---|
| 187 | "Target 2",&myDaughterLog, |
---|
| 188 | &myDetectorPhys,false,0); |
---|
| 189 | |
---|
| 190 | // Assert on navigation links |
---|
| 191 | assert(offXPhys.GetMotherLogical()==&myDetectorLog); |
---|
| 192 | assert(offMXPhys.GetMotherLogical()==&myDetectorLog); |
---|
| 193 | |
---|
| 194 | assert(myDetectorPhys.GetLogicalVolume()==&myDetectorLog); |
---|
| 195 | assert(myDetectorLog.GetNoDaughters()==2); |
---|
| 196 | assert(myDetectorLog.GetDaughter(0)==&offXPhys); |
---|
| 197 | assert(myDetectorLog.GetDaughter(1)==&offMXPhys); |
---|
| 198 | |
---|
| 199 | // Check stores are ok |
---|
| 200 | assert(G4PhysicalVolumeStore::GetInstance()->size()==3); |
---|
| 201 | assert(G4LogicalVolumeStore::GetInstance()->size()==2); |
---|
| 202 | G4SolidStore* solidStore = G4SolidStore::GetInstance(); |
---|
| 203 | G4bool exists = 0; |
---|
| 204 | std::vector<G4VSolid*>::const_iterator i; |
---|
| 205 | assert(solidStore->size()==2); |
---|
| 206 | for (i=solidStore->begin(); i!=solidStore->end(); ++i) { |
---|
| 207 | if (**i==myBox) { |
---|
| 208 | exists = 1; |
---|
| 209 | break; |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | assert(exists); |
---|
| 213 | |
---|
| 214 | // Check setup set mother ok |
---|
| 215 | assert(offXPhys.GetMotherLogical()==&myDetectorLog); |
---|
| 216 | assert(offXPhys.GetTranslation()==G4ThreeVector(-15,0,0)); |
---|
| 217 | assert(offXPhys.GetRotation()==0); |
---|
| 218 | |
---|
| 219 | return true; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | int main() |
---|
| 223 | { |
---|
| 224 | #ifdef NDEBUG |
---|
| 225 | G4Exception("FAIL: *** Assertions must be compiled in! ***"); |
---|
| 226 | #endif |
---|
| 227 | assert(testG4LogicalVolume()); |
---|
| 228 | assert(testG4PVPlacement()); |
---|
| 229 | assert(testG4PVReplica()); |
---|
| 230 | assert(testG4Volumes()); |
---|
| 231 | return 0; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | |
---|
| 237 | |
---|