9 #include <top/dbobjects/TOPGeoBarSegment.h>
10 #include <framework/gearbox/Unit.h>
11 #include <framework/logging/Logger.h>
23 bool TOPGeoBarSegment::isConsistent()
const
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;
38 void TOPGeoBarSegment::print(
const std::string& title)
const
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()
47 cout <<
", broken fraction = " << getBrokenGlueFraction();
48 if (getBrokenGlueFraction() > 0) {
49 cout <<
", angle = " << getBrokenGlueAngle() / Unit::deg <<
" deg";
50 cout <<
", material = " << getBrokenGlueMaterial();
53 printSurface(m_surface);
54 cout <<
" - sigmaAlpha: " << getSigmaAlpha() << endl;
57 typedef std::pair<double, double>
Pair;
59 std::vector<std::pair<double, double> > TOPGeoBarSegment::getBrokenGlueContour()
const
62 std::vector<Pair> contour;
63 constructContour(getWidth() / 2, getThickness() / 2, m_brokenFraction, m_brokenAngle,
70 void TOPGeoBarSegment::constructContour(
double A,
double B,
double fraction,
double angle,
71 std::vector<Pair>& contour)
const
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));
84 double alpha0 =
atan(B / A);
85 double halfPi = alpha0 > 0 ? M_PI / 2 : -M_PI / 2;
87 while (fabs(angle) > alpha0) {
89 alpha0 = M_PI / 2 - alpha0;
95 quadrant = quadrant % 4;
96 if (halfPi < 0) quadrant = (4 - quadrant) % 4;
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;
104 contour.push_back(
Pair(-A, B - y));
105 contour.push_back(
Pair(-A, B));
106 contour.push_back(
Pair(-A + x, B));
108 contour.push_back(
Pair(A, B - y));
109 contour.push_back(
Pair(A - x, B));
110 contour.push_back(
Pair(A, B));
112 }
else if (1 - fraction <= S0) {
113 double x =
sqrt(8 * A * B * (1 - fraction) / tanAngle);
114 double y = x * tanAngle;
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));
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));
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));
141 for (
auto& point : contour) {
142 double x = -point.second;
143 double y = point.first;
149 for (
auto& point : contour) {
150 double x = -point.first;
151 double y = -point.second;
157 for (
auto& point : contour) {
158 double x = point.second;
159 double y = -point.first;
165 B2ERROR(
"TOPGeoBarSegment::constructContour: bug!");
double sqrt(double a)
sqrt for double
double atan(double a)
atan for double
double tan(double a)
tan for double
std::pair< double, double > Pair
Shorthand for std::pair<double, double>
Abstract base class for different kinds of events.