Belle II Software  release-08-01-10
TOPGeoBarSegment.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/TOPGeoBarSegment.h>
10 #include <framework/gearbox/Unit.h>
11 #include <framework/logging/Logger.h>
12 #include <math.h>
13 #include <iostream>
14 
15 using namespace std;
16 
17 namespace Belle2 {
23  bool TOPGeoBarSegment::isConsistent() const
24  {
25  if (m_width <= 0) return false;
26  if (m_thickness <= 0) return false;
27  if (m_length <= 0) return false;
28  if (m_material.empty()) return false;
29  if (m_glueThickness <= 0) return false;
30  if (m_glueMaterial.empty()) return false;
31  if (m_surface.getName().empty() and !m_surface.hasProperties()) return false;
32  if (m_sigmaAlpha < 0) return false;
33  if (m_brokenFraction > 0 and m_brokenGlueMaterial.empty()) return false;
34  return true;
35  }
36 
37 
38  void TOPGeoBarSegment::print(const std::string& title) const
39  {
40  TOPGeoBase::print(title);
41  cout << " Vendor: " << getVendor() << ", serial number: " << getSerialNumber() << endl;
42  cout << " Dimensions: " << getWidth() << " X " << getThickness() << " X " << getLength()
43  << " " << s_unitName << endl;
44  cout << " Material: " << getMaterial() << endl;
45  cout << " Glue: " << getGlueMaterial() << ", thickness = " << getGlueThickness()
46  << " " << s_unitName;
47  cout << ", broken fraction = " << getBrokenGlueFraction();
48  if (getBrokenGlueFraction() > 0) {
49  cout << ", angle = " << getBrokenGlueAngle() / Unit::deg << " deg";
50  cout << ", material = " << getBrokenGlueMaterial();
51  }
52  cout << endl;
53  printSurface(m_surface);
54  cout << " - sigmaAlpha: " << getSigmaAlpha() << endl;
55  }
56 
57  typedef std::pair<double, double> Pair;
59  std::vector<std::pair<double, double> > TOPGeoBarSegment::getBrokenGlueContour() const
60  {
61 
62  std::vector<Pair> contour;
63  constructContour(getWidth() / 2, getThickness() / 2, m_brokenFraction, m_brokenAngle,
64  contour);
65 
66  return contour;
67  }
68 
69 
70  void TOPGeoBarSegment::constructContour(double A, double B, double fraction, double angle,
71  std::vector<Pair>& contour) const
72  {
73  if (fraction <= 0.) {
74  return;
75  }
76  if (fraction >= 1.) {
77  contour.push_back(Pair(-A, B));
78  contour.push_back(Pair(A, B));
79  contour.push_back(Pair(A, -B));
80  contour.push_back(Pair(-A, -B));
81  return;
82  }
83 
84  double alpha0 = atan(B / A);
85  double halfPi = alpha0 > 0 ? M_PI / 2 : -M_PI / 2;
86  int quadrant = 0;
87  while (fabs(angle) > alpha0) {
88  angle -= halfPi;
89  alpha0 = M_PI / 2 - alpha0;
90  double a = A;
91  A = B;
92  B = a;
93  quadrant++;
94  }
95  quadrant = quadrant % 4;
96  if (halfPi < 0) quadrant = (4 - quadrant) % 4;
97 
98  double tanAngle = tan(fabs(angle));
99  double S0 = A / B * tanAngle / 2;
100  if (fraction <= S0) {
101  double x = sqrt(8 * A * B * fraction / tanAngle);
102  double y = x * tanAngle;
103  if (angle > 0) {
104  contour.push_back(Pair(-A, B - y));
105  contour.push_back(Pair(-A, B));
106  contour.push_back(Pair(-A + x, B));
107  } else {
108  contour.push_back(Pair(A, B - y));
109  contour.push_back(Pair(A - x, B));
110  contour.push_back(Pair(A, B));
111  }
112  } else if (1 - fraction <= S0) {
113  double x = sqrt(8 * A * B * (1 - fraction) / tanAngle);
114  double y = x * tanAngle;
115  if (angle > 0) {
116  contour.push_back(Pair(A, -B + y));
117  contour.push_back(Pair(A - x, -B));
118  contour.push_back(Pair(-A, -B));
119  contour.push_back(Pair(-A, B));
120  contour.push_back(Pair(A, B));
121  } else {
122  contour.push_back(Pair(-A + x, -B));
123  contour.push_back(Pair(-A, -B + y));
124  contour.push_back(Pair(-A, B));
125  contour.push_back(Pair(A, B));
126  contour.push_back(Pair(A, -B));
127  }
128  } else {
129  double y = (1 - 2 * fraction) * B;
130  double dy = angle > 0 ? A * tanAngle : -A * tanAngle;
131  contour.push_back(Pair(-A, y - dy));
132  contour.push_back(Pair(-A, B));
133  contour.push_back(Pair(A, B));
134  contour.push_back(Pair(A, y + dy));
135  }
136 
137  switch (quadrant) {
138  case 0:
139  break;
140  case 1:
141  for (auto& point : contour) {
142  double x = -point.second;
143  double y = point.first;
144  point.first = x;
145  point.second = y;
146  }
147  break;
148  case 2:
149  for (auto& point : contour) {
150  double x = -point.first;
151  double y = -point.second;
152  point.first = x;
153  point.second = y;
154  }
155  break;
156  case 3:
157  for (auto& point : contour) {
158  double x = point.second;
159  double y = -point.first;
160  point.first = x;
161  point.second = y;
162  }
163  break;
164  default:
165  B2ERROR("TOPGeoBarSegment::constructContour: bug!");
166  }
167 
168  }
169 
171 } // end Belle2 namespace
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
double atan(double a)
atan for double
Definition: beamHelpers.h:34
double tan(double a)
tan for double
Definition: beamHelpers.h:31
std::pair< double, double > Pair
Shorthand for std::pair<double, double>
Abstract base class for different kinds of events.