Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
22namespace JMARKOV {}
23namespace JPP { using namespace JMARKOV; }
24
25namespace 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() ;
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 JDirection3D 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( JDirection3D(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
Data structure for direction in three dimensions.
JDirection3D & rotate_back(const JRotation3D &R)
Rotate back.
Data structure for position in three dimensions.
The JMarkovPhotonTracker generates ensembles of photon paths by tracking photons from a source to a t...
JMarkovPhotonTracker()
standard constructor
std::vector< JPhotonPath > trackPhotons(unsigned long int n, JSourceModel *src, JScatteringModel *sm, JTargetModel *trg, double lambda_abs)
Track n photons.
A photon path.
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 n...
double getLength()
get the total path length
Virtual base class for a scattering model.
virtual double getScatteringLength()
virtual JVersor3D generateDirection()=0
Return a randomly generated direction according to the scattering probability distribution.
Virtual base class for a light source.
virtual JVersor3D generateDirection()=0
Return a randomly generated direction according to the emission distribution.
const JPosition3D & getPosition() const
Virtual base class for a light detector ("photon target").
virtual double getEfficiency(JVersor3D dir) const =0
Return the efficiency, which is defined as the probability that a photon with the given direction hit...
const JPosition3D & getPosition() const
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).