LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
AuxDetGeo.cxx
Go to the documentation of this file.
1 
8 // class header
10 
11 // LArSoft libraries
12 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect namespace
13 
14 // ROOT
15 #include "TGeoTrd2.h"
16 #include "TGeoBBox.h"
17 
18 // Framework includes
20 #include "cetlib_except/exception.h"
21 
22 // C/C++ libraries
23 #include <limits>
24 
25 namespace geo{
26 
27  //-----------------------------------------
28  AuxDetGeo::AuxDetGeo(std::vector<const TGeoNode*>& path, int depth)
29  : fTotalVolume(nullptr)
30  , fTrans(path, depth)
31  {
32 
33  TGeoVolume *vc = path[depth]->GetVolume();
34  if(vc){
35  fTotalVolume = vc;
36  if(!fTotalVolume)
37  throw cet::exception("AuxDetGeo") << "cannot find AuxDet volume\n";
38 
39  }// end if found volume
40 
41  LOG_DEBUG("Geometry") << "detector total volume is " << fTotalVolume->GetName();
42 
43  // look for sensitive volumes - if there are none then this aux det
44  // could be from an older gdml file than the introduction of AuxDetSensitiveGeo
45  // in that case assume the full AuxDetGeo is sensitive and copy its information
46  // into a single AuxDetSensitive
47  this->FindAuxDetSensitive(path, depth);
48  if (fSensitive.empty())
50 
51  InitShapeSize();
52 
53  }
54 
55  //......................................................................
57  for (auto const* sdet: fSensitive) delete sdet;
58  }
59 
60 
61  //......................................................................
62  void AuxDetGeo::FindAuxDetSensitive(std::vector<const TGeoNode*>& path,
63  unsigned int depth)
64  {
65  // Check if the current node is a senstive volume - we already know
66  // we are in an Auxiliary detector
67  std::string pathName(path[depth]->GetName());
68  if( pathName.find("Sensitive") != std::string::npos){
69  this->MakeAuxDetSensitive(path, depth);
70  return;
71  }
72 
73  // Explore the next layer down
74  unsigned int deeper = depth+1;
75  if (deeper>=path.size()) {
76  throw cet::exception("ExceededMaxDepth") << "Exceeded maximum depth\n";
77  }
78  const TGeoVolume* v = path[depth]->GetVolume();
79  int nd = v->GetNdaughters();
80  for (int i=0; i<nd; ++i) {
81  path[deeper] = v->GetNode(i);
82  this->FindAuxDetSensitive(path, deeper);
83  }
84  }
85 
86  //......................................................................
87  void AuxDetGeo::MakeAuxDetSensitive(std::vector<const TGeoNode*>& path, int depth)
88  {
89  fSensitive.push_back(new AuxDetSensitiveGeo(path, depth));
90  }
91 
92  //......................................................................
93  geo::Point_t AuxDetGeo::GetCenter(double localz /* = 0.0 */) const
94  { return toWorldCoords(LocalPoint_t{ 0.0, 0.0, localz }); }
95 
96  //......................................................................
97  void AuxDetGeo::GetCenter(double* xyz, double localz) const {
98  auto const& center = GetCenter(localz);
99  xyz[0] = center.X();
100  xyz[1] = center.Y();
101  xyz[2] = center.Z();
102  } // AuxDetGeo::GetCenter(double*)
103 
104  //......................................................................
105 
106  // Return the unit normal vector (0,0,1) in local coordinates to global coordinates
108  { return toWorldCoords(geo::Zaxis<LocalVector_t>()); }
109 
110  //......................................................................
111 
112  // Return the unit normal vector (0,0,1) in local coordinates to global coordinates
113  void AuxDetGeo::GetNormalVector(double* xyzDir) const {
114  auto const& norm = GetNormalVector();
115  xyzDir[0] = norm.X();
116  xyzDir[1] = norm.Y();
117  xyzDir[2] = norm.Z();
118  } // AuxDetGeo::GetNormalVector(double*)
119 
120 
121  //......................................................................
122  geo::Length_t AuxDetGeo::DistanceToPoint(double const* point) const
124 
125  //......................................................................
126  std::size_t AuxDetGeo::FindSensitiveVolume(geo::Point_t const& point) const
127  {
128  for(std::size_t a = 0; a < fSensitive.size(); ++a) {
129  auto const& sensVol = SensitiveVolume(a);
130 
131  auto const local = sensVol.toLocalCoords(point);
132 
133  double const HalfCenterWidth = sensVol.HalfCenterWidth();
134 
135  double const deltaWidth
136  = local.Z()*(HalfCenterWidth-sensVol.HalfWidth2())/sensVol.HalfLength();
137 
138  if (local.Z() >= - sensVol.HalfLength() &&
139  local.Z() <= sensVol.HalfLength() &&
140  local.Y() >= - sensVol.HalfHeight() &&
141  local.Y() <= sensVol.HalfHeight() &&
142  // if SensitiveVolume a is a box, then HalfSmallWidth = HalfWidth
143  local.X() >= - HalfCenterWidth + deltaWidth &&
144  local.X() <= HalfCenterWidth - deltaWidth
145  ) return a;
146 
147  }// for loop over AuxDetSensitive a
148 
149  throw cet::exception("AuxDetGeo")
150  << "Can't find AuxDetSensitive for position " << point << "\n";
151  // the following is not very useful right now...
153  } // AuxDetGeo::FindSensitiveVolume(geo::Point_t)
154 
155  //......................................................................
156  std::size_t AuxDetGeo::FindSensitiveVolume(double const worldPos[3]) const
158 
159 
160  //......................................................................
162  (geo::Point_t const& point, size_t& sv) const
163  {
164  sv = FindSensitiveVolume(point);
166  throw cet::exception("AuxDetGeo")
167  << "Can't find AuxDetSensitiveGeo for position " << point << "\n";
168  }
169  return SensitiveVolume(sv);
170  }
171 
172  //......................................................................
174  (double const worldLoc[3], size_t& sv) const
176 
177  //......................................................................
179  {
181 
182  return;
183  }
184 
185  //......................................................................
187  // set the ends depending on whether the shape is a box or trapezoid
188  std::string volName(fTotalVolume->GetName());
189  if( volName.find("Trap") != std::string::npos ) {
190 
191  // Small Width
192  // ____ Height is the thickness
193  // / \ T of the trapezoid
194  // / \ |
195  // / \ | Length
196  // /__________\ _
197  // Width
198  fHalfHeight = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDy1(); // same as Dy2()
199  fLength = 2.0*((TGeoTrd2*)fTotalVolume->GetShape())->GetDz();
200  fHalfWidth1 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx1(); // at -Dz
201  fHalfWidth2 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx2(); // at +Dz
202  }
203  else {
204  fHalfWidth1 = ((TGeoBBox*)fTotalVolume->GetShape())->GetDX();
205  fHalfHeight = ((TGeoBBox*)fTotalVolume->GetShape())->GetDY();
206  fLength = 2.0*((TGeoBBox*)fTotalVolume->GetShape())->GetDZ();
208  }
209  } // AuxDetGeo::InitShapeSize()
210 
211  //......................................................................
212 
213 }
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:167
void FindAuxDetSensitive(std::vector< const TGeoNode * > &path, unsigned int depth)
Definition: AuxDetGeo.cxx:62
double Length_t
Type used for coordinates and distances. They are measured in centimeters.
Definition: geo_vectors.h:140
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
Definition: AuxDetGeo.h:159
double fHalfWidth2
2nd half width (width1==width2 for boxes), at +z/2
Definition: AuxDetGeo.h:211
geo::Length_t DistanceToPoint(geo::Point_t const &point) const
Returns the distance of point from the center of the detector.
Definition: AuxDetGeo.h:99
LocalTransformation_t fTrans
Auxiliary detector-to-world transformation.
Definition: AuxDetGeo.h:208
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:210
void SortSubVolumes(geo::GeoObjectSorter const &sorter)
Definition: AuxDetGeo.cxx:178
geo::Point3DBase_t< AuxDetGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML auxiliary detector frame.
Definition: AuxDetGeo.h:53
double fLength
length of volume, along z direction in local
Definition: AuxDetGeo.h:209
AuxDetSensitiveGeo const & PositionToSensitiveVolume(geo::Point_t const &point, size_t &sv) const
Definition: AuxDetGeo.cxx:162
std::vector< AuxDetSensitiveGeo * > fSensitive
sensitive volumes in the detector
Definition: AuxDetGeo.h:213
const TGeoVolume * fTotalVolume
Total volume of AuxDet, called vol*.
Definition: AuxDetGeo.h:207
void MakeAuxDetSensitive(std::vector< const TGeoNode * > &path, int depth)
Definition: AuxDetGeo.cxx:87
Int_t max
Definition: plot.C:27
std::size_t FindSensitiveVolume(geo::Point_t const &point) const
Definition: AuxDetGeo.cxx:126
Utilities to extend the interface of geometry vectors.
virtual void SortAuxDetSensitive(std::vector< geo::AuxDetSensitiveGeo * > &adsgeo) const =0
AuxDetGeo(std::vector< const TGeoNode * > &path, int depth)
Definition: AuxDetGeo.cxx:28
geo::Vector_t GetNormalVector() const
Returns the unit normal vector to the detector.
Definition: AuxDetGeo.cxx:107
Encapsulate the geometry of an auxiliary detector.
Float_t norm
#define LOG_DEBUG(id)
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:187
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 fHalfHeight
half height of volume
Definition: AuxDetGeo.h:212
void InitShapeSize()
Extracts the size of the detector from the geometry information.
Definition: AuxDetGeo.cxx:186
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:112
void GetCenter(double *xyz, double localz=0.0) const
Return the center position of an AuxDet.
Definition: AuxDetGeo.cxx:97