CryostatGeo.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file larcorealg/Geometry/CryostatGeo.cxx
3 ///
4 /// \author brebel@fnal.gov
5 ////////////////////////////////////////////////////////////////////////
6 
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 "TGeoNode.h"
19 #include "TGeoBBox.h"
20 #include "TGeoShape.h" // for TGeoShape
21 #include "TClass.h"
22 
23 // C++ standard libraries
24 #include <sstream> // std::ostringstream
25 #include <limits> // std::numeric_limits<>
26 #include <vector>
27 #include <utility> // std::move()
28 
29 
30 namespace geo{
31 
32  //......................................................................
34  TGeoNode const& node, geo::TransformationMatrix&& trans,
35  TPCList_t&& TPCs,
36  OpDetList_t&& OpDets
37  )
38  : fTrans(std::move(trans))
39  , fTPCs(std::move(TPCs))
40  , fOpDets(std::move(OpDets))
41  , fVolume(nullptr)
42  {
43 
44  // all planes are going to be contained in the volume named volCryostat
45  // now get the total volume of the Cryostat
46  fVolume = node.GetVolume();
47  if(!fVolume)
48  throw cet::exception("CryostatGeo") << "cannot find cryostat outline volume\n";
49 
50  MF_LOG_DEBUG("Geometry") << "cryostat volume is " << fVolume->GetName();
51 
52  // set the bounding box
54 
55  // Set OpDetName;
56  fOpDetGeoName = "volOpDetSensitive";
57 
58  }
59 
60 
61  //......................................................................
62  // sort the TPCGeo objects, and the PlaneGeo objects inside
64  {
65  sorter.SortTPCs(fTPCs);
66 
67  for (geo::TPCGeo& TPC: fTPCs) {
68  TPC.SortSubVolumes(sorter);
69  }
70 
71  sorter.SortOpDets(fOpDets);
72  } // CryostatGeo::SortSubVolumes()
73 
74 
75  //......................................................................
77 
78  // update the cryostat ID
79  fID = cryoid;
80 
81  // trigger all the optical detectors to update
82  for (unsigned int opdet = 0; opdet < NOpDet(); ++opdet)
84 
85  // trigger all the TPCs to update as well
86  for (unsigned int tpc = 0; tpc < NTPC(); ++tpc)
88 
89  } // CryostatGeo::UpdateAfterSorting()
90 
91 
92  //......................................................................
93  const TPCGeo& CryostatGeo::TPC(unsigned int itpc) const
94  {
95  TPCGeo const* pTPC = TPCPtr(itpc);
96  if(!pTPC){
97  throw cet::exception("TPCOutOfRange") << "Request for non-existant TPC "
98  << itpc << "\n";
99  }
100 
101  return *pTPC;
102  }
103 
104 
105 
106  //......................................................................
107  const OpDetGeo& CryostatGeo::OpDet(unsigned int iopdet) const
108  {
109  if(iopdet >= fOpDets.size()){
110  throw cet::exception("OpDetOutOfRange") << "Request for non-existant OpDet "
111  << iopdet;
112  }
113 
114  return fOpDets[iopdet];
115  }
116 
117 
118  //......................................................................
120  { return fTPCs; }
121 
122 
123  //......................................................................
124  // wiggle is 1+a small number to allow for rounding errors on the
125  // passed in world loc relative to the boundaries.
127  (double const worldLoc[3], double wiggle) const
128  {
129  geo::TPCID tpcid
130  = PositionToTPCID(geo::vect::makePointFromCoords(worldLoc), wiggle);
131  return tpcid? tpcid.TPC: geo::TPCID::InvalidID;
132  } // CryostatGeo::FindTPCAtPosition()
133 
134  //......................................................................
135  // wiggle is 1+a small number to allow for rounding errors on the
136  // passed in world loc relative to the boundaries.
138  (geo::Point_t const& point, double wiggle) const
139  {
140  geo::TPCGeo const* tpc = PositionToTPCptr(point, wiggle);
141  return tpc? tpc->ID(): geo::TPCID{};
142  }
143 
144  //......................................................................
145  // wiggle is 1+a small number to allow for rounding errors on the
146  // passed in world loc relative to the boundaries.
148  (geo::Point_t const& point, double wiggle) const
149  {
150  geo::TPCGeo const* tpc = PositionToTPCptr(point, wiggle);
151  if (!tpc) {
152  throw cet::exception("CryostatGeo")
153  << "Can't find any TPC for position " << point << " within " << ID()
154  << "\n";
155  }
156  return *tpc;
157  }
158 
159  //......................................................................
161  (geo::Point_t const& point, double wiggle) const
162  {
163  for (auto const& tpc: IterateTPCs())
164  if (tpc.ContainsPosition(point, wiggle)) return &tpc;
165  return nullptr;
166  } // CryostatGeo::PositionToTPCptr()
167 
168 
169  //......................................................................
170  unsigned int CryostatGeo::MaxPlanes() const {
171  unsigned int maxPlanes = 0;
172  for (geo::TPCGeo const& TPC: fTPCs) {
173  unsigned int maxPlanesInTPC = TPC.Nplanes();
174  if (maxPlanesInTPC > maxPlanes) maxPlanes = maxPlanesInTPC;
175  } // for
176  return maxPlanes;
177  } // CryostatGeo::MaxPlanes()
178 
179  //......................................................................
180  unsigned int CryostatGeo::MaxWires() const {
181  unsigned int maxWires = 0;
182  for (geo::TPCGeo const& TPC: fTPCs) {
183  unsigned int maxWiresInTPC = TPC.MaxWires();
184  if (maxWiresInTPC > maxWires) maxWires = maxWiresInTPC;
185  } // for
186  return maxWires;
187  } // CryostatGeo::MaxWires()
188 
189  //......................................................................
190  double CryostatGeo::HalfWidth() const
191  {
192  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDX();
193  }
194 
195  //......................................................................
196  double CryostatGeo::HalfHeight() const
197  {
198  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDY();
199  }
200 
201  //......................................................................
202  double CryostatGeo::HalfLength() const
203  {
204  return static_cast<TGeoBBox const*>(fVolume->GetShape())->GetDZ();
205  }
206 
207  //......................................................................
208  void CryostatGeo::Boundaries(double* boundaries) const {
209  boundaries[0] = MinX();
210  boundaries[1] = MaxX();
211  boundaries[2] = MinY();
212  boundaries[3] = MaxY();
213  boundaries[4] = MinZ();
214  boundaries[5] = MaxZ();
215  } // CryostatGeo::CryostatBoundaries(double*)
216 
217 
218  //......................................................................
220  (std::string indent /* = "" */, unsigned int verbosity /* = 1 */) const
221  {
222  std::ostringstream sstr;
223  PrintCryostatInfo(sstr, indent, verbosity);
224  return sstr.str();
225  } // CryostatGeo::CryostatInfo()
226 
227  //......................................................................
228  // Find the nearest opdet to point in this cryostat
229 
231  (geo::Point_t const& point) const
232  {
233  unsigned int iOpDet = GetClosestOpDet(point);
234  return
235  (iOpDet == std::numeric_limits<double>::max())? nullptr: &OpDet(iOpDet);
236  }
237 
238  //......................................................................
239  unsigned int CryostatGeo::GetClosestOpDet(geo::Point_t const& point) const {
240  unsigned int ClosestDet = std::numeric_limits<unsigned int>::max();
241  double ClosestDist = std::numeric_limits<double>::max();
242 
243  for(unsigned int o = 0U; o < NOpDet(); ++o) {
244  double const ThisDist = OpDet(o).DistanceToPoint(point);
245  if(ThisDist < ClosestDist) {
246  ClosestDist = ThisDist;
247  ClosestDet = o;
248  }
249  } // for
250  return ClosestDet;
251  } // CryostatGeo::GetClosestOpDet(geo::Point_t)
252 
253  //......................................................................
254  unsigned int CryostatGeo::GetClosestOpDet(double const* point) const
256 
257  //......................................................................
259 
260  // check that this is indeed a box
261  if (!dynamic_cast<TGeoBBox*>(Volume()->GetShape())) {
262  // at initialisation time we don't know yet our real ID
263  throw cet::exception("CryostatGeo") << "Cryostat is not a box! (it is a "
264  << Volume()->GetShape()->IsA()->GetName() << ")\n";
265  }
266 
267  // get the half width, height, etc of the cryostat
268  const double halflength = HalfLength();
269  const double halfwidth = HalfWidth();
270  const double halfheight = HalfHeight();
271 
273  toWorldCoords(LocalPoint_t{ -halfwidth, -halfheight, -halflength }),
274  toWorldCoords(LocalPoint_t{ +halfwidth, +halfheight, +halflength })
275  );
276 
277  } // CryostatGeo::InitCryoBoundaries()
278 
279 
280  //......................................................................
281 
282 } // namespace geo
283 ////////////////////////////////////////////////////////////////////////
geo::TPCID const & ID() const
Returns the identifier of this TPC.
Definition: TPCGeo.h:333
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:51
static constexpr TPCID_t InvalidID
Special code for an invalid ID.
Definition: geo_types.h:403
Encapsulate the construction of a single cyostat.
unsigned int MaxPlanes() const
Returns the largest number of planes among the TPCs in this cryostat.
std::string string
Definition: nybbler.cc:12
TGeoVolume * fVolume
Total volume of cryostat, called volCryostat in GDML file.
Definition: CryostatGeo.h:477
unsigned int Nplanes() const
Number of planes in this tpc.
Definition: TPCGeo.h:165
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:38
ElementIteratorBox IterateTPCs() const
Returns an object suitable for iterating through all TPCs.
Definition: CryostatGeo.h:258
std::vector< geo::TPCGeo > TPCList_t
Type used internally to store the TPCs.
Definition: CryostatGeo.h:48
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:476
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:33
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Apply sorting to the PlaneGeo objects.
Definition: TPCGeo.cxx:201
GENVECTOR_CONSTEXPR::geo::Point_t makePointFromCoords(Coords &&coords)
Creates a geo::Point_t from its coordinates (see makeFromCoords()).
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:478
Interface to algorithm class for sorting geo::XXXGeo objects.
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Method to sort TPCGeo objects.
Definition: CryostatGeo.cxx:63
void PrintCryostatInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this cryostat.
Definition: CryostatGeo.h:489
geo::OpDetGeo const * GetClosestOpDetPtr(geo::Point_t const &point) const
const TGeoVolume * Volume() const
Pointer to ROOT&#39;s volume descriptor.
Definition: CryostatGeo.h:111
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet&#39;th optical detector in the cryostat.
geo::Point3DBase_t< CryostatGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML cryostat frame.
Definition: CryostatGeo.h:78
def move(depos, offset)
Definition: depos.py:107
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:283
unsigned int NTPC() const
Number of TPCs in this cryostat.
Definition: CryostatGeo.h:181
geo::CryostatID fID
ID of this cryostat.
Definition: CryostatGeo.h:479
static int max(int a, int b)
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
unsigned int MaxWires() const
Returns the largest number of wires among the planes in this TPC.
Definition: TPCGeo.cxx:297
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:76
double MaxY() const
Returns the world y coordinate of the end of the box.
double HalfHeight() const
Half height of the cryostat [cm].
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:184
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.
geo::TPCID::TPCID_t FindTPCAtPosition(double const worldLoc[3], double const wiggle) const
Returns the index of the TPC at specified location.
double DistanceToPoint(geo::Point_t const &point) const
Returns the distance of the specified point from detector center [cm].
Definition: OpDetGeo.cxx:123
unsigned int TPCID_t
Type for the ID number.
Definition: geo_types.h:387
TPCList_t fTPCs
List of tpcs in this cryostat.
Definition: CryostatGeo.h:475
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:93
unsigned int NOpDet() const
Number of optical detectors in this TPC.
Definition: CryostatGeo.h:361
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:115
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:406
The data type to uniquely identify a optical detector.
Definition: geo_types.h:297
LArSoft geometry interface.
Definition: ChannelGeo.h:16
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:403
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:190
geo::CryostatID const & ID() const
Returns the identifier of this cryostat.
Definition: CryostatGeo.h:132
ElementIteratorBox IterateElements() const
Returns an object suitable for iterating through all TPCs.