| [1316] | 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: testPointOnSurfacePoly.cc,v 1.3 2008/04/25 08:50:00 gcosmo Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // --------------------------------------------------------------
|
|---|
| 32 | //
|
|---|
| 33 | // Test for GetPointOnSurface() method of various solids.
|
|---|
| 34 | // Returns 0 if generated random points are located on surface.
|
|---|
| 35 | //
|
|---|
| 36 | // Author: Dionysios Anninos
|
|---|
| 37 | //
|
|---|
| 38 | // --------------------------------------------------------------
|
|---|
| 39 | #include <assert.h>
|
|---|
| 40 | #include <cmath>
|
|---|
| 41 |
|
|---|
| 42 | #include "globals.hh"
|
|---|
| 43 | #include "geomdefs.hh"
|
|---|
| 44 |
|
|---|
| 45 | #include "G4TwoVector.hh"
|
|---|
| 46 | #include "G4ThreeVector.hh"
|
|---|
| 47 |
|
|---|
| 48 | #include "G4Polycone.hh"
|
|---|
| 49 | #include "G4Polyhedra.hh"
|
|---|
| 50 |
|
|---|
| 51 | #include "G4Timer.hh"
|
|---|
| 52 | #include "Randomize.hh"
|
|---|
| 53 |
|
|---|
| 54 | #include "G4RotationMatrix.hh"
|
|---|
| 55 | #include "G4AffineTransform.hh"
|
|---|
| 56 | #include "G4VoxelLimits.hh"
|
|---|
| 57 |
|
|---|
| 58 | G4bool checkPolycone(G4int N)
|
|---|
| 59 | {
|
|---|
| 60 | G4cout<<"**************************************"<<G4endl;
|
|---|
| 61 | G4cout<<"************* G4POLYCONE *************"<<G4endl;
|
|---|
| 62 | G4cout<<"**************************************"<<G4endl<<G4endl;
|
|---|
| 63 |
|
|---|
| 64 | G4ThreeVector point;
|
|---|
| 65 | G4bool what = true;
|
|---|
| 66 | G4int i=0,n=0;
|
|---|
| 67 | EInside surf;
|
|---|
| 68 | //-------------------------------------------
|
|---|
| 69 | // Original Polycone Test
|
|---|
| 70 | //-------------------------------------------
|
|---|
| 71 | // G4double zPlanes[5] = {0., 1., 3., 5., 10.};
|
|---|
| 72 | // G4double rInner[5] = {6., 7., 2., 2., 10.};
|
|---|
| 73 | // G4double rOuter[5] = {8., 8., 10.,10., 15.};
|
|---|
| 74 | // G4Polycone t1("aPcone",
|
|---|
| 75 | // 0., 2.*pi,
|
|---|
| 76 | // 5,zPlanes,rInner,rOuter);
|
|---|
| 77 |
|
|---|
| 78 | //-------------------------------------------
|
|---|
| 79 | // Polycone Test Z1=Z2
|
|---|
| 80 | //-------------------------------------------
|
|---|
| 81 | // G4double zPlanes[4] = {0. ,27.5, 27.5, 59.};
|
|---|
| 82 | // G4double rInner[4] = {555.,555., 572., 572.};
|
|---|
| 83 | // G4double rOuter[4] = {669., 669., 652.,652.};
|
|---|
| 84 | // G4Polycone t1("aPcone",
|
|---|
| 85 | // 0., 2.*pi,
|
|---|
| 86 | // 4,zPlanes,rInner,rOuter);
|
|---|
| 87 | //-------------------------------------------
|
|---|
| 88 | // More Complex Polycone Test Z1=Z2
|
|---|
| 89 | //-------------------------------------------
|
|---|
| 90 | // G4double zPlanes[6] = {0., 61., 61., 72.3, 124.2,153.0};
|
|---|
| 91 | // G4double rInner[6] = {291., 291., 2016., 2016., 2044.,2044.};
|
|---|
| 92 | // //G4double rInner[6] = {291., 2016., 2016., 2016., 2044.,2044.};
|
|---|
| 93 | // G4double rOuter[6] = {2070.,2070.,2070.,2070.,2070.,2070.};
|
|---|
| 94 | // G4Polycone t1("aPcone",
|
|---|
| 95 | // 0., 2.*pi,
|
|---|
| 96 | // 6,zPlanes,rInner,rOuter);
|
|---|
| 97 | //----------------------------------------------------------------
|
|---|
| 98 | // Complex Polycone Example from CMS DetectorDescription via GDML
|
|---|
| 99 | //----------------------------------------------------------------
|
|---|
| 100 | G4double zPlanes[6] = {-5541.,-3750.,-3750.,3750.,3750.,5541.};
|
|---|
| 101 | G4double rInner[6] = {89.3,82.2452,1775.,1775.,82.2452,89.3};
|
|---|
| 102 | G4double rOuter[6] = {2950.,2950.,2950.,2950.,2950.,2950.};
|
|---|
| 103 | G4Polycone t1("aPcone",
|
|---|
| 104 | 0., 2.*pi,
|
|---|
| 105 | 6,zPlanes,rInner,rOuter);
|
|---|
| 106 | G4Timer time;
|
|---|
| 107 | time.Start();
|
|---|
| 108 |
|
|---|
| 109 | for(i=0; i<N; i++)
|
|---|
| 110 | {
|
|---|
| 111 | point = t1.GetPointOnSurface();
|
|---|
| 112 | surf = t1.Inside(point);
|
|---|
| 113 | if(surf != kSurface)
|
|---|
| 114 | {
|
|---|
| 115 | n++; what = false;
|
|---|
| 116 | G4cout <<" x "<<point.x()<<" y "<<point.y()<<" z "<<point.z()<<G4endl;
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | time.Stop();
|
|---|
| 121 |
|
|---|
| 122 | G4cout <<" Check PolyCone had "<<n<<" inconsistencies"<< G4endl;
|
|---|
| 123 | G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
|
|---|
| 124 | return what;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | G4bool checkPolyhedra(G4int N)
|
|---|
| 128 | {
|
|---|
| 129 | G4cout<<"**************************************"<<G4endl;
|
|---|
| 130 | G4cout<<"************* G4POLYHEDRA ************"<<G4endl;
|
|---|
| 131 | G4cout<<"**************************************"<<G4endl<<G4endl;
|
|---|
| 132 |
|
|---|
| 133 | G4ThreeVector point;
|
|---|
| 134 | G4bool what = true;
|
|---|
| 135 | G4int i=0,n=0;
|
|---|
| 136 | EInside surf;
|
|---|
| 137 | //-------------------------------------------
|
|---|
| 138 | // Original Polyhedra Test
|
|---|
| 139 | //-------------------------------------------
|
|---|
| 140 | // G4double zPlanes[5] = {-1., 10., 15., 25., 30.};
|
|---|
| 141 | // G4double rInner[5] = {0., 5., 0., 7., 1.};
|
|---|
| 142 | // G4double rOuter[5] = {21., 6., 15., 15., 38.};
|
|---|
| 143 |
|
|---|
| 144 | //// G4double z[10] = {30.,25.,15.,10.,-1.,-1.,10.,15.,25.,30.};
|
|---|
| 145 | //// G4double r[10] = {1.,7.,0.,5.,0.,21.,6.,15.,15.,38.};
|
|---|
| 146 |
|
|---|
| 147 | // G4Polyhedra t1("aPhedra",
|
|---|
| 148 | // 53.*deg, 163.*deg,
|
|---|
| 149 | // 8,5,zPlanes,rInner,rOuter);
|
|---|
| 150 |
|
|---|
| 151 | //// G4Polyhedra t1("aPhedra",
|
|---|
| 152 | //// 53.*deg, 163.*deg,
|
|---|
| 153 | //// 8, 10, r, z);
|
|---|
| 154 | //-------------------------------------------
|
|---|
| 155 | // More Complex Polyhedra with Z1=Z2
|
|---|
| 156 | //-------------------------------------------
|
|---|
| 157 | // G4double zPlanes[5] = {-1., 15., 15., 25., 30.};
|
|---|
| 158 | // G4double rInner[5] = {0., 5., 0., 7., 1.};
|
|---|
| 159 | // G4double rOuter[5] = {21., 6., 15., 15., 38.};
|
|---|
| 160 | // G4Polyhedra t1("aPhedra",
|
|---|
| 161 | // 53.*deg, 163.*deg,
|
|---|
| 162 | // 8,5,zPlanes,rInner,rOuter);
|
|---|
| 163 | //--------------------------------------------------------
|
|---|
| 164 | // Complex Polyhedra from CMS Detector Description via GDML
|
|---|
| 165 | //---------------------------------------------------------
|
|---|
| 166 | //
|
|---|
| 167 | // Example with numSide=1
|
|---|
| 168 | //
|
|---|
| 169 | //
|
|---|
| 170 | // G4double zPlanes[6] = {3240., 3704.6, 3750.22, 4460.79,4491.27, 5541.};
|
|---|
| 171 | // G4double rInner[6] = { 1775., 1775.,1775.,2770.71, 2813.42,2813.42};
|
|---|
| 172 | // G4double rOuter[6] = {1866.5,1866.5,1927.03, 2870., 2870., 2870.};
|
|---|
| 173 | // G4Polyhedra t1("aPhedra",
|
|---|
| 174 | // 350.*deg, 20.*deg,
|
|---|
| 175 | // 1,6,zPlanes,rInner,rOuter);
|
|---|
| 176 | //
|
|---|
| 177 | // Example with startPhi<0 and phiTotal=twopi
|
|---|
| 178 | //
|
|---|
| 179 | G4double zPlanes[8] = {3893.58, 3980.58, 3980.58, 4461.93,5167.08, 5167.08,5515.08,5541};
|
|---|
| 180 | G4double rInner[8] = { 1712.1,1750.11,399.902,447.946,518.33,518.33,553.065,553.065};
|
|---|
| 181 | G4double rOuter[8] = {1884.78,2000.23,2000.23,2639,2639,2459,2459,2459};
|
|---|
| 182 |
|
|---|
| 183 | G4Polyhedra t1("aPhedra",
|
|---|
| 184 | -10.*deg,360.*deg,
|
|---|
| 185 | 18,8,zPlanes,rInner,rOuter);
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 | G4Timer time;
|
|---|
| 189 | time.Start();
|
|---|
| 190 |
|
|---|
| 191 | for(i=0; i<N; i++)
|
|---|
| 192 | { G4cout <<"I="<<i<<" stil to check = "<<N-i<<G4endl;
|
|---|
| 193 |
|
|---|
| 194 | point = t1.GetPointOnSurface();
|
|---|
| 195 |
|
|---|
| 196 | surf = t1.Inside(point);
|
|---|
| 197 | if(surf != kSurface)
|
|---|
| 198 | {
|
|---|
| 199 | n++; what = false;
|
|---|
| 200 | G4cout <<"Inconsistence="<<n<<" x "<<point.x()<<" y "<<point.y()<<" z "<<point.z()<<G4endl;
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | time.Stop();
|
|---|
| 205 |
|
|---|
| 206 | G4cout <<" Check Polyhedra had "<<n<<" inconsistencies"<< G4endl;
|
|---|
| 207 | G4cout <<" Time taken was: "<<time.GetRealElapsed()<<" seconds."<<G4endl<<G4endl;
|
|---|
| 208 | return what;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | int main()
|
|---|
| 212 | {
|
|---|
| 213 | G4bool what;
|
|---|
| 214 | //G4int N = 10000000;
|
|---|
| 215 | G4int N = 50000;
|
|---|
| 216 |
|
|---|
| 217 | G4cout <<G4endl;
|
|---|
| 218 | G4cout <<"********************************************************************************"<<G4endl;
|
|---|
| 219 | G4cout <<"**************** TEST GET POINT ON SURFACE METHOD ******************************"<<G4endl;
|
|---|
| 220 | G4cout <<"******************** FOR "<<N<<" RANDOM POINTS *********************************"<<G4endl;
|
|---|
| 221 | G4cout <<"********************************************************************************"<<G4endl;
|
|---|
| 222 |
|
|---|
| 223 | G4cout <<G4endl<<G4endl;
|
|---|
| 224 |
|
|---|
| 225 | what = checkPolycone(N);
|
|---|
| 226 | // what = checkPolyhedra(N);
|
|---|
| 227 |
|
|---|
| 228 | G4cout <<G4endl;
|
|---|
| 229 |
|
|---|
| 230 | G4cout <<"********************************************************************************"<<G4endl;
|
|---|
| 231 | G4cout <<"********************** END OF POINT-ON-SURFACE TEST ****************************"<<G4endl;
|
|---|
| 232 | G4cout <<"********************************************************************************"<<G4endl;
|
|---|
| 233 | G4cout <<G4endl;
|
|---|
| 234 |
|
|---|
| 235 | return 0;
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|