12 #include <TPolyLine3D.h>
13 #include <TObjArray.h>
16 #include <utl/MathConstants.h>
17 #include <utl/AugerUnits.h>
19 #include <utl/Photon.h>
20 #include <utl/Point.h>
21 #include <utl/Vector.h>
22 #include <utl/CoordinateSystemPtr.h>
24 #include <utl/RandomEngine.h>
25 #include <CLHEP/Random/Randomize.h>
27 #include <fdet/Telescope.h>
28 #include <fdet/Corrector.h>
30 #include <det/Detector.h>
32 #include <atm/Atmosphere.h>
33 #include <atm/ProfileResult.h>
39 using namespace TelescopeSimulatorKG2;
43 using CLHEP::RandFlat;
48 const bool simulateHaloEffects,
49 const double lensIncreaseRefl,
50 const double lensPosition,
51 const double minLensThickness,
52 const double torusRadius,
53 const double tubeRadius,
54 const double torusZ0) :
56 fSimulateHaloEffects(simulateHaloEffects),
57 fIncreaseReflection(lensIncreaseRefl),
59 fMinLensThickness(minLensThickness),
60 fTorusRadius(torusRadius),
61 fTubeRadius(tubeRadius),
63 fTelCS(detTel.GetTelescopeCoordinateSystem()),
64 fOrigin(0, 0, fPosZ, fTelCS),
65 fTorusOrigin(0, 0, fTorusZ0, fTelCS),
66 fPosPlane(0, 0, fPosZ, fTelCS),
67 fR1(detTel.GetCorrector().GetInnerRadius()),
68 fR2(detTel.GetCorrector().GetOuterRadius()),
69 fRefractiveIndex(detTel.GetCorrector().GetRefractiveIndex()),
70 fTransmittance(detTel.GetCorrector().GetTransmittance()),
71 fSigRho(detTel.GetCorrector().GetSigmaNormal()),
113 cout <<
"tracing without torus!" << endl;
147 photonOut = photonLens;
154 const double r2 = x*x + y*y;
155 const double r =
sqrt(r2);
162 photonOut = photonLens;
167 photonOut = photonLens;
180 const double phiAngle = atan(
abs(y/x));
182 photonOut = photonLens;
192 const Vector normal = backwards ?
194 (inLens ? nPlane : CurvaturePrototype(x, y));
195 cout <<
" we are doing this: curvaturePrototype can be used!" << endl;
201 if (photonsRefracted.size() == 1) {
204 photonOut = photonsRefracted[0];
209 cout <<
"total internal reflection but !inLens ---------- this can not happen!" << endl;
210 photonOut = photonsRefracted[0];
216 photonLens = photonsRefracted[0];
224 const double weightRefl = photonsRefracted[1].
GetWeight();
225 const double inWeight = weight;
227 const double newRefr = inWeight - newRefl;
228 photonsRefracted[1].SetWeight(newRefl);
229 photonsRefracted[0].SetWeight(newRefr);
237 if (tmpRandNr > photonsRefracted[0].GetWeight() / weight) {
241 photonOut = photonsRefracted[1];
247 photonLens = photonsRefracted[1];
260 photonLens = photonsRefracted[0];
268 photonOut = photonsRefracted[0];
286 photonOut = photonsRefracted[0];
291 photonLens = photonsRefracted[0];
303 const bool backwardsLens = nDirLens.
GetZ(
fTelCS) > 0;
304 const double cosThetaPhoton = (backwardsLens ? +1 : -1) * nDirLens.
GetCosTheta(
fTelCS);
306 const double distance = z / cosThetaPhoton;
313 Point pNext = pLens + distance * nDirLens;
328 if (everyOnehundred == 4)
332 }
while (weight > 1e-20);
335 photonOut = photonLens;
343 const bool printLens =
false;
364 if (intersections.empty()) {
365 ERROR(
"no intersection with torus???");
369 unsigned int indexOfSmallestZ = 4;
373 if (indexOfSmallestZ == 4) {
374 ERROR(
"smallestZ was not found -> indexOfSmallestZ is not correct!");
378 photonLens = photonIn;
379 photonLens.
SetPosition(intersections[indexOfSmallestZ].first.GetPosition());
403 photonOut = photonLens;
411 const double pos_r2 =
Sqr(pos_x) +
Sqr(pos_y);
412 const double pos_r =
sqrt(pos_r2);
420 photonOut = photonLens;
425 photonOut = photonLens;
431 if (!outwards && printLens)
440 const bool debug =
false;
443 const double ringElementAngle =
kPi / 12;
444 const double phiAngle = atan2(
abs(pos_y),
abs(pos_x)) + (ringElementAngle / 2);
445 const double gapWidth = ((2 *
kPi * 850*
mm) - (24 * 218*
mm)) / 24;
447 const double gapAngularWidth = sin(gapWidth / (975*
mm));
449 if (
abs(phiAngle - round(phiAngle / ringElementAngle) * ringElementAngle) < (gapAngularWidth / 2)) {
455 photonOut = photonLens;
464 if (!outwards && printLens)
474 const Vector normal = outwards ? (inLens ? nTorus : nPlane) : (inLens ? nPlane : nTorus);
490 if (photonsRefracted.size() == 1) {
493 photonOut = photonsRefracted[0];
498 ERROR(
"total internal reflection but !inLens ---------- this can not happen!");
499 photonOut = photonsRefracted[0];
506 photonLens = photonsRefracted[0];
514 const double weightRefl = photonsRefracted[1].
GetWeight();
515 const double inWeight = weight;
517 const double newRefr = inWeight - newRefl;
518 photonsRefracted[1].SetWeight(newRefl);
519 photonsRefracted[0].SetWeight(newRefr);
525 if (tmpRandNr > photonsRefracted[0].GetWeight() / weight) {
528 photonOut = photonsRefracted[1];
537 const double amountOfStrayLight = 0;
538 if (amountOfStrayLight > 0) {
539 double maxTheta = 25*
deg;
540 const Vector lambertdiffusion =
544 if (!outwards && printLens)
549 photonLens = photonsRefracted[1];
561 photonLens = photonsRefracted[0];
569 photonOut = photonsRefracted[0];
579 const double amountOfStrayLight = 0;
580 double maxTheta = 25*
deg;
581 const Vector lambertdiffusion =
585 if (!outwards && printLens)
596 photonOut = photonsRefracted[0];
601 photonLens = photonsRefracted[0];
615 if (intersections.empty()) {
616 ERROR(
"inside the lens and flying outwards - but no intersection with torus???");
620 unsigned int indexOfSmallestZ = 4;
623 if (indexOfSmallestZ == 4) {
624 ERROR(
"smallestZ was not found -> indexOfSmallestZ is not correct!");
628 pNext = intersections[indexOfSmallestZ].first.GetPosition();
631 Photon tmpPhoton = photonLens;
638 ERROR(
"propagate to next optical interface (inside lens) but photon is not inLens!!!!!");
642 const Vector& pathInLens = pNext - pLens;
643 const double distance = pathInLens.
GetMag();
648 ERROR(
"so many reflections? CHECK?!?!");
655 if (everyOnehundred == 4)
659 }
while (weight > 1e-20);
661 ERROR(
"Lost photon due to too many multiple reflections in the lens");
664 photonOut = photonLens;
672 TObjArray*
const objs =
new TObjArray();
678 for (
int i = 0; i < nSeg; ++i) {
680 const double theta_1 = 360*
deg / nSeg * i;
681 const double theta_2 = 360*
deg / nSeg * (i + 1);
683 TPolyLine3D*
const l_in =
new TPolyLine3D(2);
684 l_in->SetPoint(0, cos(theta_1)*
fR1, sin(theta_1)*fR1,
fPosZ);
685 l_in->SetPoint(1, cos(theta_2)*fR1, sin(theta_2)*fR1,
fPosZ);
686 l_in->SetLineColor(color);
687 l_in->SetLineWidth(width);
691 TPolyLine3D*
const l_out =
new TPolyLine3D(2);
692 l_out->SetPoint(0, cos(theta_1)*
fR2, sin(theta_1)*fR2,
fPosZ);
693 l_out->SetPoint(1, cos(theta_2)*fR2, sin(theta_2)*fR2,
fPosZ);
694 l_out->SetLineColor(color);
695 l_out->SetLineWidth(width);
697 objs->AddLast(l_out);
699 TPolyLine3D*
const l_seg =
new TPolyLine3D(2);
700 l_seg->SetPoint(0, cos(theta_1)*fR1, sin(theta_1)*fR1,
fPosZ);
701 l_seg->SetPoint(1, cos(theta_1)*fR2, sin(theta_1)*fR2,
fPosZ);
702 l_seg->SetLineColor(color);
703 l_seg->SetLineWidth(width);
705 objs->AddLast(l_seg);
727 const double r =
sqrt(x*x + y*y);
729 static const double f = 3.4*
m - 1.743*
m;
730 static const double Rd = 0.85*
m;
731 static const double A = 3/2. * Rd * Rd;
732 static const double n = 1.5;
734 static const double denominator = 32 * (n - 1) * f * f * f;
735 static const double a1 = 1 / denominator;
736 static const double a2 = A / denominator;
738 const double dTdr = 4 * a1 * r * r * r - 2 * a2 * r;
748 const double norm =
sqrt(nr*nr + nz*nz);
753 const double phi = atan2(y, x);
755 return Vector(-nr * cos(phi), -nr * sin(phi), nz,
fTelCS);
773 for (
unsigned int i = 0, n = intersections.size(); i < n; ++i) {
774 const double tmp_z = intersections[i].first.GetPosition().GetZ(
fTelCS);
775 if (tmp_z < smallestZ) {
788 const double r2 = r * r;
794 static const double f = 3.4*
m - 1.743*
m;
795 static const double Rd = 0.85*
m;
796 static const double A = 3/2. * Rd * Rd;
797 static const double n = 1.5;
799 static const double denominator = 32 * (n - 1) * f * f * f;
800 static const double a1 = 1 / denominator;
801 static const double a2 = A / denominator;
803 static const double z0 = 10*
mm;
805 const double z = z0 + a1 * r2 * r2 - a2 * r2;
824 ostringstream bugMsg;
825 bugMsg <<
fNbug <<
" photons lost because of \'first inLens, now in aperture\'-bug";
std::vector< PhotonNormalPair > IntersectionList
RayTracer::Track * fPhotonTrack
utl::CoordinateSystemPtr fTelCS
constexpr T Sqr(const T &x)
RandomEngineType & GetEngine()
double GetCosTheta(const CoordinateSystemPtr &coordinateSystem) const
cos of zenith (theta) angle
#define INFO(message)
Macro for logging informational messages.
double GetWeight() const
weight assigned to the photon
Lens(utl::RandomEngine &rndm, const fdet::Telescope &tel, const bool simulateHaloEffects, const double lensIncreaseRefl, const double lensPosition, const double minLensThickness, const double torusRadius, const double tubeRadius, const double torusZ0)
void SetPosition(const utl::Point &p)
int Refraction(const double n12, const utl::Photon &photonIn, const Vector &normal, PhotonList &photonsOut)
Vector TorusNormal(const utl::Point &origin, const utl::Vector &inwards, const utl::Point &point, const double torusRadius, const double tubeRadius)
void AddPoint(const utl::Point &p)
const utl::TabulatedFunction & fTransmittance
const utl::Point fPosPlane
double GetX(const CoordinateSystemPtr &coordinateSystem) const
utl::Vector CurvaturePrototype(const double x, const double y) const
Wraps the random number engine used to generate distributions.
double abs(const SVector< n, T > &v)
void SetSource(const int source)
void ChoosePhysicalIntersection(unsigned int &index, const RTFunctions::IntersectionList &intersections) const
const double fTorusRadius
RTNext TraceWithTorus(const utl::Photon &photonIn, utl::Photon &photonOut)
Simulate the lens.
void SetWeight(const double w)
source of the photons. Should use Eye::LightSource enum types
const bool fSimulateHaloEffects
const utl::Vector & GetDirection() const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
const double fIncreaseReflection
double Plane(const utl::Point &point, const utl::Vector &normal, const utl::Photon &photonIn, utl::Photon &photonOut)
Detector description interface for Telescope-related data.
double ProfilePrototype(const double r) const
Vector LambertDiffusion(utl::RandomEngine &rndm, const Vector &rayIn, const Vector &normal, const double amountOfStrayLight, const double MaxTheta)
RTNext Trace(const utl::Photon &photonIn, utl::Photon &photonOut)
const utl::Point fTorusOrigin
std::vector< utl::Photon > PhotonList
const utl::TabulatedFunction & fRefractiveIndex
double GetWavelength() const
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
#define ERROR(message)
Macro for logging error messages.
utl::RandomEngine & fRandom
void Torus(const utl::Point &origin, const utl::Vector &inwards, const double torusRadius, const double tubeRadius, const utl::Photon &photonIn, IntersectionList &intersections)
void SetDirection(const utl::Vector &v)
const utl::Point & GetPosition() const