Rev 70 | Rev 72 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 70 | Rev 71 | ||
|---|---|---|---|
| Line 383... | Line 383... | ||
| 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 |
| 385 | int CSurface::PropagateRay(CRay in, CRay *out, TVector3 *intersection) |
385 | int CSurface::PropagateRay(CRay in, CRay *out, TVector3 *intersection) |
| 386 | { |
386 | { |
| 387 | if (dbg) printf("--- CSurface::PropagateRay ---\n"); |
387 | if (dbg) printf("--- CSurface::PropagateRay ---\n"); |
| 388 | double |
388 | double cosTi; // incident ray angle |
| - | 389 | double cosTt; // transmited ray angle |
|
| 389 | TVector3 intersect, transmit; |
390 | TVector3 intersect, transmit; |
| 390 | 391 | ||
| 391 | if( !(GetIntersection(&intersect, in) == 1) ) |
392 | if( !(GetIntersection(&intersect, in) == 1) ) |
| 392 | return 0; |
393 | return 0; |
| 393 | 394 | ||
| Line 434... | Line 435... | ||
| 434 | a_te = cosAf; |
435 | a_te = cosAf; |
| 435 | a_tm = TMath::Sqrt(1 - cosAf*cosAf); |
436 | a_tm = TMath::Sqrt(1 - cosAf*cosAf); |
| 436 | if(dbg) printf(" a_te = %lf, a_tm = %lf\n", a_te, a_tm); |
437 | if(dbg) printf(" a_te = %lf, a_tm = %lf\n", a_te, a_tm); |
| 437 | } |
438 | } |
| 438 | // ---------------------------------------------------------------------------- |
439 | // ---------------------------------------------------------------------------- |
| - | 440 | ||
| - | 441 | // reflection probability |
|
| - | 442 | double p_ref = rand.Uniform(0.0, 1.0); |
|
| 439 | 443 | ||
| 440 | if(type == SURF_TOTAL) type = SURF_REFRA; |
444 | if(type == SURF_TOTAL) type = SURF_REFRA; |
| 441 | switch(type){ |
445 | switch(type){ |
| 442 | // ---------------------------------------------------------------------------- |
446 | // ---------------------------------------------------------------------------- |
| 443 | // --------------- refraction from n1 to n2 ----------------------------------- |
447 | // --------------- refraction from n1 to n2 ----------------------------------- |
| Line 456... | Line 460... | ||
| 456 | cosTtotal = 0.0; |
460 | cosTtotal = 0.0; |
| 457 | 461 | ||
| 458 | if(dbg) printf(" cosTtotal = %lf (Ttotal = %lf)\n", cosTtotal, TMath::ACos(cosTtotal)*DEGREE); |
462 | if(dbg) printf(" cosTtotal = %lf (Ttotal = %lf)\n", cosTtotal, TMath::ACos(cosTtotal)*DEGREE); |
| 459 | // reflection dependance on polarization missing |
463 | // reflection dependance on polarization missing |
| 460 | // reflection hardcoded to 0.96 |
464 | // reflection hardcoded to 0.96 |
| 461 | p_ref = rand.Uniform(0.0, 1.0); |
- | |
| 462 | if (dbg) printf(" reflection probability = %f\n", p_ref); |
465 | if (dbg) printf(" reflection probability = %f\n", p_ref); |
| 463 | 466 | ||
| 464 | // If n1>n2 and theta>thetaCritical, total reflection |
467 | // If n1>n2 and theta>thetaCritical, total reflection |
| 465 | if( |
468 | if(cosTi < cosTtotal) { |
| 466 | if(dbg) printf(" TOTAL\n"); |
469 | if(dbg) printf(" TOTAL\n"); |
| 467 | transmit = in.GetN() + sign_n*2*cosTi*n; |
470 | transmit = in.GetN() + sign_n*2*cosTi*n; |
| 468 | 471 | ||
| 469 | if(dbg) { |
472 | if(dbg) { |
| 470 | cosTN = TMath::Abs(transmit.Unit() * n); |
473 | cosTN = TMath::Abs(transmit.Unit() * n); |
| Line 482... | Line 485... | ||
| 482 | cosTt = TMath::Sqrt(1 - TMath::Power(N1_N2(sign_n), 2)*(1 - TMath::Power(cosTi, 2))); |
485 | 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); |
486 | if(dbg) printf(" cosTt = %lf (Tt = %lf) \n", cosTt, TMath::ACos(cosTt)*DEGREE); |
| 484 | 487 | ||
| 485 | transmit = N1_N2(sign_n)*in.GetN() + sign_n*(N1_N2(sign_n)*cosTi - cosTt)*n; |
488 | 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());} |
489 | if(dbg) {printf(" transmit.Unit() = "); printv(transmit.Unit());} |
| 487 | - | ||
| 488 | if(dbg) { |
490 | if(dbg) { |
| 489 | cosTN = transmit.Unit() * n; |
491 | 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); |
492 | printf(" cosTN = %lf (TN = %lf) (Abs(TN) = %lf)\n", cosTN, TMath::ACos(cosTN)*DEGREE, TMath::ACos(TMath::Abs(cosTN))*DEGREE); |
| - | 493 | } |
|
| 491 |
|
494 | |
| 492 | //if(cosTi<=cosTtotal) cosTt = TMath::Sqrt(1 - TMath::Power(N1_N2(sign_n), 2)*(1 - TMath::Power(cosTi, 2))); |
495 | //if(cosTi<=cosTtotal) cosTt = TMath::Sqrt(1 - TMath::Power(N1_N2(sign_n), 2)*(1 - TMath::Power(cosTi, 2))); |
| 493 | //if(fresnel) { |
496 | //if(fresnel) { |
| 494 |
|
497 | r_te = (n1*cosTi - n2*cosTt)/(n1*cosTi + n2*cosTt); // transverse |
| 495 |
|
498 | 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 | 499 | ||
| - | 500 | if(dbg) printf(" r_te = %lf, r_tm = %lf\n", r_te, r_tm); |
|
| - | 501 | ||
| 499 |
|
502 | // transmited polarization |
| 500 |
|
503 | v_tm_t = -v_te.Cross(transmit); |
| 501 |
|
504 | v_tm_t = v_tm_t.Unit(); |
| 502 |
|
505 | pol_t = a_te * (1.0 - TMath::Abs(r_te)) * v_te + a_tm * (1.0 - TMath::Abs(r_tm)) * v_tm_t; |
| 503 | 506 | ||
| 504 |
|
507 | if(dbg) { |
| 505 | printf(" v_tm_t = "); printv(v_tm_t); |
508 | printf(" v_tm_t = "); printv(v_tm_t); |
| 506 | printf(" pol_t = "); printv(pol_t); |
509 | printf(" pol_t = "); printv(pol_t); |
| 507 |
|
510 | } |
| 508 | 511 | ||
| 509 |
|
512 | // Fresnel coefficients |
| 510 |
|
513 | R_te = TMath::Power(r_te, 2); |
| 511 |
|
514 | R_tm = TMath::Power(r_tm, 2); |
| 512 |
|
515 | R_f = a_te*a_te*R_te + a_tm*a_tm*R_tm; |
| 513 | 516 | ||
| 514 |
|
517 | if (dbg) printf(" R_te = %lf, R_tm = %lf, R_f = %lf\n", R_te, R_tm, R_f); |
| 515 |
|
518 | } |
| 516 | 519 | ||
| 517 |
|
520 | if(p_ref >= R_f) { // se lomi |
| 518 |
|
521 | if (dbg) printf(" SURFACE REFRACTED. Return.\n"); |
| 519 | out->Set(intersect, transmit); |
522 | out->Set(intersect, transmit); |
| 520 | out->SetPolarization(pol_t); |
523 | out->SetPolarization(pol_t); |
| 521 | return REFRACTION; |
524 | return REFRACTION; |
| 522 | } else { // se odbije |
525 | } else { // se odbije |
| 523 | if (dbg) printf(" SURFACE REFLECTED. p_ref=%f, R_f=%f\n", p_ref, R_f); |
526 | if (dbg) printf(" SURFACE REFLECTED. p_ref=%f, R_f=%f\n", p_ref, R_f); |
| Line 529... | Line 532... | ||
| 529 | } |
532 | } |
| 530 | 533 | ||
| 531 | //} |
534 | //} |
| 532 | break; |
535 | break; |
| 533 | 536 | ||
| 534 | // ---------------------------------------------------------------------------- |
537 | // ---------------------------------------------------------------------------- |
| 535 | // --------------- reflection at "reflection" probability --------------------- |
538 | // --------------- reflection at "reflection" probability --------------------- |
| 536 | // ---------------------------------------------------------------------------- |
539 | // ---------------------------------------------------------------------------- |
| 537 | case SURF_REFLE: |
540 | case SURF_REFLE: |
| 538 | p_ref = rand.Uniform(0.0, 1.0); |
541 | p_ref = rand.Uniform(0.0, 1.0); |
| 539 | if(p_ref < reflection) { // se odbije |
542 | if(p_ref < reflection) { // se odbije |
| 540 | cosTi = in.GetN() * n; |
543 | cosTi = in.GetN() * n; |
| 541 | transmit = in.GetN() - 2*cosTi*n; |
544 | transmit = in.GetN() - 2*cosTi*n; |
| 542 | out->Set(intersect, transmit); |
545 | out->Set(intersect, transmit); |
| 543 | return REFLECTION; //sdhfvjhsdbfjhsdbcvjhsb |
546 | return REFLECTION; //sdhfvjhsdbfjhsdbcvjhsb |
| 544 | } else { // se ne odbije |
547 | } else { // se ne odbije |
| 545 | transmit = in.GetN(); |
548 | transmit = in.GetN(); |
| 546 | out->Set(intersect, transmit); |
549 | out->Set(intersect, transmit); |
| 547 | return ABSORBED; |
550 | return ABSORBED; |
| 548 | } |
551 | } |
| 549 | break; |
552 | break; |
| Line 712... | Line 715... | ||
| 712 | if(inters_i == 0) { |
715 | if(inters_i == 0) { |
| 713 | fate = backreflected; |
716 | fate = backreflected; |
| 714 | //hfate->Fill(backreflected); |
717 | //hfate->Fill(backreflected); |
| 715 | break; |
718 | break; |
| 716 | } // backreflection |
719 | } // backreflection |
| 717 | 720 | ||
| 718 | // the passage is possible, test propagation |
721 | // the passage is possible, test propagation |
| 719 | propagation = s_side[inters_i]->PropagateRay(ray0, &ray1, &vec1); |
722 | propagation = s_side[inters_i]->PropagateRay(ray0, &ray1, &vec1); |
| 720 | 723 | ||
| 721 | if (dbg) printf(" GUIDE: surface = %d, propagation = %d\n", inters_i, propagation); |
724 | if (dbg) printf(" GUIDE: surface = %d, propagation = %d\n", inters_i, propagation); |
| 722 | 725 | ||
| Line 917... | Line 920... | ||
| 917 | double y_gap = parameters.getGap().Y(); |
920 | double y_gap = parameters.getGap().Y(); |
| 918 | double z_gap = parameters.getGap().Z(); |
921 | double z_gap = parameters.getGap().Z(); |
| 919 | 922 | ||
| 920 | // additional glass between at top of SiPM |
923 | // additional glass between at top of SiPM |
| 921 | // example: epoxy n=1.60 |
924 | // example: epoxy n=1.60 |
| 922 | double n4 = 1. |
925 | double n4 = 1.57; |
| 923 | TVector3 plane_v[4]; |
926 | TVector3 plane_v[4]; |
| 924 | int nBins = nch + 1; |
927 | int nBins = nch + 1; |
| 925 | double p_size = b/2.0; |
928 | double p_size = b/2.0; |
| 926 | plane_v[0].SetXYZ(x_offset+d+glass_d, y_gap + p_size, z_gap - p_size); |
929 | 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); |
930 | plane_v[1].SetXYZ(x_offset+d+glass_d, y_gap + p_size, z_gap + p_size); |
| Line 1125... | Line 1128... | ||
| 1125 | } |
1128 | } |
| 1126 | } else { |
1129 | } else { |
| 1127 | if (dbg) printf("Detector: fate = hit or refracted"); |
1130 | if (dbg) printf("Detector: fate = hit or refracted"); |
| 1128 | ray1 = ray0; |
1131 | ray1 = ray0; |
| 1129 | if(draw) { |
1132 | if(draw) { |
| - | 1133 | //double epoxy = parameters->getGlassD(); |
|
| 1130 | if(glass_on) ray1->Draw(center.x(), center.x() |
1134 | if(glass_on) ray1->Draw(center.x(), center.x() + glass_d); |
| 1131 | else ray1->DrawS(center.x(), 10.0); |
1135 | else ray1->DrawS(center.x(), 10.0); |
| 1132 | } |
1136 | } |
| 1133 | } |
1137 | } |
| 1134 | 1138 | ||
| 1135 | fate = missed; // zgresil aktivno povrsino |
1139 | fate = missed; // zgresil aktivno povrsino |
| 1136 | if(glass_on) { |
1140 | if(glass_on) { |
| - | 1141 | *ray0 = *ray1; |
|
| 1137 |
|
1142 | ray1->SetColor(col_rgla); |
| 1138 | fate_glass = glass->PropagateRay(*ray0, ray1, &presecisce); |
1143 | fate_glass = glass->PropagateRay(*ray0, ray1, &presecisce); |
| 1139 | if(fate_glass == |
1144 | if(fate_glass == REFRACTION) { |
| 1140 | hglass->Fill(presecisce.y(), presecisce.z()); |
1145 | hglass->Fill(presecisce.y(), presecisce.z()); |
| 1141 | if(draw) ray1->DrawS(presecisce.x(), 10.0); |
1146 | if(draw) ray1->DrawS(presecisce.x(), 10.0); |
| 1142 |
|
1147 | //if(active->TestIntersection(&presecisce, *ray1)) { |
| 1143 | fate |
1148 | //fate = hitExit; |
| 1144 | hactive |
1149 | //hactive->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
| 1145 | hlaser |
1150 | //hlaser->Fill((in.GetR()).y() + offsetY, (in.GetR()).z() + offsetZ); |
| 1146 |
|
1151 | //} |
| 1147 |
|
1152 | //if(detector->TestIntersection(&presecisce, *ray1)) |
| 1148 | hdetector |
1153 | //hdetector->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
| 1149 |
|
1154 | //} else if(fate_glass == REFLECTION) { |
| - | 1155 | else |
|
| 1150 | if(draw) ray1->DrawS(presecisce.x(), 10.0); |
1156 | if(draw) ray1->DrawS(presecisce.x(), 10.0); |
| 1151 | } |
1157 | } |
| 1152 |
|
1158 | } |
| - | 1159 | ||
| 1153 | // Main test: ray and SiPM surface |
1160 | // Main test: ray and SiPM surface |
| 1154 | if(active->TestIntersection(&presecisce, *ray1)) { |
1161 | if(active->TestIntersection(&presecisce, *ray1)) { |
| 1155 | fate = hitExit; |
1162 | fate = hitExit; |
| 1156 | hactive->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
1163 | hactive->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
| 1157 | hlaser->Fill((in.GetR()).y() + offsetY, (in.GetR()).z() + offsetZ); |
1164 | hlaser->Fill((in.GetR()).y() + offsetY, (in.GetR()).z() + offsetZ); |
| 1158 | } |
1165 | } |
| 1159 | // If it is on the same plane as SiPM |
1166 | // If it is on the same plane as SiPM |
| 1160 | if(detector->TestIntersection(&presecisce, *ray1)) |
1167 | if(detector->TestIntersection(&presecisce, *ray1)) |
| 1161 | hdetector->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
1168 | hdetector->Fill(offsetY + presecisce.y(), offsetZ + presecisce.z()); |
| 1162 |
|
1169 | //} |
| 1163 | //} else { |
1170 | //} else { |
| 1164 | //if(draw) ray1->Draw(presecisce.x(), center.x()+d+window_d); |
1171 | //if(draw) ray1->Draw(presecisce.x(), center.x()+d+window_d); |
| 1165 | //} |
1172 | //} |
| 1166 | 1173 | ||
| 1167 | *out = *ray1; |
1174 | *out = *ray1; |