LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SurfYZPlane.cxx
Go to the documentation of this file.
1 
12 #include "TVector2.h"
13 #include "cetlib_except/exception.h"
14 #include <cmath>
15 
16 namespace trkf {
17 
18  // Static attributes.
19 
20  double SurfYZPlane::fPhiTolerance = 1.e-10;
21  double SurfYZPlane::fSepTolerance = 1.e-6;
22 
24  SurfYZPlane::SurfYZPlane() : fX0(0.), fY0(0.), fZ0(0.), fPhi(0.) {}
25 
33  SurfYZPlane::SurfYZPlane(double x0, double y0, double z0, double phi)
34  : fX0(x0), fY0(y0), fZ0(z0), fPhi(phi)
35  {}
36 
39 
42  {
43  return new SurfYZPlane(*this);
44  }
45 
47  bool SurfYZPlane::isTrackValid(const TrackVector& vec) const
48  {
49  return true;
50  }
51 
59  void SurfYZPlane::toLocal(const double xyz[3], double uvw[3]) const
60  {
61  double sinphi = std::sin(fPhi);
62  double cosphi = std::cos(fPhi);
63 
64  // u = x-x0
65  uvw[0] = xyz[0] - fX0;
66 
67  // v = (y-y0)*cos(phi) + (z-z0)*sin(phi)
68  uvw[1] = (xyz[1] - fY0) * cosphi + (xyz[2] - fZ0) * sinphi;
69 
70  // w = -(y-y0)*sin(phi) + (z-z0)*cos(phi)
71  uvw[2] = -(xyz[1] - fY0) * sinphi + (xyz[2] - fZ0) * cosphi;
72  }
73 
81  void SurfYZPlane::toGlobal(const double uvw[3], double xyz[3]) const
82  {
83  double sinphi = std::sin(fPhi);
84  double cosphi = std::cos(fPhi);
85 
86  // x = x0 + u
87  xyz[0] = fX0 + uvw[0];
88 
89  // y = y0 + v*cos(phi) - w*sin(phi)
90  xyz[1] = fY0 + uvw[1] * cosphi - uvw[2] * sinphi;
91 
92  // z = z0 + v*sin(phi) + w*cos(phi)
93  xyz[2] = fZ0 + uvw[1] * sinphi + uvw[2] * cosphi;
94  }
95 
103  void SurfYZPlane::getPosition(const TrackVector& vec, double xyz[3]) const
104  {
105  // Get position in local coordinate system.
106 
107  double uvw[3];
108  uvw[0] = vec(0);
109  uvw[1] = vec(1);
110  uvw[2] = 0.;
111 
112  // Transform to global coordinate system.
113 
114  toGlobal(uvw, xyz);
115  return;
116  }
117 
126  void SurfYZPlane::getMomentum(const TrackVector& vec, double mom[3], TrackDirection dir) const
127  {
128 
129  // Get momentum.
130 
131  double invp = std::abs(vec(4));
132  double p = 1. / std::max(invp, 1.e-3); // Capped at 1000. GeV/c.
133 
134  // Get track slope parameters.
135 
136  double dudw = vec(2);
137  double dvdw = vec(3);
138 
139  // Calculate dw/ds.
140 
141  double dwds = 1. / std::sqrt(1. + dudw * dudw + dvdw * dvdw);
142  TrackDirection realdir = getDirection(vec, dir); // Should be same as original direction.
143  if (realdir == BACKWARD)
144  dwds = -dwds;
145  else if (realdir != FORWARD)
146  throw cet::exception("SurfYZPlane") << "Track direction not specified.\n";
147 
148  // Calculate momentum vector in local coordinate system.
149 
150  double pu = p * dudw * dwds;
151  double pv = p * dvdw * dwds;
152  double pw = p * dwds;
153 
154  // Rotate momentum to global coordinte system.
155 
156  double sinphi = std::sin(fPhi);
157  double cosphi = std::cos(fPhi);
158 
159  mom[0] = pu;
160  mom[1] = pv * cosphi - pw * sinphi;
161  mom[2] = pv * sinphi + pw * cosphi;
162 
163  return;
164  }
165 
176  bool SurfYZPlane::isParallel(const Surface& surf) const
177  {
178  bool result = false;
179 
180  // Test if the other surface is a SurfYZPlane.
181 
182  const SurfYZPlane* psurf = dynamic_cast<const SurfYZPlane*>(&surf);
183  if (psurf != 0) {
184 
185  // Test whether surface angle parameters are the same
186  // within tolerance.
187 
188  double delta_phi = TVector2::Phi_mpi_pi(fPhi - psurf->phi());
189  if (std::abs(delta_phi) <= fPhiTolerance) result = true;
190  }
191  return result;
192  }
193 
207  double SurfYZPlane::distanceTo(const Surface& surf) const
208  {
209  // Check if the other surface is parallel to this one.
210 
211  bool parallel = isParallel(surf);
212  if (!parallel)
213  throw cet::exception("SurfYZPlane") << "Attempt to find distance to non-parallel surface.\n";
214 
215  // Find the origin of the other surface in global coordinates,
216  // then convert to our local coordinates.
217 
218  double otheruvw[3] = {0., 0., 0.};
219  double xyz[3];
220  double myuvw[3];
221  surf.toGlobal(otheruvw, xyz);
222  toLocal(xyz, myuvw);
223 
224  // Distance is local w-coordinate of other surface origin.
225 
226  return myuvw[2];
227  }
228 
240  bool SurfYZPlane::isEqual(const Surface& surf) const
241  {
242  bool result = false;
243 
244  // Test if the other surface is a SurfYZPlane.
245 
246  const SurfYZPlane* psurf = dynamic_cast<const SurfYZPlane*>(&surf);
247  if (psurf != 0) {
248 
249  // Test whether surface parameters are the same within tolerance.
250 
251  double delta_phi = TVector2::Phi_mpi_pi(fPhi - psurf->phi());
252  double dx = fX0 - psurf->x0();
253  double dy = fY0 - psurf->y0();
254  double dz = fZ0 - psurf->z0();
255  if (std::abs(delta_phi) <= fPhiTolerance && std::abs(dx) <= fSepTolerance &&
256  std::abs(dy) <= fSepTolerance && std::abs(dz) <= fSepTolerance)
257  result = true;
258  }
259  return result;
260  }
261 
263  std::ostream& SurfYZPlane::Print(std::ostream& out) const
264  {
265  out << "SurfYZPlane{ x0=" << fX0 << ", y0=" << fY0 << ", z0=" << fZ0 << ", phi=" << fPhi << "}";
266  return out;
267  }
268 
269 } // end namespace trkf
static double fSepTolerance
Separation tolerance for equal.
Definition: SurfYZPlane.h:99
TrackDirection
Track direction enum.
Definition: Surface.h:54
double fPhi
Rotation angle about x-axis.
Definition: SurfYZPlane.h:106
double z0() const
Z origin.
Definition: SurfYZPlane.h:60
double x0() const
X origin.
Definition: SurfYZPlane.h:58
Planar surface parallel to x-axis.
static double fPhiTolerance
Phi tolerance for parallel.
Definition: SurfYZPlane.h:98
constexpr auto abs(T v)
Returns the absolute value of the argument.
virtual ~SurfYZPlane()
Destructor.
Definition: SurfYZPlane.cxx:38
virtual bool isParallel(const Surface &surf) const
Test whether two surfaces are parallel, within tolerance.
virtual double distanceTo(const Surface &surf) const
Find perpendicular forward distance to a parallel surface.
virtual void getMomentum(const TrackVector &vec, double mom[3], TrackDirection dir=UNKNOWN) const
Get momentum vector of track.
double y0() const
Y origin.
Definition: SurfYZPlane.h:59
virtual bool isTrackValid(const TrackVector &vec) const
Surface-specific tests of validity of track parameters.
Definition: SurfYZPlane.cxx:47
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
virtual void toLocal(const double xyz[3], double uvw[3]) const
Transform global to local coordinates.
Definition: SurfYZPlane.cxx:59
virtual std::ostream & Print(std::ostream &out) const
Printout.
virtual void toGlobal(const double uvw[3], double xyz[3]) const
Transform local to global coordinates.
Definition: SurfYZPlane.cxx:81
SurfYZPlane()
Default constructor.
Definition: SurfYZPlane.cxx:24
virtual bool isEqual(const Surface &surf) const
Test two surfaces for equality, within tolerance.
TDirectory * dir
Definition: macro.C:5
double phi() const
Rotation angle about x-axis.
Definition: SurfYZPlane.h:61
double fZ0
Z origin.
Definition: SurfYZPlane.h:105
virtual TrackDirection getDirection(const TrackVector &, TrackDirection dir=UNKNOWN) const
Get direction of track (default UNKNOWN).
Definition: Surface.h:83
virtual void getPosition(const TrackVector &vec, double xyz[3]) const
Get position of track.
virtual Surface * clone() const
Clone method.
Definition: SurfYZPlane.cxx:41
virtual void toGlobal(const double uvw[3], double xyz[3]) const =0
Transform local to global coordinates.
Float_t e
Definition: plot.C:35
double fX0
X origin.
Definition: SurfYZPlane.h:103
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
double fY0
Y origin.
Definition: SurfYZPlane.h:104