All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMTsorting.cxx
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Geometry/details/PMTsorting.cxx
3  * @brief PMT sorting functions for ICARUS.
4  * @date April 26, 2020
5  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
6  * @see icarusalg/Geometry/details/PMTsorting.h
7  */
8 
9 
10 // library header
12 
13 // LArSoft libraries
14 // #include "larcorealg/CoreUtils/span.h"
15 
16 // C/C++ standard libraries
17 #include <vector>
18 #include <iterator> // std::next(), std::prev()
19 #include <algorithm> // std::sort(), std::stable_sort()
20 #include <cassert>
21 
22 
23 // -----------------------------------------------------------------------------
24 void icarus::PMTsorterStandard::sort(std::vector<geo::OpDetGeo>& opDets) const {
25  assert(opDets.size() % 2 == 0); // must be even!
26 
27  /*
28  * 1. sort all optical detectors by _x_
29  * 2. split them by plane
30  * 3. sort the detectors within each plane.
31  */
32 
33  //
34  // 1. sort all optical detectors by _x_
35  //
36  std::sort(begin(opDets), end(opDets), fSmallerCenterX);
37 
38  //
39  // 2. split them by plane: we take a horrible shortcut here...
40  //
41 
42  std::vector<OpDetSpan_t> OpDetsPerPlane;
43 
44  // just split the list in two
45  auto const middle = std::next(opDets.begin(), opDets.size() / 2U);
46  assert(fSmallerCenterX(*std::prev(middle), *middle));
47 
48  OpDetsPerPlane.emplace_back(opDets.begin(), middle);
49  OpDetsPerPlane.emplace_back(middle, opDets.end());
50  assert(OpDetsPerPlane[0].size() == OpDetsPerPlane[1].size());
51 
52  //
53  // 3. sort the detectors within each plane.
54  //
55  for (auto const& planeOpDets: OpDetsPerPlane)
56  sortInPlane(util::make_span(planeOpDets));
57 
58  // all done in place, no return
59 
60 } // icarus::PMTsorterStandard::sort()
61 
62 
63 // -----------------------------------------------------------------------------
65  /*
66  * 0. assume it's already sorted by _x_
67  * 1. sort by vertical coordinate (_y_)
68  * 2. stable sort by beam coordinate (_z_)
69  */
70 
71  // 1. sort by vertical coordinate (_y_)
72  std::stable_sort(begin(opDets), end(opDets), fSmallerCenterY);
73 
74  // 2. stable sort by beam coordinate (_z_)
75  std::stable_sort(begin(opDets), end(opDets), fSmallerCenterZ);
76 
77 } // icarus::PMTsorterStandard::sortInPlane()
78 
79 
80 // -----------------------------------------------------------------------------
OpDetGeoCenterCoordComparer<&geo::Point_t::X > const fSmallerCenterX
Sorting criterium according to x coordinate of geo::OpDetGeo center.
Definition: PMTsorting.h:152
auto make_span(BIter begin, EIter end)
Creates a span from specified iterators (can use constructor instead).
Definition: span.h:197
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
Simple class with a begin and an end.
Definition: span.h:125
void sortInPlane(OpDetSpan_t const &opDets) const
Sorts the geo::OpDetGeo assuming they belong to the same plane.
Definition: PMTsorting.cxx:64
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
Geometry obect sorter with PMT following TPC wire order.
void sort(std::vector< geo::OpDetGeo > &opDets) const
Sorts the specified optical detectors.
Definition: PMTsorting.cxx:24