LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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
18 
19 // C/C++ standard libraries
20 #include <vector>
21 #include <string>
22 #include <functional> // std::less()
23 #include <algorithm> // std::upper_bound()
24 #include <utility> // std::forward()
25 #include <memory> // std::unique_ptr()
26 #include <type_traits> // std::decay_t<>, std::declval()
27 
28 
29 namespace geo {
30 
31  namespace part {
32 
33  //--------------------------------------------------------------------------
35  template <>
37  template <typename Stream>
39  Stream&& out, geo::TPCGeo const* pTPC,
40  std::string indent = "", std::string firstIndent = ""
41  );
42  }; // PartitionDataDescriber(TPCGeo)
43 
44  //--------------------------------------------------------------------------
45 
46  } // namespace part
47 
48 
49  namespace details {
50 
51  //--------------------------------------------------------------------------
53  template <typename T>
54  auto static_less(T a, T b)
55  { return std::less<T>()(a, b); }
56 
57  //--------------------------------------------------------------------------
59  template <
60  typename T, typename Key,
61  Key KeyExtractor(T const&),
62  bool KeyComparer(Key, Key) = static_less<Key>
63  >
64  struct Comparer;
65 
66  //--------------------------------------------------------------------------
67 
68  } // namespace details
69 
70 
71  // --- BEGIN -----------------------------------------------------------------
74 
82 
83  public:
86 
89 
91  struct DriftVolume_t {
93  std::unique_ptr<TPCPartition_t> partition;
96 
99  (std::unique_ptr<TPCPartition_t>&& part, Range_t const& cover)
100  : partition(std::move(part)), driftCoverage(cover) {}
101 
103  bool coversDrift(double drift) const
104  { return driftCoverage.contains(drift); }
105 
107  static double Position(DriftVolume_t const& part)
108  { return part.driftCoverage.lower; }
109 
111  using Comparer_t
113 
114  }; // DriftPartitions::DriftVolume_t
115 
116 
119 
122 
124  using Projection_t
125  = ROOT::Math::DisplacementVector2D<ROOT::Math::Cartesian2D<double>>;
126 
129 
132 
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
146  { return decomposer.PointNormalComponent(pos); }
147 
150  DriftVolume_t const* driftVolumeAt(Position_t const& pos) const
151  { return driftVolumeAt(driftCoord(pos)); }
152 
154  DriftVolume_t const* driftVolumeAt(double drift) const;
155 
157  geo::TPCGeo const* TPCat(Position_t const& pos) const;
158 
160 
162  template <typename Stream>
163  void print(Stream&& out) const;
164 
166  void addPartition(std::unique_ptr<TPCPartition_t>&& part);
167 
168 
169  private:
170 
172  std::vector<DriftVolume_t>::iterator volumeAfter(double pos);
173 
175  std::vector<DriftVolume_t>::const_iterator volumeAfter(double pos) const;
176 
178  Range_t computeCoverage(TPCPartition_t const& TPCpart) const;
179 
180  }; // class DriftPartitions
181 
182 
183  //----------------------------------------------------------------------------
204 
205 
207  // --- END -------------------------------------------------------------------
208 
209 } // namespace geo
210 
211 
212 //------------------------------------------------------------------------------
213 //--- inline and template implementation
214 //---
215 //------------------------------------------------------------------------------
216 namespace geo {
217  namespace details {
218 
219  //--------------------------------------------------------------------------
220  // TODO use SorterByKey instead?
221  template <
222  typename T, typename Key,
223  Key KeyExtractor(T const&),
224  bool KeyComparer(Key, Key) /* = static_less<Key> */
225  >
226  struct Comparer {
227  using Key_t = Key;
228  using Object_t = T;
229 
230  bool operator() (Key_t a, Key_t b) const { return key_comp(a, b); }
231  bool operator() (Object_t const& a, Key_t b) const
232  { return this->operator() (key(a), b); }
233  bool operator() (Key_t a, Object_t const& b) const
234  { return this->operator() (a, key(b)); }
235  bool operator() (Object_t const& a, Object_t const& b) const
236  { return this->operator() (key(a), b); }
237 
238  private:
239  static auto key(T const& v) { return KeyExtractor(v); }
240  static auto key_comp(Key_t a, Key_t b) { return KeyComparer(a, b); }
241 
242  }; // struct Comparer<>
243 
244  //--------------------------------------------------------------------------
245 
246  } // namespace details
247 } // namespace geo
248 
249 
250 //------------------------------------------------------------------------------
251 template <typename Stream>
253  Stream&& out, geo::TPCGeo const* pTPC,
254  std::string indent /* = "" */, std::string firstIndent /* = "" */
255  )
256 {
257  out << firstIndent;
258  if (!pTPC) {
259  out << "no TPC";
260  return;
261  }
262  // verbosity: 2 => ID, size, drift information;
263  // 5: also number of wires and active volume
264  pTPC->PrintTPCInfo(std::forward<Stream>(out), indent, 2U);
265 } // geo::part::PartitionDataDescriber<TPCGeo>::PartitionDataDescriber()
266 
267 
268 //------------------------------------------------------------------------------
269 //--- geo::DriftPartitions
270 //---
271 inline auto geo::DriftPartitions::volumeAfter(double pos)
273 {
274  return std::upper_bound
275  (volumes.begin(), volumes.end(), pos, DriftVolume_t::Comparer_t());
276 } // geo::DriftPartitions::volumeAfter()
277 
278 inline auto geo::DriftPartitions::volumeAfter(double pos) const
280 {
281  return std::upper_bound
282  (volumes.begin(), volumes.end(), pos, DriftVolume_t::Comparer_t());
283 } // geo::DriftPartitions::volumeAfter()
284 
285 
286 //------------------------------------------------------------------------------
287 template <typename Stream>
288 void geo::DriftPartitions::print(Stream&& out) const {
289 
290  out << volumes.size() << " drift volume partitions:";
291  for (auto const& driftVol: volumes) {
292  out << "\n[" << driftVol.driftCoverage.lower
293  << " -- " << driftVol.driftCoverage.upper << "]: "
294  << driftVol.partition->describe(" ", "");
295  } // for
296  out << "\n";
297 } // geo::DriftPartitions::print()
298 
299 
300 //------------------------------------------------------------------------------
301 
302 #endif // LARCOREALG_GEOMETRY_DRIFTPARTITIONS_H
double driftCoord(Position_t const &pos) const
Returns drift coordinate (in the drift-volume-specific frame) of pos.
std::unique_ptr< TPCPartition_t > partition
A partition of the volume in width and depth.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:167
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:703
auto PointNormalComponent(Point_t const &point) const
Returns the secondary component of a point.
Definition: Decomposer.h:486
static double Position(DriftVolume_t const &part)
Returns the drift coordinate of the specified partition.
intermediate_table::iterator iterator
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.
Geometry information for a single TPC.
Definition: TPCGeo.h:37
Class providing custom dump for data contained in the partition.
Definition: Partitions.h:97
DriftPartitions buildDriftVolumes(geo::CryostatGeo const &cryo)
Creates a DriftPartitions object from the TPCs in a cryostat.
Geometry information for a single cryostat.
Definition: CryostatGeo.h:36
DriftPartitions(Decomposer_t const &decomp)
Constructor: no partition, but sets the main "drift" direction.
Base element of a partitioned structure.
Definition: Partitions.h:188
DriftVolume_t const * driftVolumeAt(Position_t const &pos) const
intermediate_table::const_iterator const_iterator
geo::Point_t Position_t
Type representing a position in 3D space.
Classes to project and compose a vector on a plane.
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)
TString part[npart]
Definition: Style.C:32
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:344
void print(Stream &&out) const
Printout of the drift volume information.
std::vector< DriftVolume_t > volumes
All drift volumes, sorted by position.
auto static_less(T a, T b)
Function translation of std::less.
ROOT::Math::DisplacementVector2D< ROOT::Math::Cartesian2D< double >> Projection_t
Type representing a position in the 2D space.
Set of drift volumes.
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:326
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:187
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:767
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).