| [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: testG4TouchableHandle.cc,v 1.8 2006/06/29 18:58:54 gunter Exp $
|
|---|
| [1347] | 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $
|
|---|
| [1316] | 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // Test file for G4TouchableHandle class
|
|---|
| 32 | // Radovan Chytracek 2001
|
|---|
| 33 |
|
|---|
| 34 | #include "ApproxEqual.hh"
|
|---|
| 35 | #include "G4ThreeVector.hh"
|
|---|
| 36 |
|
|---|
| 37 | #include "G4GRSVolume.hh"
|
|---|
| 38 | #include "G4GRSSolid.hh"
|
|---|
| 39 | #include "G4TouchableHistory.hh"
|
|---|
| 40 | #include "G4TouchableHandle.hh"
|
|---|
| 41 | #include "G4TouchableHistoryHandle.hh"
|
|---|
| 42 | #include "G4GRSSolidHandle.hh"
|
|---|
| 43 | #include "G4GRSVolumeHandle.hh"
|
|---|
| 44 |
|
|---|
| 45 | #include "G4GeometryManager.hh"
|
|---|
| 46 |
|
|---|
| 47 | #include "G4PVPlacement.hh"
|
|---|
| 48 | #include "G4PVParameterised.hh"
|
|---|
| 49 | #include "G4PVReplica.hh"
|
|---|
| 50 | #include "G4LogicalVolume.hh"
|
|---|
| 51 | #include "G4Box.hh"
|
|---|
| 52 |
|
|---|
| 53 | // Sample Parameterisation
|
|---|
| 54 | class G4LinScale : public G4VPVParameterisation
|
|---|
| 55 | {
|
|---|
| 56 | virtual void ComputeTransformation(const G4int n,
|
|---|
| 57 | G4VPhysicalVolume *pRep) const
|
|---|
| 58 | {
|
|---|
| 59 | pRep->SetTranslation(G4ThreeVector(n*4-2,n*4-2,n*4-2));
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | virtual void ComputeDimensions(G4Box &pBox,
|
|---|
| 63 | const G4int n,
|
|---|
| 64 | const G4VPhysicalVolume *) const
|
|---|
| 65 | {
|
|---|
| 66 | pBox.SetXHalfLength(n+1);
|
|---|
| 67 | pBox.SetYHalfLength(n+1);
|
|---|
| 68 | pBox.SetZHalfLength(n+1);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | virtual void ComputeDimensions(G4Tubs &,
|
|---|
| 72 | const G4int ,
|
|---|
| 73 | const G4VPhysicalVolume*) const {}
|
|---|
| 74 | virtual void ComputeDimensions(G4Trd &,
|
|---|
| 75 | const G4int,
|
|---|
| 76 | const G4VPhysicalVolume*) const {}
|
|---|
| 77 | virtual void ComputeDimensions(G4Cons &,
|
|---|
| 78 | const G4int ,
|
|---|
| 79 | const G4VPhysicalVolume*) const {}
|
|---|
| 80 | virtual void ComputeDimensions(G4Trap &,
|
|---|
| 81 | const G4int ,
|
|---|
| 82 | const G4VPhysicalVolume*) const {}
|
|---|
| 83 | virtual void ComputeDimensions(G4Hype &,
|
|---|
| 84 | const G4int ,
|
|---|
| 85 | const G4VPhysicalVolume*) const {}
|
|---|
| 86 | virtual void ComputeDimensions(G4Orb &,
|
|---|
| 87 | const G4int ,
|
|---|
| 88 | const G4VPhysicalVolume*) const {}
|
|---|
| 89 | virtual void ComputeDimensions(G4Sphere &,
|
|---|
| 90 | const G4int ,
|
|---|
| 91 | const G4VPhysicalVolume*) const {}
|
|---|
| 92 | virtual void ComputeDimensions(G4Torus &,
|
|---|
| 93 | const G4int ,
|
|---|
| 94 | const G4VPhysicalVolume*) const {}
|
|---|
| 95 | virtual void ComputeDimensions(G4Para &,
|
|---|
| 96 | const G4int ,
|
|---|
| 97 | const G4VPhysicalVolume*) const {}
|
|---|
| 98 | virtual void ComputeDimensions(G4Polycone &,
|
|---|
| 99 | const G4int ,
|
|---|
| 100 | const G4VPhysicalVolume*) const {}
|
|---|
| 101 | virtual void ComputeDimensions(G4Polyhedra &,
|
|---|
| 102 | const G4int ,
|
|---|
| 103 | const G4VPhysicalVolume*) const {}
|
|---|
| 104 | };
|
|---|
| 105 |
|
|---|
| 106 | G4LinScale myParam;
|
|---|
| 107 |
|
|---|
| 108 | G4VPhysicalVolume* BuildGeometry()
|
|---|
| 109 | {
|
|---|
| 110 | G4Box *worldBox=new G4Box("WorldBox",1000,1000,1000);
|
|---|
| 111 | G4Box *posBox=new G4Box("PosBox",10,10,10);
|
|---|
| 112 | G4Box *posBoxSlice=new G4Box("PosBoxSlice",10,10,2);
|
|---|
| 113 | G4Box *paramBox=new G4Box("ParamBox",1,1,1);
|
|---|
| 114 |
|
|---|
| 115 | G4LogicalVolume *worldLog=new G4LogicalVolume(worldBox,0,
|
|---|
| 116 | "WorldLog",0,0,0);
|
|---|
| 117 | G4LogicalVolume *posLog=new G4LogicalVolume(posBox,0,
|
|---|
| 118 | "PosLog",0,0,0);
|
|---|
| 119 | G4LogicalVolume *pos2Log=new G4LogicalVolume(posBox,0,
|
|---|
| 120 | "Pos2Log",0,0,0);
|
|---|
| 121 | G4LogicalVolume *pos3Log=new G4LogicalVolume(posBox,0,
|
|---|
| 122 | "Pos3Log",0,0,0);
|
|---|
| 123 | G4LogicalVolume *pos4Log=new G4LogicalVolume(posBox,0,
|
|---|
| 124 | "Pos4Log",0,0,0);
|
|---|
| 125 | G4LogicalVolume *posSliceLog=new G4LogicalVolume(posBoxSlice,0,
|
|---|
| 126 | "PosSliceLog",0,0,0);
|
|---|
| 127 | G4LogicalVolume *paramLog=new G4LogicalVolume(paramBox,0,
|
|---|
| 128 | "ParamLog",0,0,0);
|
|---|
| 129 |
|
|---|
| 130 | G4PVPlacement *worldPhys=new G4PVPlacement(0,G4ThreeVector(0,0,0),
|
|---|
| 131 | "WorldPhys",worldLog,0,false,0);
|
|---|
| 132 | G4PVPlacement *posPhys1=new G4PVPlacement(0,G4ThreeVector(10,11,12),
|
|---|
| 133 | "PosPhys1",posLog,worldPhys,
|
|---|
| 134 | false,0);
|
|---|
| 135 | // G4PVPlacement *posPhys2=
|
|---|
| 136 | new G4PVPlacement(0,G4ThreeVector(0,0,0),
|
|---|
| 137 | "PosPhys2",pos2Log,posPhys1,
|
|---|
| 138 | false,0);
|
|---|
| 139 | G4PVPlacement *posPhys3=new G4PVPlacement(0,G4ThreeVector(-10,-11,-12),
|
|---|
| 140 | "PosPhys3",pos3Log,worldPhys,
|
|---|
| 141 | false,0);
|
|---|
| 142 | G4PVPlacement *posPhys4=new G4PVPlacement(0,G4ThreeVector(10,0,0),
|
|---|
| 143 | "PosPhys4",pos4Log,worldPhys,
|
|---|
| 144 | false,0);
|
|---|
| 145 | // G4PVReplica *repPhys=
|
|---|
| 146 | new G4PVReplica("RepPhys",posSliceLog,posPhys3,
|
|---|
| 147 | kZAxis,5,4);
|
|---|
| 148 |
|
|---|
| 149 | // G4PVParameterised *paramPhys=
|
|---|
| 150 | new G4PVParameterised("ParamPhys",
|
|---|
| 151 | paramLog,
|
|---|
| 152 | posPhys4,
|
|---|
| 153 | kXAxis,2,&myParam);
|
|---|
| 154 | return worldPhys;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | G4bool testGRSVolume(MyNavigator& nav)
|
|---|
| 158 | {
|
|---|
| 159 | G4ThreeVector pos;
|
|---|
| 160 |
|
|---|
| 161 | pos=G4ThreeVector(11,12,13);
|
|---|
| 162 | nav.LocateGlobalPointAndSetup(pos);
|
|---|
| 163 | G4TouchableHandle touch = nav.CreateGRSVolume();
|
|---|
| 164 | assert(touch);
|
|---|
| 165 | assert(touch->GetVolume()->GetName()=="PosPhys2");
|
|---|
| 166 | assert(touch->GetSolid()->GetName()=="PosBox");
|
|---|
| 167 | assert(ApproxEqual(touch->GetTranslation(),G4ThreeVector(10,11,12)));
|
|---|
| 168 | assert(!touch->GetRotation()||touch->GetRotation()->isIdentity());
|
|---|
| 169 | // delete touch;
|
|---|
| 170 | return true;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | G4bool testGRSSolid(MyNavigator& nav)
|
|---|
| 174 | {
|
|---|
| 175 | G4ThreeVector pos;
|
|---|
| 176 |
|
|---|
| 177 | pos=G4ThreeVector(11,12,13);
|
|---|
| 178 | nav.LocateGlobalPointAndSetup(pos);
|
|---|
| 179 | G4TouchableHandle touch = nav.CreateGRSSolid();
|
|---|
| 180 | assert(touch);
|
|---|
| 181 | assert(touch->GetSolid()->GetName()=="PosBox");
|
|---|
| 182 | assert(ApproxEqual(touch->GetTranslation(),G4ThreeVector(10,11,12)));
|
|---|
| 183 | assert(!touch->GetRotation()||touch->GetRotation()->isIdentity());
|
|---|
| 184 | // delete touch;
|
|---|
| 185 | return true;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | G4bool testTouchableHistory(MyNavigator& nav)
|
|---|
| 189 | {
|
|---|
| 190 | G4ThreeVector pos(11,12,13),pos2(9,-1,-1);
|
|---|
| 191 | G4VPhysicalVolume *pvol;
|
|---|
| 192 |
|
|---|
| 193 | pvol=nav.LocateGlobalPointAndSetup(pos);
|
|---|
| 194 | assert(pvol->GetName()=="PosPhys2");
|
|---|
| 195 | assert(pvol->GetMotherLogical()->GetName()=="PosLog");
|
|---|
| 196 |
|
|---|
| 197 | G4TouchableHistoryHandle touch = nav.CreateTouchableHistory();
|
|---|
| 198 | assert(touch);
|
|---|
| 199 | assert(touch->GetVolume()->GetName()=="PosPhys2");
|
|---|
| 200 | assert(touch->GetSolid()->GetName()=="PosBox");
|
|---|
| 201 | assert(ApproxEqual(touch->GetTranslation(),G4ThreeVector(10,11,12)));
|
|---|
| 202 | assert(!touch->GetRotation()||touch->GetRotation()->isIdentity());
|
|---|
| 203 | assert(touch->GetHistory()->GetDepth()==2);
|
|---|
| 204 |
|
|---|
| 205 | pvol=nav.LocateGlobalPointAndSetup(-pos);
|
|---|
| 206 | assert(pvol->GetName()=="RepPhys");
|
|---|
| 207 | assert(pvol->GetMotherLogical()->GetName()=="Pos3Log");
|
|---|
| 208 | assert(ApproxEqual(nav.CurrentLocalCoordinate(),G4ThreeVector(-1,-1,-1)));
|
|---|
| 209 |
|
|---|
| 210 | G4TouchableHistoryHandle touch2 = nav.CreateTouchableHistory();
|
|---|
| 211 | assert(touch2);
|
|---|
| 212 | assert(touch2->GetVolume()->GetName()=="RepPhys");
|
|---|
| 213 | assert(touch2->GetSolid()->GetName()=="PosBoxSlice");
|
|---|
| 214 | assert(ApproxEqual(touch2->GetTranslation(),G4ThreeVector(-10,-11,-12)));
|
|---|
| 215 | assert(!touch2->GetRotation()||touch2->GetRotation()->isIdentity());
|
|---|
| 216 | assert(touch2->GetHistory()->GetDepth()==2);
|
|---|
| 217 |
|
|---|
| 218 | pvol=nav.LocateGlobalPointAndSetup(pos2);
|
|---|
| 219 | assert(pvol->GetName()=="ParamPhys");
|
|---|
| 220 | assert(pvol->GetMotherLogical()->GetName()=="Pos4Log");
|
|---|
| 221 | assert(ApproxEqual(nav.CurrentLocalCoordinate(),G4ThreeVector(1,1,1)));
|
|---|
| 222 |
|
|---|
| 223 | G4TouchableHistoryHandle touch3 = nav.CreateTouchableHistory();
|
|---|
| 224 | // Relocate to another parameterised volume causing modification of
|
|---|
| 225 | // physical volume + solid
|
|---|
| 226 | pvol=nav.LocateGlobalPointAndSetup(pos2+G4ThreeVector(2,2,2));
|
|---|
| 227 | assert(touch3);
|
|---|
| 228 | assert(touch3->GetVolume()->GetName()=="ParamPhys");
|
|---|
| 229 | assert(touch3->GetSolid()->GetName()=="ParamBox");
|
|---|
| 230 | assert(ApproxEqual(touch3->GetTranslation(),G4ThreeVector(8,-2,-2)));
|
|---|
| 231 | assert(!touch3->GetRotation()||touch3->GetRotation()->isIdentity());
|
|---|
| 232 | assert(touch3->GetHistory()->GetDepth()==2);
|
|---|
| 233 |
|
|---|
| 234 | G4ThreeVector dir(0,0,0);
|
|---|
| 235 | pvol=nav.ResetHierarchyAndLocate(pos, dir, *((G4TouchableHistory*)touch()) );
|
|---|
| 236 | assert(ApproxEqual(nav.CurrentLocalCoordinate(),G4ThreeVector(1,1,1)));
|
|---|
| 237 | assert(pvol->GetName()=="PosPhys2");
|
|---|
| 238 | assert(pvol->GetMotherLogical()->GetName()=="PosLog");
|
|---|
| 239 | assert(ApproxEqual(nav.GetNetTranslation(),G4ThreeVector(10,11,12)));
|
|---|
| 240 |
|
|---|
| 241 | pvol=nav.ResetHierarchyAndLocate(-pos, dir, *((G4TouchableHistory*)touch2()) );
|
|---|
| 242 | assert(ApproxEqual(nav.CurrentLocalCoordinate(),G4ThreeVector(-1,-1,-1)));
|
|---|
| 243 | assert(pvol->GetName()=="RepPhys");
|
|---|
| 244 | assert(pvol->GetMotherLogical()->GetName()=="Pos3Log");
|
|---|
| 245 | assert(ApproxEqual(nav.GetNetTranslation(),G4ThreeVector(-10,-11,-12)));
|
|---|
| 246 |
|
|---|
| 247 | pvol=nav.ResetHierarchyAndLocate(pos2, dir, *((G4TouchableHistory*)touch3()));
|
|---|
| 248 | assert(pvol->GetName()=="ParamPhys");
|
|---|
| 249 | assert(pvol->GetMotherLogical()->GetName()=="Pos4Log");
|
|---|
| 250 | assert(ApproxEqual(nav.GetNetTranslation(),G4ThreeVector(8,-2,-2)));
|
|---|
| 251 |
|
|---|
| 252 | /*
|
|---|
| 253 | delete touch;
|
|---|
| 254 | delete touch2;
|
|---|
| 255 | delete touch3;
|
|---|
| 256 | */
|
|---|
| 257 | return true;
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | int main()
|
|---|
| 261 | {
|
|---|
| 262 | G4VPhysicalVolume *myTopNode=BuildGeometry();
|
|---|
| 263 | G4GeometryManager::GetInstance()->CloseGeometry(false);
|
|---|
| 264 | MyNavigator nav;
|
|---|
| 265 | nav.SetWorldVolume(myTopNode);
|
|---|
| 266 |
|
|---|
| 267 | assert(testGRSVolume(nav));
|
|---|
| 268 | assert(testGRSSolid(nav));
|
|---|
| 269 | assert(testTouchableHistory(nav));
|
|---|
| 270 |
|
|---|
| 271 | G4GeometryManager::GetInstance()->OpenGeometry();
|
|---|
| 272 | return EXIT_SUCCESS;
|
|---|
| 273 | }
|
|---|