// // ******************************************************************** // * 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: testG4Torus.cc,v 1.16 2007/05/18 10:24:32 gcosmo Exp $ // GEANT4 tag $Name: geant4-09-04-ref-00 $ // // testG4Torus // // Test file for class G4Torus [NOT thorough] // // History // 30.10.96 V.Grichine First version for first G4Torus implementation #include "G4ios.hh" #include #include #include "globals.hh" #include "geomdefs.hh" #include "G4GeometryTolerance.hh" #include "ApproxEqual.hh" #include "G4ThreeVector.hh" #include "G4Torus.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 testG4Torus() { G4int i ; G4double Rtor = 100 ; G4double Rmax = Rtor*0.9 ; G4double Rmin = Rtor*0.1 ; //G4double z = atof ( argv[2] ); G4double x; G4double z; G4double Dist, dist, vol, volCheck; EInside side; G4ThreeVector *pNorm,norm; G4bool *pgoodNorm,goodNorm,calcNorm=true; G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); pNorm=&norm; pgoodNorm=&goodNorm; G4ThreeVector pzero(0,0,0); G4ThreeVector pbigx(240,0,0),pbigy(0,240,0),pbigz(0,0,240); G4ThreeVector pbigmx(-240,0,0),pbigmy(0,-240,0),pbigmz(0,0,-240); G4ThreeVector ponrmax(190,0,0); G4ThreeVector ponrmin(0,110,0); G4ThreeVector ponrtor(0,100,0); G4ThreeVector ponphi1(100/std::sqrt(2.),100/std::sqrt(2.),0) ; G4ThreeVector ponphi2(-100/std::sqrt(2.),100/std::sqrt(2.),0) ; G4ThreeVector ponphi12(120/std::sqrt(2.),120/std::sqrt(2.),0) ; G4ThreeVector ponphi22(-120/std::sqrt(2.),120/std::sqrt(2.),0) ; G4ThreeVector ponphi23(-120/std::sqrt(2.)+0.5,120/std::sqrt(2.),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); G4ThreeVector pstart((Rtor+Rmax)/std::sqrt(2.0),(Rtor+Rmax)/std::sqrt(2.0),0) ; G4ThreeVector vdirect(1/std::sqrt(2.0),-1/std::sqrt(2.0),0) ; G4ThreeVector pother(110,0,0); vdirect = vdirect.unit() ; G4ThreeVector p1; G4ThreeVector v1(1,0,0); v1 = v1.unit(); // Check torus roots G4Torus t1("Solid Torus #1",0,Rmax,Rtor,0,twopi); G4Torus t2("Hole cutted Torus #2",Rmin,Rmax,Rtor,pi/4,halfpi); G4Torus tn2("tn2",Rmin,Rmax,Rtor,halfpi,halfpi); G4Torus tn3("tn3",Rmin,Rmax,Rtor,halfpi,3*halfpi); G4Torus t3("Hole cutted Torus #3",4*Rmin,Rmax,Rtor,halfpi-pi/24,pi/12); G4Torus t4("Solid Torus #4",0,Rtor - 2.e3*kCarTolerance,Rtor,0,twopi); G4Torus t5("Solid cutted Torus #5",0,Rtor - 2.e3*kCarTolerance,Rtor,pi/4,halfpi); G4Torus * aTub = new G4Torus("Ring1", 0*cm, 10*cm, 1*m, 0*deg, 360*deg ); G4Torus t6("t6",100*mm, 150*mm, 200*mm,0*degree, 59.99999999999999*degree); G4Torus* clad = new G4Torus("clad",0.,1.*cm,10.*cm,0.*deg,180.*deg); // external G4Torus* core = new G4Torus("core",0.,0.5*cm,10.*cm,0.*deg,180.*deg); // internal G4cout.precision(20); G4ThreeVector p1t6( 60.73813233071262, -27.28494547459707, 37.47827539879173); G4ThreeVector vt6( 0.3059312222729116, 0.8329513862588347, -0.461083588265824); G4ThreeVector p2t6(70.75950555416668, -3.552713678800501e-15, 22.37458414788935 ); // num = t1.TorusRoots(Ri,pstart,vdirect) ; // num = t1.TorusRoots(Ri,pother,vx) ; // G4Torus t2("Hole Torus #2",45,50,50,0,360); // Check name // assert(t1.GetName()=="Solid Torus #1"); // check cubic volume vol = t1.GetCubicVolume(); volCheck = twopi*pi*Rtor*(Rmax*Rmax); assert(ApproxEqual(vol,volCheck)); vol = t2.GetCubicVolume(); volCheck = halfpi*pi*Rtor*(Rmax*Rmax-Rmin*Rmin); assert(ApproxEqual(vol,volCheck)); // Check Inside assert(t1.Inside(pzero)==kOutside); assert(t1.Inside(pbigx)==kOutside); assert(t1.Inside(ponrmax)==kSurface); assert(t2.Inside(ponrmin)==kSurface); assert(t2.Inside(pbigx)==kOutside); assert(t2.Inside(pbigy)==kOutside); assert(t2.Inside(ponphi1)==kOutside); assert(t2.Inside(ponphi2)==kOutside); assert(t2.Inside(ponphi12)==kSurface); assert(t2.Inside(ponphi22)==kSurface); side=t6.Inside(p1t6); // G4cout<<"t6.Inside(p1t6) = "<unit(),vxmy)); Dist=t2.DistanceToOut(ponphi22,vmxmy,calcNorm,pgoodNorm,pNorm); // G4cout<<"Dist=t2.DistanceToOut(ponphi22,vmxmy) = "<unit(),vmxmy)); Dist=t2.DistanceToOut(ponphi23,vmxmy,calcNorm,pgoodNorm,pNorm); // G4cout<<"Dist=t2.DistanceToOut(ponphi23,vmxmy) = "<unit(),vmxmy)); // Check for Distance to Out ( start from an internal point ) for ( i=0; i<12; i++ ) { x = -1050; z = G4double(i)/10; p1 = G4ThreeVector(x,0,z); // G4cout << p1 << " - " << v1 << G4endl; Dist = aTub->DistanceToIn (p1,v1); // G4cout << "Distance to in dir: " << Dist ; Dist = aTub->DistanceToOut (p1,v1) ; // G4cout << " Distance to out dir: " << Dist << G4endl ; // G4cout << "Distance to in : " << aTub->DistanceToIn (p1); // G4cout << " Distance to out : " << aTub->DistanceToOut (p1) // << G4endl; // G4cout << " Inside : " << aTub->Inside (p1); // G4cout << G4endl; } //DistanceToIn(P) Dist=t1.DistanceToIn(pbigx); assert(ApproxEqual(Dist,50)); Dist=t1.DistanceToIn(pbigmx); assert(ApproxEqual(Dist,50)); Dist=t1.DistanceToIn(pbigy); assert(ApproxEqual(Dist,50)); Dist=t1.DistanceToIn(pbigmy); assert(ApproxEqual(Dist,50)); Dist=t1.DistanceToIn(pbigz); // G4cout<<"Dist=t1.DistanceToIn(pbigz) = "<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) = "<DistanceToIn (p1,v1) ; // G4cout << "Distance to in dir: " << Dist ; Dist = aTub->DistanceToOut (p1,v1) ; // G4cout << " Distance to out dir: " << Dist << G4endl ; // G4cout << "Distance to in : " << aTub->DistanceToIn (p1); // G4cout << " Distance to out : " << aTub->DistanceToOut (p1) // << G4endl; // G4cout << " Inside : " << aTub->Inside (p1); // G4cout << G4endl; } // CalculateExtent G4VoxelLimits limit; // Unlimited G4RotationMatrix noRot; G4AffineTransform origin; G4double min,max; assert(t1.CalculateExtent(kXAxis,limit,origin,min,max)); assert(min<=-190&&max>=190); assert(t1.CalculateExtent(kYAxis,limit,origin,min,max)); assert(min<=-190&&max>=190); assert(t1.CalculateExtent(kZAxis,limit,origin,min,max)); assert(min<=-90&&max>=90); G4ThreeVector pmxmymz(-100,-110,-120); G4AffineTransform tPosOnly(pmxmymz); assert(t1.CalculateExtent(kXAxis,limit,tPosOnly,min,max)); assert(min<=-290&&max>=-90); assert(t1.CalculateExtent(kYAxis,limit,tPosOnly,min,max)); assert(min<=-300&&max>=-100); assert(t1.CalculateExtent(kZAxis,limit,tPosOnly,min,max)); assert(min<=-210&&max>=-30); G4RotationMatrix r90Z; r90Z.rotateZ(halfpi); G4AffineTransform tRotZ(r90Z,pzero); assert(t1.CalculateExtent(kXAxis,limit,tRotZ,min,max)); assert(min<=-50&&max>=50); assert(t1.CalculateExtent(kYAxis,limit,tRotZ,min,max)); assert(min<=-50&&max>=50); assert(t1.CalculateExtent(kZAxis,limit,tRotZ,min,max)); assert(min<=-50&&max>=50); // Check that clipped away G4VoxelLimits xClip; xClip.AddLimit(kXAxis,-300,-200); assert(!t1.CalculateExtent(kXAxis,xClip,origin,min,max)); // Assert clipped to volume G4VoxelLimits allClip; allClip.AddLimit(kXAxis,-5,+5); allClip.AddLimit(kYAxis,-5,+5); allClip.AddLimit(kZAxis,-5,+5); G4RotationMatrix genRot; genRot.rotateX(pi/6); genRot.rotateY(pi/6); genRot.rotateZ(pi/6); G4AffineTransform tGen(genRot,vx); assert(t4.CalculateExtent(kXAxis,allClip,tGen,min,max)); // G4cout<<"min = "<