TankGeometry.h
Go to the documentation of this file.
1 #ifndef _CachedDirectInjectorOG_TankGeometry_h_
2 #define _CachedDirectInjectorOG_TankGeometry_h_
3 
4 /* RB :code is a modified version of code taken from ParticleInjectorNEU, to be merged (utl?) */
5 
6 #include <utl/GeometryUtilities.h>
7 #include <utl/Particle.h>
8 #include <utl/Point.h>
9 #include <utl/Math.h>
10 #include <utl/Line.h>
11 
12 using namespace utl;
13 using namespace std;
14 
15 
16 namespace CachedDirectInjectorOG {
17 
18  class TankGeometry {
19  public:
20  TankGeometry(const double bottom, const double top, const double radius,
21  const CoordinateSystemPtr cs) :
22  fBottomPlane(Point(0, 0, bottom, cs), Vector(0,0,1, cs)),
23  fTopPlane(Point(0, 0, top, cs), Vector(0,0,1, cs)),
24  fRadius2(Sqr(radius)),
25  fCS(cs)
26  { }
27 
28  bool
29  IsHit(const Particle& particle, Point& where)
30  const
31  {
32  const Point& particlePoint = particle.GetPosition();
33  const Vector& particleDirection = particle.GetDirection();
34  const Line particleLine(particlePoint, particleDirection);
35 
36  // try top
37  where = Intersection(fTopPlane, particleLine);
38  if ((where - fTopPlane.GetAnchor()).GetMag2() < fRadius2)
39  return true;
40 
41  const double ax = particleDirection.GetX(fCS);
42  const double ay = particleDirection.GetY(fCS);
43  const double px = particlePoint.GetX(fCS);
44  const double py = particlePoint.GetY(fCS);
45  const double a = Sqr(ax) + Sqr(ay);
46  const double b = 2*(ax*px + ay*py);
47  const double c = Sqr(px) + Sqr(py) - fRadius2;
48  const double disc = Sqr(b) - 4*a*c;
49  if (disc >= 0) {
50  const double ta = 2*a;
51  const double s0 = -b/ta;
52 
53  const double delta = sqrt(disc) / ta;
54 
55  const double s = s0 - delta;
56 
57  where = particleLine.Propagate(s);
58  if (Distance(fBottomPlane, where) >= 0 && Distance(fTopPlane, where) <= 0)
59  return true;
60  }
61 
62  // try bottom, should not be neccesary, as long as particles come from above ...
63  where = Intersection(fBottomPlane, particleLine);
64  if ((where - fBottomPlane.GetAnchor()).GetMag2() < fRadius2)
65  return true;
66 
67  return false;
68  }
69 
70  private:
73  const double fRadius2;
75  };
76 
77 }
78 
79 
80 #endif
constexpr T Sqr(const T &x)
Point object.
Definition: Point.h:32
Describes a particle for Simulation.
Definition: Particle.h:26
TankGeometry(const double bottom, const double top, const double radius, const CoordinateSystemPtr cs)
Definition: TankGeometry.h:20
double Distance(const Line &line1, const Line &line2)
Line Intersection(const Plane &p1, const Plane &p2)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
constexpr double s
Definition: AugerUnits.h:163
Class describing a Plane object.
Definition: Plane.h:17
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
struct particle_info particle[80]
Vector object.
Definition: Vector.h:30
const Point & GetPosition() const
Position of the particle.
Definition: Particle.h:110
const Vector & GetDirection() const
Unit vector giving particle direction.
Definition: Particle.h:114
Definition: Line.h:17
const CoordinateSystemPtr fCS
Definition: TankGeometry.h:74

, generated on Tue Sep 26 2023.