LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
GeometryBuilderStandard.cxx
Go to the documentation of this file.
1 
7 // LArSoft libraries
11 
12 // ROOT libraries
13 #include "TGeoNode.h"
14 
15 // C++ standard library
16 #include <algorithm>
17 #include <string_view>
18 #include <tuple>
19 
20 using namespace std::literals;
21 
22 namespace {
25  bool starts_with(std::string_view const s, std::string_view const key)
26  {
27  return s.compare(0, key.size(), key) == 0;
28  }
29 
30  bool isAuxDetNode(TGeoNode const& node)
31  {
32  return starts_with(node.GetName(), "volAuxDet"sv);
33  }
34  bool isAuxDetSensitiveNode(TGeoNode const& node)
35  {
36  return std::string_view(node.GetName()).find("Sensitive") != std::string_view::npos;
37  }
38  bool isCryostatNode(TGeoNode const& node)
39  {
40  return starts_with(node.GetName(), "volCryostat"sv);
41  }
42 
43  bool isOpDetNode(TGeoNode const& node, std::string_view const opDetGeoName)
44  {
45  return starts_with(node.GetName(), opDetGeoName);
46  }
47  bool isTPCNode(TGeoNode const& node)
48  {
49  return starts_with(node.GetName(), "volTPC"sv);
50  }
51  bool isPlaneNode(TGeoNode const& node)
52  {
53  return starts_with(node.GetName(), "volTPCPlane"sv);
54  }
55 
56  geo::DriftSign PosOrNeg(bool const condition)
57  {
59  }
60 
61  //......................................................................
62  geo::DriftAxis DriftAxisWithSign(geo::Point_t const& TPCcenter,
63  std::vector<geo::PlaneGeo> const& planes)
64  {
65  auto const PlaneCenter = planes[0].GetBoxCenter(); // any will do
66 
67  auto const driftVector = PlaneCenter - TPCcenter; // approximation!
68 
69  if ((std::abs(driftVector.X()) > std::abs(driftVector.Y())) &&
70  (std::abs(driftVector.X()) > std::abs(driftVector.Z()))) {
71  return {geo::Coordinate::X, PosOrNeg(driftVector.X() > 0)};
72  }
73  if (std::abs(driftVector.Y()) > std::abs(driftVector.Z())) {
74  return {geo::Coordinate::Y, PosOrNeg(driftVector.Y() > 0)};
75  }
76  return {geo::Coordinate::Z, PosOrNeg(driftVector.Z() > 0)};
77  }
78 
79  //------------------------------------------------------------------------------
80  geo::AuxDetSensitiveGeo makeAuxDetSensitive(geo::GeoNodePath const& path)
81  {
83  }
84 
85  geo::OpDetGeo makeOpDet(geo::GeoNodePath const& path)
86  {
88  }
89 
91  {
92  // Planes are constructed only to provide information for the TPC constructor. We
93  // therefore can supply an empty wires collection with them.
94  return {path.current(),
96  std::vector<geo::WireGeo>{}};
97  }
98 
99  double driftDistance(geo::Point_t result,
100  geo::DriftAxis const drift_axis_with_sign,
101  TGeoBBox const* active_volume_box,
102  geo::Point_t last_plane_box_center)
103  {
104  auto const [axis, sign] = drift_axis_with_sign;
105  auto const [offX, offY, offZ] = std::tuple{
106  active_volume_box->GetDX(), active_volume_box->GetDY(), active_volume_box->GetDZ()};
107 
108  switch (axis) {
109  case geo::Coordinate::X: {
110  double const cathode_x = result.X() - to_int(sign) * offX;
111  return std::abs(cathode_x - last_plane_box_center.X());
112  }
113  case geo::Coordinate::Y: {
114  double const cathode_y = result.Y() - to_int(sign) * offY;
115  return std::abs(cathode_y - last_plane_box_center.Y());
116  }
117  case geo::Coordinate::Z: {
118  double const cathode_z = result.Z() - to_int(sign) * offZ;
119  return std::abs(cathode_z - last_plane_box_center.Z());
120  }
121  }
122 
123  // unreachable
124  return {};
125  }
126 }
127 
128 //------------------------------------------------------------------------------
130  : fExtractObjects(config().extractor()), fOpDetGeoName(config().opDetGeoName())
131 {}
132 
133 //------------------------------------------------------------------------------
135 {
136  std::vector<AuxDetGeo> result;
138  path, isAuxDetNode, [&result, this](Path_t& path) { result.push_back(makeAuxDet(path)); });
139  return result;
140 }
141 
142 //------------------------------------------------------------------------------
144 {
145  return {path.current(),
147  extractAuxDetSensitive(path)};
148 }
149 
150 //------------------------------------------------------------------------------
152 {
153  std::vector<AuxDetSensitiveGeo> result;
154  fExtractObjects(path, isAuxDetSensitiveNode, [&result](Path_t const& path) {
155  result.push_back(makeAuxDetSensitive(path));
156  });
157  return result;
158 }
159 
160 //------------------------------------------------------------------------------
162 {
163  std::vector<CryostatGeo> result;
165  path, isCryostatNode, [&result, this](Path_t& path) { result.push_back(makeCryostat(path)); });
166  return result;
167 }
168 
169 //------------------------------------------------------------------------------
171 {
172  return {path.current(),
174  extractTPCs(path),
175  extractOpDets(path)};
176 }
177 
178 //------------------------------------------------------------------------------
180 {
181  std::vector<OpDetGeo> result;
183  path,
184  [this](auto const& node) { return isOpDetNode(node, fOpDetGeoName); },
185  [&result](Path_t const& path) { result.push_back(makeOpDet(path)); });
186  return result;
187 }
188 
189 //------------------------------------------------------------------------------
191 {
192  std::vector<TPCGeo> result;
194  path, isTPCNode, [&result, this](Path_t& path) { result.push_back(makeTPC(path)); });
195  return result;
196 }
197 
198 //------------------------------------------------------------------------------
200 {
201  auto const [tpc, hash_value] = path.current_entry();
202  auto tpc_matrix = path.currentTransformation<TransformationMatrix>();
203 
204  std::vector<PlaneGeo> planes;
206  path, isPlaneNode, [&planes](Path_t& path) { planes.push_back(makePlane(path)); });
207 
208  // we don't keep the active volume information... just store its center:
209  auto const* active_volume_node = TPCGeo::NodeForActiveVolume(tpc);
210  assert(active_volume_node);
211 
212  auto const daughter_matrix =
213  tpc_matrix * makeTransformationMatrix(*active_volume_node->GetMatrix());
214  auto const active_volume_center =
215  vect::toPoint(daughter_matrix(ROOT::Math::Transform3D::Point{}));
216 
217  auto const driftAxisWithSign = DriftAxisWithSign(active_volume_center, planes);
218  auto const driftAxis = vect::normalize(planes[0].GetBoxCenter() - active_volume_center);
219  double distance_to_last_plane{std::numeric_limits<double>::min()};
220  geo::PlaneGeo const* last_plane = nullptr;
221  for (auto const& plane : planes) {
222  double const distance = vect::dot(plane.GetBoxCenter() - active_volume_center, driftAxis);
223  if (distance > distance_to_last_plane) {
224  distance_to_last_plane = distance;
225  last_plane = &plane;
226  }
227  }
228 
229  auto const* active_volume_box =
230  static_cast<TGeoBBox const*>(active_volume_node->GetVolume()->GetShape());
231  auto const drift_distance = driftDistance(
232  active_volume_center, driftAxisWithSign, active_volume_box, last_plane->GetBoxCenter());
233 
234  return {tpc, hash_value, std::move(tpc_matrix), driftAxisWithSign, drift_distance};
235 }
CryostatGeo makeCryostat(Path_t &path) const
Constructs a geo::CryostatGeo from the current node of the path.
TGeoNode const * current() const
Returns the current node. Undefined if the path is empty.
Definition: GeoNodePath.cxx:51
GeoColl_t< AuxDetSensitiveGeo > AuxDetSensitive_t
Geometry information for a single TPC.
Definition: TPCGeo.h:33
TPCs_t extractTPCs(Path_t &path) const
Looks for all TPCs under the specified path.
constexpr auto abs(T v)
Returns the absolute value of the argument.
GeoColl_t< AuxDetGeo > AuxDets_t
Collection of auxiliary detector information objects.
AuxDetGeo makeAuxDet(Path_t &path) const
Constructs a geo::AuxDetGeo from the current node of the path.
Geometry information for a single cryostat.
Definition: CryostatGeo.h:42
OpDets_t extractOpDets(Path_t &path) const
Looks for all optical detectors under the specified path.
GeoColl_t< CryostatGeo > Cryostats_t
Collection of cryostat information objects.
GeometryBuilderStandard(fhicl::Table< Config > const &config)
Point_t GetBoxCenter() const
Returns the centre of the box representing the plane.
Definition: PlaneGeo.h:380
Drift towards negative values.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:67
Cryostats_t doExtractCryostats(Path_t &path) const override
constexpr int to_int(Coordinate const coord) noexcept
Enumerate the possible plane projections.
Definition: geo_types.h:124
Plane makePlane(recob::tracking::Point_t const &pos, recob::tracking::Vector_t const &dir)
helper function to construct a recob::tracking::Plane from a Point_t and a Vector_t; the point is on ...
decltype(auto) makeTransformationMatrix(Trans &&trans)
Converts a transformation matrix into a geo::TransformationMatrix.
Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
static TGeoNode const * NodeForActiveVolume(TGeoNode const *tpc)
Definition: TPCGeo.cxx:213
constexpr auto dot(Vector const &a, OtherVector const &b)
Return cross product of two vectors.
Entry current_entry() const
Returns the current node. Undefined if the path is empty.
Definition: GeoNodePath.cxx:56
Matrix currentTransformation() const
Returns the total transformation to the current node, as a Matrix.
Definition: GeoNodePath.h:94
AuxDets_t doExtractAuxiliaryDetectors(Path_t &path) const override
Encapsulate the geometry of a wire .
int sign(double val)
Definition: UtilFunc.cxx:104
Drift towards positive values.
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
DriftSign
Drift sign: positive or negative.
Definition: geo_types.h:155
AuxDetSensitive_t extractAuxDetSensitive(Path_t &path) const
Looks for all auxiliary detectors under the specified path.
Encapsulate the construction of a single detector plane .
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:42
Representation of a node and its ancestry.
Definition: GeoNodePath.h:34
Vector normalize(Vector const &v)
Returns a vector parallel to v and with norm 1.
TPCGeo makeTPC(Path_t &path) const
Constructs a geo::TPCGeo from the current node of the path.
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.