9#include <simulation/kernel/ExtCylSurfaceTarget.h>
10#include <G4GeometryTolerance.hh>
12#include <G4Normal3D.hh>
13#include <G4Plane3D.hh>
14#include <framework/logging/Logger.h>
18using namespace Belle2::Simulation;
22 const G4double& zmax) :
26 m_tolerance(1000.0 * G4GeometryTolerance::GetInstance()->GetSurfaceTolerance())
28 theType = G4ErrorTarget_CylindricalSurface;
29 B2DEBUG(1,
"Simulation::ExtCylSurfaceTarget created with radius "
30 <<
m_radius <<
" zmin " << zmin <<
" zmax " << zmax);
38 const G4ThreeVector& dir)
const
40 if (fabs(dir.mag() - 1.0) > 1.0E-10) {
41 B2FATAL(
"Simulation::ExtCylSurfaceTarget::GetDistanceFromPoint() direction is not a unit vector: " << dir);
49 G4double dirz = dir.z();
50 if (dirz < -1.0E-10) {
51 dist = fmin(dist, (
m_zmin - point.z()) / dirz);
52 }
else if (dirz > 1.0E-10) {
53 dist = fmin(dist, (
m_zmax - point.z()) / dirz);
56 B2DEBUG(300,
"Simulation::ExtCylSurfaceTarget::GetDistanceFromPoint(): Global point "
57 << point <<
" dir " << dir <<
" distance " << dist);
65 G4double dist =
m_radius - point.perp();
66 dist = fmin(dist, point.z() -
m_zmin);
67 dist = fmin(dist,
m_zmax - point.z());
69 B2DEBUG(300,
"Simulation::ExtCylSurfaceTarget::GetDistanceFromPoint(): Global point "
70 << point <<
" minimum distance " << dist);
76 const G4ThreeVector& localDir)
const
79 G4double eqa = localDir.x() * localDir.x() + localDir.y() * localDir.y();
80 G4double eqb = 2.0 * (localPoint.x() * localDir.x() + localPoint.y() * localDir.y());
81 G4double eqc = localPoint.x() * localPoint.x() + localPoint.y() * localPoint.y()
83 G4double eqaInside = (localPoint.perp() >
m_radius) ? -eqa : eqa;
85 G4ThreeVector intersection = localPoint;
86 if (eqaInside > 0.0) {
87 intersection += localDir * ((-eqb +
sqrt(eqb * eqb - 4.0 * eqa * eqc)) / (2.0 * eqa));
88 }
else if (eqaInside < 0.0) {
89 intersection += localDir * ((-eqb -
sqrt(eqb * eqb - 4.0 * eqa * eqc)) / (2.0 * eqa));
92 intersection -= localDir * (eqc / eqb);
94 B2WARNING(
"Simulation::ExtCylSurfaceTarget::IntersectLocal(): localPoint "
95 << localPoint <<
" localDir " << localDir <<
" does not intersect with cylinder");
96 intersection = localDir * kInfinity;
100 B2DEBUG(300,
"Simulation::ExtCylSurfaceTarget::IntersectLocal(): localPoint "
101 << localPoint <<
" localDir " << localDir <<
" radial intersection " << intersection.perp());
110 B2ERROR(
"Simulation::ExtCylSurfaceTarget::GetTangentPlane(): point "
111 << point <<
" is not at surface; radial distance is " << point.perp() -
m_radius);
114 G4Normal3D normal(point);
116 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...
ExtCylSurfaceTarget(const G4double &, const G4double &, const G4double &)
Construct the closed cylindrical surface No coordinate transformations allowed: cylinder is coaxial w...
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.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.