Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoShape.h
Go to the documentation of this file.
1// @(#)root/geom:$Id$
2// Author: Andrei Gheata 31/01/02
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
12#ifndef ROOT_TGeoShape
13#define ROOT_TGeoShape
14
15#include "TNamed.h"
16
17// forward declarations
19class TGeoBBox;
20class TGeoMatrix;
21class TGeoHMatrix;
22class TGeoVolume;
23class TBuffer3D;
24
25class TGeoShape : public TNamed {
26private:
27 static TGeoMatrix *fgTransform; // current transformation matrix that applies to shape
28 static Double_t fgEpsMch; // Machine round-off error
29public:
67
68 enum EInside {
71 kSurface = 3
72 };
73
74 virtual void ClearThreadData() const {}
75 virtual void CreateThreadData(Int_t) {}
76
77protected:
78 // data members
79 Int_t fShapeId; // shape id
80 UInt_t fShapeBits; // shape bits
81 // methods
82 virtual void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections, Bool_t localFrame) const;
83 Int_t GetBasicColor() const;
84 void SetOnBoundary(Bool_t /*flag=kTRUE*/) {}
86
87public:
88 // constructors
89 TGeoShape();
90 TGeoShape(const char *name);
91 // destructor
92 ~TGeoShape() override;
93 // methods
94
95 static Double_t Big() { return 1.E30; }
96 static TGeoMatrix *GetTransform();
97 static void SetTransform(TGeoMatrix *matrix);
98 static Double_t Tolerance() { return 1.E-10; }
99 static Double_t ComputeEpsMch();
100 static Double_t EpsMch();
101 virtual void AfterStreamer(){};
102 virtual Double_t Capacity() const = 0;
103 void CheckShape(Int_t testNo, Int_t nsamples = 10000, Option_t *option = "");
104 virtual void ComputeBBox() = 0;
105 virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const = 0;
106 virtual void ComputeNormal_v(const Double_t *, const Double_t *, Double_t *, Int_t) {}
107 virtual Bool_t Contains(const Double_t *point) const = 0;
108 virtual void Contains_v(const Double_t *, Bool_t *, Int_t) const {}
109 virtual Bool_t CouldBeCrossed(const Double_t *point, const Double_t *dir) const = 0;
110 Int_t DistancetoPrimitive(Int_t px, Int_t py) override = 0;
111 virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact = 1,
112 Double_t step = TGeoShape::Big(), Double_t *safe = nullptr) const = 0;
113 virtual void DistFromInside_v(const Double_t *, const Double_t *, Double_t *, Int_t, Double_t *) const {}
114 virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact = 1,
115 Double_t step = TGeoShape::Big(), Double_t *safe = nullptr) const = 0;
116 virtual void DistFromOutside_v(const Double_t *, const Double_t *, Double_t *, Int_t, Double_t *) const {}
117 static Double_t DistToPhiMin(const Double_t *point, const Double_t *dir, Double_t s1, Double_t c1, Double_t s2,
119 virtual TGeoVolume *
120 Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step) = 0;
121 void Draw(Option_t *option = "") override; // *MENU*
122 void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
123 virtual const char *GetAxisName(Int_t iaxis) const = 0;
124 virtual Double_t GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const = 0;
125 virtual void GetBoundingCylinder(Double_t *param) const = 0;
127 virtual Int_t GetByteCount() const = 0;
128 virtual Bool_t GetPointsOnSegments(Int_t npoints, Double_t *array) const = 0;
129 virtual Int_t
131 Int_t GetId() const { return fShapeId; }
133 virtual void GetMeshNumbers(Int_t & /*nvert*/, Int_t & /*nsegs*/, Int_t & /*npols*/) const {}
134 const char *GetName() const override;
135 virtual Int_t GetNmeshVertices() const { return 0; }
136 const char *GetPointerName() const;
137 virtual EInside Inside(const Double_t *point) const;
138 virtual Bool_t IsAssembly() const { return kFALSE; }
139 virtual Bool_t IsComposite() const { return kFALSE; }
140 virtual Bool_t IsCylType() const = 0;
141 static Bool_t
143 static Bool_t IsCrossingSemiplane(const Double_t *point, const Double_t *dir, Double_t cphi, Double_t sphi,
148 static Bool_t IsInPhiRange(const Double_t *point, Double_t phi1, Double_t phi2);
149 virtual Bool_t IsReflected() const { return kFALSE; }
150 virtual Bool_t IsVecGeom() const { return kFALSE; }
153 virtual Bool_t IsValidBox() const = 0;
154 virtual void InspectShape() const = 0;
155 virtual TBuffer3D *MakeBuffer3D() const { return nullptr; }
156 static void NormalPhi(const Double_t *point, const Double_t *dir, Double_t *norm, Double_t c1, Double_t s1,
158 void Paint(Option_t *option = "") override;
159 virtual Double_t Safety(const Double_t *point, Bool_t in = kTRUE) const = 0;
160 virtual void Safety_v(const Double_t *, const Bool_t *, Double_t *, Int_t) const {}
161 static Double_t SafetyPhi(const Double_t *point, Bool_t in, Double_t phi1, Double_t phi2);
163 virtual void SetDimensions(Double_t *param) = 0;
164 void SetId(Int_t id) { fShapeId = id; }
165 virtual void SetPoints(Double_t *points) const = 0;
166 virtual void SetPoints(Float_t *points) const = 0;
167 virtual void SetSegsAndPols(TBuffer3D &buff) const = 0;
170 virtual void Sizeof3D() const = 0;
171
172 //----- bit manipulation
173 void SetShapeBit(UInt_t f, Bool_t set);
176 Bool_t TestShapeBit(UInt_t f) const { return (Bool_t)((fShapeBits & f) != 0); }
177 Int_t TestShapeBits(UInt_t f) const { return (Int_t)(fShapeBits & f); }
179
180 ClassDefOverride(TGeoShape, 2) // base class for shapes
181};
182
183namespace tgeo_impl {
184/// @brief Generic implementation of the inside function using just Contains and GetNormal
185template <typename Solid>
187{
188 // This emulates the Inside funtionality in Geant4 and VecGeom, i.e instead of
189 // just 'inside' and 'outside', points closer to the shape surface by less than
190 // TGeoShape::Tolerance() (1.e-9 mm) are considered on surface.
191 // This function is expensive because it costs 2 * Contains + 1 * GetNormal calls
192
193 // Compute the normal in the point, along a radial direction
196 constexpr double dir[3] = {1., 0., 0.};
197 double pt_push[3], pt_pull[3], norm[3];
198 solid->ComputeNormal(point, &dir[0], norm);
199 // Move the point back and forth along the normal and check if the Contains changes
200 for (auto i = 0; i < 3; ++i) {
201 pt_push[i] = point[i] + 10. * TGeoShape::Tolerance() * norm[i];
202 pt_pull[i] = point[i] - 10. * TGeoShape::Tolerance() * norm[i];
203 }
204 int in_push = solid->Contains(pt_push);
205 int in_pull = solid->Contains(pt_pull);
206 return kTable[in_push + 2 * in_pull];
207}
208} // namespace tgeo_impl
209
210#endif
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
#define s1(x)
Definition RSha256.hxx:91
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define BIT(n)
Definition Rtypes.h:91
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:110
Generic 3D primitive description class.
Definition TBuffer3D.h:18
Box class.
Definition TGeoBBox.h:17
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition TGeoMatrix.h:458
Geometrical transformation package.
Definition TGeoMatrix.h:38
Base abstract class for all shapes.
Definition TGeoShape.h:25
Int_t DistancetoPrimitive(Int_t px, Int_t py) override=0
Computes distance from point (px,py) to the object.
void SetOnBoundary(Bool_t)
Definition TGeoShape.h:84
Int_t TestShapeBits(UInt_t f) const
Definition TGeoShape.h:177
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
Stub implementation to avoid forcing implementation at this stage.
void SetId(Int_t id)
Definition TGeoShape.h:164
UInt_t fShapeBits
Definition TGeoShape.h:80
static Double_t Big()
Definition TGeoShape.h:95
virtual Double_t GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const =0
Int_t GetBasicColor() const
Get the basic color (0-7).
virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const =0
static Bool_t IsSegCrossing(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Double_t x3, Double_t y3, Double_t x4, Double_t y4)
Check if segments (A,B) and (C,D) are crossing, where: A(x1,y1), B(x2,y2), C(x3,y3),...
virtual void CreateThreadData(Int_t)
Definition TGeoShape.h:75
void TransformPoints(Double_t *points, UInt_t NbPoints) const
Tranform a set of points (LocalToMaster)
void SetShapeBit(UInt_t f, Bool_t set)
Equivalent of TObject::SetBit.
Bool_t IsValid() const
Definition TGeoShape.h:152
void ResetShapeBit(UInt_t f)
Definition TGeoShape.h:175
virtual Int_t GetNmeshVertices() const
Definition TGeoShape.h:135
virtual void GetMeshNumbers(Int_t &, Int_t &, Int_t &) const
Definition TGeoShape.h:133
static Double_t DistToPhiMin(const Double_t *point, const Double_t *dir, Double_t s1, Double_t c1, Double_t s2, Double_t c2, Double_t sm, Double_t cm, Bool_t in=kTRUE)
compute distance from point (inside phi) to both phi planes. Return minimum.
virtual void SetSegsAndPols(TBuffer3D &buff) const =0
void SetShapeBit(UInt_t f)
Definition TGeoShape.h:174
virtual void DistFromOutside_v(const Double_t *, const Double_t *, Double_t *, Int_t, Double_t *) const
Definition TGeoShape.h:116
TGeoShape()
Default constructor.
static Double_t SafetyPhi(const Double_t *point, Bool_t in, Double_t phi1, Double_t phi2)
Static method to compute safety w.r.t a phi corner defined by cosines/sines of the angles phi1,...
virtual void SetDimensions(Double_t *param)=0
virtual void Sizeof3D() const =0
Int_t fShapeId
Definition TGeoShape.h:79
virtual const char * GetAxisName(Int_t iaxis) const =0
virtual Bool_t GetPointsOnSegments(Int_t npoints, Double_t *array) const =0
static void SetTransform(TGeoMatrix *matrix)
Set current transformation matrix that applies to shape.
virtual void DistFromInside_v(const Double_t *, const Double_t *, Double_t *, Int_t, Double_t *) const
Definition TGeoShape.h:113
virtual TGeoVolume * Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step)=0
virtual Bool_t IsComposite() const
Definition TGeoShape.h:139
void InvertShapeBit(UInt_t f)
Definition TGeoShape.h:178
virtual void ComputeNormal_v(const Double_t *, const Double_t *, Double_t *, Int_t)
Definition TGeoShape.h:106
static Bool_t IsSameWithinTolerance(Double_t a, Double_t b)
Check if two numbers differ with less than a tolerance.
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const =0
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const =0
Bool_t IsRunTimeShape() const
Definition TGeoShape.h:151
virtual void Contains_v(const Double_t *, Bool_t *, Int_t) const
Definition TGeoShape.h:108
virtual void ClearThreadData() const
Definition TGeoShape.h:74
const char * GetPointerName() const
Provide a pointer name containing uid.
virtual void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections, Bool_t localFrame) const
Fill the supplied buffer, with sections in desired frame See TBuffer3D.h for explanation of sections,...
virtual Bool_t IsCylType() const =0
void CheckShape(Int_t testNo, Int_t nsamples=10000, Option_t *option="")
Test for shape navigation methods.
static Double_t EpsMch()
static function returning the machine round-off error
virtual EInside Inside(const Double_t *point) const
Implementation of the inside function using just Contains and GetNormal.
static Bool_t IsInPhiRange(const Double_t *point, Double_t phi1, Double_t phi2)
Static method to check if a point is in the phi range (phi1, phi2) [degrees].
static Double_t ComputeEpsMch()
Compute machine round-off double precision error as the smallest number that if added to 1....
void Paint(Option_t *option="") override
Paint this shape.
~TGeoShape() override
Destructor.
static TGeoMatrix * fgTransform
Definition TGeoShape.h:27
virtual void GetBoundingCylinder(Double_t *param) const =0
virtual void InspectShape() const =0
virtual Bool_t IsValidBox() const =0
virtual Bool_t IsReflected() const
Definition TGeoShape.h:149
Int_t ShapeDistancetoPrimitive(Int_t numpoints, Int_t px, Int_t py) const
Returns distance to shape primitive mesh.
virtual Int_t GetFittingBox(const TGeoBBox *parambox, TGeoMatrix *mat, Double_t &dx, Double_t &dy, Double_t &dz) const =0
static Double_t fgEpsMch
Definition TGeoShape.h:28
static void NormalPhi(const Double_t *point, const Double_t *dir, Double_t *norm, Double_t c1, Double_t s1, Double_t c2, Double_t s2)
Static method to compute normal to phi planes.
static Double_t SafetySeg(Double_t r, Double_t z, Double_t r1, Double_t z1, Double_t r2, Double_t z2, Bool_t outer)
Compute distance from point of coordinates (r,z) to segment (r1,z1):(r2,z2)
static Bool_t IsCrossingSemiplane(const Double_t *point, const Double_t *dir, Double_t cphi, Double_t sphi, Double_t &snext, Double_t &rxy)
Compute distance from POINT to semiplane defined by PHI angle along DIR.
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const =0
virtual Int_t GetByteCount() const =0
virtual Bool_t IsVecGeom() const
Definition TGeoShape.h:150
const char * GetName() const override
Get the shape name.
virtual void ComputeBBox()=0
virtual void AfterStreamer()
Definition TGeoShape.h:101
virtual Bool_t CouldBeCrossed(const Double_t *point, const Double_t *dir) const =0
virtual void Safety_v(const Double_t *, const Bool_t *, Double_t *, Int_t) const
Definition TGeoShape.h:160
static TGeoMatrix * GetTransform()
Returns current transformation matrix that applies to shape.
virtual Double_t Capacity() const =0
void SetRuntime(Bool_t flag=kTRUE)
Definition TGeoShape.h:168
virtual Bool_t Contains(const Double_t *point) const =0
virtual void SetPoints(Float_t *points) const =0
@ kGeoClosedShape
Definition TGeoShape.h:59
@ kGeoSavePrimitive
Definition TGeoShape.h:65
@ kGeoHalfSpace
Definition TGeoShape.h:62
@ kGeoThetaSeg
Definition TGeoShape.h:36
@ kGeoNoShape
Definition TGeoShape.h:32
@ kGeoInvalidShape
Definition TGeoShape.h:41
@ kGeoParaboloid
Definition TGeoShape.h:61
@ kGeoTubeSeg
Definition TGeoShape.h:47
@ kGeoRunTimeShape
Definition TGeoShape.h:40
@ kGeoConeSeg
Definition TGeoShape.h:49
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute mouse actions on this shape.
static Double_t Tolerance()
Definition TGeoShape.h:98
static Bool_t IsCloseToPhi(Double_t epsil, const Double_t *point, Double_t c1, Double_t s1, Double_t c2, Double_t s2)
True if point is closer than epsil to one of the phi planes defined by c1,s1 or c2,...
virtual TGeoShape * GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const =0
virtual void SetPoints(Double_t *points) const =0
virtual Bool_t IsAssembly() const
Definition TGeoShape.h:138
Bool_t TestShapeBit(UInt_t f) const
Definition TGeoShape.h:176
Int_t GetId() const
Definition TGeoShape.h:131
virtual TBuffer3D * MakeBuffer3D() const
Definition TGeoShape.h:155
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
return c1
Definition legend1.C:41
return c2
Definition legend2.C:14
TGeoShape::EInside Inside(const Double_t *point, Solid const *solid)
Generic implementation of the inside function using just Contains and GetNormal.
Definition TGeoShape.h:186
th1 Draw()