GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2024, 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 
34 namespace genie {
35 namespace geometry {
36 
37 class ROOTGeomAnalyzer;
38 
39 class PlaneParam;
40 std::ostream& operator<< (std::ostream& stream,
41  const genie::geometry::PlaneParam& pparam);
42 
43 class RayIntercept {
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) { ; }
49  ~RayIntercept() { ; }
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 };
56 std::ostream& operator<< (std::ostream& stream,
58 
59 class PlaneParam {
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 
86 class FidShape;
87 std::ostream& operator<< (std::ostream& stream,
88  const genie::geometry::FidShape& shape);
89 
90 class 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 
107 class 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 
118 class 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 
136 class 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_
Some simple volumes that know how to calculate where a ray intercepts them.
Definition: FidShape.h:90
void Print(std::ostream &stream) const
Definition: FidShape.cxx:203
Int_t fSurfOut
what surface was hit on way in
Definition: FidShape.h:54
void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)
Definition: FidShape.cxx:48
Double_t Vn(const TVector3 &raybase) const
Definition: FidShape.h:73
RayIntercept Intercept(const TVector3 &start, const TVector3 &dir) const
Definition: FidShape.cxx:159
Bool_t fIsHit
distance along ray to exit fid volume
Definition: FidShape.h:52
string dir
PlaneParam(Double_t ain=0, Double_t bin=0, Double_t cin=0, Double_t din=0)
Definition: FidShape.h:65
PlaneParam fCylCap1
radius of cylinder
Definition: FidShape.h:132
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
Int_t fSurfIn
was the volume hit
Definition: FidShape.h:53
friend std::ostream & operator<<(std::ostream &stream, const genie::geometry::PlaneParam &pparam)
RayIntercept InterceptUncapped(const TVector3 &start, const TVector3 &dir) const
Definition: FidShape.cxx:113
A ROOT/GEANT4 geometry driver.
void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)
Definition: FidShape.cxx:296
PlaneParam(Double_t *abcd)
Definition: FidShape.h:67
Double_t fCylRadius
direction cosines of cylinder axis
Definition: FidShape.h:131
TVector3 fCylAxis
base point on cylinder axis
Definition: FidShape.h:130
virtual RayIntercept Intercept(const TVector3 &start, const TVector3 &dir) const =0
FidCylinder(const TVector3 &base, const TVector3 &axis, Double_t radius, const PlaneParam &cap1, const PlaneParam &cap2)
Definition: FidShape.h:120
virtual void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)=0
void Print(std::ostream &stream) const
Definition: FidShape.cxx:63
RayIntercept Intercept(const TVector3 &start, const TVector3 &dir) const
Definition: FidShape.cxx:69
Double_t fDistOut
distance along ray to enter fid volume
Definition: FidShape.h:51
void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)
Definition: FidShape.cxx:98
Bool_t IsValid() const
Definition: FidShape.h:77
void ConvertMaster2Top(const ROOTGeomAnalyzer *rgeom)
Definition: FidShape.cxx:194
Double_t fSRadius
center of the sphere
Definition: FidShape.h:115
std::vector< PlaneParam > fPolyFaces
Definition: FidShape.h:146
friend std::ostream & operator<<(std::ostream &stream, const genie::geometry::FidShape &shape)
PlaneParam fCylCap2
define a plane for 1st cylinder cap
Definition: FidShape.h:133
FidSphere(const TVector3 &center, Double_t radius)
Definition: FidShape.h:109
virtual void Print(std::ostream &stream) const =0
void push_back(const PlaneParam &pln)
Definition: FidShape.h:140
std::ostream & operator<<(std::ostream &stream, const genie::geometry::PlaneParam &pparam)
Definition: FidShape.cxx:22
Double_t Vd(const TVector3 &raycos) const
Definition: FidShape.h:75
void Print(std::ostream &stream) const
Definition: FidShape.cxx:104
void Print(std::ostream &stream) const
Definition: FidShape.cxx:303