LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CryostatGeo.h
Go to the documentation of this file.
1 #ifndef LARCOREALG_GEOMETRY_CRYOSTATGEO_H
9 #define LARCOREALG_GEOMETRY_CRYOSTATGEO_H
10 
11 // LArSoft libraries
14 #include "larcorealg/Geometry/LocalTransformationGeo.h" // for LocalT...
18 #include "larcorealg/Geometry/WireGeo.h" // for WireGeo
19 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect
21 #include "larcoreobj/SimpleTypesAndConstants/geo_vectors.h" // geo::Point_t
22 
23 // ROOT libraries
24 #include "Math/GenVector/DisplacementVector3D.h"
25 #include "Math/GenVector/PositionVector3D.h"
26 #include "Math/GenVector/Transform3D.h"
27 #include "TGeoVolume.h"
28 
29 // C/C++ standard libraries
30 #include <string>
31 #include <vector>
32 
33 // forward declarations
34 class TGeoNode;
35 
36 namespace geo {
37 
38  class GeoObjectSorter;
39 
40  //......................................................................
44 
45  public:
46  using ID_t = CryostatID;
47 
49  using TPCList_t = std::vector<geo::TPCGeo>;
50 
52  using OpDetList_t = std::vector<geo::OpDetGeo>;
53 
55 
57  using ElementIteratorBox = TPCList_t const&;
58 
60 
75  struct CryostatGeoCoordinatesTag {};
77 
80 
83 
85 
87  CryostatGeo(TGeoNode const& node,
89  TPCList_t&& TPCs,
90  OpDetList_t&& OpDets);
91 
94 
96  double HalfWidth() const;
98  double HalfHeight() const;
100  double HalfLength() const;
102  double Width() const { return 2. * HalfWidth(); }
104  double Height() const { return 2. * HalfHeight(); }
106  double Length() const { return 2. * HalfLength(); }
108  double Mass() const { return fVolume->Weight(); }
110  const TGeoVolume* Volume() const { return fVolume; }
111 
114  geo::BoxBoundedGeo const& Boundaries() const { return BoundingBox(); }
115 
118  void Boundaries(double* boundaries) const;
119 
121  geo::Point_t GetCenter() const { return Boundaries().Center(); }
122 
125  {
126  return static_cast<geo::BoxBoundedGeo const&>(*this);
127  }
128 
130  geo::CryostatID const& ID() const { return fID; }
131 
153  template <typename Stream>
154  void PrintCryostatInfo(Stream&& out, std::string indent = "", unsigned int verbosity = 1) const;
155 
163  std::string CryostatInfo(std::string indent = "", unsigned int verbosity = 1) const;
164 
166  static constexpr unsigned int MaxVerbosity = 3;
167 
169 
170  // BEGIN TPC access --------------------------------------------------------
173 
175  unsigned int NTPC() const { return fTPCs.size(); }
177  unsigned int NElements() const { return fTPCs.size(); }
178 
184  bool HasTPC(unsigned int itpc) const { return itpc < NTPC(); }
185 
187  bool HasElement(unsigned int itpc) const { return HasTPC(itpc); }
188 
197  bool HasTPC(geo::TPCID const& tpcid) const { return HasTPC(tpcid.TPC); }
199  bool HasElement(geo::TPCID const& tpcid) const { return HasTPC(tpcid); }
200 
203  const TPCGeo& TPC(unsigned int itpc) const;
204 
214  const TPCGeo& TPC(TPCID const& tpcid) const { return TPC(tpcid.TPC); }
216  const TPCGeo& GetElement(TPCID const& tpcid) const { return TPC(tpcid); }
217 
234 
250 
256  TPCGeo const* TPCPtr(unsigned int itpc) const
257  {
258  return HasTPC(itpc) ? &(fTPCs[itpc]) : nullptr;
259  }
260 
269  TPCGeo const* TPCPtr(TPCID const& tpcid) const { return TPCPtr(tpcid.TPC); }
271  TPCGeo const* GetElementPtr(TPCID const& tpcid) const { return TPCPtr(tpcid); }
272 
279  geo::TPCID PositionToTPCID(geo::Point_t const& point, double wiggle) const;
280 
287  TPCGeo const& PositionToTPC(geo::Point_t const& point, double wiggle) const;
294  TPCGeo const& PositionToTPC(double const worldLoc[3], double wiggle) const
295  {
296  return PositionToTPC(geo::vect::makePointFromCoords(worldLoc), wiggle);
297  }
298 
305  geo::TPCGeo const* PositionToTPCptr(geo::Point_t const& point, double wiggle) const;
306 
308  unsigned int MaxPlanes() const;
309 
311  unsigned int MaxWires() const;
312 
314  // END TPC access ----------------------------------------------------------
315 
316  // BEGIN Optical detector access -------------------------------------------
319 
321  unsigned int NOpDet() const { return fOpDets.size(); }
322 
324  const OpDetGeo& OpDet(unsigned int iopdet) const;
325 
328  unsigned int GetClosestOpDet(geo::Point_t const& point) const;
330  unsigned int GetClosestOpDet(double const* point) const;
331 
334  geo::OpDetGeo const* GetClosestOpDetPtr(geo::Point_t const& point) const;
335 
337  std::string OpDetGeoName() const { return fOpDetGeoName; }
338 
340  // END Optical detector access ---------------------------------------------
341 
342  // BEGIN Coordinate transformation -----------------------------------------
345 
348  {
349  return fTrans.toWorldCoords(local);
350  }
351 
354  {
355  return fTrans.toWorldCoords(local);
356  }
357 
360  {
361  return fTrans.toLocalCoords(world);
362  }
363 
366  {
367  return fTrans.toLocalCoords(world);
368  }
369 
371  // END Coordinate transformation -------------------------------------------
372 
374  void SortSubVolumes(geo::GeoObjectSorter const& sorter);
375 
377  void UpdateAfterSorting(geo::CryostatID cryoid);
378 
379  private:
380  void FindTPC(std::vector<const TGeoNode*>& path, unsigned int depth);
381  void MakeTPC(std::vector<const TGeoNode*>& path, int depth);
382 
383  void FindOpDet(std::vector<const TGeoNode*>& path, unsigned int depth);
384  void MakeOpDet(std::vector<const TGeoNode*>& path, int depth);
385 
387  void InitCryoBoundaries();
388 
389  private:
390  using LocalTransformation_t =
392 
396  TGeoVolume* fVolume;
397  std::string fOpDetGeoName;
399  };
400 }
401 
402 //------------------------------------------------------------------------------
403 //--- template implementation
404 //---
405 template <typename Stream>
407  std::string indent /* = "" */,
408  unsigned int verbosity /* = 1 */
409 ) const
410 {
411 
412  //----------------------------------------------------------------------------
413  out << "Cryostat " << std::string(ID());
414 
415  if (verbosity-- <= 0) return; // 0
416 
417  //----------------------------------------------------------------------------
418  out << " (" << Width() << " x " << Height() << " x " << Length() << ") cm^3 at " << GetCenter();
419 
420  if (verbosity-- <= 0) return; // 1
421 
422  //----------------------------------------------------------------------------
423 
424  out << "\n"
425  << indent << "hosts " << NTPC() << " TPCs (largest number of planes: " << MaxPlanes()
426  << ", of wires: " << MaxWires() << ") and " << NOpDet() << " optical detectors";
427 
428  if (verbosity-- <= 0) return; // 2
429 
430  //----------------------------------------------------------------------------
431  // print also the containing box
432  geo::BoxBoundedGeo const& box = BoundingBox();
433  out << "\n" << indent << "bounding box: " << box.Min() << " -- " << box.Max();
434 
435  // if (verbosity-- <= 0) return; // 3
436 
437  //----------------------------------------------------------------------------
438 } // geo::CryostatGeo::PrintCryostatInfo()
439 
440 //------------------------------------------------------------------------------
441 
442 #endif // LARCOREALG_GEOMETRY_CRYOSTATGEO_H
443 
LocalPoint_t toLocalCoords(geo::Point_t const &world) const
Transform point from world frame to local cryostat frame.
Definition: CryostatGeo.h:359
void InitCryoBoundaries()
Fill the boundary information of the cryostat.
unsigned int GetClosestOpDet(geo::Point_t const &point) const
geo::Point_t GetCenter() const
Returns the geometrical center of the cryostat.
Definition: CryostatGeo.h:121
IDparameter< geo::CryostatID > CryostatID
Member type of validated geo::CryostatID parameter.
double HalfLength() const
Half height of the cryostat [cm].
std::vector< geo::OpDetGeo > OpDetList_t
Type used internally to store the optical detectors.
Definition: CryostatGeo.h:52
TPCGeo const * TPCPtr(TPCID const &tpcid) const
Returns the TPC in tpcid from this cryostat.
Definition: CryostatGeo.h:269
geo::Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: CryostatGeo.h:353
unsigned int MaxPlanes() const
Returns the largest number of planes among the TPCs in this cryostat.
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
double Mass() const
Mass of the cryostat.
Definition: CryostatGeo.h:108
TGeoVolume * fVolume
Total volume of cryostat, called volCryostat in GDML file.
Definition: CryostatGeo.h:396
LocalVector_t toLocalCoords(geo::Vector_t const &world) const
Transform direction vector from world to local.
Definition: CryostatGeo.h:365
Geometry information for a single TPC.
Definition: TPCGeo.h:36
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
ElementIteratorBox IterateTPCs() const
Returns an object suitable for iterating through all TPCs.
Definition: CryostatGeo.h:249
std::vector< geo::TPCGeo > TPCList_t
Type used internally to store the TPCs.
Definition: CryostatGeo.h:49
OpDetList_t fOpDets
List of opdets in this cryostat.
Definition: CryostatGeo.h:395
CryostatGeo(TGeoNode const &node, geo::TransformationMatrix &&trans, TPCList_t &&TPCs, OpDetList_t &&OpDets)
Construct a representation of a single cryostat of the detector.
Definition: CryostatGeo.cxx:32
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
geo::BoxBoundedGeo const & BoundingBox() const
Returns the bounding box of this cryostat.
Definition: CryostatGeo.h:124
TPCGeo const & PositionToTPC(double const worldLoc[3], double wiggle) const
Returns the ID of the TPC at specified location.
Definition: CryostatGeo.h:294
geo::TPCGeo const * PositionToTPCptr(geo::Point_t const &point, double wiggle) const
Returns a pointer to the TPC at specified location.
TPCGeo const * GetElementPtr(TPCID const &tpcid) const
Alias for TPCPtr().
Definition: CryostatGeo.h:271
std::string fOpDetGeoName
Name of opdet geometry elements in gdml.
Definition: CryostatGeo.h:397
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Method to sort TPCGeo objects.
Definition: CryostatGeo.cxx:55
std::string OpDetGeoName() const
Get name of opdet geometry element.
Definition: CryostatGeo.h:337
Tag for vectors in the "local" GDML coordinate frame of the cryostat.
Definition: CryostatGeo.h:76
bool HasElement(unsigned int itpc) const
Alias for HasTPC().
Definition: CryostatGeo.h:187
void PrintCryostatInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this cryostat.
Definition: CryostatGeo.h:406
geo::OpDetGeo const * GetClosestOpDetPtr(geo::Point_t const &point) const
const TGeoVolume * Volume() const
Pointer to ROOT&#39;s volume descriptor.
Definition: CryostatGeo.h:110
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet&#39;th optical detector in the cryostat.
Definition: CryostatGeo.cxx:95
Local-to-world transformations with LArSoft geometry vectors.
Definitions of geometry vector data types.
double Height() const
Full height of the cryostat [cm].
Definition: CryostatGeo.h:104
geo::Point3DBase_t< CryostatGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML cryostat frame.
Definition: CryostatGeo.h:79
std::string indent(std::size_t const i)
double HalfWidth() const
Half width of the cryostat [cm].
unsigned int NElements() const
Alias for NTPC().
Definition: CryostatGeo.h:177
Utilities to extend the interface of geometry vectors.
double Width() const
Full width of the cryostat [cm].
Definition: CryostatGeo.h:102
TPCGeo const * TPCPtr(unsigned int itpc) const
Returns the TPC number itpc from this cryostat.
Definition: CryostatGeo.h:256
unsigned int NTPC() const
Number of TPCs in this cryostat.
Definition: CryostatGeo.h:175
geo::CryostatID fID
ID of this cryostat.
Definition: CryostatGeo.h:398
geo::Point_t Min() const
Returns the corner point with the smallest coordinates.
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
void FindOpDet(std::vector< const TGeoNode * > &path, unsigned int depth)
Definition of data types for geometry description.
unsigned int MaxWires() const
Returns the largest number of wires among the TPCs in this cryostat.
void UpdateAfterSorting(geo::CryostatID cryoid)
Performs all needed updates after geometry has sorted the cryostats.
Definition: CryostatGeo.cxx:67
Provides a base class aware of world box coordinates.
Encapsulate the geometry of a wire.
double HalfHeight() const
Half height of the cryostat [cm].
TPCList_t const & ElementIteratorBox
Type returned by IterateElements().
Definition: CryostatGeo.h:57
Encapsulate the geometry of an optical detector.
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintCryostatInfo().
Definition: CryostatGeo.h:166
std::string CryostatInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with cryostat 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
void FindTPC(std::vector< const TGeoNode * > &path, unsigned int depth)
Selection of the type of transformation matrix used in geometry.
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
std::vector< TGeoNode const * > GeoNodePath_t
Definition: WireGeo.h:117
TPCList_t fTPCs
List of tpcs in this cryostat.
Definition: CryostatGeo.h:394
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:84
unsigned int NOpDet() const
Number of optical detectors in this TPC.
Definition: CryostatGeo.h:321
void MakeOpDet(std::vector< const TGeoNode * > &path, int depth)
geo::Vector3DBase_t< CryostatGeoCoordinatesTag > LocalVector_t
Type of displacement vectors in the local GDML cryostat frame.
Definition: CryostatGeo.h:82
bool HasElement(geo::TPCID const &tpcid) const
Alias for HasTPC(geo::TPCID const&)
Definition: CryostatGeo.h:199
const TPCGeo & TPC(TPCID const &tpcid) const
Returns the TPC in tpcid from this cryostat.
Definition: CryostatGeo.h:214
bool HasTPC(geo::TPCID const &tpcid) const
Returns whether the TPC in tpcid is present in this cryostat.
Definition: CryostatGeo.h:197
LocalTransformation_t fTrans
Cryostat-to-world transformation.
Definition: CryostatGeo.h:393
GenPoint3DBase_t< double, C > Point3DBase_t
Type of 3D point with representation in double precision.
Definition: geo_vectors.h:88
geo::BoxBoundedGeo const & Boundaries() const
Returns boundaries of the cryostat (in centimetres).
Definition: CryostatGeo.h:114
GenVector3DBase_t< double, C > Vector3DBase_t
Definition: geo_vectors.h:83
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
bool HasTPC(unsigned int itpc) const
Returns whether a TPC with index itpc is present in this cryostat.
Definition: CryostatGeo.h:184
geo::WireGeo::GeoNodePath_t GeoNodePath_t
Definition: CryostatGeo.h:54
TPCGeo const & PositionToTPC(geo::Point_t const &point, double wiggle) const
Returns the ID of the TPC at specified location.
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:399
void MakeTPC(std::vector< const TGeoNode * > &path, int depth)
GENVECTOR_CONSTEXPR::geo::Point_t makePointFromCoords(Coords &&coords)
Creates a geo::Point_t from its coordinates (see makeFromCoords()).
Namespace collecting geometry-related classes utilities.
geo::Point_t Max() const
Returns the corner point with the largest coordinates.
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local cryostat frame to world frame.
Definition: CryostatGeo.h:347
geo::TPCID PositionToTPCID(geo::Point_t const &point, double wiggle) const
Returns the ID of the TPC at specified location.
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.
Specialization of local-to-world transformations for ROOT GenVector.
double Length() const
Length of the cryostat [cm].
Definition: CryostatGeo.h:106
Encapsulate the construction of a single detector plane.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:192
const TPCGeo & GetElement(TPCID const &tpcid) const
Alias for TPC().
Definition: CryostatGeo.h:216
geo::Point_t Center() const
Returns the center point of the box.
geo::CryostatID const & ID() const
Returns the identifier of this cryostat.
Definition: CryostatGeo.h:130
ElementIteratorBox IterateElements() const
Returns an object suitable for iterating through all TPCs.