Rev 71 | Rev 73 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 71 | Rev 72 | ||
|---|---|---|---|
| Line 3... | Line 3... | ||
| 3 | #include <iostream> |
3 | #include <iostream> |
| 4 | 4 | ||
| 5 | // vector output shortcut |
5 | // vector output shortcut |
| 6 | void printv(TVector3 v) |
6 | void printv(TVector3 v) |
| 7 | { |
7 | { |
| 8 |
|
8 | printf("(x,y,z) = (%.4lf, %.4lf, %.4lf)\n", v.x(), v.y(), v.z()); |
| 9 | } |
9 | } |
| 10 | // TVector3::Rotate does not seem accurate enough |
10 | // TVector3::Rotate does not seem accurate enough |
| 11 | TVector3 rotatey(TVector3 v, double theta) |
11 | TVector3 rotatey(TVector3 v, double theta) |
| 12 | { |
12 | { |
| 13 |
|
13 | return TVector3(v.x() * TMath::Cos(theta) + v.z() * TMath::Sin(theta), |
| 14 |
|
14 | v.y(), |
| 15 |
|
15 | -v.x() * TMath::Sin(theta) + v.z() * TMath::Cos(theta)); |
| 16 | } |
16 | } |
| 17 | // another shortcut not found in TMath |
17 | // another shortcut not found in TMath |
| 18 | int sign(double in) |
18 | int sign(double in) |
| 19 | { |
19 | { |
| 20 |
|
20 | if(in >= 0.0) return 1; |
| 21 |
|
21 | else return -1; |
| 22 | } |
22 | } |
| 23 | //================================================================================= |
23 | //================================================================================= |
| 24 | 24 | ||
| 25 | //----------------------------------------------------------------------------- |
25 | //----------------------------------------------------------------------------- |
| 26 | void CRay::Set(TVector3 r0, TVector3 n0) |
26 | void CRay::Set(TVector3 r0, TVector3 n0) |
| 27 | { |
27 | { |
| 28 |
|
28 | r = r0; n = n0.Unit(); |
| 29 | } |
29 | } |
| 30 | //----------------------------------------------------------------------------- |
30 | //----------------------------------------------------------------------------- |
| 31 | //void CRay::Set(double x0, double y0, double z0, double l0, double m0, double n0) |
31 | //void CRay::Set(double x0, double y0, double z0, double l0, double m0, double n0) |
| 32 | //{ |
32 | //{ |
| 33 |
|
33 | //r.SetXYZ(x0, y0, z0); |
| 34 |
|
34 | //n.SetXYZ(l0, m0, n0); n = n.Unit(); |
| 35 | //} |
35 | //} |
| 36 | //----------------------------------------------------------------------------- |
36 | //----------------------------------------------------------------------------- |
| 37 | /* |
37 | /* |
| 38 | CRay& CRay::operator = (const CRay& p) |
38 | CRay& CRay::operator = (const CRay& p) |
| 39 | { |
39 | { |
| Line 43... | Line 43... | ||
| 43 | return *this; |
43 | return *this; |
| 44 | } */ |
44 | } */ |
| 45 | //----------------------------------------------------------------------------- |
45 | //----------------------------------------------------------------------------- |
| 46 | void CRay::Print() |
46 | void CRay::Print() |
| 47 | { |
47 | { |
| 48 |
|
48 | printf("---> CRay::Print() <---\n"); |
| 49 |
|
49 | printf("(x,y,z)=(%.2lf, %.2lf, %.2lf); (l,m,n)=(%.2lf, %.2lf, %.2lf)\n", |
| 50 |
|
50 | r.x(), r.y(), r.z(), n.x(), n.y(), n.z()); |
| 51 | } |
51 | } |
| 52 | //----------------------------------------------------------------------------- |
52 | //----------------------------------------------------------------------------- |
| 53 | void CRay::Draw() |
53 | void CRay::Draw() |
| 54 | { |
54 | { |
| 55 | double t = 50.0; |
55 | double t = 50.0; |
| 56 | TPolyLine3D *line3d = new TPolyLine3D(2); |
56 | TPolyLine3D *line3d = new TPolyLine3D(2); |
| 57 |
|
57 | //line3d->SetPoint(0, r.x() - t*n.x(), r.y() - t*n.y(), r.z() - t*n.z()); |
| 58 |
|
58 | line3d->SetPoint(0, r.x(), r.y(), r.z()); |
| 59 |
|
59 | line3d->SetPoint(1, r.x() + t*n.x(), r.y() + t*n.y(), r.z() + t*n.z()); |
| 60 |
|
60 | line3d->SetLineWidth(1); |
| 61 |
|
61 | line3d->SetLineColor(color); |
| 62 | 62 | ||
| 63 |
|
63 | line3d->Draw(); |
| 64 | } |
64 | } |
| 65 | //----------------------------------------------------------------------------- |
65 | //----------------------------------------------------------------------------- |
| 66 | void CRay::Draw(double x_from, double x_to) |
66 | void CRay::Draw(double x_from, double x_to) |
| 67 | { |
67 | { |
| 68 | double A1, A2; |
68 | double A1, A2; |
| 69 | TPolyLine3D *line3d = new TPolyLine3D(2); |
69 | TPolyLine3D *line3d = new TPolyLine3D(2); |
| 70 | 70 | ||
| 71 |
|
71 | if(n.x() < MARGIN) { |
| 72 |
|
72 | A1 = A2 = 0.0; |
| 73 |
|
73 | } else { |
| 74 |
|
74 | A1 = (x_from - r.x())/n.x(); |
| 75 |
|
75 | A2 = (x_to - r.x())/n.x(); |
| 76 |
|
76 | } |
| 77 | 77 | ||
| 78 |
|
78 | line3d->SetPoint(0, x_from, A1*n.y()+r.y(), A1*n.z()+r.z()); |
| 79 |
|
79 | line3d->SetPoint(1, x_to, A2*n.y()+r.y(), A2*n.z()+r.z()); |
| 80 |
|
80 | line3d->SetLineWidth(1); |
| 81 |
|
81 | line3d->SetLineColor(color); |
| 82 | 82 | ||
| 83 |
|
83 | line3d->Draw(); |
| 84 | } |
84 | } |
| 85 | //----------------------------------------------------------------------------- |
85 | //----------------------------------------------------------------------------- |
| 86 | void CRay::DrawS(double x_from, double t) |
86 | void CRay::DrawS(double x_from, double t) |
| 87 | { |
87 | { |
| 88 |
|
88 | double A1; |
| 89 |
|
89 | TPolyLine3D *line3d = new TPolyLine3D(2); |
| 90 | 90 | ||
| 91 |
|
91 | if(n.x() < MARGIN) |
| 92 |
|
92 | A1 = 0.0; |
| 93 |
|
93 | else |
| 94 |
|
94 | A1 = (x_from - r.x())/n.x(); |
| 95 | 95 | ||
| 96 |
|
96 | line3d->SetPoint(0, x_from, A1*n.y()+r.y(), A1*n.z()+r.z()); |
| 97 |
|
97 | line3d->SetPoint(1, r.x() + t*n.x(), r.y() + t*n.y(), r.z() + t*n.z()); |
| 98 |
|
98 | line3d->SetLineWidth(1); |
| 99 |
|
99 | line3d->SetLineColor(color); |
| 100 | 100 | ||
| 101 |
|
101 | line3d->Draw(); |
| 102 | } |
102 | } |
| 103 | //================================================================================= |
103 | //================================================================================= |
| 104 | 104 | ||
| 105 | 105 | ||
| 106 | //================================================================================= |
106 | //================================================================================= |
| 107 | CPlane4::CPlane4() : |
107 | CPlane4::CPlane4() : |
| 108 | n(TVector3(1.0, 0.0, 0.0)), |
108 | n(TVector3(1.0, 0.0, 0.0)), |
| 109 | A(0), |
109 | A(0), |
| 110 | B(0), |
110 | B(0), |
| 111 | C(0), |
111 | C(0), |
| 112 | D(0) |
112 | D(0) |
| 113 | { r[0] = TVector3(0.0,-1.0,-1.0); |
113 | { r[0] = TVector3(0.0,-1.0,-1.0); |
| 114 |
|
114 | r[1] = TVector3(0.0,-1.0, 1.0); |
| 115 |
|
115 | r[2] = TVector3(0.0, 1.0, 1.0); |
| 116 |
|
116 | r[3] = TVector3(0.0, 1.0,-1.0); |
| 117 |
|
117 | for(int i=0;i<4;i++) edge[i] = TVector3(0,0,0); |
| 118 |
|
118 | for(int i=0;i<4;i++) angle_r[i] = 0; |
| 119 | }; |
119 | }; |
| 120 | //----------------------------------------------------------------------------- |
120 | //----------------------------------------------------------------------------- |
| 121 | CPlane4::CPlane4(TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4) |
121 | CPlane4::CPlane4(TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4) |
| 122 | { |
122 | { |
| 123 |
|
123 | //Set(r1, r2, r3, r4); |
| 124 | //} |
124 | //} |
| 125 | //----------------------------------------------------------------------------- |
125 | //----------------------------------------------------------------------------- |
| 126 | / |
126 | // za izracun parametrov ravnine je en vektor prevec, vendar tega |
| 127 | // rabim kot zadnji vogal poligona |
127 | // rabim kot zadnji vogal poligona |
| 128 | //void CPlane4::Set(TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4) |
128 | //void CPlane4::Set(TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4) |
| 129 | //{ |
129 | //{ |
| 130 | double x1,y1,z1, x2,y2,z2, x3,y3,z3; |
- | |
| 131 | - | ||
| 132 | x1 = r1.x(); y1 = r1.y(); z1 = r1.z(); |
- | |
| 133 | x2 = r2.x(); y2 = r2.y(); z2 = r2.z(); |
- | |
| 134 | x3 = r3.x(); y3 = r3.y(); z3 = r3.z(); |
- | |
| 135 | - | ||
| 136 | A = y3*(z1 - z2) + y1*(z2 - z3) + y2*(z3 - z1); |
- | |
| 137 | B = x3*(z2 - z1) + x1*(z3 - z2) + x2*(z1 - z3); |
- | |
| 138 | C = x3*(y1 - y2) + x1*(y2 - y3) + x2*(y3 - y1); |
- | |
| 139 | D = y3*(x1*z2 - x2*z1) + x3*(y2*z1 - y1*z2) + z3*(x2*y1 - x1*y2); |
- | |
| 140 | - | ||
| 141 | r[0] = r1; r[1] = r2; r[2] = r3; r[3] = r4; |
- | |
| 142 | n.SetXYZ(A, B, C); |
- | |
| 143 | n = n.Unit(); |
- | |
| 144 | - | ||
| 145 | for(int i=0;i<4;i++) |
- | |
| 146 | edge[i] = r[i-3 ? i+1 : 0] - r[i]; |
- | |
| 147 | - | ||
| 148 | for(int i=0;i<4;i++) |
- | |
| 149 | angle_r[i] = TMath::ACos(/*TMath::Abs*/( ((-edge[i ? i-1 : 3]).Unit()) * (edge[i].Unit()) )); |
- | |
| 150 | }; |
- | |
| 151 | - | ||
| 152 | void CPlane4::Set(TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4) |
- | |
| 153 | { |
- | |
| 154 | double x1,y1,z1, x2,y2,z2, x3,y3,z3; |
130 | double x1,y1,z1, x2,y2,z2, x3,y3,z3; |
| - | 131 | ||
| - | 132 | x1 = r1.x(); y1 = r1.y(); z1 = r1.z(); |
|
| - | 133 | x2 = r2.x(); y2 = r2.y(); z2 = r2.z(); |
|
| - | 134 | x3 = r3.x(); y3 = r3.y(); z3 = r3.z(); |
|
| - | 135 | ||
| - | 136 | A = y3*(z1 - z2) + y1*(z2 - z3) + y2*(z3 - z1); |
|
| - | 137 | B = x3*(z2 - z1) + x1*(z3 - z2) + x2*(z1 - z3); |
|
| - | 138 | C = x3*(y1 - y2) + x1*(y2 - y3) + x2*(y3 - y1); |
|
| - | 139 | D = y3*(x1*z2 - x2*z1) + x3*(y2*z1 - y1*z2) + z3*(x2*y1 - x1*y2); |
|
| - | 140 | ||
| - | 141 | r[0] = r1; r[1] = r2; r[2] = r3; r[3] = r4; |
|
| - | 142 | n.SetXYZ(A, B, C); |
|
| - | 143 | n = n.Unit(); |
|
| - | 144 | ||
| - | 145 | for(int i=0;i<4;i++) |
|
| - | 146 | edge[i] = r[i-3 ? i+1 : 0] - r[i]; |
|
| - | 147 | ||
| - | 148 | for(int i=0;i<4;i++) |
|
| - | 149 | angle_r[i] = TMath::ACos(/*TMath::Abs*/( ((-edge[i ? i-1 : 3]).Unit()) * (edge[i].Unit()) )); |
|
| - | 150 | }; |
|
| - | 151 | ||
| - | 152 | void CPlane4::Set(TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4) |
|
| 155 | 153 | { |
|
| - | 154 | double x1,y1,z1, x2,y2,z2, x3,y3,z3; |
|
| - | 155 | ||
| 156 |
|
156 | x1 = r1.x(); y1 = r1.y(); z1 = r1.z(); |
| 157 |
|
157 | x2 = r2.x(); y2 = r2.y(); z2 = r2.z(); |
| 158 |
|
158 | x3 = r3.x(); y3 = r3.y(); z3 = r3.z(); |
| 159 | 159 | ||
| 160 |
|
160 | A = y3*(z1 - z2) + y1*(z2 - z3) + y2*(z3 - z1); |
| 161 |
|
161 | B = x3*(z2 - z1) + x1*(z3 - z2) + x2*(z1 - z3); |
| 162 |
|
162 | C = x3*(y1 - y2) + x1*(y2 - y3) + x2*(y3 - y1); |
| 163 |
|
163 | D = y3*(x1*z2 - x2*z1) + x3*(y2*z1 - y1*z2) + z3*(x2*y1 - x1*y2); |
| 164 | 164 | ||
| 165 |
|
165 | r[0] = r1; r[1] = r2; r[2] = r3; r[3] = r4; |
| 166 |
|
166 | n.SetXYZ(A, B, C); |
| 167 |
|
167 | n = n.Unit(); |
| 168 | 168 | ||
| 169 |
|
169 | for(int i=0;i<4;i++) |
| 170 |
|
170 | edge[i] = r[i-3 ? i+1 : 0] - r[i]; |
| 171 | 171 | ||
| 172 |
|
172 | for(int i=0;i<4;i++) |
| 173 |
|
173 | angle_r[i] = TMath::ACos(/*TMath::Abs*/( ((-edge[i ? i-1 : 3]).Unit()) * (edge[i].Unit()) )); |
| 174 | }; |
174 | }; |
| 175 | 175 | ||
| 176 | CPlane4::CPlane4(TVector3 *vr) |
176 | CPlane4::CPlane4(TVector3 *vr) |
| 177 | { |
177 | { |
| 178 | double x1,y1,z1, x2,y2,z2, x3,y3,z3; |
178 | double x1,y1,z1, x2,y2,z2, x3,y3,z3; |
| 179 | - | ||
| 180 | x1 = vr[0].x(); y1 = vr[0].y(); z1 = vr[0].z(); |
- | |
| 181 | x2 = vr[1].x(); y2 = vr[1].y(); z2 = vr[1].z(); |
- | |
| 182 | x3 = vr[2].x(); y3 = vr[2].y(); z3 = vr[2].z(); |
- | |
| 183 | - | ||
| 184 | A = y3*(z1 - z2) + y1*(z2 - z3) + y2*(z3 - z1); |
- | |
| 185 | B = x3*(z2 - z1) + x1*(z3 - z2) + x2*(z1 - z3); |
- | |
| 186 | C = x3*(y1 - y2) + x1*(y2 - y3) + x2*(y3 - y1); |
- | |
| 187 | D = y3*(x1*z2 - x2*z1) + x3*(y2*z1 - y1*z2) + z3*(x2*y1 - x1*y2); |
- | |
| 188 | - | ||
| 189 | r[0] = vr[0]; r[1] = vr[1]; r[2] = vr[2]; r[3] = vr[3]; |
- | |
| 190 | n.SetXYZ(A, B, C); |
- | |
| 191 | n = n.Unit(); |
- | |
| 192 | - | ||
| 193 | for(int i=0;i<4;i++) |
- | |
| 194 | edge[i] = r[i-3 ? i+1 : 0] - r[i]; |
- | |
| 195 | 179 | ||
| - | 180 | x1 = vr[0].x(); y1 = vr[0].y(); z1 = vr[0].z(); |
|
| - | 181 | x2 = vr[1].x(); y2 = vr[1].y(); z2 = vr[1].z(); |
|
| - | 182 | x3 = vr[2].x(); y3 = vr[2].y(); z3 = vr[2].z(); |
|
| - | 183 | ||
| - | 184 | A = y3*(z1 - z2) + y1*(z2 - z3) + y2*(z3 - z1); |
|
| - | 185 | B = x3*(z2 - z1) + x1*(z3 - z2) + x2*(z1 - z3); |
|
| - | 186 | C = x3*(y1 - y2) + x1*(y2 - y3) + x2*(y3 - y1); |
|
| - | 187 | D = y3*(x1*z2 - x2*z1) + x3*(y2*z1 - y1*z2) + z3*(x2*y1 - x1*y2); |
|
| - | 188 | ||
| - | 189 | r[0] = vr[0]; r[1] = vr[1]; r[2] = vr[2]; r[3] = vr[3]; |
|
| - | 190 | n.SetXYZ(A, B, C); |
|
| - | 191 | n = n.Unit(); |
|
| - | 192 | ||
| - | 193 | for(int i=0;i<4;i++) |
|
| - | 194 | edge[i] = r[i-3 ? i+1 : 0] - r[i]; |
|
| - | 195 | ||
| 196 |
|
196 | for(int i=0;i<4;i++) |
| 197 |
|
197 | angle_r[i] = TMath::ACos(/*TMath::Abs*/( ((-edge[i ? i-1 : 3]).Unit()) * (edge[i].Unit()) )); |
| 198 | }; |
198 | }; |
| 199 | //----------------------------------------------------------------------------- |
199 | //----------------------------------------------------------------------------- |
| 200 | // posce presecisce !neskoncne! ravnine s premico (class CRay) |
200 | // posce presecisce !neskoncne! ravnine s premico (class CRay) |
| 201 | // ce najde presecisce vrne 1 |
201 | // ce najde presecisce vrne 1 |
| 202 | int CPlane4::GetIntersection(TVector3 *vec, CRay ray) |
202 | int CPlane4::GetIntersection(TVector3 *vec, CRay ray) |
| 203 | { |
203 | { |
| 204 | TVector3 N; //nenormirani vektor (A,B,C) |
204 | TVector3 N; //nenormirani vektor (A,B,C) |
| 205 | double num, den; //stevec, imenovalec |
205 | double num, den; //stevec, imenovalec |
| 206 | double t; |
206 | double t; |
| 207 | TVector3 tmp; |
207 | TVector3 tmp; |
| 208 | - | ||
| 209 | N.SetXYZ(A,B,C); |
- | |
| 210 | - | ||
| 211 | num = N*ray.GetR() + D; |
- | |
| 212 | den = N*ray.GetN(); |
- | |
| 213 | 208 | ||
| 214 |
|
209 | N.SetXYZ(A,B,C); |
| 215 | 210 | ||
| - | 211 | num = N*ray.GetR() + D; |
|
| - | 212 | den = N*ray.GetN(); |
|
| - | 213 | ||
| - | 214 | if (dbg) printf("t = %6.3lf / %6.3lf = %6.3lf\n", num, den, num/den); |
|
| - | 215 | ||
| 216 |
|
216 | //if(den == 0) |
| 217 |
|
217 | if(TMath::Abs(den) < MARGIN) { |
| 218 |
|
218 | //if(num == 0) |
| 219 |
|
219 | if(TMath::Abs(num) < MARGIN) { |
| 220 |
|
220 | if (dbg) printf("The ray is on the surface!\n"); |
| 221 |
|
221 | return 0; //return 2; // premica lezi na ravnini |
| 222 |
|
222 | } |
| 223 |
|
223 | else { |
| 224 |
|
224 | if (dbg) printf("The ray is parallel to the surface!\n"); |
| 225 |
|
225 | return 0; // ni presecisca |
| 226 |
|
226 | } |
| 227 |
|
227 | } |
| 228 | 228 | ||
| 229 |
|
229 | t = num / den; |
| 230 | 230 | ||
| 231 |
|
231 | tmp = ray.GetR(); |
| 232 |
|
232 | tmp -= t*ray.GetN(); |
| 233 |
|
233 | *vec = tmp; |
| 234 |
|
234 | return 1; |
| 235 | } |
235 | } |
| 236 | //----------------------------------------------------------------------------- |
236 | //----------------------------------------------------------------------------- |
| 237 | // ali je vektor vec, ki lezi na ravnini skupaj z e1 in e2, med njima |
237 | // ali je vektor vec, ki lezi na ravnini skupaj z e1 in e2, med njima |
| 238 | // angle_r je kot med e1 in e2, vsi vektorji imajo skupno izhodisce |
238 | // angle_r je kot med e1 in e2, vsi vektorji imajo skupno izhodisce |
| 239 | int CPlane4::IsInTri(TVector3 vec, TVector3 e1, TVector3 e2, double angle) |
239 | int CPlane4::IsInTri(TVector3 vec, TVector3 e1, TVector3 e2, double angle) |
| 240 | { |
240 | { |
| 241 | double angle_ve1, angle_ve2; |
241 | double angle_ve1, angle_ve2; |
| 242 | 242 | ||
| 243 |
|
243 | if(dbg) printf("--- CPlane4::IsInTri ---\n"); |
| 244 | 244 | ||
| 245 |
|
245 | angle_ve1 = TMath::ACos(/*TMath::Abs*/( (e1.Unit()) * (vec.Unit()) )); |
| 246 |
|
246 | angle_ve2 = TMath::ACos(/*TMath::Abs*/( (e2.Unit()) * (vec.Unit()) )); |
| 247 | 247 | ||
| 248 |
|
248 | if(dbg) |
| 249 |
|
249 | { |
| 250 |
|
250 | printf("angle_ve1 = %lf\n", angle_ve1*DEGREE); |
| 251 |
|
251 | printf("angle_ve2 = %lf\n", angle_ve2*DEGREE); |
| 252 |
|
252 | printf("angle_sum = %lf\n", (angle_ve1 + angle_ve2)*DEGREE); |
| 253 |
|
253 | printf(" angle_r = %lf\n", angle*DEGREE); |
| 254 |
|
254 | } |
| 255 | 255 | ||
| 256 | bool difference = (MARGIN < TMath::Abs(angle - (angle_ve1 + angle_ve2))); |
256 | bool difference = (MARGIN < TMath::Abs(angle - (angle_ve1 + angle_ve2))); |
| 257 | if (dbg) printf(" MARGIN < Difference = %d\n", difference); |
257 | if (dbg) printf(" MARGIN < Difference = %d\n", difference); |
| 258 | return (int) !difference; |
258 | return (int) !difference; |
| 259 | } |
259 | } |
| 260 | //----------------------------------------------------------------------------- |
260 | //----------------------------------------------------------------------------- |
| 261 | // ali je vektor vec, ki lezi na ravnini!, znotraj meja, ki jih definirajo |
261 | // ali je vektor vec, ki lezi na ravnini!, znotraj meja, ki jih definirajo |
| 262 | // strije vogali te ravnine r[i] |
262 | // strije vogali te ravnine r[i] |
| 263 | int CPlane4::IsVectorIn(TVector3 vec) |
263 | int CPlane4::IsVectorIn(TVector3 vec) |
| 264 | { |
264 | { |
| 265 | int status; |
265 | int status; |
| 266 | 266 | ||
| 267 |
|
267 | if(dbg) printf("--- CPlane4::IsVectorIn ---\n"); |
| 268 | 268 | ||
| 269 |
|
269 | for(int i=0;i<3;i++) |
| 270 |
|
270 | { |
| 271 |
|
271 | status = IsInTri(vec - r[i], edge[i], -edge[i ? i-1 : 3], angle_r[i]); |
| 272 |
|
272 | if(dbg) printf(" [%d] vec is %s\n", i, status ? "inside" : "outside"); |
| 273 |
|
273 | if(!status) return 0; |
| 274 |
|
274 | } |
| 275 | 275 | ||
| 276 |
|
276 | return 1; |
| 277 | } |
277 | } |
| 278 | //----------------------------------------------------------------------------- |
278 | //----------------------------------------------------------------------------- |
| 279 | int CPlane4::TestIntersection(CRay in) |
279 | int CPlane4::TestIntersection(CRay in) |
| 280 | { |
280 | { |
| 281 |
|
281 | TVector3 tmp; |
| - | 282 | ||
| - | 283 | if( GetIntersection(&tmp, in) ) |
|
| - | 284 | if( IsVectorIn(tmp) ) |
|
| - | 285 | return 1; |
|
| 282 | 286 | ||
| 283 | if( GetIntersection(&tmp, in) ) |
- | |
| 284 | if( IsVectorIn(tmp) ) |
- | |
| 285 | return 1; |
- | |
| 286 | - | ||
| 287 |
|
287 | return 0; |
| 288 | } |
288 | } |
| 289 | //----------------------------------------------------------------------------- |
289 | //----------------------------------------------------------------------------- |
| 290 | int CPlane4::TestIntersection(TVector3 *vec, CRay in) |
290 | int CPlane4::TestIntersection(TVector3 *vec, CRay in) |
| 291 | { |
291 | { |
| 292 |
|
292 | TVector3 tmp; |
| 293 | 293 | ||
| 294 |
|
294 | if( GetIntersection(&tmp, in) ) |
| 295 |
|
295 | if( IsVectorIn(tmp) ) { |
| 296 |
|
296 | *vec = tmp; |
| 297 |
|
297 | return 1; |
| 298 |
|
298 | } |
| 299 | 299 | ||
| 300 |
|
300 | return 0; |
| 301 | } |
301 | } |
| 302 | //----------------------------------------------------------------------------- |
302 | //----------------------------------------------------------------------------- |
| 303 | void CPlane4::Print() |
303 | void CPlane4::Print() |
| 304 | { |
304 | { |
| 305 |
|
305 | printf("--- CPlane4::Print() ---\n"); |
| 306 |
|
306 | printf(" r=(%.2lf, %.2lf, %.2lf); n=(%.2lf, %.2lf, %.2lf); ", |
| 307 |
|
307 | r[0].x(), r[0].y(), r[0].z(), n.x(), n.y(), n.z()); |
| 308 |
|
308 | printf( "(A,B,C,D)=(%.2lf, %.2lf, %.2lf, %.2lf) \n", A, B, C, D); |
| 309 |
|
309 | for(int i=0;i<4;i++) printf(" edge[%d] = (%lf, %lf, %lf)\n", i, edge[i].x(), edge[i].y(), edge[i].z()); |
| 310 |
|
310 | for(int i=0;i<4;i++) printf(" angle[%d] = %lf\n", i, angle_r[i]*DEGREE); |
| 311 | } |
311 | } |
| 312 | //----------------------------------------------------------------------------- |
312 | //----------------------------------------------------------------------------- |
| 313 | void CPlane4::Draw(int color, int width) |
313 | void CPlane4::Draw(int color, int width) |
| 314 | { |
314 | { |
| 315 | TPolyLine3D *line3d = new TPolyLine3D(5); |
315 | TPolyLine3D *line3d = new TPolyLine3D(5); |
| 316 | - | ||
| 317 | for(int i=0;i<4;i++) line3d->SetPoint(i, r[i].x(), r[i].y(), r[i].z()); |
- | |
| 318 | line3d->SetPoint(4, r[0].x(), r[0].y(), r[0].z()); |
- | |
| 319 | line3d->SetLineWidth(width); line3d->SetLineColor(color); |
- | |
| 320 | - | ||
| 321 | line3d->Draw(); |
- | |
| 322 | } |
- | |
| 323 | //================================================================================= |
- | |
| 324 | - | ||
| 325 | 316 | ||
| - | 317 | for(int i=0;i<4;i++) line3d->SetPoint(i, r[i].x(), r[i].y(), r[i].z()); |
|
| - | 318 | line3d->SetPoint(4, r[0].x(), r[0].y(), r[0].z()); |
|
| - | 319 | line3d->SetLineWidth(width); line3d->SetLineColor(color); |
|
| - | 320 | ||
| - | 321 | line3d->Draw(); |
|
| - | 322 | } |
|
| 326 | //================================================================================= |
323 | //================================================================================= |
| 327 | CSurface::CSurface(int type0): |
- | |
| 328 | type(type0) |
- | |
| 329 | { |
- | |
| 330 | TVector3 vr[4]; |
- | |
| 331 | TDatime now; |
- | |
| 332 | 324 | ||
| - | 325 | ||
| - | 326 | //================================================================================= |
|
| - | 327 | CSurface::CSurface(int type0): |
|
| - | 328 | type(type0) |
|
| - | 329 | { |
|
| - | 330 | TVector3 vr[4]; |
|
| - | 331 | TDatime now; |
|
| - | 332 | ||
| 333 |
|
333 | vr[0].SetXYZ(0.0,-1.0,-1.0); |
| 334 |
|
334 | vr[1].SetXYZ(0.0,-1.0, 1.0); |
| 335 |
|
335 | vr[2].SetXYZ(0.0, 1.0, 1.0); |
| 336 |
|
336 | vr[3].SetXYZ(0.0, 1.0,-1.0); |
| 337 |
|
337 | //CPlane4::Set(vr); |
| 338 |
|
338 | SetIndex(1.0, 1.5); |
| 339 | 339 | ||
| 340 |
|
340 | reflection = c_reflectivity; |
| 341 |
|
341 | rand.SetSeed(now.Get()); |
| 342 | 342 | ||
| 343 |
|
343 | SetFresnel(); |
| 344 | } |
344 | } |
| 345 | //----------------------------------------------------------------------------- |
345 | //----------------------------------------------------------------------------- |
| 346 | CSurface::CSurface(int type0, TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4, double n10, double n20, double reflectivity) |
346 | CSurface::CSurface(int type0, TVector3 r1, TVector3 r2, TVector3 r3, TVector3 r4, double n10, double n20, double reflectivity) |
| 347 | { |
347 | { |
| 348 | TDatime now; |
348 | TDatime now; |
| 349 | 349 | ||
| 350 |
|
350 | type = type0; CPlane4::Set(r1, r2, r3, r4); |
| 351 |
|
351 | SetIndex(n10, n20); |
| 352 | 352 | ||
| 353 |
|
353 | reflection = reflectivity; |
| 354 |
|
354 | rand.SetSeed(now.Get()); |
| 355 | 355 | ||
| 356 |
|
356 | SetFresnel(); |
| 357 | } |
357 | } |
| 358 | //----------------------------------------------------------------------------- |
358 | //----------------------------------------------------------------------------- |
| 359 | CSurface::CSurface(int type0, TVector3 *vr, double n10, double n20, double reflectivity) |
359 | CSurface::CSurface(int type0, TVector3 *vr, double n10, double n20, double reflectivity) |
| 360 | { |
360 | { |
| 361 | TDatime now; |
361 | TDatime now; |
| 362 | 362 | ||
| 363 |
|
363 | type = type0; CPlane4::Set(vr); |
| 364 |
|
364 | SetIndex(n10, n20); |
| 365 | 365 | ||
| 366 |
|
366 | reflection = reflectivity; |
| 367 |
|
367 | rand.SetSeed(now.Get()); |
| 368 | 368 | ||
| 369 |
|
369 | SetFresnel(); |
| 370 | } |
370 | } |
| 371 | //----------------------------------------------------------------------------- |
371 | //----------------------------------------------------------------------------- |
| 372 | void CSurface::SetIndex(double n10, double n20) |
372 | void CSurface::SetIndex(double n10, double n20) |
| 373 | { |
373 | { |
| 374 |
|
374 | n1 = n10; n2 = n20; n1_n2 = n1/n2; |
| 375 | 375 | ||
| 376 |
|
376 | if(n1 > n2) |
| 377 |
|
377 | cosTtotal = TMath::Sqrt( 1 - TMath::Power(n2/n1, 2) ); |
| 378 |
|
378 | else |
| 379 |
|
379 | cosTtotal = 0.0; |
| 380 | } |
380 | } |
| 381 | //----------------------------------------------------------------------------- |
381 | //----------------------------------------------------------------------------- |
| 382 | // sprejme zarek, vrne uklonjen/odbit zarek in presecisce |
382 | // sprejme zarek, vrne uklonjen/odbit zarek in presecisce |
| 383 | // vrne 0 ce ni presecisca; 1 ce se je lomil |
383 | // vrne 0 ce ni presecisca; 1 ce se je lomil |
| 384 | // 2 ce se je odbil; -2 ce se je absorbiral |
384 | // 2 ce se je odbil; -2 ce se je absorbiral |
| Line 387... | Line 387... | ||
| 387 | if (dbg) printf("--- CSurface::PropagateRay ---\n"); |
387 | if (dbg) printf("--- CSurface::PropagateRay ---\n"); |
| 388 | double cosTi; // incident ray angle |
388 | double cosTi; // incident ray angle |
| 389 | double cosTt; // transmited ray angle |
389 | double cosTt; // transmited ray angle |
| 390 | TVector3 intersect, transmit; |
390 | TVector3 intersect, transmit; |
| 391 | 391 | ||
| 392 |
|
392 | if( !(GetIntersection(&intersect, in) == 1) ) |
| 393 |
|
393 | return 0; |
| 394 | 394 | ||
| 395 |
|
395 | *intersection = intersect; |
| 396 |
|
396 | if( !IsVectorIn(intersect) ) |
| 397 |
|
397 | return 0; |
| 398 | 398 | ||
| 399 |
|
399 | // --------------- Fresnel ---------------------------------------------------- |
| 400 |
|
400 | // R_f = a_te * R_te + a_tm * R_tm |
| 401 |
|
401 | // e - electrical/perependicular |
| 402 |
|
402 | // m - magnetic polarization/parallel |
| 403 |
|
403 | double r_te=0; |
| 404 |
|
404 | double r_tm=0; |
| 405 |
|
405 | double R_te=0; // s reflection coefficient |
| 406 |
|
406 | double R_tm=0; // p reflection coefficient |
| 407 |
|
407 | double R_f = 0.0; |
| 408 |
|
408 | double a_te = 0.0; // s-wave amplitude, cos Alpha |
| 409 |
|
409 | double a_tm = 0.0; // p-wave amplitude, sin Alpha |
| 410 |
|
410 | TVector3 v_te; // unit s-polarization vector |
| 411 |
|
411 | TVector3 v_tm; // unit p-polarization vector |
| 412 |
|
412 | TVector3 v_tm_t;// transmited polarization parallel with the plane of incidence |
| 413 |
|
413 | TVector3 pol_t = in.GetP(); // transmited polarization |
| 414 |
|
414 | int sign_n; // sign of normal direction vs. inbound ray |
| 415 |
|
415 | double cosTN; // debug |
| 416 | 416 | ||
| 417 |
|
417 | if(fresnel) { |
| 418 |
|
418 | // p-polarization unit vector v_te |
| 419 |
|
419 | // is in the plane orthogonal to the plane of incidence |
| 420 |
|
420 | // defined as the plane spanned by |
| 421 |
|
421 | // incident surface vector n and wave vector k |
| 422 |
|
422 | // k in this notation is in.GetN() |
| 423 |
|
423 | v_te = n.Cross(in.GetN()); |
| 424 |
|
424 | v_te = v_te.Unit(); |
| 425 |
|
425 | v_tm = -v_te.Cross(in.GetN()); |
| 426 |
|
426 | v_tm = v_tm.Unit(); |
| 427 |
|
427 | if(dbg) { |
| 428 |
|
428 | printf(" v_te = "); printv(v_te); |
| 429 |
|
429 | printf(" v_tm = "); printv(v_tm); |
| 430 |
|
430 | } |
| 431 | 431 | ||
| 432 |
|
432 | double cosAf = v_te * in.GetP(); |
| 433 |
|
433 | if(dbg) printf(" cosAf = %lf (Af = %lf)\n", cosAf, TMath::ACos(cosAf)*DEGREE); |
| 434 | 434 | ||
| 435 |
|
435 | a_te = cosAf; |
| 436 |
|
436 | a_tm = TMath::Sqrt(1 - cosAf*cosAf); |
| 437 |
|
437 | if(dbg) printf(" a_te = %lf, a_tm = %lf\n", a_te, a_tm); |
| 438 |
|
438 | } |
| 439 |
|
439 | // ---------------------------------------------------------------------------- |
| 440 | 440 | ||
| 441 |
|
441 | // reflection probability |
| 442 |
|
442 | double p_ref = rand.Uniform(0.0, 1.0); |
| 443 | 443 | ||
| 444 |
|
444 | if(type == SURF_TOTAL) type = SURF_REFRA; |
| 445 |
|
445 | switch(type){ |
| 446 |
|
446 | // ---------------------------------------------------------------------------- |
| 447 |
|
447 | // --------------- refraction from n1 to n2 ----------------------------------- |
| 448 |
|
448 | // ---------------------------------------------------------------------------- |
| 449 |
|
449 | case SURF_REFRA: |
| 450 |
|
450 | cosTi = in.GetN() * n; |
| 451 |
|
451 | if(dbg) printf(" cosTi = %lf (Ti = %lf)\n", cosTi, TMath::ACos(cosTi)*DEGREE); |
| 452 |
|
452 | sign_n = -sign(cosTi); |
| 453 |
|
453 | if(dbg) printf(" sign_n = %d\n", sign_n); |
| 454 |
|
454 | cosTi = TMath::Abs(cosTi); |
| 455 | 455 | ||
| 456 |
|
456 | // Check if there can be total reflection: n1 > n2 |
| 457 |
|
457 | if(N1_N2(-sign_n) < 1.0) |
| 458 |
|
458 | cosTtotal = TMath::Sqrt( 1 - TMath::Power(N1_N2(-sign_n), 2) ); |
| 459 |
|
459 | else |
| 460 |
|
460 | cosTtotal = 0.0; |
| 461 | 461 | ||
| 462 |
|
462 | if(dbg) printf(" cosTtotal = %lf (Ttotal = %lf)\n", cosTtotal, TMath::ACos(cosTtotal)*DEGREE); |
| 463 |
|
463 | // reflection dependance on polarization missing |
| 464 |
|
464 | // reflection hardcoded to 0.96 |
| 465 |
|
465 | if (dbg) printf(" reflection probability = %f\n", p_ref); |
| 466 | 466 | ||
| 467 |
|
467 | // If n1>n2 and theta>thetaCritical, total reflection |
| 468 |
|
468 | if(cosTi < cosTtotal) { |
| 469 |
|
469 | if(dbg) printf(" TOTAL\n"); |
| 470 |
|
470 | transmit = in.GetN() + sign_n*2*cosTi*n; |
| 471 | 471 | ||
| 472 |
|
472 | if(dbg) { |
| 473 |
|
473 | cosTN = TMath::Abs(transmit.Unit() * n); |
| 474 |
|
474 | printf(" cosTN = %lf (TN = %lf) (Abs(TN) = %lf)\n", cosTN, TMath::ACos(cosTN)*DEGREE, TMath::ACos(TMath::Abs(cosTN))*DEGREE); |
| 475 |
|
475 | } |
| 476 |
|
476 | out->Set(intersect, transmit); |
| 477 | 477 | ||
| 478 |
|
478 | // Shift? |
| 479 |
|
479 | pol_t = -in.GetP() + sign_n*2*cosTi*n; |
| 480 |
|
480 | out->SetPolarization(pol_t); |
| 481 |
|
481 | return REFLECTION; |
| 482 |
|
482 | } else { |
| 483 |
|
483 | // reflection or refraction according to Fresnel equations |
| 484 |
|
484 | if(dbg) printf(" REFRACTION\n"); |
| 485 |
|
485 | if(dbg) printf(" N1_N2(sign_n) = %lf\n", N1_N2(sign_n)); |
| 486 |
|
486 | cosTt = TMath::Sqrt(1 - TMath::Power(N1_N2(sign_n), 2)*(1 - TMath::Power(cosTi, 2))); |
| 487 | 487 | if(dbg) printf(" cosTt = %lf (Tt = %lf) \n", cosTt, TMath::ACos(cosTt)*DEGREE); |
|
| 488 | transmit = N1_N2(sign_n)*in.GetN() + sign_n*(N1_N2(sign_n)*cosTi - cosTt)*n; |
488 | |
| 489 |
|
489 | transmit = N1_N2(sign_n)*in.GetN() + sign_n*(N1_N2(sign_n)*cosTi - cosTt)*n; |
| 490 |
|
490 | if(dbg) {printf(" transmit.Unit() = "); printv(transmit.Unit());} |
| 491 |
|
491 | if(dbg) { |
| 492 |
|
492 | cosTN = transmit.Unit() * n; |
| 493 |
|
493 | printf(" cosTN = %lf (TN = %lf) (Abs(TN) = %lf)\n", cosTN, TMath::ACos(cosTN)*DEGREE, TMath::ACos(TMath::Abs(cosTN))*DEGREE); |
| 494 | 494 | } |
|
| 495 | //if(cosTi<=cosTtotal) cosTt = TMath::Sqrt(1 - TMath::Power(N1_N2(sign_n), 2)*(1 - TMath::Power(cosTi, 2))); |
495 | |
| 496 |
|
496 | //if(cosTi<=cosTtotal) cosTt = TMath::Sqrt(1 - TMath::Power(N1_N2(sign_n), 2)*(1 - TMath::Power(cosTi, 2))); |
| 497 |
|
497 | //if(fresnel) { |
| 498 |
|
498 | r_te = (n1*cosTi - n2*cosTt)/(n1*cosTi + n2*cosTt); // transverse |
| 499 | 499 | r_tm = (n2*cosTi - n1*cosTt)/(n1*cosTt + n2*cosTi); // paralel |
|
| 500 | if(dbg) printf(" r_te = %lf, r_tm = %lf\n", r_te, r_tm); |
500 | |
| 501 | 501 | if(dbg) printf(" r_te = %lf, r_tm = %lf\n", r_te, r_tm); |
|
| 502 | // transmited polarization |
502 | |
| 503 |
|
503 | // transmited polarization |
| 504 |
|
504 | v_tm_t = -v_te.Cross(transmit); |
| 505 |
|
505 | v_tm_t = v_tm_t.Unit(); |
| 506 | 506 | pol_t = a_te * (1.0 - TMath::Abs(r_te)) * v_te + a_tm * (1.0 - TMath::Abs(r_tm)) * v_tm_t; |
|
| 507 | if(dbg) { |
507 | |
| 508 |
|
508 | if(dbg) { |
| 509 |
|
509 | printf(" v_tm_t = "); printv(v_tm_t); |
| 510 |
|
510 | printf(" pol_t = "); printv(pol_t); |
| 511 | 511 | } |
|
| 512 | // Fresnel coefficients |
512 | |
| 513 |
|
513 | // Fresnel coefficients |
| 514 |
|
514 | R_te = TMath::Power(r_te, 2); |
| 515 |
|
515 | R_tm = TMath::Power(r_tm, 2); |
| 516 | 516 | R_f = a_te*a_te*R_te + a_tm*a_tm*R_tm; |
|
| 517 | if (dbg) printf(" R_te = %lf, R_tm = %lf, R_f = %lf\n", R_te, R_tm, R_f); |
517 | |
| 518 |
|
518 | if (dbg) printf(" R_te = %lf, R_tm = %lf, R_f = %lf\n", R_te, R_tm, R_f); |
| 519 | 519 | } |
|
| 520 | if(p_ref >= R_f) { // se lomi |
520 | |
| 521 |
|
521 | if(p_ref >= R_f) { // se lomi |
| 522 |
|
522 | if (dbg) printf(" SURFACE REFRACTED. Return.\n"); |
| 523 |
|
523 | out->Set(intersect, transmit); |
| 524 |
|
524 | out->SetPolarization(pol_t); |
| 525 |
|
525 | return REFRACTION; |
| 526 |
|
526 | } else { // se odbije |
| 527 |
|
527 | if (dbg) printf(" SURFACE REFLECTED. p_ref=%f, R_f=%f\n", p_ref, R_f); |
| 528 |
|
528 | transmit = in.GetN() + sign_n*2*cosTi*n; |
| 529 |
|
529 | out->Set(intersect, transmit); |
| 530 |
|
530 | pol_t = -in.GetP() + sign_n*2*cosTi*n; |
| 531 |
|
531 | out->SetPolarization(pol_t); |
| 532 |
|
532 | return REFLECTION; |
| 533 | 533 | } |
|
| 534 | //} |
534 | |
| 535 |
|
535 | //} |
| 536 | 536 | break; |
|
| 537 | // ---------------------------------------------------------------------------- |
537 | |
| 538 |
|
538 | // ---------------------------------------------------------------------------- |
| 539 |
|
539 | // --------------- reflection at "reflection" probability --------------------- |
| 540 |
|
540 | // ---------------------------------------------------------------------------- |
| 541 |
|
541 | case SURF_REFLE: |
| 542 |
|
542 | p_ref = rand.Uniform(0.0, 1.0); |
| 543 |
|
543 | if(p_ref < reflection) { // se odbije |
| 544 |
|
544 | cosTi = in.GetN() * n; |
| 545 |
|
545 | transmit = in.GetN() - 2*cosTi*n; |
| 546 |
|
546 | out->Set(intersect, transmit); |
| 547 |
|
547 | return REFLECTION; //sdhfvjhsdbfjhsdbcvjhsb |
| 548 |
|
548 | } else { // se ne odbije |
| 549 |
|
549 | transmit = in.GetN(); |
| 550 |
|
550 | out->Set(intersect, transmit); |
| 551 |
|
551 | return ABSORBED; |
| 552 |
|
552 | } |
| 553 | 553 | break; |
|
| 554 | // total reflection from n1 to n2 with R probbability |
554 | |
| 555 |
|
555 | // total reflection from n1 to n2 with R probbability |
| 556 |
|
556 | case SURF_IMPER: |
| 557 |
|
557 | p_ref = rand.Uniform(0.0, 1.0); |
| 558 |
|
558 | if(p_ref < reflection) { // se odbije |
| 559 |
|
559 | cosTi = in.GetN() * n; |
| 560 |
|
560 | if(TMath::Abs(cosTi) < cosTtotal) { // totalni odboj |
| 561 |
|
561 | transmit = in.GetN() - 2*cosTi*n; |
| 562 |
|
562 | out->Set(intersect, transmit); |
| 563 |
|
563 | } else { // ni tot. odboja |
| 564 |
|
564 | transmit = in.GetN(); |
| 565 |
|
565 | out->Set(intersect, transmit); |
| 566 |
|
566 | return ABSORBED; |
| 567 |
|
567 | } |
| 568 |
|
568 | } else { // se ne odbije |
| 569 |
|
569 | transmit = in.GetN(); |
| 570 |
|
570 | out->Set(intersect, transmit); |
| 571 |
|
571 | return ABSORBED; |
| 572 |
|
572 | } |
| 573 | 573 | break; |
|
| 574 | default: |
574 | |
| 575 |
|
575 | default: |
| 576 |
|
576 | *out = in; |
| 577 |
|
577 | break; |
| - | 578 | } |
|
| - | 579 | ||
| - | 580 | return REFRACTION; |
|
| - | 581 | } |
|
| - | 582 | //================================================================================= |
|
| - | 583 | ||
| 578 | 584 | ||
| 579 | return REFRACTION; |
- | |
| 580 | } |
- | |
| 581 | //================================================================================= |
585 | //================================================================================= |
| - | 586 | Guide::Guide(TVector3 center0, DetectorParameters ¶meters) : |
|
| - | 587 | _d(parameters.getD()), |
|
| - | 588 | _n1(parameters.getN1()), |
|
| - | 589 | _n2(parameters.getN2()), |
|
| - | 590 | _n3(parameters.getN3()), |
|
| - | 591 | _r(c_reflectivity), |
|
| - | 592 | _absorption(0), |
|
| - | 593 | _A(0), |
|
| - | 594 | _badCoupling(parameters.badCoupling()) |
|
| - | 595 | { |
|
| - | 596 | double t; |
|
| - | 597 | TDatime now; |
|
| - | 598 | rand.SetSeed(now.Get()); |
|
| - | 599 | center = center0; |
|
| - | 600 | double b = parameters.getB(); |
|
| - | 601 | double a = parameters.getA(); |
|
| - | 602 | // if PlateOn, then n0 = n3 (optical grease), else = n1 (air) |
|
| - | 603 | //double n0 = (parameters.getPlateOn() ? parameters.getN3(): n1); |
|
| - | 604 | double n0 = (parameters.getPlateOn() ? _n2 : _n1); |
|
| - | 605 | int fresnel = parameters.getFresnel(); |
|
| - | 606 | ||
| - | 607 | // light guide edges |
|
| - | 608 | t = b/2.0; |
|
| - | 609 | vodnik_edge[0].SetXYZ(0.0, t,-t); |
|
| - | 610 | vodnik_edge[1].SetXYZ(0.0, t, t); |
|
| - | 611 | vodnik_edge[2].SetXYZ(0.0,-t, t); |
|
| - | 612 | vodnik_edge[3].SetXYZ(0.0,-t,-t); |
|
| - | 613 | t = a/2.0; |
|
| - | 614 | vodnik_edge[4].SetXYZ(_d, t,-t); |
|
| - | 615 | vodnik_edge[5].SetXYZ(_d, t, t); |
|
| - | 616 | vodnik_edge[6].SetXYZ(_d,-t, t); |
|
| - | 617 | vodnik_edge[7].SetXYZ(_d,-t,-t); |
|
| - | 618 | ||
| - | 619 | for(int i = 0; i<8; i++) vodnik_edge[i] += center; |
|
| - | 620 | ||
| - | 621 | // light guide surfaces |
|
| - | 622 | s_side[0] = new CSurface(SURF_REFRA, vodnik_edge, n0, _n2, _r); |
|
| - | 623 | s_side[0]->FlipN(); |
|
| - | 624 | ||
| - | 625 | s_side[1] = new CSurface(SURF_REFRA, vodnik_edge[3], vodnik_edge[2], |
|
| - | 626 | vodnik_edge[6], vodnik_edge[7], _n2, _n1, _r); |
|
| - | 627 | s_side[2] = new CSurface(SURF_REFRA, vodnik_edge[2], vodnik_edge[1], |
|
| - | 628 | vodnik_edge[5], vodnik_edge[6], _n2, _n1, _r); |
|
| - | 629 | s_side[3] = new CSurface(SURF_REFRA, vodnik_edge[1], vodnik_edge[0], |
|
| - | 630 | vodnik_edge[4], vodnik_edge[5], _n2, _n1, _r); |
|
| - | 631 | s_side[4] = new CSurface(SURF_REFRA, vodnik_edge[0], vodnik_edge[3], |
|
| - | 632 | vodnik_edge[7], vodnik_edge[4], _n2, _n1, _r); |
|
| - | 633 | // n3 - ref ind at the exit, grease, air |
|
| - | 634 | s_side[5] = new CSurface(SURF_REFRA, &vodnik_edge[4], _n2, _n3, _r); |
|
| - | 635 | s_side[5]->FlipN(); |
|
| - | 636 | // exit surface in the case of bad coupling |
|
| - | 637 | noCoupling = new CSurface(SURF_REFRA, &vodnik_edge[4], _n2, 1.0, _r); |
|
| - | 638 | noCoupling->FlipN(); |
|
| - | 639 | // grease = specific pattern area of coupling |
|
| - | 640 | TVector3 activePosition(center); |
|
| - | 641 | activePosition += TVector3(_d, 0, 0); |
|
| - | 642 | TVector3 normal(1,0,0); |
|
| - | 643 | grease = new CPlaneR(activePosition, normal, a/2.0); |
|
| - | 644 | ||
| - | 645 | if(fresnel) for(int i=0; i<6; i++) s_side[i]->SetFresnel(1); |
|
| - | 646 | ||
| - | 647 | // statistics histograms |
|
| - | 648 | hfate = (TH1F*)gROOT->FindObject("hfate"); if(hfate) delete hfate; |
|
| - | 649 | hfate = new TH1F("hfate", "Ray fate", 8, -3.5, 4.5); |
|
| - | 650 | (hfate->GetXaxis())->SetBinLabel(1, "Back Ref"); |
|
| - | 651 | (hfate->GetXaxis())->SetBinLabel(2, "No Ref"); |
|
| - | 652 | (hfate->GetXaxis())->SetBinLabel(3, "Refrac"); |
|
| - | 653 | (hfate->GetXaxis())->SetBinLabel(4, "LG Miss"); |
|
| - | 654 | (hfate->GetXaxis())->SetBinLabel(5, "Exit"); |
|
| - | 655 | (hfate->GetXaxis())->SetBinLabel(6, "Enter"); |
|
| - | 656 | (hfate->GetXaxis())->SetBinLabel(7, "Rays"); |
|
| - | 657 | (hfate->GetXaxis())->SetBinLabel(8, "Absorb"); |
|
| - | 658 | ||
| - | 659 | hnodb_all = (TH1F*)gROOT->FindObject("hnodb_all"); if(hnodb_all) delete hnodb_all; |
|
| - | 660 | hnodb_all = new TH1F("hnodb_all", "", MAX_REFLECTIONS, -0.5, MAX_REFLECTIONS-0.5); |
|
| 582 | 661 | ||
| - | 662 | hnodb_exit = (TH1F*)gROOT->FindObject("hnodb_exit"); if(hnodb_exit) delete hnodb_exit; |
|
| - | 663 | hnodb_exit = new TH1F("hnodb_exit", "", MAX_REFLECTIONS, -0.5, MAX_REFLECTIONS-0.5); |
|
| - | 664 | ||
| - | 665 | int nBins = nch + 1; |
|
| - | 666 | hin = (TH2F*)gROOT->FindObject("hin"); if(hin) delete hin; |
|
| - | 667 | hin = new TH2F("hin", ";x [mm]; y[mm]", nBins, -b/2.0, +b/2.0, nBins, -b/2.0, +b/2.0); |
|
| 583 | 668 | ||
| 584 | //================================================================================= |
- | |
| 585 | Guide::Guide(TVector3 center0, DetectorParameters ¶meters) |
- | |
| 586 | { |
- | |
| 587 | double t; |
- | |
| 588 | - | ||
| 589 | TDatime now; |
- | |
| 590 | rand.SetSeed(now.Get()); |
- | |
| 591 | - | ||
| 592 | center = center0; |
- | |
| 593 | double b = parameters.getB(); |
- | |
| 594 | double a = parameters.getA(); |
- | |
| 595 | _d = parameters.getD(); |
- | |
| 596 | n1 = parameters.getN1(); |
- | |
| 597 | n2 = parameters.getN2(); |
- | |
| 598 | // if PlateOn, then n0 = n3 (optical grease), else = n1 (air) |
- | |
| 599 | //double n0 = (parameters.getPlateOn() ? parameters.getN3(): n1); |
- | |
| 600 | double n0 = (parameters.getPlateOn() ? n2 : n1); |
- | |
| 601 | n3 = parameters.getN3(); |
- | |
| 602 | _r = c_reflectivity; |
- | |
| 603 | int fresnel = parameters.getFresnel(); |
- | |
| 604 | - | ||
| 605 | // light guide edges |
- | |
| 606 | t = b/2.0; |
- | |
| 607 | vodnik_edge[0].SetXYZ(0.0, t,-t); |
- | |
| 608 | vodnik_edge[1].SetXYZ(0.0, t, t); |
- | |
| 609 | vodnik_edge[2].SetXYZ(0.0,-t, t); |
- | |
| 610 | vodnik_edge[3].SetXYZ(0.0,-t,-t); |
- | |
| 611 | t = a/2.0; |
- | |
| 612 | vodnik_edge[4].SetXYZ(_d, t,-t); |
- | |
| 613 | vodnik_edge[5].SetXYZ(_d, t, t); |
- | |
| 614 | vodnik_edge[6].SetXYZ(_d,-t, t); |
- | |
| 615 | vodnik_edge[7].SetXYZ(_d,-t,-t); |
- | |
| 616 | - | ||
| 617 | for(int i = 0; i<8; i++) vodnik_edge[i] += center; |
- | |
| 618 | - | ||
| 619 | // light guide surfaces |
- | |
| 620 | s_side[0] = new CSurface(SURF_REFRA, vodnik_edge, n0, n2, _r); |
- | |
| 621 | s_side[0]->FlipN(); |
- | |
| 622 | - | ||
| 623 | s_side[1] = new CSurface(SURF_REFRA, vodnik_edge[3], vodnik_edge[2], vodnik_edge[6], vodnik_edge[7], n2, n1, _r); |
- | |
| 624 | s_side[2] = new CSurface(SURF_REFRA, vodnik_edge[2], vodnik_edge[1], vodnik_edge[5], vodnik_edge[6], n2, n1, _r); |
- | |
| 625 | s_side[3] = new CSurface(SURF_REFRA, vodnik_edge[1], vodnik_edge[0], vodnik_edge[4], vodnik_edge[5], n2, n1, _r); |
- | |
| 626 | s_side[4] = new CSurface(SURF_REFRA, vodnik_edge[0], vodnik_edge[3], vodnik_edge[7], vodnik_edge[4], n2, n1, _r); |
- | |
| 627 | - | ||
| 628 | s_side[5] = new CSurface(SURF_REFRA, &vodnik_edge[4], n2, n3, _r); // n3 - ref ind at the exit, grease, air, epoxy |
- | |
| 629 | s_side[5]->FlipN(); |
- | |
| 630 | - | ||
| 631 | if(fresnel) for(int i=0; i<6; i++) s_side[i]->SetFresnel(1); |
- | |
| 632 | - | ||
| 633 | // statistics histograms |
- | |
| 634 | hfate = (TH1F*)gROOT->FindObject("hfate"); if(hfate) delete hfate; |
- | |
| 635 | hfate = new TH1F("hfate", "Ray fate", 8, -3.5, 4.5); |
- | |
| 636 | (hfate->GetXaxis())->SetBinLabel(1, "Back Ref"); |
- | |
| 637 | (hfate->GetXaxis())->SetBinLabel(2, "No Ref"); |
- | |
| 638 | (hfate->GetXaxis())->SetBinLabel(3, "Refrac"); |
- | |
| 639 | (hfate->GetXaxis())->SetBinLabel(4, "LG Miss"); |
- | |
| 640 | (hfate->GetXaxis())->SetBinLabel(5, "Exit"); |
- | |
| 641 | (hfate->GetXaxis())->SetBinLabel(6, "Enter"); |
- | |
| 642 | (hfate->GetXaxis())->SetBinLabel(7, "Rays"); |
- | |
| 643 | (hfate->GetXaxis())->SetBinLabel(8, "Absorb"); |
- | |
| 644 | - | ||
| 645 | hnodb_all = (TH1F*)gROOT->FindObject("hnodb_all"); if(hnodb_all) delete hnodb_all; |
- | |
| 646 | hnodb_all = new TH1F("hnodb_all", "N reflected", MAX_REFLECTIONS, -0.5, MAX_REFLECTIONS-0.5); |
- | |
| 647 | - | ||
| 648 | hnodb_exit = (TH1F*)gROOT->FindObject("hnodb_exit"); if(hnodb_exit) delete hnodb_exit; |
- | |
| 649 | hnodb_exit = new TH1F("hnodb_exit", "N reflected and exit", MAX_REFLECTIONS, -0.5, MAX_REFLECTIONS-0.5); |
- | |
| 650 | - | ||
| 651 | int nBins = nch + 1; |
- | |
| 652 | hin = (TH2F*)gROOT->FindObject("hin"); if(hin) delete hin; |
- | |
| 653 | hin = new TH2F("hin", "Guide entrance window", nBins, -b/2.0, +b/2.0, nBins, -b/2.0, +b/2.0); |
- | |
| 654 | - | ||
| 655 |
|
669 | hout = (TH2F*)gROOT->FindObject("hout"); if(hout) delete hout; |
| 656 |
|
670 | hout = new TH2F("hout", ";x [mm];y [mm]", nBins, -a/2.0, +a/2.0, nBins, -a/2.0, +a/2.0); |
| 657 | - | ||
| 658 | absorption = 0; |
- | |
| 659 | A = 0; |
- | |
| 660 | } |
671 | } |
| 661 | //----------------------------------------------------------------------------- |
672 | //----------------------------------------------------------------------------- |
| 662 | // Sledi zarku skozi vodnik. Vrne: |
673 | // Sledi zarku skozi vodnik. Vrne: |
| 663 | // 0, ce zgresi vstopno ploskev |
674 | // 0, ce zgresi vstopno ploskev |
| 664 | // 1, ce zadane izstopno ploskev |
675 | // 1, ce zadane izstopno ploskev |
| Line 668... | Line 679... | ||
| 668 | // -3, ce se odbije nazaj in gre nazaj ven skozi sprednjo ploskev |
679 | // -3, ce se odbije nazaj in gre nazaj ven skozi sprednjo ploskev |
| 669 | // +4, ce se absorbira v materialu |
680 | // +4, ce se absorbira v materialu |
| 670 | Fate Guide::PropagateRay(CRay in, CRay *out, int *n_points, TVector3 *points) |
681 | Fate Guide::PropagateRay(CRay in, CRay *out, int *n_points, TVector3 *points) |
| 671 | { |
682 | { |
| 672 | if (dbg) printf("--- GUIDE::PropagateRay ---\n"); |
683 | if (dbg) printf("--- GUIDE::PropagateRay ---\n"); |
| - | 684 | // ray0 - incident ray |
|
| - | 685 | // ray1 - trans/refl ray |
|
| 673 | CRay ray0; |
686 | CRay ray0; |
| 674 | CRay ray1; |
687 | CRay ray1; |
| 675 | TVector3 vec0, vec1; |
688 | TVector3 vec0, vec1; |
| 676 | int inters_i = 0; |
689 | int inters_i = 0; |
| 677 | 690 | ||
| 678 |
|
691 | ray0 = in; |
| 679 |
|
692 | int n_odb = 0; |
| 680 |
|
693 | int last_hit = 0; |
| 681 |
|
694 | int propagation = 0; |
| 682 |
|
695 | int result = s_side[0]->PropagateRay(ray0, &ray1, &vec1); |
| 683 |
|
696 | if( !(result) ) { |
| 684 |
|
697 | // ce -NI- presecisca z vstopno |
| 685 |
|
698 | if (dbg) printf(" GUIDE: missed the light guide\n"); |
| 686 |
|
699 | fate = missed; |
| 687 |
|
700 | //hfate->Fill(0); |
| 688 |
|
701 | } else if(result == REFLECTION) { |
| 689 |
|
702 | if (dbg) printf(" REFLECTED on the entry surface!\n"); |
| 690 |
|
703 | fate = backreflected; |
| 691 |
|
704 | //hfate->Fill(-3); |
| 692 |
|
705 | } else { |
| 693 |
|
706 | if (dbg) printf(" GUIDE: ray entered\n"); |
| 694 |
|
707 | points[0] = ray1.GetR(); |
| 695 |
|
708 | hfate->Fill(enter); // enter |
| 696 |
|
709 | hin->Fill(vec1.y(), vec1.z()); |
| 697 |
|
710 | if (dbg) printf(" GUIDE: n_odb = %d\n", n_odb); |
| 698 | 711 | ||
| 699 |
|
712 | while (n_odb++ < MAX_REFLECTIONS) { |
| 700 |
|
713 | if (dbg) printf(" GUIDE: Boundary test: %d\n",n_odb); |
| 701 |
|
714 | ray0 = ray1; |
| 702 |
|
715 | vec0 = vec1; |
| 703 |
|
716 | propagation = 11; |
| 704 |
|
717 | for(inters_i=0; inters_i<6; inters_i++) { |
| 705 |
|
718 | if (dbg) printf(" GUIDE: Test intersection with surface %d \n", inters_i); |
| 706 |
|
719 | if( inters_i != last_hit) { |
| 707 |
|
720 | int testBoundary = s_side[inters_i]->TestIntersection(&vec1, ray1); |
| 708 |
|
721 | if( testBoundary ) { |
| 709 |
|
722 | if (dbg) printf(" GUIDE: ray intersects with LG surface %d\n",inters_i); |
| 710 |
|
723 | break; |
| 711 |
|
724 | } |
| 712 |
|
725 | } |
| 713 |
|
726 | } |
| 714 |
|
727 | points[n_odb] = vec1; |
| 715 |
|
728 | if(inters_i == 0) { |
| 716 |
|
729 | fate = backreflected; |
| 717 |
|
730 | //hfate->Fill(backreflected); |
| 718 |
|
731 | break; |
| 719 |
|
732 | } // backreflection |
| 720 | 733 | ||
| 721 |
|
734 | // the passage is possible, test propagation |
| 722 |
|
735 | propagation = s_side[inters_i]->PropagateRay(ray0, &ray1, &vec1); |
| 723 | 736 | ||
| 724 |
|
737 | if (dbg) printf(" GUIDE: surface = %d, propagation = %d\n", inters_i, propagation); |
| 725 | 738 | ||
| 726 | if(propagation == REFRACTION) { |
739 | |
| 727 |
|
740 | if(propagation == ABSORBED) { |
| 728 |
|
741 | fate = noreflection; |
| 729 |
|
742 | break; |
| 730 |
|
743 | } //refraction due to finite reflectivity |
| 731 | break; |
744 | |
| 732 |
|
745 | if(inters_i == 5) { |
| 733 |
|
746 | if (_badCoupling) { |
| 734 |
|
747 | TVector3 hitVector(0,0,0); |
| 735 |
|
748 | bool hitActive = grease->TestIntersection(&hitVector, ray0); |
| 736 |
|
749 | if (hitActive and dbg) printf(" GUIDE: hit grease\n"); |
| 737 | 750 | if (!hitActive) propagation = noCoupling->PropagateRay(ray0, &ray1, &vec1); |
|
| 738 |
|
751 | } |
| 739 |
|
752 | // check on which side the vector is? |
| 740 |
|
753 | TVector3 ray = ray1.GetN(); |
| 741 |
|
754 | TVector3 exitNormal = s_side[5]->GetN(); |
| 742 |
|
755 | if (dbg) printf("ray*n_5 = %lf\n", ray*exitNormal); |
| 743 |
|
756 | if (ray*exitNormal > 0) { |
| 744 |
|
757 | if (dbg) printf(" GUIDE: ray is backreflected from exit window.\n"); |
| 745 |
|
758 | fate = backreflected; |
| 746 |
|
759 | n_odb++; |
| 747 |
|
760 | points[n_odb] = vec1; |
| 748 |
|
761 | ray0 = ray1; |
| 749 |
|
762 | break; |
| 750 |
|
763 | } |
| 751 |
|
764 | fate = hitExit; |
| 752 |
|
765 | hout->Fill(vec1.y(), vec1.z()); |
| 753 |
|
766 | hnodb_exit->Fill(n_odb-1); |
| 754 |
|
767 | n_odb++; |
| 755 |
|
768 | points[n_odb] = vec1; |
| 756 |
|
769 | ray0 = ray1; |
| 757 |
|
770 | break; |
| 758 |
|
771 | } |
| 759 | break; |
772 | |
| 760 |
|
773 | if(propagation == REFRACTION) { |
| 761 |
|
774 | fate = refracted; |
| 762 |
|
775 | n_odb++; |
| 763 | |
776 | points[n_odb] = vec1; |
| 764 | 777 | ray0 = ray1; |
|
| 765 |
|
778 | break; |
| 766 |
|
779 | } // no total reflection when should be |
| 767 | double travel = 0.0; |
780 | |
| 768 |
|
781 | last_hit = inters_i; |
| 769 |
|
782 | } |
| 770 |
|
783 | } |
| 771 | printf("travel = %lf\n", travel); //dbg |
784 | |
| 772 |
|
785 | //--- material absorption --- |
| 773 |
|
786 | if(_absorption) { |
| 774 |
|
787 | double travel = 0.0; |
| 775 |
|
788 | if (dbg) printf("n_odb = %d\n", n_odb); |
| 776 |
|
789 | for(int point = 0; point < n_odb-1; point++) { |
| 777 | 790 | travel += (points[point] - points[point+1]).Mag(); |
|
| 778 |
|
791 | if (dbg) printf("travel = %lf\n", travel); |
| 779 |
|
792 | } |
| 780 |
|
793 | double T_abs = TMath::Exp(-travel/_A); |
| 781 | 794 | if(dbg)printf("T_abs = %lf\n", T_abs); |
|
| 782 |
|
795 | double p_abs = rand.Uniform(0.0, 1.0); |
| 783 |
|
796 | if(dbg)printf("p_abs = %lf\n", p_abs); |
| 784 | hnodb_all->Fill(n_odb-2); |
797 | |
| 785 |
|
798 | if(p_abs > T_abs) fate = absorbed; // absorption |
| 786 |
|
799 | } |
| 787 |
|
800 | //--- material absorption --- |
| - | 801 | ||
| - | 802 | hfate->Fill(fate); |
|
| - | 803 | hfate->Fill(rays); |
|
| - | 804 | hnodb_all->Fill(n_odb-2); |
|
| - | 805 | *n_points = n_odb+1; |
|
| - | 806 | *out = ray0; |
|
| - | 807 | return fate; |
|
| 788 | } |
808 | } |
| 789 | //----------------------------------------------------------------------------- |
809 | //----------------------------------------------------------------------------- |
| 790 | void Guide::GetVFate(int *out) |
810 | void Guide::GetVFate(int *out) |
| 791 | { |
811 | { |
| 792 |
|
812 | for(int i=0;i<7;i++) out[i] = (int)hfate->GetBinContent(i+1); |
| 793 | } |
813 | } |
| 794 | //----------------------------------------------------------------------------- |
814 | //----------------------------------------------------------------------------- |
| 795 | void Guide::Draw(int color, int width) |
815 | void Guide::Draw(int color, int width) |
| 796 | { |
816 | { |
| 797 |
|
817 | for(int i = 0; i<6; i++) s_side[i]->Draw(color, width); |
| 798 | } |
818 | } |
| 799 | //----------------------------------------------------------------------------- |
819 | //----------------------------------------------------------------------------- |
| 800 | void Guide::DrawSkel(int color, int width) |
820 | void Guide::DrawSkel(int color, int width) |
| 801 | { |
821 | { |
| 802 |
|
822 | TPolyLine3D *line3d = new TPolyLine3D(2); |
| 803 |
|
823 | line3d->SetLineWidth(width); line3d->SetLineColor(color); |
| 804 | 824 | ||
| 805 |
|
825 | for(int i=0; i<4; i++) { |
| 806 |
|
826 | line3d->SetPoint(0, vodnik_edge[i+0].x(), vodnik_edge[i+0].y(), vodnik_edge[i+0].z()); |
| 807 |
|
827 | line3d->SetPoint(1, vodnik_edge[i+4].x(), vodnik_edge[i+4].y(), vodnik_edge[i+4].z()); |
| 808 |
|
828 | line3d->DrawClone(); |
| 809 |
|
829 | } |
| 810 | } |
830 | } |
| 811 | //================================================================================= |
831 | //================================================================================= |
| 812 | 832 | ||
| 813 | //================================================================================= |
833 | //================================================================================= |
| 814 | int CPlaneR::TestIntersection(TVector3 *vec, CRay ray) |
834 | int CPlaneR::TestIntersection(TVector3 *vec, CRay ray) |
| 815 | { |
835 | { |
| 816 |
|
836 | double num, den; //stevec, imenovalec |
| 817 |
|
837 | double t; |
| 818 |
|
838 | TVector3 tmp; |
| 819 | 839 | ||
| 820 |
|
840 | if(dbg) printf("---> CPlaneR::TestIntersection <---\n"); |
| 821 |
|
841 | if(dbg) {printf("c = "); printv(center); printf(" | n = "); printv(n); printf("\n");} |
| 822 | - | ||
| 823 | double D = - n*center; |
- | |
| 824 | num = n*ray.GetR() + D; |
- | |
| 825 | den = n*ray.GetN(); |
- | |
| 826 | - | ||
| 827 | if(dbg) printf("D = %.4lf | num = %.4lf | den = %.4lf\n", D, num, den); |
- | |
| 828 | 842 | ||
| - | 843 | double D = - n*center; |
|
| - | 844 | num = n*ray.GetR() + D; |
|
| - | 845 | den = n*ray.GetN(); |
|
| - | 846 | ||
| - | 847 | if(dbg) printf("D = %.4lf | num = %.4lf | den = %.4lf\n", D, num, den); |
|
| - | 848 | ||
| 829 |
|
849 | if(TMath::Abs(den) < MARGIN) { |
| 830 |
|
850 | if(TMath::Abs(num) < MARGIN) |
| 831 |
|
851 | return 0; |
| 832 |
|
852 | else |
| 833 |
|
853 | return 0; |
| 834 |
|
854 | } |
| 835 | 855 | ||
| 836 |
|
856 | t = num / den; |
| 837 | 857 | ||
| 838 |
|
858 | if(dbg) printf("t = %.4lf | ", t); |
| 839 | 859 | ||
| 840 |
|
860 | tmp = ray.GetR(); |
| 841 |
|
861 | tmp -= t*ray.GetN(); |
| 842 |
|
862 | *vec = tmp; |
| 843 | 863 | ||
| 844 |
|
864 | if(dbg) {printv(tmp); printf(" | Rv = %.4lf <> R = %.4lf\n", ((tmp - center).Mag()), _r);} |
| 845 | 865 | ||
| 846 | 866 | ||
| 847 |
|
867 | if( ((tmp - center).Mag()) < _r ) |
| 848 |
|
868 | return 1; |
| 849 |
|
869 | else |
| 850 |
|
870 | return 0; |
| 851 | } |
871 | } |
| 852 | //----------------------------------------------------------------------------- |
872 | //----------------------------------------------------------------------------- |
| 853 | void CPlaneR::Draw(int color, int width) |
873 | void CPlaneR::Draw(int color, int width) |
| 854 | { |
874 | { |
| 855 |
|
875 | const int NN = 32; |
| 856 |
|
876 | double phi, x, y; |
| 857 | 877 | ||
| 858 |
|
878 | TPolyLine3D *arc; |
| 859 |
|
879 | arc = new TPolyLine3D(NN+1); |
| 860 |
|
880 | arc->SetLineWidth(width); |
| 861 |
|
881 | arc->SetLineColor(color); |
| 862 | 882 | ||
| 863 |
|
883 | for(int i=0; i<=NN; i++) { |
| 864 |
|
884 | phi = i*2.0*TMath::Pi()/NN; |
| 865 |
|
885 | x = _r*TMath::Cos(phi); |
| 866 |
|
886 | y = _r*TMath::Sin(phi); |
| 867 |
|
887 | arc->SetPoint(i, center.x(), x, y); |
| 868 |
|
888 | } |
| 869 |
|
889 | arc->Draw(); |
| 870 | } |
890 | } |
| 871 | //================================================================================= |
891 | //================================================================================= |
| 872 | 892 | ||
| 873 | 893 | ||
| 874 | //================================================================================= |
894 | //================================================================================= |
| 875 | CDetector::CDetector(TVector3 center0, DetectorParameters& parameters) : |
895 | CDetector::CDetector(TVector3 center0, DetectorParameters& parameters) : |
| 876 | center(center0), |
896 | center(center0), |
| 877 | glass_on(parameters.getGlassOn()), |
897 | glass_on(parameters.getGlassOn()), |
| 878 | glass_d(parameters.getGlassD()), |
898 | glass_d(parameters.getGlassD()), |
| 879 | //x_gap(parameters.getGap().X()), |
- | |
| 880 | //y_gap(parameters.getGap().Y()), |
- | |
| 881 | //z_gap(parameters.getGap().Z()), |
- | |
| 882 | //glass(new CSurface), |
- | |
| 883 | //glass_circle(new CPlaneR), |
- | |
| 884 | //active(new CPlane4), |
- | |
| 885 |
|
899 | col_in(2), |
| 886 |
|
900 | col_lg(8), |
| 887 |
|
901 | col_out(4), |
| 888 |
|
902 | col_rgla(6), |
| 889 |
|
903 | col_LG(1), |
| 890 |
|
904 | col_glass(4), |
| 891 |
|
905 | col_active(7), |
| 892 |
|
906 | guide_on(parameters.getGuideOn()), |
| 893 | //window_R( parameters.getB() ), |
- | |
| 894 | //window_d(0), |
- | |
| 895 | guide(new Guide(center0, parameters)), |
907 | guide(new Guide(center0, parameters)), |
| 896 | plate(new Plate(parameters)), |
908 | plate(new Plate(parameters)), |
| 897 | _plateWidth(parameters.getPlateWidth()), |
909 | _plateWidth(parameters.getPlateWidth()), |
| 898 | _plateOn(parameters.getPlateOn()), |
910 | _plateOn(parameters.getPlateOn()), |
| 899 | offsetY(parameters.getOffsetY()), |
911 | offsetY(parameters.getOffsetY()), |
| 900 | offsetZ(parameters.getOffsetZ()) |
912 | offsetZ(parameters.getOffsetZ()) |
| 901 |
|
913 | { |
| 902 | // }; |
914 | // }; |
| 903 | 915 | ||
| 904 | //----------------------------------------------------------------------------- |
916 | //----------------------------------------------------------------------------- |
| 905 | //void CDetector::Init() |
917 | //void CDetector::Init() |
| 906 | //{ |
918 | //{ |
| 907 | double d = parameters.getD(); |
919 | double d = parameters.getD(); |
| 908 |
|
920 | double x_offset; |
| 909 |
|
921 | if(guide_on) x_offset = center.x(); |
| 910 |
|
922 | else x_offset = center.x() - d; |
| 911 | - | ||
| 912 | //guide = new CVodnik(center, SiPM, M, d, type_in, type_side, type_out, n1, n2, n3, reflectivity, fresnel, absorption, A); |
- | |
| 913 | 923 | ||
| 914 |
|
924 | double b = parameters.getB(); |
| 915 |
|
925 | //double n1 = parameters.getN1(); |
| 916 |
|
926 | //double n2 = parameters.getN2(); |
| 917 |
|
927 | double n3 = parameters.getN3(); |
| 918 |
|
928 | double reflectivity = c_reflectivity; |
| 919 |
|
929 | double x_gap = parameters.getGap().X(); |
| 920 |
|
930 | double y_gap = parameters.getGap().Y(); |
| 921 |
|
931 | double z_gap = parameters.getGap().Z(); |
| 922 | 932 | ||
| 923 |
|
933 | // additional glass between at top of SiPM |
| 924 |
|
934 | // example: epoxy n=1.60 |
| 925 |
|
935 | double n4 = 1.57; |
| 926 |
|
936 | TVector3 plane_v[4]; |
| 927 |
|
937 | int nBins = nch + 1; |
| 928 |
|
938 | double p_size = b/2.0; |
| 929 |
|
939 | plane_v[0].SetXYZ(x_offset+d+glass_d, y_gap + p_size, z_gap - p_size); |
| 930 |
|
940 | plane_v[1].SetXYZ(x_offset+d+glass_d, y_gap + p_size, z_gap + p_size); |
| 931 |
|
941 | plane_v[2].SetXYZ(x_offset+d+glass_d, y_gap - p_size, z_gap + p_size); |
| 932 |
|
942 | plane_v[3].SetXYZ(x_offset+d+glass_d, y_gap - p_size, z_gap - p_size); |
| 933 |
|
943 | glass = new CSurface(SURF_REFRA, plane_v, n3, n4, reflectivity); |
| 934 |
|
944 | glass->FlipN(); |
| 935 | 945 | ||
| 936 |
|
946 | // additional circular glass between LG and SiPM |
| 937 |
|
947 | glass_circle = new CPlaneR(TVector3(x_offset+d+glass_d, y_gap, z_gap), TVector3(-1.0, 0.0, 0.0), b); |
| 938 | 948 | ||
| 939 |
|
949 | hglass = (TH2F*)gROOT->FindObject("hglass"); if(hglass) delete hglass; |
| 940 |
|
950 | hglass = new TH2F("hglass", "", |
| 941 |
|
951 | nBins, y_gap - p_size, y_gap + p_size, |
| 942 |
|
952 | nBins, z_gap - p_size, z_gap + p_size); |
| 943 | 953 | ||
| 944 |
|
954 | // SiPM active surface |
| 945 |
|
955 | p_size = parameters.getActive()/2.0; |
| 946 |
|
956 | if (dbg) cout<<"SiPM active length "<<parameters.getActive()<<endl; |
| 947 | //p_size = 1.0/2.0; |
- | |
| - | 957 | ||
| 948 |
|
958 | plane_v[0].SetXYZ(x_offset+d+x_gap, y_gap + p_size, z_gap - p_size); |
| 949 |
|
959 | plane_v[1].SetXYZ(x_offset+d+x_gap, y_gap + p_size, z_gap + p_size); |
| 950 |
|
960 | plane_v[2].SetXYZ(x_offset+d+x_gap, y_gap - p_size, z_gap + p_size); |
| 951 |
|
961 | plane_v[3].SetXYZ(x_offset+d+x_gap, y_gap - p_size, z_gap - p_size); |
| 952 |
|
962 | active = new CPlane4(plane_v); |
| - | 963 | //active surface in case of bad coupling is circle d=a |
|
| - | 964 | TVector3 activePosition(center); |
|
| - | 965 | activePosition += TVector3(d + x_gap, 0, 0); |
|
| - | 966 | TVector3 normal(1,0,0); |
|
| - | 967 | grease = new CPlaneR(activePosition, normal, 1.0*p_size); |
|
| 953 | 968 | ||
| 954 |
|
969 | hactive = (TH2F*)gROOT->FindObject("hactive"); if(hactive) delete hactive; |
| 955 |
|
970 | //hactive = new TH2F("hactive", "Active area hits", nBins, y_gap - p_size, y_gap + p_size, nBins, z_gap - p_size, z_gap + p_size); |
| 956 |
|
971 | hactive = new TH2F("hactive", ";x [mm];y [mm]", nBins, y_gap - p_size + offsetY, y_gap + p_size + offsetY, nBins, z_gap - p_size + offsetZ, z_gap + p_size + offsetZ); |
| 957 | 972 | ||
| 958 |
|
973 | p_size = b/2.0; |
| 959 |
|
974 | //p_size = 2.5; |
| 960 |
|
975 | //p_size = M*0.6; |
| 961 |
|
976 | hlaser = (TH2F*)gROOT->FindObject("hlaser"); if(hlaser) delete hlaser; |
| 962 |
|
977 | hlaser = new TH2F("hlaser", ";x [mm]; y [mm]", nBins, -p_size+offsetY, p_size+offsetY, nBins, -p_size+offsetZ, p_size+offsetZ); |
| 963 | 978 | ||
| 964 |
|
979 | // collection surface in SiPM plane |
| 965 |
|
980 | p_size = 1.4*b/2.0; |
| 966 |
|
981 | plane_v[0].SetXYZ(x_offset+d+x_gap, y_gap + p_size, z_gap - p_size); |
| 967 |
|
982 | plane_v[1].SetXYZ(x_offset+d+x_gap, y_gap + p_size, z_gap + p_size); |
| 968 |
|
983 | plane_v[2].SetXYZ(x_offset+d+x_gap, y_gap - p_size, z_gap + p_size); |
| 969 |
|
984 | plane_v[3].SetXYZ(x_offset+d+x_gap, y_gap - p_size, z_gap - p_size); |
| 970 |
|
985 | detector = new CPlane4(plane_v); |
| 971 | 986 | ||
| 972 |
|
987 | hdetector = (TH2F*)gROOT->FindObject("hdetector"); if(hdetector) delete hdetector; |
| 973 |
|
988 | //hdetector = new TH2F("hdetector", "Hits detector plane", nBins, y_gap - p_size, y_gap + p_size, nBins, z_gap - p_size, z_gap + p_size); |
| 974 |
|
989 | hdetector = new TH2F("hdetector", ";x [mm]; y [mm]", nBins, y_gap-p_size + offsetY, y_gap + p_size + offsetY, nBins, z_gap - p_size + offsetZ, z_gap + p_size + offsetZ); |
| 975 | 990 | ||
| 976 |
|
991 | /* |
| 977 | window_circle = new CPlaneR(TVector3(x_offset+d+window_d, y_gap, z_gap), TVector3(-1.0, 0.0, 0.0), window_R); |
992 | window_circle = new CPlaneR(TVector3(x_offset+d+window_d, y_gap, z_gap), TVector3(-1.0, 0.0, 0.0), window_R); |
| 978 | |
993 | |
| 979 | p_size = M*a; |
994 | p_size = M*a; |
| 980 | plane_v[0].SetXYZ(x_offset+d+window_d, y_gap + p_size, z_gap - p_size); |
995 | plane_v[0].SetXYZ(x_offset+d+window_d, y_gap + p_size, z_gap - p_size); |
| 981 | plane_v[1].SetXYZ(x_offset+d+window_d, y_gap + p_size, z_gap + p_size); |
996 | plane_v[1].SetXYZ(x_offset+d+window_d, y_gap + p_size, z_gap + p_size); |
| 982 | plane_v[2].SetXYZ(x_offset+d+window_d, y_gap - p_size, z_gap + p_size); |
997 | plane_v[2].SetXYZ(x_offset+d+window_d, y_gap - p_size, z_gap + p_size); |
| 983 | plane_v[3].SetXYZ(x_offset+d+window_d, y_gap - p_size, z_gap - p_size); |
998 | plane_v[3].SetXYZ(x_offset+d+window_d, y_gap - p_size, z_gap - p_size); |
| 984 | window = new CSurface(SURF_REFRA, plane_v, n1, n2, reflectivity); window->FlipN(); |
999 | window = new CSurface(SURF_REFRA, plane_v, n1, n2, reflectivity); window->FlipN(); |
| 985 | |
1000 | |
| 986 | hwindow = (TH2F*)gROOT->FindObject("hwindow"); if(hwindow) delete hwindow; |
1001 | hwindow = (TH2F*)gROOT->FindObject("hwindow"); if(hwindow) delete hwindow; |
| 987 | hwindow = new TH2F("hwindow", "Hits Window", nch, y_gap - window_R, y_gap + window_R, nch, z_gap - window_R, z_gap + window_R); |
1002 | hwindow = new TH2F("hwindow", "Hits Window", nch, y_gap - window_R, y_gap + window_R, nch, z_gap - window_R, z_gap + window_R); |
| 988 | |
1003 | */ |
| 989 |
|
1004 | p_size = b/2.0; |
| 990 |
|
1005 | histoPlate = (TH2F*)gROOT->FindObject("histoPlate"); if(histoPlate) delete histoPlate; |
| 991 |
|
1006 | histoPlate = new TH2F("histoPlate", "Hits on glass plate", nBins, -p_size, +p_size, nBins, -p_size, +p_size); |
| 992 | } |
1007 | } |
| 993 | 1008 | ||
| 994 | //----------------------------------------------------------------------------- |
1009 | //----------------------------------------------------------------------------- |
| 995 | // vrne 1 ce je zadel aktvino povrsino |
1010 | // vrne 1 ce je zadel aktvino povrsino |
| 996 | // vrne <1 ce jo zgresi |
1011 | // vrne <1 ce jo zgresi |
| 997 | int CDetector::Propagate(CRay in, CRay *out, int draw) |
1012 | int CDetector::Propagate(CRay in, CRay *out, int draw) |
| 998 | - | ||
| 999 | // Sledi zarku skozi vodnik. Vrne: |
1013 | // Sledi zarku skozi vodnik. Vrne: |
| 1000 | // 0, ce zgresi vstopno ploskev MISSED |
1014 | // 0, ce zgresi vstopno ploskev MISSED |
| 1001 | // 1, ce zadane izstopno ploskev HIT |
1015 | // 1, ce zadane izstopno ploskev HIT |
| 1002 | // -1, ce se v vodniku ne odbije totalno REFRACTED |
1016 | // -1, ce se v vodniku ne odbije totalno REFRACTED |
| 1003 | // 2, enter the light guide, bin 2 of hfate EXIT |
1017 | // 2, enter the light guide, bin 2 of hfate EXIT |
| 1004 | // -2, ce se ne odbije zaradi koncnega R stranic - no total reflection REFRACTED |
1018 | // -2, ce se ne odbije zaradi koncnega R stranic - no total reflection REFRACTED |
| 1005 | // -3, ce se odbije nazaj in gre nazaj ven skozi sprednjo ploskev BACK_REFLECTED |
1019 | // -3, ce se odbije nazaj in gre nazaj ven skozi sprednjo ploskev BACK_REFLECTED |
| 1006 | // +4, ce se absorbira v materialu ABSORBED |
1020 | // +4, ce se absorbira v materialu ABSORBED |
| 1007 | { |
1021 | { |
| 1008 | if (dbg) printf("--- Detector::Propagate ---\n"); |
1022 | if (dbg) printf("--- Detector::Propagate ---\n"); |
| 1009 |
|
1023 | //CRay *ray0 = new CRay; ray0->Set(in.GetR(), in.GetN()); ray0->SetColor(col_in); |
| 1010 |
|
1024 | CRay *rayin = new CRay(in); |
| 1011 |
|
1025 | rayin->SetColor(col_in); |
| 1012 |
|
1026 | CRay *rayout = new CRay(in); |
| 1013 |
|
1027 | rayout->SetColor(col_in); |
| 1014 | - | ||
| 1015 | const int max_n_points = guide->GetMAXODB() + 2; |
- | |
| 1016 | TVector3 pointsPlate[max_n_points]; |
- | |
| 1017 | //TVector3 intersection; |
- | |
| 1018 | Fate fatePlate; |
- | |
| 1019 | int nPointsPlate; |
- | |
| 1020 | TPolyLine3D *line3d = new TPolyLine3D(2); |
- | |
| 1021 | line3d->SetLineWidth(1); |
- | |
| 1022 | line3d->SetLineColor(4); |
- | |
| 1023 | - | ||
| 1024 | // Draw the plate and propagate the ray through |
- | |
| 1025 | // check if the ray should be reflected?? |
- | |
| 1026 | - | ||
| 1027 | if(_plateOn) { |
- | |
| 1028 | - | ||
| 1029 | fatePlate = plate->propagateRay(*rayin, rayout, &nPointsPlate, pointsPlate); |
- | |
| 1030 | if(draw) rayin->DrawS(center.x()- _plateWidth, -10.0); |
- | |
| 1031 | if(draw) { |
- | |
| 1032 | if(fatePlate == missed) { |
- | |
| 1033 | rayout->SetColor(col_in); |
- | |
| 1034 | rayout->DrawS(center.x() - _plateWidth, -10.0); |
- | |
| 1035 | } |
- | |
| 1036 | else if(fatePlate == backreflected){ |
- | |
| 1037 | if (dbg) printf("Backreflected at plate!\n"); |
- | |
| 1038 | } |
- | |
| 1039 | else { |
- | |
| 1040 | int p_i; |
- | |
| 1041 | for(p_i = 0; p_i < nPointsPlate-1; p_i++) { |
- | |
| 1042 | line3d->SetPoint(0, pointsPlate[p_i].x(), pointsPlate[p_i].y(), pointsPlate[p_i].z()); |
- | |
| 1043 | line3d->SetPoint(1, pointsPlate[p_i+1].x(), pointsPlate[p_i+1].y(), pointsPlate[p_i+1].z()); |
- | |
| 1044 | line3d->DrawClone(); |
- | |
| 1045 | } |
- | |
| 1046 | rayout->DrawS(pointsPlate[p_i].x(), -0.1); |
- | |
| 1047 | if(fatePlate == noreflection) { // lost on plate side |
- | |
| 1048 | rayout->SetColor(col_out); |
- | |
| 1049 | rayout->DrawS(pointsPlate[p_i].x(), 10.0); |
- | |
| 1050 | } |
- | |
| 1051 | } |
- | |
| 1052 | } |
- | |
| 1053 | - | ||
| 1054 | if(! (fatePlate == hitExit or fatePlate == refracted) ) { |
- | |
| 1055 | guide->GetHFate()->Fill(rays); |
- | |
| 1056 | if (dbg)printf("CDetector::propagate Simulated ray missed the entry surface!\n"); |
- | |
| 1057 | if (fatePlate == backreflected) |
- | |
| 1058 | guide->GetHFate()->Fill(fatePlate); // reflected back |
- | |
| 1059 | else |
- | |
| 1060 | guide->GetHFate()->Fill(noreflection); //lost on plate side |
- | |
| 1061 | return fatePlate; |
- | |
| 1062 | } |
- | |
| 1063 | - | ||
| 1064 | //Ray hits light guide |
- | |
| 1065 | histoPlate->Fill(pointsPlate[0].y(), pointsPlate[0].z()); // entry point |
- | |
| 1066 | - | ||
| 1067 | } |
- | |
| 1068 | else { |
- | |
| 1069 | //rayout = rayin; |
- | |
| 1070 | if(draw) rayout->DrawS(center.x(), -10.0); |
- | |
| 1071 | } |
- | |
| 1072 | - | ||
| 1073 | // If the ray is not reflected in the plate |
- | |
| 1074 | // Draw the light guide and propagate the ray through |
- | |
| 1075 | - | ||
| 1076 | //const int max_n_points = guide->GetMAXODB() + 2; |
- | |
| 1077 | TVector3 points[max_n_points]; |
- | |
| 1078 | TVector3 presecisce; |
- | |
| 1079 | 1028 | ||
| 1080 |
|
1029 | const int max_n_points = guide->GetMAXODB() + 2; |
| 1081 |
|
1030 | TVector3 pointsPlate[max_n_points]; |
| 1082 |
|
1031 | //TVector3 intersection; |
| 1083 |
|
1032 | Fate fatePlate; |
| 1084 |
|
1033 | int nPointsPlate; |
| 1085 |
|
1034 | TPolyLine3D *line3d = new TPolyLine3D(2); |
| 1086 | 1035 | line3d->SetLineWidth(1); |
|
| 1087 |
|
1036 | line3d->SetLineColor(4); |
| 1088 | if (dbg) { |
1037 | |
| 1089 |
|
1038 | // Draw the plate and propagate the ray through |
| 1090 |
|
1039 | // check if the ray should be reflected?? |
| 1091 | 1040 | ||
| 1092 |
|
1041 | if(_plateOn) { |
| 1093 | int p_i; |
1042 | |
| 1094 |
|
1043 | fatePlate = plate->propagateRay(*rayin, rayout, &nPointsPlate, pointsPlate); |
| 1095 |
|
1044 | if(draw) rayin->DrawS(center.x()- _plateWidth, -10.0); |
| 1096 |
|
1045 | if(draw) { |
| 1097 |
|
1046 | if(fatePlate == missed) { |
| 1098 |
|
1047 | rayout->SetColor(col_in); |
| 1099 |
|
1048 | rayout->DrawS(center.x() - _plateWidth, -10.0); |
| 1100 |
|
1049 | } |
| 1101 |
|
1050 | else if(fatePlate == backreflected){ |
| 1102 |
|
1051 | if (dbg) printf("Backreflected at plate!\n"); |
| 1103 |
|
1052 | } |
| 1104 |
|
1053 | else { |
| 1105 |
|
1054 | int p_i; |
| 1106 |
|
1055 | for(p_i = 0; p_i < nPointsPlate-1; p_i++) { |
| 1107 |
|
1056 | line3d->SetPoint(0, pointsPlate[p_i].x(), pointsPlate[p_i].y(), pointsPlate[p_i].z()); |
| 1108 |
|
1057 | line3d->SetPoint(1, pointsPlate[p_i+1].x(), pointsPlate[p_i+1].y(), pointsPlate[p_i+1].z()); |
| 1109 |
|
1058 | line3d->DrawClone(); |
| 1110 |
|
1059 | } |
| 1111 |
|
1060 | rayout->DrawS(pointsPlate[p_i].x(), -0.1); |
| 1112 |
|
1061 | if(fatePlate == noreflection) { // lost on plate side |
| 1113 |
|
1062 | rayout->SetColor(col_out); |
| 1114 |
|
1063 | rayout->DrawS(pointsPlate[p_i].x(), 10.0); |
| 1115 |
|
1064 | } |
| 1116 |
|
1065 | } |
| 1117 |
|
1066 | } |
| 1118 | 1067 | ||
| 1119 | 1068 | if(! (fatePlate == hitExit or fatePlate == refracted) ) { |
|
| 1120 |
|
1069 | guide->GetHFate()->Fill(rays); |
| 1121 |
|
1070 | if (dbg)printf("CDetector::propagate Simulated ray missed the entry surface!\n"); |
| 1122 |
|
1071 | if (fatePlate == backreflected) |
| 1123 |
|
1072 | guide->GetHFate()->Fill(fatePlate); // reflected back |
| 1124 |
|
1073 | else |
| 1125 |
|
1074 | guide->GetHFate()->Fill(noreflection); //lost on plate side |
| 1126 |
|
1075 | return fatePlate; |
| 1127 |
|
1076 | } |
| 1128 | } |
1077 | |
| 1129 |
|
1078 | //Ray hits light guide |
| 1130 |
|
1079 | histoPlate->Fill(pointsPlate[0].y(), pointsPlate[0].z()); // entry point |
| 1131 | ray1 = ray0; |
1080 | |
| 1132 |
|
1081 | } |
| 1133 |
|
1082 | else { |
| 1134 |
|
1083 | //rayout = rayin; |
| 1135 |
|
1084 | if(draw) rayout->DrawS(center.x(), -10.0); |
| 1136 |
|
1085 | } |
| 1137 | } |
1086 | |
| 1138 | 1087 | // If the ray is not reflected in the plate |
|
| 1139 |
|
1088 | // Draw the light guide and propagate the ray through |
| 1140 | if(glass_on) { |
1089 | |
| 1141 |
|
1090 | //const int max_n_points = guide->GetMAXODB() + 2; |
| 1142 |
|
1091 | TVector3 points[max_n_points]; |
| 1143 |
|
1092 | TVector3 presecisce; |
| 1144 | if(fate_glass == REFRACTION) { |
1093 | |
| 1145 |
|
1094 | int n_points; |
| 1146 |
|
1095 | int fate_glass; |
| 1147 |
|
1096 | CRay *ray0 = new CRay(*rayout); |
| 1148 |
|
1097 | // delete rayout; -> creates dangling reference when tries to delete ray0! |
| 1149 |
|
1098 | //delete rayin; -> delete rayout! |
| 1150 |
|
1099 | CRay *ray1 = new CRay; |
| 1151 | //} |
1100 | |
| 1152 |
|
1101 | fate = guide->PropagateRay(*ray0, ray1, &n_points, points); |
| 1153 |
|
1102 | if (dbg) { |
| 1154 |
|
1103 | if (fate == backreflected) printf("DETECTOR::backreflected\n"); |
| 1155 |
|
1104 | } |
| 1156 | if(draw) ray1->DrawS(presecisce.x(), 10.0); |
1105 | |
| 1157 |
|
1106 | line3d->SetLineColor(col_lg); |
| 1158 |
|
1107 | int p_i; |
| - | 1108 | if(guide_on) { |
|
| - | 1109 | if(draw) { |
|
| - | 1110 | if(fate == missed) { |
|
| - | 1111 | if (dbg) printf("Detector: fate=missed\n"); |
|
| - | 1112 | TVector3 r = ray1->GetR(); |
|
| - | 1113 | TVector3 n = ray1->GetN(); |
|
| - | 1114 | ray1->Set(r,n); |
|
| - | 1115 | ray1->DrawS(center.x(), 10.0); |
|
| - | 1116 | } else { |
|
| - | 1117 | for(p_i = 0; p_i < n_points-1; p_i++) { |
|
| - | 1118 | line3d->SetPoint(0, points[p_i].x(), points[p_i].y(), points[p_i].z()); |
|
| - | 1119 | line3d->SetPoint(1, points[p_i+1].x(), points[p_i+1].y(), points[p_i+1].z()); |
|
| - | 1120 | line3d->DrawClone(); |
|
| - | 1121 | } |
|
| - | 1122 | if(fate != noreflection) { |
|
| - | 1123 | if (dbg) printf("Detector: fate != noreflection, fate = %d\n", (int)fate); |
|
| - | 1124 | if(glass_on) {/*if(fate == 1)*/ ray1->Draw(points[p_i].x(), center.x() + guide->getD() + glass_d);} |
|
| - | 1125 | else { |
|
| - | 1126 | ray1->SetColor(col_out); |
|
| - | 1127 | ray1->DrawS(points[p_i].x(), 10.0); |
|
| - | 1128 | } |
|
| - | 1129 | } |
|
| - | 1130 | } |
|
| - | 1131 | } |
|
| - | 1132 | ||
| - | 1133 | ||
| - | 1134 | if(! (fate == hitExit or fate == refracted) ) { |
|
| - | 1135 | if (dbg) printf("Detector: fate != hit, refracted\n"); |
|
| - | 1136 | *out = *ray1; |
|
| - | 1137 | delete ray0; |
|
| - | 1138 | delete ray1; |
|
| - | 1139 | delete rayout; |
|
| - | 1140 | delete rayin; |
|
| - | 1141 | return fate; |
|
| - | 1142 | } |
|
| - | 1143 | } else { |
|
| - | 1144 | if (dbg) printf("Detector: fate = hit or refracted"); |
|
| - | 1145 | ray1 = ray0; |
|
| - | 1146 | if(draw) { |
|
| - | 1147 | //double epoxy = parameters->getGlassD(); |
|
| - | 1148 | if(glass_on) ray1->Draw(center.x(), center.x() + glass_d); |
|
| - | 1149 | else ray1->DrawS(center.x(), 10.0); |
|
| - | 1150 | } |
|
| - | 1151 | } |
|
| - | 1152 | ||
| - | 1153 | fate = missed; // zgresil aktivno povrsino |
|
| - | 1154 | if(glass_on) { |
|
| - | 1155 | *ray0 = *ray1; |
|
| - | 1156 | ray1->SetColor(col_rgla); |
|
| - | 1157 | fate_glass = glass->PropagateRay(*ray0, ray1, &presecisce); |
|
| - | 1158 | if(fate_glass == REFRACTION) { |
|
| - | 1159 | hglass->Fill(presecisce.y(), presecisce.z()); |
|
| - | 1160 | if(draw) ray1->DrawS(presecisce.x(), 10.0); |
|
| - | 1161 | //if(active->TestIntersection(&presecisce, *ray1)) { |
|
| - | 1162 | //fate = hitExit; |
|
| - | 1163 | //hactive->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
|
| - | 1164 | //hlaser->Fill((in.GetR()).y() + offsetY, (in.GetR()).z() + offsetZ); |
|
| - | 1165 | //} |
|
| - | 1166 | //if(detector->TestIntersection(&presecisce, *ray1)) |
|
| - | 1167 | //hdetector->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
|
| - | 1168 | //} else if(fate_glass == REFLECTION) { |
|
| - | 1169 | else |
|
| - | 1170 | if(draw) ray1->DrawS(presecisce.x(), 10.0); |
|
| - | 1171 | } |
|
| - | 1172 | } |
|
| - | 1173 | ||
| - | 1174 | // Main test: ray and SiPM surface |
|
| - | 1175 | if(active->TestIntersection(&presecisce, *ray1)) { |
|
| - | 1176 | fate = hitExit; |
|
| - | 1177 | hactive->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
|
| - | 1178 | hlaser->Fill((in.GetR()).y() + offsetY, (in.GetR()).z() + offsetZ); |
|
| - | 1179 | } |
|
| - | 1180 | // If it is on the same plane as SiPM |
|
| - | 1181 | if(detector->TestIntersection(&presecisce, *ray1)) |
|
| - | 1182 | hdetector->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
|
| - | 1183 | //} |
|
| - | 1184 | //} else { |
|
| - | 1185 | //if(draw) ray1->Draw(presecisce.x(), center.x()+d+window_d); |
|
| - | 1186 | //} |
|
| 1159 | 1187 | ||
| 1160 | // Main test: ray and SiPM surface |
- | |
| 1161 | if(active->TestIntersection(&presecisce, *ray1)) { |
- | |
| 1162 | fate = hitExit; |
- | |
| 1163 | hactive->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
- | |
| 1164 | hlaser->Fill((in.GetR()).y() + offsetY, (in.GetR()).z() + offsetZ); |
- | |
| 1165 | } |
- | |
| 1166 | // If it is on the same plane as SiPM |
- | |
| 1167 | if(detector->TestIntersection(&presecisce, *ray1)) |
- | |
| 1168 | hdetector->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
- | |
| 1169 | //} |
- | |
| 1170 | //} else { |
- | |
| 1171 | //if(draw) ray1->Draw(presecisce.x(), center.x()+d+window_d); |
- | |
| 1172 | //} |
- | |
| 1173 | - | ||
| 1174 |
|
1188 | *out = *ray1; |
| 1175 |
|
1189 | delete ray0; |
| 1176 |
|
1190 | delete ray1; |
| 1177 |
|
1191 | delete rayout; |
| 1178 |
|
1192 | delete rayin; |
| 1179 |
|
1193 | return fate; |
| 1180 | } |
1194 | } |
| 1181 | //----------------------------------------------------------------------------- |
1195 | //----------------------------------------------------------------------------- |
| 1182 | void CDetector::Draw(int width) |
1196 | void CDetector::Draw(int width) |
| 1183 | { |
1197 | { |
| 1184 |
|
1198 | if(guide_on) { |
| 1185 |
|
1199 | if( TMath::Abs(guide->getN1()-guide->getN2()) < MARGIN ) { |
| 1186 |
|
1200 | if(_plateOn) plate->drawSkel(col_LG, width); |
| 1187 |
|
1201 | guide->DrawSkel(col_LG, width); |
| 1188 |
|
1202 | } |
| 1189 |
|
1203 | else { |
| 1190 |
|
1204 | if(_plateOn) plate->draw(4, width); |
| 1191 |
|
1205 | guide->Draw(col_LG, width); |
| 1192 |
|
1206 | } |
| 1193 |
|
1207 | } |
| 1194 | 1208 | ||
| 1195 |
|
1209 | if(glass_on) glass_circle->Draw(col_glass, width); |
| 1196 |
|
1210 | //window_circle->Draw(col_glass, width); |
| 1197 |
|
1211 | active->Draw(col_active, width); |
| 1198 | } |
1212 | } |
| 1199 | //================================================================================= |
1213 | //================================================================================= |
| 1200 | 1214 | ||
| 1201 | Plate::Plate(DetectorParameters& parameters) |
1215 | Plate::Plate(DetectorParameters& parameters) |
| 1202 | { |
1216 | { |
| 1203 | TVector3 center = CENTER; |
1217 | TVector3 center = CENTER; |
| 1204 | const double b = parameters.getB(); |
1218 | const double b = parameters.getB(); |
| 1205 | const double n1 = parameters.getN1(); |
1219 | const double n1 = parameters.getN1(); |
| 1206 |
|
1220 | const double n2 = parameters.getN2(); |
| 1207 |
|
1221 | const double t = b/2.; |
| 1208 |
|
1222 | const double plateWidth = parameters.getPlateWidth(); |
| 1209 |
|
1223 | center.SetX( CENTER.X() - plateWidth ); |
| 1210 | 1224 | ||
| 1211 |
|
1225 | plate_edge[0].SetXYZ(0.0, t,-t); |
| 1212 |
|
1226 | plate_edge[1].SetXYZ(0.0, t, t); |
| 1213 |
|
1227 | plate_edge[2].SetXYZ(0.0,-t, t); |
| 1214 |
|
1228 | plate_edge[3].SetXYZ(0.0,-t,-t); |
| 1215 |
|
1229 | plate_edge[4].SetXYZ(plateWidth, t,-t); |
| 1216 |
|
1230 | plate_edge[5].SetXYZ(plateWidth, t, t); |
| 1217 |
|
1231 | plate_edge[6].SetXYZ(plateWidth,-t, t); |
| 1218 |
|
1232 | plate_edge[7].SetXYZ(plateWidth,-t,-t); |
| 1219 | 1233 | ||
| 1220 |
|
1234 | for(int i = 0; i<8; i++) plate_edge[i] += center; |
| 1221 | 1235 | ||
| 1222 |
|
1236 | sides[0] = new CSurface(SURF_REFRA, plate_edge, n1, n2, c_reflectivity); |
| 1223 |
|
1237 | sides[0]->FlipN(); |
| 1224 | 1238 | ||
| 1225 |
|
1239 | sides[1] = new CSurface(SURF_REFRA, plate_edge[3], plate_edge[2], plate_edge[6], plate_edge[7], n2, n2, c_reflectivity); |
| 1226 |
|
1240 | sides[2] = new CSurface(SURF_REFRA, plate_edge[2], plate_edge[1], plate_edge[5], plate_edge[6], n2, n2, c_reflectivity); |
| 1227 |
|
1241 | sides[3] = new CSurface(SURF_REFRA, plate_edge[1], plate_edge[0], plate_edge[4], plate_edge[5], n2, n2, c_reflectivity); |
| 1228 |
|
1242 | sides[4] = new CSurface(SURF_REFRA, plate_edge[0], plate_edge[3], plate_edge[7], plate_edge[4], n2, n2, c_reflectivity); |
| 1229 | 1243 | ||
| 1230 |
|
1244 | sides[5] = new CSurface(SURF_REFRA, &plate_edge[4], n2, n2, c_reflectivity); |
| 1231 |
|
1245 | sides[5]->FlipN(); |
| 1232 | 1246 | ||
| 1233 |
|
1247 | for(int i=0; i<6; i++) sides[i]->SetFresnel(1); |
| 1234 | } |
1248 | } |
| 1235 | 1249 | ||
| 1236 | void Plate::draw(int color, int width) |
1250 | void Plate::draw(int color, int width) |
| 1237 | { |
1251 | { |
| 1238 |
|
1252 | for(int i = 0; i<6; i++) sides[i]->Draw(color, width); |
| 1239 | } |
1253 | } |
| 1240 | 1254 | ||
| 1241 | void Plate::drawSkel(int color, int width) |
1255 | void Plate::drawSkel(int color, int width) |
| 1242 | { |
1256 | { |
| 1243 |
|
1257 | TPolyLine3D line3d(2); |
| 1244 |
|
1258 | line3d.SetLineWidth(width); |
| 1245 |
|
1259 | line3d.SetLineColor(color); |
| 1246 | 1260 | ||
| 1247 |
|
1261 | for(int i=0; i<4; i++) { |
| 1248 |
|
1262 | line3d.SetPoint(0, plate_edge[i+0].x(), plate_edge[i+0].y(), plate_edge[i+0].z()); |
| 1249 |
|
1263 | line3d.SetPoint(1, plate_edge[i+4].x(), plate_edge[i+4].y(), plate_edge[i+4].z()); |
| 1250 |
|
1264 | line3d.DrawClone(); |
| 1251 |
|
1265 | } |
| 1252 | } |
1266 | } |
| 1253 | 1267 | ||
| 1254 | Fate Plate::propagateRay(CRay in, CRay *out, int *n_points, TVector3 *points) |
1268 | Fate Plate::propagateRay(CRay in, CRay *out, int *n_points, TVector3 *points) |
| 1255 | { |
1269 | { |
| 1256 | CRay ray0; |
1270 | CRay ray0; |
| 1257 | CRay ray1; |
1271 | CRay ray1; |
| 1258 | TVector3 vec0, vec1; |
1272 | TVector3 vec0, vec1; |
| 1259 | Fate fate = enter; |
1273 | Fate fate = enter; |
| 1260 | int inters_i = 0; |
1274 | int inters_i = 0; |
| 1261 | 1275 | ||
| 1262 |
|
1276 | ray0 = in; |
| 1263 |
|
1277 | int n_odb = 0; |
| 1264 |
|
1278 | int last_hit = 0; |
| 1265 |
|
1279 | int propagation = 0; |
| 1266 | 1280 | ||
| 1267 |
|
1281 | int result = sides[0]->PropagateRay(ray0, &ray1, &vec1); |
| 1268 |
|
1282 | if( !result ) { |
| 1269 |
|
1283 | // ce -NI- presecisca z vstopno |
| 1270 |
|
1284 | fate = missed; |
| 1271 |
|
1285 | } else if(result == REFLECTION) { |
| 1272 |
|
1286 | if (dbg) printf("PLATE: reflected\n"); |
| 1273 |
|
1287 | fate = backreflected; |
| 1274 |
|
1288 | } else { |
| 1275 |
|
1289 | points[0] = ray1.GetR(); |
| 1276 |
|
1290 | //hfate->Fill(enter); |
| 1277 |
|
1291 | //hin->Fill(vec1.y(), vec1.z()); |
| 1278 |
|
1292 | while (n_odb++ < MAX_REFLECTIONS) { |
| 1279 |
|
1293 | ray0 = ray1; |
| 1280 |
|
1294 | vec0 = vec1; |
| 1281 |
|
1295 | propagation = 11; |
| 1282 |
|
1296 | for(inters_i=0; inters_i<6; inters_i++) { |
| 1283 |
|
1297 | if( inters_i != last_hit) { |
| 1284 |
|
1298 | if( sides[inters_i]->TestIntersection(&vec1, ray1) ) break; |
| 1285 |
|
1299 | } |
| 1286 |
|
1300 | } |
| 1287 |
|
1301 | points[n_odb] = vec1; |
| 1288 |
|
1302 | if(inters_i == 0) { |
| 1289 |
|
1303 | fate = backreflected; |
| 1290 |
|
1304 | break;} // backreflection |
| 1291 | 1305 | ||
| 1292 |
|
1306 | propagation = sides[inters_i]->PropagateRay(ray0, &ray1, &vec1); |
| 1293 |
|
1307 | if(inters_i == 5) { // successfull exit |
| 1294 |
|
1308 | fate = hitExit; |
| 1295 |
|
1309 | //hout->Fill(vec1.y(), vec1.z()); |
| 1296 |
|
1310 | //hnodb_exit->Fill(n_odb-1); |
| 1297 |
|
1311 | n_odb++; |
| 1298 |
|
1312 | points[n_odb] = vec1; |
| 1299 |
|
1313 | ray0 = ray1; |
| 1300 |
|
1314 | break; |
| 1301 |
|
1315 | } |
| 1302 |
|
1316 | if(propagation == 1) { |
| 1303 |
|
1317 | fate = noreflection; //at side |
| 1304 |
|
1318 | n_odb++; |
| 1305 |
|
1319 | points[n_odb] = vec1; |
| 1306 |
|
1320 | ray0 = ray1; |
| 1307 |
|
1321 | break;} // no total reflection when should be |
| 1308 | 1322 | ||
| 1309 |
|
1323 | if(propagation == -2) { |
| 1310 |
|
1324 | fate = noreflection; |
| 1311 |
|
1325 | break; |
| 1312 |
|
1326 | } // absorption due to finite reflectivity |
| 1313 | 1327 | ||
| 1314 |
|
1328 | last_hit = inters_i; |
| 1315 |
|
1329 | } |
| 1316 |
|
1330 | } |
| 1317 | 1331 | ||
| 1318 |
|
1332 | *n_points = n_odb+1; |
| 1319 |
|
1333 | *out = ray0; |
| 1320 |
|
1334 | return fate; |
| 1321 | }; |
1335 | }; |
| 1322 | //=============================================================================================================================== <<<<<<<< |
1336 | //=============================================================================================================================== <<<<<<<< |
| 1323 | 1337 | ||
| 1324 | 1338 | ||