12 #ifndef ICARUSALG_UTILITIES_TRAJECTORYUTILS_H
13 #define ICARUSALG_UTILITIES_TRAJECTORYUTILS_H
29 template <
typename Iter>
88 template <
typename FIter,
typename LIter>
90 (FIter itFirst, LIter itLast,
double relTarget = 0.5);
153 template <
typename FIter,
typename LIter>
154 auto pathMiddlePoint(FIter itFirst, LIter itLast,
double relTarget = 0.5);
189 template <
typename BIter,
typename EIter>
226 template <
typename BIter,
typename EIter>
267 template <
typename Iter,
typename S
ideFunc>
269 (Iter
begin, Iter
end, SideFunc sideOf);
279 template <
typename FIter,
typename LIter>
281 (FIter itFirst, LIter itLast,
double relTarget )
288 struct SegmentInfo_t {
291 bool operator< (SegmentInfo_t
const& other)
const
292 {
return length < other.length; }
297 if (itFirst == itLast) {
298 return PathPointInfo_t<FIter>{
306 SegmentInfo_t startChunk, endChunk;
307 FIter itStart = itFirst, itPrevStart = itStart;
308 LIter itEnd = itLast, itPrevEnd = itEnd;
312 if (startChunk < endChunk) {
313 itPrevStart = itStart;
314 if (++itStart == itEnd) {
317 itStart = itPrevStart;
324 if (itStart == --itEnd) {
332 assert(!(itStart == itEnd));
340 assert(!(itStart == itEnd));
342 auto delta = *itEnd - *itStart;
345 double const pathLength = startChunk.length + deltaLength + endChunk.length;
347 double const targetLength = pathLength * relTarget;
349 if (startChunk.length > targetLength) {
352 endChunk.length += deltaLength;
353 assert(itStart == itEnd);
355 itStart = itPrevStart;
356 delta = *itEnd - *itStart;
358 startChunk.length -= deltaLength;
360 else if (endChunk.length > targetLength) {
363 startChunk.length += deltaLength;
364 assert(itStart == itEnd);
367 delta = *itEnd - *itStart;
369 endChunk.length -= deltaLength;
373 assert(!(itStart == itEnd));
374 assert(startChunk.length <= targetLength);
375 assert(startChunk.length + deltaLength >= targetLength);
376 assert(endChunk.length <= pathLength - targetLength);
377 assert(endChunk.length + deltaLength >= pathLength - targetLength);
381 double const f = (deltaLength != 0.0)
382 ? ((targetLength - startChunk.length) / deltaLength): 0.0;
386 return PathPointInfo_t<FIter>{
397 template <
typename FIter,
typename LIter>
399 (FIter itFirst, LIter itLast,
double relTarget )
410 if (targetInfo.
frac == 0.0)
return *(targetInfo.
itPoint);
412 auto const delta = *std::next(targetInfo.
itPoint) - *(targetInfo.
itPoint);
413 return *(targetInfo.
itPoint) + delta * targetInfo.
frac;
419 template <
typename BIter,
typename EIter>
422 if (!(begin != end))
return 0.0;
424 double totalLength = 0.0;
426 while (++it != end) {
436 template <
typename BIter,
typename EIter>
438 if (!(begin != end))
return {};
439 std::vector<double> lengths;
441 double totalLength = 0.0;
445 lengths.push_back(totalLength);
447 }
while (++it != end);
453 template <
typename Iter,
typename S
ideFunc>
459 Iter itStart =
begin;
460 auto const startSide = sideOf(*itStart);
461 while (++itStart != end) {
462 if (sideOf(*itStart) != startSide)
break;
465 if (itStart == end)
return {
end, end };
471 Iter itEnd = std::prev(end);
472 auto const endSide = sideOf(*itEnd);
473 while (--itEnd != itStart) {
474 if (sideOf(*itEnd) != endSide)
break;
478 return { itStart, itEnd };
486 #endif // ICARUSALG_UTILITIES_TRAJECTORYUTILS_H
std::vector< double > partialPathLengths(BIter begin, EIter end)
Returns a sequences of partial lengths for the specified path.
double step
Distance from the detected point to the next one.
constexpr bool operator<(CryostatID const &a, CryostatID const &b)
Order cryostats with increasing ID.
Iter itPoint
Iterator to the path point just before the required one.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
auto end(FixedBins< T, C > const &) noexcept
Utilities to extend the interface of geometry vectors.
double length
Path length; negative means not available.
PathPointInfo_t< FIter > findMiddlePointInPath(FIter itFirst, LIter itLast, double relTarget=0.5)
Returns information to identify the middle of the specified path.
double pathLength(BIter begin, EIter end)
Returns the total length of the specified path.
auto norm(Vector const &v)
Return norm of the specified vector.
auto begin(FixedBins< T, C > const &) noexcept
double frac
The point is frac*step away from the point.
auto pathMiddlePoint(FIter itFirst, LIter itLast, double relTarget=0.5)
Returns the geometric point in the middle of the specified path.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::pair< Iter, Iter > findCrossingSegment(Iter begin, Iter end, SideFunc sideOf)
Returns a path segment with ends on different sides than path ends.
Data returned by findMiddlePointInPath().