Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JMARKOV::JPhotonPath Class Reference

A photon path. More...

#include <JPhotonPath.hh>

Inheritance diagram for JMARKOV::JPhotonPath:
JGEOMETRY3D::JPolyline3D JIO::JSerialisable std::vector< JGEOMETRY3D::JPosition3D >

Public Member Functions

 JPhotonPath ()
 default constructor
 
 JPhotonPath (int _nscat)
 constructor to actually be used
 
string getString ()
 get a string with the path vertex positions
 
double getLength ()
 get the total path length
 
void addVertex ()
 
void addVertex (JPosition3D &pos)
 
bool hitsSphere (const JPosition3D &pos, double r)
 Returns whether the photon path intersects a sphere of radius r at position pos.
 
JPosition3D getSphereHitPosition (const JPosition3D &pos, double r)
 Returns the position where the photon hits a sphere of radius r at position pos. If the photon does not hit, it returns (0,0,0).
 
std::vector< JPosition3DgetPointsWithX (double x)
 return all coordinates where the photon path has the given x
 
std::vector< JPosition3DgetPointsWithY (double y)
 return all coordinates where the photon path has the given y
 
std::vector< JPosition3DgetPointsWithZ (double z)
 return all coordinates where the photon path has the given z
 
JIO::JReaderread (JIO::JReader &in)
 Read from input.
 
JIO::JWriterwrite (JIO::JWriter &out) const
 Write to output.
 
const JPolyline3DgetPolyline () const
 Get polyline.
 
JPolyline3DgetPolyline ()
 Get polyline.
 
JPolyline3Dtransform (const JMatrix3D &T)
 Transform all vertices.
 
void transform (const JRotation3D &R, const JVector3D &pos)
 Transform all vertices of the polyline with a rotation and offset.
 
JPolyline3Drotate (const JRotation3D &R)
 Rotate all vertices.
 
JPolyline3Drotate (const JRotation3X &R)
 Rotate all vertices around X-axis.
 
JPolyline3Drotate (const JRotation3Y &R)
 Rotate all vertices around Y-axis.
 
JPolyline3Drotate (const JRotation3Z &R)
 Rotate all vertices around Z-axis.
 
JPolyline3Drotate_back (const JRotation3D &R)
 Rotate back all vertices.
 
JPolyline3Drotate_back (const JRotation3X &R)
 Rotate all vertices back around X-axis.
 
JPolyline3Drotate_back (const JRotation3Y &R)
 Rotate all vertices back around Y-axis.
 
JPolyline3Drotate_back (const JRotation3Z &R)
 Rotate all vertices back around Z-axis.
 
void transform_back (const JRotation3D &R, const JVector3D &pos)
 Transform back all vertices of the polyline.
 

Public Attributes

int n
 
double weight
 

Detailed Description

A photon path.

This is basically a JPolyline3D with at least two vertices and a weight.

Definition at line 38 of file JPhotonPath.hh.

Constructor & Destructor Documentation

◆ JPhotonPath() [1/2]

JMARKOV::JPhotonPath::JPhotonPath ( )
inline

default constructor

Definition at line 42 of file JPhotonPath.hh.

42: n(2), weight(1) { resize(n) ; }

◆ JPhotonPath() [2/2]

JMARKOV::JPhotonPath::JPhotonPath ( int _nscat)
inline

constructor to actually be used

Definition at line 45 of file JPhotonPath.hh.

45: n(_nscat+2), weight(1) { resize(n) ; }

Member Function Documentation

◆ getString()

string JMARKOV::JPhotonPath::getString ( )

get a string with the path vertex positions

Definition at line 136 of file JPhotonPath.hh.

136 {
137 ostringstream oss ;
138 for( unsigned int i=0 ; i<size() ; ++i ) {
139 oss << at(i) ;
140 if( i+1!=size() ) oss << ", " ;
141 }
142 return oss.str() ;
143 }

◆ getLength()

double JMARKOV::JPhotonPath::getLength ( )

get the total path length

Definition at line 104 of file JPhotonPath.hh.

104 {
105 iterator v1 = begin() ;
106 iterator v2(v1) ;
107 ++v2 ;
108 double L = 0 ;
109 for( ; v2!=end() ; ++v1,++v2 ) {
110 // length of path segment
111 L += (*v2-*v1).getLength() ;
112 }
113 return L ;
114 }
double getLength()
get the total path length

◆ addVertex() [1/2]

void JMARKOV::JPhotonPath::addVertex ( )
inline

Definition at line 53 of file JPhotonPath.hh.

53 {
54 JPosition3D pos(0,0,0) ;
55 addVertex(pos) ;
56 }

◆ addVertex() [2/2]

void JMARKOV::JPhotonPath::addVertex ( JPosition3D & pos)

Definition at line 116 of file JPhotonPath.hh.

116 {
117 ++n ;
118 push_back(pos) ;
119 }

◆ hitsSphere()

bool JMARKOV::JPhotonPath::hitsSphere ( const JPosition3D & pos,
double r )

Returns whether the photon path intersects a sphere of radius r at position pos.

Definition at line 176 of file JPhotonPath.hh.

176 {
177 // loop over the path segments
178 for( unsigned int i=1 ; i<size() ; ++i ) {
179 // the current path segment is from x1 to x2
180
181 // vector pointing from x1 to x2
182 JPosition3D seg = at(i)-at(i-1) ;
183 JVersor3D dir_seg(seg) ; // normalized version of seg
184 double Lseg = seg.getLength() ;
185
186 // vector pointing from the center of the sphere to x1
187 JPosition3D to_center(at(i-1)-pos) ;
188 JVersor3D dir_to_center(to_center) ; // normalized version of to_center
189 double r_to_center = to_center.getLength() ;
190
191 // cosine of angle between the two directions
192 double ct = dir_seg.getDot(dir_to_center) ;
193
194 // if sin^2(theta) > (r_to_center/radius)^2
195 if( 1-ct*ct > r*r/(r_to_center*r_to_center) ) {
196 // definitely no hit in this segment
197 // continue with the next one
198 continue ;
199 }
200
201 // the segment can be parametrized as x1 + xi * dir_seg
202 // where xi is in the range [0,Lseg]
203 // there are two possible solutions for xi
204 double D = sqrt( r_to_center*r_to_center*(ct*ct-1) + r*r ) ;
205 double xi1 = -r_to_center*ct + D ;
206 if( xi1>0 && xi1<Lseg ) return true ;
207 double xi2 = -r_to_center*ct - D ;
208 if( xi2>0 && xi2<Lseg ) return true ;
209 }
210 return false ;
211 }

◆ getSphereHitPosition()

JPosition3D JMARKOV::JPhotonPath::getSphereHitPosition ( const JPosition3D & pos,
double r )

Returns the position where the photon hits a sphere of radius r at position pos. If the photon does not hit, it returns (0,0,0).

Definition at line 213 of file JPhotonPath.hh.

213 {
214 // loop over the path segments
215 for( unsigned int i=1 ; i<size() ; ++i ) {
216 // the current path segment is from x1 to x2
217
218 // vector pointing from x1 to x2
219 JPosition3D seg = at(i)-at(i-1) ;
220 JVersor3D dir_seg(seg) ; // normalized version of seg
221 double Lseg = seg.getLength() ;
222
223 // vector pointing from the center of the sphere to x1
224 JPosition3D to_center(at(i-1)-pos) ;
225 JVersor3D dir_to_center(to_center) ; // normalized version of to_center
226 double r_to_center = to_center.getLength() ;
227
228 // cosine of angle between the two directions
229 double ct = dir_seg.getDot(dir_to_center) ;
230
231 // if sin^2(theta) > (r_to_center/radius)^2
232 if( 1-ct*ct > r*r/(r_to_center*r_to_center) ) {
233 // definitely no hit in this segment
234 // continue with the next one
235 continue ;
236 }
237
238 // the segment can be parametrized as x1 + xi * dir_seg
239 // where xi is in the range [0,Lseg]
240 // there are two possible solutions for xi
241 double D = sqrt( r_to_center*r_to_center*(ct*ct-1) + r*r ) ;
242
243 // first xi
244 double xi1 = -r_to_center*ct + D ;
245 if( xi1<0 || xi1>Lseg ) {
246 xi1 = 1.1*Lseg ;
247 }
248
249 // second xi
250 double xi2 = -r_to_center*ct - D ;
251 // if this is a xi within the segment
252 if( xi2>0 && xi2<Lseg ) {
253 // and it is before xi1, we replace xi1
254 if( xi2<xi1 ) xi1 = xi2 ;
255 }
256
257 if( xi1>0 && xi1<Lseg ) {
258 return at(i-1) + JPosition3D(dir_seg)*xi1 ;
259 }
260 }
261 return JPosition3D(0,0,0) ;
262 }

◆ getPointsWithX()

std::vector< JPosition3D > JMARKOV::JPhotonPath::getPointsWithX ( double x)

return all coordinates where the photon path has the given x

Definition at line 121 of file JPhotonPath.hh.

121 {
123
124 // loop over the path segments
125 for( unsigned int i=1 ; i<size() ; ++i ) {
126 JPosition3D v1( at(i-1) ) ;
127 JPosition3D v2( at(i) ) ;
128 if( (v1.getX()>x) != (v2.getX()>x) ) {
129 double frac = (x-v1.getX())/(v2.getX()-v1.getX()) ;
130 res.push_back( v1+frac*(v2-v1) ) ;
131 }
132 }
133 return res ;
134 }

◆ getPointsWithY()

std::vector< JPosition3D > JMARKOV::JPhotonPath::getPointsWithY ( double y)

return all coordinates where the photon path has the given y

Definition at line 145 of file JPhotonPath.hh.

145 {
147
148 // loop over the path segments
149 for( unsigned int i=1 ; i<size() ; ++i ) {
150 JPosition3D v1( at(i-1) ) ;
151 JPosition3D v2( at(i) ) ;
152 if( (v1.getY()>y) != (v2.getY()>y) ) {
153 double frac = (y-v1.getY())/(v2.getY()-v1.getY()) ;
154 res.push_back( v1+frac*(v2-v1) ) ;
155 }
156 }
157 return res ;
158 }

◆ getPointsWithZ()

std::vector< JPosition3D > JMARKOV::JPhotonPath::getPointsWithZ ( double z)

return all coordinates where the photon path has the given z

Definition at line 160 of file JPhotonPath.hh.

160 {
162
163 // loop over the path segments
164 for( unsigned int i=1 ; i<size() ; ++i ) {
165 JPosition3D v1( at(i-1) ) ;
166 JPosition3D v2( at(i) ) ;
167 if( (v1.getZ()>z) != (v2.getZ()>z) ) {
168 double frac = (z-v1.getZ())/(v2.getZ()-v1.getZ()) ;
169 res.push_back( v1+frac*(v2-v1) ) ;
170 }
171 }
172 return res ;
173 }

◆ read()

JIO::JReader & JMARKOV::JPhotonPath::read ( JIO::JReader & in)
inlinevirtual

Read from input.

Parameters
inJReader
Returns
JReader

Implements JIO::JSerialisable.

Definition at line 75 of file JPhotonPath.hh.

75 {
76 // read number of vertices and adjust size accordingly
77 in >> n ;
78 if( n>0 ) resize(n) ;
79 // read vertices
80 for( iterator it=begin() ; it!=end() ; ++it )
81 in >> *it ;
82 // read weight
83 in >> weight ;
84
85 return in ;
86 }

◆ write()

JIO::JWriter & JMARKOV::JPhotonPath::write ( JIO::JWriter & out) const
inlinevirtual

Write to output.

Parameters
outJWriter
Returns
JWriter

Implements JIO::JSerialisable.

Definition at line 88 of file JPhotonPath.hh.

88 {
89 // write size
90 out << (int)size() ;
91 // write vertices
92 for( const_iterator it=begin() ; it!=end() ; ++it )
93 out << *it ; //it->getX() << it->getY() << it->getZ() ;
94 // write weight
95 out << weight ;
96
97 return out ;
98 }

◆ getPolyline() [1/2]

const JPolyline3D & JGEOMETRY3D::JPolyline3D::getPolyline ( ) const
inlineinherited

Get polyline.

Returns
polyline

Definition at line 43 of file JPolyline3D.hh.

43 {
44 return static_cast<const JPolyline3D&>(*this);
45 }
JPolyline3D()
default constructor

◆ getPolyline() [2/2]

JPolyline3D & JGEOMETRY3D::JPolyline3D::getPolyline ( )
inlineinherited

Get polyline.

Returns
polyline

Definition at line 52 of file JPolyline3D.hh.

53 {
54 return static_cast<JPolyline3D&>(*this);
55 }

◆ transform() [1/2]

JPolyline3D & JGEOMETRY3D::JPolyline3D::transform ( const JMatrix3D & T)
inlineinherited

Transform all vertices.

Parameters
Tmatrix

Definition at line 62 of file JPolyline3D.hh.

62 {
63 for( iterator it=begin(); it!=end() ; ++it ) it->transform(T) ;
64 return *this;
65 }

◆ transform() [2/2]

void JGEOMETRY3D::JPolyline3D::transform ( const JRotation3D & R,
const JVector3D & pos )
inlineinherited

Transform all vertices of the polyline with a rotation and offset.

See the corresponding function in JPosition3D for more information

Parameters
Rrotation matrix
posposition of origin (after rotation)

Definition at line 157 of file JPolyline3D.hh.

157 {
158 for( iterator it=begin(); it!=end() ; ++it ) it->transform(R,pos) ;
159 }

◆ rotate() [1/4]

JPolyline3D & JGEOMETRY3D::JPolyline3D::rotate ( const JRotation3D & R)
inlineinherited

Rotate all vertices.

Parameters
Rrotation matrix

Definition at line 72 of file JPolyline3D.hh.

73 {
74 for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R);
75 return *this;
76 }

◆ rotate() [2/4]

JPolyline3D & JGEOMETRY3D::JPolyline3D::rotate ( const JRotation3X & R)
inlineinherited

Rotate all vertices around X-axis.

Parameters
Rrotation matrix

Definition at line 93 of file JPolyline3D.hh.

93 {
94 for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R);
95 return *this;
96 }

◆ rotate() [3/4]

JPolyline3D & JGEOMETRY3D::JPolyline3D::rotate ( const JRotation3Y & R)
inlineinherited

Rotate all vertices around Y-axis.

Parameters
Rrotation matrix

Definition at line 114 of file JPolyline3D.hh.

114 {
115 for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R);
116 return *this;
117 }

◆ rotate() [4/4]

JPolyline3D & JGEOMETRY3D::JPolyline3D::rotate ( const JRotation3Z & R)
inlineinherited

Rotate all vertices around Z-axis.

Parameters
Rrotation matrix

Definition at line 135 of file JPolyline3D.hh.

135 {
136 for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R);
137 return *this;
138 }

◆ rotate_back() [1/4]

JPolyline3D & JGEOMETRY3D::JPolyline3D::rotate_back ( const JRotation3D & R)
inlineinherited

Rotate back all vertices.

Parameters
Rrotation matrix

Definition at line 83 of file JPolyline3D.hh.

83 {
84 for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ;
85 return *this;
86 }

◆ rotate_back() [2/4]

JPolyline3D & JGEOMETRY3D::JPolyline3D::rotate_back ( const JRotation3X & R)
inlineinherited

Rotate all vertices back around X-axis.

Parameters
Rrotation matrix

Definition at line 103 of file JPolyline3D.hh.

103 {
104 for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ;
105 return *this;
106 }

◆ rotate_back() [3/4]

JPolyline3D & JGEOMETRY3D::JPolyline3D::rotate_back ( const JRotation3Y & R)
inlineinherited

Rotate all vertices back around Y-axis.

Parameters
Rrotation matrix

Definition at line 125 of file JPolyline3D.hh.

125 {
126 for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ;
127 return *this;
128 }

◆ rotate_back() [4/4]

JPolyline3D & JGEOMETRY3D::JPolyline3D::rotate_back ( const JRotation3Z & R)
inlineinherited

Rotate all vertices back around Z-axis.

Parameters
Rrotation matrix

Definition at line 145 of file JPolyline3D.hh.

145 {
146 for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ;
147 return *this;
148 }

◆ transform_back()

void JGEOMETRY3D::JPolyline3D::transform_back ( const JRotation3D & R,
const JVector3D & pos )
inlineinherited

Transform back all vertices of the polyline.

Parameters
Rrotation matrix
pospolyline of origin (before rotation)

Definition at line 167 of file JPolyline3D.hh.

167 {
168 for( iterator it=begin(); it!=end() ; ++it ) it->transform_back(R,pos) ;
169 }

Member Data Documentation

◆ n

int JMARKOV::JPhotonPath::n

Definition at line 100 of file JPhotonPath.hh.

◆ weight

double JMARKOV::JPhotonPath::weight

Definition at line 101 of file JPhotonPath.hh.


The documentation for this class was generated from the following file: