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.push_back(photon);
37
38 int nbars = m_bars.size();
39 if (photon.getKz() > 0 and photon.getZ() > m_prism.zR) {
40 for (int i = 0; i < nbars; i++) {
41 const auto& bar = m_bars[i];
42 const auto& lastState = m_photonStates.back();
43 if (lastState.getZ() >= bar.zR) continue;
44 m_photonStates.push_back(lastState);
45 auto& newState = m_photonStates.back();
46 if (i < nbars - 1) {
47 newState.propagate(bar);
48 } else if (m_optics == c_SemiLinear) {
49 newState.propagateSemiLinear(bar, m_mirror);
50 } else {
51 newState.propagateExact(bar, m_mirror);
52 }
53 if (not newState.getPropagationStatus()) return;
54
55 m_Nxm += (m_Nxm % 2 == 0) ? newState.getNx() : -newState.getNx();
56 m_Nym += (m_Nym % 2 == 0) ? newState.getNy() : -newState.getNy();
57 }
58 }
59
60 for (int i = nbars - 1; i >= 0; i--) {
61 const auto& bar = m_bars[i];
62 const auto& lastState = m_photonStates.back();
63 if (lastState.getZ() <= bar.zL) continue;
64 m_photonStates.push_back(lastState);
65 auto& newState = m_photonStates.back();
66 newState.propagate(bar);
67 if (not newState.getPropagationStatus()) return;
68
69 m_Nxb += (m_Nxb % 2 == 0) ? newState.getNx() : -newState.getNx();
70 m_Nyb += (m_Nyb % 2 == 0) ? newState.getNy() : -newState.getNy();
71 }
72
73 const auto& lastState = m_photonStates.back();
74 m_photonStates.push_back(lastState);
75 auto& newState = m_photonStates.back();
76 newState.propagate(m_prism);
77 if (not newState.getPropagationStatus()) return;
78
79 if (averaging) {
80 m_extraStates.push_back(lastState);
81 auto& flippedState = m_extraStates.back().flipKy();
82 flippedState.propagate(m_prism);
83 if (not flippedState.getPropagationStatus()) return;
84 }
85
86 m_Nxe = newState.getNx();
87 m_Nye = newState.getNy();
88
89 m_status = true;
90 }
91
92 bool FastRaytracer::getTotalReflStatus(double cosTotal) const
93 {
94 for (const auto& photonState : m_photonStates) {
95 if (not photonState.getTotalReflStatus(cosTotal)) return false;
96 }
97 return true;
98 }
99
101 {
102 if (m_photonStates.empty()) return 0;
103 if (m_extraStates.empty()) return m_photonStates.back().getPropagationLen();
104 return (m_photonStates.back().getPropagationLen() + m_extraStates.back().getPropagationLen()) / 2;
105 }
106
108 {
109 if (m_photonStates.empty() or m_extraStates.empty()) return 0;
110 return (m_photonStates.back().getPropagationLen() - m_extraStates.back().getPropagationLen());
111 }
112
113 double FastRaytracer::getXD() const
114 {
115 if (m_photonStates.empty()) return 0;
116
117 double x = m_extraStates.empty() ?
118 m_photonStates.back().getXD() : (m_photonStates.back().getXD() + m_extraStates.back().getXD()) / 2;
119
120 for (int i = m_photonStates.size() - 2; i > 0; i--) {
121 const auto& photonState = m_photonStates[i];
122 if (photonState.getSegmentType() == PhotonState::c_MirrorSegment) break;
123 x = photonState.getUnfoldedX(x);
124 }
125 return x;
126 }
127
128
129 double FastRaytracer::getYD() const
130 {
131 if (m_photonStates.empty()) return 0;
132
133 double y = m_photonStates.back().getYD();
134 for (int i = m_photonStates.size() - 2; i > 0; i--) {
135 const auto& photonState = m_photonStates[i];
136 if (photonState.getSegmentType() == PhotonState::c_MirrorSegment) break;
137 y = photonState.getUnfoldedY(y);
138 }
139 return y;
140 }
141
142
144 {
145 if (m_photonStates.empty()) return 0;
146
147 double y = m_photonStates.back().getY();
148 for (int i = m_photonStates.size() - 1; i > 0; i--) {
149 const auto& photonState = m_photonStates[i];
150 if (photonState.getSegmentType() == PhotonState::c_MirrorSegment) break;
151 y = photonState.getUnfoldedY(y);
152 }
153 return y;
154 }
155
156
157 double FastRaytracer::getZD() const
158 {
159 if (m_photonStates.empty()) return 0;
160 if (m_extraStates.empty()) return m_photonStates.back().getZD();
161 return (m_photonStates.back().getZD() + m_extraStates.back().getZD()) / 2;
162 }
163
164
165 double FastRaytracer::getYB() const
166 {
167 if (m_photonStates.size() < 2) return 0;
168
169 int i0 = m_photonStates.size() - 2;
170 double y = m_photonStates[i0].getY();
171 for (int i = i0; i > 0; i--) {
172 const auto& photonState = m_photonStates[i];
173 if (photonState.getSegmentType() == PhotonState::c_MirrorSegment) break;
174 y = photonState.getUnfoldedY(y);
175 }
176 return y;
177 }
178
179
181 {
182 int Nx = m_Nxm;
183 Nx += (Nx % 2 == 0) ? m_Nxb : -m_Nxb;
184 Nx += (Nx % 2 == 0) ? m_Nxe : -m_Nxe;
185 return Nx;
186 }
187
188
190 {
191 int Ny = m_Nym;
192 Ny += (Ny % 2 == 0) ? m_Nyb : -m_Nyb;
193 Ny += (Ny % 2 == 0) ? m_Nye : -m_Nye;
194 return Ny;
195 }
196
198 {
199 int N = (m_Nye > 0) ? m_Nye / 2 : (std::abs(m_Nye) + 1) / 2;
200 return N;
201 }
202
203 } // TOP
205} // 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.
Definition: PhotonState.h:105
@ c_MirrorSegment
mirror segment
Definition: PhotonState.h:37
double getKz() const
Returns direction in z.
Definition: PhotonState.h:161
EOptics m_optics
spherical mirror optics
@ c_SemiLinear
semi-linear approximation
Definition: RaytracerBase.h:42
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.
double zR
maximal z, i.e position of prism-bar joint