All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMTsorting.h
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Geometry/details/PMTsorting.h
3  * @brief Geometry obect sorter with PMT following TPC wire order.
4  * @date April 26, 2020
5  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
6  * @see icarusalg/Geometry/details/PMTsorting.cxx
7  */
8 
9 #ifndef ICARUSALG_GEOMETRY_DETAILS_PMTSORTING_H
10 #define ICARUSALG_GEOMETRY_DETAILS_PMTSORTING_H
11 
12 
13 // LArSoft libraries
16 #include "larcorealg/CoreUtils/span.h" // util::span
17 #include "larcoreobj/SimpleTypesAndConstants/geo_vectors.h" // geo::Point_t
18 
19 // framework libraries
20 #include "fhiclcpp/types/Atom.h"
21 
22 // C/C++ standard libraries
23 #include <vector>
24 
25 
26 // -----------------------------------------------------------------------------
27 namespace icarus { class PMTsorterStandard; }
28 
29 /**
30  * @brief Sorter sorting PMT to follow the same order as TPC (standard).
31  *
32  * This class sorts the elements of the LArSoft detector description.
33  * The "standard" algorithm (`geo::GeoObjectSorterStandard`) arranges TPC
34  * elements with x, then z, then y. The PMT are arranged so that their channels
35  * mimic the order of the TPC channels.
36  *
37  * The algorithm for assigning channels to the PMT follows the criteria:
38  *
39  * * PMT are ordered by increasing _x_ (related to drift direction);
40  * * channels are assigned value ranges increasing with _x_ coordinate;
41  * * within a wire plane, PMT number increases with its _z_ (beam direction)
42  * coordinate;
43  * * in case of same _z_ (in ICARUS all PMT are in 2- or 3-PMT "towers"), an
44  * increasing _y_ order (geographical vertical, toward the sky) is chosen.
45  *
46  * PMT channels are assigned by a fixed LArSoft algorithm, cryostat by cryostat
47  * with increasing cryostat number (first `C:0`, then `C:1`, ...).
48  *
49  *
50  * Configuration parameters
51  * -------------------------
52  *
53  * This sorter supports the following parameters:
54  *
55  * * `ToleranceX`, `ToleranceY`, `ToleranceZ` (double, default: `1.0`):
56  * rounding used for sorting optical detector position, in centimeters;
57  * if the coordinate of two optical detectors are closer than the tolerance
58  * for that coordinate (absolute), they two detectors are considered to be at
59  * the same position in that coordinate
60  * (note that the default value is very generous).
61  *
62  */
64 
65  /// List of optical detector pointers for sorting.
66  using OpDetList_t = std::vector<geo::OpDetGeo>;
67 
68  /// Part of list of optical detector pointers for sorting.
70 
71  public:
72 
73  struct Config {
74 
75  using Name = fhicl::Name;
76  using Comment = fhicl::Comment;
77 
78  fhicl::Atom<double> ToleranceX {
79  Name("ToleranceX"),
80  Comment("tolerance when sorting optical detectors on x coordinate [cm]"),
81  1.0 // default
82  };
83 
84  fhicl::Atom<double> ToleranceY {
85  Name("ToleranceY"),
86  Comment("tolerance when sorting optical detectors on x coordinate [cm]"),
87  1.0 // default
88  };
89 
90  fhicl::Atom<double> ToleranceZ {
91  Name("ToleranceZ"),
92  Comment("tolerance when sorting optical detectors on x coordinate [cm]"),
93  1.0 // default
94  };
95 
96  }; // Config
97 
98 
99  /// Constructor: passes the configuration to the base class.
100  PMTsorterStandard(Config const& config)
101  : fSmallerCenterX{ config.ToleranceX() }
102  , fSmallerCenterY{ config.ToleranceY() }
103  , fSmallerCenterZ{ config.ToleranceZ() }
104  {}
105 
106 
107  // @{
108  /**
109  * @brief Sorts the specified optical detectors.
110  * @param opDets collection of pointers to all optical detectors in a cryostat
111  *
112  * The collection `opDets` of optical detectors is sorted in place.
113  * Sorting criteria are documented in `icarus::GeoObjectSorterPMTasTPC` class
114  * documentation.
115  *
116  * This algorithm requires all optical detectors to have their center defined
117  * (`geo::OpDetGeo::GetCenter()`). No other information is used.
118  *
119  * @note The current implementation is very sensitive to rounding errors!
120  *
121  */
122  void sort(std::vector<geo::OpDetGeo>& opDets) const;
123 
124  void operator() (std::vector<geo::OpDetGeo>& opDets) const { sort(opDets); }
125  // @}
126 
127 
128  private:
129 
130  /// `geo::OpDetGeo` comparer according to one coordinate of their center.
131  /// Accomodates for some tolerance.
132  template <double (geo::Point_t::*Coord)() const>
134 
135  /// Object used for comparison; includes a tolerance.
137 
138  /// Constructor: fixes the tolerance for the comparison.
140 
141  /// Returns whether `A` has a center coordinate `Coord` smaller than `B`.
142  bool operator() (geo::OpDetGeo const& A, geo::OpDetGeo const& B) const
143  {
144  return fCmp.strictlySmaller
145  ((A.GetCenter().*Coord)(), (B.GetCenter().*Coord)());
146  }
147 
148  }; // OpDetGeoCenterCoordComparer
149 
150 
151  /// Sorting criterium according to _x_ coordinate of `geo::OpDetGeo` center.
153 
154  /// Sorting criterium according to _y_ coordinate of `geo::OpDetGeo` center.
156 
157  /// Sorting criterium according to _z_ coordinate of `geo::OpDetGeo` center.
159 
160 
161  /// Sorts the `geo::OpDetGeo` assuming they belong to the same plane.
162  void sortInPlane(OpDetSpan_t const& opDets) const;
163 
164 }; // icarus::PMTsorterStandard
165 
166 
167 // -----------------------------------------------------------------------------
168 
169 
170 #endif // ICARUSALG_GEOMETRY_DETAILS_PMTSORTING_H
OpDetGeoCenterCoordComparer<&geo::Point_t::X > const fSmallerCenterX
Sorting criterium according to x coordinate of geo::OpDetGeo center.
Definition: PMTsorting.h:152
OpDetGeoCenterCoordComparer(double tol=0.0)
Constructor: fixes the tolerance for the comparison.
Definition: PMTsorting.h:139
OpDetGeoCenterCoordComparer<&geo::Point_t::Y > const fSmallerCenterY
Sorting criterium according to y coordinate of geo::OpDetGeo center.
Definition: PMTsorting.h:155
An object with a begin and end iterator.
std::vector< geo::OpDetGeo > OpDetList_t
List of optical detector pointers for sorting.
Definition: PMTsorting.h:66
bool operator()(geo::OpDetGeo const &A, geo::OpDetGeo const &B) const
Returns whether A has a center coordinate Coord smaller than B.
Definition: PMTsorting.h:142
auto const tol
Definition: SurfXYZTest.cc:16
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
fhicl::Atom< double > ToleranceZ
Definition: PMTsorting.h:90
PMTsorterStandard(Config const &config)
Constructor: passes the configuration to the base class.
Definition: PMTsorting.h:100
Simple class with a begin and an end.
Definition: span.h:125
Class for approximate comparisons.
constexpr bool strictlySmaller(Value_t a, Value_t b) const
Returns whether a is strictly smaller than b.
void sortInPlane(OpDetSpan_t const &opDets) const
Sorts the geo::OpDetGeo assuming they belong to the same plane.
Definition: PMTsorting.cxx:64
Definitions of geometry vector data types.
Sorter sorting PMT to follow the same order as TPC (standard).
Definition: PMTsorting.h:63
OpDetGeoCenterCoordComparer<&geo::Point_t::Z > const fSmallerCenterZ
Sorting criterium according to z coordinate of geo::OpDetGeo center.
Definition: PMTsorting.h:158
BEGIN_PROLOG vertical distance to the surface Name
void operator()(std::vector< geo::OpDetGeo > &opDets) const
Definition: PMTsorting.h:124
Encapsulate the geometry of an optical detector.
fhicl::Atom< double > ToleranceY
Definition: PMTsorting.h:84
fhicl::Atom< double > ToleranceX
Definition: PMTsorting.h:78
void sort(std::vector< geo::OpDetGeo > &opDets) const
Sorts the specified optical detectors.
Definition: PMTsorting.cxx:24
float A
Definition: dedx.py:137
lar::util::RealComparisons< double > const fCmp
Object used for comparison; includes a tolerance.
Definition: PMTsorting.h:136