[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: testG4Hype.cc,v 1.8 2006/06/29 18:49:45 gunter Exp $ |
---|
[1347] | 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $ |
---|
[1316] | 29 | // |
---|
| 30 | |
---|
| 31 | // testG4Hype |
---|
| 32 | // |
---|
| 33 | // Test file for class G4Hype [NOT thorough] |
---|
| 34 | // |
---|
| 35 | // Ensure asserts are compiled in |
---|
| 36 | |
---|
| 37 | #include <assert.h> |
---|
| 38 | #include <cmath> |
---|
| 39 | |
---|
| 40 | #include "globals.hh" |
---|
| 41 | #include "geomdefs.hh" |
---|
| 42 | |
---|
| 43 | #include "ApproxEqual.hh" |
---|
| 44 | |
---|
| 45 | #include "G4ThreeVector.hh" |
---|
| 46 | #include "G4Hype.hh" |
---|
| 47 | #include "G4RotationMatrix.hh" |
---|
| 48 | #include "G4AffineTransform.hh" |
---|
| 49 | #include "G4VoxelLimits.hh" |
---|
| 50 | |
---|
| 51 | G4bool testG4Hype() |
---|
| 52 | { |
---|
| 53 | G4ThreeVector pzero(0,0,0); |
---|
| 54 | |
---|
| 55 | G4ThreeVector pbigx(100,0,0),pbigy(0,100,0),pbigz(0,0,100); |
---|
| 56 | G4ThreeVector pbigmx(-100,0,0),pbigmy(0,-100,0),pbigmz(0,0,-100); |
---|
| 57 | |
---|
| 58 | G4ThreeVector ponxside(50,0,0); |
---|
| 59 | |
---|
| 60 | G4ThreeVector vx(1,0,0),vy(0,1,0),vz(0,0,1); |
---|
| 61 | G4ThreeVector vmx(-1,0,0),vmy(0,-1,0),vmz(0,0,-1); |
---|
| 62 | G4ThreeVector vxy(1/std::sqrt(2.0),1/std::sqrt(2.0),0); |
---|
| 63 | G4ThreeVector vmxy(-1/std::sqrt(2.0),1/std::sqrt(2.0),0); |
---|
| 64 | G4ThreeVector vmxmy(-1/std::sqrt(2.0),-1/std::sqrt(2.0),0); |
---|
| 65 | G4ThreeVector vxmy(1/std::sqrt(2.0),-1/std::sqrt(2.0),0); |
---|
| 66 | |
---|
| 67 | G4double Dist; |
---|
| 68 | G4ThreeVector *pNorm,norm; |
---|
| 69 | G4bool *pgoodNorm,goodNorm,calcNorm=true; |
---|
| 70 | |
---|
| 71 | pNorm=&norm; |
---|
| 72 | pgoodNorm=&goodNorm; |
---|
| 73 | |
---|
| 74 | double iR1=0; |
---|
| 75 | double oR1=50; |
---|
| 76 | double iR2=45; |
---|
| 77 | double oR2=50; |
---|
| 78 | double noStereo=0; |
---|
| 79 | double yesStereo=0.3; |
---|
| 80 | double len=50; |
---|
| 81 | |
---|
| 82 | G4Hype t1("Solid Hype #1",iR1,oR1,noStereo,yesStereo,len); |
---|
| 83 | G4Hype t2("Hole Hype #2",iR2,oR2,yesStereo,yesStereo,len); |
---|
| 84 | |
---|
| 85 | G4ThreeVector Spoint ; |
---|
| 86 | G4double dist ; |
---|
| 87 | for ( int i = 0 ; i < 10 ; i++ ) { |
---|
| 88 | // G4cout << "Event " << i << G4endl << G4endl ; |
---|
| 89 | Spoint = t1.GetPointOnSurface() ; |
---|
| 90 | dist = t1.DistanceToIn(Spoint,-Spoint/Spoint.mag()) ; |
---|
| 91 | G4cout << "Spoint " << Spoint << " " << dist << G4endl ; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | t1.GetPointOnSurface() ; |
---|
| 95 | t2.GetPointOnSurface() ; |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | // Check name |
---|
| 99 | assert(t1.GetName()=="Solid Hype #1"); |
---|
| 100 | |
---|
| 101 | // Check Inside |
---|
| 102 | assert(t1.Inside(pzero)==kInside); |
---|
| 103 | assert(t1.Inside(pbigx)==kOutside); |
---|
| 104 | |
---|
| 105 | // Check Surface Normal |
---|
| 106 | G4ThreeVector normal; |
---|
| 107 | |
---|
| 108 | normal=t1.SurfaceNormal(ponxside); |
---|
| 109 | assert(ApproxEqual(normal,vx)); |
---|
| 110 | |
---|
| 111 | // DistanceToOut(P) |
---|
| 112 | Dist=t1.DistanceToOut(pzero); |
---|
| 113 | assert(ApproxEqual(Dist,50)); |
---|
| 114 | |
---|
| 115 | // DistanceToOut(P,V) |
---|
| 116 | Dist=t1.DistanceToOut(pzero,vx,calcNorm,pgoodNorm,pNorm); |
---|
| 117 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vx)&&(!*pgoodNorm)); |
---|
| 118 | Dist=t1.DistanceToOut(pzero,vmx,calcNorm,pgoodNorm,pNorm); |
---|
| 119 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmx)&&(!*pgoodNorm)); |
---|
| 120 | Dist=t1.DistanceToOut(pzero,vy,calcNorm,pgoodNorm,pNorm); |
---|
| 121 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vy)&&(!*pgoodNorm)); |
---|
| 122 | Dist=t1.DistanceToOut(pzero,vmy,calcNorm,pgoodNorm,pNorm); |
---|
| 123 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmy)&&(!*pgoodNorm)); |
---|
| 124 | Dist=t1.DistanceToOut(pzero,vz,calcNorm,pgoodNorm,pNorm); |
---|
| 125 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vz)&&(*pgoodNorm)); |
---|
| 126 | Dist=t1.DistanceToOut(pzero,vmz,calcNorm,pgoodNorm,pNorm); |
---|
| 127 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmz)&&(*pgoodNorm)); |
---|
| 128 | Dist=t1.DistanceToOut(pzero,vxy,calcNorm,pgoodNorm,pNorm); |
---|
| 129 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vxy)&&(!*pgoodNorm)); |
---|
| 130 | |
---|
| 131 | Dist=t2.DistanceToOut(pzero,vxy,calcNorm,pgoodNorm,pNorm); |
---|
| 132 | G4cout<<"Dist=t2.DistanceToOut(pzero,vxy) = "<<Dist<<G4endl; |
---|
| 133 | |
---|
| 134 | Dist=t2.DistanceToOut(ponxside,vmx,calcNorm,pgoodNorm,pNorm); |
---|
| 135 | G4cout<<"Dist=t2.DistanceToOut(ponxside,vmx) = "<<Dist<<G4endl; |
---|
| 136 | Dist=t2.DistanceToOut(ponxside,vmxmy,calcNorm,pgoodNorm,pNorm); |
---|
| 137 | G4cout<<"Dist=t2.DistanceToOut(ponxside,vmxmy) = "<<Dist<<G4endl; |
---|
| 138 | Dist=t2.DistanceToOut(ponxside,vz,calcNorm,pgoodNorm,pNorm); |
---|
| 139 | G4cout<<"Dist=t2.DistanceToOut(ponxside,vz) = "<<Dist<<G4endl; |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | //DistanceToIn(P) |
---|
| 143 | Dist=t1.DistanceToIn(pbigx); |
---|
| 144 | assert(Dist <= 50*(1.0+DBL_EPSILON)); |
---|
| 145 | Dist=t1.DistanceToIn(pbigmx); |
---|
| 146 | assert(Dist <= 50*(1.0+DBL_EPSILON)); |
---|
| 147 | Dist=t1.DistanceToIn(pbigy); |
---|
| 148 | assert(Dist <= 50*(1.0+DBL_EPSILON)); |
---|
| 149 | Dist=t1.DistanceToIn(pbigmy); |
---|
| 150 | assert(Dist <= 50*(1.0+DBL_EPSILON)); |
---|
| 151 | Dist=t1.DistanceToIn(pbigz); |
---|
| 152 | assert(Dist <= 50*(1.0+DBL_EPSILON)); |
---|
| 153 | Dist=t1.DistanceToIn(pbigmz); |
---|
| 154 | assert(Dist <= 50*(1.0+DBL_EPSILON)); |
---|
| 155 | |
---|
| 156 | // DistanceToIn(P,V) |
---|
| 157 | Dist=t1.DistanceToIn(pbigx,vmx); |
---|
| 158 | assert(ApproxEqual(Dist,50)); |
---|
| 159 | Dist=t1.DistanceToIn(pbigmx,vx); |
---|
| 160 | assert(ApproxEqual(Dist,50)); |
---|
| 161 | Dist=t1.DistanceToIn(pbigy,vmy); |
---|
| 162 | assert(ApproxEqual(Dist,50)); |
---|
| 163 | Dist=t1.DistanceToIn(pbigmy,vy); |
---|
| 164 | assert(ApproxEqual(Dist,50)); |
---|
| 165 | Dist=t1.DistanceToIn(pbigz,vmz); |
---|
| 166 | assert(ApproxEqual(Dist,50)); |
---|
| 167 | Dist=t1.DistanceToIn(pbigmz,vz); |
---|
| 168 | assert(ApproxEqual(Dist,50)); |
---|
| 169 | Dist=t1.DistanceToIn(pbigx,vxy); |
---|
| 170 | assert(ApproxEqual(Dist,kInfinity)); |
---|
| 171 | |
---|
| 172 | // CalculateExtent |
---|
| 173 | G4VoxelLimits limit; // Unlimited |
---|
| 174 | G4RotationMatrix noRot; |
---|
| 175 | G4AffineTransform origin; |
---|
| 176 | G4double min,max; |
---|
| 177 | assert(t1.CalculateExtent(kXAxis,limit,origin,min,max)); |
---|
| 178 | assert(min<=-50&&max>=50); |
---|
| 179 | assert(t1.CalculateExtent(kYAxis,limit,origin,min,max)); |
---|
| 180 | assert(min<=-50&&max>=50); |
---|
| 181 | assert(t1.CalculateExtent(kZAxis,limit,origin,min,max)); |
---|
| 182 | assert(min<=-50&&max>=50); |
---|
| 183 | |
---|
| 184 | G4ThreeVector pmxmymz(-100,-110,-120); |
---|
| 185 | G4AffineTransform tPosOnly(pmxmymz); |
---|
| 186 | assert(t1.CalculateExtent(kXAxis,limit,tPosOnly,min,max)); |
---|
| 187 | assert(min<=-150&&max>=-50); |
---|
| 188 | assert(t1.CalculateExtent(kYAxis,limit,tPosOnly,min,max)); |
---|
| 189 | assert(min<=-160&&max>=-60); |
---|
| 190 | assert(t1.CalculateExtent(kZAxis,limit,tPosOnly,min,max)); |
---|
| 191 | assert(min<=-170&&max>=-70); |
---|
| 192 | |
---|
| 193 | G4RotationMatrix r90Z; |
---|
| 194 | r90Z.rotateZ(halfpi); |
---|
| 195 | G4AffineTransform tRotZ(r90Z,pzero); |
---|
| 196 | assert(t1.CalculateExtent(kXAxis,limit,tRotZ,min,max)); |
---|
| 197 | assert(min<=-50&&max>=50); |
---|
| 198 | assert(t1.CalculateExtent(kYAxis,limit,tRotZ,min,max)); |
---|
| 199 | assert(min<=-50&&max>=50); |
---|
| 200 | assert(t1.CalculateExtent(kZAxis,limit,tRotZ,min,max)); |
---|
| 201 | assert(min<=-50&&max>=50); |
---|
| 202 | |
---|
| 203 | // Check that clipped away |
---|
| 204 | G4VoxelLimits xClip; |
---|
| 205 | xClip.AddLimit(kXAxis,-100,-60); |
---|
| 206 | assert(!t1.CalculateExtent(kXAxis,xClip,origin,min,max)); |
---|
| 207 | |
---|
| 208 | // Assert clipped to volume |
---|
| 209 | G4VoxelLimits allClip; |
---|
| 210 | allClip.AddLimit(kXAxis,-5,+5); |
---|
| 211 | allClip.AddLimit(kYAxis,-5,+5); |
---|
| 212 | allClip.AddLimit(kZAxis,-5,+5); |
---|
| 213 | G4RotationMatrix genRot; |
---|
| 214 | genRot.rotateX(pi/6); |
---|
| 215 | genRot.rotateY(pi/6); |
---|
| 216 | genRot.rotateZ(pi/6); |
---|
| 217 | G4AffineTransform tGen(genRot,vx); |
---|
| 218 | assert(t1.CalculateExtent(kXAxis,allClip,tGen,min,max)); |
---|
| 219 | assert(min<=-5&&max>=5); |
---|
| 220 | assert(t1.CalculateExtent(kYAxis,allClip,tGen,min,max)); |
---|
| 221 | assert(min<=-5&&max>=5); |
---|
| 222 | assert(t1.CalculateExtent(kZAxis,allClip,tGen,min,max)); |
---|
| 223 | assert(min<=-5&&max>=5); |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | // Test z clipping ok |
---|
| 227 | for (G4double zTest=-100;zTest<100;zTest+=9) |
---|
| 228 | { |
---|
| 229 | G4VoxelLimits zTestClip; |
---|
| 230 | zTestClip.AddLimit(kZAxis,-kInfinity,zTest); |
---|
| 231 | if (zTest<-50) |
---|
| 232 | { |
---|
| 233 | assert(!t1.CalculateExtent(kZAxis,zTestClip,origin,min,max)); |
---|
| 234 | } |
---|
| 235 | else |
---|
| 236 | { |
---|
| 237 | assert(t1.CalculateExtent(kZAxis,zTestClip,origin,min,max)); |
---|
| 238 | G4double testMin=-50; |
---|
| 239 | G4double testMax=(zTest<50) ? zTest : 50; |
---|
| 240 | assert (ApproxEqual(min,testMin) |
---|
| 241 | &&ApproxEqual(max,testMax)); |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | // Test y clipping ok |
---|
| 246 | |
---|
| 247 | // Hype end Outer Radius -> clipping scale |
---|
| 248 | double eOR=std::sqrt(std::tan(yesStereo)*std::tan(yesStereo)*len*len+oR1*oR1); |
---|
| 249 | |
---|
| 250 | for (G4double xTest=-100;xTest<100;xTest+=9) |
---|
| 251 | { |
---|
| 252 | G4VoxelLimits xTestClip; |
---|
| 253 | xTestClip.AddLimit(kXAxis,-kInfinity,xTest); |
---|
| 254 | if (xTest<-eOR) |
---|
| 255 | { |
---|
| 256 | assert(!t1.CalculateExtent(kYAxis,xTestClip,origin,min,max)); |
---|
| 257 | } |
---|
| 258 | else |
---|
| 259 | { |
---|
| 260 | assert(t1.CalculateExtent(kYAxis,xTestClip,origin,min,max)); |
---|
| 261 | // Calc max y coordinate |
---|
| 262 | G4double testMax=(xTest<0) ? std::sqrt(eOR*eOR-xTest*xTest) : eOR; |
---|
| 263 | assert ((min < -testMax) && (max > testMax)); |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | // Test x clipping ok |
---|
| 268 | for (G4double yTest=-100;yTest<100;yTest+=9) |
---|
| 269 | { |
---|
| 270 | G4VoxelLimits yTestClip; |
---|
| 271 | yTestClip.AddLimit(kYAxis,-kInfinity,yTest); |
---|
| 272 | if (yTest<-eOR) |
---|
| 273 | { |
---|
| 274 | assert(!t1.CalculateExtent(kXAxis,yTestClip,origin,min,max)); |
---|
| 275 | } |
---|
| 276 | else |
---|
| 277 | { |
---|
| 278 | assert(t1.CalculateExtent(kXAxis,yTestClip,origin,min,max)); |
---|
| 279 | // Calc max y coordinate |
---|
| 280 | G4double testMax=(yTest<0) ? std::sqrt(eOR*eOR-yTest*yTest) : eOR; |
---|
| 281 | assert ((min < -testMax) && (max > testMax)); |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | |
---|
| 286 | return true; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | int main() |
---|
| 290 | { |
---|
| 291 | #ifdef NDEBUG |
---|
| 292 | G4Exception("FAIL: *** Assertions must be compiled in! ***"); |
---|
| 293 | #endif |
---|
| 294 | assert(testG4Hype()); |
---|
| 295 | return 0; |
---|
| 296 | } |
---|
| 297 | |
---|