LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CryostatGeo.cxx
Go to the documentation of this file.
1 
7 // class header
9 
10 // LArSoft includes
11 #include "larcorealg/Geometry/GeoObjectSorter.h" // for GeoObjectSo...
12 
13 // Framework includes
14 #include "cetlib_except/exception.h"
16 
17 // ROOT includes
18 #include "TClass.h"
19 #include "TGeoBBox.h"
20 #include "TGeoNode.h"
21 #include "TGeoShape.h" // for TGeoShape
22 
23 // C++ standard libraries
24 #include <limits> // std::numeric_limits<>
25 #include <sstream> // std::ostringstream
26 #include <utility> // std::move()
27 #include <vector>
28 
29 namespace geo {
30 
31  //......................................................................
32  CryostatGeo::CryostatGeo(TGeoNode const& node,
34  TPCList_t&& TPCs,
35  OpDetList_t&& OpDets)
36  : fTrans(std::move(trans)), fTPCs(std::move(TPCs)), fOpDets(std::move(OpDets)), fVolume(nullptr)
37  {
38 
39  // all planes are going to be contained in the volume named volCryostat
40  // now get the total volume of the Cryostat
41  fVolume = node.GetVolume();
42  if (!fVolume) throw cet::exception("CryostatGeo") << "cannot find cryostat outline volume\n";
43 
44  MF_LOG_DEBUG("Geometry") << "cryostat volume is " << fVolume->GetName();
45 
46  // set the bounding box
48 
49  // Set OpDetName;
50  fOpDetGeoName = "volOpDetSensitive";
51  }
52 
53  //......................................................................
54  // sort the TPCGeo objects, and the PlaneGeo objects inside
56  {
57  sorter.SortTPCs(fTPCs);
58 
59  for (geo::TPCGeo& TPC : fTPCs) {
60  TPC.SortSubVolumes(sorter);
61  }
62 
63  sorter.SortOpDets(fOpDets);
64  } // CryostatGeo::SortSubVolumes()
65 
66  //......................................................................
68  {
69 
70  // update the cryostat ID
71  fID = cryoid;
72 
73  // trigger all the optical detectors to update
74  for (unsigned int opdet = 0; opdet < NOpDet(); ++opdet)
76 
77  // trigger all the TPCs to update as well
78  for (unsigned int tpc = 0; tpc < NTPC(); ++tpc)
80 
81  } // CryostatGeo::UpdateAfterSorting()
82 
83  //......................................................................
84  const TPCGeo& CryostatGeo::TPC(unsigned int itpc) const
85  {
86  TPCGeo const* pTPC = TPCPtr(itpc);
87  if (!pTPC) {
88  throw cet::exception("TPCOutOfRange") << "Request for non-existant TPC " << itpc << "\n";
89  }
90 
91  return *pTPC;
92  }
93 
94  //......................................................................
95  const OpDetGeo& CryostatGeo::OpDet(unsigned int iopdet) const
96  {
97  if (iopdet >= fOpDets.size()) {
98  throw cet::exception("OpDetOutOfRange") << "Request for non-existant OpDet " << iopdet;
99  }
100 
101  return fOpDets[iopdet];
102  }
103 
104  //......................................................................
106  {
107  return fTPCs;
108  }
109 
110  //......................................................................
111  // wiggle is 1+a small number to allow for rounding errors on the
112  // passed in world loc relative to the boundaries.
113  geo::TPCID CryostatGeo::PositionToTPCID(geo::Point_t const& point, double wiggle) const
114  {
115  geo::TPCGeo const* tpc = PositionToTPCptr(point, wiggle);
116  return tpc ? tpc->ID() : geo::TPCID{};
117  }
118 
119  //......................................................................
120  // wiggle is 1+a small number to allow for rounding errors on the
121  // passed in world loc relative to the boundaries.
122  TPCGeo const& CryostatGeo::PositionToTPC(geo::Point_t const& point, double wiggle) const
123  {
124  geo::TPCGeo const* tpc = PositionToTPCptr(point, wiggle);
125  if (!tpc) {
126  throw cet::exception("CryostatGeo")
127  << "Can't find any TPC for position " << point << " within " << ID() << "\n";
128  }
129  return *tpc;
130  }
131 
132  //......................................................................
133  geo::TPCGeo const* CryostatGeo::PositionToTPCptr(geo::Point_t const& point, double wiggle) const
134  {
135  for (auto const& tpc : IterateTPCs())
136  if (tpc.ContainsPosition(point, wiggle)) return &tpc;
137  return nullptr;
138  } // CryostatGeo::PositionToTPCptr()
139 
140  //......................................................................
141  unsigned int CryostatGeo::MaxPlanes() const
142  {
143  unsigned int maxPlanes = 0;
144  for (geo::TPCGeo const& TPC : fTPCs) {
145  unsigned int maxPlanesInTPC = TPC.Nplanes();
146  if (maxPlanesInTPC > maxPlanes) maxPlanes = maxPlanesInTPC;
147  } // for
148  return maxPlanes;
149  } // CryostatGeo::MaxPlanes()
150 
151  //......................................................................
152  unsigned int CryostatGeo::MaxWires() const
153  {
154  unsigned int maxWires = 0;
155  for (geo::TPCGeo const& TPC : fTPCs) {
156  unsigned int maxWiresInTPC = TPC.MaxWires();
157  if (maxWiresInTPC > maxWires) maxWires = maxWiresInTPC;
158  } // for
159  return maxWires;
160  } // CryostatGeo::MaxWires()
161 
162  //......................................................................
163  double CryostatGeo::HalfWidth() const
164  {
165  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDX();
166  }
167 
168  //......................................................................
169  double CryostatGeo::HalfHeight() const
170  {
171  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDY();
172  }
173 
174  //......................................................................
175  double CryostatGeo::HalfLength() const
176  {
177  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDZ();
178  }
179 
180  //......................................................................
181  void CryostatGeo::Boundaries(double* boundaries) const
182  {
183  boundaries[0] = MinX();
184  boundaries[1] = MaxX();
185  boundaries[2] = MinY();
186  boundaries[3] = MaxY();
187  boundaries[4] = MinZ();
188  boundaries[5] = MaxZ();
189  } // CryostatGeo::CryostatBoundaries(double*)
190 
191  //......................................................................
192  std::string CryostatGeo::CryostatInfo(std::string indent /* = "" */,
193  unsigned int verbosity /* = 1 */) const
194  {
195  std::ostringstream sstr;
196  PrintCryostatInfo(sstr, indent, verbosity);
197  return sstr.str();
198  } // CryostatGeo::CryostatInfo()
199 
200  //......................................................................
201  // Find the nearest opdet to point in this cryostat
202 
204  {
205  unsigned int iOpDet = GetClosestOpDet(point);
206  return (iOpDet == std::numeric_limits<double>::max()) ? nullptr : &OpDet(iOpDet);
207  }
208 
209  //......................................................................
210  unsigned int CryostatGeo::GetClosestOpDet(geo::Point_t const& point) const
211  {
212  unsigned int ClosestDet = std::numeric_limits<unsigned int>::max();
213  double ClosestDist = std::numeric_limits<double>::max();
214 
215  for (unsigned int o = 0U; o < NOpDet(); ++o) {
216  double const ThisDist = OpDet(o).DistanceToPoint(point);
217  if (ThisDist < ClosestDist) {
218  ClosestDist = ThisDist;
219  ClosestDet = o;
220  }
221  } // for
222  return ClosestDet;
223  } // CryostatGeo::GetClosestOpDet(geo::Point_t)
224 
225  //......................................................................
226  unsigned int CryostatGeo::GetClosestOpDet(double const* point) const
227  {
229  }
230 
231  //......................................................................
233  {
234 
235  // check that this is indeed a box
236  if (!dynamic_cast<TGeoBBox*>(Volume()->GetShape())) {
237  // at initialisation time we don't know yet our real ID
238  throw cet::exception("CryostatGeo")
239  << "Cryostat is not a box! (it is a " << Volume()->GetShape()->IsA()->GetName() << ")\n";
240  }
241 
242  // get the half width, height, etc of the cryostat
243  const double halflength = HalfLength();
244  const double halfwidth = HalfWidth();
245  const double halfheight = HalfHeight();
246 
247  SetBoundaries(toWorldCoords(LocalPoint_t{-halfwidth, -halfheight, -halflength}),
248  toWorldCoords(LocalPoint_t{+halfwidth, +halfheight, +halflength}));
249 
250  } // CryostatGeo::InitCryoBoundaries()
251 
252  //......................................................................
253 
254 } // namespace geo
geo::TPCID const & ID() const
Returns the identifier of this TPC.
Definition: TPCGeo.h:270
void InitCryoBoundaries()
Fill the boundary information of the cryostat.
unsigned int GetClosestOpDet(geo::Point_t const &point) const
virtual void SortTPCs(std::vector< geo::TPCGeo > &tgeo) const =0
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
Encapsulate the construction of a single cyostat.
unsigned int MaxPlanes() const
Returns the largest number of planes among the TPCs in this cryostat.
TGeoVolume * fVolume
Total volume of cryostat, called volCryostat in GDML file.
Definition: CryostatGeo.h:396
unsigned int Nplanes() const
Number of planes in this tpc.
Definition: TPCGeo.h:137
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:90
Geometry information for a single TPC.
Definition: TPCGeo.h:36
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
STL namespace.
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:93
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
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Apply sorting to the PlaneGeo objects.
Definition: TPCGeo.cxx:191
virtual void SortOpDets(std::vector< geo::OpDetGeo > &opdet) const
geo::TPCGeo const * PositionToTPCptr(geo::Point_t const &point, double wiggle) const
Returns a pointer to the TPC at specified location.
std::string fOpDetGeoName
Name of opdet geometry elements in gdml.
Definition: CryostatGeo.h:397
Interface to algorithm class for sorting geo::XXXGeo objects.
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Method to sort TPCGeo objects.
Definition: CryostatGeo.cxx:55
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
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].
double MinZ() const
Returns the world z coordinate of the start of the box.
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
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
unsigned int MaxWires() const
Returns the largest number of wires among the planes in this TPC.
Definition: TPCGeo.cxx:284
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
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:57
std::string CryostatInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with cryostat information.
double DistanceToPoint(geo::Point_t const &point) const
Returns the distance of the specified point from detector center [cm].
Definition: OpDetGeo.cxx:98
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
TPCList_t fTPCs
List of tpcs in this cryostat.
Definition: CryostatGeo.h:394
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.
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
double MaxZ() const
Returns the world z coordinate of the end of the box.
#define MF_LOG_DEBUG(id)
geo::BoxBoundedGeo const & Boundaries() const
Returns boundaries of the cryostat (in centimetres).
Definition: CryostatGeo.h:114
TPCGeo const & PositionToTPC(geo::Point_t const &point, double wiggle) const
Returns the ID of the TPC at specified location.
The data type to uniquely identify a optical detector.
Definition: geo_types.h:297
GENVECTOR_CONSTEXPR::geo::Point_t makePointFromCoords(Coords &&coords)
Creates a geo::Point_t from its coordinates (see makeFromCoords()).
Namespace collecting geometry-related classes utilities.
double MinY() const
Returns the world y coordinate of the start of the box.
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.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
The data type to uniquely identify a cryostat.
Definition: geo_types.h:192
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.