GENIEGenerator
Loading...
Searching...
No Matches
FidShape.h
Go to the documentation of this file.
1//____________________________________________________________________________
2/*!
3
4\class genie::geometry::FidShape
5
6\brief Some simple volumes that know how to calculate where a ray
7 intercepts them.
8
9 Some of the algorithms here are (loosely) based on those found in:
10 Graphics Gems II, ISBN 0-12-064480-0
11 pg. 247 "Fast Ray-Convex Polyhedron Intersection"
12 Graphics Gems IV, ed. Paul Heckbert, ISBN 0-12-336156-7 T385.G6974 (1994)
13 pg. 356 "Intersecting a Ray with a Cylinder"
14
15\author Robert Hatcher <rhatcher@fnal.gov>
16 FNAL
17
18\created August 3, 2010
19
20\cpright Copyright (c) 2003-2025, The GENIE Collaboration
21 For the full text of the license visit http://copyright.genie-mc.org
22*/
23//____________________________________________________________________________
24
25#ifndef _FID_SHAPE_H_
26#define _FID_SHAPE_H_
27
28#include <vector>
29#include <cfloat> // for DBL_MAX
30
31#include "TMath.h"
32#include "TLorentzVector.h"
33
34namespace genie {
35namespace geometry {
36
38
39class PlaneParam;
40std::ostream& operator<< (std::ostream& stream,
41 const genie::geometry::PlaneParam& pparam);
42
44 /// A class to hold information about where a ray intercepts a
45 /// convex shape.
46 public:
47 RayIntercept() : fDistIn(-DBL_MAX), fDistOut(DBL_MAX),
48 fIsHit(false), fSurfIn(-1), fSurfOut(-1) { ; }
50 Double_t fDistIn; /// distance along ray to enter fid volume
51 Double_t fDistOut; /// distance along ray to exit fid volume
52 Bool_t fIsHit; /// was the volume hit
53 Int_t fSurfIn; /// what surface was hit on way in
54 Int_t fSurfOut; /// what surface was hit on way out
55};
56std::ostream& operator<< (std::ostream& stream,
58
60 // A plane is described by the equation a*x +b*y + c*z + d = 0
61 // n = [a,b,c] are the plane normal components (one must be non-zero)
62 // d is the distance to the origin
63 // for a point "p" on the plane: d = - p.n (note the "-")
64 public:
65 PlaneParam(Double_t ain=0, Double_t bin=0, Double_t cin=0, Double_t din=0)
66 { a = ain; b = bin; c = cin; d = din; Normalize(); }
67 PlaneParam(Double_t* abcd)
68 { a = abcd[0]; b = abcd[1]; c = abcd[2]; d = abcd[3]; Normalize(); }
69
70 void Normalize() // make the a,b,c parameters a unit normal
71 { Double_t mag = TMath::Sqrt(a*a+b*b+c*c);
72 if (mag>0) { a /= mag; b /= mag; c /= mag; d /= mag; } }
73 Double_t Vn(const TVector3& raybase) const
74 { return raybase.X()*a + raybase.Y()*b + raybase.Z()*c + d; }
75 Double_t Vd(const TVector3& raycos) const
76 { return raycos.Px()*a + raycos.Py()*b + raycos.Pz()*c; }
77 Bool_t IsValid() const { return (a != 0 || b != 0 || c != 0 ); }
78 void ConvertMaster2Top(const ROOTGeomAnalyzer* rgeom);
79 void Print(std::ostream& stream) const;
80 friend std::ostream& operator<< (std::ostream& stream,
81 const genie::geometry::PlaneParam& pparam);
82
83 Double_t a, b, c, d; // the parameters
84};
85
86class FidShape;
87std::ostream& operator<< (std::ostream& stream,
88 const genie::geometry::FidShape& shape);
89
90class FidShape {
91 // generic fiducial shape
92 public:
93 FidShape() { ; }
94 virtual ~FidShape() { ; }
95 /// derived classes must implement the Intercept() method
96 /// which calculates the entry/exit point of a ray w/ the shape
97 virtual RayIntercept Intercept(const TVector3& start, const TVector3& dir) const = 0;
98 /// derived classes must implement the ConvertMaster2Top() method
99 /// which transforms the shape specification from master coordinates to "top vol"
100 virtual void ConvertMaster2Top(const ROOTGeomAnalyzer* rgeom) = 0;
101 virtual void Print(std::ostream& stream) const = 0;
102 friend std::ostream& operator<< (std::ostream& stream,
103 const genie::geometry::FidShape& shape);
104
105};
106
107class FidSphere : public FidShape {
108 public:
109 FidSphere(const TVector3& center, Double_t radius) : fCenter(center), fSRadius(radius) { ; }
110 RayIntercept Intercept(const TVector3& start, const TVector3& dir) const;
111 void ConvertMaster2Top(const ROOTGeomAnalyzer* rgeom);
112 void Print(std::ostream& stream) const;
113 protected:
114 TVector3 fCenter; /// center of the sphere
115 Double_t fSRadius; /// radius of the sphere
116};
117
118class FidCylinder : public FidShape {
119 public:
120 FidCylinder(const TVector3& base, const TVector3& axis, Double_t radius,
121 const PlaneParam& cap1, const PlaneParam& cap2)
122 : fCylBase(base), fCylAxis(axis), fCylRadius(radius), fCylCap1(cap1), fCylCap2(cap2) { ; }
123 RayIntercept Intercept(const TVector3& start, const TVector3& dir) const;
124 RayIntercept InterceptUncapped(const TVector3& start, const TVector3& dir) const;
125 void ConvertMaster2Top(const ROOTGeomAnalyzer* rgeom);
126 void Print(std::ostream& stream) const;
127 protected:
128
129 TVector3 fCylBase; /// base point on cylinder axis
130 TVector3 fCylAxis; /// direction cosines of cylinder axis
131 Double_t fCylRadius; /// radius of cylinder
132 PlaneParam fCylCap1; /// define a plane for 1st cylinder cap
133 PlaneParam fCylCap2; /// define a plane for 2nd cylinder cap
134};
135
136class FidPolyhedron : public FidShape {
137 /// convex polyhedron is made of multiple planar equations
138 public:
140 void push_back(const PlaneParam& pln) { fPolyFaces.push_back(pln); }
141 void clear() { fPolyFaces.clear(); }
142 RayIntercept Intercept(const TVector3& start, const TVector3& dir) const;
143 void ConvertMaster2Top(const ROOTGeomAnalyzer* rgeom);
144 void Print(std::ostream& stream) const;
145 protected:
146 std::vector<PlaneParam> fPolyFaces; /// the collection of planar equations for the faces
147};
148
149} // geometry namespace
150} // genie namespace
151
152#endif // _FID_SHAPE_H_
string dir
TVector3 fCylAxis
base point on cylinder axis
Definition FidShape.h:130
PlaneParam fCylCap2
define a plane for 1st cylinder cap
Definition FidShape.h:133
RayIntercept InterceptUncapped(const TVector3 &start, const TVector3 &dir) const
Definition FidShape.cxx:113
Double_t fCylRadius
direction cosines of cylinder axis
Definition FidShape.h:131
PlaneParam fCylCap1
radius of cylinder
Definition FidShape.h:132
RayIntercept Intercept(const TVector3 &start, const TVector3 &dir) const
Definition FidShape.cxx:159
void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)
Definition FidShape.cxx:194
void Print(std::ostream &stream) const
Definition FidShape.cxx:203
FidCylinder(const TVector3 &base, const TVector3 &axis, Double_t radius, const PlaneParam &cap1, const PlaneParam &cap2)
Definition FidShape.h:120
std::vector< PlaneParam > fPolyFaces
Definition FidShape.h:146
void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)
Definition FidShape.cxx:296
RayIntercept Intercept(const TVector3 &start, const TVector3 &dir) const
Definition FidShape.cxx:216
FidPolyhedron()
convex polyhedron is made of multiple planar equations
Definition FidShape.h:139
void Print(std::ostream &stream) const
Definition FidShape.cxx:303
void push_back(const PlaneParam &pln)
Definition FidShape.h:140
Some simple volumes that know how to calculate where a ray intercepts them.
Definition FidShape.h:90
virtual void Print(std::ostream &stream) const =0
virtual RayIntercept Intercept(const TVector3 &start, const TVector3 &dir) const =0
virtual void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)=0
friend std::ostream & operator<<(std::ostream &stream, const genie::geometry::FidShape &shape)
void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)
Definition FidShape.cxx:98
Double_t fSRadius
center of the sphere
Definition FidShape.h:115
RayIntercept Intercept(const TVector3 &start, const TVector3 &dir) const
Definition FidShape.cxx:69
void Print(std::ostream &stream) const
Definition FidShape.cxx:104
FidSphere(const TVector3 &center, Double_t radius)
Definition FidShape.h:109
void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)
Definition FidShape.cxx:48
PlaneParam(Double_t ain=0, Double_t bin=0, Double_t cin=0, Double_t din=0)
Definition FidShape.h:65
Bool_t IsValid() const
Definition FidShape.h:77
void Print(std::ostream &stream) const
Definition FidShape.cxx:63
friend std::ostream & operator<<(std::ostream &stream, const genie::geometry::PlaneParam &pparam)
Double_t Vd(const TVector3 &raycos) const
Definition FidShape.h:75
PlaneParam(Double_t *abcd)
Definition FidShape.h:67
Double_t Vn(const TVector3 &raybase) const
Definition FidShape.h:73
A ROOT/GEANT4 geometry driver.
Int_t fSurfIn
was the volume hit
Definition FidShape.h:53
Int_t fSurfOut
what surface was hit on way in
Definition FidShape.h:54
Bool_t fIsHit
distance along ray to exit fid volume
Definition FidShape.h:52
Double_t fDistOut
distance along ray to enter fid volume
Definition FidShape.h:51
GENIE geometry drivers.
std::ostream & operator<<(std::ostream &stream, const genie::geometry::PlaneParam &pparam)
Definition FidShape.cxx:22
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25