// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // $Id: testG4Tubs.cc,v 1.22 2008/11/05 13:56:30 gcosmo Exp $ // GEANT4 tag $Name: geant4-09-04-ref-00 $ // // testG4Tubs // // Test file for class G4Tubs [NOT thorough] // // Ensure asserts are compiled in // // History: // // ~95-96 P. Kent R&D // 21.5.99 V. Grichine tests of phi-intersections (t3 and t4) #include #include #include "globals.hh" #include "geomdefs.hh" #include "ApproxEqual.hh" #include "G4GeometryTolerance.hh" #include "G4ThreeVector.hh" #include "G4Tubs.hh" #include "G4RotationMatrix.hh" #include "G4AffineTransform.hh" #include "G4VoxelLimits.hh" /////////////////////////////////////////////////////////////////// // // Dave's auxiliary function const G4String OutputInside(const EInside a) { switch(a) { case kInside: return "Inside"; case kOutside: return "Outside"; case kSurface: return "Surface"; } return "????"; } G4bool testG4Tubs() { G4cout.precision(16) ; EInside side; G4ThreeVector pzero(0,0,0); G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); G4ThreeVector pbigx(100,0,0),pbigy(0,100,0),pbigz(0,0,100); G4ThreeVector pbigmx(-100,0,0),pbigmy(0,-100,0),pbigmz(0,0,-100); G4ThreeVector ponxside(50,0,0); G4ThreeVector vx(1,0,0),vy(0,1,0),vz(0,0,1); G4ThreeVector vmx(-1,0,0),vmy(0,-1,0),vmz(0,0,-1); G4ThreeVector vxy(1/std::sqrt(2.0),1/std::sqrt(2.0),0); G4ThreeVector vmxy(-1/std::sqrt(2.0),1/std::sqrt(2.0),0); G4ThreeVector vmxmy(-1/std::sqrt(2.0),-1/std::sqrt(2.0),0); G4ThreeVector vxmy(1/std::sqrt(2.0),-1/std::sqrt(2.0),0); G4double Dist, dist, vol; G4ThreeVector *pNorm,norm; G4bool *pgoodNorm,goodNorm,calcNorm=true; pNorm=&norm; pgoodNorm=&goodNorm; G4Tubs t1("Solid Tube #1",0,50*mm,50*mm,0,2*pi); G4Tubs t1a("Solid Tube #1",0,50*mm,50*mm,0,0.5*pi); G4Tubs t2("Hole Tube #2",45*mm,50*mm,50*mm,0,2*pi); G4Tubs t2a("Hole Tube #2",5*mm,50*mm,50*mm,0,2*pi); G4Tubs t2b("Hole Tube #2",15*mm,50*mm,50*mm,0,2*pi); G4Tubs t2c("Hole Tube #2",25*mm,50*mm,50*mm,0,2*pi); G4Tubs t2d("Hole Tube #2",35*mm,50*mm,50*mm,0,2*pi); G4Tubs t3("Solid Sector #3",0,50*mm,50*mm,halfpi,halfpi); G4Tubs t4("Hole Sector #4",45*mm,50*mm,50*mm,halfpi,halfpi); G4Tubs t5("Hole Sector #5",50*mm,100*mm,50*mm,0.0,270.0*deg); G4Tubs t6("Solid Sector #3",0,50*mm,50*mm,halfpi,3.*halfpi); G4Tubs tube6("tube6",750,760,350,0.31415926535897931,5.6548667764616276); G4Tubs tube7("tube7",2200,3200,2500,-0.68977164349384879,3.831364227270472); G4Tubs tube8("tube8",2550,2580,2000,0,2*pi); G4Tubs tube9("tube9",1150,1180,2000,0,2*pi); G4Tubs tube10("tube10",400*mm,405*mm,400*mm,0*degree,360*degree) ; G4Tubs* clad = new G4Tubs("clad",90.,110.,10.5*cm,0.*deg,180.*deg); // external G4Tubs* core = new G4Tubs("core",95.,105.,10.*cm,0.*deg,180.*deg); // internal G4cout.precision(20); // Check name assert(t1.GetName()=="Solid Tube #1"); // Check cubic volume vol = t1.GetCubicVolume(); assert(ApproxEqual(vol,785398.16339744825)); assert( ApproxEqual(vol,785398.163397) ); // Check Inside // // Make a tub // G4Tubs *arc = new G4Tubs( "outer", 1*m, 1.1*m, 0.01*m, -15*deg, 30*deg ); // // First issue: // A point on the start phi surface just beyond the // start angle but still well within tolerance // is found to be "outside" by G4Tubs::Inside // // pt1 = exactly on phi surface (within precision) // pt2 = t1 but slightly higher, and still on tolerant surface // pt3 = t1 but slightly lower, and still on tolerant surface // G4ThreeVector pt1( 1.05*m*std::cos(-15*deg), 1.05*m*std::sin(-15*deg), 0*m ); G4ThreeVector pt2 = pt1 + G4ThreeVector(0,0.001*kCarTolerance,0) ; G4ThreeVector pt3 = pt1 - G4ThreeVector(0,0.001*kCarTolerance,0) ; EInside a1 = arc->Inside(pt1); EInside a2 = arc->Inside(pt2); EInside a3 = arc->Inside(pt3); // G4cout << "Point pt1 is " << OutputInside(a1) << G4endl; assert(a1==kSurface); // G4cout << "Point pt2 is " << OutputInside(a2) << G4endl; assert(a2==kSurface); // G4cout << "Point pt3 is " << OutputInside(a3) << G4endl; assert(a3==kSurface); assert(t1.Inside(pzero)==kInside); assert(t1.Inside(pbigx)==kOutside); EInside in = t5.Inside(G4ThreeVector(60,-0.001*kCarTolerance,0)) ; assert(in == kSurface); // G4cout<<"t5.Inside(G4ThreeVector(60,-0.001*kCarTolerance,0)) = " // <unit(),vx)&&*pgoodNorm); Dist=t1.DistanceToOut(pzero,vmx,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmx)&&*pgoodNorm); Dist=t1.DistanceToOut(pzero,vy,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vy)&&*pgoodNorm); Dist=t1.DistanceToOut(pzero,vmy,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmy)&&*pgoodNorm); Dist=t1.DistanceToOut(pzero,vz,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vz)&&*pgoodNorm); Dist=t1.DistanceToOut(pzero,vmz,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmz)&&*pgoodNorm); Dist=t1.DistanceToOut(pzero,vxy,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vxy)&&*pgoodNorm); Dist=t2.DistanceToOut(pzero,vxy,calcNorm,pgoodNorm,pNorm); // G4cout<<"Dist=t2.DistanceToOut(pzero,vxy) = "<DistanceToIn(pTmp,vy); pTmp += dist*vy; G4cout<<"pTmpX = "<Inside(pTmp) = "<Inside(pTmp); G4cout<<"clad->Inside(pTmp) = "<DistanceToIn(pTmp,vy); pTmp += dist*vy; G4cout<<"pTmpX = "<Inside(pTmp) = "<Inside(pTmp); G4cout<<"clad->Inside(pTmp) = "<DistanceToOut(pTmp,vy,calcNorm,pgoodNorm,pNorm); pTmp += dist*vy; G4cout<<"pTmpX = "<Inside(pTmp) = "<Inside(pTmp); G4cout<<"clad->Inside(pTmp) = "<DistanceToOut(pTmp,vy,calcNorm,pgoodNorm,pNorm); pTmp += dist*vy; G4cout<<"pTmpX = "<Inside(pTmp) = "<Inside(pTmp); G4cout<<"clad->Inside(pTmp) = "<=50); assert(t1.CalculateExtent(kYAxis,unlimit,origin,min,max)); assert(min<=-50&&max>=50); assert(t1.CalculateExtent(kZAxis,unlimit,origin,min,max)); assert(min<=-50&&max>=50); assert(t3.CalculateExtent(kXAxis,unlimit,origin,min,max)); assert(min<=-50&&max>=0); assert(t3.CalculateExtent(kYAxis,unlimit,origin,min,max)); assert(min<=0&&max>=50); assert(t3.CalculateExtent(kZAxis,unlimit,origin,min,max)); assert(min<=-50&&max>=50); ///////////////////////////////////////////////////// assert(t1.CalculateExtent(kXAxis,limitXYZ,origin,min,max)); G4cout<<"t1.CE(kXAxis,limitXYZ,origin,min = " <