G4Root
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
g4root
src
TG4RootSolid.cxx
Go to the documentation of this file.
1
// @(#)root/g4root:$Id$
2
// Author: Andrei Gheata 07/08/06
3
4
/*************************************************************************
5
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6
* All rights reserved. *
7
* *
8
* For the licensing terms see $ROOTSYS/LICENSE. *
9
* For the list of contributors see $ROOTSYS/README/CREDITS. *
10
*************************************************************************/
11
16
17
#include "
TG4RootSolid.h
"
18
19
#include "G4AffineTransform.hh"
20
#include "G4Polyhedron.hh"
21
#include "G4VGraphicsScene.hh"
22
#include "G4VPVParameterisation.hh"
23
#include "G4Version.hh"
24
#include "G4VoxelLimits.hh"
25
#if G4VERSION_NUMBER < 1000
26
#include "G4NURBS.hh"
27
#include "G4NURBSbox.hh"
28
#endif
29
// #include "G4SystemOfUnits.hh"
30
#include "G4VisExtent.hh"
31
32
#include "TGeoBBox.h"
33
#include "TGeoShape.h"
34
#include "TMath.h"
35
36
// Moved after ROOT includes to avoid warnings about shadowing variables
37
// from CLHEP units
38
#include <G4SystemOfUnits.hh>
39
40
// ClassImp(TG4RootSolid)
41
43
static
const
Double_t
gCm
= 1. / cm;
44
45
//______________________________________________________________________________
46
TG4RootSolid::TG4RootSolid
(TGeoShape* shape) :
G4VSolid
(shape->GetName())
47
{
49
fShape
= shape;
50
}
51
52
//______________________________________________________________________________
53
G4bool
TG4RootSolid::CalculateExtent
(
const
EAxis
/*pAxis*/
,
54
const
G4VoxelLimits&
/*pVoxelLimit*/
,
const
G4AffineTransform&
/*pTransform*/
,
55
G4double&
/*pMin*/
, G4double&
/*pMax*/
)
const
56
{
60
G4cout <<
"Warning: TG4RootSolid::CalculateExtent() not implemented"
61
<< G4endl;
62
return
false
;
63
}
64
65
//______________________________________________________________________________
66
EInside
TG4RootSolid::Inside
(
const
G4ThreeVector& p)
const
67
{
71
Double_t pt[3];
72
pt[0] = p.x() *
gCm
;
73
pt[1] = p.y() *
gCm
;
74
pt[2] = p.z() *
gCm
;
75
Bool_t in =
fShape
->Contains(pt);
76
// Temporary computation of safety due to the fact that TGeoShape does
77
// not return kSurface
78
G4double safety =
fShape
->Safety(pt, in) * cm;
79
if
(TMath::Abs(safety) < 0.5 * kCarTolerance)
return
kSurface;
80
if
(in)
return
kInside;
81
return
kOutside;
82
}
83
84
//______________________________________________________________________________
85
G4ThreeVector
TG4RootSolid::SurfaceNormal
(
const
G4ThreeVector& p)
const
88
{
89
Double_t pt[3], dir[3], norm[3];
90
pt[0] = p.x() *
gCm
;
91
pt[1] = p.y() *
gCm
;
92
pt[2] = p.z() *
gCm
;
93
dir[0] = 0.0;
94
dir[1] = 0.0;
95
dir[2] = 1.0;
96
fShape
->ComputeNormal(pt, dir, norm);
97
pt[0] += norm[0] * 2. * kCarTolerance;
98
pt[1] += norm[1] * 2. * kCarTolerance;
99
pt[2] += norm[2] * 2. * kCarTolerance;
100
// Do a trick that should work if the point p is on the surface...
101
G4ThreeVector n(norm[0], norm[1], norm[2]);
102
Bool_t in =
fShape
->Contains(pt);
103
if
(!in)
return
n;
104
n.set(-norm[0], -norm[1], -norm[2]);
105
return
n;
106
}
107
108
//______________________________________________________________________________
109
G4double
TG4RootSolid::DistanceToIn
(
110
const
G4ThreeVector& p,
const
G4ThreeVector& v)
const
111
{
117
Double_t pt[3], dir[3];
118
pt[0] = p.x() *
gCm
;
119
pt[1] = p.y() *
gCm
;
120
pt[2] = p.z() *
gCm
;
121
dir[0] = v.x();
122
dir[1] = v.y();
123
dir[2] = v.z();
124
G4double dist =
fShape
->DistFromOutside(pt, dir, 3) * cm;
125
if
(dist < TGeoShape::Big())
return
dist;
126
return
kInfinity;
127
}
128
129
//______________________________________________________________________________
130
G4double
TG4RootSolid::DistanceToIn
(
const
G4ThreeVector& p)
const
131
{
134
Double_t pt[3];
135
pt[0] = p.x() *
gCm
;
136
pt[1] = p.y() *
gCm
;
137
pt[2] = p.z() *
gCm
;
138
G4double safety =
fShape
->Safety(pt, kFALSE) * cm;
139
return
safety;
140
}
141
142
//______________________________________________________________________________
143
G4double
TG4RootSolid::DistanceToOut
(
const
G4ThreeVector& p,
144
const
G4ThreeVector& v,
const
G4bool calcNorm, G4bool* validNorm,
145
G4ThreeVector* n)
const
146
{
162
Double_t pt[3], dir[3], norm[3];
163
pt[0] = p.x() *
gCm
;
164
pt[1] = p.y() *
gCm
;
165
pt[2] = p.z() *
gCm
;
166
dir[0] = v.x();
167
dir[1] = v.y();
168
dir[2] = v.z();
169
G4double dist =
fShape
->DistFromInside(pt, dir, 3) * cm;
170
if
(calcNorm) *validNorm =
true
;
171
if
(dist < 0.5 * kCarTolerance)
172
dist = 0.;
173
else
{
174
pt[0] += dist * dir[0];
175
pt[1] += dist * dir[1];
176
pt[2] += dist * dir[2];
177
}
178
if
(calcNorm) {
179
fShape
->ComputeNormal(pt, dir, norm);
180
*n = G4ThreeVector(norm[0], norm[1], norm[2]);
181
}
182
return
dist;
183
}
184
185
//______________________________________________________________________________
186
G4double
TG4RootSolid::DistanceToOut
(
const
G4ThreeVector& p)
const
187
{
190
Double_t pt[3];
191
pt[0] = p.x() *
gCm
;
192
pt[1] = p.y() *
gCm
;
193
pt[2] = p.z() *
gCm
;
194
G4double safety =
fShape
->Safety(pt, kTRUE) * cm;
195
return
safety;
196
}
197
198
//______________________________________________________________________________
199
void
TG4RootSolid::ComputeDimensions
(G4VPVParameterisation*
/*p*/
,
200
const
G4int
/*n*/
,
const
G4VPhysicalVolume*
/*pRep*/
)
201
{
204
G4cout <<
"Warning: TG4RootSolid::ComputeDimensions() not implemented"
205
<< G4endl;
206
}
207
208
//______________________________________________________________________________
209
G4double
TG4RootSolid::GetCubicVolume
()
210
{
216
G4double capacity =
fShape
->Capacity() * cm3;
217
return
capacity;
218
}
219
220
//______________________________________________________________________________
221
G4GeometryType
TG4RootSolid::GetEntityType
()
const
222
{
225
return
G4String(
fShape
->ClassName());
226
}
227
228
//______________________________________________________________________________
229
G4ThreeVector
TG4RootSolid::GetPointOnSurface
()
const
230
{
232
G4cout <<
"Warning: TG4RootSolid::GetPointOnSurface() not implemented"
233
<< G4endl;
234
return
G4ThreeVector(0., 0., 0.);
235
}
236
237
//______________________________________________________________________________
238
std::ostream&
TG4RootSolid::StreamInfo
(std::ostream& os)
const
239
{
241
os <<
"-----------------------------------------------------------\n"
242
<<
" *** Dump for solid - "
<< GetName() <<
" ***\n"
243
<<
" ===================================================\n"
244
<<
" Solid type: ROOT solid / "
<<
fShape
->ClassName() <<
"\n"
245
<<
" Bounding box: \n"
246
<<
" half length X: "
<< ((TGeoBBox*)
fShape
)->GetDX() * cm / mm
247
<<
" mm \n"
248
<<
" half length Y: "
<< ((TGeoBBox*)
fShape
)->GetDY() * cm / mm
249
<<
" mm \n"
250
<<
" half length Z: "
<< ((TGeoBBox*)
fShape
)->GetDZ() * cm / mm
251
<<
" mm \n"
252
<<
"-----------------------------------------------------------\n"
;
253
254
return
os;
255
}
256
257
// Visualization functions
258
259
//______________________________________________________________________________
260
void
TG4RootSolid::DescribeYourselfTo
(G4VGraphicsScene& scene)
const
261
{
264
scene.AddSolid(*
this
);
265
}
266
267
//______________________________________________________________________________
268
G4VisExtent
TG4RootSolid::GetExtent
()
const
269
{
271
G4double dx = ((TGeoBBox*)
fShape
)->GetDX() * cm;
272
G4double dy = ((TGeoBBox*)
fShape
)->GetDY() * cm;
273
G4double dz = ((TGeoBBox*)
fShape
)->GetDZ() * cm;
274
const
Double_t* origin = ((TGeoBBox*)
fShape
)->GetOrigin();
275
G4double ox = origin[0] * cm;
276
G4double oy = origin[1] * cm;
277
G4double oz = origin[2] * cm;
278
return
G4VisExtent(-dx + ox, dx + ox, -dy + oy, dy + oy, -dz + oz, dz + oz);
279
}
280
281
//______________________________________________________________________________
282
G4Polyhedron*
TG4RootSolid::CreatePolyhedron
()
const
283
{
285
G4double dx = ((TGeoBBox*)
fShape
)->GetDX() * cm;
286
G4double dy = ((TGeoBBox*)
fShape
)->GetDY() * cm;
287
G4double dz = ((TGeoBBox*)
fShape
)->GetDZ() * cm;
288
return
new
G4PolyhedronBox(dx, dy, dz);
289
}
290
291
#if G4VERSION_NUMBER < 1000
292
//______________________________________________________________________________
293
G4NURBS*
TG4RootSolid::CreateNURBS
()
const
294
{
297
return
NULL;
298
}
299
#endif
300
301
//______________________________________________________________________________
302
G4Polyhedron*
TG4RootSolid::GetPolyhedron
()
const
303
{
306
return
CreatePolyhedron
();
307
}
308
309
//______________________________________________________________________________
310
const
G4VSolid
*
TG4RootSolid::GetConstituentSolid
(G4int
/*no*/
)
const
311
{
313
return
NULL;
314
}
315
316
//______________________________________________________________________________
317
G4VSolid
*
TG4RootSolid::GetConstituentSolid
(G4int
/*no*/
)
318
{
321
return
NULL;
322
}
323
324
//______________________________________________________________________________
325
const
G4DisplacedSolid*
TG4RootSolid::GetDisplacedSolidPtr
()
const
326
{
328
return
NULL;
329
}
330
331
//______________________________________________________________________________
332
G4DisplacedSolid*
TG4RootSolid::GetDisplacedSolidPtr
()
333
{
335
return
NULL;
336
}
gCm
static const double gCm
constant for conversion cm <-> mm
Definition
TG4RootNavigator.cxx:30
TG4RootSolid.h
Definition of the TG4RootSolid class.
G4VSolid
TG4RootSolid::GetEntityType
virtual G4GeometryType GetEntityType() const
Definition
TG4RootSolid.cxx:221
TG4RootSolid::GetConstituentSolid
virtual const G4VSolid * GetConstituentSolid(G4int no) const
Definition
TG4RootSolid.cxx:310
TG4RootSolid::DistanceToIn
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
Definition
TG4RootSolid.cxx:109
TG4RootSolid::GetDisplacedSolidPtr
virtual const G4DisplacedSolid * GetDisplacedSolidPtr() const
Definition
TG4RootSolid.cxx:325
TG4RootSolid::DistanceToOut
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
Definition
TG4RootSolid.cxx:143
TG4RootSolid::StreamInfo
virtual std::ostream & StreamInfo(std::ostream &os) const
Definition
TG4RootSolid.cxx:238
TG4RootSolid::GetPolyhedron
virtual G4Polyhedron * GetPolyhedron() const
Definition
TG4RootSolid.cxx:302
TG4RootSolid::fShape
TGeoShape * fShape
TGeo associated shape.
Definition
TG4RootSolid.h:35
TG4RootSolid::CalculateExtent
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
Definition
TG4RootSolid.cxx:53
TG4RootSolid::GetCubicVolume
virtual G4double GetCubicVolume()
Definition
TG4RootSolid.cxx:209
TG4RootSolid::ComputeDimensions
virtual void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
Definition
TG4RootSolid.cxx:199
TG4RootSolid::TG4RootSolid
TG4RootSolid()
Default ctor.
Definition
TG4RootSolid.h:38
TG4RootSolid::CreateNURBS
virtual G4NURBS * CreateNURBS() const
Definition
TG4RootSolid.cxx:293
TG4RootSolid::GetPointOnSurface
virtual G4ThreeVector GetPointOnSurface() const
Definition
TG4RootSolid.cxx:229
TG4RootSolid::GetExtent
virtual G4VisExtent GetExtent() const
Definition
TG4RootSolid.cxx:268
TG4RootSolid::CreatePolyhedron
virtual G4Polyhedron * CreatePolyhedron() const
Definition
TG4RootSolid.cxx:282
TG4RootSolid::Inside
virtual EInside Inside(const G4ThreeVector &p) const
Definition
TG4RootSolid.cxx:66
TG4RootSolid::SurfaceNormal
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
Definition
TG4RootSolid.cxx:85
TG4RootSolid::DescribeYourselfTo
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const
Definition
TG4RootSolid.cxx:260
Generated on
for G4Root by
1.17.0