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