PathSegmentList.h
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \class genie::geometry::PathSegmentList
5 
6 \brief Object to be filled with the neutrino path-segments representing
7  geometry volume steps (generally boundary-to-boundary) along with
8  geometry materials. Good for a single starting position and
9  travelling along the direction of the neutrino 4-momentum.
10 
11 \author Robert Hatcher <rhatcher@fnal.gov>
12  FNAL
13 
14 \created May 26, 2009
15 
16 \cpright Copyright (c) 2003-2019, The GENIE Collaboration
17  For the full text of the license visit http://copyright.genie-mc.org
18  or see $GENIE/LICENSE
19 */
20 //____________________________________________________________________________
21 
22 #ifndef _PATH_SEGMENT_LIST_H_
23 #define _PATH_SEGMENT_LIST_H_
24 
25 /// --- for test purposes allow compilation of class without string member
26 /// fetching/keeping the geometry path seems to add a significant (2x)
27 /// overhead to swimming through the geometry.
28 #define PATHSEG_KEEP_PATH
29 //#undef PATHSEG_KEEP_PATH
30 
31 #include <utility> // for pair<>
32 #include <vector>
33 #include <list>
34 #include <ostream>
35 #include <string>
36 #include <map>
37 
38 #include <TVector3.h>
39 class TGeoVolume;
40 class TGeoMedium;
41 class TGeoMaterial;
42 
43 using std::vector;
44 using std::ostream;
45 using std::string;
46 using std::pair;
47 
48 namespace genie {
49 namespace geometry {
50 
51 class PathSegment;
52 ostream & operator << (ostream & stream, const PathSegment & list);
53 
54 typedef std::pair<Double_t,Double_t> StepRange;
55 typedef std::vector<StepRange> StepRangeSet;
56 
57 class PathSegment {
58 
59  public:
60  PathSegment();
61  ~PathSegment() { ; }
62 
63  /// point of entry to geometry element
64  void SetEnter(const TVector3 & p3enter, double raydist)
65  { fEnter = p3enter; fRayDist = raydist; }
66  void SetEnter(const Double_t * p3enter, double raydist)
67  { fEnter.SetXYZ(p3enter[0],p3enter[1],p3enter[2]); fRayDist = raydist; }
68 
69  /// point of exit from geometry element
70  void SetExit(const TVector3 & p3exit) { fExit = p3exit; }
71  void SetExit(const Double_t * p3exit)
72  { fExit.SetXYZ(p3exit[0],p3exit[1],p3exit[2]); }
73 
74  /// info about the geometry element
75  void SetGeo(const TGeoVolume * gvol, const TGeoMedium * gmed,
76  const TGeoMaterial * gmat)
77  { fVolume = gvol; fMedium = gmed; fMaterial = gmat; }
78 #ifdef PATHSEG_KEEP_PATH
79  void SetPath(const char* path) { fPathString = path; }
80 #endif
81 
82  /// step taken in the geometry element
83  void SetStep(Double_t step, bool setlimits = true );
84 
85  bool IsTrimmedEmpty() const { return fStepRangeSet.empty(); }
86 
87  /// get the sum of all the step range (in case step has been trimmed or split)
88  Double_t GetSummedStepRange() const;
89 
90  /// calculate position within allowed ranges passed on fraction of total
91  TVector3 GetPosition(Double_t frac) const;
92 
93  /// perform cross check on segment, return differences
94  void DoCrossCheck(const TVector3& startpos, double& ddist, double& dstep) const;
95 
96  //void Copy (const PathSegment & ps);
97  //PathSegment& operator = (const PathSegment & ps);
98 
99  void Print (ostream & stream) const;
100  friend ostream & operator << (ostream & stream, const PathSegment & list);
101  friend bool operator < (const PathSegment &lhs, const PathSegment &rhs);
102 
103 
104  Double_t fRayDist; ///< distance from start of ray
105  Double_t fStepLength; ///< total step size in volume
106  const TGeoVolume * fVolume; ///< ref only ptr to TGeoVolume
107  const TGeoMedium * fMedium; ///< ref only ptr to TGeoMedium
108  const TGeoMaterial * fMaterial; ///< ref only ptr to TGeoMaterial
109  TVector3 fEnter; ///< top vol coordinates and units
110  TVector3 fExit; ///< top vol coordinates and units
111 #ifdef PATHSEG_KEEP_PATH
112  std::string fPathString; ///< full path names
113 #endif
114  StepRangeSet fStepRangeSet; ///< collection of {steplo,stephi} pairs
115 };
116 
117 inline bool operator < (const PathSegment &lhs, const PathSegment &rhs)
118  { return ( lhs.fRayDist < rhs.fRayDist ); }
119 
120 
121 class PathSegmentList;
122 ostream & operator << (ostream & stream, const PathSegmentList & list);
123 
125 
126 public :
127  PathSegmentList();
129  ~PathSegmentList();
130 
131  void SetDoCrossCheck (bool doit = true) { fDoCrossCheck = doit; }
132  void SetPrintVerbose (bool doit = true) { fPrintVerbose = doit; }
133  void SetAllToZero (void);
134  void SetStartInfo (const TVector3& pos = TVector3(0,0,1e37),
135  const TVector3& dir = TVector3(0,0,0) );
136  bool IsSameStart (const TVector3& pos, const TVector3& dir) const;
137  void AddSegment (const PathSegment& ps) { fSegmentList.push_back(ps); }
138 
139  const TVector3& GetDirection() const { return fDirection; }
140  const TVector3& GetStartPos() const { return fStartPos; }
141 
142  typedef std::list<PathSegment> PathSegmentV_t;
143  typedef PathSegmentV_t::const_iterator PathSegVCItr_t;
144 
145  const PathSegmentV_t& GetPathSegmentV (void) const { return fSegmentList; }
146  size_t size(void) const { return fSegmentList.size(); }
147 
148  typedef std::map<const TGeoMaterial*,Double_t> MaterialMap_t;
149  typedef MaterialMap_t::const_iterator MaterialMapCItr_t;
150 
151  void FillMatStepSum (void);
152  const MaterialMap_t& GetMatStepSumMap (void) const { return fMatStepSum; };
153 
154  void CrossCheck(double& mxddist, double& mxdstep) const;
155 
156 #ifdef UNNEEDED_SEGFUNCS
157  // XmlParserStatus_t LoadFromXml (string filename);
158  // void SaveAsXml (string filename) const;
159 #endif
160 
161  void Copy (const PathSegmentList & plist);
162  PathSegmentList & operator = (const PathSegmentList & list);
163 
164  void Print (ostream & stream) const;
165  friend ostream & operator << (ostream & stream, const PathSegmentList & list);
166 
167  protected:
168 
169  /// Record, for future comparison, the path taken
170  TVector3 fStartPos; ///< starting position (in top vol coords)
171  TVector3 fDirection; ///< direction (in top vol coords)
172 
173  /// Actual list of segments
174  PathSegmentV_t fSegmentList;
175 
176  /// Segment list re-evaluated by material for fast lookup of path lengths
177  MaterialMap_t fMatStepSum;
178 
181 
182 };
183 
184 } // geometry namespace
185 } // genie namespace
186 
187 #endif // _PATH_SEGMENT_LIST_H_
void SetEnter(const TVector3 &p3enter, double raydist)
point of entry to geometry element
const TVector3 & GetStartPos() const
void SetPrintVerbose(bool doit=true)
PathSegmentV_t fSegmentList
Actual list of segments.
std::vector< StepRange > StepRangeSet
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
MaterialMap_t fMatStepSum
Segment list re-evaluated by material for fast lookup of path lengths.
void SetPath(const char *path)
StepRangeSet fStepRangeSet
collection of {steplo,stephi} pairs
TVector3 fEnter
top vol coordinates and units
TVector3 fStartPos
Record, for future comparison, the path taken.
void SetEnter(const Double_t *p3enter, double raydist)
void AddSegment(const PathSegment &ps)
friend ostream & operator<<(ostream &stream, const PathSegment &list)
Object to be filled with the neutrino path-segments representing geometry volume steps (generally bou...
const TVector3 & GetDirection() const
void SetStep(Double_t step, bool setlimits=true)
step taken in the geometry element
const TGeoMaterial * fMaterial
ref only ptr to TGeoMaterial
PathSegmentV_t::const_iterator PathSegVCItr_t
void Print(ostream &stream) const
TVector3 fDirection
direction (in top vol coords)
const TGeoVolume * fVolume
ref only ptr to TGeoVolume
TVector3 fExit
top vol coordinates and units
const TGeoMedium * fMedium
ref only ptr to TGeoMedium
double frac(double x)
Fractional part.
Double_t GetSummedStepRange() const
get the sum of all the step range (in case step has been trimmed or split)
std::pair< Double_t, Double_t > StepRange
const PathSegmentV_t & GetPathSegmentV(void) const
MaterialMap_t::const_iterator MaterialMapCItr_t
const std::string path
Definition: plot_BEN.C:43
Double_t fRayDist
distance from start of ray
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
friend bool operator<(const PathSegment &lhs, const PathSegment &rhs)
void SetDoCrossCheck(bool doit=true)
TDirectory * dir
Definition: macro.C:5
void SetGeo(const TGeoVolume *gvol, const TGeoMedium *gmed, const TGeoMaterial *gmat)
info about the geometry element
std::map< const TGeoMaterial *, Double_t > MaterialMap_t
TVector3 GetPosition(Double_t frac) const
calculate position within allowed ranges passed on fraction of total
const MaterialMap_t & GetMatStepSumMap(void) const
void SetExit(const Double_t *p3exit)
void SetExit(const TVector3 &p3exit)
point of exit from geometry element
std::initializer_list< hep_hpc::hdf5::PropertyList > plist
void DoCrossCheck(const TVector3 &startpos, double &ddist, double &dstep) const
perform cross check on segment, return differences
std::list< PathSegment > PathSegmentV_t
std::ostream & operator<<(std::ostream &stream, const genie::geometry::PlaneParam &pparam)
Definition: FidShape.cxx:26
Double_t fStepLength
total step size in volume
std::string fPathString
full path names