source: trunk/source/geometry/solids/specific/test/testG4EllipticalCone.cc @ 1316

Last change on this file since 1316 was 1316, checked in by garnier, 14 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 6.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: testG4EllipticalCone.cc
28// GEANT4 tag $Name:
29//
30// testG4EllipticalCone
31//
32//  Test file for class 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 "G4EllipticalCone.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 testG4EllipticalCone()
62{
63
64    G4ThreeVector pzero(0,0,0);
65    G4ThreeVector pout ( 0*cm, 0*cm, 5*cm ) ;
66    G4ThreeVector dir = pzero-pout ;
67    dir *= 1/dir.mag();
68   
69    G4EllipticalCone t1("Solid EllipticalCone #1",
70                        2*mm,       // xSemiAxis
71                        1*mm,       // ySemiAxis
72                        15*cm,      // zheight   
73                        10*cm) ;    // zTopCut
74                           
75    G4double dist = t1.DistanceToOut(pout,dir) ; 
76    G4cout << "*********** Testing DistanceToOut method *************** "<<G4endl;
77    G4cout << "Distance = " << dist << G4endl <<G4endl; 
78
79    // Check Inside
80 
81    G4cout << "************ Test Inside(p) ****************" << G4endl ;
82    G4cout << "pzero : " << t1.Inside(pzero) << G4endl <<G4endl ; 
83   
84    //test the name
85    G4cout << "The name is : " << t1.GetName() << G4endl ; 
86
87    // testing the volume
88 
89    G4double volume = t1.GetCubicVolume() ; 
90    G4cout << G4endl ;
91    G4cout << "Solid EllipticalCone #1 has Volume = " << volume / cm / cm /cm << " cm^3" 
92           << G4endl << G4endl; 
93
94    return true; 
95}
96
97//
98//  This test generates a random point on the surface of the solid and 
99//  checks the distance from a point outside in the direction of the
100//  line between the two points
101//
102G4bool testDistanceToIn() 
103{   
104  G4EllipticalCone t1("Solid EllipticalCone #1", 
105                      2*cm,       // xSemiAxis
106                      1*cm,       // ySemiAxis 
107                      15*cm,      // zheight
108                      10*cm) ;    // zTopCut
109 
110  G4int N = 10000;
111  G4int n = 0;
112
113  G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
114
115  for(G4int i=0; i<N; i++)
116  {
117    G4ThreeVector point = t1.GetPointOnSurface();
118    point.setX(std::fabs(point.x()));
119    point.setY(std::fabs(point.y()));
120   
121    G4ThreeVector out (100*cm, 100*cm, 100*cm);
122   
123    G4ThreeVector dir = point - out;
124    G4double dist2 = dir.mag();
125    dir /= dist2;
126   
127    G4double dist1 = t1.DistanceToIn(point,dir);
128    G4double diff = std::fabs(dist1 - dist2);
129   
130    if(diff < 2.*kCarTolerance)
131      n++;     
132  }
133
134  G4cout <<" ************   For testG4EllipticalCone   ******************"<<G4endl<<G4endl;
135  G4cout <<" Number of inconsistencies for testDistanceToIn was: "<< n <<" ..."<<G4endl
136         <<" ... For a total of "<<N<<" trials."<< G4endl <<G4endl;
137
138  return true;
139}
140G4bool testDistanceToOut() 
141{   
142  G4EllipticalCone t1("Solid EllipticalCone #1", 
143                      2*cm,       // xSemiAxis
144                      1*cm,       // ySemiAxis 
145                      15*cm,      // zheight
146                      10*cm) ;    // zTopCut
147 
148  G4int N = 10000;
149  G4int n = 0;
150
151  G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
152
153  for(G4int i=0; i<N; i++)
154  {
155    G4ThreeVector point = t1.GetPointOnSurface();
156    point.setX(std::fabs(point.x()));
157    point.setY(std::fabs(point.y()));
158   
159    G4ThreeVector out (0*cm, 0*cm, 0*cm);
160   
161    G4ThreeVector dir = point - out;
162    G4double dist2 = dir.mag();
163    dir /= dist2;
164   
165    G4double dist1 = t1.DistanceToOut(point,dir);
166    G4double diff = std::fabs(dist1 - dist2);
167   
168    if(diff < 2.*kCarTolerance)
169      n++;     
170  }
171
172  G4cout <<" ************   For testG4EllipticalCone   ******************"<<G4endl<<G4endl;
173  G4cout <<" Number of inconsistencies for testDistanceToOut was: "<< n <<" ..."<<G4endl
174         <<" ... For a total of "<<N<<" trials."<< G4endl <<G4endl;
175
176  return true;
177}
178
179 
180int main() 
181{ 
182
183  G4cout << G4endl;
184  G4cout << "*********************************************************************" <<G4endl;
185  G4cout << "****************** UNIT TEST FOR ELLIPTICAL CONE ********************" <<G4endl;
186  G4cout << "*********************************************************************" <<G4endl;
187  G4cout << G4endl;
188
189  // temporary test
190  G4ThreeVector Spoint ;
191  G4double dist ;
192
193  G4EllipticalCone t1("Solid EllipticalCone #1",
194                      0.5*mm,       // xSemiAxis
195                      1*mm,       // ySemiAxis
196                      40*cm,      // zheight   
197                      25*cm) ;    // zTopCut
198 
199
200  EInside side ; 
201  for ( G4int i = 0 ; i < 3 ; i++ ) {
202    // G4cout << "Event " << i << G4endl << G4endl ;
203    Spoint = t1.GetPointOnSurface() ;
204    side = t1.Inside(Spoint) ;
205    dist = t1.DistanceToIn(Spoint, -Spoint/Spoint.mag()) ;
206    G4cout << "Spoint " << Spoint << " " <<  dist  << " " << side  << G4endl ;
207  }
208
209#ifdef NDEBUG
210  G4Exception("FAIL: *** Assertions must be compiled in! ***");
211#endif
212  assert(testG4EllipticalCone()); 
213   
214  G4bool what;
215  what = testDistanceToIn();
216  what = testDistanceToOut();
217  G4cout << G4endl;
218  G4cout << "*********************************************************************" <<G4endl;
219  G4cout << "******************* END OF TEST - THANK YOU!!! **********************" <<G4endl;
220  G4cout << "*********************************************************************" <<G4endl;
221  G4cout << G4endl;
222
223  return 0;
224}
Note: See TracBrowser for help on using the repository browser.