source: trunk/source/geometry/solids/specific/test/testG4EllipticalTube.cc

Last change on this file was 1350, checked in by garnier, 15 years ago

update to last version 4.9.4

File size: 7.9 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: testG4EllipticalTube.cc
28// GEANT4 tag $Name:
29//
30// testG4EllipticalTube
31//
32// Test file for class G4EllipticalTube derived from G4EllipticalCone
33//
34// Ensure asserts are compiled in
35
36#include <assert.h>
37#include <cmath>
38
39#include "globals.hh"
40#include "geomdefs.hh"
41#include "G4GeometryTolerance.hh"
42
43#include "G4ThreeVector.hh"
44#include "G4EllipticalTube.hh"
45#include "G4RotationMatrix.hh"
46#include "G4AffineTransform.hh"
47#include "G4VoxelLimits.hh"
48
49const G4String OutputInside(const EInside a)
50{
51 switch(a)
52 {
53 case kInside: return "Inside";
54 case kOutside: return "Outside";
55 case kSurface: return "Surface";
56 }
57 return "????";
58}
59
60
61G4bool testG4EllipticalTube()
62{
63
64 G4ThreeVector pzero(0,0,0);
65 G4ThreeVector pout ( 0*cm, 0*cm, 25*cm ) ;
66 G4ThreeVector psurface(2.*mm,0*mm,0*cm);
67 G4ThreeVector dir = pzero-pout ;
68 dir *= 1/dir.mag();
69
70 //For Normal
71 G4ThreeVector *pNorm,norm;
72 G4bool *pgoodNorm,goodNorm,calcNorm=true;
73
74 pNorm=&norm;
75 pgoodNorm=&goodNorm;//For Normal
76
77
78 G4EllipticalTube t1("Solid EllipticalTube #1",
79 2*mm, // xSemiAxis
80 1*mm, // ySemiAxis
81 15*cm); // zheight
82
83
84 G4double dist = t1.DistanceToOut(pout,dir) ;
85 G4cout << "*********** Testing DistanceToOut method *************** "<<G4endl;
86 G4cout << "Distance = " << dist << G4endl <<G4endl;
87 dist = t1.DistanceToOut(psurface,G4ThreeVector(1,0,0),calcNorm,pgoodNorm,pNorm);
88 G4cout << "Distance = " << dist << G4endl ;
89 G4cout << "with Normal = "<< (*pNorm) << G4endl << G4endl ;
90 // Check Inside
91
92 G4cout << "************ Test Inside(p) ****************" << G4endl ;
93 G4cout << "pzero : " << t1.Inside(pzero) << G4endl <<G4endl ;
94 G4cout << "psurface:" << t1.Inside(psurface) << G4endl <<G4endl ;
95 //test the name
96 G4cout << "The name is : " << t1.GetName() << G4endl ;
97
98 // testing the volume
99
100 G4double volume = t1.GetCubicVolume() ;
101 G4cout << G4endl ;
102 G4cout << "Solid EllipticalTube #1 has Volume = " << volume / cm / cm /cm << " cm^3"
103 << G4endl << G4endl;
104
105 return true;
106}
107
108//
109// This test generates a random point on the surface of the solid and
110// checks the distance from a point outside in the direction of the
111// line between the two points
112//
113G4bool testDistanceToIn()
114{
115 G4EllipticalTube t1("Solid EllipticalTube #1",
116 2*cm, // xSemiAxis
117 1*cm, // ySemiAxis
118 15*cm); // zheight
119
120
121 G4int N = 10000;
122 G4int n = 0;
123
124 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
125
126 for(G4int i=0; i<N; i++)
127 {
128 G4ThreeVector point = t1.GetPointOnSurface();
129 point.setX(std::fabs(point.x()));
130 point.setY(std::fabs(point.y()));
131
132 G4ThreeVector out (100*cm, 100*cm, 100*cm);
133
134 G4ThreeVector dir = point - out;
135 G4double dist2 = dir.mag();
136 dir /= dist2;
137
138 G4double dist1 = t1.DistanceToIn(point,dir);
139 G4double diff = std::fabs(dist1 - dist2);
140
141 if(diff < 2.*kCarTolerance)
142 n++;
143 }
144
145 G4cout <<" ************ For testG4EllipticalTube ******************"<<G4endl<<G4endl;
146 G4cout <<" Number of inconsistencies for testDistanceToIn was: "<< n <<" ..."<<G4endl
147 <<" ... For a total of "<<N<<" trials."<< G4endl <<G4endl;
148
149 return true;
150}
151G4bool testDistanceToOut()
152{
153 G4EllipticalTube t1("Solid EllipticalTube #1",
154 2*cm, // xSemiAxis
155 1*cm, // ySemiAxis
156 15*cm); // zheight
157
158 G4int N = 10000;
159 G4int n = 0;
160 G4int nn= 0;
161
162 G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
163
164 //For Normal
165 G4ThreeVector *pNorm,norm,SurfNormal;
166 G4bool *pgoodNorm,goodNorm,calcNorm=true;
167
168 pNorm=&norm;
169 pgoodNorm=&goodNorm;
170 //
171
172 for(G4int i=0; i<N; i++)
173 {
174 G4ThreeVector point = t1.GetPointOnSurface();
175 point.setX(std::fabs(point.x()));
176 point.setY(std::fabs(point.y()));
177
178 G4ThreeVector out (0*cm, 0*cm, 0*cm);
179
180 G4ThreeVector dir = point - out;
181 G4double dist2 = dir.mag();
182 dir /= dist2;
183
184 G4double dist1 = t1.DistanceToOut(point,dir,calcNorm,pgoodNorm,pNorm);
185 G4double diff = std::fabs(dist1 - dist2);
186 G4double difNorm=((*pNorm)-t1.SurfaceNormal(point)).mag();
187
188 if(difNorm > 2.*kCarTolerance){
189 if(std::fabs(std::fabs(point.z())-15.0*cm)>kCarTolerance) nn++;
190 G4cout<<"point="<<point<<" norm="<< (*pNorm)<<" surfNorm="<<t1.SurfaceNormal(point)<<G4endl;
191
192 }
193
194 if(diff < 2.*kCarTolerance)
195 n++;
196 }
197
198 G4cout <<" ************ For testG4EllipticalTube ******************"<<G4endl<<G4endl;
199 G4cout <<" Number of inconsistencies for testDistanceToOut was: "<< n <<" ..."<<G4endl
200 <<" ... For a total of "<<N<<" trials."<< G4endl <<G4endl;
201 G4cout <<" Number of differences for test Normal was "<< nn << " ...."<<G4endl <<G4endl;
202
203 return true;
204}
205
206
207int main()
208{
209
210 G4cout << G4endl;
211 G4cout << "*********************************************************************" <<G4endl;
212 G4cout << "****************** UNIT TEST FOR ELLIPTICAL TUBE ********************" <<G4endl;
213 G4cout << "*********************************************************************" <<G4endl;
214 G4cout << G4endl;
215
216 // temporary test
217 G4ThreeVector Spoint ;
218 G4double dist ;
219
220 G4EllipticalTube t1("Solid EllipticalTube #1",
221 0.5*mm, // xSemiAxis
222 1*mm, // ySemiAxis
223 40*cm); // zheight
224
225
226 EInside side ;
227 for ( G4int i = 0 ; i < 3 ; i++ ) {
228 // G4cout << "Event " << i << G4endl << G4endl ;
229 Spoint = t1.GetPointOnSurface() ;
230 side = t1.Inside(Spoint) ;
231 dist = t1.DistanceToIn(Spoint, -Spoint/Spoint.mag()) ;
232 G4cout << "Spoint " << Spoint << " " << dist << " " << side << G4endl ;
233 }
234
235#ifdef NDEBUG
236 G4Exception("FAIL: *** Assertions must be compiled in! ***");
237#endif
238 assert(testG4EllipticalTube());
239
240 G4bool what;
241 what = testDistanceToIn();
242 what = testDistanceToOut();
243 G4cout << G4endl;
244 G4cout << "*********************************************************************" <<G4endl;
245 G4cout << "******************* END OF TEST - THANK YOU!!! **********************" <<G4endl;
246 G4cout << "*********************************************************************" <<G4endl;
247 G4cout << G4endl;
248
249 return 0;
250}
Note: See TracBrowser for help on using the repository browser.