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

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