G4Root Version 6.6
Loading...
Searching...
No Matches
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
43static const Double_t gCm = 1. / cm;
44
45//______________________________________________________________________________
46TG4RootSolid::TG4RootSolid(TGeoShape* shape) : G4VSolid(shape->GetName())
47{
49 fShape = shape;
50}
51
52//______________________________________________________________________________
53G4bool 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//______________________________________________________________________________
66EInside 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//______________________________________________________________________________
85G4ThreeVector 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//______________________________________________________________________________
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//______________________________________________________________________________
130G4double 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//______________________________________________________________________________
143G4double 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//______________________________________________________________________________
186G4double 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//______________________________________________________________________________
199void TG4RootSolid::ComputeDimensions(G4VPVParameterisation* /*p*/,
200 const G4int /*n*/, const G4VPhysicalVolume* /*pRep*/)
201{
204 G4cout << "Warning: TG4RootSolid::ComputeDimensions() not implemented"
205 << G4endl;
206}
207
208//______________________________________________________________________________
210{
216 G4double capacity = fShape->Capacity() * cm3;
217 return capacity;
218}
219
220//______________________________________________________________________________
221G4GeometryType TG4RootSolid::GetEntityType() const
222{
225 return G4String(fShape->ClassName());
226}
227
228//______________________________________________________________________________
230{
232 G4cout << "Warning: TG4RootSolid::GetPointOnSurface() not implemented"
233 << G4endl;
234 return G4ThreeVector(0., 0., 0.);
235}
236
237//______________________________________________________________________________
238std::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//______________________________________________________________________________
260void TG4RootSolid::DescribeYourselfTo(G4VGraphicsScene& scene) const
261{
264 scene.AddSolid(*this);
265}
266
267//______________________________________________________________________________
268G4VisExtent 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//______________________________________________________________________________
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//______________________________________________________________________________
294{
297 return NULL;
298}
299#endif
300
301//______________________________________________________________________________
302G4Polyhedron* TG4RootSolid::GetPolyhedron() const
303{
306 return CreatePolyhedron();
307}
308
309//______________________________________________________________________________
311{
313 return NULL;
314}
315
316//______________________________________________________________________________
318{
321 return NULL;
322}
323
324//______________________________________________________________________________
325const G4DisplacedSolid* TG4RootSolid::GetDisplacedSolidPtr() const
326{
328 return NULL;
329}
330
331//______________________________________________________________________________
333{
335 return NULL;
336}
static const double gCm
constant for conversion cm <-> mm
static const Double_t gCm
constant for conversion cm <-> mm
Definition of the TG4RootSolid class.
virtual G4GeometryType GetEntityType() const
virtual const G4VSolid * GetConstituentSolid(G4int no) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
virtual const G4DisplacedSolid * GetDisplacedSolidPtr() const
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const
virtual std::ostream & StreamInfo(std::ostream &os) const
virtual G4Polyhedron * GetPolyhedron() const
TGeoShape * fShape
TGeo associated shape.
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
virtual G4double GetCubicVolume()
virtual void ComputeDimensions(G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
TG4RootSolid()
Default ctor.
virtual G4NURBS * CreateNURBS() const
virtual G4ThreeVector GetPointOnSurface() const
virtual G4VisExtent GetExtent() const
virtual G4Polyhedron * CreatePolyhedron() const
virtual EInside Inside(const G4ThreeVector &p) const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const