26 #define BOOST_TEST_MODULE ( tracktrajectory_test ) 27 #include "boost/test/unit_test.hpp" 66 if (!
tag.empty()) BOOST_TEST_MESSAGE(
tag);
67 if (
std::abs(exp) < (tol / 100.)) BOOST_CHECK_SMALL(v, tol);
68 else BOOST_CHECK_CLOSE(v, exp, tol);
71 template <
typename VectA,
typename VectB>
73 BOOST_TEST(v.X() == exp.X());
74 BOOST_TEST(v.Y() == exp.Y());
75 BOOST_TEST(v.Z() == exp.Z());
78 template <
typename VectA,
typename VectB>
88 m.SetRotationMatrix(Tm);
100 const size_t NPoints = expected.
positions.size();
101 BOOST_TEST(traj.
NPoints() == NPoints);
104 for (
size_t i = 0; i <= NPoints + 1; ++i) {
105 BOOST_TEST_MESSAGE(
"HasPoint() position #" << i);
106 BOOST_TEST(traj.
HasPoint(i) == (i < NPoints));
109 if (NPoints == 0)
return;
115 std::set<size_t> validPoints;
116 for (
size_t i = 0; i < NPoints; ++i) {
119 validPoints.insert(i);
121 std::size_t
const firstValidPoint = validPoints.empty()
123 std::size_t
const lastValidPoint = validPoints.empty()
127 BOOST_TEST(traj.
LastPoint() == NPoints - 1);
130 for (
size_t i = 0; i < NPoints; ++i) {
132 bool const isValid = (validPoints.count(i) > 0);
133 BOOST_TEST_MESSAGE(
"HasValidPoint() position #" << i);
142 auto iNext = validPoints.upper_bound(i);
143 if (iNext == validPoints.end()) {
147 else if (iNext == validPoints.begin()) {
159 if (!validPoints.empty()) {
167 BOOST_TEST_MESSAGE(
"Vertex()");
170 BOOST_TEST_MESSAGE(
"Start()");
173 BOOST_TEST_MESSAGE(
"End()");
177 for (
size_t i = 0; i < NPoints; ++i) {
179 BOOST_TEST_MESSAGE(
"LocationAtPoint() position #" << i);
186 TVector3 Vstart, Vend;
187 std::tie(Vstart, Vend) = traj.
Extent<TVector3>();
188 BOOST_TEST(Vstart[0] == expected.
positions[firstValidPoint].X());
189 BOOST_TEST(Vstart[1] == expected.
positions[firstValidPoint].Y());
190 BOOST_TEST(Vstart[2] == expected.
positions[firstValidPoint].Z());
191 BOOST_TEST(Vend[0] == expected.
positions[lastValidPoint].X());
192 BOOST_TEST(Vend[1] == expected.
positions[lastValidPoint].Y());
193 BOOST_TEST(Vend[2] == expected.
positions[lastValidPoint].Z());
197 std::tie(start, end) = traj.
Extent();
198 BOOST_TEST_MESSAGE(
"Extent() start");
200 BOOST_TEST_MESSAGE(
"Extent() end");
205 BOOST_CHECK_CLOSE(traj.
Length(), expected.
length, 0.01);
206 if (validPoints.size() >= 2) {
207 std::size_t
const secondValidPoint = *(std::next(validPoints.begin()));
208 BOOST_CHECK_CLOSE(traj.
Length(firstValidPoint + 1),
219 BOOST_TEST_MESSAGE(
"VertexDirection()");
224 BOOST_TEST_MESSAGE(
"StartDirection()");
229 BOOST_TEST_MESSAGE(
"EndDirection()");
232 BOOST_CHECK_CLOSE(traj.
EndDirection().Mag2(), 1.0, 0.01);
236 BOOST_CHECK_CLOSE(traj.
Theta(), expected.
theta, 0.01);
237 BOOST_CHECK_CLOSE(traj.
Phi(), expected.
phi, 0.01);
244 BOOST_TEST_MESSAGE(
"VertexMomentumVector()");
248 BOOST_TEST_MESSAGE(
"StartMomentumVector()");
252 BOOST_TEST_MESSAGE(
"EndMomentumVector()");
257 BOOST_TEST_MESSAGE(
"VertexMomentum()");
261 BOOST_TEST_MESSAGE(
"StartMomentum()");
265 BOOST_TEST_MESSAGE(
"EndMomentum()");
271 for (
size_t i = 0; i < NPoints; ++i) {
273 BOOST_TEST_MESSAGE(
"DirectionAtPoint() position #" << i);
280 for (
size_t i = 0; i < NPoints; ++i) {
282 if (validPoints.count(i) == 0)
continue;
284 BOOST_TEST_MESSAGE(
"MomentumVectorAtPoint() position #" << i);
292 BOOST_TEST_MESSAGE(
"MomentumAtPoint() position #" << i);
304 TVector3 AstartDir, AendDir;
305 std::tie(AstartDir, AendDir) = traj.
Direction<TVector3>();
307 (AstartDir[0], expected.
momenta[firstValidPoint].Unit().X(), 0.01);
309 (AstartDir[1], expected.
momenta[firstValidPoint].Unit().Y(), 0.01);
311 (AstartDir[2], expected.
momenta[firstValidPoint].Unit().Z(), 0.01);
313 (AendDir[0], expected.
momenta[lastValidPoint].Unit().X(), 0.01);
315 (AendDir[1], expected.
momenta[lastValidPoint].Unit().Y(), 0.01);
317 (AendDir[2], expected.
momenta[lastValidPoint].Unit().Z(), 0.01);
320 std::tie(startDir, endDir) = traj.
Direction();
321 BOOST_TEST_MESSAGE(
"Direction() start");
323 BOOST_TEST_MESSAGE(
"Direction() end");
329 for (
size_t i = 0; i < NPoints; ++i) {
331 if (validPoints.count(i) == 0)
continue;
336 BOOST_TEST_MESSAGE(
"Test transformation to local at point #" << i);
340 BOOST_TEST_MESSAGE(
"Test transformation to global at point #" << i);
347 for (
size_t i = 0; i < NPoints; ++i) {
349 if (validPoints.count(i) == 0)
continue;
354 BOOST_TEST_MESSAGE(
"Test legacy transformation to local at point #" << i);
359 BOOST_TEST_MESSAGE(
"Test legacy transformation to global at point #" << i);
374 BOOST_TEST_MESSAGE(
"Testing the default recob::TrackTrajectory constructor");
383 expected.
flags.clear();
395 <<
"Default-constructed track trajectory dump with verbosity level " 397 traj.
Dump(std::cout, v,
" ",
" ");
410 BOOST_TEST_MESSAGE(
"Testing the main recob::TrackTrajectory constructor");
502 expected.
length = 12. * std::sqrt(6);
519 std::cout <<
"Track trajectory dump with verbosity level " 521 traj.
Dump(std::cout, v,
" ",
" ");
534 expected.
momenta.begin(), [](
auto const& v){
return v.unit(); });
545 std::cout <<
"Momentumless trajectory dump with verbosity level " 547 mltraj.
Dump(std::cout, v,
" ",
" ");
587 expected.
length = 2. * std::sqrt(20.0);
597 std::cout <<
"Short trajectory dump with verbosity level " 599 shorttraj.
Dump(std::cout, v,
" ",
" ");
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void Dump(Stream &&out, unsigned int verbosity, std::string indent, std::string indentFirst) const
Prints trajectory content into a stream.
bool HasPoint(size_t i) const
Returns whether the specified trajectory point is available.
recob::TrackTrajectory::Positions_t positions
BOOST_AUTO_TEST_CASE(TrackTrajectoryTestDefaultConstructorTestCase)
static constexpr Flag_t NoPoint
The trajectory point is not defined.
T DirectionAtPoint(unsigned int p) const
Direction at point p. Use e.g. as:
size_t LastValidPoint() const
Returns the index of the last valid point in the trajectory.
T GlobalToLocalRotationAtPoint(unsigned int p) const
Returns a rotation matrix that brings trajectory direction along z. Use e.g. as:
tracking::Positions_t Positions_t
Type of trajectory point list.
double ZenithAngle(size_t p) const
"Zenith" angle of trajectory, with respect to the vertical axis.
void TrackTrajectoryTestMainConstructor()
Vector_t const & StartMomentumVector() const
Returns the momentum of the trajectory at the first valid point [GeV/c].
Vector_t const & VertexMomentumVector() const
Returns the momentum of the trajectory at the first valid point [GeV/c].
T LocalToGlobalRotationAtPoint(unsigned int p) const
Returns a rotation matrix bringing relative directions to global. Use e.g. as:
double EndMomentum() const
PointFlags_t::flag flag
Flag traits (including the definition of flag mnemonics).
recob::TrackTrajectory::Rotation_t makeRotationMatrix(TMatrixD const &Tm)
void CheckValue(T v, T exp, T tol, std::string tag="")
unsigned int CountValidPoints() const
Computes and returns the number of points with valid location.
tracking::Momenta_t Momenta_t
Type of momentum list.
std::pair< T, T > Extent() const
Fills the first and last valid point in the trajectory.
void CheckVectorsEqual(VectA const &v, VectB const &exp)
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
std::pair< T, T > Direction() const
Fills the starting and ending direction of the trajectory.
void TrackTrajectoryTestDefaultConstructor()
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
size_t LastPoint() const
Returns the index of the last point in the trajectory.
size_t PreviousValidPoint(size_t index) const
Returns the index of the previous valid point in the trajectory.
size_t NPoints() const
Returns the number of stored trajectory points.
A trajectory in space reconstructed from hits.
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
double MomentumAtPoint(size_t i) const
Computes and returns the modulus of the momentum at a point.
bool HasValidPoint(size_t i) const
Returns whether the specified point has NoPoint flag unset.
double StartMomentum() const
tracking::Rotation_t Rotation_t
Type for representation of space rotations.
recob::TrackTrajectory::Flags_t flags
tracking::Vector_t Vector_t
Type for representation of momenta in 3D space.
void TestTrackTrajectory(recob::TrackTrajectory const &traj, Expected_t const &expected)
std::vector< PointFlags_t > Flags_t
Type of point flag list.
size_t NumberTrajectoryPoints() const
Returns the number of stored trajectory points.
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
Set of flags pertaining a point of the track.
recob::TrackTrajectory::Momenta_t momenta
double Phi(size_t p) const
Azimuthal angle at a point on the trajectory, with respect to z.
Point_t const & Vertex() const
Returns the position of the first valid point of the trajectory [cm].
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
tracking::Coord_t Coord_t
Type used for coordinates and values in general.
double Theta(size_t p) const
Trajectory angle at point, with respect to positive z direction.
size_t FirstValidPoint() const
Returns the index of the first valid point in the trajectory.
static constexpr size_t InvalidIndex
Value returned on failed index queries.
bool HasMomentum() const
Returns whether information about the momentum is available.
Vector_t const & EndMomentumVector() const
Returns the momentum of the trajectory at the last valid point [GeV/c].
static constexpr unsigned int MaxDumpVerbosity
Largest verbosity level supported by Dump().
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
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)
size_t NextValidPoint(size_t index) const
Returns the index of the next valid point in the trajectory.
double AzimuthAngle(size_t p) const
"Azimuth" angle of trajectory, with respect to the sky.
tracking::Point_t Point_t
Type for representation of position in physical 3D space.
double VertexMomentum() const
T MomentumVectorAtPoint(unsigned int p) const
Momentum vector at point p. Use e.g. as:
Collection of Physical constants used in LArSoft.
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
QTextStream & endl(QTextStream &s)
void CheckVectorsClose(VectA const &v, VectB const &exp, double tol=0.01)