AuxDetGeo.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file AuxDetGeo.cxx
3 /// \brief Encapsulate the geometry of an auxilary detector
4 ///
5 /// \author miceli@fnal.gov
6 ////////////////////////////////////////////////////////////////////////
7 
8 // class header
10 
11 // LArSoft libraries
12 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect namespace
14 
15 // ROOT
16 #include "TGeoTrd2.h"
17 #include "TGeoBBox.h"
18 #include "TGeoNode.h"
19 
20 // Framework includes
22 #include "cetlib_except/exception.h"
23 
24 // C/C++ libraries
25 #include <sstream> // std::ostringstream
26 #include <string>
27 #include <limits>
28 
29 namespace geo{
30 
31  //-----------------------------------------
33  TGeoNode const& node, geo::TransformationMatrix&& trans,
34  AuxDetSensitiveList_t&& sensitive
35  )
36  : fTotalVolume(node.GetVolume())
37  , fTrans(std::move(trans))
38  , fSensitive(std::move(sensitive))
39  {
40 
41  if(!fTotalVolume)
42  throw cet::exception("AuxDetGeo") << "cannot find AuxDet volume\n";
43 
44  MF_LOG_DEBUG("Geometry") << "detector total volume is " << fTotalVolume->GetName();
45 
46  // if there are no sensitive volumes then this aux det
47  // could be from an older gdml file than the introduction of AuxDetSensitiveGeo
48  // in that case assume the full AuxDetGeo is sensitive and copy its information
49  // into a single AuxDetSensitive
50  if (fSensitive.empty())
51  fSensitive.emplace_back(node, geo::TransformationMatrix(fTrans.Matrix()));
52 
53  InitShapeSize();
54 
55  }
56 
57  //......................................................................
58  geo::Point_t AuxDetGeo::GetCenter(double localz /* = 0.0 */) const
59  { return toWorldCoords(LocalPoint_t{ 0.0, 0.0, localz }); }
60 
61  //......................................................................
62  void AuxDetGeo::GetCenter(double* xyz, double localz) const {
63  auto const& center = GetCenter(localz);
64  xyz[0] = center.X();
65  xyz[1] = center.Y();
66  xyz[2] = center.Z();
67  } // AuxDetGeo::GetCenter(double*)
68 
69  //......................................................................
70 
71  // Return the unit normal vector (0,0,1) in local coordinates to global coordinates
73  { return toWorldCoords(geo::Zaxis<LocalVector_t>()); }
74 
75  //......................................................................
76 
77  // Return the unit normal vector (0,0,1) in local coordinates to global coordinates
78  void AuxDetGeo::GetNormalVector(double* xyzDir) const {
79  auto const& norm = GetNormalVector();
80  xyzDir[0] = norm.X();
81  xyzDir[1] = norm.Y();
82  xyzDir[2] = norm.Z();
83  } // AuxDetGeo::GetNormalVector(double*)
84 
85 
86  //......................................................................
87  geo::Length_t AuxDetGeo::DistanceToPoint(double const* point) const
89 
90  //......................................................................
91  std::size_t AuxDetGeo::FindSensitiveVolume(geo::Point_t const& point) const
92  {
93  for(std::size_t a = 0; a < fSensitive.size(); ++a) {
94  auto const& sensVol = SensitiveVolume(a);
95 
96  auto const local = sensVol.toLocalCoords(point);
97 
98  double const HalfCenterWidth = sensVol.HalfCenterWidth();
99 
100  double const deltaWidth
101  = local.Z()*(HalfCenterWidth-sensVol.HalfWidth2())/sensVol.HalfLength();
102 
103  if (local.Z() >= - sensVol.HalfLength() &&
104  local.Z() <= sensVol.HalfLength() &&
105  local.Y() >= - sensVol.HalfHeight() &&
106  local.Y() <= sensVol.HalfHeight() &&
107  // if SensitiveVolume a is a box, then HalfSmallWidth = HalfWidth
108  local.X() >= - HalfCenterWidth + deltaWidth &&
109  local.X() <= HalfCenterWidth - deltaWidth
110  ) return a;
111 
112  }// for loop over AuxDetSensitive a
113 
114  throw cet::exception("AuxDetGeo")
115  << "Can't find AuxDetSensitive for position " << point << "\n";
116  // the following is not very useful right now...
118  } // AuxDetGeo::FindSensitiveVolume(geo::Point_t)
119 
120  //......................................................................
121  std::size_t AuxDetGeo::FindSensitiveVolume(double const worldPos[3]) const
123 
124 
125  //......................................................................
127  (geo::Point_t const& point, size_t& sv) const
128  {
129  sv = FindSensitiveVolume(point);
131  throw cet::exception("AuxDetGeo")
132  << "Can't find AuxDetSensitiveGeo for position " << point << "\n";
133  }
134  return SensitiveVolume(sv);
135  }
136 
137  //......................................................................
139  (double const worldLoc[3], size_t& sv) const
141 
142  //......................................................................
144  {
146  }
147 
148  //......................................................................
150  (std::string indent /* = "" */, unsigned int verbosity /* = 1 */) const
151  {
152  std::ostringstream sstr;
153  PrintAuxDetInfo(sstr, indent, verbosity);
154  return sstr.str();
155  } // AuxDetGeo::AuxDetInfo()
156 
157 
158  //......................................................................
160  // set the ends depending on whether the shape is a box or trapezoid
161  std::string volName(fTotalVolume->GetName());
162  if( volName.find("Trap") != std::string::npos ) {
163 
164  // Small Width
165  // ____ Height is the thickness
166  // / \ T of the trapezoid
167  // / \ |
168  // / \ | Length
169  // /__________\ _
170  // Width
171  fHalfHeight = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDy1(); // same as Dy2()
172  fLength = 2.0*((TGeoTrd2*)fTotalVolume->GetShape())->GetDz();
173  fHalfWidth1 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx1(); // at -Dz
174  fHalfWidth2 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx2(); // at +Dz
175  }
176  else {
177  fHalfWidth1 = ((TGeoBBox*)fTotalVolume->GetShape())->GetDX();
178  fHalfHeight = ((TGeoBBox*)fTotalVolume->GetShape())->GetDY();
179  fLength = 2.0*((TGeoBBox*)fTotalVolume->GetShape())->GetDZ();
181  }
182  } // AuxDetGeo::InitShapeSize()
183 
184  //......................................................................
185 
186 }
187 ////////////////////////////////////////////////////////////////////////
std::string AuxDetInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with auxiliary detector information.
Definition: AuxDetGeo.cxx:150
Utilities to extend the interface of geometry vectors.
std::string string
Definition: nybbler.cc:12
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:171
double fHalfWidth2
2nd half width (width1==width2 for boxes), at +z/2
Definition: AuxDetGeo.h:227
geo::Length_t DistanceToPoint(geo::Point_t const &point) const
Returns the distance of point from the center of the detector.
Definition: AuxDetGeo.h:111
LocalTransformation_t fTrans
Auxiliary detector-to-world transformation.
Definition: AuxDetGeo.h:224
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:226
STL namespace.
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Definition: AuxDetGeo.cxx:143
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
geo::Point3DBase_t< AuxDetGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML auxiliary detector frame.
Definition: AuxDetGeo.h:64
double fLength
length of volume, along z direction in local
Definition: AuxDetGeo.h:225
AuxDetSensitiveGeo const & PositionToSensitiveVolume(geo::Point_t const &point, size_t &sv) const
Definition: AuxDetGeo.cxx:127
GENVECTOR_CONSTEXPR::geo::Point_t makePointFromCoords(Coords &&coords)
Creates a geo::Point_t from its coordinates (see makeFromCoords()).
Interface to algorithm class for sorting geo::XXXGeo objects.
const TGeoVolume * fTotalVolume
Total volume of AuxDet, called vol*.
Definition: AuxDetGeo.h:223
std::size_t FindSensitiveVolume(geo::Point_t const &point) const
Definition: AuxDetGeo.cxx:91
const double a
def move(depos, offset)
Definition: depos.py:107
virtual void SortAuxDetSensitive(std::vector< geo::AuxDetSensitiveGeo > &adsgeo) const =0
Encapsulate the geometry of an auxiliary detector.
geo::Vector_t GetNormalVector() const
Returns the unit normal vector to the detector.
Definition: AuxDetGeo.cxx:72
static int max(int a, int b)
auto norm(Vector const &v)
Return norm of the specified vector.
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
double Length_t
Type used for coordinates and distances. They are measured in centimeters.
Definition: geo_vectors.h:137
AuxDetGeo(TGeoNode const &node, geo::TransformationMatrix &&trans, AuxDetSensitiveList_t &&sensitive)
Definition: AuxDetGeo.cxx:32
def center(depos, point)
Definition: depos.py:117
#define MF_LOG_DEBUG(id)
std::vector< geo::AuxDetSensitiveGeo > AuxDetSensitiveList_t
Type of list of sensitive volumes.
Definition: AuxDetGeo.h:42
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double fHalfHeight
half height of volume
Definition: AuxDetGeo.h:228
void InitShapeSize()
Extracts the size of the detector from the geometry information.
Definition: AuxDetGeo.cxx:159
void PrintAuxDetInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this auxiliary detector.
Definition: AuxDetGeo.h:245
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:124
std::vector< AuxDetSensitiveGeo > fSensitive
sensitive volumes in the detector
Definition: AuxDetGeo.h:229
void GetCenter(double *xyz, double localz=0.0) const
Return the center position of an AuxDet.
Definition: AuxDetGeo.cxx:62