9 #include <simulation/kernel/ExtCylSurfaceTarget.h>
10 #include <G4GeometryTolerance.hh>
11 #include <geomdefs.hh>
12 #include <G4Plane3D.hh>
13 #include <framework/logging/Logger.h>
17 using namespace Belle2::Simulation;
19 ExtCylSurfaceTarget::ExtCylSurfaceTarget(
const G4double& radius,
21 const G4double& zmax) :
25 m_tolerance(1000.0 * G4GeometryTolerance::GetInstance()->GetSurfaceTolerance())
27 theType = G4ErrorTarget_CylindricalSurface;
28 B2DEBUG(1,
"Simulation::ExtCylSurfaceTarget created with radius "
29 <<
m_radius <<
" zmin " << zmin <<
" zmax " << zmax);
37 const G4ThreeVector& dir)
const
39 if (fabs(dir.mag() - 1.0) > 1.0E-10) {
40 B2FATAL(
"Simulation::ExtCylSurfaceTarget::GetDistanceFromPoint() direction is not a unit vector: " << dir);
48 G4double dirz = dir.z();
49 if (dirz < -1.0E-10) {
50 dist = fmin(dist, (
m_zmin - point.z()) / dirz);
51 }
else if (dirz > 1.0E-10) {
52 dist = fmin(dist, (
m_zmax - point.z()) / dirz);
55 B2DEBUG(300,
"Simulation::ExtCylSurfaceTarget::GetDistanceFromPoint(): Global point "
56 << point <<
" dir " << dir <<
" distance " << dist);
64 G4double dist =
m_radius - point.perp();
65 dist = fmin(dist, point.z() -
m_zmin);
66 dist = fmin(dist,
m_zmax - point.z());
68 B2DEBUG(300,
"Simulation::ExtCylSurfaceTarget::GetDistanceFromPoint(): Global point "
69 << point <<
" minimum distance " << dist);
75 const G4ThreeVector& localDir)
const
78 G4double eqa = localDir.x() * localDir.x() + localDir.y() * localDir.y();
79 G4double eqb = 2.0 * (localPoint.x() * localDir.x() + localPoint.y() * localDir.y());
80 G4double eqc = localPoint.x() * localPoint.x() + localPoint.y() * localPoint.y()
82 G4double eqaInside = (localPoint.perp() >
m_radius) ? -eqa : eqa;
84 G4ThreeVector intersection = localPoint;
85 if (eqaInside > 0.0) {
86 intersection += localDir * ((-eqb + sqrt(eqb * eqb - 4.0 * eqa * eqc)) / (2.0 * eqa));
87 }
else if (eqaInside < 0.0) {
88 intersection += localDir * ((-eqb - sqrt(eqb * eqb - 4.0 * eqa * eqc)) / (2.0 * eqa));
91 intersection -= localDir * (eqc / eqb);
93 B2WARNING(
"Simulation::ExtCylSurfaceTarget::IntersectLocal(): localPoint "
94 << localPoint <<
" localDir " << localDir <<
" does not intersect with cylinder");
95 intersection = localDir * kInfinity;
99 B2DEBUG(300,
"Simulation::ExtCylSurfaceTarget::IntersectLocal(): localPoint "
100 << localPoint <<
" localDir " << localDir <<
" radial intersection " << intersection.perp());
109 B2ERROR(
"Simulation::ExtCylSurfaceTarget::GetTangentPlane(): point "
110 << point <<
" is not at surface; radial distance is " << point.perp() -
m_radius);
113 G4Normal3D normal(point);
115 return G4Plane3D(normal, point);
G4double m_radius
Cylinder radius.
~ExtCylSurfaceTarget()
Destructor.
G4double m_tolerance
Tolerance for distance between a point and cylinder's curved surface.
virtual G4Plane3D GetTangentPlane(const G4ThreeVector &point) const
Get the plane tangent to the cylinder at a given point.
virtual void Dump(const G4String &msg) const
Dump the cylinder parameters.
virtual G4ThreeVector IntersectLocal(const G4ThreeVector &point, const G4ThreeVector &direc) const
Return the intersection of the cylinder with the line defined in local (cylinder) coordinates by poin...
G4double m_zmax
Cylinder maximum-z coordinate.
virtual G4double GetDistanceFromPoint(const G4ThreeVector &point, const G4ThreeVector &direc) const
Get the distance from a point to the cylinder along direc.
G4double m_zmin
Cylinder minimum-z coordinate.
Abstract base class for different kinds of events.