1 | #include <vector>
|
---|
2 | #include <iostream>
|
---|
3 |
|
---|
4 | #include <TH1.h>
|
---|
5 | #include <TMarker.h>
|
---|
6 | #include <TArrow.h>
|
---|
7 | #include <TCanvas.h>
|
---|
8 | #include <TRandom.h>
|
---|
9 |
|
---|
10 | #include "MFresnelLens.h"
|
---|
11 |
|
---|
12 | /*****************************************************************
|
---|
13 |
|
---|
14 | fresnellens_traceray.C - 2D Example of ray-tracing the fresnel lens
|
---|
15 |
|
---|
16 | The macro has to be compilesd to work
|
---|
17 |
|
---|
18 | To run the macro from the command line (assuming you are in a directory
|
---|
19 | Mars/build where you have built your Mars environment) you have to do
|
---|
20 |
|
---|
21 | root ../hawc/fresnellens_traceray.C++
|
---|
22 |
|
---|
23 | or from within root
|
---|
24 |
|
---|
25 | [0] .x ../hawc/fresnellens_traceray.C++
|
---|
26 |
|
---|
27 | ******************************************************************/
|
---|
28 | void fresnellens_traceray()
|
---|
29 | {
|
---|
30 | // ------------------- setup lens -----------------------
|
---|
31 |
|
---|
32 | const double D = 54.92; // [cm] Diameter of the refractive surface
|
---|
33 | const double F = 50.21; // [cm] Nominal focal length of the lens
|
---|
34 |
|
---|
35 | const double H = 0.25; // [cm] Width of a single groove
|
---|
36 | const double w = 0.01; // [cm] Width of a single groove
|
---|
37 | //const double w = 1; // [cm] Width of a single groove
|
---|
38 | //const double H = 2.5; // [cm] Thickness of lens
|
---|
39 |
|
---|
40 | const double Z = F+H; // [cm] camera position w.r.t. lens exit (see also MGeomCamFAMOUS!)
|
---|
41 | const double R = D/2; // [cm] radius of lens
|
---|
42 |
|
---|
43 | const double lambda0 = 546; // [nm] Wavelength for lens surface definition
|
---|
44 | const double lambda = 546; // [nm] Wavelength for the simulated photons
|
---|
45 |
|
---|
46 | double angle = 6; // Angle of incidence of the simulated rays
|
---|
47 |
|
---|
48 | double Z0 = 3; // Starting Z-position of rays
|
---|
49 |
|
---|
50 | MFresnelLens lens;
|
---|
51 | lens.DefineLens(F, D, w, H, lambda0);
|
---|
52 | //lens.SetPSF(psf);
|
---|
53 | //lens.EnableSlopeAbsorption();
|
---|
54 | //lens.EnableDraftAbsorption();
|
---|
55 | //lens.DisableBottomReflection();
|
---|
56 | //lens.DisableMultiEntry();
|
---|
57 | //lens.DisableFresnelReflection();
|
---|
58 | lens.ReadTransmission("resmc/hawcseye/transmission-pmma-3mm.txt", 0.3, true);
|
---|
59 |
|
---|
60 | // ------------------ Setup display ---------------------
|
---|
61 |
|
---|
62 | TH1C h("", "", 10000, -R*1.1, R*1.1);
|
---|
63 | h.SetStats(kFALSE);
|
---|
64 | h.SetMaximum( 3);
|
---|
65 | h.SetMinimum(-1.1*F);
|
---|
66 | h.DrawCopy();
|
---|
67 |
|
---|
68 | TLine line;
|
---|
69 | line.SetLineWidth(2);
|
---|
70 |
|
---|
71 | for (unsigned int i=0; i<lens.GetNumGrooves(); i++)
|
---|
72 | {
|
---|
73 | const MFresnelLens::Groove &g = lens[i];
|
---|
74 |
|
---|
75 | line.SetLineColor(kBlack);
|
---|
76 | line.DrawLine( w*i, 0, g.r, g.slope.h);
|
---|
77 | line.DrawLine(-w*i, 0, -g.r, g.slope.h);;
|
---|
78 |
|
---|
79 | line.SetLineColor(kRed);
|
---|
80 | line.DrawLine( g.r, g.slope.h, w*i+w, 0);
|
---|
81 | line.DrawLine(-g.r, g.slope.h, -w*i-w, 0);
|
---|
82 | }
|
---|
83 |
|
---|
84 | line.SetLineColor(kBlack);
|
---|
85 | line.SetLineWidth(1);
|
---|
86 | line.DrawLine(-30, -H, 30, -H);
|
---|
87 | line.DrawLine(-30, -Z, 30, -Z);
|
---|
88 | line.DrawLine( R, -Z, R, 0);
|
---|
89 | line.DrawLine(-R, -Z, -R, 0);
|
---|
90 | line.SetLineWidth(3);
|
---|
91 | line.DrawLine(-4.5*1.5, -Z, 4.5*1.5, -Z);
|
---|
92 | line.SetLineWidth(1);
|
---|
93 |
|
---|
94 | // ------------------------------------------------------
|
---|
95 |
|
---|
96 | TArrow arrow;
|
---|
97 | TMarker marker;
|
---|
98 |
|
---|
99 | marker.SetMarkerColor(kBlue);
|
---|
100 | marker.SetMarkerStyle(kFullDotMedium);
|
---|
101 |
|
---|
102 | arrow.SetArrowSize(0.01);
|
---|
103 | arrow.SetLineColor(kBlue);
|
---|
104 |
|
---|
105 | double vc = 1./(TMath::C()*100/1e9); // cm/ns
|
---|
106 |
|
---|
107 | for (int i=0; i<100; i++)
|
---|
108 | {
|
---|
109 | double X = gRandom->Uniform(-R, R);
|
---|
110 |
|
---|
111 | TVector3 pos(X, 0, 0);
|
---|
112 | TVector3 dir(0, 0, -1);
|
---|
113 |
|
---|
114 | dir.SetMagThetaPhi(1, (180-angle)*TMath::DegToRad(), 0);
|
---|
115 |
|
---|
116 | MQuaternion p(pos, 0);
|
---|
117 | MQuaternion u(dir, vc);
|
---|
118 |
|
---|
119 | // Photon must be at the lens surface before it can enter the lens
|
---|
120 | p.PropagateZ(u, Z0);
|
---|
121 |
|
---|
122 | vector<MQuaternion> vec;
|
---|
123 | vec.push_back(p);
|
---|
124 |
|
---|
125 | const int cnt = lens.TraceRay(vec, p, u, lambda, true);
|
---|
126 |
|
---|
127 | // Particle sucdessfully reached the focal plane
|
---|
128 | if (cnt>=0)
|
---|
129 | {
|
---|
130 | p.PropagateZ(u, -Z);
|
---|
131 | vec.push_back(p);
|
---|
132 |
|
---|
133 | p.PropagateZ(u, u.Z()<0 ? -2.5*F : Z0);
|
---|
134 | vec.push_back(p);
|
---|
135 | }
|
---|
136 |
|
---|
137 | // Particle is upgoing and has hit no surface
|
---|
138 | if (cnt==-1291 || cnt==-1391)
|
---|
139 | {
|
---|
140 | p.PropagateZ(u, 3);
|
---|
141 | vec.push_back(p);
|
---|
142 | }
|
---|
143 |
|
---|
144 | arrow.SetLineColor(kBlue);
|
---|
145 | for (unsigned int j=0; j<vec.size()-1; j++)
|
---|
146 | {
|
---|
147 | arrow.DrawArrow(vec[j].X(), vec[j].Z(), vec[j+1].X(), vec[j+1].Z());
|
---|
148 | marker.DrawMarker(vec[j+1].X(), vec[j+1].Z());
|
---|
149 | }
|
---|
150 | }
|
---|
151 | }
|
---|