Belle II Software development
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
15using namespace std;
16
17namespace Belle2 {
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;
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;
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
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.
float m_glueThickness
glue thickness
std::string m_material
bar segment material name
double getBrokenGlueAngle() const
Returns angle of the delaminated surface.
std::string m_brokenGlueMaterial
broken glue material name
const std::string & getGlueMaterial() const
Returns glue material name (glue on -z side)
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
std::string m_glueMaterial
glue material name
double getSigmaAlpha() const
Returns geant4 parameter describing surface roughness.
double getBrokenGlueFraction() const
Returns fraction of the delaminated surface.
const std::string & getMaterial() const
Returns bar segment material name.
const std::string & getVendor() const
Returns vendor's 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
virtual double getGlueThickness() const
Returns glue thickness (glue on -z side)
const std::string & getBrokenGlueMaterial() const
Returns material name which represents broken glue.
const std::string & getSerialNumber() const
Returns serial number.
float m_brokenAngle
angle of broken (delaminated) glue
static const double deg
degree to radians
Definition: Unit.h:109
double atan(double a)
atan for double
Definition: beamHelpers.h:34
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
virtual bool isConsistent() const override
Check for consistency of data members.
virtual void print(const std::string &title="Bar segment geometry parameters") const override
Print the content of the class.
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
std::vector< std::pair< double, double > > getBrokenGlueContour() const
Returns the x-y contour of broken glue.
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.
STL namespace.