source: trunk/source/geometry/solids/test/testSurfaceAreaCube.cc@ 1330

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

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

File size: 4.6 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: testSurfaceAreaCube.cc,v 1.1 2006/10/20 14:38:52 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
29//
30// --------------------------------------------------------------------
31// Adapted by Hans Dierckx to test surface Area
32
33// The MC method is applied to different solids that have a total surface
34// area of 100 units. The method is repeated 20 times, after which the
35// average and standard deviation is calculated. This generates the graphs
36// in the report, if one would set the right values for N and gamma in
37// G4VSolid.cc.
38
39// Ensure asserts are compiled in
40
41#include <assert.h>
42#include <cmath>
43#include <ctime>
44
45#include "globals.hh"
46#include "geomdefs.hh"
47
48#include "G4ThreeVector.hh"
49
50#include "G4Box.hh"
51#include "G4Tubs.hh"
52#include "G4Trap.hh"
53#include "G4Trd.hh"
54#include "G4Para.hh"
55#include "G4Sphere.hh"
56#include "G4Orb.hh"
57#include "G4Torus.hh"
58#include "G4Cons.hh"
59#include "G4BooleanSolid.hh"
60#include "G4IntersectionSolid.hh"
61
62#include "G4RotationMatrix.hh"
63#include "G4AffineTransform.hh"
64#include "G4VoxelLimits.hh"
65
66
67#include "Randomize.hh"
68
69/*
70G4bool testG4Surf()
71{
72 G4double surf, MCsurf;
73
74 G4cout << "\n\nCalculating Box:" << G4endl;
75 G4Box box("Test Box",1,0.5,3);
76 // fDx fDy fDz
77 surf = box.GetSurfaceArea();
78 G4cout <<"Surface = " << surf << G4endl;
79 G4IntersectionSolid box2("Box 2", &box, &w);
80 MCsurf= box2.GetSurfaceArea();
81 G4cout <<"MC result = " << MCsurf << G4endl;
82 G4cout << "deviation =" << (surf-MCsurf)/surf*100 << " %"<< G4endl;
83 G4cout <<"*******************" << G4endl;
84
85 return true;
86}
87*/
88
89int main()
90{
91
92 // initialise random generator:
93 CLHEP::RanluxEngine defaultEngine(1234567,4);
94 CLHEP::HepRandom::setTheEngine(&defaultEngine);
95 G4int seed = time(NULL);
96 CLHEP::HepRandom::setTheSeed(seed);
97
98
99 // testobj = Sphere
100 G4Box w("Bigger Box",5,5,5);
101 // G4double R = std::sqrt(25./pi);
102 //G4Orb sol("Orb",R);
103
104 // G4double R= std::sqrt(100./16./pi);
105 // G4Tubs sol("Test Cyl",0.5*R,1.5*R,1.5*R,0,twopi);
106
107 G4double R = std::sqrt(2.5);
108 G4Trd sol("Test Trd", R,2*R, 2*R,R,std::sqrt(3.)*0.5*R);
109 //Dx1,Dx2,Dy1,Dy2,Dz
110 G4double exsurf = sol.GetSurfaceArea();
111 G4cout << "Exact result:"<< exsurf << G4endl;
112 G4IntersectionSolid sol2("Box 2", &sol, &w);
113
114 for(G4int N = 100000; N<=10000001; N *=10){
115 G4double scale;
116 for(scale=2; scale>=0.00096; scale /=2){
117 G4double sum = 0;
118 G4double std = 0;
119 G4double s;
120 G4double rep = 20;
121 for(G4int p=0; p<rep;p++)
122 {
123 sol2.SetAreaStatistics(N); // Inside loop to force area
124 sol2.SetAreaAccuracy(scale*R); // recomputation for calculating
125 s = sol2.GetSurfaceArea(); // average result ...
126 sum =sum+s;
127 std =std+(exsurf-s)*(exsurf-s);
128 }
129 G4double avsurf = sum/rep;
130 std = std::sqrt(std/(rep-1));
131 G4cout << "MC result: N= "<< N << " Average = "<< avsurf
132 << " std= " << std << " scale = "<< scale << G4endl;
133 }
134}
135 return 0;
136}
Note: See TracBrowser for help on using the repository browser.