Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMarkovPhotonTracker.hh
Go to the documentation of this file.
1 #ifndef H_MARKOV_PHOTON_TRACKER
2 #define H_MARKOV_PHOTON_TRACKER
3 
4 /**
5  * \author mjongen
6  */
7 
8 // c++ standard library includes
9 #include<iostream>
10 #include<iomanip>
11 #include<cmath>
12 #include<cstdlib>
13 
14 // root includes
15 #include "TObject.h"
16 #include "TH1F.h"
17 #include "TRandom3.h"
18 
19 // JPP includes
21 
22 namespace JMARKOV {}
23 namespace JPP { using namespace JMARKOV; }
24 
25 namespace JMARKOV {
26 
27  /**
28  The JMarkovPhotonTracker generates ensembles of photon paths by
29  tracking photons from a source to a target.
30 
31  The target is modelled as a sphere with finite radius r.
32 
33  Random numbers are drawn from gRandom.
34  **/
36  public:
37 
38  /// standard constructor
40 
41  /**
42  Track n photons.
43 
44  The tracks of all photons that hit the target are returned.
45  **/
46  std::vector<JPhotonPath> trackPhotons( unsigned long int n, JSourceModel* src, JScatteringModel* sm, JTargetModel* trg, double lambda_abs ) ;
47 
48  } ;
49 
51  const double lambda_scat = sm->getScatteringLength() ;
52  std::vector<JPhotonPath> ensemble ;
53 
54  for( unsigned long int i=0 ; i<n ; ++i ) {
55  // how long until the photon is absorbed
56  double Lmax = gRandom->Exp(lambda_abs) ;
57  // initial direction
58  JVersor3D dir = src->generateDirection() ;
59 
60  // current length of the photon path
61  double L = 0 ;
62  // how often the photon has scattered so far
63  int nscat = 0 ;
64 
65  // initialize path
66  JPhotonPath p(0) ;
67  p[0] = src->getPosition() ;
68  p[1] = src->getPosition() ; // temporary placeholder
69 
70  while( true ) {
71  // distance until next scattering (or absorption)
72  double stepsize = gRandom->Exp( lambda_scat ) ;
73  // whether this is going to be the last step
74  bool isAbsorbed = false ;
75  if( stepsize > Lmax-L ) {
76  stepsize = Lmax-L ;
77  isAbsorbed = true ;
78  }
79 
80  // set new vertex position
81  p[1+nscat] = p[nscat] + stepsize * JPosition3D(dir) ;
82 
83  // check whether the photon hits the target
84  JPhotonPath lastvertex(0) ;
85  lastvertex[0] = p[p.size()-2] ;
86  lastvertex[1] = p[p.size()-1] ;
87  if( lastvertex.hitsSphere(trg->getPosition(),trg->getRadius()) ) {
88  const JPosition3D hit_position = lastvertex.getSphereHitPosition( trg->getPosition(), trg->getRadius() ) ;
89 
90  // correct the position of the final vertex
91  p[p.size()-1] = hit_position ;
92  // weigh the photon path with the target efficiency
93  p.weight = trg->getEfficiency( p[p.size()-1]-p[p.size()-2] ) ;
94  // add to the ensemble
95  ensemble.push_back(p) ;
96  break ;
97  }
98 
99  if( isAbsorbed ) break ;
100 
101  L += lastvertex.getLength() ;
102 
103  // scatter
104  ++nscat ;
105  JRotation3D rot(dir) ;
106  dir = sm->generateDirection() ;
107  dir = dir.rotate_back(rot) ;
108  p.addVertex() ;
109  }
110  }
111 
112  return ensemble ;
113  }
114 
115 }
116 
117 #endif
The JMarkovPhotonTracker generates ensembles of photon paths by tracking photons from a source to a t...
JMarkovPhotonTracker()
standard constructor
virtual JVersor3D generateDirection()=0
Return a randomly generated direction according to the emission distribution.
double getRadius() const
const JPosition3D & getPosition() const
A photon path.
Definition: JPhotonPath.hh:38
Rotation matrix.
Definition: JRotation3D.hh:111
std::vector< JPhotonPath > trackPhotons(unsigned long int n, JSourceModel *src, JScatteringModel *sm, JTargetModel *trg, double lambda_abs)
Track n photons.
virtual JVersor3D generateDirection()=0
Return a randomly generated direction according to the scattering probability distribution.
bool hitsSphere(const JPosition3D &pos, double r)
Returns whether the photon path intersects a sphere of radius r at position pos.
Definition: JPhotonPath.hh:176
const int n
Definition: JPolint.hh:697
const JPosition3D & getPosition() const
virtual double getEfficiency(JVersor3D dir) const =0
Return the efficiency, which is defined as the probability that a photon with the given direction hit...
Virtual base class for a light source.
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 n...
Definition: JPhotonPath.hh:213
Virtual base class for a scattering model.
Virtual base class for a light detector (&quot;photon target&quot;).
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
virtual double getScatteringLength()
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:26
double getLength()
get the total path length
Definition: JPhotonPath.hh:104