LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
GeometryCore.h
Go to the documentation of this file.
1 
8 #ifndef LARCOREALG_GEOMETRY_GEOMETRYCORE_H
9 #define LARCOREALG_GEOMETRY_GEOMETRYCORE_H
10 
11 // LArSoft libraries
25 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect namespace
26 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
29 
30 // Framework and infrastructure libraries
31 #include "fhiclcpp/fwd.h"
32 
33 // C/C++ standard libraries
34 #include <cstddef> // size_t
35 #include <memory> // std::shared_ptr<>
36 #include <set>
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
41 // ROOT class prototypes
42 class TGeoManager;
43 class TGeoNode;
44 class TGeoVolume;
45 class TGeoMaterial;
46 
48 namespace geo {
49 
50  // BEGIN Geometry group ------------------------------------------------------
53 
91  class GeometryCore : Iterable<details::GeometryIterationPolicy, details::ToGeometryElement> {
93 
94  public:
95  using CryostatList_t = std::vector<CryostatGeo>;
96 
103  GeometryCore(fhicl::ParameterSet const& pset,
104  std::unique_ptr<GeometryBuilder> builder,
105  std::unique_ptr<GeoObjectSorter> sorter);
106  GeometryCore(GeometryCore const&) = delete;
107  GeometryCore(GeometryCore&&) = delete;
108  GeometryCore& operator=(GeometryCore const&) = delete;
109  GeometryCore& operator=(GeometryCore&&) = delete;
110 
121  double DefaultWiggle() const { return fPositionWiggle; }
122 
130  std::string const& GDMLFile() const { return fGDMLfile; }
131 
132  // BEGIN Detector information
135 
136  //
137  // global features
138  //
140  std::string const& DetectorName() const { return fDetectorName; }
141 
142  //
143  // position
144  //
145 
147  TGeoVolume const* WorldVolume() const;
148 
167  void WorldBox(double* xlo, double* xhi, double* ylo, double* yhi, double* zlo, double* zhi)
168  const;
169 
172  BoxBoundedGeo WorldBox() const;
173 
185  //
186  Length_t SurfaceY() const { return fSurfaceY; }
187 
188  //
189  // object description and information
190  //
191 
193  TGeoManager* ROOTGeoManager() const;
194 
196  std::string const& GetWorldVolumeName() const;
197 
201  BoxBoundedGeo DetectorEnclosureBox(std::string const& name = "volDetEnclosure") const;
202 
204 
212  std::string VolumeName(Point_t const& point) const;
214 
224  std::vector<TGeoNode const*> FindAllVolumes(std::set<std::string> const& vol_names) const;
225 
239  std::vector<std::vector<TGeoNode const*>> FindAllVolumePaths(
240  std::set<std::string> const& vol_names) const;
241 
243  TGeoMaterial const* Material(Point_t const& point) const;
245 
250  std::string MaterialName(Point_t const& point) const;
252 
254  double TotalMass() const { return TotalMass(GetWorldVolumeName()); }
256  double TotalMass(std::string vol) const;
258 
260 
273  double MassBetweenPoints(Point_t const& p1, Point_t const& p2) const;
275 
277  template <typename Stream>
278  void Print(Stream&& out, std::string indent = " ") const;
279 
282  std::string Info(std::string indent = " ") const;
283 
285  // END Detector information
286 
289 
290  //
291  // group features
292  //
293 
295 
303  unsigned int Ncryostats() const { return fCryostats.size(); }
304  unsigned int NElements() const { return Ncryostats(); }
305  unsigned int NSiblingElements(CryostatID const&) const { return Ncryostats(); }
307 
308  //
309  // access
310  //
311 
313 
318  bool HasCryostat(CryostatID const& cryoid) const { return cryoid.Cryostat < Ncryostats(); }
319  bool HasElement(CryostatID const& cryoid) const { return HasCryostat(cryoid); }
321 
323 
333  CryostatGeo const& Cryostat(CryostatID const& cryoid = details::cryostat_zero) const;
334  CryostatGeo const& GetElement(CryostatID const& cryoid) const { return Cryostat(cryoid); }
336 
338 
345  CryostatGeo const* CryostatPtr(CryostatID const& cryoid) const
346  {
347  return HasCryostat(cryoid) ? &fCryostats[cryoid.Cryostat] : nullptr;
348  }
349  CryostatGeo const* GetElementPtr(CryostatID const& cryoid) const { return CryostatPtr(cryoid); }
351 
359  CryostatGeo const* PositionToCryostatPtr(Point_t const& point) const;
360 
368  CryostatID PositionToCryostatID(Point_t const& point) const;
369 
371 
379  CryostatGeo const& PositionToCryostat(Point_t const& point) const;
380 
381  //
382  // iterators
383  //
384  using Iteration::begin;
385  using Iteration::end;
386  using Iteration::Iterate;
387 
388  //
389  // single object features
390  //
391 
394 
395  //
396  // group features
397  //
398 
400  unsigned int MaxTPCs() const;
401 
403  unsigned int TotalNTPC() const;
404 
406 
416  unsigned int NTPC(CryostatID const& cryoid = details::cryostat_zero) const
417  {
418  CryostatGeo const* pCryo = GetElementPtr(cryoid);
419  return pCryo ? pCryo->NElements() : 0;
420  }
421  unsigned int NElements(CryostatID const& cryoid) const { return NTPC(cryoid); }
422  unsigned int NSiblingElements(TPCID const& tpcid) const { return NTPC(tpcid); }
424 
425  //
426  // access
427  //
429  bool HasTPC(TPCID const& tpcid) const
430  {
431  CryostatGeo const* pCryo = CryostatPtr(tpcid);
432  return pCryo ? pCryo->HasTPC(tpcid) : false;
433  }
434 
436  bool HasElement(TPCID const& tpcid) const { return HasTPC(tpcid); }
437 
439 
448  TPCGeo const& TPC(TPCID const& tpcid = details::tpc_zero) const
449  {
450  return Cryostat(tpcid).TPC(tpcid);
451  }
452  TPCGeo const& GetElement(TPCID const& tpcid) const { return TPC(tpcid); }
454 
456 
463  TPCGeo const* TPCPtr(TPCID const& tpcid) const
464  {
465  CryostatGeo const* pCryo = CryostatPtr(tpcid);
466  return pCryo ? pCryo->TPCPtr(tpcid) : nullptr;
467  }
468  TPCGeo const* GetElementPtr(TPCID const& tpcid) const { return TPCPtr(tpcid); }
470 
472 
477  TPCID FindTPCAtPosition(Point_t const& point) const;
479 
485  TPCGeo const* PositionToTPCptr(Point_t const& point) const;
486 
488 
494  TPCGeo const& PositionToTPC(Point_t const& point) const;
496 
503  TPCID PositionToTPCID(Point_t const& point) const;
504 
505  //
506  // object description
507  //
508 
526 
528  //
529  // group features
530  //
531 
533  unsigned int NOpDets() const;
534 
535  //
536  // access
537  //
543  OpDetGeo const& OpDetGeoFromOpDet(unsigned int OpDet) const;
544 
546 
556  unsigned int GetClosestOpDet(Point_t const& point) const;
558 
559  //
560  // object description
561  //
562 
571  std::string OpDetGeoName(CryostatID const& cid = details::cryostat_zero) const;
572 
574 
575  //
576  // group features
577  //
583 
586  //
587  // group features
588  //
589 
591  unsigned int OpDetFromCryo(unsigned int o, unsigned int c) const;
592 
594 
595  //
596  // unsorted methods
597  //
598 
599  CryostatList_t const& Cryostats() const noexcept { return fCryostats; }
600 
601  private:
602  void LoadGeometryFile();
603  void SortGeometry();
604 
606 
607  std::unique_ptr<GeometryBuilder> fBuilder;
608  std::unique_ptr<GeoObjectSorter> fSorter;
609 
610  TGeoManager* fManager{nullptr};
611  std::string fGDMLfile;
612  std::string fDetectorName;
613  double fSurfaceY;
615 
616  std::vector<GeoNodePathEntry> FindDetectorEnclosure(
617  std::string const& name = "volDetEnclosure") const;
618 
619  bool FindFirstVolume(std::string const& name, std::vector<GeoNodePathEntry>& path) const;
620 
622  void BuildGeometry();
623 
624  }; // class GeometryCore
625 
627  // END Geometry group --------------------------------------------------------
628 
629 } // namespace geo
630 
631 //------------------------------------------------------------------------------
632 template <typename Stream>
633 void geo::GeometryCore::Print(Stream&& out, std::string indent /* = " " */) const
634 {
635 
636  out << "Detector " << DetectorName() << " has " << Ncryostats() << " cryostats:";
637 
638  auto const& detEnclosureBox = DetectorEnclosureBox();
639  out << "\n"
640  << indent << "Detector enclosure: " << detEnclosureBox.Min() << " -- "
641  << detEnclosureBox.Max() << " cm => ( " << detEnclosureBox.SizeX() << " x "
642  << detEnclosureBox.SizeY() << " x " << detEnclosureBox.SizeZ() << " ) cm^3";
643 
644  for (auto const& cryostat : Iterate<CryostatGeo>()) {
645  out << "\n" << indent;
646  cryostat.PrintCryostatInfo(std::forward<Stream>(out), indent + " ", cryostat.MaxVerbosity);
647 
648  unsigned const int nTPCs = cryostat.NTPC();
649  for (unsigned int t = 0; t < nTPCs; ++t) {
650  TPCGeo const& tpc = cryostat.TPC(t);
651 
652  out << "\n" << indent << " ";
653  tpc.PrintTPCInfo(std::forward<Stream>(out), indent + " ", tpc.MaxVerbosity);
654  } // for TPC
655 
656  unsigned int nOpDets = cryostat.NOpDet();
657  for (unsigned int iOpDet = 0; iOpDet < nOpDets; ++iOpDet) {
658  OpDetGeo const& opDet = cryostat.OpDet(iOpDet);
659  out << "\n" << indent << " [OpDet #" << iOpDet << "] ";
660  opDet.PrintOpDetInfo(std::forward<Stream>(out), indent + " ", opDet.MaxVerbosity);
661  } // for
662  } // for cryostat
663 
664  out << '\n';
665 
666 } // geo::GeometryCore::Print()
667 
668 #endif // LARCOREALG_GEOMETRY_GEOMETRYCORE_H
CryostatGeo const * PositionToCryostatPtr(Point_t const &point) const
Returns the cryostat at specified location.
std::string const & GetWorldVolumeName() const
Return the name of the world volume (needed by Geant4 simulation)
void PrintTPCInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this TPC.
Definition: TPCGeo.h:271
unsigned int TotalNTPC() const
Returns the total number of TPCs in the detector.
Encapsulate the construction of a single cyostat .
double Length_t
Type used for coordinates and distances. They are measured in centimeters.
Definition: geo_vectors.h:133
Encapsulate the geometry of the sensitive portion of an auxiliary detector .
std::vector< GeoNodePathEntry > FindDetectorEnclosure(std::string const &name="volDetEnclosure") const
void Print(Stream &&out, std::string indent=" ") const
Prints geometry information with maximum verbosity.
Definition: GeometryCore.h:633
unsigned int NTPC(CryostatID const &cryoid=details::cryostat_zero) const
Returns the total number of TPCs in the specified cryostat.
Definition: GeometryCore.h:416
CryostatList_t fCryostats
Definition: GeometryCore.h:605
unsigned int GetClosestOpDet(Point_t const &point) const
Find the nearest OpChannel to some point.
CryostatGeo const * GetElementPtr(CryostatID const &cryoid) const
Returns the specified cryostat.
Definition: GeometryCore.h:349
Geometry information for a single TPC.
Definition: TPCGeo.h:33
BoxBoundedGeo DetectorEnclosureBox(std::string const &name="volDetEnclosure") const
double fSurfaceY
The point where air meets earth for this detector.
Definition: GeometryCore.h:613
TGeoVolume const * WorldVolume() const
Returns a pointer to the world volume.
Interface for geometry extractor classes.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:195
TGeoMaterial const * Material(Point_t const &point) const
Returns the material at the specified position.
Geometry information for a single cryostat.
Definition: CryostatGeo.h:42
CryostatGeo const & GetElement(CryostatID const &cryoid) const
Returns the specified cryostat.
Definition: GeometryCore.h:334
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
Definition: GeometryCore.h:303
CryostatGeo const & PositionToCryostat(Point_t const &point) const
Returns the cryostat at specified location.
TGeoManager * ROOTGeoManager() const
Access to the ROOT geometry description manager.
Length_t SurfaceY() const
The position of the detector respect to earth surface.
Definition: GeometryCore.h:186
std::string OpDetGeoName(CryostatID const &cid=details::cryostat_zero) const
Returns gdml string which gives sensitive opdet name.
unsigned int OpDetFromCryo(unsigned int o, unsigned int c) const
Get unique opdet number from cryo and internal count.
unsigned int NElements() const
Returns the number of cryostats in the detector.
Definition: GeometryCore.h:304
TPCGeo const & GetElement(TPCID const &tpcid) const
Returns the specified TPC.
Definition: GeometryCore.h:452
std::vector< CryostatGeo > CryostatList_t
Definition: GeometryCore.h:95
unsigned int NSiblingElements(TPCID const &tpcid) const
Returns the largest number of TPCs a cryostat in the detector has.
Definition: GeometryCore.h:422
double TotalMass() const
Returns the total mass [kg] of the specified volume (default: world).
Definition: GeometryCore.h:255
CryostatList_t const & Cryostats() const noexcept
Definition: GeometryCore.h:599
Interface to algorithm class for sorting geo::AuxDet objects .
bool HasElement(CryostatID const &cryoid) const
Returns whether we have the specified cryostat.
Definition: GeometryCore.h:319
std::string VolumeName(Point_t const &point) const
Returns the name of the deepest volume containing specified point.
TPCID FindTPCAtPosition(Point_t const &point) const
Returns the ID of the TPC at specified location.
TPCGeo const * GetElementPtr(TPCID const &tpcid) const
Returns the specified TPC.
Definition: GeometryCore.h:468
constexpr CryostatID cryostat_zero
Definition: ZeroIDs.h:7
Definitions of geometry vector data types.
TPCGeo const & PositionToTPC(Point_t const &point) const
Returns the TPC at specified location.
CryostatGeo const * CryostatPtr(CryostatID const &cryoid) const
Returns the specified cryostat.
Definition: GeometryCore.h:345
std::string MaterialName(Point_t const &point) const
Name of the deepest material containing the point xyz.
std::string indent(std::size_t const i)
unsigned int NElements() const
Alias for NTPC().
Definition: CryostatGeo.h:173
void PrintOpDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=0) const
Prints information about this optical detector.
Definition: OpDetGeo.h:260
Utilities to extend the interface of geometry vectors.This library provides facilities that can be us...
TPCGeo const * TPCPtr(unsigned int itpc) const
Returns the TPC number itpc from this cryostat.
Definition: CryostatGeo.h:252
unsigned int NSiblingElements(CryostatID const &) const
Returns the number of cryostats in the detector.
Definition: GeometryCore.h:305
std::unique_ptr< GeoObjectSorter > fSorter
Definition: GeometryCore.h:608
bool HasCryostat(CryostatID const &cryoid) const
Returns whether we have the specified cryostat.
Definition: GeometryCore.h:318
std::string Info(std::string indent=" ") const
Returns a string with complete geometry information.
bool FindFirstVolume(std::string const &name, std::vector< GeoNodePathEntry > &path) const
GeometryCore(fhicl::ParameterSet const &pset, std::unique_ptr< GeometryBuilder > builder, std::unique_ptr< GeoObjectSorter > sorter)
Initialize geometry from a given configuration.
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
Description of the physical geometry of one entire detector.
Definition: GeometryCore.h:91
Definition of data types for geometry description.
TGeoManager * fManager
Definition: GeometryCore.h:610
double DefaultWiggle() const
Returns the tolerance used in looking for positions.
Definition: GeometryCore.h:121
CryostatGeo const & Cryostat(CryostatID const &cryoid=details::cryostat_zero) const
Returns the specified cryostat.
unsigned int NOpDets() const
Number of OpDets in the whole detector.
Provides a base class aware of world box coordinates.
double fPositionWiggle
accounting for rounding errors when testing positions
Definition: GeometryCore.h:614
Encapsulate the geometry of an auxiliary detector.
std::vector< TGeoNode const * > FindAllVolumes(std::set< std::string > const &vol_names) const
Returns all the nodes with volumes with any of the specified names.
GeometryCore & operator=(GeometryCore const &)=delete
Encapsulate the geometry of an optical detector.
std::string fGDMLfile
path to geometry file used for Geant4 simulation
Definition: GeometryCore.h:611
BoxBoundedGeo WorldBox() const
CryostatID PositionToCryostatID(Point_t const &point) const
Returns the ID of the cryostat at specified location.
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
double MassBetweenPoints(Point_t const &p1, Point_t const &p2) const
Returns the column density between two points.
TPCGeo const & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:73
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:31
void BuildGeometry()
Parses ROOT geometry nodes and builds LArSoft geometry representation.
TPCGeo const * TPCPtr(TPCID const &tpcid) const
Returns the specified TPC.
Definition: GeometryCore.h:463
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintOpDetInfo().
Definition: OpDetGeo.h:209
bool HasElement(TPCID const &tpcid) const
Returns whether we have the specified TPC.
Definition: GeometryCore.h:436
constexpr TPCID tpc_zero
Definition: ZeroIDs.h:8
std::unique_ptr< GeometryBuilder > fBuilder
Definition: GeometryCore.h:607
std::string const & GDMLFile() const
Returns the full directory path to the GDML file source.
Definition: GeometryCore.h:130
std::string fDetectorName
Name of the detector.
Definition: GeometryCore.h:612
std::vector< std::vector< TGeoNode const * > > FindAllVolumePaths(std::set< std::string > const &vol_names) const
Returns paths of all nodes with volumes with the specified names.
bool HasTPC(unsigned int itpc) const
Returns whether a TPC with index itpc is present in this cryostat.
Definition: CryostatGeo.h:180
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
Definition: GeometryCore.h:140
unsigned int NElements(CryostatID const &cryoid) const
Returns the largest number of TPCs a cryostat in the detector has.
Definition: GeometryCore.h:421
TPCGeo const & TPC(TPCID const &tpcid=details::tpc_zero) const
Returns the specified TPC.
Definition: GeometryCore.h:448
TPCGeo const * PositionToTPCptr(Point_t const &point) const
Returns the TPC at specified location.
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintTPCInfo().
Definition: TPCGeo.h:204
ROOT libraries.
unsigned int MaxTPCs() const
Returns the largest number of TPCs a cryostat in the detector has.
TPCID PositionToTPCID(Point_t const &point) const
Returns the ID of the TPC at specified location.
bool HasTPC(TPCID const &tpcid) const
Returns whether we have the specified TPC.
Definition: GeometryCore.h:429
OpDetGeo const & OpDetGeoFromOpDet(unsigned int OpDet) const
Returns the geo::OpDetGeo object for the given detector number.
Encapsulate the construction of a single detector plane .
The data type to uniquely identify a cryostat.
Definition: geo_types.h:187