LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
TPCGeo.h
Go to the documentation of this file.
1 
7 #ifndef LARCOREALG_GEOMETRY_TPCGEO_H
8 #define LARCOREALG_GEOMETRY_TPCGEO_H
9 
10 // LArSoft libraries
15 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect
17 
18 // ROOT libraries
19 #include "TGeoMatrix.h"
20 #include "TGeoVolume.h"
21 
22 // C/C++ standard library
23 #include <set>
24 #include <vector>
25 
26 class TGeoNode;
27 
28 namespace geo {
29 
30  //......................................................................
33  class TPCGeo : public BoxBoundedGeo {
34  public:
35  using ID_t = TPCID;
36 
38 
51  struct TPCGeoCoordinatesTag {};
53 
56 
59 
61 
62  // Construct a representation of a single plane of the detector
63  TPCGeo(TGeoNode const* tpc_node,
64  std::size_t hash_value,
65  TransformationMatrix&& trans,
66  DriftAxis driftAxis,
67  double driftDistance);
68 
71 
80 
81  Point_t GetCathodeCenter() const;
82 
84  Vector_t DriftDir() const { return fDriftDir; }
85 
87  double DriftDistance() const;
88 
90  double ActiveHalfWidth() const { return fActiveHalfWidth; }
92  double ActiveWidth() const { return 2.0 * ActiveHalfWidth(); }
94  double ActiveHalfHeight() const { return fActiveHalfHeight; }
96  double ActiveHeight() const { return 2.0 * ActiveHalfHeight(); }
98  double ActiveLength() const { return fActiveLength; }
100  double ActiveHalfLength() const { return fActiveLength / 2.0; }
102  double HalfWidth() const { return fHalfWidth; }
104  double Width() const { return 2.0 * HalfWidth(); }
106  double HalfHeight() const { return fHalfHeight; }
108  double Height() const { return 2.0 * HalfHeight(); }
110  double Length() const { return fLength; }
112  double HalfLength() const { return fLength / 2.0; }
113  double ActiveMass() const { return fActiveVolume->Weight(); }
114  const TGeoVolume* ActiveVolume() const { return fActiveVolume; }
115  const TGeoVolume* TotalVolume() const { return fTotalVolume; }
116 
118  decltype(auto) WidthDir() const { return fWidthDir; }
119 
121  decltype(auto) HeightDir() const { return fHeightDir; }
122 
124  decltype(auto) LengthDir() const { return fLengthDir; }
125 
127 
130 
133 
136 
138  Point_t GetFrontFaceCenter() const;
139 
141  BoxBoundedGeo const& BoundingBox() const { return *this; }
142 
144  BoxBoundedGeo const& ActiveBoundingBox() const { return fActiveBox; }
145 
147  TPCID const& ID() const { return fID; }
148 
150 
153 
155  Point_t toWorldCoords(LocalPoint_t const& local) const { return fTrans.toWorldCoords(local); }
156 
158  Vector_t toWorldCoords(LocalVector_t const& local) const { return fTrans.toWorldCoords(local); }
159 
161  LocalPoint_t toLocalCoords(Point_t const& world) const { return fTrans.toLocalCoords(world); }
162 
164  LocalVector_t toLocalCoords(Vector_t const& world) const { return fTrans.toLocalCoords(world); }
165 
167 
169  void UpdateAfterSorting(TPCID tpcid);
170 
192  template <typename Stream>
193  void PrintTPCInfo(Stream&& out, std::string indent = "", unsigned int verbosity = 1) const;
194 
201  std::string TPCInfo(std::string indent = "", unsigned int verbosity = 1) const;
202 
204  static constexpr unsigned int MaxVerbosity = 6;
205 
217  static bool CoordinateContained(double c, double min, double max, double wiggle = 1.)
218  {
219  return (c >= (min > 0 ? min / wiggle : min * wiggle)) &&
220  (c <= (max < 0 ? max / wiggle : max * wiggle));
221  }
222 
223  static bool CoordinateContained(double c, double const* range, double wiggle = 1.)
224  {
225  return CoordinateContained(c, range[0], range[1], wiggle);
226  }
227 
228  std::size_t Hash() const { return fHash; }
229  static TGeoNode const* NodeForActiveVolume(TGeoNode const* tpc);
230 
231  private:
232  using LocalTransformation_t =
234 
235  std::size_t fHash;
237 
241 
242  TGeoVolume* fActiveVolume{nullptr};
243  TGeoVolume* fTotalVolume{nullptr};
245 
248  double fActiveLength;
249  double fHalfWidth;
250  double fHalfHeight;
251  double fLength;
252 
256 
258 
260 
262  void InitTPCBoundaries();
263  };
264 }
265 
266 //------------------------------------------------------------------------------
267 //--- template implementation
268 //---
269 //------------------------------------------------------------------------------
270 template <typename Stream>
271 void geo::TPCGeo::PrintTPCInfo(Stream&& out,
272  std::string indent /* = "" */,
273  unsigned int verbosity /* = 1 */
274 ) const
275 {
276 
277  //----------------------------------------------------------------------------
278  out << "TPC " << std::string(ID());
279 
280  if (verbosity-- <= 0) return; // 0
281 
282  //----------------------------------------------------------------------------
283  out << " (" << Width() << " x " << Height() << " x " << Length() << ") cm^3 at " << GetCenter();
284 
285  if (verbosity-- <= 0) return; // 1
286 
287  //----------------------------------------------------------------------------
288  out << "\n"
289  << indent << "drift direction " << DriftDir() << " from cathode around " << GetCathodeCenter()
290  << " through " << DriftDistance() << " cm";
291 
292  if (verbosity-- <= 0) return; // 2
293 
294  if (verbosity-- <= 0) return; // 3
295 
296  //----------------------------------------------------------------------------
297  out << "\n"
298  << indent << "active volume (" << ActiveWidth() << " x " << ActiveHeight() << " x "
299  << ActiveLength() << ") cm^3, front face at " << GetFrontFaceCenter() << " cm;"
300  << "\n"
301  << indent << "main directions:"
302  << " width " << WidthDir() << " height " << HeightDir() << " length " << LengthDir();
303 
304  if (verbosity-- <= 0) return; // 4
305 
306  //----------------------------------------------------------------------------
307  // print also the containing box
308  BoxBoundedGeo const& box = BoundingBox();
309  out << "\n" << indent << "bounding box: " << box.Min() << " -- " << box.Max();
310 
311  //----------------------------------------------------------------------------
312  // print also the active box
313  BoxBoundedGeo const& activeBox = ActiveBoundingBox();
314  out << "\n" << indent << "active volume box: " << activeBox.Min() << " -- " << activeBox.Max();
315 
316  //----------------------------------------------------------------------------
317 } // geo::TPCGeo::PrintTPCInfo()
318 
319 #endif // LARCOREALG_GEOMETRY_TPCGEO_H
320 
void InitTPCBoundaries()
Recomputes the TPC boundary.
Definition: TPCGeo.cxx:179
decltype(auto) LengthDir() const
Returns the direction Length() is measured on.
Definition: TPCGeo.h:124
decltype(auto) WidthDir() const
Returns the direction Width() is measured on.
Definition: TPCGeo.h:118
DriftSign sign
Definition: geo_types.h:174
Point_t GetCathodeCenter() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.cxx:139
void PrintTPCInfo(Stream &&out, std::string indent="", unsigned int verbosity=1) const
Prints information about this TPC.
Definition: TPCGeo.h:271
decltype(auto) HeightDir() const
Returns the direction Height() is measured on.
Definition: TPCGeo.h:121
LocalVector_t toLocalCoords(Vector_t const &world) const
Transform direction vector from world to local.
Definition: TPCGeo.h:164
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
double fLength
Length of total volume.
Definition: TPCGeo.h:251
Point_t Max() const
Returns the corner point with the largest coordinates.
double ActiveHalfHeight() const
Half height (associated with y coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:94
const TGeoVolume * TotalVolume() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.h:115
LocalPoint_t toLocalCoords(Point_t const &world) const
Transform point from world frame to local TPC frame.
Definition: TPCGeo.h:161
double fActiveHalfWidth
Half width of active volume.
Definition: TPCGeo.h:246
Geometry information for a single TPC.
Definition: TPCGeo.h:33
constexpr Vector Yaxis()
Returns a y axis vector of the specified type.
Definition: geo_vectors.h:215
BoxBoundedGeo fActiveBox
Box of the active volume.
Definition: TPCGeo.h:257
LocalPoint_t toLocalCoords(GlobalPoint_t const &world) const
Transforms a point from world frame to local frame.
static bool CoordinateContained(double c, double const *range, double wiggle=1.)
Definition: TPCGeo.h:223
double ActiveMass() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.h:113
double HalfLength() const
Length is associated with z coordinate [cm].
Definition: TPCGeo.h:112
DriftAxis DriftAxisWithSign() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.h:78
static bool CoordinateContained(double c, double min, double max, double wiggle=1.)
Returns whether the specified coordinate is in a range.
Definition: TPCGeo.h:217
Point_t toWorldCoords(LocalPoint_t const &local) const
Transform point from local TPC frame to world frame.
Definition: TPCGeo.h:155
std::size_t Hash() const
Definition: TPCGeo.h:228
double Width() const
Width is associated with x coordinate [cm].
Definition: TPCGeo.h:104
double Height() const
Height is associated with y coordinate [cm].
Definition: TPCGeo.h:108
double Length() const
Length is associated with z coordinate [cm].
Definition: TPCGeo.h:110
Interface to algorithm class for sorting geo::AuxDet objects .
Point_t GetCenter() const
Returns the center of the TPC volume in world coordinates [cm].
Definition: TPCGeo.h:132
double ActiveHalfLength() const
Length (associated with z coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:100
double fHalfWidth
Half width of total volume.
Definition: TPCGeo.h:249
BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
Definition: TPCGeo.h:144
Vector3DBase_t< TPCGeoCoordinatesTag > LocalVector_t
Type of displacement vectors in the local GDML TPC frame.
Definition: TPCGeo.h:58
Local-to-world transformations with LArSoft geometry vectors.
double fActiveLength
Length of active volume.
Definition: TPCGeo.h:248
TPCGeo(TGeoNode const *tpc_node, std::size_t hash_value, TransformationMatrix &&trans, DriftAxis driftAxis, double driftDistance)
Definition: TPCGeo.cxx:47
double ActiveHalfWidth() const
Half width (associated with x coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:90
std::string indent(std::size_t const i)
Vector_t toWorldCoords(LocalVector_t const &local) const
Transform direction vector from local to world.
Definition: TPCGeo.h:158
Utilities to extend the interface of geometry vectors.This library provides facilities that can be us...
constexpr Vector Xaxis()
Returns a x axis vector of the specified type.
Definition: geo_vectors.h:208
TGeoVolume * fTotalVolume
Total volume of TPC, called volTPC in GDML file.
Definition: TPCGeo.h:243
const TGeoVolume * ActiveVolume() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.h:114
static TGeoNode const * NodeForActiveVolume(TGeoNode const *tpc)
Definition: TPCGeo.cxx:213
double ActiveHeight() const
Height (associated with y coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:96
geo::DriftSign DriftSign() const
Returns the expected drift direction based on geometry.
Definition: TPCGeo.h:79
void UpdateAfterSorting(TPCID tpcid)
Performs all updates after cryostat has sorted TPCs.
Definition: TPCGeo.cxx:207
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
Definition of data types for geometry description.
Point_t GetActiveVolumeCenter() const
Returns the center of the TPC active volume in world coordinates [cm].
Definition: TPCGeo.h:135
double ActiveLength() const
Length (associated with z coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:98
Provides a base class aware of world box coordinates.
Tag for vectors in the "local" GDML coordinate frame of the TPC.
Definition: TPCGeo.h:52
double HalfHeight() const
Height is associated with y coordinate [cm].
Definition: TPCGeo.h:106
constexpr Vector Zaxis()
Returns a z axis vector of the specified type.
Definition: geo_vectors.h:222
std::string TPCInfo(std::string indent="", unsigned int verbosity=1) const
Returns a string with information about this TPC.
Definition: TPCGeo.cxx:171
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
Point_t Min() const
Returns the corner point with the smallest coordinates.
DriftSign
Drift sign: positive or negative.
Definition: geo_types.h:155
TGeoVolume * fActiveVolume
Active volume of LAr, called volTPCActive in GDML file.
Definition: TPCGeo.h:242
double DriftDistance() const
Drift distance is defined as the distance between the anode and the cathode, in centimeters.
Definition: TPCGeo.cxx:165
Selection of the type of transformation matrix used in geometry.
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:31
TPCID fID
ID of this TPC.
Definition: TPCGeo.h:259
std::size_t fHash
Uniquely identifies TPC before sorting has been performed.
Definition: TPCGeo.h:235
Vector_t fWidthDir
Direction width refers to.
Definition: TPCGeo.h:253
BoxBoundedGeo const & BoundingBox() const
Returns the bounding box of this TPC.
Definition: TPCGeo.h:141
double ActiveWidth() const
Width (associated with x coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:92
LocalTransformation_t fTrans
TPC-to-world transformation.
Definition: TPCGeo.h:236
DriftAxis fDriftAxis
Definition: TPCGeo.h:238
Vector_t fHeightDir
Direction height refers to.
Definition: TPCGeo.h:254
Vector_t fLengthDir
Direction length refers to.
Definition: TPCGeo.h:255
GenPoint3DBase_t< double, C > Point3DBase_t
Type of 3D point with representation in double precision.
Definition: geo_vectors.h:88
GenVector3DBase_t< double, C > Vector3DBase_t
Definition: geo_vectors.h:83
IDparameter< geo::TPCID > TPCID
Member type of validated geo::TPCID parameter.
GlobalPoint_t toWorldCoords(LocalPoint_t const &local) const
Transforms a point from local frame to world frame.
Point_t fActiveCenter
Center of the active volume, in world coordinates [cm].
Definition: TPCGeo.h:244
Vector_t DriftDir() const
Returns the direction of the drift (vector pointing toward the planes).
Definition: TPCGeo.h:84
static constexpr unsigned int MaxVerbosity
Maximum verbosity supported by PrintTPCInfo().
Definition: TPCGeo.h:204
ROOT libraries.
TPCID const & ID() const
Returns the identifier of this TPC.
Definition: TPCGeo.h:147
Point3DBase_t< TPCGeoCoordinatesTag > LocalPoint_t
Type of points in the local GDML TPC frame.
Definition: TPCGeo.h:55
Point_t GetFrontFaceCenter() const
Returns the center of the active TPC volume side facing negative z.
Definition: TPCGeo.cxx:200
double fHalfHeight
Half height of total volume.
Definition: TPCGeo.h:250
double HalfWidth() const
Width is associated with x coordinate [cm].
Definition: TPCGeo.h:102
ROOT::Math::Transform3D TransformationMatrix
Type of transformation matrix used in geometry.
double fDriftDistance
Definition: TPCGeo.h:240
Vector_t fDriftDir
Definition: TPCGeo.h:239
double fActiveHalfHeight
Half height of active volume.
Definition: TPCGeo.h:247