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