[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: testSolidComparisons.cc,v 1.6 2007/05/18 11:06:34 gcosmo Exp $ |
---|
[1347] | 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $ |
---|
[1316] | 29 | // |
---|
| 30 | // |
---|
| 31 | // -------------------------------------------------------------- |
---|
| 32 | // |
---|
| 33 | // Test for comparison of solids of different type but similar topology |
---|
| 34 | // Returns 0 if there no inconsistencies in the answers provided by the |
---|
| 35 | // compared solids. |
---|
| 36 | // |
---|
| 37 | // Author: Dionysios Anninos |
---|
| 38 | // |
---|
| 39 | // -------------------------------------------------------------- |
---|
| 40 | #include <assert.h> |
---|
| 41 | #include <cmath> |
---|
| 42 | |
---|
| 43 | #include "globals.hh" |
---|
| 44 | #include "geomdefs.hh" |
---|
| 45 | #include "G4GeometryTolerance.hh" |
---|
| 46 | |
---|
| 47 | #include "G4ThreeVector.hh" |
---|
| 48 | #include "G4TwoVector.hh" |
---|
| 49 | |
---|
| 50 | #include "G4Tubs.hh" |
---|
| 51 | #include "G4Ellipsoid.hh" |
---|
| 52 | #include "G4EllipticalTube.hh" |
---|
| 53 | #include "G4Orb.hh" |
---|
| 54 | #include "G4Sphere.hh" |
---|
| 55 | #include "G4Box.hh" |
---|
| 56 | #include "G4Trap.hh" |
---|
| 57 | #include "G4ExtrudedSolid.hh" |
---|
| 58 | |
---|
| 59 | #include "Randomize.hh" |
---|
| 60 | |
---|
| 61 | #include "G4RotationMatrix.hh" |
---|
| 62 | #include "G4AffineTransform.hh" |
---|
| 63 | #include "G4VoxelLimits.hh" |
---|
| 64 | |
---|
| 65 | using namespace CLHEP; |
---|
| 66 | |
---|
| 67 | void logErrors(G4double x, G4double y, G4double z, |
---|
| 68 | G4double vx, G4double vy, G4double vz, G4double dist) |
---|
| 69 | { |
---|
| 70 | G4cout <<"The point ("<<x<<","<<y<<","<<z<<")"<<G4endl |
---|
| 71 | <<"In the direction ("<<vx<<","<<vy<<","<<vz<<")"<<G4endl |
---|
| 72 | <<"Gives a difference of "<<dist<<"cm !"<<G4endl; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | G4bool compareEllipsoidtoOrb(G4int N) |
---|
| 76 | { |
---|
| 77 | |
---|
| 78 | G4bool what = true; |
---|
| 79 | G4int i=0, n=0; |
---|
| 80 | G4ThreeVector pin, pout, dir; |
---|
| 81 | G4double xin, yin, zin, xout, yout, zout, dist1, dist2, dist; |
---|
| 82 | |
---|
| 83 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
| 84 | |
---|
| 85 | // construct the ellipsoid and Orb with the same dimensions |
---|
| 86 | |
---|
| 87 | G4Ellipsoid t1("Solid Ellipsoid #1", |
---|
| 88 | 20*cm, // xSemiAxis |
---|
| 89 | 20*cm, // ySemiAxis |
---|
| 90 | 20*cm) ; // zSemiAxis |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | G4Orb t2("Solid Orb #1", 20*cm) ; |
---|
| 94 | |
---|
| 95 | for(i=0; i<N; i++) |
---|
| 96 | { |
---|
| 97 | xout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 98 | yout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 99 | zout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 100 | |
---|
| 101 | xin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 102 | yin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 103 | zin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 104 | |
---|
| 105 | pin = G4ThreeVector(xin, yin, zin ); |
---|
| 106 | pout = G4ThreeVector(xout, yout, zout); |
---|
| 107 | |
---|
| 108 | dir = pin - pout; |
---|
| 109 | dir /= dir.mag(); |
---|
| 110 | |
---|
| 111 | dist1 = t1.DistanceToIn(pout,dir) ; |
---|
| 112 | dist2 = t2.DistanceToIn(pout,dir) ; |
---|
| 113 | |
---|
| 114 | if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 115 | { |
---|
| 116 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 117 | { |
---|
| 118 | what = false; |
---|
| 119 | dist = std::fabs(dist1 - dist2); |
---|
| 120 | logErrors( pout.x(), pout.y(), pout.z(), |
---|
| 121 | dir.x() , dir.y() , dir.z() , dist); |
---|
| 122 | n++; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | dist1 = t1.DistanceToOut(pin,dir); |
---|
| 127 | dist2 = t2.DistanceToOut(pin,dir); |
---|
| 128 | |
---|
| 129 | if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 130 | { |
---|
| 131 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 132 | { |
---|
| 133 | what = false; |
---|
| 134 | dist = std::fabs(dist1 - dist2); |
---|
| 135 | logErrors( pin.x(), pin.y(), pin.z(), |
---|
| 136 | dir.x(), dir.y(), dir.z(), dist); |
---|
| 137 | n++; |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | G4cout <<"The number of inconsistencies when comparing Ellipsoid to Orb were: "<<n<<"."<<G4endl; |
---|
| 143 | return what; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | G4bool compareEllipsoidtoSphere(G4int N) |
---|
| 147 | { |
---|
| 148 | |
---|
| 149 | G4bool what = true; |
---|
| 150 | G4int i=0,n=0; |
---|
| 151 | G4ThreeVector pin, pout, dir; |
---|
| 152 | G4double xin, yin, zin, xout, yout, zout, dist1, dist2, dist; |
---|
| 153 | |
---|
| 154 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
| 155 | |
---|
| 156 | // construct the ellipsoid and sphere with the same dimensions |
---|
| 157 | |
---|
| 158 | G4Ellipsoid t1("Solid Ellipsoid #1", |
---|
| 159 | 20*cm, // xSemiAxis |
---|
| 160 | 20*cm, // ySemiAxis |
---|
| 161 | 20*cm) ; // zSemiAxis |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | G4Sphere t2("Solid Sphere #1", |
---|
| 165 | 0*cm, |
---|
| 166 | 20*cm, |
---|
| 167 | 0*rad, 2*pi*rad, |
---|
| 168 | 0*rad, 2*pi*rad) ; |
---|
| 169 | |
---|
| 170 | for(i=0; i<N; i++) |
---|
| 171 | { |
---|
| 172 | xout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 173 | yout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 174 | zout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 175 | |
---|
| 176 | xin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 177 | yin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 178 | zin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 179 | |
---|
| 180 | pin = G4ThreeVector(xin, yin, zin); |
---|
| 181 | pout = G4ThreeVector(xout, yout, zout); |
---|
| 182 | |
---|
| 183 | dir = pin - pout; |
---|
| 184 | dir /= dir.mag(); |
---|
| 185 | |
---|
| 186 | dist1 = t1.DistanceToIn(pout,dir) ; |
---|
| 187 | dist2 = t2.DistanceToIn(pout,dir) ; |
---|
| 188 | |
---|
| 189 | if(dist1 != kInfinity && dist2 != kInfinity) |
---|
| 190 | { |
---|
| 191 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 192 | { |
---|
| 193 | what = false; |
---|
| 194 | dist = std::fabs(dist1 - dist2); |
---|
| 195 | logErrors(pout.x(), pout.y(), pout.z(), |
---|
| 196 | dir.x() , dir.y() , dir.z() , dist); |
---|
| 197 | n++; |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | dist1 = t1.DistanceToOut(pin,dir); |
---|
| 202 | dist2 = t2.DistanceToOut(pin,dir); |
---|
| 203 | |
---|
| 204 | if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 205 | { |
---|
| 206 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 207 | { |
---|
| 208 | what = false; |
---|
| 209 | dist = std::fabs(dist1 - dist2); |
---|
| 210 | logErrors( pin.x(), pin.y(), pin.z(), |
---|
| 211 | dir.x(), dir.y(), dir.z(), dist); |
---|
| 212 | n++; |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | G4cout <<"The number of inconsistencies when comparing Ellipsoid to Sphere were: "<<n<<"."<<G4endl; |
---|
| 218 | return what; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | G4bool compareEllipticalTubetoTubs(G4int N) |
---|
| 222 | { |
---|
| 223 | |
---|
| 224 | G4bool what = true; |
---|
| 225 | G4int i=0,n=0; |
---|
| 226 | G4ThreeVector pin, pout, dir; |
---|
| 227 | G4double xin, yin, zin, xout, yout, zout, dist1, dist2,dist; |
---|
| 228 | |
---|
| 229 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
| 230 | |
---|
| 231 | // construct the tube and elliptical tube with the same dimensions |
---|
| 232 | |
---|
| 233 | G4EllipticalTube t1("Solid EllipticalTube #1", |
---|
| 234 | 20*cm, // xSemiAxis |
---|
| 235 | 20*cm, // ySemiAxis |
---|
| 236 | 20*cm) ; // zHeight |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | G4Tubs t2("Solid Tubs #1", |
---|
| 240 | 0*cm, |
---|
| 241 | 20*cm, |
---|
| 242 | 20*cm, |
---|
| 243 | 0., twopi); |
---|
| 244 | |
---|
| 245 | for(i=0; i<N; i++) |
---|
| 246 | { |
---|
| 247 | xout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 248 | yout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 249 | zout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 250 | |
---|
| 251 | xin = RandFlat::shoot(-19.0*cm,19.0*cm); |
---|
| 252 | yin = RandFlat::shoot(-1.0*cm , 1.0*cm)*std::sqrt(361.*cm*cm-sqr(xin)); |
---|
| 253 | zin = RandFlat::shoot(-19.0*cm,19.0*cm); |
---|
| 254 | |
---|
| 255 | pin = G4ThreeVector(xin, yin, zin); |
---|
| 256 | pout = G4ThreeVector(xout, yout, zout); |
---|
| 257 | |
---|
| 258 | dir = pin - pout; |
---|
| 259 | dir /= dir.mag(); |
---|
| 260 | |
---|
| 261 | dist1 = t1.DistanceToIn(pout,dir) ; |
---|
| 262 | dist2 = t2.DistanceToIn(pout,dir) ; |
---|
| 263 | |
---|
| 264 | if(dist1 != kInfinity && dist2 != kInfinity) |
---|
| 265 | { |
---|
| 266 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 267 | { |
---|
| 268 | what = false; |
---|
| 269 | dist = std::fabs(dist1 - dist2); |
---|
| 270 | logErrors(pout.x(), pout.y(), pout.z(), |
---|
| 271 | dir.x() , dir.y() , dir.z() , dist); |
---|
| 272 | n++; |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | // dist1 = t1.DistanceToOut(pin,dir); |
---|
| 277 | // dist2 = t2.DistanceToOut(pin,dir); |
---|
| 278 | |
---|
| 279 | // if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 280 | // { |
---|
| 281 | // if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 282 | // { |
---|
| 283 | // what = false; |
---|
| 284 | // dist = std::fabs(dist1 - dist2); |
---|
| 285 | // logErrors(pin.x(), pin.y(), pin.z(), |
---|
| 286 | // dir.x(), dir.y(), dir.z(), dist); |
---|
| 287 | // n++; |
---|
| 288 | // } |
---|
| 289 | // } |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | G4cout <<"The number of inconsistencies when comparing EllipticalTube to Tubs were: "<<n<<"."<<G4endl; |
---|
| 293 | return what; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | G4bool compareBoxtoTrap(G4int N) |
---|
| 297 | { |
---|
| 298 | |
---|
| 299 | G4bool what = true; |
---|
| 300 | G4int i=0,n=0; |
---|
| 301 | G4ThreeVector pin, pout, dir; |
---|
| 302 | G4double xin, yin, zin, xout, yout, zout, dist1, dist2, dist; |
---|
| 303 | |
---|
| 304 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
| 305 | |
---|
| 306 | G4ThreeVector pt[8] = { G4ThreeVector(-20*cm,-20*cm,-20*cm ), |
---|
| 307 | G4ThreeVector( 20*cm,-20*cm,-20*cm ), |
---|
| 308 | G4ThreeVector(-20*cm, 20*cm,-20*cm ), |
---|
| 309 | G4ThreeVector( 20*cm, 20*cm,-20*cm ), |
---|
| 310 | G4ThreeVector(-20*cm,-20*cm, 20*cm ), |
---|
| 311 | G4ThreeVector( 20*cm,-20*cm, 20*cm ), |
---|
| 312 | G4ThreeVector(-20*cm, 20*cm, 20*cm ), |
---|
| 313 | G4ThreeVector( 20*cm, 20*cm, 20*cm ) }; |
---|
| 314 | |
---|
| 315 | // construct the Trap and Box with the same dimensions |
---|
| 316 | |
---|
| 317 | G4Trap t1("Solid Trap #1", |
---|
| 318 | pt) ; |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | G4Box t2("Solid Box #1", |
---|
| 322 | 20*cm, |
---|
| 323 | 20*cm, |
---|
| 324 | 20*cm); |
---|
| 325 | |
---|
| 326 | for(i=0; i<N; i++) |
---|
| 327 | { |
---|
| 328 | xout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 329 | yout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 330 | zout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 331 | |
---|
| 332 | xin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 333 | yin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 334 | zin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 335 | |
---|
| 336 | pin = G4ThreeVector(xin, yin, zin); |
---|
| 337 | pout = G4ThreeVector(xout, yout, zout); |
---|
| 338 | |
---|
| 339 | dir = pin - pout; |
---|
| 340 | dir /= dir.mag(); |
---|
| 341 | |
---|
| 342 | dist1 = t1.DistanceToIn(pout,dir) ; |
---|
| 343 | dist2 = t2.DistanceToIn(pout,dir) ; |
---|
| 344 | |
---|
| 345 | if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 346 | { |
---|
| 347 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 348 | { |
---|
| 349 | what = false; |
---|
| 350 | dist = std::fabs(dist1 - dist2); |
---|
| 351 | logErrors(pout.x(),pout.y(),pout.z(), |
---|
| 352 | dir.x(), dir.y(), dir.z(), dist); |
---|
| 353 | n++; |
---|
| 354 | } |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | dist1 = t1.DistanceToOut(pin,dir); |
---|
| 358 | dist2 = t2.DistanceToOut(pin,dir); |
---|
| 359 | |
---|
| 360 | if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 361 | { |
---|
| 362 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 363 | { |
---|
| 364 | what = false; |
---|
| 365 | dist = std::fabs(dist1 - dist2); |
---|
| 366 | logErrors(pin.x(), pin.y(), pin.z(), |
---|
| 367 | dir.x(), dir.y(), dir.z(), dist); |
---|
| 368 | n++; |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | G4cout <<"The number of inconsistencies when comparing Box to Trap were: "<<n<<"."<<G4endl; |
---|
| 374 | return what; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | G4bool compareSpheretoOrb(G4int N) |
---|
| 378 | { |
---|
| 379 | |
---|
| 380 | G4bool what = true; |
---|
| 381 | G4int i=0,n=0; |
---|
| 382 | G4ThreeVector pin, pout, dir; |
---|
| 383 | G4double xin, yin, zin, xout, yout, zout, dist1, dist2,dist; |
---|
| 384 | |
---|
| 385 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
| 386 | |
---|
| 387 | // construct the ellipsoid and sphere with the same dimensions |
---|
| 388 | |
---|
| 389 | G4Orb t1("Solid Orb #1", |
---|
| 390 | 20*cm) ; |
---|
| 391 | |
---|
| 392 | G4Sphere t2("Solid Sphere #1", |
---|
| 393 | 0*cm, |
---|
| 394 | 20*cm, |
---|
| 395 | 0*deg, 2*pi*rad, |
---|
| 396 | 0*rad, 2*pi*rad) ; |
---|
| 397 | |
---|
| 398 | for(i=0; i<N; i++) |
---|
| 399 | { |
---|
| 400 | xout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 401 | yout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 402 | zout = RandFlat::shoot(25.0*cm,300.0*cm); |
---|
| 403 | |
---|
| 404 | xin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 405 | yin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 406 | zin = RandFlat::shoot(-10.0*cm,10.0*cm); |
---|
| 407 | |
---|
| 408 | pin = G4ThreeVector(xin, yin, zin); |
---|
| 409 | pout = G4ThreeVector(xout, yout, zout); |
---|
| 410 | |
---|
| 411 | dir = pin - pout; |
---|
| 412 | dir /= dir.mag(); |
---|
| 413 | |
---|
| 414 | dist1 = t1.DistanceToIn(pout,dir) ; |
---|
| 415 | dist2 = t2.DistanceToIn(pout,dir) ; |
---|
| 416 | |
---|
| 417 | if(dist1 != kInfinity && dist2 != kInfinity) |
---|
| 418 | { |
---|
| 419 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 420 | { |
---|
| 421 | what = false; |
---|
| 422 | dist = std::fabs(dist1 - dist2); |
---|
| 423 | logErrors(pout.x(),pout.y(), pout.z(), |
---|
| 424 | dir.x() ,dir.y() , dir.z() ,dist); |
---|
| 425 | n++; |
---|
| 426 | } |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | dist1 = t1.DistanceToOut(pin,dir); |
---|
| 430 | dist2 = t2.DistanceToOut(pin,dir); |
---|
| 431 | |
---|
| 432 | if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 433 | { |
---|
| 434 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 435 | { |
---|
| 436 | what = false; |
---|
| 437 | dist = std::fabs(dist1 - dist2); |
---|
| 438 | logErrors(pin.x(), pin.y(), pin.z(), |
---|
| 439 | dir.x(), dir.y(), dir.z(), dist); |
---|
| 440 | n++; |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | } |
---|
| 444 | G4cout <<"The number of inconsistencies when comparing Sphere to Orb were: "<<n<<"."<<G4endl; |
---|
| 445 | return what; |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | G4bool compareBoxtoExtruded(G4int N) |
---|
| 449 | { |
---|
| 450 | |
---|
| 451 | G4bool what = true; |
---|
| 452 | G4int i=0,n=0; |
---|
| 453 | G4ThreeVector pin, pout, dir; |
---|
| 454 | G4double xin, yin, zin, xout, yout, zout, dist1, dist2, dist; |
---|
| 455 | |
---|
| 456 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
| 457 | |
---|
| 458 | // construct the Extruded-Solid and Box with the same dimensions |
---|
| 459 | |
---|
| 460 | std::vector<G4TwoVector> polygon; |
---|
| 461 | polygon.push_back(G4TwoVector(-1.0*cm,-0.5*cm)); |
---|
| 462 | polygon.push_back(G4TwoVector(-1.0*cm, 0.5*cm)); |
---|
| 463 | polygon.push_back(G4TwoVector( 1.0*cm, 0.5*cm)); |
---|
| 464 | polygon.push_back(G4TwoVector( 1.0*cm,-0.5*cm)); |
---|
| 465 | |
---|
| 466 | G4ExtrudedSolid t1("Solid Xtru #1", polygon, 3.0*cm, |
---|
| 467 | G4TwoVector(), 1.0, G4TwoVector(), 1.0); |
---|
| 468 | |
---|
| 469 | G4Box t2("Solid Box #2", |
---|
| 470 | 1.0*cm, |
---|
| 471 | 0.5*cm, |
---|
| 472 | 3.0*cm); |
---|
| 473 | |
---|
| 474 | for(i=0; i<N; i++) |
---|
| 475 | { |
---|
| 476 | xout = RandFlat::shoot(5.0*cm,20.0*cm); |
---|
| 477 | yout = RandFlat::shoot(5.0*cm,20.0*cm); |
---|
| 478 | zout = RandFlat::shoot(5.0*cm,20.0*cm); |
---|
| 479 | |
---|
| 480 | xin = RandFlat::shoot(-0.9*cm,0.9*cm); |
---|
| 481 | yin = RandFlat::shoot(-0.4*cm,0.4*cm); |
---|
| 482 | zin = RandFlat::shoot(-2.9*cm,2.9*cm); |
---|
| 483 | |
---|
| 484 | pin = G4ThreeVector(xin, yin, zin); |
---|
| 485 | pout = G4ThreeVector(xout, yout, zout); |
---|
| 486 | |
---|
| 487 | dir = pin - pout; |
---|
| 488 | dir /= dir.mag(); |
---|
| 489 | |
---|
| 490 | dist1 = t1.DistanceToIn(pout,dir) ; |
---|
| 491 | dist2 = t2.DistanceToIn(pout,dir) ; |
---|
| 492 | |
---|
| 493 | if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 494 | { |
---|
| 495 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 496 | { |
---|
| 497 | what = false; |
---|
| 498 | dist = std::fabs(dist1 - dist2); |
---|
| 499 | logErrors(pout.x(),pout.y(),pout.z(), |
---|
| 500 | dir.x(), dir.y(), dir.z(), dist); |
---|
| 501 | n++; |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | dist1 = t1.DistanceToOut(pin,dir); |
---|
| 506 | dist2 = t2.DistanceToOut(pin,dir); |
---|
| 507 | |
---|
| 508 | if(dist1 != kInfinity && dist2 !=kInfinity) |
---|
| 509 | { |
---|
| 510 | if(std::fabs(dist1 - dist2) >= 5.*kCarTolerance) |
---|
| 511 | { |
---|
| 512 | what = false; |
---|
| 513 | dist = std::fabs(dist1 - dist2); |
---|
| 514 | logErrors(pin.x(), pin.y(), pin.z(), |
---|
| 515 | dir.x(), dir.y(), dir.z(), dist); |
---|
| 516 | n++; |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | G4cout << "The number of inconsistencies when comparing Box to Extruded-Solid were: " |
---|
| 522 | << n << "." << G4endl; |
---|
| 523 | return what; |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | // other comparisons can be, trap with polyhedra, cube with polyhedra, tet with polyhedra |
---|
| 527 | |
---|
| 528 | int main() |
---|
| 529 | { |
---|
| 530 | |
---|
| 531 | G4bool what; |
---|
| 532 | |
---|
| 533 | what = compareEllipsoidtoOrb(1000); |
---|
| 534 | what = compareEllipticalTubetoTubs(1000); |
---|
| 535 | what = compareEllipsoidtoSphere(1000); |
---|
| 536 | what = compareBoxtoTrap(1000); |
---|
| 537 | what = compareSpheretoOrb(1000); |
---|
| 538 | what = compareBoxtoExtruded(1000); |
---|
| 539 | |
---|
| 540 | |
---|
| 541 | return 0; |
---|
| 542 | } |
---|