Changeset 921 for trunk/source/geometry/solids/CSG/src/G4Tubs.cc
- Timestamp:
- Feb 16, 2009, 10:14:30 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/geometry/solids/CSG/src/G4Tubs.cc
r850 r921 25 25 // 26 26 // 27 // $Id: G4Tubs.cc,v 1. 68 2008/06/23 13:37:39gcosmo Exp $28 // GEANT4 tag $Name: HEAD$27 // $Id: G4Tubs.cc,v 1.74 2008/11/06 15:26:53 gcosmo Exp $ 28 // GEANT4 tag $Name: geant4-09-02-cand-01 $ 29 29 // 30 30 // … … 108 108 "Invalid Z half-length"); 109 109 } 110 if ( pRMin < pRMax && pRMin >= 0) // Check radii110 if ( (pRMin < pRMax) && (pRMin >= 0) ) // Check radii 111 111 { 112 112 fRMin = pRMin ; … … 121 121 "Invalid radii."); 122 122 } 123 if ( pDPhi >= twopi ) // Check angles 123 124 fPhiFullTube = true; 125 if ( pDPhi >= twopi-kAngTolerance*0.5 ) // Check angles 124 126 { 125 127 fDPhi=twopi; 128 fSPhi=0; 126 129 } 127 130 else 128 131 { 132 fPhiFullTube = false; 129 133 if ( pDPhi > 0 ) 130 134 { … … 136 140 << " Negative delta-Phi ! - " 137 141 << pDPhi << G4endl; 138 G4Exception("G4Tubs::G4Tubs()", "InvalidSetup", FatalException, 139 "Invalid dphi."); 140 } 141 } 142 143 // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0 144 145 fSPhi = pSPhi; 146 147 if ( fSPhi < 0 ) 148 { 149 fSPhi = twopi - std::fmod(std::fabs(fSPhi),twopi) ; 150 } 151 else 152 { 153 fSPhi = std::fmod(fSPhi,twopi) ; 154 } 155 if (fSPhi + fDPhi > twopi ) 156 { 157 fSPhi -= twopi ; 158 } 142 G4Exception("G4Tubs::G4Tubs()", "InvalidSetup", 143 FatalException, "Invalid dphi."); 144 } 145 146 // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0 147 148 if ( pSPhi < 0 ) 149 { 150 fSPhi = twopi - std::fmod(std::fabs(pSPhi),twopi); 151 } 152 else 153 { 154 fSPhi = std::fmod(pSPhi,twopi) ; 155 } 156 if ( fSPhi+fDPhi > twopi ) 157 { 158 fSPhi -= twopi ; 159 } 160 } 161 InitializeTrigonometry(); 159 162 } 160 163 … … 290 293 yoff2 = yMax - yoffset ; 291 294 292 if ( yoff1 >= 0 && yoff2 >= 0 ) // Y limits cross max/min x => no change293 { 295 if ( (yoff1 >= 0) && (yoff2 >= 0) ) // Y limits cross max/min x 296 { // => no change 294 297 pMin = xMin ; 295 298 pMax = xMax ; … … 317 320 xoff2 = xMax - xoffset ; 318 321 319 if ( xoff1 >= 0 && xoff2 >= 0 ) // X limits cross max/min y => no change320 { 322 if ( (xoff1 >= 0) && (xoff2 >= 0) ) // X limits cross max/min y 323 { // => no change 321 324 pMin = yMin ; 322 325 pMax = yMax ; … … 363 366 noEntries = vertices->size() ; 364 367 noBetweenSections4 = noEntries - 4 ; 365 /* 366 G4cout << "vertices = " << noEntries << "\t" 367 << "v-4 = " << noBetweenSections4 << G4endl; 368 G4cout << G4endl; 369 for(i = 0 ; i < noEntries ; i++ ) 370 { 371 G4cout << i << "\t" << "v.x = " << ((*vertices)[i]).x() << "\t" 372 << "v.y = " << ((*vertices)[i]).y() << "\t" 373 << "v.z = " << ((*vertices)[i]).z() << "\t" << G4endl; 374 } 375 G4cout << G4endl; 376 G4cout << "ClipCrossSection" << G4endl; 377 */ 368 378 369 for (i = 0 ; i < noEntries ; i += 4 ) 379 370 { 380 // G4cout << "section = " << i << G4endl; 381 ClipCrossSection(vertices,i,pVoxelLimit,pAxis,pMin,pMax) ; 382 } 383 // G4cout << "ClipBetweenSections" << G4endl; 371 ClipCrossSection(vertices, i, pVoxelLimit, pAxis, pMin, pMax) ; 372 } 384 373 for (i = 0 ; i < noBetweenSections4 ; i += 4 ) 385 374 { 386 // G4cout << "between sections = " << i << G4endl; 387 ClipBetweenSections(vertices,i,pVoxelLimit,pAxis,pMin,pMax) ; 388 } 389 if (pMin != kInfinity || pMax != -kInfinity ) 375 ClipBetweenSections(vertices, i, pVoxelLimit, pAxis, pMin, pMax) ; 376 } 377 if ((pMin != kInfinity) || (pMax != -kInfinity) ) 390 378 { 391 379 existsAfterClip = true ; … … 426 414 G4double r2,pPhi,tolRMin,tolRMax; 427 415 EInside in = kOutside ; 428 429 if (std::fabs(p.z()) <= fDz - kCarTolerance*0.5) 416 static const G4double halfCarTolerance=kCarTolerance*0.5; 417 static const G4double halfRadTolerance=kRadTolerance*0.5; 418 static const G4double halfAngTolerance=kAngTolerance*0.5; 419 420 if (std::fabs(p.z()) <= fDz - halfCarTolerance) 430 421 { 431 422 r2 = p.x()*p.x() + p.y()*p.y() ; 432 423 433 if (fRMin) { tolRMin = fRMin + kRadTolerance*0.5; }424 if (fRMin) { tolRMin = fRMin + halfRadTolerance ; } 434 425 else { tolRMin = 0 ; } 435 426 436 tolRMax = fRMax - kRadTolerance*0.5;427 tolRMax = fRMax - halfRadTolerance ; 437 428 438 if ( r2 >= tolRMin*tolRMin && r2 <= tolRMax*tolRMax)439 { 440 if ( f DPhi == twopi)429 if ((r2 >= tolRMin*tolRMin) && (r2 <= tolRMax*tolRMax)) 430 { 431 if ( fPhiFullTube ) 441 432 { 442 433 in = kInside ; … … 447 438 // if not inside, try outer tolerant phi boundaries 448 439 449 pPhi = std::atan2(p.y(),p.x()) ; 450 if ((tolRMin==0)&&(p.x()==0)&&(p.y()==0)) 440 if ((tolRMin==0)&&(p.x()<=halfCarTolerance)&&(p.y()<=halfCarTolerance)) 451 441 { 452 442 in=kSurface; … … 454 444 else 455 445 { 456 if ( pPhi < -kAngTolerance*0.5 ) { pPhi += twopi; } // 0<=pPhi<2pi 446 pPhi = std::atan2(p.y(),p.x()) ; 447 if ( pPhi < -halfAngTolerance ) { pPhi += twopi; } // 0<=pPhi<2pi 457 448 458 449 if ( fSPhi >= 0 ) 459 450 { 460 if ( (std::abs(pPhi) < kAngTolerance*0.5)461 && (std::abs(fSPhi + fDPhi - twopi) < kAngTolerance*0.5) )451 if ( (std::abs(pPhi) < halfAngTolerance) 452 && (std::abs(fSPhi + fDPhi - twopi) < halfAngTolerance) ) 462 453 { 463 454 pPhi += twopi ; // 0 <= pPhi < 2pi 464 455 } 465 if ( (pPhi >= fSPhi + kAngTolerance*0.5)466 && (pPhi <= fSPhi + fDPhi - kAngTolerance*0.5) )456 if ( (pPhi >= fSPhi + halfAngTolerance) 457 && (pPhi <= fSPhi + fDPhi - halfAngTolerance) ) 467 458 { 468 459 in = kInside ; 469 460 } 470 else if ( (pPhi >= fSPhi - kAngTolerance*0.5)471 && (pPhi <= fSPhi + fDPhi + kAngTolerance*0.5) )461 else if ( (pPhi >= fSPhi - halfAngTolerance) 462 && (pPhi <= fSPhi + fDPhi + halfAngTolerance) ) 472 463 { 473 464 in = kSurface ; … … 476 467 else // fSPhi < 0 477 468 { 478 if ( (pPhi <= fSPhi + twopi - kAngTolerance*0.5)479 && (pPhi >= fSPhi + fDPhi + kAngTolerance*0.5) ) {;}480 else if ( (pPhi <= fSPhi + twopi + kAngTolerance*0.5)481 && (pPhi >= fSPhi + fDPhi - kAngTolerance*0.5) )469 if ( (pPhi <= fSPhi + twopi - halfAngTolerance) 470 && (pPhi >= fSPhi + fDPhi + halfAngTolerance) ) {;} //kOutside 471 else if ( (pPhi <= fSPhi + twopi + halfAngTolerance) 472 && (pPhi >= fSPhi + fDPhi - halfAngTolerance) ) 482 473 { 483 474 in = kSurface ; … … 493 484 else // Try generous boundaries 494 485 { 495 tolRMin = fRMin - kRadTolerance*0.5;496 tolRMax = fRMax + kRadTolerance*0.5;486 tolRMin = fRMin - halfRadTolerance ; 487 tolRMax = fRMax + halfRadTolerance ; 497 488 498 489 if ( tolRMin < 0 ) { tolRMin = 0; } … … 500 491 if ( (r2 >= tolRMin*tolRMin) && (r2 <= tolRMax*tolRMax) ) 501 492 { 502 if ( fDPhi == twopi || r2 == 0 ) // Continuous in phi or on z-axis503 { 493 if (fPhiFullTube || (r2 <=halfRadTolerance*halfRadTolerance) ) 494 { // Continuous in phi or on z-axis 504 495 in = kSurface ; 505 496 } … … 508 499 pPhi = std::atan2(p.y(),p.x()) ; 509 500 510 if ( pPhi < - kAngTolerance*0.5) { pPhi += twopi; } // 0<=pPhi<2pi501 if ( pPhi < -halfAngTolerance) { pPhi += twopi; } // 0<=pPhi<2pi 511 502 if ( fSPhi >= 0 ) 512 503 { 513 if ( (std::abs(pPhi) < kAngTolerance*0.5)514 && (std::abs(fSPhi + fDPhi - twopi) < kAngTolerance*0.5) )504 if ( (std::abs(pPhi) < halfAngTolerance) 505 && (std::abs(fSPhi + fDPhi - twopi) < halfAngTolerance) ) 515 506 { 516 507 pPhi += twopi ; // 0 <= pPhi < 2pi 517 508 } 518 if ( (pPhi >= fSPhi - kAngTolerance*0.5)519 && (pPhi <= fSPhi + fDPhi + kAngTolerance*0.5) )509 if ( (pPhi >= fSPhi - halfAngTolerance) 510 && (pPhi <= fSPhi + fDPhi + halfAngTolerance) ) 520 511 { 521 512 in = kSurface ; … … 524 515 else // fSPhi < 0 525 516 { 526 if ( (pPhi <= fSPhi + twopi - kAngTolerance*0.5)527 && (pPhi >= fSPhi + fDPhi + kAngTolerance*0.5) ) {;}517 if ( (pPhi <= fSPhi + twopi - halfAngTolerance) 518 && (pPhi >= fSPhi + fDPhi + halfAngTolerance) ) {;} // kOutside 528 519 else 529 520 { … … 535 526 } 536 527 } 537 else if (std::fabs(p.z()) <= fDz + kCarTolerance*0.5)528 else if (std::fabs(p.z()) <= fDz + halfCarTolerance) 538 529 { // Check within tolerant r limits 539 530 r2 = p.x()*p.x() + p.y()*p.y() ; 540 tolRMin = fRMin - kRadTolerance*0.5;541 tolRMax = fRMax + kRadTolerance*0.5;531 tolRMin = fRMin - halfRadTolerance ; 532 tolRMax = fRMax + halfRadTolerance ; 542 533 543 534 if ( tolRMin < 0 ) { tolRMin = 0; } … … 545 536 if ( (r2 >= tolRMin*tolRMin) && (r2 <= tolRMax*tolRMax) ) 546 537 { 547 if (f DPhi == twopi || r2 == 0 ) // Continuous in phi or on z-axis548 { 538 if (fPhiFullTube || (r2 <=halfRadTolerance*halfRadTolerance)) 539 { // Continuous in phi or on z-axis 549 540 in = kSurface ; 550 541 } … … 553 544 pPhi = std::atan2(p.y(),p.x()) ; 554 545 555 if ( pPhi < - kAngTolerance*0.5) { pPhi += twopi; } // 0<=pPhi<2pi546 if ( pPhi < -halfAngTolerance ) { pPhi += twopi; } // 0<=pPhi<2pi 556 547 if ( fSPhi >= 0 ) 557 548 { 558 if ( (std::abs(pPhi) < kAngTolerance*0.5)559 && (std::abs(fSPhi + fDPhi - twopi) < kAngTolerance*0.5) )549 if ( (std::abs(pPhi) < halfAngTolerance) 550 && (std::abs(fSPhi + fDPhi - twopi) < halfAngTolerance) ) 560 551 { 561 552 pPhi += twopi ; // 0 <= pPhi < 2pi 562 553 } 563 if ( (pPhi >= fSPhi - kAngTolerance*0.5)564 && (pPhi <= fSPhi + fDPhi + kAngTolerance*0.5) )554 if ( (pPhi >= fSPhi - halfAngTolerance) 555 && (pPhi <= fSPhi + fDPhi + halfAngTolerance) ) 565 556 { 566 557 in = kSurface; … … 569 560 else // fSPhi < 0 570 561 { 571 if ( (pPhi <= fSPhi + twopi - kAngTolerance*0.5)572 && (pPhi >= fSPhi + fDPhi + kAngTolerance*0.5) ) {;}562 if ( (pPhi <= fSPhi + twopi - halfAngTolerance) 563 && (pPhi >= fSPhi + fDPhi + halfAngTolerance) ) {;} 573 564 else 574 565 { … … 589 580 590 581 G4ThreeVector G4Tubs::SurfaceNormal( const G4ThreeVector& p ) const 591 { G4int noSurfaces = 0; 582 { 583 G4int noSurfaces = 0; 592 584 G4double rho, pPhi; 593 G4double delta = 0.5*kCarTolerance, dAngle = 0.5*kAngTolerance;594 585 G4double distZ, distRMin, distRMax; 595 586 G4double distSPhi = kInfinity, distEPhi = kInfinity; 587 588 static const G4double halfCarTolerance = 0.5*kCarTolerance; 589 static const G4double halfAngTolerance = 0.5*kAngTolerance; 590 596 591 G4ThreeVector norm, sumnorm(0.,0.,0.); 597 592 G4ThreeVector nZ = G4ThreeVector(0, 0, 1.0); … … 604 599 distZ = std::fabs(std::fabs(p.z()) - fDz); 605 600 606 if ( fDPhi < twopi) // && rho )// Protected against (0,0,z)607 { 608 if ( rho )601 if (!fPhiFullTube) // Protected against (0,0,z) 602 { 603 if ( rho > halfCarTolerance ) 609 604 { 610 605 pPhi = std::atan2(p.y(),p.x()); 611 606 612 if(pPhi < fSPhi- delta) { pPhi += twopi; }613 else if(pPhi > fSPhi+fDPhi+ delta) { pPhi -= twopi; }614 615 distSPhi = std::fabs( pPhi - fSPhi);607 if(pPhi < fSPhi- halfCarTolerance) { pPhi += twopi; } 608 else if(pPhi > fSPhi+fDPhi+ halfCarTolerance) { pPhi -= twopi; } 609 610 distSPhi = std::fabs(pPhi - fSPhi); 616 611 distEPhi = std::fabs(pPhi - fSPhi - fDPhi); 617 612 } … … 624 619 nPe = G4ThreeVector(-std::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0); 625 620 } 626 if ( rho > delta ){ nR = G4ThreeVector(p.x()/rho,p.y()/rho,0); }627 628 if( distRMax <= delta)621 if ( rho > halfCarTolerance ) { nR = G4ThreeVector(p.x()/rho,p.y()/rho,0); } 622 623 if( distRMax <= halfCarTolerance ) 629 624 { 630 625 noSurfaces ++; 631 626 sumnorm += nR; 632 627 } 633 if( fRMin && distRMin <= delta)628 if( fRMin && (distRMin <= halfCarTolerance) ) 634 629 { 635 630 noSurfaces ++; … … 638 633 if( fDPhi < twopi ) 639 634 { 640 if (distSPhi <= dAngle) // delta)635 if (distSPhi <= halfAngTolerance) 641 636 { 642 637 noSurfaces ++; 643 638 sumnorm += nPs; 644 639 } 645 if (distEPhi <= dAngle) // delta)640 if (distEPhi <= halfAngTolerance) 646 641 { 647 642 noSurfaces ++; … … 649 644 } 650 645 } 651 if (distZ <= delta)646 if (distZ <= halfCarTolerance) 652 647 { 653 648 noSurfaces ++; … … 668 663 else if ( noSurfaces == 1 ) { norm = sumnorm; } 669 664 else { norm = sumnorm.unit(); } 665 670 666 return norm; 671 667 } … … 714 710 } 715 711 } 716 if ( fDPhi < twopi&& rho ) // Protected against (0,0,z)712 if (!fPhiFullTube && rho ) // Protected against (0,0,z) 717 713 { 718 714 phi = std::atan2(p.y(),p.x()) ; … … 749 745 case kNRMin : // Inner radius 750 746 { 751 norm = G4ThreeVector(-p.x()/rho, -p.y()/rho,0) ;747 norm = G4ThreeVector(-p.x()/rho, -p.y()/rho, 0) ; 752 748 break ; 753 749 } 754 750 case kNRMax : // Outer radius 755 751 { 756 norm = G4ThreeVector(p.x()/rho, p.y()/rho,0) ;752 norm = G4ThreeVector(p.x()/rho, p.y()/rho, 0) ; 757 753 break ; 758 754 } 759 755 case kNZ : // + or - dz 760 756 { 761 if ( p.z() > 0 ) norm = G4ThreeVector(0,0,1) ;762 else norm = G4ThreeVector(0,0,-1) ;757 if ( p.z() > 0 ) { norm = G4ThreeVector(0,0,1) ; } 758 else { norm = G4ThreeVector(0,0,-1); } 763 759 break ; 764 760 } 765 761 case kNSPhi: 766 762 { 767 norm = G4ThreeVector(std::sin(fSPhi), -std::cos(fSPhi),0) ;763 norm = G4ThreeVector(std::sin(fSPhi), -std::cos(fSPhi), 0) ; 768 764 break ; 769 765 } 770 766 case kNEPhi: 771 767 { 772 norm = G4ThreeVector(-std::sin(fSPhi+fDPhi), std::cos(fSPhi+fDPhi),0) ;768 norm = G4ThreeVector(-std::sin(fSPhi+fDPhi), std::cos(fSPhi+fDPhi), 0) ; 773 769 break; 774 770 } … … 804 800 // 805 801 // NOTE: 806 // - Precalculations for phi trigonometry are Done `just in time' 807 // - `if valid' implies tolerant checking of intersection points 802 // - 'if valid' implies tolerant checking of intersection points 808 803 809 804 G4double G4Tubs::DistanceToIn( const G4ThreeVector& p, 810 805 const G4ThreeVector& v ) const 811 806 { 812 G4double snxt = kInfinity ; // snxt = default return value 813 814 // Precalculated trig for phi intersections - used by r,z intersections to 815 // check validity 816 817 G4bool seg ; // true if segmented 818 819 G4double hDPhi, hDPhiOT, hDPhiIT, cosHDPhiOT=0., cosHDPhiIT=0. ; 820 // half dphi + outer tolerance 821 822 G4double cPhi, sinCPhi=0., cosCPhi=0. ; // central phi 823 824 G4double tolORMin2, tolIRMax2 ; // `generous' radii squared 825 807 G4double snxt = kInfinity ; // snxt = default return value 808 G4double tolORMin2, tolIRMax2 ; // 'generous' radii squared 826 809 G4double tolORMax2, tolIRMin2, tolODz, tolIDz ; 810 811 static const G4double halfCarTolerance = 0.5*kCarTolerance; 812 static const G4double halfRadTolerance = 0.5*kRadTolerance; 827 813 828 814 // Intersection point variables 829 815 // 830 G4double Dist, s, xi, yi, zi, rho2, inum, iden, cosPsi ; 831 832 G4double t1, t2, t3, b, c, d ; // Quadratic solver variables 833 834 G4double Comp ; 835 G4double cosSPhi, sinSPhi ; // Trig for phi start intersect 836 837 G4double ePhi, cosEPhi, sinEPhi ; // for phi end intersect 838 839 // Set phi divided flag and precalcs 840 841 if ( fDPhi < twopi ) 842 { 843 seg = true ; 844 hDPhi = 0.5*fDPhi ; // half delta phi 845 cPhi = fSPhi + hDPhi ; 846 hDPhiOT = hDPhi + 0.5*kAngTolerance ; // outers tol' half delta phi 847 hDPhiIT = hDPhi - 0.5*kAngTolerance ; 848 sinCPhi = std::sin(cPhi) ; 849 cosCPhi = std::cos(cPhi) ; 850 cosHDPhiOT = std::cos(hDPhiOT) ; 851 cosHDPhiIT = std::cos(hDPhiIT) ; 852 } 853 else 854 { 855 seg = false ; 856 } 857 816 G4double Dist, s, xi, yi, zi, rho2, inum, iden, cosPsi, Comp ; 817 G4double t1, t2, t3, b, c, d ; // Quadratic solver variables 818 858 819 // Calculate tolerant rmin and rmax 859 820 860 821 if (fRMin > kRadTolerance) 861 822 { 862 tolORMin2 = (fRMin - 0.5*kRadTolerance)*(fRMin - 0.5*kRadTolerance) ;863 tolIRMin2 = (fRMin + 0.5*kRadTolerance)*(fRMin + 0.5*kRadTolerance) ;823 tolORMin2 = (fRMin - halfRadTolerance)*(fRMin - halfRadTolerance) ; 824 tolIRMin2 = (fRMin + halfRadTolerance)*(fRMin + halfRadTolerance) ; 864 825 } 865 826 else … … 868 829 tolIRMin2 = 0.0 ; 869 830 } 870 tolORMax2 = (fRMax + 0.5*kRadTolerance)*(fRMax + 0.5*kRadTolerance) ;871 tolIRMax2 = (fRMax - 0.5*kRadTolerance)*(fRMax - 0.5*kRadTolerance) ;831 tolORMax2 = (fRMax + halfRadTolerance)*(fRMax + halfRadTolerance) ; 832 tolIRMax2 = (fRMax - halfRadTolerance)*(fRMax - halfRadTolerance) ; 872 833 873 834 // Intersection with Z surfaces 874 835 875 tolIDz = fDz - kCarTolerance*0.5;876 tolODz = fDz + kCarTolerance*0.5;836 tolIDz = fDz - halfCarTolerance ; 837 tolODz = fDz + halfCarTolerance ; 877 838 878 839 if (std::fabs(p.z()) >= tolIDz) … … 880 841 if ( p.z()*v.z() < 0 ) // at +Z going in -Z or visa versa 881 842 { 882 s = (std::fabs(p.z()) - fDz)/std::fabs(v.z()) ; 843 s = (std::fabs(p.z()) - fDz)/std::fabs(v.z()) ; // Z intersect distance 883 844 884 845 if(s < 0.0) { s = 0.0; } … … 890 851 // Check validity of intersection 891 852 892 if ( tolIRMin2 <= rho2 && rho2 <= tolIRMax2)893 { 894 if ( seg&& rho2)853 if ((tolIRMin2 <= rho2) && (rho2 <= tolIRMax2)) 854 { 855 if (!fPhiFullTube && rho2) 895 856 { 896 857 // Psi = angle made with central (average) phi of shape … … 899 860 iden = std::sqrt(rho2) ; 900 861 cosPsi = inum/iden ; 901 if (cosPsi >= cosHDPhiIT) return s ;862 if (cosPsi >= cosHDPhiIT) { return s ; } 902 863 } 903 864 else … … 909 870 else 910 871 { 911 if ( snxt< kCarTolerance*0.5) { snxt=0; }872 if ( snxt<halfCarTolerance ) { snxt=0; } 912 873 return snxt ; // On/outside extent, and heading away 913 874 // -> cannot intersect … … 934 895 b = t2/t1 ; 935 896 c = t3 - fRMax*fRMax ; 936 if ( t3 >= tolORMax2 && t2<0) // This also handles the tangent case897 if ((t3 >= tolORMax2) && (t2<0)) // This also handles the tangent case 937 898 { 938 899 // Try outer cylinder intersection … … 954 915 // Z ok. Check phi intersection if reqd 955 916 // 956 if ( !seg)917 if (fPhiFullTube) 957 918 { 958 919 return s ; … … 963 924 yi = p.y() + s*v.y() ; 964 925 cosPsi = (xi*cosCPhi + yi*sinCPhi)/fRMax ; 965 if (cosPsi >= cosHDPhiIT) return s ;926 if (cosPsi >= cosHDPhiIT) { return s ; } 966 927 } 967 928 } // end if std::fabs(zi) … … 974 935 // check not inside, and heading through tubs (-> 0 to in) 975 936 976 if ( t3 > tolIRMin2 && t2 < 0 && std::fabs(p.z()) <= tolIDz)937 if ((t3 > tolIRMin2) && (t2 < 0) && (std::fabs(p.z()) <= tolIDz)) 977 938 { 978 939 // Inside both radii, delta r -ve, inside z extent 979 940 980 if ( seg)941 if (!fPhiFullTube) 981 942 { 982 943 inum = p.x()*cosCPhi + p.y()*sinCPhi ; … … 1004 965 snxt = c/(-b+std::sqrt(d)); // using safe solution 1005 966 // for quadratic equation 1006 if ( snxt <kCarTolerance*0.5) { snxt=0; }967 if ( snxt < halfCarTolerance ) { snxt=0; } 1007 968 return snxt ; 1008 969 } … … 1035 996 snxt= c/(-b+std::sqrt(d)); // using safe solution 1036 997 // for quadratic equation 1037 if ( snxt <kCarTolerance*0.5) { snxt=0; }998 if ( snxt < halfCarTolerance ) { snxt=0; } 1038 999 return snxt ; 1039 1000 } … … 1043 1004 } 1044 1005 } 1045 } // end if ( seg)1006 } // end if (!fPhiFullTube) 1046 1007 } // end if (t3>tolIRMin2) 1047 1008 } // end if (Inside Outer Radius) … … 1056 1017 1057 1018 s = -b + std::sqrt(d) ; 1058 if (s >= - 0.5*kCarTolerance) // check forwards1019 if (s >= -halfCarTolerance) // check forwards 1059 1020 { 1060 1021 // Check z intersection … … 1066 1027 // Z ok. Check phi 1067 1028 // 1068 if ( !seg)1029 if ( fPhiFullTube ) 1069 1030 { 1070 1031 return s ; … … 1098 1059 // -> use some form of loop Construct ? 1099 1060 // 1100 if ( seg)1061 if ( !fPhiFullTube ) 1101 1062 { 1102 1063 // First phi surface (Starting phi) 1103 1104 sinSPhi = std::sin(fSPhi) ; 1105 cosSPhi = std::cos(fSPhi) ; 1064 // 1106 1065 Comp = v.x()*sinSPhi - v.y()*cosSPhi ; 1107 1066 … … 1110 1069 Dist = (p.y()*cosSPhi - p.x()*sinSPhi) ; 1111 1070 1112 if ( Dist < kCarTolerance*0.5)1071 if ( Dist < halfCarTolerance ) 1113 1072 { 1114 1073 s = Dist/Comp ; … … 1135 1094 // - check intersecting with correct half-plane 1136 1095 // 1137 if ((yi*cosCPhi-xi*sinCPhi) <= 0) snxt = s ;1138 } 1096 if ((yi*cosCPhi-xi*sinCPhi) <= halfCarTolerance) { snxt = s; } 1097 } 1139 1098 } 1140 1099 } … … 1142 1101 } 1143 1102 1144 // Second phi surface (`E'nding phi) 1145 1146 ePhi = fSPhi + fDPhi ; 1147 sinEPhi = std::sin(ePhi) ; 1148 cosEPhi = std::cos(ePhi) ; 1103 // Second phi surface (Ending phi) 1104 1149 1105 Comp = -(v.x()*sinEPhi - v.y()*cosEPhi) ; 1150 1106 … … 1153 1109 Dist = -(p.y()*cosEPhi - p.x()*sinEPhi) ; 1154 1110 1155 if ( Dist < kCarTolerance*0.5)1111 if ( Dist < halfCarTolerance ) 1156 1112 { 1157 1113 s = Dist/Comp ; … … 1177 1133 // - check intersecting with correct half-plane 1178 1134 // 1179 if ( (yi*cosCPhi-xi*sinCPhi) >= 0 ) 1180 } 1135 if ( (yi*cosCPhi-xi*sinCPhi) >= 0 ) { snxt = s; } 1136 } //?? >=-halfCarTolerance 1181 1137 } 1182 1138 } 1183 1139 } 1184 1140 } // Comp < 0 1185 } // seg != 01186 if ( snxt< kCarTolerance*0.5) { snxt=0; }1141 } // !fPhiFullTube 1142 if ( snxt<halfCarTolerance ) { snxt=0; } 1187 1143 return snxt ; 1188 1144 } … … 1217 1173 { 1218 1174 G4double safe=0.0, rho, safe1, safe2, safe3 ; 1219 G4double phiC, cosPhiC, sinPhiC, safePhi,ePhi, cosPsi ;1175 G4double safePhi, cosPsi ; 1220 1176 1221 1177 rho = std::sqrt(p.x()*p.x() + p.y()*p.y()) ; … … 1228 1184 if ( safe3 > safe ) { safe = safe3; } 1229 1185 1230 if (fDPhi < twopi && rho) 1231 { 1232 phiC = fSPhi + fDPhi*0.5 ; 1233 cosPhiC = std::cos(phiC) ; 1234 sinPhiC = std::sin(phiC) ; 1235 1186 if ( (!fPhiFullTube) && (rho) ) 1187 { 1236 1188 // Psi=angle from central phi to point 1237 1189 // 1238 cosPsi = (p.x()*cos PhiC + p.y()*sinPhiC)/rho ;1239 1190 cosPsi = (p.x()*cosCPhi + p.y()*sinCPhi)/rho ; 1191 1240 1192 if ( cosPsi < std::cos(fDPhi*0.5) ) 1241 1193 { 1242 1194 // Point lies outside phi range 1243 1195 1244 if ( (p.y()*cos PhiC - p.x()*sinPhiC) <= 0 )1245 { 1246 safePhi = std::fabs(p.x()*s td::sin(fSPhi) - p.y()*std::cos(fSPhi)) ;1196 if ( (p.y()*cosCPhi - p.x()*sinCPhi) <= 0 ) 1197 { 1198 safePhi = std::fabs(p.x()*sinSPhi - p.y()*cosSPhi) ; 1247 1199 } 1248 1200 else 1249 1201 { 1250 ePhi = fSPhi + fDPhi ; 1251 safePhi = std::fabs(p.x()*std::sin(ePhi) - p.y()*std::cos(ePhi)) ; 1202 safePhi = std::fabs(p.x()*sinEPhi - p.y()*cosEPhi) ; 1252 1203 } 1253 1204 if ( safePhi > safe ) { safe = safePhi; } … … 1269 1220 G4ThreeVector *n ) const 1270 1221 { 1271 ESide side = kNull , sider = kNull, sidephi =kNull ;1272 G4double snxt, sr = kInfinity, sphi =kInfinity, pdist ;1222 ESide side=kNull , sider=kNull, sidephi=kNull ; 1223 G4double snxt, sr=kInfinity, sphi=kInfinity, pdist ; 1273 1224 G4double deltaR, t1, t2, t3, b, c, d2, roMin2 ; 1274 1225 1226 static const G4double halfCarTolerance = kCarTolerance*0.5; 1227 static const G4double halfAngTolerance = kAngTolerance*0.5; 1228 1275 1229 // Vars for phi intersection: 1276 1230 1277 G4double sinSPhi, cosSPhi, ePhi, sinEPhi, cosEPhi ;1278 G4double cPhi, sinCPhi, cosCPhi ;1279 1231 G4double pDistS, compS, pDistE, compE, sphi2, xi, yi, vphi, roi2 ; 1280 1232 … … 1284 1236 { 1285 1237 pdist = fDz - p.z() ; 1286 if ( pdist > kCarTolerance*0.5)1238 if ( pdist > halfCarTolerance ) 1287 1239 { 1288 1240 snxt = pdist/v.z() ; … … 1303 1255 pdist = fDz + p.z() ; 1304 1256 1305 if ( pdist > kCarTolerance*0.5)1257 if ( pdist > halfCarTolerance ) 1306 1258 { 1307 1259 snxt = -pdist/v.z() ; … … 1326 1278 // Radial Intersections 1327 1279 // 1328 // Find inters ction with cylinders at rmax/rmin1280 // Find intersection with cylinders at rmax/rmin 1329 1281 // Intersection point (xi,yi,zi) on line x=p.x+t*v.x etc. 1330 1282 // … … 1359 1311 b = t2/t1 ; 1360 1312 c = deltaR/t1 ; 1361 d2 = b*b-c;1362 if( d2>=0.){sr = -b + std::sqrt(d2);}1363 else {sr=0.;};1313 d2 = b*b-c; 1314 if( d2 >= 0 ) { sr = -b + std::sqrt(d2); } 1315 else { sr = 0.; } 1364 1316 sider = kRMax ; 1365 1317 } … … 1371 1323 if ( calcNorm ) 1372 1324 { 1373 // if ( p.x() || p.y() )1374 // {1375 // *n=G4ThreeVector(p.x(),p.y(),0);1376 // }1377 // else1378 // {1379 // *n=v;1380 // }1381 1325 *n = G4ThreeVector(p.x()/fRMax,p.y()/fRMax,0) ; 1382 1326 *validNorm = true ; … … 1417 1361 c = deltaR/t1 ; 1418 1362 d2 = b*b-c; 1419 if( d2>=0.)1363 if( d2 >=0. ) 1420 1364 { 1421 1365 sr = -b + std::sqrt(d2) ; … … 1423 1367 } 1424 1368 else // Case: On the border+t2<kRadTolerance 1425 // (v is perpendicula ir to the surface)1369 // (v is perpendicular to the surface) 1426 1370 { 1427 1371 if (calcNorm) … … 1441 1385 c = deltaR/t1; 1442 1386 d2 = b*b-c; 1443 if( d2>=0.)1387 if( d2 >= 0 ) 1444 1388 { 1445 1389 sr = -b + std::sqrt(d2) ; … … 1447 1391 } 1448 1392 else // Case: On the border+t2<kRadTolerance 1449 // (v is perpendicula ir to the surface)1393 // (v is perpendicular to the surface) 1450 1394 { 1451 1395 if (calcNorm) … … 1461 1405 // Phi Intersection 1462 1406 1463 if ( fDPhi < twopi ) 1464 { 1465 sinSPhi = std::sin(fSPhi) ; 1466 cosSPhi = std::cos(fSPhi) ; 1467 ePhi = fSPhi + fDPhi ; 1468 sinEPhi = std::sin(ePhi) ; 1469 cosEPhi = std::cos(ePhi) ; 1470 cPhi = fSPhi + fDPhi*0.5 ; 1471 sinCPhi = std::sin(cPhi) ; 1472 cosCPhi = std::cos(cPhi) ; 1473 1407 if ( !fPhiFullTube ) 1408 { 1474 1409 // add angle calculation with correction 1475 1410 // of the difference in domain of atan2 and Sphi 1476 1411 // 1477 1412 vphi = std::atan2(v.y(),v.x()) ; 1478 1479 if ( vphi < fSPhi - kAngTolerance*0.5) { vphi += twopi; }1480 else if ( vphi > fSPhi + fDPhi + kAngTolerance*0.5) { vphi -= twopi; }1413 1414 if ( vphi < fSPhi - halfAngTolerance ) { vphi += twopi; } 1415 else if ( vphi > fSPhi + fDPhi + halfAngTolerance ) { vphi -= twopi; } 1481 1416 1482 1417 … … 1492 1427 compS = -sinSPhi*v.x() + cosSPhi*v.y() ; 1493 1428 compE = sinEPhi*v.x() - cosEPhi*v.y() ; 1429 1494 1430 sidephi = kNull; 1495 1431 1496 if( ( (fDPhi <= pi) && ( (pDistS <= 0.5*kCarTolerance)1497 && (pDistE <= 0.5*kCarTolerance) ) )1498 || ( (fDPhi > pi) && !((pDistS > 0.5*kCarTolerance)1499 && (pDistE > 0.5*kCarTolerance) ) ) )1432 if( ( (fDPhi <= pi) && ( (pDistS <= halfCarTolerance) 1433 && (pDistE <= halfCarTolerance) ) ) 1434 || ( (fDPhi > pi) && !((pDistS > halfCarTolerance) 1435 && (pDistE > halfCarTolerance) ) ) ) 1500 1436 { 1501 1437 // Inside both phi *full* planes … … 1505 1441 sphi = pDistS/compS ; 1506 1442 1507 if (sphi >= - 0.5*kCarTolerance)1443 if (sphi >= -halfCarTolerance) 1508 1444 { 1509 1445 xi = p.x() + sphi*v.x() ; … … 1513 1449 // (if not -> no intersect) 1514 1450 // 1515 if((std::abs(xi)<=kCarTolerance)&&(std::abs(yi)<=kCarTolerance)) 1516 { sidephi = kSPhi; 1517 if (((fSPhi-0.5*kAngTolerance)<=vphi) 1518 &&((ePhi+0.5*kAngTolerance)>=vphi)) 1451 if( (std::abs(xi)<=kCarTolerance)&&(std::abs(yi)<=kCarTolerance) ) 1452 { 1453 sidephi = kSPhi; 1454 if (((fSPhi-halfAngTolerance)<=vphi) 1455 &&((fSPhi+fDPhi+halfAngTolerance)>=vphi)) 1519 1456 { 1520 1457 sphi = kInfinity; 1521 1458 } 1522 1459 } 1523 else if ( (yi*cosCPhi-xi*sinCPhi)>=0)1460 else if ( yi*cosCPhi-xi*sinCPhi >=0 ) 1524 1461 { 1525 1462 sphi = kInfinity ; … … 1528 1465 { 1529 1466 sidephi = kSPhi ; 1530 if ( pDistS > - kCarTolerance*0.5)1467 if ( pDistS > -halfCarTolerance ) 1531 1468 { 1532 1469 sphi = 0.0 ; // Leave by sphi immediately … … 1550 1487 // Only check further if < starting phi intersection 1551 1488 // 1552 if ( (sphi2 > - 0.5*kCarTolerance) && (sphi2 < sphi) )1489 if ( (sphi2 > -halfCarTolerance) && (sphi2 < sphi) ) 1553 1490 { 1554 1491 xi = p.x() + sphi2*v.x() ; … … 1559 1496 // Leaving via ending phi 1560 1497 // 1561 if( !(((fSPhi-0.5*kAngTolerance)<=vphi)1562 &&((ePhi+0.5*kAngTolerance)>=vphi)))1498 if( !((fSPhi-halfAngTolerance <= vphi) 1499 &&(fSPhi+fDPhi+halfAngTolerance >= vphi)) ) 1563 1500 { 1564 1501 sidephi = kEPhi ; 1565 if ( pDistE <= - kCarTolerance*0.5) { sphi = sphi2 ; }1566 else { sphi = 0.0 ;}1502 if ( pDistE <= -halfCarTolerance ) { sphi = sphi2 ; } 1503 else { sphi = 0.0 ; } 1567 1504 } 1568 1505 } … … 1574 1511 // 1575 1512 sidephi = kEPhi ; 1576 if ( pDistE <= - kCarTolerance*0.5) { sphi = sphi2 ; }1577 else { sphi = 0.0 ;}1513 if ( pDistE <= -halfCarTolerance ) { sphi = sphi2 ; } 1514 else { sphi = 0.0 ; } 1578 1515 } 1579 1516 } … … 1589 1526 // On z axis + travel not || to z axis -> if phi of vector direction 1590 1527 // within phi of shape, Step limited by rmax, else Step =0 1591 1592 // vphi = std::atan2(v.y(),v.x()) ;//defined previosly1593 // G4cout<<"In axis vphi="<<vphi1594 // <<" Sphi="<<fSPhi<<" Ephi="<<ePhi<<G4endl;1595 // old if ( (fSPhi < vphi) && (vphi < fSPhi + fDPhi) )1596 // new : correction for if statement, must be '<='1597 1528 1598 if ( ( (fSPhi-0.5*kAngTolerance)<= vphi)1599 && (vphi <= ( ePhi+0.5*kAngTolerance) ))1529 if ( (fSPhi - halfAngTolerance <= vphi) 1530 && (vphi <= fSPhi + fDPhi + halfAngTolerance ) ) 1600 1531 { 1601 1532 sphi = kInfinity ; … … 1640 1571 if ( fDPhi <= pi ) 1641 1572 { 1642 *n = G4ThreeVector(s td::sin(fSPhi),-std::cos(fSPhi),0) ;1573 *n = G4ThreeVector(sinSPhi,-cosSPhi,0) ; 1643 1574 *validNorm = true ; 1644 1575 } … … 1652 1583 if (fDPhi <= pi) 1653 1584 { 1654 *n = G4ThreeVector(-s td::sin(fSPhi+fDPhi),std::cos(fSPhi+fDPhi),0) ;1585 *n = G4ThreeVector(-sinEPhi,cosEPhi,0) ; 1655 1586 *validNorm = true ; 1656 1587 } … … 1662 1593 1663 1594 case kPZ: 1664 *n =G4ThreeVector(0,0,1) ;1665 *validNorm =true ;1595 *n = G4ThreeVector(0,0,1) ; 1596 *validNorm = true ; 1666 1597 break ; 1667 1598 … … 1690 1621 } 1691 1622 } 1692 if ( snxt< kCarTolerance*0.5) { snxt=0 ; }1623 if ( snxt<halfCarTolerance ) { snxt=0 ; } 1693 1624 1694 1625 return snxt ; … … 1701 1632 G4double G4Tubs::DistanceToOut( const G4ThreeVector& p ) const 1702 1633 { 1703 G4double safe=0.0, rho, safeR1, safeR2, safeZ ; 1704 G4double safePhi, phiC, cosPhiC, sinPhiC, ePhi ; 1634 G4double safe=0.0, rho, safeR1, safeR2, safeZ, safePhi ; 1705 1635 rho = std::sqrt(p.x()*p.x() + p.y()*p.y()) ; 1706 1636 … … 1738 1668 // Check if phi divided, Calc distances closest phi plane 1739 1669 // 1740 if ( fDPhi < twopi ) 1741 { 1742 // Above/below central phi of Tubs? 1743 1744 phiC = fSPhi + fDPhi*0.5 ; 1745 cosPhiC = std::cos(phiC) ; 1746 sinPhiC = std::sin(phiC) ; 1747 1748 if ( (p.y()*cosPhiC - p.x()*sinPhiC) <= 0 ) 1749 { 1750 safePhi = -(p.x()*std::sin(fSPhi) - p.y()*std::cos(fSPhi)) ; 1670 if ( !fPhiFullTube ) 1671 { 1672 if ( p.y()*cosCPhi-p.x()*sinCPhi <= 0 ) 1673 { 1674 safePhi = -(p.x()*sinSPhi - p.y()*cosSPhi) ; 1751 1675 } 1752 1676 else 1753 1677 { 1754 ePhi = fSPhi + fDPhi ; 1755 safePhi = (p.x()*std::sin(ePhi) - p.y()*std::cos(ePhi)) ; 1678 safePhi = (p.x()*sinEPhi - p.y()*cosEPhi) ; 1756 1679 } 1757 1680 if (safePhi < safe) { safe = safePhi ; } … … 1806 1729 // on the x axis. Will give better extent calculations when not rotated. 1807 1730 1808 if (f DPhi == pi*2.0 && fSPhi == 0) { sAngle = -meshAngle*0.5 ; }1809 else 1731 if (fPhiFullTube && (fSPhi == 0) ) { sAngle = -meshAngle*0.5 ; } 1732 else { sAngle = fSPhi ; } 1810 1733 1811 1734 vertices = new G4ThreeVectorList(); … … 1975 1898 if (fRMin != 0) 1976 1899 { 1977 if (f DPhi >= twopi)1900 if (fPhiFullTube) 1978 1901 { 1979 1902 pNURBS = new G4NURBStube (fRMin,fRMax,fDz) ; … … 1986 1909 else 1987 1910 { 1988 if (f DPhi >= twopi)1911 if (fPhiFullTube) 1989 1912 { 1990 1913 pNURBS = new G4NURBScylinder (fRMax,fDz) ;
Note: See TracChangeset
for help on using the changeset viewer.