source: trunk/Mars/hawc/fresnellens_psf.C@ 19948

Last change on this file since 19948 was 19933, checked in by tbretz, 5 years ago
Added some infomration on Tim's simulation.
File size: 4.9 KB
Line 
1/*****************************************************************
2
3 fresnellens_psf.C - Example how to use MFresnelLens directly
4
5 To run the macro from the command line (assuming you are in a directory
6 Mars/build where you have built your Mars environment) you have to do
7
8 root ../hawc/fresnellens_psf.C
9
10 or from within root
11
12 [0] .x ../hawc/fresnellens_psf.C
13
14******************************************************************/
15void fresnellens_psf()
16{
17 // ------------------- setup lens -----------------------
18
19 const double D = 54.92; // [cm] Diameter of the refractive surface
20 const double F = 50.21; // [cm] Nominal focal length of the lens
21 const double w = 0.01; // [cm] Width of a single groove
22
23 // Tim used some unintentionally wrong values in his simulation:
24 // const double D = 50.21; // [cm] Diameter of the refractive surface
25 // const double F = 49.833; // [cm] calculated as D * (F/D) with D=50.21/54.92
26 // const double w = 0.05; // [cm] Width of a single groove
27
28 const double H = 0.25; // [cm] Thickness of lens
29 const double Z = F; // [cm] camera position w.r.t. lens exit (see also MGeomCamFAMOUS!)
30
31 const double R = D/2; // [cm] radius of lens
32 //const double w = 0.01; // [cm] Width of a single groove
33 //const double w = 1; // [cm] Width of a single groove
34 //const double H = 1.5; // [cm] Thickness of lens
35
36 const double Rcam = 1.5*4.5; // [cm] radius of camera
37
38 const double lambda = 546; // [nm] Wavelength for simulated rays
39
40 double psf = 0; // Do not change! It might have unpredicted side effectes
41
42 double angle = 0; // [cm] angle of incidence of simulates rays
43
44 //TVector3 point_source(0, -F*atan(angle*TMath::DegToRad()), F); // Point source at x=0, y=0, z=F
45 TVector3 point_source; // No point source
46
47 MFresnelLens lens;
48 lens.SetPSF(psf);
49 //lens.DefineLens(F, D, w, H, lambda);
50 //lens.EnableSlopeAbsorption();
51 //lens.EnableDraftAbsorption();
52 //lens.DisableBottomReflection();
53 //lens.DisableMultiEntry();
54 //lens.DisableFresnelReflection();
55 lens.ReadTransmission("resmc/hawcseye/transmission-pmma-3mm.txt", 0.3, true);
56
57 // ------------------- setup histograms -----------------
58
59 unsigned int NN = 1000;
60
61 TH2F h_out("OUT", "Photon Distribution (out)", NN*4/3, -R*4/3, R*4/3, NN, -R, R);
62 TH2F h_psf("PSF", "Point Spread Function", 2000*4/3, -R*4/3, R*4/3, 2000, -R, R);
63 TH2F h_cam("CAM", "Point Spread Function", 4*37*4/3, -14*4/3, 14*4/3, 4*37, -14, 14);
64
65 TH1F h_rc("RET", "Return code", 8, 0.5, 8.5);
66
67 // ------------------ Run simulation ---------------------
68
69 int cnt = 0; // counter for photons hitting the camera
70
71 int Nrays = 100000;
72 for (int i=0; i<Nrays; i++)
73 {
74 // ---------------------------------------------------------------
75 Double_t X, Y;
76 gRandom->Circle(X, Y, R*sqrt(gRandom->Uniform(0, 1)));
77
78 TVector3 pos(X, Y, 0);
79
80 // ---------------------------------------------------------------
81
82 TVector3 dir;
83 if (point_source.Mag()<1e-10)
84 dir.SetMagThetaPhi(1, (180-angle)*TMath::DegToRad(), TMath::Pi()/2);
85 else
86 {
87 // Note that this is not a perfect point source as the
88 // flux is homogeneous over the surface of the lens
89 TVector3 ps = pos - point_source;
90 dir.SetMagThetaPhi(1, ps.Theta(), ps.Phi());
91 }
92
93 double v = 1./(TMath::C()*100/1e9); // cm/ns
94
95 // ---------------------------------------------------------------
96
97 MQuaternion pp(pos, 0);
98 MQuaternion uu(dir, v);
99
100 // ---------------------------------------------------------------
101
102 int ret = lens.ExecuteOptics(pp, uu, lambda);
103
104 // Skip photons which will not hit the focal plane within r<R
105 if (ret<0)
106 {
107 h_rc.Fill((-ret)%10); // Keep reason for loss
108 continue;
109 }
110
111 // Keep exit position on bottom surface
112 h_out.Fill(pp.X(), pp.Y());
113
114 // Propagate to th focal plane
115 pp.PropagateZ(uu, Z);
116
117 // Keep position in focal plane
118 h_psf.Fill(pp.X(), pp.Y());
119 h_cam.Fill(pp.X(), pp.Y());
120
121 if (pp.R()<Rcam)
122 cnt++;
123 }
124
125 // ------------------ Display result ---------------------
126
127 TEllipse circ;
128 circ.SetLineWidth(2);
129 circ.SetFillStyle(0);
130
131 TMarker m;
132 m.SetMarkerStyle(kFullDotMedium);
133
134 TCanvas *c = new TCanvas;
135 c->Divide(2,2);
136 c->cd(1);
137 h_cam.DrawCopy("colz");
138 circ.DrawEllipse(0, 0, 4.5*1.5, 4.5*1.5, 0, 360, 0);
139 m.DrawMarker(0, angle*F/TMath::RadToDeg());
140 c->cd(2);
141 h_out.DrawCopy("colz");
142 c->cd(3);
143 h_psf.DrawCopy("colz");
144 circ.DrawEllipse(0, 0, 4.5*1.5, 4.5*1.5, 0, 360, 0);
145 m.DrawMarker(0, angle*F/TMath::RadToDeg());
146 c->cd(4);
147 h_rc.DrawCopy();
148
149 // Photons inside the camera
150 cout << "Efficiency = " << double(cnt)/Nrays << " (N=" << cnt << ")" << endl;
151}
Note: See TracBrowser for help on using the repository browser.