26 #define BOOST_TEST_MODULE ( tracktrajectory_test )
27 #include "boost/test/unit_test.hpp"
62 if (!tag.empty()) BOOST_TEST_MESSAGE(tag);
63 if (
std::abs(exp) < (tol / 100.)) BOOST_CHECK_SMALL(v, tol);
64 else BOOST_CHECK_CLOSE(v, exp, tol);
67 template <
typename VectA,
typename VectB>
69 BOOST_TEST(v.X() == exp.X());
70 BOOST_TEST(v.Y() == exp.Y());
71 BOOST_TEST(v.Z() == exp.Z());
74 template <
typename VectA,
typename VectB>
84 m.SetRotationMatrix(Tm);
97 BOOST_TEST(NPoints == expected.
positions.size());
100 for (
size_t i = 0; i <= NPoints + 1; ++i) {
101 BOOST_TEST_MESSAGE(
"HasPoint() position #" << i);
102 BOOST_TEST(traj.
HasPoint(i) == (i < NPoints));
105 if (NPoints == 0)
return;
110 BOOST_TEST(traj.
LastPoint() == NPoints - 1);
113 BOOST_TEST_MESSAGE(
"Vertex()");
116 BOOST_TEST_MESSAGE(
"Start()");
119 BOOST_TEST_MESSAGE(
"End()");
123 for (
size_t i = 0; i < NPoints; ++i) {
125 BOOST_TEST_MESSAGE(
"LocationAtPoint() position #" << i);
132 TVector3 Vstart, Vend;
133 std::tie(Vstart, Vend) = traj.
Extent<TVector3>();
134 BOOST_TEST(Vstart[0] == expected.
positions[0].X());
135 BOOST_TEST(Vstart[1] == expected.
positions[0].Y());
136 BOOST_TEST(Vstart[2] == expected.
positions[0].Z());
137 BOOST_TEST(Vend[0] == expected.
positions[NPoints - 1].X());
138 BOOST_TEST(Vend[1] == expected.
positions[NPoints - 1].Y());
139 BOOST_TEST(Vend[2] == expected.
positions[NPoints - 1].Z());
143 std::tie(start, end) = traj.
Extent();
144 BOOST_TEST_MESSAGE(
"Extent() start");
146 BOOST_TEST_MESSAGE(
"Extent() end");
151 BOOST_CHECK_CLOSE(traj.
Length(), expected.
length, 0.01);
153 BOOST_CHECK_CLOSE(traj.
Length(1),
161 BOOST_TEST_MESSAGE(
"VertexDirection()");
165 BOOST_TEST_MESSAGE(
"StartDirection()");
169 BOOST_TEST_MESSAGE(
"EndDirection()");
171 BOOST_CHECK_CLOSE(traj.
EndDirection().Mag2(), 1.0, 0.01);
175 BOOST_CHECK_CLOSE(traj.
Theta(), expected.
theta, 0.01);
176 BOOST_CHECK_CLOSE(traj.
Phi(), expected.
phi, 0.01);
183 BOOST_TEST_MESSAGE(
"VertexMomentumVector()");
186 BOOST_TEST_MESSAGE(
"StartMomentumVector()");
189 BOOST_TEST_MESSAGE(
"EndMomentumVector()");
194 BOOST_TEST_MESSAGE(
"VertexMomentum()");
197 BOOST_TEST_MESSAGE(
"StartMomentum()");
200 BOOST_TEST_MESSAGE(
"EndMomentum()");
206 for (
size_t i = 0; i < NPoints; ++i) {
208 BOOST_TEST_MESSAGE(
"DirectionAtPoint() position #" << i);
215 for (
size_t i = 0; i < NPoints; ++i) {
217 BOOST_TEST_MESSAGE(
"MomentumVectorAtPoint() position #" << i);
225 BOOST_TEST_MESSAGE(
"MomentumAtPoint() position #" << i);
237 TVector3 AstartDir, AendDir;
238 std::tie(AstartDir, AendDir) = traj.
Direction<TVector3>();
239 BOOST_CHECK_CLOSE(AstartDir[0], expected.
momenta[0].Unit().X(), 0.01);
240 BOOST_CHECK_CLOSE(AstartDir[1], expected.
momenta[0].Unit().Y(), 0.01);
241 BOOST_CHECK_CLOSE(AstartDir[2], expected.
momenta[0].Unit().Z(), 0.01);
242 BOOST_CHECK_CLOSE(AendDir[0], expected.
momenta[NPoints - 1].Unit().X(), 0.01);
243 BOOST_CHECK_CLOSE(AendDir[1], expected.
momenta[NPoints - 1].Unit().Y(), 0.01);
244 BOOST_CHECK_CLOSE(AendDir[2], expected.
momenta[NPoints - 1].Unit().Z(), 0.01);
247 std::tie(startDir, endDir) = traj.
Direction();
248 BOOST_TEST_MESSAGE(
"Direction() start");
250 BOOST_TEST_MESSAGE(
"Direction() end");
256 for (
size_t i = 0; i < NPoints; ++i) {
261 BOOST_TEST_MESSAGE(
"Test transformation to local at point #" << i);
265 BOOST_TEST_MESSAGE(
"Test transformation to global at point #" << i);
272 for (
size_t i = 0; i < NPoints; ++i) {
277 BOOST_TEST_MESSAGE(
"Test legacy transformation to local at point #" << i);
282 BOOST_TEST_MESSAGE(
"Test legacy transformation to global at point #" << i);
297 BOOST_TEST_MESSAGE(
"Testing the default recob::Trajectory constructor");
316 std::cout <<
"Default-constructed trajectory dump with verbosity level "
317 << v <<
":" << std::endl;
331 BOOST_TEST_MESSAGE(
"Testing the main recob::Trajectory constructor");
396 = (expected.
positions.size() - 1) * std::sqrt(3.0 - 2.0 * V2_2);
407 auto momenta = expected.
momenta;
411 std::cout <<
"Trajectory dump with verbosity level "
412 << v <<
":" << std::endl;
426 expected.
momenta.begin(), [](
auto const& v){
return v.unit(); });
435 std::cout <<
"Momentumless trajectory dump with verbosity level "
436 << v <<
":" << std::endl;
Point_t const & Vertex() const
Returns the position of the first point of the trajectory [cm].
double Phi(size_t p=0) const
Azimuthal angle at a point on the trajectory, with respect to z.
Data product for reconstructed trajectory in space.
double EndMomentum() const
Computes and returns the modulus of momentum at the last point [GeV/c].
bool HasPoint(size_t i) const
Returns whether the specified trajectory point is available.
recob::TrackTrajectory::Positions_t positions
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
Vector_t const & StartMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
Point_t const & End() const
Returns the position of the last point of the trajectory [cm].
double AzimuthAngle(size_t p=0) const
"Azimuth" angle of trajectory, with respect to the sky.
double ZenithAngle(size_t p=0) const
"Zenith" angle of trajectory, with respect to the vertical axis.
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
Rotation_t LocalToGlobalRotationAtPoint(size_t p) const
Returns a rotation matrix bringing relative directions to global.
recob::TrackTrajectory::Rotation_t makeRotationMatrix(TMatrixD const &Tm)
double VertexMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
void CheckValue(T v, T exp, T tol, std::string tag="")
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
double StartMomentum() const
Computes and returns the modulus of momentum at the first point [GeV/c].
void CheckVectorsEqual(VectA const &v, VectB const &exp)
Vector_t DirectionAtPoint(size_t i) const
Computes and returns the direction of the trajectory at a point.
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
Returns a rotation matrix that brings trajectory direction along z.
recob::Trajectory::Momenta_t momenta
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
size_t LastPoint() const
Returns the index of the last point in the trajectory.
std::pair< T, T > Extent() const
Fills the first and last point in the trajectory.
double MomentumAtPoint(size_t i) const
Computes and returns the modulus of the momentum at a point.
auto end(FixedBins< T, C > const &) noexcept
void TestTrajectory(recob::Trajectory const &traj, Expected_t const &expected)
std::pair< T, T > Direction() const
Fills the starting and ending direction of the trajectory.
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
recob::Trajectory::Positions_t positions
tracking::Positions_t Positions_t
Type of trajectory point list.
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
recob::TrackTrajectory::Momenta_t momenta
tracking::Momenta_t Momenta_t
Type of momentum list.
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
A trajectory in space reconstructed from hits.
bool HasMomentum() const
Returns whether information about the momentum is available.
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
void TrajectoryTestDefaultConstructor()
Vector_t const & VertexMomentumVector() const
Returns the momentum of the trajectory at the first point [GeV/c].
double Theta(size_t p=0) const
Trajectory angle at point, with respect to positive z direction.
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
Collection of Physical constants used in LArSoft.
Point_t const & Start() const
Returns the position of the first point of the trajectory [cm].
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
BEGIN_PROLOG could also be cout
void TrajectoryTestMainConstructor()
Vector_t const & EndMomentumVector() const
Returns the momentum of the trajectory at the last point [GeV/c].
void CheckVectorsClose(VectA const &v, VectB const &exp, double tol=0.01)