LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DriftPartitions.h
Go to the documentation of this file.
1 
11 #ifndef LARCOREALG_GEOMETRY_DRIFTPARTITIONS_H
12 #define LARCOREALG_GEOMETRY_DRIFTPARTITIONS_H
13 
14 // LArSoft libraries
20 
21 // ROOT libraries
22 #include "Math/GenVector/Cartesian2D.h"
23 #include "Math/GenVector/DisplacementVector2D.h"
24 
25 // C/C++ standard libraries
26 #include <algorithm> // std::upper_bound()
27 #include <functional> // std::less()
28 #include <memory> // std::unique_ptr()
29 #include <string>
30 #include <type_traits> // std::decay_t<>, std::declval()
31 #include <utility> // std::forward()
32 #include <vector>
33 
34 namespace geo {
35 
36  class CryostatGeo;
37 
38  namespace part {
39 
40  //--------------------------------------------------------------------------
42  template <>
44  template <typename Stream>
45  PartitionDataDescriber(Stream&& out,
46  geo::TPCGeo const* pTPC,
47  std::string indent = "",
48  std::string firstIndent = "");
49  }; // PartitionDataDescriber(TPCGeo)
50 
51  //--------------------------------------------------------------------------
52 
53  } // namespace part
54 
55  namespace details {
56 
57  //--------------------------------------------------------------------------
59  template <typename T>
60  auto static_less(T a, T b)
61  {
62  return std::less<T>()(a, b);
63  }
64 
65  //--------------------------------------------------------------------------
67  template <typename T,
68  typename Key,
69  Key KeyExtractor(T const&),
70  bool KeyComparer(Key, Key) = static_less<Key>>
71  struct Comparer;
72 
73  //--------------------------------------------------------------------------
74 
75  } // namespace details
76 
77  // --- BEGIN -----------------------------------------------------------------
80 
88 
89  public:
92 
95 
97  struct DriftVolume_t {
99  std::unique_ptr<TPCPartition_t> partition;
102 
104  DriftVolume_t(std::unique_ptr<TPCPartition_t>&& part, Range_t const& cover)
105  : partition(std::move(part)), driftCoverage(cover)
106  {}
107 
109  bool coversDrift(double drift) const { return driftCoverage.contains(drift); }
110 
112  static double Position(DriftVolume_t const& part) { return part.driftCoverage.lower; }
113 
116 
117  }; // DriftPartitions::DriftVolume_t
118 
121 
124 
126  using Projection_t = ROOT::Math::DisplacementVector2D<ROOT::Math::Cartesian2D<double>>;
127 
130 
133 
135  std::vector<DriftVolume_t> volumes;
137 
139  explicit DriftPartitions(Decomposer_t const& decomp) : decomposer(decomp) {}
140 
143 
145  double driftCoord(Position_t const& pos) const { return decomposer.PointNormalComponent(pos); }
146 
149  DriftVolume_t const* driftVolumeAt(Position_t const& pos) const
150  {
151  return driftVolumeAt(driftCoord(pos));
152  }
153 
155  DriftVolume_t const* driftVolumeAt(double drift) const;
156 
158  geo::TPCGeo const* TPCat(Position_t const& pos) const;
159 
161 
163  template <typename Stream>
164  void print(Stream&& out) const;
165 
167  void addPartition(std::unique_ptr<TPCPartition_t>&& part);
168 
169  private:
171  std::vector<DriftVolume_t>::iterator volumeAfter(double pos);
172 
174  std::vector<DriftVolume_t>::const_iterator volumeAfter(double pos) const;
175 
177  Range_t computeCoverage(TPCPartition_t const& TPCpart) const;
178 
179  }; // class DriftPartitions
180 
181  //----------------------------------------------------------------------------
202 
204  // --- END -------------------------------------------------------------------
205 
206 } // namespace geo
207 
208 //------------------------------------------------------------------------------
209 //--- inline and template implementation
210 //---
211 //------------------------------------------------------------------------------
212 namespace geo {
213  namespace details {
214 
215  //--------------------------------------------------------------------------
216  // TODO use SorterByKey instead?
217  template <typename T,
218  typename Key,
219  Key KeyExtractor(T const&),
220  bool KeyComparer(Key, Key) /* = static_less<Key> */
221  >
222  struct Comparer {
223  using Key_t = Key;
224  using Object_t = T;
225 
226  bool operator()(Key_t a, Key_t b) const { return key_comp(a, b); }
227  bool operator()(Object_t const& a, Key_t b) const { return this->operator()(key(a), b); }
228  bool operator()(Key_t a, Object_t const& b) const { return this->operator()(a, key(b)); }
229  bool operator()(Object_t const& a, Object_t const& b) const
230  {
231  return this->operator()(key(a), b);
232  }
233 
234  private:
235  static auto key(T const& v) { return KeyExtractor(v); }
236  static auto key_comp(Key_t a, Key_t b) { return KeyComparer(a, b); }
237 
238  }; // struct Comparer<>
239 
240  //--------------------------------------------------------------------------
241 
242  } // namespace details
243 } // namespace geo
244 
245 //------------------------------------------------------------------------------
246 template <typename Stream>
248  Stream&& out,
249  geo::TPCGeo const* pTPC,
250  std::string indent /* = "" */,
251  std::string firstIndent /* = "" */
252 )
253 {
254  out << firstIndent;
255  if (!pTPC) {
256  out << "no TPC";
257  return;
258  }
259  // verbosity: 2 => ID, size, drift information;
260  // 5: also number of wires and active volume
261  pTPC->PrintTPCInfo(std::forward<Stream>(out), indent, 2U);
262 } // geo::part::PartitionDataDescriber<TPCGeo>::PartitionDataDescriber()
263 
264 //------------------------------------------------------------------------------
265 //--- geo::DriftPartitions
266 //---
268 {
269  return std::upper_bound(volumes.begin(), volumes.end(), pos, DriftVolume_t::Comparer_t());
270 } // geo::DriftPartitions::volumeAfter()
271 
272 inline auto geo::DriftPartitions::volumeAfter(double pos) const
274 {
275  return std::upper_bound(volumes.begin(), volumes.end(), pos, DriftVolume_t::Comparer_t());
276 } // geo::DriftPartitions::volumeAfter()
277 
278 //------------------------------------------------------------------------------
279 template <typename Stream>
280 void geo::DriftPartitions::print(Stream&& out) const
281 {
282 
283  out << volumes.size() << " drift volume partitions:";
284  for (auto const& driftVol : volumes) {
285  out << "\n[" << driftVol.driftCoverage.lower << " -- " << driftVol.driftCoverage.upper
286  << "]: " << driftVol.partition->describe(" ", "");
287  } // for
288  out << "\n";
289 } // geo::DriftPartitions::print()
290 
291 //------------------------------------------------------------------------------
292 
293 #endif // LARCOREALG_GEOMETRY_DRIFTPARTITIONS_H
double driftCoord(Position_t const &pos) const
Returns drift coordinate (in the drift-volume-specific frame) of pos.
intermediate_table::iterator iterator
std::unique_ptr< TPCPartition_t > partition
A partition of the volume in width and depth.
Decomposer_t decomposer
Decomposition on drift, width and depth axes.
void PrintTPCInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this TPC.
Definition: TPCGeo.h:656
auto PointNormalComponent(Point_t const &point) const
Returns the secondary component of a point.
Definition: Decomposer.h:481
bool operator()(Object_t const &a, Key_t b) const
static double Position(DriftVolume_t const &part)
Returns the drift coordinate of the specified partition.
bool operator()(Object_t const &a, Object_t const &b) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
Key Key_t
Type of comparison key.
static auto key(T const &v)
std::vector< DriftVolume_t >::iterator volumeAfter(double pos)
Returns an iterator to the drift volume starting after pos.
bool operator()(Key_t a, Key_t b) const
Geometry information for a single TPC.
Definition: TPCGeo.h:36
STL namespace.
Class providing custom dump for data contained in the partition.
Definition: Partitions.h:96
DriftPartitions buildDriftVolumes(geo::CryostatGeo const &cryo)
Creates a DriftPartitions object from the TPCs in a cryostat.
intermediate_table::const_iterator const_iterator
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
DriftPartitions(Decomposer_t const &decomp)
Constructor: no partition, but sets the main "drift" direction.
Base element of a partitioned structure.
Definition: Partitions.h:183
TString part[npart]
Definition: Style.C:32
DriftVolume_t const * driftVolumeAt(Position_t const &pos) const
geo::Point_t Position_t
Type representing a position in 3D space.
Classes to project and compose a vector on a plane.
Definitions of geometry vector data types.
Classes describing partition of an area with associated data.
T Object_t
Type of object to be compared.
static auto key_comp(Key_t a, Key_t b)
std::string indent(std::size_t const i)
Class managing comparisons between T objects via a Key key.
bool contains(Data_t v) const
Returns whether the specified value is within the range.
Definition: SimpleGeo.h:377
DriftVolume_t(std::unique_ptr< TPCPartition_t > &&part, Range_t const &cover)
Constructor: imports the specified partition and drift coverage range.
void print(Stream &&out) const
Printout of the drift volume information.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
std::vector< DriftVolume_t > volumes
All drift volumes, sorted by position.
auto static_less(T a, T b)
Function translation of std::less.
Some simple functions to represent geometry entities.
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double >> Projection_t
Type representing a position in the 2D space.
Set of drift volumes.
bool operator()(Key_t a, Object_t const &b) const
bool coversDrift(double drift) const
Returns whether this drift volume covers specified drift coordinate.
Direction_t DriftDir_t
Type representing the drift direction (assumed to have norm 1).
Data associated to a single drift volume.
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:358
Namespace collecting geometry-related classes utilities.
PartitionDataDescriber(Stream &&out, Data const *data, std::string indent="", std::string firstIndent="")
Constructor; see describePartitionData() for argument description.
Definition: Partitions.h:715
Encapsulate the construction of a single detector plane.
Range_t driftCoverage
Interval of drift direction covered by this drift volume.
geo::Vector_t Direction_t
Type representing a direction in 3D space (norm is not constrained).