LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
CryostatGeo.cxx
Go to the documentation of this file.
1 
5 // class header
7 
8 // LArSoft includes
9 #include "larcorealg/Geometry/GeoObjectSorter.h" // for GeoObjectSo...
10 
11 // Framework includes
12 #include "cetlib_except/exception.h"
14 
15 // ROOT includes
16 #include "TClass.h"
17 #include "TGeoBBox.h"
18 #include "TGeoNode.h"
19 #include "TGeoShape.h" // for TGeoShape
20 
21 // C++ standard libraries
22 #include <algorithm>
23 #include <limits> // std::numeric_limits<>
24 #include <sstream> // std::ostringstream
25 #include <utility> // std::move()
26 #include <vector>
27 
28 namespace geo {
29 
30  //......................................................................
31  CryostatGeo::CryostatGeo(TGeoNode const* node,
32  TransformationMatrix&& trans,
33  TPCList_t&& TPCs,
34  OpDetList_t&& OpDets)
35  : fTrans(std::move(trans))
36  , fTPCs(std::move(TPCs))
37  , fOpDets(std::move(OpDets))
38  , fVolume(node->GetVolume())
39  {
40  // all planes are going to be contained in the volume named volCryostat
41  if (!fVolume) throw cet::exception("CryostatGeo") << "cannot find cryostat outline volume\n";
42 
43  MF_LOG_DEBUG("Geometry") << "cryostat volume is " << fVolume->GetName();
44 
45  // set the bounding box
47  }
48 
49  //......................................................................
50  // sort the TPCGeo objects, and the PlaneGeo objects inside
52  {
53  sorter.sort(fTPCs);
54  sorter.sort(fOpDets);
55  }
56 
57  //......................................................................
59  {
60  // update the cryostat ID
61  fID = cryoid;
62 
63  // trigger all the optical detectors to update
64  for (unsigned int opdet = 0; opdet < NOpDet(); ++opdet)
66 
67  // trigger all the TPCs to update as well
68  for (unsigned int tpc = 0; tpc < NTPC(); ++tpc)
69  fTPCs[tpc].UpdateAfterSorting(TPCID(fID, tpc));
70  }
71 
72  //......................................................................
73  TPCGeo const& CryostatGeo::TPC(unsigned int itpc) const
74  {
75  TPCGeo const* pTPC = TPCPtr(itpc);
76  if (!pTPC) {
77  throw cet::exception("TPCOutOfRange") << "Request for non-existant TPC " << itpc << "\n";
78  }
79  return *pTPC;
80  }
81 
82  //......................................................................
83  OpDetGeo const& CryostatGeo::OpDet(unsigned int iopdet) const
84  {
85  if (iopdet >= fOpDets.size()) {
86  throw cet::exception("OpDetOutOfRange") << "Request for non-existant OpDet " << iopdet;
87  }
88  return fOpDets[iopdet];
89  }
90 
91  //......................................................................
93  {
94  return fTPCs;
95  }
96 
97  //......................................................................
98  // wiggle is 1+a small number to allow for rounding errors on the
99  // passed in world loc relative to the boundaries.
100  TPCID CryostatGeo::PositionToTPCID(Point_t const& point, double wiggle) const
101  {
102  TPCGeo const* tpc = PositionToTPCptr(point, wiggle);
103  return tpc ? tpc->ID() : TPCID{};
104  }
105 
106  //......................................................................
107  // wiggle is 1+a small number to allow for rounding errors on the
108  // passed in world loc relative to the boundaries.
109  TPCGeo const& CryostatGeo::PositionToTPC(Point_t const& point, double wiggle) const
110  {
111  TPCGeo const* tpc = PositionToTPCptr(point, wiggle);
112  if (!tpc) {
113  throw cet::exception("CryostatGeo")
114  << "Can't find any TPC for position " << point << " within " << ID() << "\n";
115  }
116  return *tpc;
117  }
118 
119  //......................................................................
120  TPCGeo const* CryostatGeo::PositionToTPCptr(Point_t const& point, double wiggle) const
121  {
122  for (auto const& tpc : IterateTPCs())
123  if (tpc.ContainsPosition(point, wiggle)) return &tpc;
124  return nullptr;
125  }
126 
127  //......................................................................
128  double CryostatGeo::HalfWidth() const
129  {
130  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDX();
131  }
132 
133  //......................................................................
134  double CryostatGeo::HalfHeight() const
135  {
136  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDY();
137  }
138 
139  //......................................................................
140  double CryostatGeo::HalfLength() const
141  {
142  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDZ();
143  }
144 
145  //......................................................................
146  void CryostatGeo::Boundaries(double* boundaries) const
147  {
148  boundaries[0] = MinX();
149  boundaries[1] = MaxX();
150  boundaries[2] = MinY();
151  boundaries[3] = MaxY();
152  boundaries[4] = MinZ();
153  boundaries[5] = MaxZ();
154  }
155 
156  //......................................................................
157  std::string CryostatGeo::CryostatInfo(std::string indent /* = "" */,
158  unsigned int verbosity /* = 1 */) const
159  {
160  std::ostringstream sstr;
161  PrintCryostatInfo(sstr, indent, verbosity);
162  return sstr.str();
163  }
164 
165  //......................................................................
166  // Find the nearest opdet to point in this cryostat
167 
169  {
170  unsigned int iOpDet = GetClosestOpDet(point);
171  return (iOpDet == std::numeric_limits<double>::max()) ? nullptr : &OpDet(iOpDet);
172  }
173 
174  //......................................................................
175  unsigned int CryostatGeo::GetClosestOpDet(Point_t const& point) const
176  {
177  unsigned int ClosestDet = std::numeric_limits<unsigned int>::max();
178  double ClosestDist = std::numeric_limits<double>::max();
179 
180  for (unsigned int o = 0U; o < NOpDet(); ++o) {
181  double const ThisDist = OpDet(o).DistanceToPoint(point);
182  if (ThisDist < ClosestDist) {
183  ClosestDist = ThisDist;
184  ClosestDet = o;
185  }
186  } // for
187  return ClosestDet;
188  }
189 
190  //......................................................................
191  unsigned int CryostatGeo::GetClosestOpDet(double const* point) const
192  {
194  }
195 
196  //......................................................................
198  {
199  // check that this is indeed a box
200  if (!dynamic_cast<TGeoBBox*>(Volume()->GetShape())) {
201  // at initialisation time we don't know yet our real ID
202  throw cet::exception("CryostatGeo")
203  << "Cryostat is not a box! (it is a " << Volume()->GetShape()->IsA()->GetName() << ")\n";
204  }
205 
206  // get the half width, height, etc of the cryostat
207  double const halflength = HalfLength();
208  double const halfwidth = HalfWidth();
209  double const halfheight = HalfHeight();
210 
211  SetBoundaries(toWorldCoords(LocalPoint_t{-halfwidth, -halfheight, -halflength}),
212  toWorldCoords(LocalPoint_t{+halfwidth, +halfheight, +halflength}));
213  }
214 
215  //......................................................................
216 
217 } // namespace geo
IDparameter< geo::OpDetID > OpDetID
Member type of validated geo::OpDetID parameter.
void InitCryoBoundaries()
Fill the boundary information of the cryostat.
double HalfLength() const
Half height of the cryostat [cm].
Encapsulate the construction of a single cyostat .
OpDetGeo const & OpDet(unsigned int iopdet) const
Return the iopdet&#39;th optical detector in the cryostat.
Definition: CryostatGeo.cxx:83
unsigned int GetClosestOpDet(Point_t const &point) const
TGeoVolume * fVolume
Total volume of cryostat, called volCryostat in GDML file.
Definition: CryostatGeo.h:380
GENVECTOR_CONSTEXPR Point_t makePointFromCoords(Coords &&coords)
Creates a geo::Point_t from its coordinates (see makeFromCoords()).
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
Geometry information for a single TPC.
Definition: TPCGeo.h:33
ElementIteratorBox IterateTPCs() const
Returns an object suitable for iterating through all TPCs.
Definition: CryostatGeo.h:245
STL namespace.
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
OpDetList_t fOpDets
List of opdets in this cryostat.
Definition: CryostatGeo.h:379
CryostatGeo(TGeoNode const *node, TransformationMatrix &&trans, TPCList_t &&TPCs, OpDetList_t &&OpDets)
Construct a representation of a single cryostat of the detector.
Definition: CryostatGeo.cxx:31
std::vector< OpDetGeo > OpDetList_t
Type used internally to store the optical detectors.
Definition: CryostatGeo.h:51
OpDetGeo const * GetClosestOpDetPtr(Point_t const &point) const
Interface to algorithm class for sorting geo::AuxDet objects .
double DistanceToPoint(Point_t const &point) const
Returns the distance of the specified point from detector center [cm].
Definition: OpDetGeo.cxx:94
Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local cryostat frame to world frame.
Definition: CryostatGeo.h:343
void PrintCryostatInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this cryostat.
Definition: CryostatGeo.h:390
const TGeoVolume * Volume() const
Pointer to ROOT&#39;s volume descriptor.
Definition: CryostatGeo.h:109
TPCGeo const & PositionToTPC(Point_t const &point, double wiggle) const
Returns the ID of the TPC at specified location.
std::string indent(std::size_t const i)
double HalfWidth() const
Half width of the cryostat [cm].
double MinZ() const
Returns the world z coordinate of the start of the box.
void UpdateAfterSorting(CryostatID cryoid)
Performs all needed updates after geometry has sorted the cryostats.
Definition: CryostatGeo.cxx:58
TPCGeo const * TPCPtr(unsigned int itpc) const
Returns the TPC number itpc from this cryostat.
Definition: CryostatGeo.h:252
unsigned int NTPC() const
Number of TPCs in this cryostat.
Definition: CryostatGeo.h:171
CryostatID const & ID() const
Returns the identifier of this cryostat.
Definition: CryostatGeo.h:126
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
void sort(std::vector< CryostatGeo > &cryostats) const
double MaxY() const
Returns the world y coordinate of the end of the box.
double HalfHeight() const
Half height of the cryostat [cm].
TPCList_t const & ElementIteratorBox
Type returned by IterateElements().
Definition: CryostatGeo.h:56
std::string CryostatInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with cryostat information.
TPCID PositionToTPCID(Point_t const &point, double wiggle) const
Returns the ID of the TPC 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
TPCGeo const & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:73
TPCList_t fTPCs
List of tpcs in this cryostat.
Definition: CryostatGeo.h:378
void SetBoundaries(Coord_t x_min, Coord_t x_max, Coord_t y_min, Coord_t y_max, Coord_t z_min, Coord_t z_max)
Sets the boundaries in world coordinates as specified.
unsigned int NOpDet() const
Number of optical detectors in this TPC.
Definition: CryostatGeo.h:317
double MaxZ() const
Returns the world z coordinate of the end of the box.
#define MF_LOG_DEBUG(id)
Point3DBase_t< CryostatGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML cryostat frame.
Definition: CryostatGeo.h:78
std::vector< TPCGeo > TPCList_t
Type used internally to store the TPCs.
Definition: CryostatGeo.h:48
BoxBoundedGeo const & Boundaries() const
Returns boundaries of the cryostat (in centimetres).
Definition: CryostatGeo.h:113
IDparameter< geo::TPCID > TPCID
Member type of validated geo::TPCID parameter.
void SortSubVolumes(GeoObjectSorter const &sorter)
Method to sort TPCGeo objects.
Definition: CryostatGeo.cxx:51
CryostatID fID
ID of this cryostat.
Definition: CryostatGeo.h:382
TPCGeo const * PositionToTPCptr(Point_t const &point, double wiggle) const
Returns a pointer to the TPC at specified location.
ROOT libraries.
double MinY() const
Returns the world y coordinate of the start of the box.
TPCID const & ID() const
Returns the identifier of this TPC.
Definition: TPCGeo.h:147
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
The data type to uniquely identify a cryostat.
Definition: geo_types.h:187
ElementIteratorBox IterateElements() const
Returns an object suitable for iterating through all TPCs.
Definition: CryostatGeo.cxx:92