source: trunk/Mars/hawc/fresnellens_traceray.C

Last change on this file was 19934, checked in by tbretz, 5 years ago
Some better example values
File size: 4.9 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
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
38 // For a well visible structure, use instead
39 //const double H = 2.5; // [cm] Width of a single groove
40 //const double w = 1.0; // [cm] Width of a single groove
41
42 //const double w = 1; // [cm] Width of a single groove
43 //const double H = 2.5; // [cm] Thickness of lens
44
45 const double Z = F+H; // [cm] camera position w.r.t. lens exit (see also MGeomCamFAMOUS!)
46 const double R = D/2; // [cm] radius of lens
47
48 const double lambda0 = 546; // [nm] Wavelength for lens surface definition
49 const double lambda = 546; // [nm] Wavelength for the simulated photons
50
51 const bool point_source = false; // Enable simulation of a point source
52
53 const double angle = 6; // [deg] Angle of incidence of the simulated rays
54
55 const double Z0 = point_source ? F : 3; // [cm] Starting Z-position of rays
56 const double X0 = Z0*atan(angle*TMath::DegToRad()); // [cm] (If<0: parallel rays (see angle), If>=0: point source at X0/Z0)
57
58 MFresnelLens lens;
59 lens.DefineLens(F, D, w, H, lambda0);
60 //lens.SetPSF(psf);
61 //lens.EnableSlopeAbsorption();
62 //lens.EnableDraftAbsorption();
63 //lens.DisableBottomReflection();
64 //lens.DisableMultiEntry();
65 //lens.DisableFresnelReflection();
66 lens.ReadTransmission("resmc/hawcseye/transmission-pmma-3mm.txt", 0.3, true);
67
68 // ------------------ Setup display ---------------------
69
70 TH1C h("", "", 10000, -R*1.1, R*1.1);
71 h.SetStats(kFALSE);
72 h.SetMaximum( 3);
73 h.SetMinimum(-1.1*F);
74 h.DrawCopy();
75
76 TLine line;
77 line.SetLineWidth(2);
78
79 for (unsigned int i=0; i<lens.GetNumGrooves(); i++)
80 {
81 const MFresnelLens::Groove &g = lens[i];
82
83 line.SetLineColor(kBlack);
84 line.DrawLine( w*i, 0, g.r, g.slope.h);
85 line.DrawLine(-w*i, 0, -g.r, g.slope.h);;
86
87 line.SetLineColor(kRed);
88 line.DrawLine( g.r, g.slope.h, w*i+w, 0);
89 line.DrawLine(-g.r, g.slope.h, -w*i-w, 0);
90 }
91
92 line.SetLineColor(kBlack);
93 line.SetLineWidth(1);
94 line.DrawLine(-30, -H, 30, -H);
95 line.DrawLine(-30, -Z, 30, -Z);
96 line.DrawLine( R, -Z, R, 0);
97 line.DrawLine(-R, -Z, -R, 0);
98 line.SetLineWidth(3);
99 line.DrawLine(-4.5*1.5, -Z, 4.5*1.5, -Z);
100 line.SetLineWidth(1);
101
102 // ------------------------------------------------------
103
104 if (point_source)
105 cout << "\nPoint source at x=" << X0 << " z=" << Z0 << "\n" << endl;
106
107 // ------------------------------------------------------
108
109 TArrow arrow;
110 TMarker marker;
111
112 marker.SetMarkerColor(kBlue);
113 marker.SetMarkerStyle(kFullDotMedium);
114
115 arrow.SetArrowSize(0.01);
116 arrow.SetLineColor(kBlue);
117
118 double vc = 1./(TMath::C()*100/1e9); // cm/ns
119
120 for (int i=0; i<100; i++)
121 {
122 double X = gRandom->Uniform(-R, R);
123
124 TVector3 pos(X, 0, 0);
125 TVector3 dir(0, 0, -1);
126
127 double theta = point_source ?
128 TMath::Pi()-atan((X+X0)/Z0) :
129 (180-angle)*TMath::DegToRad();
130
131 dir.SetMagThetaPhi(1, theta, 0);
132
133 MQuaternion p(pos, 0);
134 MQuaternion u(dir, vc);
135
136 // Propagate to starting plane in front of the lens
137 p.PropagateZ(u, Z0);
138
139 vector<MQuaternion> vec;
140 vec.push_back(p);
141
142 const int cnt = lens.TraceRay(vec, p, u, lambda, true);
143
144 // Particle successfully reached the focal plane
145 if (cnt>=0)
146 {
147 p.PropagateZ(u, -Z);
148 vec.push_back(p);
149
150 p.PropagateZ(u, u.Z()<0 ? -2.5*F : Z0);
151 vec.push_back(p);
152 }
153
154 // Particle is upgoing and has hit no surface
155 if (cnt==-1291 || cnt==-1391)
156 {
157 p.PropagateZ(u, 3);
158 vec.push_back(p);
159 }
160
161 arrow.SetLineColor(kBlue);
162 for (unsigned int j=0; j<vec.size()-1; j++)
163 {
164 arrow.DrawArrow(vec[j].X(), vec[j].Z(), vec[j+1].X(), vec[j+1].Z());
165 marker.DrawMarker(vec[j+1].X(), vec[j+1].Z());
166 }
167 }
168}
Note: See TracBrowser for help on using the repository browser.