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