3 #include <utl/config.h>
5 #include <utl/Photon.h>
7 #include <utl/Vector.h>
8 #include <utl/CoordinateSystemPtr.h>
9 #include <utl/RandomEngine.h>
10 #include <utl/MathConstants.h>
12 #include <CLHEP/Random/Randomize.h>
22 using CLHEP::RandFlat;
23 using CLHEP::RandGauss;
25 namespace TelescopeSimulatorKG {
27 namespace RTFunctions {
34 const double dot = nIn*normal;
48 double b = normal*nIn;
49 double a = (point - pIn)*normal;
68 double cosTheta_in = nIn*normal;
69 Vector projOnSurface = nIn - cosTheta_in*normal;
73 double sin2theta_out = projOnSurface.
GetMag2();
76 Photon photonReflected(photonIn);
77 const double dot = nIn*normal;
81 if(sin2theta_out >= 1) {
82 photonsOut.push_back(photonReflected);
88 if (cosTheta_in>0) cosTheta_out = +
sqrt (1.-sin2theta_out);
89 else cosTheta_out = -
sqrt (1.-sin2theta_out);
105 fact = 1./n12 * cosTheta_out/cosTheta_in;
107 const double T_par =
pow(2. * n12 * cosTheta_in / (n12 * cosTheta_out + cosTheta_in), 2);
108 const double T_perp =
pow(2. * n12 * cosTheta_in / (n12 * cosTheta_in + cosTheta_out), 2);
109 const double T = fact * .5 * (T_par + T_perp);
111 const double weightIn = photonIn.
GetWeight();
113 Photon photonRefracted(photonIn);
114 photonRefracted.
SetDirection(projOnSurface + cosTheta_out*normal);
116 photonsOut.push_back(photonRefracted);
118 photonReflected.
SetWeight(weightIn * (1-T));
119 photonsOut.push_back(photonReflected);
146 intersection.clear();
151 const Vector pointToOrigin = pIn - origin;
152 const double dist2 = pointToOrigin.
GetMag2();
154 const double projection = pointToOrigin * nIn;
155 double delta = projection*projection + radius*radius - dist2;
161 Photon photonOut(photonIn);
165 intersection.push_back(pair<Photon,Vector>(photonOut, normal));
171 const double move1 = -projection - delta;
172 const double move2 = -projection + delta;
174 Photon photonOut1(photonIn);
175 photonOut1.
SetPosition(pIn + min(move1, move2)*nIn);
178 intersection.push_back(pair<Photon,Vector>(photonOut1, normal1));
180 Photon photonOut2(photonIn);
184 intersection.push_back(pair<Photon,Vector>(photonOut2, normal2));
213 if (sigma_alpha==0) {
219 double phiIn = normalIn.
GetPhi (inCS);
220 double thetaIn = normalIn.
GetTheta (inCS);
225 double f_max = std::min(1.0, 4.*sigma_alpha);
227 double phi = RandFlat::shoot (&rndm.
GetEngine(), 0., 2.*
kPi);
228 double sinPhi = sin(phi);
229 double cosPhi = cos(phi);
237 alpha = RandGauss::shoot (&rndm.
GetEngine(), 0., sigma_alpha);
238 }
while (RandFlat::shoot (&rndm.
GetEngine(), 0., f_max) > sin(alpha) ||
241 double sinAlpha = sin(alpha);
242 double cosAlpha = cos(alpha);
244 double unit_x = sinAlpha * cosPhi;
245 double unit_y = sinAlpha * sinPhi;
246 double unit_z = cosAlpha;
248 facetNormal =
Vector (unit_x, unit_y, unit_z, normalCS);
250 }
while (rayIn * facetNormal >= 0.0);
double Plane(const utl::Point &point, const utl::Vector &normal, const utl::Photon &photonIn, utl::Photon &photonOut)
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
std::vector< utl::Photon > PhotonList
RandomEngineType & GetEngine()
int Reflection(const utl::Photon &photonIn, const Vector &normal, utl::Photon &photonOut)
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
CoordinateSystemPtr GetCoordinateSystem() const
Get the coordinate system of the current internal representation.
double GetWeight() const
weight assigned to the photon
double pow(const double x, const unsigned int i)
void SetPosition(const utl::Point &p)
int Sphere(const Point &origin, const double radius, const utl::Photon &photonIn, IntersectionList &intersection)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Wraps the random number engine used to generate distributions.
void SetWeight(const double w)
source of the photons. Should use Eye::LightSource enum types
std::vector< PhotonNormalPair > IntersectionList
const utl::Vector & GetDirection() const
int Refraction(const double n12, const utl::Photon &photonIn, const Vector &normal, PhotonList &photonsOut)
void SetDirection(const utl::Vector &v)
Vector RandomNormal(utl::RandomEngine &rndm, const Vector &normalIn, double sigma_alpha, const Vector &rayIn)
const utl::Point & GetPosition() const