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