LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
AuxDetGeo.cxx
Go to the documentation of this file.
1 
8 // class header
10 
11 // LArSoft libraries
13 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect namespace
14 
15 // ROOT
16 #include "TGeoBBox.h"
17 #include "TGeoNode.h"
18 #include "TGeoTrd2.h"
19 
20 // Framework includes
21 #include "cetlib_except/exception.h"
23 
24 // C/C++ libraries
25 #include <limits>
26 #include <sstream> // std::ostringstream
27 #include <string>
28 
29 namespace geo {
30 
31  //-----------------------------------------
32  AuxDetGeo::AuxDetGeo(TGeoNode const& node,
34  AuxDetSensitiveList_t&& sensitive)
35  : fTotalVolume(node.GetVolume()), fTrans(std::move(trans)), fSensitive(std::move(sensitive))
36  {
37  if (!fTotalVolume) throw cet::exception("AuxDetGeo") << "cannot find AuxDet volume\n";
38 
39  MF_LOG_DEBUG("Geometry") << "detector total volume is " << fTotalVolume->GetName();
40 
41  // if there are no sensitive volumes then this aux det
42  // could be from an older gdml file than the introduction of AuxDetSensitiveGeo
43  // in that case assume the full AuxDetGeo is sensitive and copy its information
44  // into a single AuxDetSensitive
45  if (fSensitive.empty())
46  fSensitive.emplace_back(node, geo::TransformationMatrix(fTrans.Matrix()));
47 
48  InitShapeSize();
49  }
50 
51  //......................................................................
52  geo::Point_t AuxDetGeo::GetCenter(double localz /* = 0.0 */) const
53  {
54  return toWorldCoords(LocalPoint_t{0.0, 0.0, localz});
55  }
56 
57  //......................................................................
58 
59  // Return the unit normal vector (0,0,1) in local coordinates to global coordinates
61  {
62  return toWorldCoords(geo::Zaxis<LocalVector_t>());
63  }
64 
65  //......................................................................
66  std::size_t AuxDetGeo::FindSensitiveVolume(geo::Point_t const& point) const
67  {
68  for (std::size_t a = 0; a < fSensitive.size(); ++a) {
69  auto const& sensVol = SensitiveVolume(a);
70 
71  auto const local = sensVol.toLocalCoords(point);
72 
73  double const HalfCenterWidth = sensVol.HalfCenterWidth();
74 
75  double const deltaWidth =
76  local.Z() * (HalfCenterWidth - sensVol.HalfWidth2()) / sensVol.HalfLength();
77 
78  if (local.Z() >= -sensVol.HalfLength() && local.Z() <= sensVol.HalfLength() &&
79  local.Y() >= -sensVol.HalfHeight() && local.Y() <= sensVol.HalfHeight() &&
80  // if SensitiveVolume a is a box, then HalfSmallWidth = HalfWidth
81  local.X() >= -HalfCenterWidth + deltaWidth && local.X() <= HalfCenterWidth - deltaWidth)
82  return a;
83 
84  } // for loop over AuxDetSensitive a
85 
86  throw cet::exception("AuxDetGeo")
87  << "Can't find AuxDetSensitive for position " << point << "\n";
88  } // AuxDetGeo::FindSensitiveVolume(geo::Point_t)
89 
90  //......................................................................
92  size_t& sv) const
93  {
94  sv = FindSensitiveVolume(point);
95  if (sv == std::numeric_limits<std::size_t>::max()) {
96  throw cet::exception("AuxDetGeo")
97  << "Can't find AuxDetSensitiveGeo for position " << point << "\n";
98  }
99  return SensitiveVolume(sv);
100  }
101 
102  //......................................................................
104  {
106  }
107 
108  //......................................................................
109  std::string AuxDetGeo::AuxDetInfo(std::string indent /* = "" */,
110  unsigned int verbosity /* = 1 */) const
111  {
112  std::ostringstream sstr;
113  PrintAuxDetInfo(sstr, indent, verbosity);
114  return sstr.str();
115  }
116 
117  //......................................................................
119  {
120  // set the ends depending on whether the shape is a box or trapezoid
121  std::string volName(fTotalVolume->GetName());
122  if (volName.find("Trap") != std::string::npos) {
123 
124  // Small Width
125  // ____ Height is the thickness
126  // / \ T of the trapezoid
127  // / \ |
128  // / \ | Length
129  // /__________\ _
130  // Width
131  fHalfHeight = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDy1(); // same as Dy2()
132  fLength = 2.0 * ((TGeoTrd2*)fTotalVolume->GetShape())->GetDz();
133  fHalfWidth1 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx1(); // at -Dz
134  fHalfWidth2 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx2(); // at +Dz
135  }
136  else {
137  fHalfWidth1 = ((TGeoBBox*)fTotalVolume->GetShape())->GetDX();
138  fHalfHeight = ((TGeoBBox*)fTotalVolume->GetShape())->GetDY();
139  fLength = 2.0 * ((TGeoBBox*)fTotalVolume->GetShape())->GetDZ();
141  }
142  }
143 
144  //......................................................................
145 
146 }
std::string AuxDetInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with auxiliary detector information.
Definition: AuxDetGeo.cxx:109
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
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:143
double fHalfWidth2
2nd half width (width1==width2 for boxes), at +z/2
Definition: AuxDetGeo.h:194
LocalTransformation_t fTrans
Auxiliary detector-to-world transformation.
Definition: AuxDetGeo.h:191
TransformationMatrix_t const & Matrix() const
Direct access to the transformation matrix.
double fHalfWidth1
1st half width of volume, at -z/2 in local coordinates
Definition: AuxDetGeo.h:193
STL namespace.
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Definition: AuxDetGeo.cxx:103
geo::Point3DBase_t< AuxDetGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML auxiliary detector frame.
Definition: AuxDetGeo.h:63
double fLength
length of volume, along z direction in local
Definition: AuxDetGeo.h:192
AuxDetSensitiveGeo const & PositionToSensitiveVolume(geo::Point_t const &point, size_t &sv) const
Definition: AuxDetGeo.cxx:91
Interface to algorithm class for sorting geo::XXXGeo objects.
const TGeoVolume * fTotalVolume
Total volume of AuxDet, called vol*.
Definition: AuxDetGeo.h:190
std::size_t FindSensitiveVolume(geo::Point_t const &point) const
Definition: AuxDetGeo.cxx:66
virtual void SortAuxDetSensitive(std::vector< geo::AuxDetSensitiveGeo > &adsgeo) const =0
std::string indent(std::size_t const i)
Utilities to extend the interface of geometry vectors.
geo::Vector_t GetNormalVector() const
Returns the unit normal vector to the detector.
Definition: AuxDetGeo.cxx:60
Encapsulate the geometry of an auxiliary detector.
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
AuxDetGeo(TGeoNode const &node, geo::TransformationMatrix &&trans, AuxDetSensitiveList_t &&sensitive)
Definition: AuxDetGeo.cxx:32
#define MF_LOG_DEBUG(id)
geo::Point_t GetCenter(double localz=0.0) const
Returns the geometric center of the sensitive volume.
Definition: AuxDetGeo.cxx:52
std::vector< geo::AuxDetSensitiveGeo > AuxDetSensitiveList_t
Type of list of sensitive volumes.
Definition: AuxDetGeo.h:41
Namespace collecting geometry-related classes utilities.
double fHalfHeight
half height of volume
Definition: AuxDetGeo.h:195
void InitShapeSize()
Extracts the size of the detector from the geometry information.
Definition: AuxDetGeo.cxx:118
void PrintAuxDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this auxiliary detector.
Definition: AuxDetGeo.h:211
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local auxiliary detector frame to world frame.
Definition: AuxDetGeo.h:106
std::vector< AuxDetSensitiveGeo > fSensitive
sensitive volumes in the detector
Definition: AuxDetGeo.h:196