source: trunk/Mars/hawc/fresnellens_traceray.C@ 19645

Last change on this file since 19645 was 19645, checked in by tbretz, 5 years ago
Added
File size: 4.2 KB
Line 
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******************************************************************/
28void 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 const double Z = F+H/2; // [cm] camera position w.r.t. lens exit (see also MGeomCamFAMOUS!)
35
36 const double R = D/2; // [cm] radius of lens
37 const double w = 0.01; // [cm] Width of a single groove
38 const double H = 0.25; // [cm] Width of a single groove
39 //const double w = 1; // [cm] Width of a single groove
40 //const double H = 2.5; // [cm] Thickness of lens
41
42 const double lambda = 546; // [nm] Wavelength for lens surface definition
43
44 double angle = 0; // Check ix=0 at angle=-55 and N=10
45
46 double Z0 = 3;
47
48 const double n0 = MFresnelLens::RefractiveIndex(lambda);
49
50 MFresnelLens lens;
51 lens.DefineLens(F, D, w, H, lambda);
52 //lens.SetPSF(psf);
53 //lens.DefineLens(F, D, w, H, lambda);
54 //lens.EnableSlopeAbsorption();
55 //lens.EnableDraftAbsorption();
56 //lens.DisableBottomReflection();
57 //lens.DisableMultiEntry();
58 //lens.DisableFresnelReflection();
59 lens.ReadTransmission("resmc/hawcseye/transmission-pmma-3mm.txt", 0.3, true);
60
61 // ------------------ Setup display ---------------------
62
63 TH1C h("", "", 10000, -R*1.1, R*1.1);
64 h.SetStats(kFALSE);
65 h.SetMaximum( 3);
66 h.SetMinimum(-1.1*F);
67 h.DrawCopy();
68
69 TLine line;
70 line.SetLineWidth(2);
71
72 for (unsigned int i=0; i<lens.GetNumGrooves(); i++)
73 {
74 const MFresnelLens::Groove &g = lens[i];
75
76 line.SetLineColor(kBlack);
77 line.DrawLine( w*i, 0, g.r, g.slope.h);
78 line.DrawLine(-w*i, 0, -g.r, g.slope.h);;
79
80 line.SetLineColor(kRed);
81 line.DrawLine( g.r, g.slope.h, w*i+w, 0);
82 line.DrawLine(-g.r, g.slope.h, -w*i-w, 0);
83 }
84
85 line.SetLineColor(kBlack);
86 line.SetLineWidth(1);
87 line.DrawLine(-30, -H, 30, -H);
88 line.DrawLine(-30, -Z, 30, -Z);
89 line.DrawLine( R, -Z, R, 0);
90 line.DrawLine(-R, -Z, -R, 0);
91 line.SetLineWidth(3);
92 line.DrawLine(-4.5*1.5, -Z, 4.5*1.5, -Z);
93 line.SetLineWidth(1);
94
95 // ------------------------------------------------------
96
97 TArrow arrow;
98 TMarker marker;
99
100 marker.SetMarkerColor(kBlue);
101 marker.SetMarkerStyle(kFullDotMedium);
102
103 arrow.SetArrowSize(0.01);
104 arrow.SetLineColor(kBlue);
105
106 double vc = 1./(TMath::C()*100/1e9); // cm/ns
107
108 for (int i=0; i<100; i++)
109 {
110 double X = gRandom->Uniform(-R, R);
111
112 TVector3 pos(X, 0, 0);
113 TVector3 dir(0, 0, -1);
114
115 dir.SetMagThetaPhi(1, (180-angle)*TMath::DegToRad(), 0);
116
117 MQuaternion p(pos, 0);
118 MQuaternion u(dir, vc);
119
120 // Photon must be at the lens surface before it can enter the lens
121 p.PropagateZ(u, Z0);
122
123 vector<MQuaternion> vec;
124 vec.push_back(p);
125
126 const int cnt = lens.TraceRay(vec, p, u, lambda, true);
127
128 // Particle sucdessfully reached the focal plane
129 if (cnt>=0)
130 {
131 p.PropagateZ(u, -Z);
132 vec.push_back(p);
133
134 p.PropagateZ(u, u.Z()<0 ? -2.5*F : Z0);
135 vec.push_back(p);
136 }
137
138 // Particle is upgoing and has hit no surface
139 if (cnt==-1291 || cnt==-1391)
140 {
141 p.PropagateZ(u, 3);
142 vec.push_back(p);
143 }
144
145 arrow.SetLineColor(kBlue);
146 for (unsigned int j=0; j<vec.size()-1; j++)
147 {
148 arrow.DrawArrow(vec[j].X(), vec[j].Z(), vec[j+1].X(), vec[j+1].Z());
149 marker.DrawMarker(vec[j+1].X(), vec[j+1].Z());
150 }
151 }
152}
Note: See TracBrowser for help on using the repository browser.