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

Last change on this file since 19948 was 19631, checked in by tbretz, 5 years ago
New example macro
File size: 2.2 KB
Line 
1Bool_t HandleInput()
2{
3 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
4 while (1)
5 {
6 //
7 // While reading the input process gui events asynchronously
8 //
9 timer.TurnOn();
10 TString input = Getline("Type 'q' to exit, <return> to go on: ");
11 timer.TurnOff();
12
13 if (input=="q\n")
14 return kFALSE;
15
16 if (input=="\n")
17 return kTRUE;
18 };
19
20 return kFALSE;
21}
22
23void PropagateZ(TVector3 &p, TVector3 &w, double z, TArrow &arr)
24{
25 arr.SetX1(p.X());
26 arr.SetY1(p.Z());
27
28 p += (z-p.Z())/w.Z()*w;
29
30 arr.SetX2(p.X());
31 arr.SetY2(p.Z());
32}
33
34void PropagateDZ(TVector3 &p, TVector3 &w, double dz, TArrow &arr)
35{
36 arr.SetX1(p.X());
37 arr.SetY1(p.Z());
38
39 p += dz/w.Z()*w;
40
41 arr.SetX2(p.X());
42 arr.SetY2(p.Z());
43}
44
45void transition()
46{
47 TH1C h("", "", 100, -2, 2);
48 h.SetMinimum(-1.5);
49 h.SetMaximum(1.5);
50 h.SetStats(kFALSE);
51 h.DrawCopy();
52
53 TLine line;
54 line.DrawLine(-2, 0, 2, 0);
55
56 TVector3 norm(0, 0, -1);
57 norm *= 1./norm.Mag();
58
59 TArrow arr;
60 arr.SetArrowSize(0.01);
61 arr.DrawArrow(0, 0, 0+norm.X(), 0+norm.Z());
62
63 TArrow arr_in(1, 1, 0, 0);
64 arr_in.SetArrowSize(0.01);
65 arr_in.SetLineColor(kBlue);
66 arr_in.Draw();
67
68 TArrow arr_out(0, 0, 1, 1);
69 arr_out.SetArrowSize(0.01);
70 arr_out.SetLineColor(kRed);
71 arr_out.Draw();
72
73 while (1)
74 {
75 double x, y;
76 gRandom->Circle(x, y, 1);
77
78 TVector3 pos(x, 0, y);
79 TVector3 dir = -pos;
80
81 arr_in.SetX1(-dir.X()*1.5);
82 arr_in.SetY1(-dir.Z()*1.5);
83
84 double n1 = dir.Z()>0 ? 1.5 : 1; // where the ray comes from
85 double n2 = dir.Z()>0 ? 1 : 1.5; // where the ray goes to
86
87 cout << sin(acos(dir*norm)) << endl;
88
89 int rc = MOptics::ApplyTransition(dir, norm, n1, n2);
90
91 cout << rc << endl;
92
93 if (rc>=3) // Refraction
94 {
95 // Snell's law: n2*sin(theta2) = n1*sin(theta1) -- Is thge result correct?
96 cout << n2/n1*sin(acos(dir*norm)) << endl;
97 }
98
99 arr_out.SetX2(dir.X()*1.5);
100 arr_out.SetY2(dir.Z()*1.5);
101
102 gPad->Modified();
103 gPad->Update();
104
105 if (!HandleInput())
106 break;
107 }
108}
Note: See TracBrowser for help on using the repository browser.