9#include <top/reconstruction_cpp/PhotonState.h>
10#include <top/reconstruction_cpp/func.h>
11#include <framework/logging/Logger.h>
27 m_x(position.X()),
m_y(position.Y()),
m_z(position.Z()),
28 m_kx(direction.X()),
m_ky(direction.Y()),
m_kz(direction.Z()),
34 m_x(position.X()),
m_y(position.Y()),
m_z(position.Z()),
40 double thc,
double fic):
41 m_x(position.X()),
m_y(position.Y()),
m_z(position.Z()),
44 ROOT::Math::XYZVector dir(cos(fic) * sin(thc), sin(fic) * sin(thc), cos(thc));
53 if (std::abs(
m_x) > bar.
A / 2)
return false;
54 if (std::abs(
m_y) > bar.
B / 2)
return false;
62 if (std::abs(
m_x) > bar.
A / 2)
return false;
63 if (std::abs(
m_y) > bar.
B / 2)
return false;
64 if (
m_z < bar.
zL)
return false;
65 double Rsq = pow(
m_x - mirror.
xc, 2) + pow(
m_y - mirror.
yc, 2) + pow(
m_z - mirror.
zc, 2);
66 if (Rsq > pow(mirror.
R, 2))
return false;
73 if (std::abs(
m_x) > prism.
A / 2)
return false;
77 if (
m_y < y)
return false;
87 const double A = bar.
A;
88 const double B = bar.
B;
102 if (z ==
m_z)
return;
107 if (len < 0 or len >
s_maxLen)
return;
135 if (
m_kz < 0)
return;
138 if (
m_z < mirror.
zb) {
151 double z =
m_z - mirror.
zc;
153 double rr = x * x + z * z;
154 double D = rdir * rdir + (mirror.
R * mirror.
R - rr) * ss;
157 len = (D - rdir) / ss;
158 if (len < 0 or len >
s_maxLen)
return;
161 if (nxx == nx)
break;
164 if (std::abs(xmm - xm) < 0.001)
break;
165 B2DEBUG(20,
"TOP::PhotonState::propagateSemiLinear: not converging");
179 double normX = (
m_x - mirror.
xc) / mirror.
R;
180 double normZ = (
m_z - mirror.
zc) / mirror.
R;
181 double s = 2 * (
m_kx * normX +
m_kz * normZ);
201 if (
m_kz < 0)
return;
204 if (
m_z < mirror.
zb) {
219 double z =
m_z - mirror.
zc;
221 double rr = x * x + y * y + z * z;
222 double D = rdir * rdir + (mirror.
R * mirror.
R - rr);
226 if (len < 0 or len >
s_maxLen)
return;
231 if (nxx == nx and nyy == ny)
break;
234 if (std::abs(xmm - xm) < 0.001 and std::abs(ymm - ym) < 0.001)
break;
235 B2DEBUG(20,
"TOP::PhotonState::propagateExact: not converging");
248 double normX = (
m_x - mirror.
xc) / mirror.
R;
249 double normY = (
m_y - mirror.
yc) / mirror.
R;
250 double normZ = (
m_z - mirror.
zc) / mirror.
R;
251 double s = 2 * (
m_kx * normX +
m_ky * normY +
m_kz * normZ);
279 const double prismA = prism.
A;
280 const double yUp = prism.
yUp;
281 const double yDown = prism.
yDown;
282 const double zR = prism.
zR;
283 const double zFlat = prism.
zFlat;
284 const double zDet = prism.
zD;
289 m_y0 = (yUp + yDown) / 2;
293 if (z >= zR or std::abs(ky / kz) < std::abs(prism.
slope))
return;
294 if (std::abs(y + ky / kz * (zR - z)) < prism.
B / 2)
return;
296 const double ky_in = ky;
297 const double kz_in = kz;
309 y = std::min(y, yUp);
314 const int k0 = prism.
k0;
318 while (k < numWindows) {
319 const auto& win = windows[k];
320 double s = ky * win.sz - kz * win.sy;
322 double len = ((win.y0 - y) * win.sz - (win.z0 - z) * win.sy) / s;
325 double yu = yD - win.y0;
326 double zu = zD - win.z0;
327 double yw = yu * win.sy + zu * win.sz;
328 if (yw >= yDown and yw <= yUp) {
329 if (len < 0 or len >
s_maxLen)
return;
330 double kyNew = ky * win.sy + kz * win.sz;
331 double kzNew = kz * win.sy - ky * win.sz;
338 kz = ny % 2 == 0 ? kzNew : -kzNew;
343 cosy = std::max(cosy, std::abs(ky_in * win.nsy[ii] + kz_in * win.nsz[ii]));
350 B2DEBUG(20,
"TOP::PhotonState::propagate: unfolded prism window not found"
358 double len = (zDet - z) / kz;
359 if (len < 0 or len >
s_maxLen)
return;
double m_y0
origin in y for unfolding
EType m_type
quartz segment type at last propagation step
double m_cosy
maximal cosine of impact angle to surface in y
int m_nx
signed number of reflections in x at last propagation step
double m_zD
unfolded prism detection position in z
void propagate(const RaytracerBase::BarSegment &bar)
Propagate photon to the exit of bar segment.
static double s_maxLen
maximal allowed propagation length
PhotonState()
Default constructor.
double m_ky
direction in y
double m_A
width of the quartz segment (dimension in x) for unfolding
double m_cosx
maximal cosine of impact angle to surface in x
int m_ny
signed number of reflections in y at last propagation step
double m_kx
direction in x
double m_yD
unfolded prism detection position in y
double m_B
thickness of the quartz segment (dimension in y) for unfolding
bool m_status
propagation status
void propagateSemiLinear(const RaytracerBase::BarSegment &bar, const RaytracerBase::Mirror &mirror)
Propagate photon to the mirror and reflect it using semi-linear mirror optics.
@ c_BarSegment
bar segment
@ c_MirrorSegment
mirror segment
double m_propLen
propagation length since initial position
void propagateExact(const RaytracerBase::BarSegment &bar, const RaytracerBase::Mirror &mirror)
Propagate photon to the mirror and reflect it using exact mirror optics.
bool isInside(const RaytracerBase::BarSegment &bar) const
Checks if photon is inside the bar segment (including surface).
double m_kz
direction in z
Class to store variables with their name which were sent to the logging service.
double sqrt(double a)
sqrt for double
double unfold(double x, int nx, double A)
unfold a coordinate.
void rotateUz(ROOT::Math::XYZVector &vec, const ROOT::Math::XYZVector &z_Axis)
Replacement for a function TVector3::RotateUz which is not implemented in GenVector classes.
void fold(double xu, double A, double &x, double &kx, int &nx)
fold a coordinate (inverse of unfold).
long lround(double x)
Rounds to the nearest integer, halfway cases away from zero.
Abstract base class for different kinds of events.
bar segment data in module local frame.
double A
width (dimension in x)
double B
thickness (dimension in y)
spherical mirror data in module local frame.
double yc
center of curvature in y
double xc
center of curvature in x
double zb
minimum of mirror surface in z
double zc
center of curvature in z
prism data in module local frame.
double A
width (dimension in x)
std::vector< TOPGeoPrism::UnfoldedWindow > unfoldedWindows
unfolded prism exit windows
double yDown
minimal y of exit window
double slope
slope of slanted surface (dy/dz)
double yUp
maximal y of exit window
double zFlat
z where flat continues to slanted surface
double zR
maximal z, i.e position of prism-bar joint
double B
thickness at bar (dimension in y)
double zD
detector (photo-cathode) position
int k0
index of true prism in the vector 'unfoldedWindows'