Belle II Software development
FastRaytracer.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <top/reconstruction_cpp/FastRaytracer.h>
10#include <framework/logging/Logger.h>
11#include <cmath>
12
13namespace Belle2 {
18 namespace TOP {
19
21 {
22 m_photonStates.clear();
23 m_extraStates.clear();
24 m_status = false;
25 m_Nxm = 0;
26 m_Nxb = 0;
27 m_Nxe = 0;
28 m_Nym = 0;
29 m_Nyb = 0;
30 m_Nye = 0;
31 }
32
33 void FastRaytracer::propagate(const PhotonState& photon, bool averaging) const
34 {
35 clear();
36 m_photonStates.reserve(m_bars.size() * 2 + 2);
37 m_photonStates.push_back(photon);
38
39 int nbars = m_bars.size();
40 if (photon.getKz() > 0 and photon.getZ() > m_prism.zR) {
41 for (int i = 0; i < nbars; i++) {
42 const auto& bar = m_bars[i];
43 const auto& lastState = m_photonStates.back();
44 if (lastState.getZ() >= bar.zR) continue;
45 m_photonStates.push_back(lastState);
46 auto& newState = m_photonStates.back();
47 if (i < nbars - 1) {
48 newState.propagate(bar);
49 } else if (m_optics == c_SemiLinear) {
50 newState.propagateSemiLinear(bar, m_mirror);
51 } else {
52 newState.propagateExact(bar, m_mirror);
53 }
54 if (not newState.getPropagationStatus()) return;
55
56 m_Nxm += (m_Nxm % 2 == 0) ? newState.getNx() : -newState.getNx();
57 m_Nym += (m_Nym % 2 == 0) ? newState.getNy() : -newState.getNy();
58 }
59 }
60
61 for (int i = nbars - 1; i >= 0; i--) {
62 const auto& bar = m_bars[i];
63 const auto& lastState = m_photonStates.back();
64 if (lastState.getZ() <= bar.zL) continue;
65 m_photonStates.push_back(lastState);
66 auto& newState = m_photonStates.back();
67 newState.propagate(bar);
68 if (not newState.getPropagationStatus()) return;
69
70 m_Nxb += (m_Nxb % 2 == 0) ? newState.getNx() : -newState.getNx();
71 m_Nyb += (m_Nyb % 2 == 0) ? newState.getNy() : -newState.getNy();
72 }
73
74 const auto& lastState = m_photonStates.back();
75 m_photonStates.push_back(lastState);
76 auto& newState = m_photonStates.back();
77 newState.propagate(m_prism);
78 if (not newState.getPropagationStatus()) return;
79
80 if (averaging) {
81 m_extraStates.push_back(lastState);
82 auto& flippedState = m_extraStates.back().flipKy();
83 flippedState.propagate(m_prism);
84 if (not flippedState.getPropagationStatus()) return;
85 }
86
87 m_Nxe = newState.getNx();
88 m_Nye = newState.getNy();
89
90 m_status = true;
91 }
92
93 bool FastRaytracer::getTotalReflStatus(double cosTotal) const
94 {
95 for (const auto& photonState : m_photonStates) {
96 if (not photonState.getTotalReflStatus(cosTotal)) return false;
97 }
98 return true;
99 }
100
102 {
103 if (m_photonStates.empty()) return 0;
104 if (m_extraStates.empty()) return m_photonStates.back().getPropagationLen();
105 return (m_photonStates.back().getPropagationLen() + m_extraStates.back().getPropagationLen()) / 2;
106 }
107
109 {
110 if (m_photonStates.empty() or m_extraStates.empty()) return 0;
111 return (m_photonStates.back().getPropagationLen() - m_extraStates.back().getPropagationLen());
112 }
113
114 double FastRaytracer::getXD() const
115 {
116 if (m_photonStates.empty()) return 0;
117
118 double x = m_extraStates.empty() ?
119 m_photonStates.back().getXD() : (m_photonStates.back().getXD() + m_extraStates.back().getXD()) / 2;
120
121 for (int i = m_photonStates.size() - 2; i > 0; i--) {
122 const auto& photonState = m_photonStates[i];
123 if (photonState.getSegmentType() == PhotonState::c_MirrorSegment) break;
124 x = photonState.getUnfoldedX(x);
125 }
126 return x;
127 }
128
129
130 double FastRaytracer::getYD() const
131 {
132 if (m_photonStates.empty()) return 0;
133
134 double y = m_photonStates.back().getYD();
135 for (int i = m_photonStates.size() - 2; i > 0; i--) {
136 const auto& photonState = m_photonStates[i];
137 if (photonState.getSegmentType() == PhotonState::c_MirrorSegment) break;
138 y = photonState.getUnfoldedY(y);
139 }
140 return y;
141 }
142
143
145 {
146 if (m_photonStates.empty()) return 0;
147
148 double y = m_photonStates.back().getY();
149 for (int i = m_photonStates.size() - 1; i > 0; i--) {
150 const auto& photonState = m_photonStates[i];
151 if (photonState.getSegmentType() == PhotonState::c_MirrorSegment) break;
152 y = photonState.getUnfoldedY(y);
153 }
154 return y;
155 }
156
157
158 double FastRaytracer::getZD() const
159 {
160 if (m_photonStates.empty()) return 0;
161 if (m_extraStates.empty()) return m_photonStates.back().getZD();
162 return (m_photonStates.back().getZD() + m_extraStates.back().getZD()) / 2;
163 }
164
165
166 double FastRaytracer::getYB() const
167 {
168 if (m_photonStates.size() < 2) return 0;
169
170 int i0 = m_photonStates.size() - 2;
171 double y = m_photonStates[i0].getY();
172 for (int i = i0; i > 0; i--) {
173 const auto& photonState = m_photonStates[i];
174 if (photonState.getSegmentType() == PhotonState::c_MirrorSegment) break;
175 y = photonState.getUnfoldedY(y);
176 }
177 return y;
178 }
179
180
182 {
183 int Nx = m_Nxm;
184 Nx += (Nx % 2 == 0) ? m_Nxb : -m_Nxb;
185 Nx += (Nx % 2 == 0) ? m_Nxe : -m_Nxe;
186 return Nx;
187 }
188
189
191 {
192 int Ny = m_Nym;
193 Ny += (Ny % 2 == 0) ? m_Nyb : -m_Nyb;
194 Ny += (Ny % 2 == 0) ? m_Nye : -m_Nye;
195 return Ny;
196 }
197
199 {
200 int N = (m_Nye > 0) ? m_Nye / 2 : (std::abs(m_Nye) + 1) / 2;
201 return N;
202 }
203
204 } // TOP
206} // Belle2
int m_Nym
number of reflections in y before mirror
double getZD() const
Returns unfolded position in z of virtual Detector plane.
double getPropagationLen() const
Returns total propagation length since initial position.
double getInPlaneYD() const
Returns unfolded position in y such that the prism unfolded windows are turned over into the real Det...
std::vector< PhotonState > m_photonStates
photon states at propagation steps
void propagate(const PhotonState &photon, bool averaging=false) const
Propagate photon to photo-detector plane.
int m_Nxm
number of reflections in x before mirror
int getNx() const
Returns signed number of reflections in x.
double getYB() const
Returns unfolded position in y at Bar-prism-connection plane.
double getYD() const
Returns unfolded position in y at virtual Detector plane.
bool getTotalReflStatus(double cosTotal) const
Returns total internal reflection status.
bool m_status
propagation status
int m_Nxe
number of reflections in x inside prism
int getNy() const
Returns signed number of reflections in y.
int getNys() const
Returns number of reflections on slanted prism surface.
double getPropagationLenDelta() const
Returns total propagation length difference between true and flipped prism.
int m_Nyb
number of reflections in y after mirror and before prism
int m_Nxb
number of reflections in x after mirror and before prism
int m_Nye
number of reflections in y inside prism
void clear() const
Clear mutable variables.
std::vector< PhotonState > m_extraStates
extra storage
double getXD() const
Returns unfolded position in x at virtual Detector plane.
State of the Cerenkov photon in the quartz optics.
Definition PhotonState.h:27
double getZ() const
Returns position in z.
@ c_MirrorSegment
mirror segment
Definition PhotonState.h:37
double getKz() const
Returns direction in z.
EOptics m_optics
spherical mirror optics
@ c_SemiLinear
semi-linear approximation
Mirror m_mirror
spherical mirror geometry data
Prism m_prism
prism geometry data
std::vector< BarSegment > m_bars
geometry data of bar segments
Abstract base class for different kinds of events.