Belle II Software  release-06-02-00
TOPGeoPrism.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/dbobjects/TOPGeoPrism.h>
10 #include <framework/gearbox/Unit.h>
11 #include <framework/logging/Logger.h>
12 #include <cmath>
13 #include <iostream>
14 #include <algorithm>
15 
16 using namespace std;
17 
18 namespace Belle2 {
24  TOPGeoPrism::UnfoldedWindow::UnfoldedWindow(const TVector2& orig, const TVector2& dir,
25  const TVector2& norm, const TVector2& slanted):
26  y0(orig.X()), z0(orig.Y()), sy(dir.X()), sz(dir.Y()), ny(norm.X()), nz(norm.Y())
27  {
28  nsy[0] = sy;
29  nsz[0] = sz;
30  nsy[1] = slanted.X();
31  nsz[1] = slanted.Y();
32  }
33 
34 
36  {
37  if (m_exitThickness <= 0) return false;
38  if (m_flatLength < 0) return false;
39  if (m_width <= 0) return false;
40  if (m_thickness <= 0) return false;
41  if (m_length <= 0) return false;
42  if (m_material.empty()) return false;
43  if (m_surface.getName().empty() and !m_surface.hasProperties()) return false;
44  if (m_sigmaAlpha < 0) return false;
45  if (m_brokenFraction > 0 and m_brokenGlueMaterial.empty()) return false;
46  if (!m_peelOffRegions.empty()) {
47  if (m_peelOffSize <= 0) return false;
48  if (m_peelOffThickness <= 0) return false;
49  if (m_peelOffMaterial.empty()) return false;
50  double halfSize = (getWidth() - getPeelOffSize()) / 2;
51  for (const auto& region : m_peelOffRegions) {
52  if (fabs(getPeelOffCenter(region)) > halfSize) return false;
53  }
54  }
55  return true;
56  }
57 
58 
59  void TOPGeoPrism::print(const std::string& title) const
60  {
61  TOPGeoBase::print(title);
62  cout << " Vendor: " << getVendor() << ", serial number: " << getSerialNumber() << endl;
63  cout << " Dimensions: " << getWidth() << " X " << getThickness() << " X " << getLength()
64  << " " << s_unitName << endl;
65  cout << " Exit window dimensions: " << getWidth() << " X "
66  << getExitThickness() << " " << s_unitName << endl;
67  cout << " Prism angle: " << getAngle() / Unit::deg << " deg";
68  cout << ", flat surface length: " << getFlatLength() << " " << s_unitName << endl;
69  cout << " Material: " << getMaterial() << endl;
70  if (getFilterThickness() > 0) { // old payload
71  cout << " Wavelenght filter: " << getFilterMaterial()
72  << ", thickness: " << getFilterThickness() << " " << s_unitName << endl;
73  }
74  if (!m_peelOffRegions.empty()) {
75  cout << " Peel-off cookie regions: ";
76  cout << " size = " << getPeelOffSize() << " " << s_unitName;
77  cout << " thickness = " << getPeelOffThickness() << " " << s_unitName;
78  cout << " material = " << getPeelOffMaterial() << endl;
79  for (const auto& region : m_peelOffRegions) {
80  cout << " ID = " << region.ID << ", fraction = " << region.fraction
81  << ", angle = " << region.angle / Unit::deg << " deg"
82  << ", xc = " << getPeelOffCenter(region) << " " << s_unitName << endl;
83  }
84  } else {
85  cout << " Peel-off regions: None" << endl;
86  }
88  cout << " - sigmaAlpha: " << getSigmaAlpha() << endl;
89 
90  }
91 
92 
93  void TOPGeoPrism::appendPeelOffRegion(unsigned ID, double fraction, double angle)
94  {
95  for (const auto& region : m_peelOffRegions) {
96  if (region.ID == ID) {
97  B2ERROR("TOPGeoPrism::appendPeelOffRegion: region already appended."
98  << LogVar("region ID", ID));
99  return;
100  }
101  }
102  PeelOffRegion region;
103  region.ID = ID;
104  region.fraction = fraction;
105  region.angle = angle;
106  double halfSize = (getWidth() - getPeelOffSize()) / 2;
107  if (fabs(getPeelOffCenter(region)) > halfSize) {
108  B2ERROR("TOPGeoPrism::appendPeelOffRegion: region doesn't fit into prism."
109  << LogVar("region ID", ID));
110  return;
111  }
112  m_peelOffRegions.push_back(region);
113  }
114 
115  typedef std::pair<double, double> Pair;
116 
117  std::vector<Pair> TOPGeoPrism::getPeelOffContour(const PeelOffRegion& region) const
118  {
119  std::vector<Pair> contour;
121  region.fraction, region.angle,
122  contour);
123 
124  return contour;
125  }
126 
127 
128  void TOPGeoPrism::unfold() const
129  {
130  double z = -(m_length - m_flatLength);
131  double yUp = m_thickness / 2;
132  double yDown = yUp - m_exitThickness;
133  TVector2 points[2] = {TVector2(yUp, z), TVector2(yDown, z)}; // points on upper and slanted surfaces
134 
135  double alpha = getAngle();
136  TVector2 normals[2] = {TVector2(1, 0), TVector2(-cos(alpha), sin(alpha))}; // normals of upper and slanted surfaces
137 
138  TVector2 orig(0, z); // window origin
139  TVector2 surf(1, 0); // window surface direction (= upper surface normal)
140  TVector2 norm(0, -1); // window normal
141  auto slanted = normals[1]; // slanted surface normal
142 
143  reflect(points, normals, orig, surf, norm, slanted, 1, m_unfoldedWindows); // unfolding down
144  std::reverse(m_unfoldedWindows.begin(), m_unfoldedWindows.end());
145  m_unfoldedWindows.push_back(UnfoldedWindow(orig, surf, norm, slanted)); // true window
146  m_k0 = m_unfoldedWindows.size() - 1;
147  reflect(points, normals, orig, surf, norm, slanted, 0, m_unfoldedWindows); // unfolding up
148  }
149 
150 
151  void TOPGeoPrism::reflect(const TVector2* points, const TVector2* normals,
152  const TVector2& orig, const TVector2& surf, const TVector2& norm,
153  const TVector2& slanted, int k,
154  std::vector<UnfoldedWindow>& result) const
155  {
156  TVector2 rp[2] = {points[0], points[1]};
157  TVector2 n[2] = {normals[0], normals[1]};
158  auto r = orig;
159  auto s = surf;
160  auto q = norm;
161  auto sl = slanted;
162 
163  while (rp[k].Y() < 0) {
164  r -= 2 * ((r - rp[k]) * n[k]) * n[k]; // reflect window origin
165  s -= 2 * (s * n[k]) * n[k]; // reflect window surface direction
166  q -= 2 * (q * n[k]) * n[k]; // reflect window normal
167  sl -= 2 * (sl * n[k]) * n[k]; // reflect slanted normal
168  result.push_back(UnfoldedWindow(r, s, q, sl));
169  if (result.size() > 100) {
170  B2ERROR("TOPGeoPrism::reflect: too many reflections -> must be a bug");
171  return;
172  }
173  int i = (k + 1) % 2; // index of opposite surface
174  rp[i] -= 2 * ((rp[i] - rp[k]) * n[k]) * n[k]; // reflect point on the opposite surface
175  n[i] -= 2 * (n[i] * n[k]) * n[k]; // reflect normal of opposite surface
176  k = i; // toggle the reflection surface
177  }
178  }
179 
180 
182 } // end Belle2 namespace
const std::string & getName() const
get name of the optical surface
bool hasProperties() const
check if the material has at least one property
double getWidth() const
Returns bar segment width.
std::string m_material
bar segment material name
std::string m_brokenGlueMaterial
broken glue material name
const std::string & getVendor() const
Returns vendor's name.
GeoOpticalSurface m_surface
optical surface
double getThickness() const
Returns bar segment thickness.
float m_brokenFraction
fraction of broken (delaminated) glue
float m_thickness
bar segment thickness
double getSigmaAlpha() const
Returns geant4 parameter describing surface roughness.
const std::string & getSerialNumber() const
Returns serial number.
const std::string & getMaterial() const
Returns bar segment material name.
float m_sigmaAlpha
geant4 parameter for surface roughness
float m_length
bar segment length
double getLength() const
Returns bar segment length.
float m_width
bar segment width
double getPeelOffCenter(const PeelOffRegion &region) const
Returns peel-off offset in x of the given region.
Definition: TOPGeoPrism.h:197
float m_flatLength
length of the flat part at the bottom
Definition: TOPGeoPrism.h:276
const std::string & getPeelOffMaterial() const
Returns peel-off material.
Definition: TOPGeoPrism.h:184
double getFilterThickness() const
Returns wavelength filter thickness (filter on -z side).
Definition: TOPGeoPrism.h:153
float m_peelOffThickness
thickness of peel-off volume
Definition: TOPGeoPrism.h:280
std::vector< PeelOffRegion > m_peelOffRegions
peel-off regions
Definition: TOPGeoPrism.h:282
float m_peelOffSize
size in x of peel-off volume
Definition: TOPGeoPrism.h:278
double getExitThickness() const
Returns prism thickness at PMT side.
Definition: TOPGeoPrism.h:125
double getAngle() const
Returns prism angle.
Definition: TOPGeoPrism.h:143
double getPeelOffThickness() const
Returns peel-off thickness.
Definition: TOPGeoPrism.h:178
double getPeelOffSize() const
Returns cookie size in x (corresponding to 2x2 PMT)
Definition: TOPGeoPrism.h:172
std::string m_peelOffMaterial
material name of peel-off volume
Definition: TOPGeoPrism.h:281
double getFlatLength() const
Returns the length of a flat surface at prism bottom.
Definition: TOPGeoPrism.h:131
int m_k0
do not write out
Definition: TOPGeoPrism.h:287
std::vector< UnfoldedWindow > m_unfoldedWindows
cache for unfolded prism exit windows
Definition: TOPGeoPrism.h:285
float m_exitThickness
thickness at PMT side
Definition: TOPGeoPrism.h:275
const std::string & getFilterMaterial() const
Returns wavelength filter material name (filter on -z side) For backward compatibility,...
Definition: TOPGeoPrism.h:160
static const double deg
degree to radians
Definition: Unit.h:109
Class to store variables with their name which were sent to the logging service.
void appendPeelOffRegion(unsigned ID, double fraction, double angle)
Appends peel-off cookie region.
Definition: TOPGeoPrism.cc:93
void reflect(const TVector2 *points, const TVector2 *normals, const TVector2 &orig, const TVector2 &surf, const TVector2 &norm, const TVector2 &slanted, int k, std::vector< UnfoldedWindow > &result) const
Do unfolding.
Definition: TOPGeoPrism.cc:151
bool isConsistent() const override
Check for consistency of data members.
Definition: TOPGeoPrism.cc:35
std::vector< std::pair< double, double > > getPeelOffContour(const PeelOffRegion &region) const
Returns the x-y contour of the peel-off region.
Definition: TOPGeoPrism.cc:117
void unfold() const
Unfold prism exit window.
Definition: TOPGeoPrism.cc:128
virtual void printSurface(const GeoOpticalSurface &surface) const
Print the content of optical surface.
Definition: TOPGeoBase.cc:44
void constructContour(double A, double B, double fraction, double angle, std::vector< std::pair< double, double > > &contour) const
Construct a 2D contour.
virtual void print(const std::string &title) const
Print the content of the class.
Definition: TOPGeoBase.cc:28
void print(const std::string &title="Prism geometry parameters") const override
Print the content of the class.
Definition: TOPGeoPrism.cc:59
std::pair< double, double > Pair
Shorthand for std::pair<double, double>
static std::string s_unitName
conversion unit name
Definition: TOPGeoBase.h:87
Abstract base class for different kinds of events.
Parameters of peel-off cookie region (corresponds to 2x2 PMT's)
Definition: TOPGeoPrism.h:33
Unfolded prism exit window.
Definition: TOPGeoPrism.h:43
double nsz[2]
normals to upper [0] and slanted [1] surfaces, z component
Definition: TOPGeoPrism.h:51
double nsy[2]
normals to upper [0] and slanted [1] surfaces, y component
Definition: TOPGeoPrism.h:50
double sz
window surface direction in z
Definition: TOPGeoPrism.h:47
double sy
window surface direction in y
Definition: TOPGeoPrism.h:46