LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
WireGeo.h
Go to the documentation of this file.
1 
9 #ifndef LARCOREALG_GEOMETRY_WIREGEO_H
10 #define LARCOREALG_GEOMETRY_WIREGEO_H
11 
12 // LArSoft
14 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect
15 
16 // ROOT
17 #include "TVector3.h"
18 #include "TGeoMatrix.h" // TGeoHMatrix
19 
20 // C/C++ libraries
21 #include <vector>
22 #include <cmath> // std::sin(), ...
23 
24 
25 // forward declarations
26 class TGeoNode;
27 
28 
29 namespace geo {
30 
31  struct WireID; // forward declaration
32 
33 
61  class WireGeo {
62 
63  using DefaultVector_t = TVector3; // ... not for long
64  using DefaultPoint_t = TVector3; // ... not for long
65 
66  public:
67 
68  using GeoNodePath_t = std::vector<TGeoNode const*>;
69 
71 
85  struct WireGeoCoordinatesTag {};
87 
90 
93 
95 
96  WireGeo(GeoNodePath_t const& path, size_t depth);
97 
98 
101 
103  double RMax() const;
104 
106  double HalfL() const { return fHalfL; }
107 
109  double RMin() const;
110 
125  void GetCenter(double* xyz, double localz=0.0) const;
126 
129  void GetStart(double* xyz) const { GetCenter(xyz, -fHalfL); }
130 
133  void GetEnd(double* xyz) const { GetCenter(xyz, +fHalfL); }
134 
149  template <typename Point = DefaultPoint_t>
150  Point GetPositionFromCenter(double localz) const
151  { return GetPositionFromCenterUnbounded<Point>(capLength(localz)); }
152 
166  template <typename Point = DefaultPoint_t>
167  Point GetPositionFromCenterUnbounded(double localz) const;
168 
170  template <typename Point = DefaultPoint_t>
171  Point GetCenter() const { return geo::vect::convertTo<Point>(fCenter); }
172 
174  template <typename Point = DefaultPoint_t>
175  Point GetStart() const
176  { return GetPositionFromCenterUnbounded<Point>(-HalfL()); }
177 
179  template <typename Point = DefaultPoint_t>
180  Point GetEnd() const
181  { return GetPositionFromCenterUnbounded<Point>(+HalfL()); }
182 
184  double Length() const { return 2. * HalfL(); }
185 
187 
190 
192  double ThetaZ() const { return fThetaZ; }
193 
199  double ThetaZ(bool degrees) const;
200 
202  double CosThetaZ() const { return std::cos(ThetaZ()); }
204  double SinThetaZ() const { return std::sin(ThetaZ()); }
205  double TanThetaZ() const { return std::tan(ThetaZ()); }
207 
209  bool isHorizontal() const { return std::abs(SinThetaZ()) < 1e-5; }
210 
212  bool isVertical() const { return std::abs(CosThetaZ()) < 1e-5; }
213 
215  bool isParallelTo(geo::WireGeo const& wire) const
216  {
217  return // parallel if the dot product of the directions is about +/- 1
218  std::abs(std::abs(Direction<geo::Vector_t>().Dot(wire.Direction<geo::Vector_t>())) - 1.) < 1e-5;
219  }
220 
222  template <typename Vector = DefaultVector_t>
223  Vector Direction() const;
224 
246  template <typename Stream>
247  void PrintWireInfo
248  (Stream&& out, std::string indent = "", unsigned int verbosity = 1) const;
249 
251  static constexpr unsigned int MaxVerbosity = 4;
252 
254 
255 
258 
260 
268  void LocalToWorld(const double* wire, double* world) const
270  { fTrans.LocalToWorld(wire, world); }
271 
274  { return fTrans.toWorldCoords(local); }
275 
277  void LocalToWorldVect(const double* wire, double* world) const
278  { fTrans.LocalToWorldVect(wire, world); }
279 
282  { return fTrans.toWorldCoords(local); }
283 
285  void WorldToLocal(const double* world, double* wire) const
286  { fTrans.WorldToLocal(world, wire); }
287 
290  { return fTrans.toLocalCoords(world); }
291 
293  void WorldToLocalVect(const double* world, double* wire) const
294  { fTrans.WorldToLocalVect(world, wire); }
295 
298  { return fTrans.toLocalCoords(world); }
299 
301 
302 
303  const TGeoNode* Node() const { return fWireNode; }
304 
307  double ComputeZatY0() const
308  { return fCenter.Z() - fCenter.Y() / TanThetaZ(); }
309 
317  double DistanceFrom(geo::WireGeo const& wire) const;
318 
319 
322  void UpdateAfterSorting(geo::WireID const&, bool flip);
323 
325  static double WirePitch(geo::WireGeo const& w1, geo::WireGeo const& w2)
326  { return std::abs(w2.DistanceFrom(w1)); }
327 
328  private:
331 
332  const TGeoNode* fWireNode;
333  double fThetaZ;
334  double fHalfL;
337  bool flipped;
338 
341  bool isFlipped() const { return flipped; }
342 
344  double relLength(double local) const { return isFlipped()? -local: local; }
345 
347  double capLength(double local) const
348  { return std::min(+HalfL(), std::max(-HalfL(), local)); }
349 
351  double capRelLength(double local) const
352  { return capLength(relLength(local)); }
353 
355  void Flip();
356 
357 
358  static double gausSum(double a, double b) { return std::sqrt(a*a + b*b); }
359 
360  };
361 }
362 
363 
364 //------------------------------------------------------------------------------
365 //--- template implementation
366 //---
367 //------------------------------------------------------------------------------
368 template <typename Point>
370  return geo::vect::convertTo<Point>
371  (toWorldCoords(LocalPoint_t{ 0.0, 0.0, relLength(localz) }));
372 } // geo::WireGeo::GetPositionFromCenterImpl()
373 
374 
375 //------------------------------------------------------------------------------
376 template <typename Vector /* = DefaultVector_t */>
377 Vector geo::WireGeo::Direction() const {
378  // maybe (GetCenter() - GetStart()) / HalfL() would be faster;
379  // strangely, TVector3 does not implement operator/ (double).
380  return geo::vect::convertTo<Vector>(GetEnd<geo::Point_t>() - GetStart<geo::Point_t>()) * (1.0 / Length());
381 } // geo::WireGeo::Direction()
382 
383 
384 //------------------------------------------------------------------------------
385 template <typename Stream>
387  Stream&& out,
388  std::string indent /* = "" */,
389  unsigned int verbosity /* = 1 */
390 ) const {
391 
392  //----------------------------------------------------------------------------
393  out << "wire from " << GetStart<geo::Point_t>()
394  << " to " << GetEnd<geo::Point_t>();
395 
396  if (verbosity-- <= 0) return; // 0
397 
398  //----------------------------------------------------------------------------
399  out << " (" << Length() << " cm long)";
400 
401  if (verbosity-- <= 0) return; // 1
402 
403  //----------------------------------------------------------------------------
404  out << ", theta(z)=" << ThetaZ() << " rad";
405 
406  if (verbosity-- <= 0) return; // 2
407 
408  //----------------------------------------------------------------------------
409  out << "\n" << indent
410  << " center at " << GetCenter<geo::Point_t>() << " cm";
411 
412  if (verbosity-- <= 0) return; // 3
413 
414  //----------------------------------------------------------------------------
415  out << ", direction: " << Direction<geo::Vector_t>();
416  if (isHorizontal()) out << " (horizontal)";
417  if (isVertical()) out << " (vertical)";
418 
419 // if (verbosity-- <= 0) return; // 4
420 
421  //----------------------------------------------------------------------------
422 } // geo::WireGeo::PrintWireInfo()
423 
424 
425 //------------------------------------------------------------------------------
426 
427 #endif // LARCOREALG_GEOMETRY_WIREGEO_H
bool isVertical() const
Returns if this wire is vertical (theta_z ~ pi/2)
Definition: WireGeo.h:212
void Flip()
Set to swap the start and end wire.
Definition: WireGeo.cxx:131
void GetStart(double *xyz) const
Definition: WireGeo.h:129
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:61
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 PrintWireInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this wire.
Definition: WireGeo.h:386
TVector3 DefaultPoint_t
Definition: WireGeo.h:64
Point GetCenter() const
Returns the world coordinate of the center of the wire [cm].
Definition: WireGeo.h:171
double fThetaZ
angle of the wire with respect to the z direction
Definition: WireGeo.h:333
geo::Point_t fCenter
Center of the wire in world coordinates.
Definition: WireGeo.h:335
Point GetEnd() const
Returns the world coordinate of one end of the wire [cm].
Definition: WireGeo.h:180
double DistanceFrom(geo::WireGeo const &wire) const
Returns 3D distance from the specified wire.
Definition: WireGeo.cxx:100
double Length() const
Returns the wire length in centimeters.
Definition: WireGeo.h:184
const TGeoNode * Node() const
Definition: WireGeo.h:303
double SinThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
Definition: WireGeo.h:204
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
void LocalToWorld(double const *local, double *world) const
Transforms a point from local frame to world frame.
void LocalToWorldVect(double const *local, double *world) const
Transforms a vector from local frame to world frame.
static double WirePitch(geo::WireGeo const &w1, geo::WireGeo const &w2)
Returns the pitch (distance on y/z plane) between two wires, in cm.
Definition: WireGeo.h:325
geo::Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:273
double ThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
Definition: WireGeo.h:192
double fHalfL
half length of the wire
Definition: WireGeo.h:334
void LocalToWorldVect(const double *wire, double *world) const
Transform direction vector from local to world.
Definition: WireGeo.h:277
Point GetPositionFromCenter(double localz) const
Returns the position (world coordinate) of a point on the wire.
Definition: WireGeo.h:150
void UpdateAfterSorting(geo::WireID const &, bool flip)
Definition: WireGeo.cxx:123
void LocalToWorld(const double *wire, double *world) const
Transform point from local wire frame to world frame.
Definition: WireGeo.h:269
Int_t max
Definition: plot.C:27
bool isHorizontal() const
Returns if this wire is horizontal (theta_z ~ 0)
Definition: WireGeo.h:209
Local-to-world transformations with LArSoft geometry vectors.
geo::Vector3DBase_t< WireGeoCoordinatesTag > LocalVector_t
Type of displacement vectors in the local GDML wire plane frame.
Definition: WireGeo.h:92
double RMax() const
Returns the outer half-size of the wire [cm].
Definition: WireGeo.cxx:88
static double gausSum(double a, double b)
Definition: WireGeo.h:358
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
std::string indent(std::size_t const i)
Utilities to extend the interface of geometry vectors.
double capRelLength(double local) const
Stacked capLength() and relLength().
Definition: WireGeo.h:351
bool isFlipped() const
Definition: WireGeo.h:341
LocalVector_t toLocalCoords(geo::Vector_t const &world) const
Transform direction vector from world to local.
Definition: WireGeo.h:297
Vector Direction() const
Returns the wire direction as a norm-one vector.
Definition: WireGeo.h:377
LocalPoint_t toLocalCoords(geo::Point_t const &world) const
Transform point from world frame to local wire frame.
Definition: WireGeo.h:289
void WorldToLocalVect(const double *world, double *wire) const
Transform direction vector from world to local.
Definition: WireGeo.h:293
double HalfL() const
Returns half the length of the wire [cm].
Definition: WireGeo.h:106
double TanThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
Definition: WireGeo.h:205
void WorldToLocal(double const *world, double *local) const
Transforms a point from world frame to local frame.
Point GetPositionFromCenterUnbounded(double localz) const
Returns the position (world coordinate) of a point on the wire.
Definition: WireGeo.h:369
double relLength(double local) const
Returns the relative length from center to be used when transforming.
Definition: WireGeo.h:344
std::vector< TGeoNode const * > GeoNodePath_t
Definition: WireGeo.h:68
void GetEnd(double *xyz) const
Definition: WireGeo.h:133
Int_t min
Definition: plot.C:26
LocalTransformation_t fTrans
Wire to world transform.
Definition: WireGeo.h:336
double capLength(double local) const
Caps the specified local length coordinate to lay on the wire.
Definition: WireGeo.h:347
Point GetStart() const
Returns the world coordinate of one end of the wire [cm].
Definition: WireGeo.h:175
geo::Point3DBase_t< WireGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML wire plane frame.
Definition: WireGeo.h:89
Tag for vectors in the "local" GDML coordinate frame of the plane.
Definition: WireGeo.h:86
geo::Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: WireGeo.h:281
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintWireInfo().
Definition: WireGeo.h:251
GenPoint3DBase_t< double, C > Point3DBase_t
Type of 3D point with representation in double precision.
Definition: geo_vectors.h:95
TVector3 DefaultVector_t
Definition: WireGeo.h:63
GenVector3DBase_t< double, C > Vector3DBase_t
Definition: geo_vectors.h:90
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
double CosThetaZ() const
Returns trigonometric operations on ThetaZ()
Definition: WireGeo.h:203
double ComputeZatY0() const
Definition: WireGeo.h:307
Float_t e
Definition: plot.C:34
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
Namespace collecting geometry-related classes utilities.
void WorldToLocalVect(const double *world, double *local) const
Transforms a vector from world frame to local frame.
bool isParallelTo(geo::WireGeo const &wire) const
Returns if this wire is parallel to another.
Definition: WireGeo.h:215
double RMin() const
Returns the inner radius of the wire (usually 0) [cm].
Definition: WireGeo.cxx:92
WireGeo(GeoNodePath_t const &path, size_t depth)
Definition: WireGeo.cxx:29
const TGeoNode * fWireNode
Pointer to the wire node.
Definition: WireGeo.h:332
bool flipped
whether start and end are reversed
Definition: WireGeo.h:337
void WorldToLocal(const double *world, double *wire) const
Transform point from world frame to local wire frame.
Definition: WireGeo.h:285