| 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 | // Test File for tracking functions on a solid surface
|
|---|
| 28 | //
|
|---|
| 29 | // o Basic asserts on each function +
|
|---|
| 30 | // awkward cases for tracking / geom algorithms
|
|---|
| 31 | //
|
|---|
| 32 | // o Add tests on dicovering bugs in G4Sphere.cc...
|
|---|
| 33 | //
|
|---|
| 34 | // History:
|
|---|
| 35 | //
|
|---|
| 36 | // 28.03.06 V.Grichine orb modifications for accuracy 2nd algorithms
|
|---|
| 37 | //
|
|---|
| 38 | // 16.07.05 V.Grichine creation for box, tubs, cons, sphere, orb, torus
|
|---|
| 39 | // based on testSurfaceInOut.cc
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | #include "G4ios.hh"
|
|---|
| 44 | #include <assert.h>
|
|---|
| 45 | #include <cmath>
|
|---|
| 46 | #include "globals.hh"
|
|---|
| 47 | #include "geomdefs.hh"
|
|---|
| 48 | #include "Randomize.hh"
|
|---|
| 49 |
|
|---|
| 50 | #include "ApproxEqual.hh"
|
|---|
| 51 |
|
|---|
| 52 | #include "G4ThreeVector.hh"
|
|---|
| 53 | #include "G4RotationMatrix.hh"
|
|---|
| 54 | #include "G4AffineTransform.hh"
|
|---|
| 55 | #include "G4VoxelLimits.hh"
|
|---|
| 56 | #include "G4GeometryTolerance.hh"
|
|---|
| 57 |
|
|---|
| 58 | #include "G4Box.hh"
|
|---|
| 59 | #include "G4Orb.hh"
|
|---|
| 60 | #include "G4Tubs.hh"
|
|---|
| 61 | #include "G4Sphere.hh"
|
|---|
| 62 | #include "G4Cons.hh"
|
|---|
| 63 | #include "G4Hype.hh"
|
|---|
| 64 | #include "G4Para.hh"
|
|---|
| 65 | #include "G4Torus.hh"
|
|---|
| 66 | #include "G4Trd.hh"
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | ///////////////////////////////////////////////////////////////////////////
|
|---|
| 71 | //
|
|---|
| 72 | //
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | //const G4double kApproxEqualTolerance = kCarTolerance;
|
|---|
| 76 |
|
|---|
| 77 | // Return true if the double check is approximately equal to target
|
|---|
| 78 | //
|
|---|
| 79 | // Process:
|
|---|
| 80 | //
|
|---|
| 81 | // Return true is difference < kApproxEqualTolerance
|
|---|
| 82 |
|
|---|
| 83 | //G4bool ApproxEqual(const G4double check,const G4double target)
|
|---|
| 84 | //{
|
|---|
| 85 | // return (std::fabs(check-target)<kApproxEqualTolerance) ? true : false ;
|
|---|
| 86 | //}
|
|---|
| 87 |
|
|---|
| 88 | // Return true if the 3vector check is approximately equal to target
|
|---|
| 89 | //G4bool ApproxEqual(const G4ThreeVector& check, const G4ThreeVector& target)
|
|---|
| 90 | //{
|
|---|
| 91 | // return (ApproxEqual(check.x(),target.x())&&
|
|---|
| 92 | // ApproxEqual(check.y(),target.y())&&
|
|---|
| 93 | // ApproxEqual(check.z(),target.z()))? true : false;
|
|---|
| 94 | //}
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | ///////////////////////////////////////////////////////////////////
|
|---|
| 100 | //
|
|---|
| 101 | // Dave's auxiliary function
|
|---|
| 102 |
|
|---|
| 103 | const G4String OutputInside(const EInside a)
|
|---|
| 104 | {
|
|---|
| 105 | switch(a)
|
|---|
| 106 | {
|
|---|
| 107 | case kInside: return "Inside";
|
|---|
| 108 | case kOutside: return "Outside";
|
|---|
| 109 | case kSurface: return "Surface";
|
|---|
| 110 | }
|
|---|
| 111 | return "????";
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 116 | //
|
|---|
| 117 | // Random unit direction vector
|
|---|
| 118 |
|
|---|
| 119 | G4ThreeVector GetRandomUnitVector()
|
|---|
| 120 | {
|
|---|
| 121 | G4double cosTheta, sinTheta, phi, vx, vy, vz;
|
|---|
| 122 |
|
|---|
| 123 | cosTheta = -1. + 2.*G4UniformRand();
|
|---|
| 124 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 125 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 126 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 127 |
|
|---|
| 128 | phi = 2*pi*G4UniformRand();
|
|---|
| 129 |
|
|---|
| 130 | vx = sinTheta*std::cos(phi);
|
|---|
| 131 | vy = sinTheta*std::sin(phi);
|
|---|
| 132 | vz = cosTheta;
|
|---|
| 133 |
|
|---|
| 134 | return G4ThreeVector(vx,vy,vz);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 138 | //
|
|---|
| 139 | // Random vector around box surface
|
|---|
| 140 |
|
|---|
| 141 | G4ThreeVector GetVectorAroundBox( G4Box& box )
|
|---|
| 142 | {
|
|---|
| 143 | G4double a, b, c, px, py, pz;
|
|---|
| 144 | G4double part = std::pow(2,1./3.);
|
|---|
| 145 |
|
|---|
| 146 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
|---|
| 147 |
|
|---|
| 148 | a = part*box.GetXHalfLength();
|
|---|
| 149 | b = part*box.GetYHalfLength();
|
|---|
| 150 | c = part*box.GetZHalfLength();
|
|---|
| 151 |
|
|---|
| 152 | px = -a - 0.5*kCarTolerance + (2.*a + kCarTolerance)*G4UniformRand();
|
|---|
| 153 | py = -b - 0.5*kCarTolerance + (2.*b + kCarTolerance)*G4UniformRand();
|
|---|
| 154 | pz = -c - 0.5*kCarTolerance + (2.*c + kCarTolerance)*G4UniformRand();
|
|---|
| 155 |
|
|---|
| 156 | return G4ThreeVector(px,py,pz);
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 160 | //
|
|---|
| 161 | // Random vector on orb surface
|
|---|
| 162 |
|
|---|
| 163 | G4ThreeVector GetVectorOnOrb(G4Orb& orb, G4ThreeVector& norm)
|
|---|
| 164 | {
|
|---|
| 165 | G4double cosTheta, sinTheta, phi, radius, px, py, pz;
|
|---|
| 166 |
|
|---|
| 167 | radius = orb.GetRadius();
|
|---|
| 168 | // radius += -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 169 |
|
|---|
| 170 | cosTheta = -1. + 2.*G4UniformRand();
|
|---|
| 171 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 172 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 173 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 174 |
|
|---|
| 175 | phi = 2*pi*G4UniformRand();
|
|---|
| 176 |
|
|---|
| 177 | px = radius*sinTheta*std::cos(phi);
|
|---|
| 178 | py = radius*sinTheta*std::sin(phi);
|
|---|
| 179 | pz = radius*cosTheta;
|
|---|
| 180 |
|
|---|
| 181 | norm = G4ThreeVector( sinTheta*std::cos(phi), sinTheta*std::sin(phi), cosTheta);
|
|---|
| 182 |
|
|---|
| 183 | return G4ThreeVector(px,py,pz);
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 187 | //
|
|---|
| 188 | // Random vector around orb surface
|
|---|
| 189 |
|
|---|
| 190 | G4ThreeVector GetVectorAroundOrb(G4Orb& orb)
|
|---|
| 191 | {
|
|---|
| 192 | G4double cosTheta, sinTheta, phi, radius, px, py, pz;
|
|---|
| 193 |
|
|---|
| 194 | radius = 4.*orb.GetRadius(); // 1.26
|
|---|
| 195 | radius *= G4UniformRand();
|
|---|
| 196 |
|
|---|
| 197 | cosTheta = -1. + 2.*G4UniformRand();
|
|---|
| 198 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 199 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 200 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 201 |
|
|---|
| 202 | phi = 2*pi*G4UniformRand();
|
|---|
| 203 |
|
|---|
| 204 | px = radius*sinTheta*std::cos(phi);
|
|---|
| 205 | py = radius*sinTheta*std::sin(phi);
|
|---|
| 206 | pz = radius*cosTheta;
|
|---|
| 207 |
|
|---|
| 208 | return G4ThreeVector(px,py,pz);
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 212 | //
|
|---|
| 213 | // Random vector on sphere surface
|
|---|
| 214 |
|
|---|
| 215 | G4ThreeVector GetVectorOnSphere(G4Sphere& sphere)
|
|---|
| 216 | {
|
|---|
| 217 | G4double cosTheta, sinTheta, phi, radius, px, py, pz;
|
|---|
| 218 | G4double part = 1./6.;
|
|---|
| 219 | G4double rand = G4UniformRand();
|
|---|
| 220 |
|
|---|
| 221 | G4double pRmin = sphere.GetInsideRadius();
|
|---|
| 222 | G4double pRmax = sphere.GetOuterRadius();
|
|---|
| 223 | G4double phi1 = sphere.GetStartPhiAngle();
|
|---|
| 224 | G4double phi2 = phi1 + sphere.GetDeltaPhiAngle();
|
|---|
| 225 | G4double theta1 = sphere.GetStartThetaAngle();
|
|---|
| 226 | G4double theta2 = theta1 + sphere.GetDeltaThetaAngle();
|
|---|
| 227 |
|
|---|
| 228 | G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
|---|
| 229 | G4double kAngTolerance = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
|
|---|
| 230 |
|
|---|
| 231 | if ( rand < part ) // Rmax
|
|---|
| 232 | {
|
|---|
| 233 | radius = pRmax -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 234 |
|
|---|
| 235 | cosTheta = std::cos(theta2+0.5*kAngTolerance) +
|
|---|
| 236 | (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
|
|---|
| 237 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 238 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 239 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 240 |
|
|---|
| 241 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 242 | }
|
|---|
| 243 | else if ( rand < 2*part ) // Rmin
|
|---|
| 244 | {
|
|---|
| 245 | radius = pRmin -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 246 |
|
|---|
| 247 | cosTheta = std::cos(theta2+0.5*kAngTolerance) +
|
|---|
| 248 | (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
|
|---|
| 249 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 250 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 251 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 252 |
|
|---|
| 253 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 254 | }
|
|---|
| 255 | else if ( rand < 3*part ) // phi1
|
|---|
| 256 | {
|
|---|
| 257 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 | cosTheta = std::cos(theta2+0.5*kAngTolerance) +
|
|---|
| 261 | (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
|
|---|
| 262 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 263 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 264 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 265 |
|
|---|
| 266 | phi = phi1 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 267 | }
|
|---|
| 268 | else if ( rand < 4*part ) // phi2
|
|---|
| 269 | {
|
|---|
| 270 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 | cosTheta = std::cos(theta2+0.5*kAngTolerance) +
|
|---|
| 274 | (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
|
|---|
| 275 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 276 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 277 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 278 |
|
|---|
| 279 | phi = phi2 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 280 | }
|
|---|
| 281 | else if ( rand < 5*part ) // theta1
|
|---|
| 282 | {
|
|---|
| 283 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 | cosTheta = std::cos(theta1+0.5*kAngTolerance) +
|
|---|
| 287 | (std::cos(theta1-0.5*kAngTolerance)-std::cos(theta1+0.5*kAngTolerance))*G4UniformRand();
|
|---|
| 288 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 289 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 290 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 291 |
|
|---|
| 292 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 293 | }
|
|---|
| 294 | else // theta2
|
|---|
| 295 | {
|
|---|
| 296 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 | cosTheta = std::cos(theta2+0.5*kAngTolerance) +
|
|---|
| 300 | (std::cos(theta2-0.5*kAngTolerance)-std::cos(theta2+0.5*kAngTolerance))*G4UniformRand();
|
|---|
| 301 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 302 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 303 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 304 |
|
|---|
| 305 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 306 | }
|
|---|
| 307 | px = radius*sinTheta*std::cos(phi);
|
|---|
| 308 | py = radius*sinTheta*std::sin(phi);
|
|---|
| 309 | pz = radius*cosTheta;
|
|---|
| 310 |
|
|---|
| 311 | return G4ThreeVector(px,py,pz);
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 316 | //
|
|---|
| 317 | // Random vector around sphere surface
|
|---|
| 318 |
|
|---|
| 319 | G4ThreeVector GetVectorAroundSphere(G4Sphere& sphere)
|
|---|
| 320 | {
|
|---|
| 321 | G4double cosTheta, sinTheta, phi, radius, px, py, pz;
|
|---|
| 322 |
|
|---|
| 323 | // G4double pRmin = sphere.GetInsideRadius();
|
|---|
| 324 | G4double pRmax = 1.26*sphere.GetOuterRadius();
|
|---|
| 325 | // G4double phi1 = sphere.GetStartPhiAngle();
|
|---|
| 326 | // G4double phi2 = phi1 + sphere.GetDeltaPhiAngle();
|
|---|
| 327 | // G4double theta1 = sphere.GetStartThetaAngle();
|
|---|
| 328 | // G4double theta2 = theta1 + sphere.GetDeltaThetaAngle();
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 | radius = pRmax*G4UniformRand();
|
|---|
| 332 | cosTheta = -1. + 2.*G4UniformRand();
|
|---|
| 333 | if( cosTheta > 1.) cosTheta = 1.;
|
|---|
| 334 | if( cosTheta < -1.) cosTheta = -1.;
|
|---|
| 335 | sinTheta = std::sqrt( 1. - cosTheta*cosTheta );
|
|---|
| 336 |
|
|---|
| 337 | phi = 2*pi*G4UniformRand();
|
|---|
| 338 |
|
|---|
| 339 | px = radius*sinTheta*std::cos(phi);
|
|---|
| 340 | py = radius*sinTheta*std::sin(phi);
|
|---|
| 341 | pz = radius*cosTheta;
|
|---|
| 342 |
|
|---|
| 343 | return G4ThreeVector(px,py,pz);
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 347 | //
|
|---|
| 348 | // Random vector on tubs surface
|
|---|
| 349 |
|
|---|
| 350 | G4ThreeVector GetVectorOnTubs(G4Tubs& tubs)
|
|---|
| 351 | {
|
|---|
| 352 | G4double phi, radius, px, py, pz;
|
|---|
| 353 | // G4double part = 1.;
|
|---|
| 354 | // G4double rand = G4UniformRand();
|
|---|
| 355 |
|
|---|
| 356 | // G4double pRmin = tubs.GetInnerRadius ();
|
|---|
| 357 | G4double pRmax = tubs.GetOuterRadius ();
|
|---|
| 358 | G4double tubsZ = 0.999*tubs.GetZHalfLength ();
|
|---|
| 359 | // G4double phi1 = tubs.GetStartPhiAngle ();
|
|---|
| 360 | // G4double phi2 = phi1 + tubs.GetDeltaPhiAngle ();
|
|---|
| 361 |
|
|---|
| 362 | // G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
|---|
| 363 | // G4double kAngTolerance = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
|
|---|
| 364 |
|
|---|
| 365 | // if ( rand < part ) // Rmax
|
|---|
| 366 | {
|
|---|
| 367 | radius = pRmax; // -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 368 | // pz = -tubsZ - 0.5*kCarTolerance + (2*tubsZ + kCarTolerance)*G4UniformRand();
|
|---|
| 369 | pz = -tubsZ + 2*tubsZ*G4UniformRand();
|
|---|
| 370 | // phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 371 | phi = 2*pi*G4UniformRand();
|
|---|
| 372 | }
|
|---|
| 373 | /*
|
|---|
| 374 | else if ( rand < 2*part ) // Rmin
|
|---|
| 375 | {
|
|---|
| 376 | radius = pRmin -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 377 | pz = -tubsZ - 0.5*kCarTolerance + (2*tubsZ + kCarTolerance)*G4UniformRand();
|
|---|
| 378 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 379 | }
|
|---|
| 380 | else if ( rand < 3*part ) // phi1
|
|---|
| 381 | {
|
|---|
| 382 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 383 | pz = -tubsZ - 0.5*kCarTolerance + (2*tubsZ + kCarTolerance)*G4UniformRand();
|
|---|
| 384 | phi = phi1 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 385 | }
|
|---|
| 386 | else if ( rand < 4*part ) // phi2
|
|---|
| 387 | {
|
|---|
| 388 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 389 | pz = -tubsZ - 0.5*kCarTolerance + (2*tubsZ + kCarTolerance)*G4UniformRand();
|
|---|
| 390 | phi = phi2 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 391 | }
|
|---|
| 392 | else if ( rand < 5*part ) // -fZ
|
|---|
| 393 | {
|
|---|
| 394 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 395 |
|
|---|
| 396 | pz = -tubsZ - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 397 |
|
|---|
| 398 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 399 | }
|
|---|
| 400 | else // fZ
|
|---|
| 401 | {
|
|---|
| 402 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 403 | pz = tubsZ - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 404 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 405 | }
|
|---|
| 406 | */
|
|---|
| 407 | px = radius*std::cos(phi);
|
|---|
| 408 | py = radius*std::sin(phi);
|
|---|
| 409 |
|
|---|
| 410 | return G4ThreeVector(px,py,pz);
|
|---|
| 411 | }
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 416 | //
|
|---|
| 417 | // Random vector around tubs surface
|
|---|
| 418 |
|
|---|
| 419 | G4ThreeVector GetVectorAroundTubs(G4Tubs& tubs)
|
|---|
| 420 | {
|
|---|
| 421 | G4double phi, radius, px, py, pz;
|
|---|
| 422 | G4double partR = 3.; // 1.26;
|
|---|
| 423 | G4double partZ = 1.; // 1.26;
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 | G4double pRmax = partR*tubs.GetOuterRadius ();
|
|---|
| 427 | G4double tubsZ = 0.999*partZ*tubs.GetZHalfLength ();
|
|---|
| 428 |
|
|---|
| 429 | // G4double pRmin = tubs.GetInnerRadius ();
|
|---|
| 430 | // G4double phi1 = tubs.GetStartPhiAngle ();
|
|---|
| 431 | // G4double phi2 = phi1 + tubs.GetDeltaPhiAngle ();
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 | radius = pRmax*G4UniformRand();
|
|---|
| 435 | pz = -tubsZ + 2*tubsZ*G4UniformRand();
|
|---|
| 436 | phi = 2*pi*G4UniformRand();
|
|---|
| 437 |
|
|---|
| 438 | px = radius*std::cos(phi);
|
|---|
| 439 | py = radius*std::sin(phi);
|
|---|
| 440 |
|
|---|
| 441 | return G4ThreeVector(px,py,pz);
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 445 | //
|
|---|
| 446 | // Random vector on cons surface
|
|---|
| 447 |
|
|---|
| 448 | G4ThreeVector GetVectorOnCons(G4Cons& cons)
|
|---|
| 449 | {
|
|---|
| 450 | // G4double pRmin, pRmax;
|
|---|
| 451 | G4double phi, radius, px, py, pz;
|
|---|
| 452 | // G4double part = 1.; // /6.;
|
|---|
| 453 | // G4double rand = G4UniformRand();
|
|---|
| 454 |
|
|---|
| 455 | // G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
|---|
| 456 | // G4double kAngTolerance = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
|
|---|
| 457 |
|
|---|
| 458 | // G4double pRmin1 = cons.GetInnerRadiusMinusZ ();
|
|---|
| 459 | G4double pRmax1 = cons.GetOuterRadiusMinusZ ();
|
|---|
| 460 | // G4double pRmin2 = cons.GetInnerRadiusPlusZ ();
|
|---|
| 461 | G4double pRmax2 = cons.GetOuterRadiusPlusZ ();
|
|---|
| 462 | G4double consZ = cons.GetZHalfLength ();
|
|---|
| 463 | // G4double phi1 = cons.GetStartPhiAngle ();
|
|---|
| 464 | // G4double phi2 = phi1 + cons.GetDeltaPhiAngle ();
|
|---|
| 465 |
|
|---|
| 466 | // G4double tgMin = 0.5*(pRmin2 - pRmin1)/consZ;
|
|---|
| 467 | G4double tgMax = 0.5*(pRmax2 - pRmax1)/consZ;
|
|---|
| 468 |
|
|---|
| 469 | // consZ *= 0.999;
|
|---|
| 470 |
|
|---|
| 471 | G4double cof = 0.999;
|
|---|
| 472 |
|
|---|
| 473 | // if ( rand < part ) // Rmax
|
|---|
| 474 | {
|
|---|
| 475 | pz = -cof*consZ + 2*cof*consZ*G4UniformRand();
|
|---|
| 476 | radius = pRmax1 + tgMax*( pz + consZ );
|
|---|
| 477 |
|
|---|
| 478 | // radius = pRmax; // -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 479 |
|
|---|
| 480 | phi = 2*pi*G4UniformRand();
|
|---|
| 481 | }
|
|---|
| 482 | /*
|
|---|
| 483 | else if ( rand < 2*part ) // Rmin
|
|---|
| 484 | {
|
|---|
| 485 | pz = -consZ - 0.5*kCarTolerance + (2*consZ + kCarTolerance)*G4UniformRand();
|
|---|
| 486 | pRmin = pRmin1 + tgMin*(pz+consZ);
|
|---|
| 487 | radius = pRmin -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 488 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 489 | }
|
|---|
| 490 | else if ( rand < 3*part ) // phi1
|
|---|
| 491 | {
|
|---|
| 492 | pz = -consZ - 0.5*kCarTolerance + (2*consZ + kCarTolerance)*G4UniformRand();
|
|---|
| 493 | pRmax = pRmax1 + tgMax*(pz+consZ);
|
|---|
| 494 | pRmin = pRmin1 + tgMin*(pz+consZ);
|
|---|
| 495 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 496 | phi = phi1 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 497 | }
|
|---|
| 498 | else if ( rand < 4*part ) // phi2
|
|---|
| 499 | {
|
|---|
| 500 | pz = -consZ - 0.5*kCarTolerance + (2*consZ + kCarTolerance)*G4UniformRand();
|
|---|
| 501 | pRmax = pRmax1 + tgMax*(pz+consZ);
|
|---|
| 502 | pRmin = pRmin1 + tgMin*(pz+consZ);
|
|---|
| 503 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 504 | phi = phi2 -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 505 | }
|
|---|
| 506 | else if ( rand < 5*part ) // -fZ
|
|---|
| 507 | {
|
|---|
| 508 | pz = -consZ - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 509 | radius = pRmin1 - 0.5*kCarTolerance + (pRmax1-pRmin1+kCarTolerance)*G4UniformRand();
|
|---|
| 510 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 511 | }
|
|---|
| 512 | else // fZ
|
|---|
| 513 | {
|
|---|
| 514 | pz = consZ - 0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 515 | radius = pRmin2 - 0.5*kCarTolerance + (pRmax2-pRmin2+kCarTolerance)*G4UniformRand();
|
|---|
| 516 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 517 | }
|
|---|
| 518 | */
|
|---|
| 519 | px = radius*std::cos(phi);
|
|---|
| 520 | py = radius*std::sin(phi);
|
|---|
| 521 |
|
|---|
| 522 | return G4ThreeVector(px,py,pz);
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 526 | //
|
|---|
| 527 | // Random vector around cons surface
|
|---|
| 528 |
|
|---|
| 529 | G4ThreeVector GetVectorAroundCons(G4Cons& cons)
|
|---|
| 530 | {
|
|---|
| 531 | G4double phi, pRmax, radius, px, py, pz;
|
|---|
| 532 |
|
|---|
| 533 | // G4double rand = G4UniformRand();
|
|---|
| 534 |
|
|---|
| 535 | // G4double pRmin1 = cons.GetInnerRadiusMinusZ ();
|
|---|
| 536 | G4double pRmax1 = cons.GetOuterRadiusMinusZ ();
|
|---|
| 537 | // G4double pRmin2 = cons.GetInnerRadiusPlusZ ();
|
|---|
| 538 | G4double pRmax2 = cons.GetOuterRadiusPlusZ ();
|
|---|
| 539 | G4double consZ = cons.GetZHalfLength ();
|
|---|
| 540 | // G4double phi1 = cons.GetStartPhiAngle ();
|
|---|
| 541 | // G4double phi2 = phi1 + cons.GetDeltaPhiAngle ();
|
|---|
| 542 | // G4double tgMin = (pRmin2 - pRmin1)/(2.*consZ);
|
|---|
| 543 | G4double tgMax = (pRmax2 - pRmax1)/(2.*consZ);
|
|---|
| 544 |
|
|---|
| 545 | consZ *= 0.999;
|
|---|
| 546 |
|
|---|
| 547 | pz = -consZ + 2*consZ*G4UniformRand();
|
|---|
| 548 | pRmax = pRmax1 + tgMax*(pz+consZ);
|
|---|
| 549 | pRmax *= 3.;
|
|---|
| 550 | radius = pRmax*G4UniformRand();
|
|---|
| 551 | phi = twopi*G4UniformRand();
|
|---|
| 552 |
|
|---|
| 553 | px = radius*std::cos(phi);
|
|---|
| 554 | py = radius*std::sin(phi);
|
|---|
| 555 |
|
|---|
| 556 | return G4ThreeVector(px,py,pz);
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 560 | //
|
|---|
| 561 | // Random vector on torus surface
|
|---|
| 562 |
|
|---|
| 563 | G4ThreeVector GetVectorOnTorus(G4Torus& torus)
|
|---|
| 564 | {
|
|---|
| 565 | G4double phi, alpha, radius, px, py, pz;
|
|---|
| 566 | // G4double part = 1./4.;
|
|---|
| 567 | // G4double rand = G4UniformRand();
|
|---|
| 568 |
|
|---|
| 569 | // G4double pRmin = torus.GetRmin();
|
|---|
| 570 | G4double pRmax = torus.GetRmax();
|
|---|
| 571 | G4double pRtor = torus.GetRtor();
|
|---|
| 572 | // G4double phi1 = torus.GetSPhi();
|
|---|
| 573 | // G4double phi2 = phi1 + torus.GetDPhi ();
|
|---|
| 574 |
|
|---|
| 575 | // G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
|---|
| 576 | // G4double kAngTolerance = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
|
|---|
| 577 |
|
|---|
| 578 | // if ( rand < part ) // Rmax
|
|---|
| 579 | {
|
|---|
| 580 | radius = pRmax; // -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 581 | alpha = -halfpi + pi*G4UniformRand();
|
|---|
| 582 | phi = pi*G4UniformRand();
|
|---|
| 583 | }
|
|---|
| 584 | /*
|
|---|
| 585 | else if ( rand < 2*part ) // Rmin
|
|---|
| 586 | {
|
|---|
| 587 | radius = pRmin -0.5*kCarTolerance + (kCarTolerance)*G4UniformRand();
|
|---|
| 588 | alpha = twopi*G4UniformRand();
|
|---|
| 589 | phi = phi1 - 0.5*kAngTolerance + (phi2 - phi1 + kAngTolerance)*G4UniformRand();
|
|---|
| 590 | }
|
|---|
| 591 | else if ( rand < 3*part ) // phi1
|
|---|
| 592 | {
|
|---|
| 593 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 594 | alpha = twopi*G4UniformRand();
|
|---|
| 595 | // pz = -pRtor - 0.5*kCarTolerance + (2*pRtor + kCarTolerance)*G4UniformRand();
|
|---|
| 596 | phi = phi1 -0.5*kAngTolerance + (kAngTolerance)*G4UniformRand();
|
|---|
| 597 | }
|
|---|
| 598 | else // phi2
|
|---|
| 599 | {
|
|---|
| 600 | radius = pRmin - 0.5*kCarTolerance + (pRmax-pRmin+kCarTolerance)*G4UniformRand();
|
|---|
| 601 | alpha = twopi*G4UniformRand();
|
|---|
| 602 | phi = phi2 -0.5*kAngTolerance + (kAngTolerance)*G4UniformRand();
|
|---|
| 603 | }
|
|---|
| 604 | */
|
|---|
| 605 | px = (pRtor+radius*std::cos(alpha))*std::cos(phi);
|
|---|
| 606 | py = (pRtor+radius*std::cos(alpha))*std::sin(phi);
|
|---|
| 607 | pz = radius*std::sin(alpha);
|
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 | return G4ThreeVector(px,py,pz);
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 614 | //
|
|---|
| 615 | // Random vector around torus surface
|
|---|
| 616 |
|
|---|
| 617 | G4ThreeVector GetVectorAroundTorus(G4Torus& torus)
|
|---|
| 618 | {
|
|---|
| 619 | G4double phi, alpha, radius, px, py, pz;
|
|---|
| 620 |
|
|---|
| 621 | G4double pRmax = torus.GetRmax();
|
|---|
| 622 | G4double pRtor = torus.GetRtor();
|
|---|
| 623 |
|
|---|
| 624 |
|
|---|
| 625 | radius = 3*pRmax*G4UniformRand();
|
|---|
| 626 | alpha = -halfpi + pi*G4UniformRand();
|
|---|
| 627 | phi = pi*G4UniformRand();
|
|---|
| 628 |
|
|---|
| 629 | pRtor *= 3*G4UniformRand();
|
|---|
| 630 |
|
|---|
| 631 | px = (pRtor+radius*std::cos(alpha))*std::cos(phi);
|
|---|
| 632 | py = (pRtor+radius*std::cos(alpha))*std::sin(phi);
|
|---|
| 633 | pz = radius*std::sin(alpha);
|
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 | return G4ThreeVector(px,py,pz);
|
|---|
| 637 | }
|
|---|
| 638 |
|
|---|
| 639 |
|
|---|
| 640 | enum Esolid {kBox, kOrb, kSphere, kCons, kTubs, kTorus, kPara, kTrapezoid, kTrd};
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 | //////////////////////////////////////////////////////////////////////
|
|---|
| 644 | //
|
|---|
| 645 | // Main executable function
|
|---|
| 646 |
|
|---|
| 647 | int main(int argc, char** argv)
|
|---|
| 648 | {
|
|---|
| 649 | G4int test_one_solid( Esolid, int, int );
|
|---|
| 650 |
|
|---|
| 651 | G4int no_points = 1000;
|
|---|
| 652 | G4int dirs_per_point = 10000;
|
|---|
| 653 |
|
|---|
| 654 | G4cout << "Usage: testDistanceAccuracy [ no_surface_points ] [ no_directions_each ] "
|
|---|
| 655 | << G4endl << G4endl;
|
|---|
| 656 |
|
|---|
| 657 | G4int points_in = 0, dirs_in = 0;
|
|---|
| 658 |
|
|---|
| 659 | if( argc >= 2 ) points_in = atoi(argv[1]);
|
|---|
| 660 | if( argc >= 3 ) dirs_in = atoi(argv[2]);
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 | if( points_in > 0 ) { no_points= points_in; }
|
|---|
| 664 | if( dirs_in > 0 ) { dirs_per_point = dirs_in; }
|
|---|
| 665 |
|
|---|
| 666 | G4cout << "Testing each solid with " << no_points << " surface points and "
|
|---|
| 667 | << dirs_per_point << " directions each. " << G4endl;
|
|---|
| 668 |
|
|---|
| 669 | Esolid useCase;
|
|---|
| 670 |
|
|---|
| 671 | /*
|
|---|
| 672 | G4cout<< "To test Box." << G4endl;
|
|---|
| 673 | test_one_solid( useCase= kBox, no_points, dirs_per_point );
|
|---|
| 674 |
|
|---|
| 675 | G4cout<< "To test Para." << G4endl;
|
|---|
| 676 | test_one_solid( useCase= kPara, no_points, dirs_per_point );
|
|---|
| 677 |
|
|---|
| 678 | G4cout<< "To test Trapezoid." << G4endl;
|
|---|
| 679 | test_one_solid( useCase= kTrapezoid, no_points, dirs_per_point );
|
|---|
| 680 |
|
|---|
| 681 | G4cout<< "To test Trd." << G4endl;
|
|---|
| 682 | test_one_solid( useCase= kTrd, no_points, dirs_per_point );
|
|---|
| 683 |
|
|---|
| 684 | G4cout<< "To test Orb." << G4endl;
|
|---|
| 685 | test_one_solid( useCase= kOrb, no_points, dirs_per_point );
|
|---|
| 686 |
|
|---|
| 687 |
|
|---|
| 688 | G4cout<< "To test Tubs." << G4endl;
|
|---|
| 689 | test_one_solid( useCase= kTubs, no_points, dirs_per_point );
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 | G4cout<< "To test Cons." << G4endl;
|
|---|
| 693 | test_one_solid( useCase= kCons, no_points, dirs_per_point );
|
|---|
| 694 | */
|
|---|
| 695 | G4cout<< "To test Torus" << G4endl;
|
|---|
| 696 | test_one_solid( useCase= kTorus, no_points, dirs_per_point );
|
|---|
| 697 |
|
|---|
| 698 | return 0;
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | //
|
|---|
| 702 |
|
|---|
| 703 | int test_one_solid ( Esolid useCase, int num_points, int directions_per_point )
|
|---|
| 704 | {
|
|---|
| 705 | G4int i,j;
|
|---|
| 706 | G4int iMax = num_points, jMax = directions_per_point;
|
|---|
| 707 | G4int iCheck=iMax/10;
|
|---|
| 708 |
|
|---|
| 709 | G4double kRadTolerance = G4GeometryTolerance::GetInstance()->GetRadialTolerance();
|
|---|
| 710 |
|
|---|
| 711 | jMax = 50;
|
|---|
| 712 |
|
|---|
| 713 | G4int iInNoSurf = 0, iOutNoSurf = 0, iIn = 0, iOut = 0;
|
|---|
| 714 |
|
|---|
| 715 | G4cout << " Reporting every " << iCheck << " points. " << G4endl;
|
|---|
| 716 |
|
|---|
| 717 | G4double distIn, distOut, distCheck, dDist, position, dIn[50], dOut[50];
|
|---|
| 718 |
|
|---|
| 719 | for(j=0;j<jMax;j++)
|
|---|
| 720 | {
|
|---|
| 721 | dIn[j] = 0.;
|
|---|
| 722 | dOut[j] = 0.;
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | EInside surfaceP, surfaceA;
|
|---|
| 726 | G4ThreeVector norm,*pNorm;
|
|---|
| 727 | G4bool *pgoodNorm, goodNorm, calcNorm=true;
|
|---|
| 728 |
|
|---|
| 729 | pNorm=&norm;
|
|---|
| 730 | pgoodNorm=&goodNorm;
|
|---|
| 731 |
|
|---|
| 732 | G4cout.precision(20);
|
|---|
| 733 |
|
|---|
| 734 | G4ThreeVector normP( 0., 0., 1.);
|
|---|
| 735 |
|
|---|
| 736 | // Boxes for test
|
|---|
| 737 |
|
|---|
| 738 | G4Box b1("Test Box #1",20,30,40);
|
|---|
| 739 | G4Box b2("Test Box #2",10,10,10);
|
|---|
| 740 | G4Box box3("BABAR Box",0.14999999999999999,
|
|---|
| 741 | 24.707000000000001,
|
|---|
| 742 | 22.699999999999999) ;
|
|---|
| 743 |
|
|---|
| 744 | // orbs for test
|
|---|
| 745 |
|
|---|
| 746 | G4Orb o1("Solid G4Orb",50);
|
|---|
| 747 | G4Orb o10("s10",0.018*mm);
|
|---|
| 748 | // G4Orb* solidO1= new G4Orb("O1", 2.7*cm);
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 | // spheres for test
|
|---|
| 752 |
|
|---|
| 753 | // G4Sphere s5("Patch (phi/theta seg)",45,50,-pi/4,halfpi,pi/4,halfpi);
|
|---|
| 754 | // G4Sphere s5("Patch (phi/theta seg)",45,50,-pi/4.,pi/4.,pi/4,pi/4.);
|
|---|
| 755 | G4Sphere s3("Patch (phi/theta seg)",45,50,0.,2*pi,pi/6,pi/2);
|
|---|
| 756 |
|
|---|
| 757 | G4Sphere s4("Patch (phi/theta seg)",45,50,pi/4.,pi/4.,0.,pi);
|
|---|
| 758 |
|
|---|
| 759 | G4Sphere s5("Patch (phi/theta seg)",45,50,-pi/4.,pi/4.,pi/2,pi/4.);
|
|---|
| 760 |
|
|---|
| 761 | G4Sphere s6("John example",300,500,0,5.76,0,pi) ;
|
|---|
| 762 | G4Sphere s7("sphere7",1400.,1550.,0.022321428571428572,0.014642857142857141,
|
|---|
| 763 | 1.5631177553663251,0.014642857142857141 );
|
|---|
| 764 | G4Sphere s8("sphere",278.746*mm, 280.0*mm, 0.0*degree, 360.0*degree,
|
|---|
| 765 | 0.0*degree, 90.0*degree);
|
|---|
| 766 |
|
|---|
| 767 | G4Sphere b216("b216", 1400.0, 1550.0,
|
|---|
| 768 | 0.022321428571428572,
|
|---|
| 769 | 0.014642857142857141,
|
|---|
| 770 | 1.578117755366325,
|
|---|
| 771 | 0.014642857142867141);
|
|---|
| 772 |
|
|---|
| 773 | G4Sphere s9("s9",0*mm,410*mm,0*degree,360*degree,90*degree,90*degree);
|
|---|
| 774 |
|
|---|
| 775 | G4Sphere b402("b402", 475*mm, 480*mm,
|
|---|
| 776 | 0*degree,360*degree,17.8*degree,144.4*degree);
|
|---|
| 777 |
|
|---|
| 778 |
|
|---|
| 779 | G4Sphere s10("s10",0*mm,0.018*mm,0*degree,360*degree,0*degree,180*degree);
|
|---|
| 780 |
|
|---|
| 781 |
|
|---|
| 782 | G4Sphere s11("s11",5000000.*mm,
|
|---|
| 783 | 3700000000.*mm,
|
|---|
| 784 | 0*degree,360*degree,0*degree,180*degree);
|
|---|
| 785 |
|
|---|
| 786 |
|
|---|
| 787 | G4Sphere sAlex("sAlex",500.*mm,
|
|---|
| 788 | 501.*mm,
|
|---|
| 789 | 0*degree,360*degree,0*degree,180*degree);
|
|---|
| 790 |
|
|---|
| 791 | G4Sphere sLHCB("sLHCB",8600*mm, 8606*mm,
|
|---|
| 792 | -1.699135525184141*degree,
|
|---|
| 793 | 3.398271050368263*degree,88.52855940538514*degree,2.942881189229715*degree );
|
|---|
| 794 |
|
|---|
| 795 | G4Sphere spAroundX("SpAroundX", 10.*mm, 1000.*mm, -1.0*degree,
|
|---|
| 796 | 2.0*degree,
|
|---|
| 797 | 0.*degree, 180.0*degree );
|
|---|
| 798 |
|
|---|
| 799 | G4Sphere st = s3;
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 | // G4Tubs
|
|---|
| 803 |
|
|---|
| 804 | G4Tubs t1("Solid tubs", 0.*mm, 50*mm, 50*mm, 0., twopi);
|
|---|
| 805 |
|
|---|
| 806 | G4Tubs t4("Hole Sector #4",45*mm,50*mm,50*mm,-halfpi,halfpi);
|
|---|
| 807 |
|
|---|
| 808 |
|
|---|
| 809 |
|
|---|
| 810 |
|
|---|
| 811 |
|
|---|
| 812 | G4Cons c1("Solid Cone", 0.*mm, 100.*mm, 0.*mm, 200.*mm, 50.*mm, 0., twopi);
|
|---|
| 813 |
|
|---|
| 814 |
|
|---|
| 815 | G4Cons c4("Hollow Cut Cone",50,100,50,200,50,-pi/6,pi/3);
|
|---|
| 816 | G4Cons c5("Hollow Cut Cone",25,50,75,150,50,0,3*halfpi);
|
|---|
| 817 |
|
|---|
| 818 |
|
|---|
| 819 | G4double Rtor = 100. ;
|
|---|
| 820 | G4double Rmax = Rtor*0.9 ;
|
|---|
| 821 | G4double Rmin = Rtor*0.1 ;
|
|---|
| 822 |
|
|---|
| 823 | G4Torus tor1("Soild Torus ",0.,Rmax,Rtor,0.,twopi);
|
|---|
| 824 |
|
|---|
| 825 | G4Torus torus1("torus1",10.,15.,20.,0.,3*halfpi);
|
|---|
| 826 | G4Torus tor2("Hole cutted Torus #2",Rmin,Rmax,Rtor,pi/4,halfpi);
|
|---|
| 827 | G4Torus torn2("tn2",Rmin,Rmax,Rtor,halfpi,halfpi);
|
|---|
| 828 | G4Torus torn3("tn3",Rmin,Rmax,Rtor,halfpi,3*halfpi);
|
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 | // Check of some use cases shown zero-zero problems
|
|---|
| 832 |
|
|---|
| 833 | G4ThreeVector pCheck, vCheck, v;
|
|---|
| 834 |
|
|---|
| 835 | // pCheck = G4ThreeVector( 41.418613476008794, -16.893662525384702, 4.9094423552800466 );
|
|---|
| 836 | // vCheck = G4ThreeVector( 0.34553222148699703, 0.91172822040596313, 0.22216916084289551 );
|
|---|
| 837 | // distIn = s5.DistanceToIn(pCheck,vCheck);
|
|---|
| 838 | // distOut = s5.DistanceToOut(pCheck,vCheck,calcNorm,pgoodNorm,pNorm);
|
|---|
| 839 |
|
|---|
| 840 | // pCheck = G4ThreeVector( 43.169180219772784, -11.564259048580507, 5.2621090605480623 );
|
|---|
| 841 | // surfaceP = s5.Inside(pCheck);
|
|---|
| 842 |
|
|---|
| 843 | pCheck = G4ThreeVector( -51.189087930597751, -17.382942686173514, -45.939946175080983 );
|
|---|
| 844 | vCheck = G4ThreeVector( 0.44410267104120671, -0.88563345532911941, -0.13574314117431641 );
|
|---|
| 845 | distIn = c5.DistanceToIn(pCheck,vCheck);
|
|---|
| 846 | distOut = c5.DistanceToOut(pCheck,vCheck,calcNorm,pgoodNorm,pNorm);
|
|---|
| 847 |
|
|---|
| 848 | pCheck = G4ThreeVector(-41.407491890396564, -31.155805955816909, -48.18046093035241 );
|
|---|
| 849 | vCheck = G4ThreeVector(0.79040557001853884, -0.52472467107317944, -0.31610608100891113 );
|
|---|
| 850 | distIn = c5.DistanceToIn(pCheck,vCheck);
|
|---|
| 851 | distOut = c5.DistanceToOut(pCheck,vCheck,calcNorm,pgoodNorm,pNorm);
|
|---|
| 852 |
|
|---|
| 853 | pCheck = G4ThreeVector(-66.68328490196707, -47.460245099793099, -18.151754141035401 );
|
|---|
| 854 | vCheck = G4ThreeVector(-0.066679791594195931, 0.88577693677046576, -0.45929622650146484 );
|
|---|
| 855 | distIn = c5.DistanceToIn(pCheck,vCheck);
|
|---|
| 856 | distOut = c5.DistanceToOut(pCheck,vCheck,calcNorm,pgoodNorm,pNorm);
|
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 | #ifdef NDEBUG
|
|---|
| 860 | G4Exception("FAIL: *** Assertions must be compiled in! ***");
|
|---|
| 861 | #endif
|
|---|
| 862 |
|
|---|
| 863 | std::ofstream foutDistIn("DistIn.dat", std::ios::out ) ;
|
|---|
| 864 | foutDistIn.setf( std::ios::scientific, std::ios::floatfield );
|
|---|
| 865 |
|
|---|
| 866 | std::ofstream foutDistOut("DistOut.dat", std::ios::out ) ;
|
|---|
| 867 | foutDistOut.setf( std::ios::scientific, std::ios::floatfield );
|
|---|
| 868 |
|
|---|
| 869 |
|
|---|
| 870 | // Check box tracking function
|
|---|
| 871 |
|
|---|
| 872 | switch (useCase)
|
|---|
| 873 | {
|
|---|
| 874 |
|
|---|
| 875 | case kBox:
|
|---|
| 876 |
|
|---|
| 877 | G4cout<<"Testing G4Box:"<<G4endl<<G4endl;
|
|---|
| 878 |
|
|---|
| 879 | iInNoSurf = 0, iOutNoSurf = 0, iIn = 0, iOut = 0;
|
|---|
| 880 |
|
|---|
| 881 | for( i = 0; i < iMax; i++)
|
|---|
| 882 | {
|
|---|
| 883 | if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
|
|---|
| 884 |
|
|---|
| 885 | G4ThreeVector p = GetVectorAroundBox(b1);
|
|---|
| 886 | surfaceP = b1.Inside(p);
|
|---|
| 887 |
|
|---|
| 888 | if(surfaceP != kSurface)
|
|---|
| 889 | {
|
|---|
| 890 | if(surfaceP == kOutside)
|
|---|
| 891 | {
|
|---|
| 892 | for( j = 0; j < jMax; j++ )
|
|---|
| 893 | {
|
|---|
| 894 | G4ThreeVector v = GetRandomUnitVector();
|
|---|
| 895 |
|
|---|
| 896 | distIn = b1.DistanceToIn(p,v);
|
|---|
| 897 |
|
|---|
| 898 | if(distIn != kInfinity)
|
|---|
| 899 | {
|
|---|
| 900 | iIn++;
|
|---|
| 901 |
|
|---|
| 902 | surfaceP = b1.Inside(p + distIn*v);
|
|---|
| 903 |
|
|---|
| 904 | if(surfaceP != kSurface )
|
|---|
| 905 | {
|
|---|
| 906 | iInNoSurf++;
|
|---|
| 907 | // G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
|
|---|
| 908 | // G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
|
|---|
| 909 | // G4cout<<"location p: "; // << G4endl;
|
|---|
| 910 | // G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
|
|---|
| 911 | // G4cout<<" direction v: "; // << G4endl;
|
|---|
| 912 | // G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
|
|---|
| 913 | }
|
|---|
| 914 | }
|
|---|
| 915 | }
|
|---|
| 916 | }
|
|---|
| 917 | else
|
|---|
| 918 | {
|
|---|
| 919 | for( j = 0; j < jMax; j++ )
|
|---|
| 920 | {
|
|---|
| 921 | iOut++;
|
|---|
| 922 |
|
|---|
| 923 | G4ThreeVector v = GetRandomUnitVector();
|
|---|
| 924 |
|
|---|
| 925 | distOut = b1.DistanceToOut(p,v,calcNorm,pgoodNorm,pNorm);
|
|---|
| 926 | surfaceP = b1.Inside(p + distOut*v);
|
|---|
| 927 |
|
|---|
| 928 | if(surfaceP != kSurface )
|
|---|
| 929 | {
|
|---|
| 930 | iOutNoSurf++;
|
|---|
| 931 | // G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
|
|---|
| 932 | // G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
|
|---|
| 933 | // G4cout<<"location p: "; // << G4endl;
|
|---|
| 934 | // G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
|
|---|
| 935 | // G4cout<<" direction v: "; // << G4endl;
|
|---|
| 936 | // G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
|
|---|
| 937 | }
|
|---|
| 938 | }
|
|---|
| 939 | }
|
|---|
| 940 | }
|
|---|
| 941 |
|
|---|
| 942 | }
|
|---|
| 943 | G4cout<<"iIn = "<<iIn<<"; iOut = "<<iOut<<G4endl;
|
|---|
| 944 | G4cout<<"iInNoSurf = "<<iInNoSurf<<"; iOutNoSurf = "<<iOutNoSurf<<G4endl;
|
|---|
| 945 |
|
|---|
| 946 |
|
|---|
| 947 | break;
|
|---|
| 948 |
|
|---|
| 949 | case kOrb:
|
|---|
| 950 |
|
|---|
| 951 | G4cout<<"Testing G4Orb:"<<G4endl<<G4endl;
|
|---|
| 952 |
|
|---|
| 953 | iInNoSurf = 0, iOutNoSurf = 0, iIn = 0, iOut = 0;
|
|---|
| 954 |
|
|---|
| 955 | for( i = 0; i < iMax; i++)
|
|---|
| 956 | {
|
|---|
| 957 | if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
|
|---|
| 958 |
|
|---|
| 959 | G4ThreeVector pA = GetVectorAroundOrb(o1);
|
|---|
| 960 | G4ThreeVector pS = GetVectorOnOrb(o1, normP);
|
|---|
| 961 |
|
|---|
| 962 | G4ThreeVector dP = pS - pA;
|
|---|
| 963 |
|
|---|
| 964 | if ( dP.mag2() > 0.)
|
|---|
| 965 | {
|
|---|
| 966 | distCheck = dP.mag();
|
|---|
| 967 | vCheck = dP.unit();
|
|---|
| 968 | // G4cout<<"distCheck ="<< distCheck<<"; dP.unit() mag = "<<dP.mag()<<G4endl;
|
|---|
| 969 | }
|
|---|
| 970 | else continue;
|
|---|
| 971 |
|
|---|
| 972 | surfaceP = o1.Inside(pS);
|
|---|
| 973 |
|
|---|
| 974 | if( surfaceP == kSurface )
|
|---|
| 975 | {
|
|---|
| 976 | surfaceA = o1.Inside(pA);
|
|---|
| 977 |
|
|---|
| 978 | if( surfaceA == kOutside )
|
|---|
| 979 | {
|
|---|
| 980 | if ( dP.dot(pS) <= 0. )
|
|---|
| 981 | {
|
|---|
| 982 | iIn++;
|
|---|
| 983 |
|
|---|
| 984 | distIn = o1.DistanceToIn(pA,vCheck);
|
|---|
| 985 |
|
|---|
| 986 | dDist = distIn - distCheck;
|
|---|
| 987 |
|
|---|
| 988 | // G4cout<<" distIn = "<<distIn<<"; distCheck = "<<distCheck<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 989 |
|
|---|
| 990 | dDist *= 10./kRadTolerance;
|
|---|
| 991 |
|
|---|
| 992 | for( j = 0; j < jMax; j++ )
|
|---|
| 993 | {
|
|---|
| 994 | position = -25. + j;
|
|---|
| 995 | if ( dDist < position )
|
|---|
| 996 | {
|
|---|
| 997 | dIn[j] += 1.;
|
|---|
| 998 | break;
|
|---|
| 999 | }
|
|---|
| 1000 | else continue;
|
|---|
| 1001 | }
|
|---|
| 1002 | if ( j == jMax ) dIn[jMax-1] += 1.;
|
|---|
| 1003 | if ( j == jMax || j == 0 )
|
|---|
| 1004 | {
|
|---|
| 1005 | // G4cout<<"distIn = "<<distIn<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1006 | // G4cout<<"distCheck = "<<distCheck<<"; vCheck.dot( pS.unit() ) = "
|
|---|
| 1007 | // <<vCheck.dot( pS.unit() )<<G4endl;
|
|---|
| 1008 | }
|
|---|
| 1009 | }
|
|---|
| 1010 | else continue;
|
|---|
| 1011 | }
|
|---|
| 1012 | else
|
|---|
| 1013 | {
|
|---|
| 1014 | iOut++;
|
|---|
| 1015 |
|
|---|
| 1016 | distOut = o1.DistanceToOut(pA,vCheck,calcNorm,pgoodNorm,pNorm);
|
|---|
| 1017 |
|
|---|
| 1018 | dDist = distOut - distCheck;
|
|---|
| 1019 |
|
|---|
| 1020 | // G4cout<<" distOut = "<<distOut<<"; distCheck = "<<distCheck<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1021 |
|
|---|
| 1022 | dDist *= 10./kRadTolerance;
|
|---|
| 1023 |
|
|---|
| 1024 | for( j = 0; j < jMax; j++ )
|
|---|
| 1025 | {
|
|---|
| 1026 | position = -25. + j;
|
|---|
| 1027 | if ( dDist < position )
|
|---|
| 1028 | {
|
|---|
| 1029 | dOut[j] += 1.;
|
|---|
| 1030 | break;
|
|---|
| 1031 | }
|
|---|
| 1032 | else continue;
|
|---|
| 1033 | }
|
|---|
| 1034 | if ( j == jMax) dOut[jMax-1] += 1.;
|
|---|
| 1035 | }
|
|---|
| 1036 | }
|
|---|
| 1037 | else
|
|---|
| 1038 | {
|
|---|
| 1039 | G4cout<<"pS is out of orb surface: "<<pS.x()<<"\t"<<pS.y()<<"\t"<<pS.z()<<G4endl;
|
|---|
| 1040 | }
|
|---|
| 1041 | }
|
|---|
| 1042 | G4cout<<"iIn = "<<iIn<<"; iOut = "<<iOut<<G4endl;
|
|---|
| 1043 | G4cout<<"iInNoSurf = "<<iInNoSurf<<"; iOutNoSurf = "<<iOutNoSurf<<G4endl<<G4endl;
|
|---|
| 1044 |
|
|---|
| 1045 | G4cout<<"iIn = "<<iIn<<G4endl<<G4endl;
|
|---|
| 1046 | for( j = 0; j < jMax; j++ )
|
|---|
| 1047 | {
|
|---|
| 1048 | position = -25. + j;
|
|---|
| 1049 | G4cout<<position<<"\t"<<dIn[j]<<G4endl;
|
|---|
| 1050 | foutDistIn<<position<<"\t"<<dIn[j]<<G4endl;
|
|---|
| 1051 | }
|
|---|
| 1052 | G4cout<<G4endl;
|
|---|
| 1053 | G4cout<<"iOut = "<<iOut<<G4endl<<G4endl;
|
|---|
| 1054 | for( j = 0; j < jMax; j++ )
|
|---|
| 1055 | {
|
|---|
| 1056 | position = -25. + j;
|
|---|
| 1057 | G4cout<<position<<"\t"<<dOut[j]<<G4endl;
|
|---|
| 1058 | foutDistOut<<position<<"\t"<<dOut[j]<<G4endl;
|
|---|
| 1059 | }
|
|---|
| 1060 |
|
|---|
| 1061 | break;
|
|---|
| 1062 |
|
|---|
| 1063 | case kSphere:
|
|---|
| 1064 |
|
|---|
| 1065 | G4cout<<"Testing one cutted G4Sphere:" << s5 <<G4endl<<G4endl;
|
|---|
| 1066 |
|
|---|
| 1067 | iInNoSurf = 0, iOutNoSurf = 0, iIn = 0, iOut = 0;
|
|---|
| 1068 |
|
|---|
| 1069 | for( i = 0; i < iMax; i++)
|
|---|
| 1070 | {
|
|---|
| 1071 | if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
|
|---|
| 1072 |
|
|---|
| 1073 | G4ThreeVector p = GetVectorAroundSphere(st);
|
|---|
| 1074 | surfaceP = st.Inside(p);
|
|---|
| 1075 |
|
|---|
| 1076 | if(surfaceP != kSurface)
|
|---|
| 1077 | {
|
|---|
| 1078 | if(surfaceP == kOutside)
|
|---|
| 1079 | {
|
|---|
| 1080 | for( j = 0; j < jMax; j++ )
|
|---|
| 1081 | {
|
|---|
| 1082 | G4ThreeVector v = GetRandomUnitVector();
|
|---|
| 1083 |
|
|---|
| 1084 | distIn = st.DistanceToIn(p,v);
|
|---|
| 1085 |
|
|---|
| 1086 | if(distIn != kInfinity)
|
|---|
| 1087 | {
|
|---|
| 1088 | iIn++;
|
|---|
| 1089 |
|
|---|
| 1090 | surfaceP = st.Inside(p + distIn*v);
|
|---|
| 1091 |
|
|---|
| 1092 | if(surfaceP != kSurface )
|
|---|
| 1093 | {
|
|---|
| 1094 | iInNoSurf++;
|
|---|
| 1095 | // G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
|
|---|
| 1096 | // G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
|
|---|
| 1097 | // G4cout<<"location p: "; // << G4endl;
|
|---|
| 1098 | // G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
|
|---|
| 1099 | // G4cout<<" direction v: "; // << G4endl;
|
|---|
| 1100 | // G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
|
|---|
| 1101 | }
|
|---|
| 1102 | }
|
|---|
| 1103 | }
|
|---|
| 1104 | }
|
|---|
| 1105 | else
|
|---|
| 1106 | {
|
|---|
| 1107 | for( j = 0; j < jMax; j++ )
|
|---|
| 1108 | {
|
|---|
| 1109 | iOut++;
|
|---|
| 1110 |
|
|---|
| 1111 | G4ThreeVector v = GetRandomUnitVector();
|
|---|
| 1112 |
|
|---|
| 1113 | distOut = st.DistanceToOut(p,v,calcNorm,pgoodNorm,pNorm);
|
|---|
| 1114 | surfaceP = st.Inside(p + distOut*v);
|
|---|
| 1115 |
|
|---|
| 1116 | if(surfaceP != kSurface )
|
|---|
| 1117 | {
|
|---|
| 1118 | iOutNoSurf++;
|
|---|
| 1119 | // G4cout<<" distIn < kCarTolerance && distOut < kCarTolerance"<<G4endl;
|
|---|
| 1120 | // G4cout<<"distIn = "<<distIn<<"; distOut = "<<distOut<<G4endl;
|
|---|
| 1121 | // G4cout<<"location p: "; // << G4endl;
|
|---|
| 1122 | // G4cout<<"( "<<p.x()<<", "<<p.y()<<", "<<p.z()<<" ); "<<G4endl;
|
|---|
| 1123 | // G4cout<<" direction v: "; // << G4endl;
|
|---|
| 1124 | // G4cout<<"( "<<v.x()<<", "<<v.y()<<", "<<v.z()<<" ); "<<G4endl<<G4endl;
|
|---|
| 1125 | }
|
|---|
| 1126 | }
|
|---|
| 1127 | }
|
|---|
| 1128 | }
|
|---|
| 1129 |
|
|---|
| 1130 | }
|
|---|
| 1131 | G4cout<<"iIn = "<<iIn<<"; iOut = "<<iOut<<G4endl;
|
|---|
| 1132 | G4cout<<"iInNoSurf = "<<iInNoSurf<<"; iOutNoSurf = "<<iOutNoSurf<<G4endl;
|
|---|
| 1133 |
|
|---|
| 1134 |
|
|---|
| 1135 | break;
|
|---|
| 1136 |
|
|---|
| 1137 | case kTubs:
|
|---|
| 1138 |
|
|---|
| 1139 | G4cout<<"Testing G4Tubs:"<<G4endl<<G4endl;
|
|---|
| 1140 |
|
|---|
| 1141 | iInNoSurf = 0, iOutNoSurf = 0, iIn = 0, iOut = 0;
|
|---|
| 1142 |
|
|---|
| 1143 | for( i = 0; i < iMax; i++)
|
|---|
| 1144 | {
|
|---|
| 1145 | if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
|
|---|
| 1146 |
|
|---|
| 1147 | G4ThreeVector pA = GetVectorAroundTubs(t1);
|
|---|
| 1148 | G4ThreeVector pS = GetVectorOnTubs(t1); // , normP);
|
|---|
| 1149 |
|
|---|
| 1150 | G4ThreeVector dP = pS - pA;
|
|---|
| 1151 |
|
|---|
| 1152 | if ( dP.mag2() > 0.)
|
|---|
| 1153 | {
|
|---|
| 1154 | distCheck = dP.mag();
|
|---|
| 1155 | vCheck = dP.unit();
|
|---|
| 1156 | // G4cout<<"distCheck ="<< distCheck<<"; dP.unit() mag = "<<dP.mag()<<G4endl;
|
|---|
| 1157 | }
|
|---|
| 1158 | else continue;
|
|---|
| 1159 |
|
|---|
| 1160 | surfaceP = t1.Inside(pS);
|
|---|
| 1161 |
|
|---|
| 1162 | if( surfaceP == kSurface )
|
|---|
| 1163 | {
|
|---|
| 1164 | surfaceA = t1.Inside(pA);
|
|---|
| 1165 |
|
|---|
| 1166 | if( surfaceA == kOutside )
|
|---|
| 1167 | {
|
|---|
| 1168 | norm = t1.SurfaceNormal(pS);
|
|---|
| 1169 |
|
|---|
| 1170 | if ( dP.dot(norm) < 0. ) // may be < strictly?
|
|---|
| 1171 | {
|
|---|
| 1172 | iIn++;
|
|---|
| 1173 |
|
|---|
| 1174 | distIn = t1.DistanceToIn(pA,vCheck);
|
|---|
| 1175 |
|
|---|
| 1176 | dDist = distIn - distCheck;
|
|---|
| 1177 |
|
|---|
| 1178 | // G4cout<<" distIn = "<<distIn<<"; distCheck = "<<distCheck<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1179 |
|
|---|
| 1180 | dDist *= 10./kRadTolerance;
|
|---|
| 1181 |
|
|---|
| 1182 | for( j = 0; j < jMax; j++ )
|
|---|
| 1183 | {
|
|---|
| 1184 | position = -25. + j;
|
|---|
| 1185 | if ( dDist < position )
|
|---|
| 1186 | {
|
|---|
| 1187 | dIn[j] += 1.;
|
|---|
| 1188 | break;
|
|---|
| 1189 | }
|
|---|
| 1190 | else continue;
|
|---|
| 1191 | }
|
|---|
| 1192 | if ( j == jMax ) dIn[jMax-1] += 1.;
|
|---|
| 1193 | if ( j == jMax || j == 0 )
|
|---|
| 1194 | {
|
|---|
| 1195 | // G4cout<<"distIn = "<<distIn<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1196 | // G4cout<<"distCheck = "<<distCheck<<"; vCheck.dot( pS.unit() ) = "
|
|---|
| 1197 | // <<vCheck.dot( pS.unit() )<<G4endl;
|
|---|
| 1198 | }
|
|---|
| 1199 | }
|
|---|
| 1200 | else continue;
|
|---|
| 1201 | }
|
|---|
| 1202 | else
|
|---|
| 1203 | {
|
|---|
| 1204 | iOut++;
|
|---|
| 1205 |
|
|---|
| 1206 | distOut = t1.DistanceToOut(pA,vCheck,calcNorm,pgoodNorm,pNorm);
|
|---|
| 1207 |
|
|---|
| 1208 | dDist = distOut - distCheck;
|
|---|
| 1209 |
|
|---|
| 1210 | // G4cout<<" distOut = "<<distOut<<"; distCheck = "<<distCheck<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1211 |
|
|---|
| 1212 | dDist *= 10./kRadTolerance;
|
|---|
| 1213 |
|
|---|
| 1214 | for( j = 0; j < jMax; j++ )
|
|---|
| 1215 | {
|
|---|
| 1216 | position = -25. + j;
|
|---|
| 1217 | if ( dDist < position )
|
|---|
| 1218 | {
|
|---|
| 1219 | dOut[j] += 1.;
|
|---|
| 1220 | break;
|
|---|
| 1221 | }
|
|---|
| 1222 | else continue;
|
|---|
| 1223 | }
|
|---|
| 1224 | if ( j == jMax) dOut[jMax-1] += 1.;
|
|---|
| 1225 | }
|
|---|
| 1226 | }
|
|---|
| 1227 | else
|
|---|
| 1228 | {
|
|---|
| 1229 | G4cout<<"pS is out of tubs surface: "<<pS.x()<<"\t"<<pS.y()<<"\t"<<pS.z()<<G4endl;
|
|---|
| 1230 | }
|
|---|
| 1231 | }
|
|---|
| 1232 | G4cout<<"iIn = "<<iIn<<"; iOut = "<<iOut<<G4endl;
|
|---|
| 1233 | G4cout<<"iInNoSurf = "<<iInNoSurf<<"; iOutNoSurf = "<<iOutNoSurf<<G4endl<<G4endl;
|
|---|
| 1234 |
|
|---|
| 1235 | G4cout<<"iIn = "<<iIn<<G4endl<<G4endl;
|
|---|
| 1236 | for( j = 0; j < jMax; j++ )
|
|---|
| 1237 | {
|
|---|
| 1238 | position = -25. + j;
|
|---|
| 1239 | G4cout<<position<<"\t"<<dIn[j]<<G4endl;
|
|---|
| 1240 | foutDistIn<<position<<"\t"<<dIn[j]<<G4endl;
|
|---|
| 1241 | }
|
|---|
| 1242 | G4cout<<G4endl;
|
|---|
| 1243 | G4cout<<"iOut = "<<iOut<<G4endl<<G4endl;
|
|---|
| 1244 | for( j = 0; j < jMax; j++ )
|
|---|
| 1245 | {
|
|---|
| 1246 | position = -25. + j;
|
|---|
| 1247 | G4cout<<position<<"\t"<<dOut[j]<<G4endl;
|
|---|
| 1248 | foutDistOut<<position<<"\t"<<dOut[j]<<G4endl;
|
|---|
| 1249 | }
|
|---|
| 1250 |
|
|---|
| 1251 | break;
|
|---|
| 1252 |
|
|---|
| 1253 | case kCons:
|
|---|
| 1254 |
|
|---|
| 1255 | G4cout<<"Testing G4Cons:"<<G4endl<<G4endl;
|
|---|
| 1256 |
|
|---|
| 1257 |
|
|---|
| 1258 | iInNoSurf = 0, iOutNoSurf = 0, iIn = 0, iOut = 0;
|
|---|
| 1259 |
|
|---|
| 1260 | for( i = 0; i < iMax; i++)
|
|---|
| 1261 | {
|
|---|
| 1262 | if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
|
|---|
| 1263 |
|
|---|
| 1264 | G4ThreeVector pA = GetVectorAroundCons(c1);
|
|---|
| 1265 | G4ThreeVector pS = GetVectorOnCons(c1); // , normP);
|
|---|
| 1266 |
|
|---|
| 1267 | G4ThreeVector dP = pS - pA;
|
|---|
| 1268 |
|
|---|
| 1269 | if ( dP.mag2() > 0.)
|
|---|
| 1270 | {
|
|---|
| 1271 | distCheck = dP.mag();
|
|---|
| 1272 | vCheck = dP.unit();
|
|---|
| 1273 | // G4cout<<"distCheck ="<< distCheck<<"; dP.unit() mag = "<<dP.mag()<<G4endl;
|
|---|
| 1274 | }
|
|---|
| 1275 | else continue;
|
|---|
| 1276 |
|
|---|
| 1277 | surfaceP = c1.Inside(pS);
|
|---|
| 1278 |
|
|---|
| 1279 | if( surfaceP == kSurface )
|
|---|
| 1280 | {
|
|---|
| 1281 | surfaceA = c1.Inside(pA);
|
|---|
| 1282 |
|
|---|
| 1283 | if( surfaceA == kOutside )
|
|---|
| 1284 | {
|
|---|
| 1285 | norm = c1.SurfaceNormal(pS);
|
|---|
| 1286 |
|
|---|
| 1287 | if ( dP.dot(norm) < 0. ) // may be < strictly?
|
|---|
| 1288 | {
|
|---|
| 1289 | iIn++;
|
|---|
| 1290 |
|
|---|
| 1291 | distIn = c1.DistanceToIn(pA,vCheck);
|
|---|
| 1292 |
|
|---|
| 1293 | dDist = distIn - distCheck;
|
|---|
| 1294 |
|
|---|
| 1295 | // G4cout<<" distIn = "<<distIn<<"; distCheck = "<<distCheck<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1296 |
|
|---|
| 1297 | dDist *= 10./kRadTolerance;
|
|---|
| 1298 |
|
|---|
| 1299 | for( j = 0; j < jMax; j++ )
|
|---|
| 1300 | {
|
|---|
| 1301 | position = -25. + j;
|
|---|
| 1302 | if ( dDist < position )
|
|---|
| 1303 | {
|
|---|
| 1304 | dIn[j] += 1.;
|
|---|
| 1305 | break;
|
|---|
| 1306 | }
|
|---|
| 1307 | else continue;
|
|---|
| 1308 | }
|
|---|
| 1309 | if ( j == jMax ) dIn[jMax-1] += 1.;
|
|---|
| 1310 | if ( j == jMax || j == 0 )
|
|---|
| 1311 | {
|
|---|
| 1312 | // G4cout<<"distIn = "<<distIn<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1313 | // G4cout<<"distCheck = "<<distCheck<<"; vCheck.dot( pS.unit() ) = "
|
|---|
| 1314 | // <<vCheck.dot( pS.unit() )<<G4endl;
|
|---|
| 1315 | }
|
|---|
| 1316 | }
|
|---|
| 1317 | else continue;
|
|---|
| 1318 | }
|
|---|
| 1319 | else
|
|---|
| 1320 | {
|
|---|
| 1321 | iOut++;
|
|---|
| 1322 |
|
|---|
| 1323 | distOut = c1.DistanceToOut(pA,vCheck,calcNorm,pgoodNorm,pNorm);
|
|---|
| 1324 |
|
|---|
| 1325 | dDist = distOut - distCheck;
|
|---|
| 1326 |
|
|---|
| 1327 | // G4cout<<" distOut = "<<distOut<<"; distCheck = "<<distCheck<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1328 |
|
|---|
| 1329 | dDist *= 10./kRadTolerance;
|
|---|
| 1330 |
|
|---|
| 1331 | for( j = 0; j < jMax; j++ )
|
|---|
| 1332 | {
|
|---|
| 1333 | position = -25. + j;
|
|---|
| 1334 | if ( dDist < position )
|
|---|
| 1335 | {
|
|---|
| 1336 | dOut[j] += 1.;
|
|---|
| 1337 | break;
|
|---|
| 1338 | }
|
|---|
| 1339 | else continue;
|
|---|
| 1340 | }
|
|---|
| 1341 | if ( j == jMax) dOut[jMax-1] += 1.;
|
|---|
| 1342 | }
|
|---|
| 1343 | }
|
|---|
| 1344 | else
|
|---|
| 1345 | {
|
|---|
| 1346 | // G4cout<<"pS is out of cons surface: "<<pS.x()<<"\t"<<pS.y()<<"\t"<<pS.z()<<G4endl;
|
|---|
| 1347 | }
|
|---|
| 1348 | }
|
|---|
| 1349 | G4cout<<"iIn = "<<iIn<<"; iOut = "<<iOut<<G4endl;
|
|---|
| 1350 | G4cout<<"iInNoSurf = "<<iInNoSurf<<"; iOutNoSurf = "<<iOutNoSurf<<G4endl<<G4endl;
|
|---|
| 1351 |
|
|---|
| 1352 | G4cout<<"iIn = "<<iIn<<G4endl<<G4endl;
|
|---|
| 1353 | for( j = 0; j < jMax; j++ )
|
|---|
| 1354 | {
|
|---|
| 1355 | position = -25. + j;
|
|---|
| 1356 | G4cout<<position<<"\t"<<dIn[j]<<G4endl;
|
|---|
| 1357 | foutDistIn<<position<<"\t"<<dIn[j]<<G4endl;
|
|---|
| 1358 | }
|
|---|
| 1359 | G4cout<<G4endl;
|
|---|
| 1360 | G4cout<<"iOut = "<<iOut<<G4endl<<G4endl;
|
|---|
| 1361 | for( j = 0; j < jMax; j++ )
|
|---|
| 1362 | {
|
|---|
| 1363 | position = -25. + j;
|
|---|
| 1364 | G4cout<<position<<"\t"<<dOut[j]<<G4endl;
|
|---|
| 1365 | foutDistOut<<position<<"\t"<<dOut[j]<<G4endl;
|
|---|
| 1366 | }
|
|---|
| 1367 |
|
|---|
| 1368 | break;
|
|---|
| 1369 |
|
|---|
| 1370 | case kTorus:
|
|---|
| 1371 |
|
|---|
| 1372 | G4cout<<"Testing all cutted G4Torus:"<<G4endl<<G4endl;
|
|---|
| 1373 |
|
|---|
| 1374 |
|
|---|
| 1375 |
|
|---|
| 1376 | iInNoSurf = 0, iOutNoSurf = 0, iIn = 0, iOut = 0;
|
|---|
| 1377 |
|
|---|
| 1378 | for( i = 0; i < iMax; i++)
|
|---|
| 1379 | {
|
|---|
| 1380 | if(i%iCheck == 0) G4cout<<"i = "<<i<<G4endl;
|
|---|
| 1381 |
|
|---|
| 1382 | G4ThreeVector pA = GetVectorAroundTorus(tor1);
|
|---|
| 1383 | G4ThreeVector pS = GetVectorOnTorus(tor1); // , normP);
|
|---|
| 1384 |
|
|---|
| 1385 | G4ThreeVector dP = pS - pA;
|
|---|
| 1386 |
|
|---|
| 1387 | if ( dP.mag2() > 0.)
|
|---|
| 1388 | {
|
|---|
| 1389 | distCheck = dP.mag();
|
|---|
| 1390 | vCheck = dP.unit();
|
|---|
| 1391 | // G4cout<<"distCheck ="<< distCheck<<"; dP.unit() mag = "<<dP.mag()<<G4endl;
|
|---|
| 1392 | }
|
|---|
| 1393 | else continue;
|
|---|
| 1394 |
|
|---|
| 1395 | surfaceP = tor1.Inside(pS);
|
|---|
| 1396 |
|
|---|
| 1397 | if( surfaceP == kSurface )
|
|---|
| 1398 | {
|
|---|
| 1399 | surfaceA = tor1.Inside(pA);
|
|---|
| 1400 |
|
|---|
| 1401 | if( surfaceA == kOutside )
|
|---|
| 1402 | {
|
|---|
| 1403 | norm = tor1.SurfaceNormal(pS);
|
|---|
| 1404 |
|
|---|
| 1405 | if ( dP.dot(norm) < 0. ) // may be < strictly?
|
|---|
| 1406 | {
|
|---|
| 1407 | iIn++;
|
|---|
| 1408 |
|
|---|
| 1409 | distIn = tor1.DistanceToIn(pA,vCheck);
|
|---|
| 1410 |
|
|---|
| 1411 | dDist = distIn - distCheck;
|
|---|
| 1412 |
|
|---|
| 1413 | // G4cout<<" distIn = "<<distIn<<"; distCheck = "<<distCheck<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1414 |
|
|---|
| 1415 | dDist *= 10./kRadTolerance;
|
|---|
| 1416 |
|
|---|
| 1417 | for( j = 0; j < jMax; j++ )
|
|---|
| 1418 | {
|
|---|
| 1419 | position = -25. + j;
|
|---|
| 1420 | if ( dDist < position )
|
|---|
| 1421 | {
|
|---|
| 1422 | dIn[j] += 1.;
|
|---|
| 1423 | break;
|
|---|
| 1424 | }
|
|---|
| 1425 | else continue;
|
|---|
| 1426 | }
|
|---|
| 1427 | if ( j == jMax ) dIn[jMax-1] += 1.;
|
|---|
| 1428 | if ( j == jMax || j == 0 )
|
|---|
| 1429 | {
|
|---|
| 1430 | // G4cout<<"distIn = "<<distIn<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1431 | // G4cout<<"distCheck = "<<distCheck<<"; vCheck.dot( pS.unit() ) = "
|
|---|
| 1432 | // <<vCheck.dot( pS.unit() )<<G4endl;
|
|---|
| 1433 | }
|
|---|
| 1434 | }
|
|---|
| 1435 | else continue;
|
|---|
| 1436 | }
|
|---|
| 1437 | else
|
|---|
| 1438 | {
|
|---|
| 1439 | iOut++;
|
|---|
| 1440 |
|
|---|
| 1441 | distOut = tor1.DistanceToOut(pA,vCheck,calcNorm,pgoodNorm,pNorm);
|
|---|
| 1442 |
|
|---|
| 1443 | dDist = distOut - distCheck;
|
|---|
| 1444 |
|
|---|
| 1445 | // G4cout<<" distOut = "<<distOut<<"; distCheck = "<<distCheck<<"; dDist = "<<dDist<<G4endl;
|
|---|
| 1446 |
|
|---|
| 1447 | dDist *= 10./kRadTolerance;
|
|---|
| 1448 |
|
|---|
| 1449 | for( j = 0; j < jMax; j++ )
|
|---|
| 1450 | {
|
|---|
| 1451 | position = -25. + j;
|
|---|
| 1452 | if ( dDist < position )
|
|---|
| 1453 | {
|
|---|
| 1454 | dOut[j] += 1.;
|
|---|
| 1455 | break;
|
|---|
| 1456 | }
|
|---|
| 1457 | else continue;
|
|---|
| 1458 | }
|
|---|
| 1459 | if ( j == jMax) dOut[jMax-1] += 1.;
|
|---|
| 1460 | }
|
|---|
| 1461 | }
|
|---|
| 1462 | else
|
|---|
| 1463 | {
|
|---|
| 1464 | // G4cout<<"pS is out of cons surface: "<<pS.x()<<"\t"<<pS.y()<<"\t"<<pS.z()<<G4endl;
|
|---|
| 1465 | }
|
|---|
| 1466 | }
|
|---|
| 1467 | G4cout<<"iIn = "<<iIn<<"; iOut = "<<iOut<<G4endl;
|
|---|
| 1468 | G4cout<<"iInNoSurf = "<<iInNoSurf<<"; iOutNoSurf = "<<iOutNoSurf<<G4endl<<G4endl;
|
|---|
| 1469 |
|
|---|
| 1470 | G4cout<<"iIn = "<<iIn<<G4endl<<G4endl;
|
|---|
| 1471 | for( j = 0; j < jMax; j++ )
|
|---|
| 1472 | {
|
|---|
| 1473 | position = -25. + j;
|
|---|
| 1474 | G4cout<<position<<"\t"<<dIn[j]<<G4endl;
|
|---|
| 1475 | foutDistIn<<position<<"\t"<<dIn[j]<<G4endl;
|
|---|
| 1476 | }
|
|---|
| 1477 | G4cout<<G4endl;
|
|---|
| 1478 | G4cout<<"iOut = "<<iOut<<G4endl<<G4endl;
|
|---|
| 1479 | for( j = 0; j < jMax; j++ )
|
|---|
| 1480 | {
|
|---|
| 1481 | position = -25. + j;
|
|---|
| 1482 | G4cout<<position<<"\t"<<dOut[j]<<G4endl;
|
|---|
| 1483 | foutDistOut<<position<<"\t"<<dOut[j]<<G4endl;
|
|---|
| 1484 | }
|
|---|
| 1485 |
|
|---|
| 1486 | break;
|
|---|
| 1487 |
|
|---|
| 1488 | default:
|
|---|
| 1489 | G4cout<<"A test is not implemented for this case: " << useCase <<G4endl<<G4endl;
|
|---|
| 1490 |
|
|---|
| 1491 | break;
|
|---|
| 1492 | }
|
|---|
| 1493 | return 0;
|
|---|
| 1494 | }
|
|---|
| 1495 |
|
|---|