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