Belle II Software  release-08-01-10
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 using namespace ROOT::Math;
18 
19 namespace Belle2 {
25  TOPGeoPrism::UnfoldedWindow::UnfoldedWindow(const XYVector& orig, const XYVector& dir,
26  const XYVector& norm, const XYVector& slanted):
27  y0(orig.X()), z0(orig.Y()), sy(dir.X()), sz(dir.Y()), ny(norm.X()), nz(norm.Y())
28  {
29  nsy[0] = sy;
30  nsz[0] = sz;
31  nsy[1] = slanted.X();
32  nsz[1] = slanted.Y();
33  }
34 
35 
37  {
38  if (m_exitThickness <= 0) return false;
39  if (m_flatLength < 0) return false;
40  if (m_width <= 0) return false;
41  if (m_thickness <= 0) return false;
42  if (m_length <= 0) return false;
43  if (m_material.empty()) return false;
44  if (m_surface.getName().empty() and !m_surface.hasProperties()) return false;
45  if (m_sigmaAlpha < 0) return false;
46  if (m_brokenFraction > 0 and m_brokenGlueMaterial.empty()) return false;
47  if (!m_peelOffRegions.empty()) {
48  if (m_peelOffSize <= 0) return false;
49  if (m_peelOffThickness <= 0) return false;
50  if (m_peelOffMaterial.empty()) return false;
51  double halfSize = (getWidth() - getPeelOffSize()) / 2;
52  for (const auto& region : m_peelOffRegions) {
53  if (fabs(getPeelOffCenter(region)) > halfSize) return false;
54  }
55  }
56  return true;
57  }
58 
59 
60  void TOPGeoPrism::print(const std::string& title) const
61  {
62  TOPGeoBase::print(title);
63  cout << " Vendor: " << getVendor() << ", serial number: " << getSerialNumber() << endl;
64  cout << " Dimensions: " << getWidth() << " X " << getThickness() << " X " << getLength()
65  << " " << s_unitName << endl;
66  cout << " Exit window dimensions: " << getWidth() << " X "
67  << getExitThickness() << " " << s_unitName << endl;
68  cout << " Prism angle: " << getAngle() / Unit::deg << " deg";
69  cout << ", flat surface length: " << getFlatLength() << " " << s_unitName << endl;
70  cout << " Material: " << getMaterial() << endl;
71  if (getFilterThickness() > 0) { // old payload
72  cout << " Wavelenght filter: " << getFilterMaterial()
73  << ", thickness: " << getFilterThickness() << " " << s_unitName << endl;
74  }
75  if (!m_peelOffRegions.empty()) {
76  cout << " Peel-off cookie regions: ";
77  cout << " size = " << getPeelOffSize() << " " << s_unitName;
78  cout << " thickness = " << getPeelOffThickness() << " " << s_unitName;
79  cout << " material = " << getPeelOffMaterial() << endl;
80  for (const auto& region : m_peelOffRegions) {
81  cout << " ID = " << region.ID << ", fraction = " << region.fraction
82  << ", angle = " << region.angle / Unit::deg << " deg"
83  << ", xc = " << getPeelOffCenter(region) << " " << s_unitName << endl;
84  }
85  } else {
86  cout << " Peel-off regions: None" << endl;
87  }
89  cout << " - sigmaAlpha: " << getSigmaAlpha() << endl;
90 
91  }
92 
93 
94  void TOPGeoPrism::appendPeelOffRegion(unsigned ID, double fraction, double angle)
95  {
96  for (const auto& region : m_peelOffRegions) {
97  if (region.ID == ID) {
98  B2ERROR("TOPGeoPrism::appendPeelOffRegion: region already appended."
99  << LogVar("region ID", ID));
100  return;
101  }
102  }
103  PeelOffRegion region;
104  region.ID = ID;
105  region.fraction = fraction;
106  region.angle = angle;
107  double halfSize = (getWidth() - getPeelOffSize()) / 2;
108  if (fabs(getPeelOffCenter(region)) > halfSize) {
109  B2ERROR("TOPGeoPrism::appendPeelOffRegion: region doesn't fit into prism."
110  << LogVar("region ID", ID));
111  return;
112  }
113  m_peelOffRegions.push_back(region);
114  }
115 
116  typedef std::pair<double, double> Pair;
117 
118  std::vector<Pair> TOPGeoPrism::getPeelOffContour(const PeelOffRegion& region) const
119  {
120  std::vector<Pair> contour;
122  region.fraction, region.angle,
123  contour);
124 
125  return contour;
126  }
127 
128 
129  void TOPGeoPrism::unfold() const
130  {
131  double z = -(m_length - m_flatLength);
132  double yUp = m_thickness / 2;
133  double yDown = yUp - m_exitThickness;
134  XYVector points[2] = {XYVector(yUp, z), XYVector(yDown, z)}; // points on upper and slanted surfaces
135 
136  double alpha = getAngle();
137  XYVector normals[2] = {XYVector(1, 0), XYVector(-cos(alpha), sin(alpha))}; // normals of upper and slanted surfaces
138 
139  XYVector orig(0, z); // window origin
140  XYVector surf(1, 0); // window surface direction (= upper surface normal)
141  XYVector norm(0, -1); // window normal
142  auto slanted = normals[1]; // slanted surface normal
143 
144  reflect(points, normals, orig, surf, norm, slanted, 1, m_unfoldedWindows); // unfolding down
145  std::reverse(m_unfoldedWindows.begin(), m_unfoldedWindows.end());
146  m_unfoldedWindows.push_back(UnfoldedWindow(orig, surf, norm, slanted)); // true window
147  m_k0 = m_unfoldedWindows.size() - 1;
148  reflect(points, normals, orig, surf, norm, slanted, 0, m_unfoldedWindows); // unfolding up
149  }
150 
151 
152  void TOPGeoPrism::reflect(const XYVector* points, const XYVector* normals,
153  const XYVector& orig, const XYVector& surf, const XYVector& norm,
154  const XYVector& slanted, int k,
155  std::vector<UnfoldedWindow>& result) const
156  {
157  XYVector rp[2] = {points[0], points[1]};
158  XYVector n[2] = {normals[0], normals[1]};
159  auto r = orig;
160  auto s = surf;
161  auto q = norm;
162  auto sl = slanted;
163 
164  while (rp[k].Y() < 0) {
165  r -= 2 * ((r - rp[k]).Dot(n[k])) * n[k]; // reflect window origin
166  s -= 2 * s.Dot(n[k]) * n[k]; // reflect window surface direction
167  q -= 2 * q.Dot(n[k]) * n[k]; // reflect window normal
168  sl -= 2 * sl.Dot(n[k]) * n[k]; // reflect slanted normal
169  result.push_back(UnfoldedWindow(r, s, q, sl));
170  if (result.size() > 100) {
171  B2ERROR("TOPGeoPrism::reflect: too many reflections -> must be a bug");
172  return;
173  }
174  int i = (k + 1) % 2; // index of opposite surface
175  rp[i] -= 2 * (rp[i] - rp[k]).Dot(n[k]) * n[k]; // reflect point on the opposite surface
176  n[i] -= 2 * n[i].Dot(n[k]) * n[k]; // reflect normal of opposite surface
177  k = i; // toggle the reflection surface
178  }
179  }
180 
181 
183 } // 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:198
float m_flatLength
length of the flat part at the bottom
Definition: TOPGeoPrism.h:278
const std::string & getPeelOffMaterial() const
Returns peel-off material.
Definition: TOPGeoPrism.h:185
double getFilterThickness() const
Returns wavelength filter thickness (filter on -z side).
Definition: TOPGeoPrism.h:154
float m_peelOffThickness
thickness of peel-off volume
Definition: TOPGeoPrism.h:282
std::vector< PeelOffRegion > m_peelOffRegions
peel-off regions
Definition: TOPGeoPrism.h:284
float m_peelOffSize
size in x of peel-off volume
Definition: TOPGeoPrism.h:280
double getExitThickness() const
Returns prism thickness at PMT side.
Definition: TOPGeoPrism.h:126
double getAngle() const
Returns prism angle.
Definition: TOPGeoPrism.h:144
double getPeelOffThickness() const
Returns peel-off thickness.
Definition: TOPGeoPrism.h:179
double getPeelOffSize() const
Returns cookie size in x (corresponding to 2x2 PMT)
Definition: TOPGeoPrism.h:173
std::string m_peelOffMaterial
material name of peel-off volume
Definition: TOPGeoPrism.h:283
double getFlatLength() const
Returns the length of a flat surface at prism bottom.
Definition: TOPGeoPrism.h:132
int m_k0
do not write out
Definition: TOPGeoPrism.h:289
std::vector< UnfoldedWindow > m_unfoldedWindows
cache for unfolded prism exit windows
Definition: TOPGeoPrism.h:287
float m_exitThickness
thickness at PMT side
Definition: TOPGeoPrism.h:277
const std::string & getFilterMaterial() const
Returns wavelength filter material name (filter on -z side) For backward compatibility,...
Definition: TOPGeoPrism.h:161
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:94
bool isConsistent() const override
Check for consistency of data members.
Definition: TOPGeoPrism.cc:36
void reflect(const ROOT::Math::XYVector *points, const ROOT::Math::XYVector *normals, const ROOT::Math::XYVector &orig, const ROOT::Math::XYVector &surf, const ROOT::Math::XYVector &norm, const ROOT::Math::XYVector &slanted, int k, std::vector< UnfoldedWindow > &result) const
Do unfolding.
Definition: TOPGeoPrism.cc:152
std::vector< std::pair< double, double > > getPeelOffContour(const PeelOffRegion &region) const
Returns the x-y contour of the peel-off region.
Definition: TOPGeoPrism.cc:118
void unfold() const
Unfold prism exit window.
Definition: TOPGeoPrism.cc:129
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:60
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