Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Solid.cc
Go to the documentation of this file.
1#include <cmath>
2#include <iostream>
3
6#include "Garfield/Solid.hh"
7
8namespace Garfield {
9
10unsigned int Solid::s_id = 0;
11
12void Solid::SetDirection(const double dx, const double dy, const double dz) {
13 const double d = sqrt(dx * dx + dy * dy + dz * dz);
14 if (d < Small) {
15 std::cerr << m_className << ": Direction vector has zero norm.\n";
16 return;
17 }
18 m_dX = dx / d;
19 m_dY = dy / d;
20 m_dZ = dz / d;
21 double phi, theta;
22 const double dt = sqrt(m_dX * m_dX + m_dY * m_dY);
23 if (dt < Small) {
24 phi = 0.;
25 if (m_dZ > 0.) {
26 theta = 0.;
27 } else {
28 theta = Pi;
29 }
30 } else {
31 phi = atan2(m_dY, m_dX);
32 theta = atan2(dt, m_dZ);
33 }
34 m_cTheta = cos(theta);
35 m_sTheta = sin(theta);
36 m_cPhi = cos(phi);
37 m_sPhi = sin(phi);
38}
39
40bool Solid::GetProfile(std::vector<double>& /*xv*/,
41 std::vector<double>& /*yv*/) const {
42
43 std::cerr << m_className << "::GetProfile: function not implemented.\n";
44 return false;
45}
46
47double Solid::NotImplemented(const std::string& fcn) const {
48 std::cerr << m_className << "::" << fcn << ": function not implemented.\n";
49 return 0.;
50}
51
52bool Solid::Intersect(const double x1, const double y1, const double z1,
53 const double x2, const double y2, const double z2,
54 const double x0, const double y0, const double z0,
55 const double a, const double b, const double c,
56 double& xc, double& yc, double& zc) {
57 //-----------------------------------------------------------------------
58 // PLALIN - Cuts an arbitrary plane with a line.
59 // Variables : (X1,Y1,Z1) : starting point of the line
60 // (X2,Y2,Z2) : end point of the line
61 // (X0,Y0,Z0) : point on the plane
62 // (A,B,C) : parameters of the plane
63 //-----------------------------------------------------------------------
64
65 xc = yc = zc = 0.;
66 bool on = false;
67 // Form the two products.
68 const double prod1 = (x0 - x1) * a + (y0 - y1) * b + (z0 - z1) * c;
69 const double prod2 = (x2 - x1) * a + (y2 - y1) * b + (z2 - z1) * c;
70 // Set a tolerance for lambda.
71 constexpr double eps = 1.e-5;
72 // Check the products are non-zero.
73 const double dx = x2 - x1;
74 const double dy = y2 - y1;
75 const double dz = z2 - z1;
76 const double d2 = dx * dx + dy * dy + dz * dz;
77 if (std::abs(prod2) > 1.e-6 * sqrt((a * a + b * b + c * c) * d2)) {
78 double s = prod1 / prod2;
79 if (s >= -eps && s <= 1. + eps) on = true;
80 s = std::max(0., std::min(1., s));
81 xc = x1 + s * dx;
82 yc = y1 + s * dy;
83 zc = z1 + s * dz;
84 }
85 return on;
86}
87
88}
double m_dZ
Definition: Solid.hh:205
double m_cTheta
Polar angle.
Definition: Solid.hh:209
static bool Intersect(const double x1, const double y1, const double z1, const double x2, const double y2, const double z2, const double x0, const double y0, const double z0, const double a, const double b, const double c, double &xc, double &yc, double &zc)
Definition: Solid.cc:52
double m_dX
Direction vector.
Definition: Solid.hh:205
void SetDirection(const double dx, const double dy, const double dz)
Definition: Solid.cc:12
virtual bool GetProfile(std::vector< double > &xv, std::vector< double > &yv) const
Get the vertices defining an extrusion.
Definition: Solid.cc:40
double m_sPhi
Definition: Solid.hh:207
double m_sTheta
Definition: Solid.hh:209
double m_dY
Definition: Solid.hh:205
double m_cPhi
Azimuthal angle.
Definition: Solid.hh:207
std::string m_className
Class name.
Definition: Solid.hh:212