LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
geo::details::ActiveAreaCalculator Struct Reference

Class computing the active area of the plane. More...

Public Member Functions

 ActiveAreaCalculator (geo::PlaneGeo const &plane, double wMargin, double dMargin)
 
 ActiveAreaCalculator (geo::PlaneGeo const &plane, double margin=0.0)
 
 operator geo::PlaneGeo::Rect ()
 

Private Types

using Projection_t = ROOT::Math::PositionVector2D< ROOT::Math::Cartesian2D< double >, geo::PlaneGeo::WidthDepthReferenceTag >
 
using Vector_t = geo::PlaneGeo::WidthDepthDisplacement_t
 

Private Member Functions

void initializeWireEnds ()
 
void includeAllWireEnds ()
 
void adjustCorners ()
 
void applyMargin ()
 
geo::PlaneGeo::Rect recomputeArea ()
 

Static Private Member Functions

static bool none_or_both (bool a, bool b)
 Returns true if a and b are both true or both false (exclusive nor). More...
 
template<typename T >
static bool equal (T a, T b, T tol=T(1e-5))
 Returns whether the two numbers are the same, lest a tolerance. More...
 

Private Attributes

PlaneGeo const & plane
 Plane to work on. More...
 
double const wMargin = 0.0
 Margin subtracted from each side of width. More...
 
double const dMargin = 0.0
 Margin subtracted from each side of depth. More...
 
geo::PlaneGeo::Rect activeArea
 Result. More...
 
Projection_t wireEnds [4]
 Cache: wire end projections. More...
 

Static Private Attributes

static constexpr std::size_t kFirstWireStart = 0
 
static constexpr std::size_t kFirstWireEnd = 1
 
static constexpr std::size_t kLastWireStart = 2
 
static constexpr std::size_t kLastWireEnd = 3
 

Detailed Description

Class computing the active area of the plane.

The active area is defined in the width/depth space which include approximatively all wires.

This algorithm requires the frame reference and the wire pitch to be already defined.

That area is tuned so that all its points are closer than half a wire pitch from a wire.

Definition at line 78 of file PlaneGeo.cxx.

Member Typedef Documentation

using geo::details::ActiveAreaCalculator::Projection_t = ROOT::Math::PositionVector2D<ROOT::Math::Cartesian2D<double>, geo::PlaneGeo::WidthDepthReferenceTag>
private

Definition at line 92 of file PlaneGeo.cxx.

Constructor & Destructor Documentation

geo::details::ActiveAreaCalculator::ActiveAreaCalculator ( geo::PlaneGeo const &  plane,
double  wMargin,
double  dMargin 
)
inline

Definition at line 80 of file PlaneGeo.cxx.

82  {}
double const dMargin
Margin subtracted from each side of depth.
Definition: PlaneGeo.cxx:105
PlaneGeo const & plane
Plane to work on.
Definition: PlaneGeo.cxx:103
double const wMargin
Margin subtracted from each side of width.
Definition: PlaneGeo.cxx:104
geo::details::ActiveAreaCalculator::ActiveAreaCalculator ( geo::PlaneGeo const &  plane,
double  margin = 0.0 
)
inline

Definition at line 84 of file PlaneGeo.cxx.

85  : ActiveAreaCalculator(plane, margin, margin)
86  {}
PlaneGeo const & plane
Plane to work on.
Definition: PlaneGeo.cxx:103
ActiveAreaCalculator(geo::PlaneGeo const &plane, double wMargin, double dMargin)
Definition: PlaneGeo.cxx:80

Member Function Documentation

void geo::details::ActiveAreaCalculator::adjustCorners ( )
inlineprivate

Definition at line 150 of file PlaneGeo.cxx.

References lar::util::simple_geo::Rectangle< Data >::depth, geo::vect::dot(), equal(), geo::PlaneGeo::GetIncreasingWireDirection(), lar::util::simple_geo::Range< Data >::lower, none_or_both(), lar::util::simple_geo::Range< Data >::upper, geo::PlaneGeo::VectorWidthDepthProjection(), lar::util::simple_geo::Rectangle< Data >::width, geo::PlaneGeo::WirePitch(), X, x1, and Y.

Referenced by recomputeArea().

151  {
152  //
153  // Modify the corners so that none is father than half a pitch from all
154  // wires.
155  //
156  // directions in wire/depth plane
157  Vector_t const widthDir = {1.0, 0.0};
158  Vector_t const depthDir = {0.0, 1.0};
159  Vector_t wireCoordDir =
161  double const hp = plane.WirePitch() / 2.0; // half pitch
162 
163  //
164  // The plan: identify if wires are across or corner, and then:
165  // - across:
166  // - identify which sides
167  // - set the farther end of the wire from the side to be p/2 from
168  // its corner
169  // - corner:
170  // - identify which corners
171  // - move the corners to p/2 from the wires
172  //
173 
174  //
175  // are the wires crossing side to side, as opposed to cutting corners?
176  //
177 
178  // these are the angles of the original wire coordinate direction
179  double const cosAngleWidth = geo::vect::dot(wireCoordDir, widthDir);
180  double const cosAngleDepth = geo::vect::dot(wireCoordDir, depthDir);
181  // if the wire coordinate direction is on first or third quadrant:
182  bool const bPositiveAngle = none_or_both((wireCoordDir.X() >= 0), (wireCoordDir.Y() >= 0));
183 
184  // now we readjust the wire coordinate direction to always point
185  // toward positive width; this breaks the relation between
186  // wireCoordDir and which is the first/last wire
187  if (cosAngleWidth < 0) wireCoordDir = -wireCoordDir;
188 
189  // let's study the first wire (ends are sorted by width)
191  bool const bAlongWidth // horizontal
194  bool const bAlongDepth =
195  !bAlongWidth && // vertical
200  assert(!(bAlongWidth && bAlongDepth));
201 
202  if (bAlongWidth) { // horizontal
203 
204  // +---------+
205  // | ___,--| upper width bound
206  // |--' |
207 
208  // find which is the wire with higher width:
209  // the last wire is highest if the wire coordinate direction (which
210  // is defined by what is first and what is last) is parallel to the
211  // width direction
212  std::size_t const iUpperWire = (cosAngleDepth > 0) ? kLastWireStart : kFirstWireStart;
213  // largest distance from upper depth bound of the two ends of wire
214  double const maxUpperDistance =
216  std::min(wireEnds[iUpperWire].Y(), wireEnds[iUpperWire ^ 0x1].Y());
217  // set the upper side so that the maximum distance is p/2
218  // (it may be actually less if the wire is not perfectly horizontal)
219  activeArea.depth.upper += (hp - maxUpperDistance);
220 
221  // |--.___ |
222  // | `--| deal with the lower bound now
223  // +---------+
224 
225  std::size_t const iLowerWire = (cosAngleDepth > 0) ? kFirstWireStart : kLastWireStart;
226  // largest distance from lower depth bound of the two ends of wire
227  double const maxLowerDistance =
228  std::max(wireEnds[iLowerWire].Y(), wireEnds[iLowerWire ^ 0x1].Y()) -
230  // set the upper side so that the minimum distance is p/2
231  activeArea.depth.lower -= (hp - maxLowerDistance);
232 
233  } // horizontal wires
234  else if (bAlongDepth) { // vertical
235  // --,---+
236  // | |
237  // \ |
238  // | | upper depth bound
239  // \ |
240  // | |
241  // ------+
242 
243  // find which is the wire with higher depth:
244  // the last wire is highest if the wire coordinate direction (which
245  // is defined by what is first and what is last) is parallel to the
246  // depth direction
247  std::size_t const iUpperWire = (cosAngleWidth > 0) ? kLastWireStart : kFirstWireStart;
248  // largest distance from upper depth bound of the two ends of wire
249  double const maxUpperDistance =
251  std::min(wireEnds[iUpperWire].X(), wireEnds[iUpperWire ^ 0x1].X());
252  // set the upper side so that the minimum distance is p/2
253  activeArea.width.upper += (hp - maxUpperDistance);
254 
255  // +-,----
256  // | |
257  // | \ .
258  // | | deal with the lower bound now
259  // | \ .
260  // | |
261  // +------
262  std::size_t const iLowerWire = (cosAngleWidth > 0) ? kFirstWireStart : kLastWireStart;
263  // largest distance from lower width bound of the two ends of wire
264  double const maxLowerDistance =
265  std::max(wireEnds[iLowerWire].X(), wireEnds[iLowerWire ^ 0x1].X()) -
267  // set the upper side so that the minimum distance is p/2
268  activeArea.width.lower -= (hp - maxLowerDistance);
269 
270  } // vertical wires
271  else if (bPositiveAngle) { // wires are not going across: corners!
272  // corners at (lower width, lower depth), (upper width, upper depth)
273 
274  // -._------+
275  // `-._ | upper width corner (upper depth)
276  // `-|
277 
278  // start of the wire on the upper corner
279  // (width coordinate is lower for start than for end)
280  std::size_t const iUpperWire = (cosAngleWidth > 0) ? kLastWireStart : kFirstWireStart;
281 
282  double const upperDistance = geo::vect::dot(
283  Vector_t(activeArea.width.upper - wireEnds[iUpperWire].X(), 0.0), wireCoordDir);
284  // make the upper distance become p/2
285  auto const upperDelta = (hp - upperDistance) * wireCoordDir;
286  activeArea.width.upper += upperDelta.X();
287  activeArea.depth.upper += upperDelta.Y();
288 
289  // |-._
290  // | `-._ lower width corner (lower depth)
291  // +-------`-
292 
293  // end of the wire on the lower corner
294  // (width coordinate is lower than the end)
295  std::size_t const iLowerWire = (cosAngleWidth > 0) ? kFirstWireEnd : kLastWireEnd;
296 
297  double const lowerDistance = geo::vect::dot(
298  Vector_t(wireEnds[iLowerWire].X() - activeArea.width.lower, 0.0), wireCoordDir);
299  // make the lower distance become p/2 (note direction of wire coord)
300  auto const lowerDelta = (hp - lowerDistance) * wireCoordDir;
301  activeArea.width.lower -= lowerDelta.X();
302  activeArea.depth.lower -= lowerDelta.Y();
303  }
304  else { // !bPositiveAngle
305  // corners at (lower width, upper depth), (upper width, lower depth)
306 
307  // _,-|
308  // _,-' | upper width corner (lower depth)
309  // -'-------+
310 
311  // start of the wire on the upper corner
312  // (width coordinate is lower than the end)
313  std::size_t const iUpperWire = (cosAngleWidth > 0) ? kLastWireStart : kFirstWireStart;
314 
315  double const upperDistance = geo::vect::dot(
316  Vector_t(activeArea.width.upper - wireEnds[iUpperWire].X(), 0.0), wireCoordDir);
317  // make the upper distance become p/2
318  auto const upperDelta = (hp - upperDistance) * wireCoordDir;
319  activeArea.width.upper += upperDelta.X();
320  activeArea.depth.lower += upperDelta.Y();
321 
322  // +------_,-
323  // | _,-' lower width corner (upper depth)
324  // |-'
325 
326  // end of the wire on the lower corner
327  // (width coordinate is lower than the end)
328  std::size_t const iLowerWire = (cosAngleWidth > 0) ? kFirstWireEnd : kLastWireEnd;
329 
330  double const lowerDistance = geo::vect::dot(
331  Vector_t(wireEnds[iLowerWire].X() - activeArea.width.lower, 0.0), wireCoordDir);
332  // make the lower distance become p/2 (note direction of wire coord)
333  auto const lowerDelta = (hp - lowerDistance) * wireCoordDir;
334  activeArea.width.lower -= lowerDelta.X();
335  activeArea.depth.upper -= lowerDelta.Y();
336 
337  } // if ...
338 
339  } // adjustCorners()
WidthDepthProjection_t VectorWidthDepthProjection(geo::Vector_t const &v) const
Returns the projection of the specified vector on the plane.
Definition: PlaneGeo.h:1018
static bool none_or_both(bool a, bool b)
Returns true if a and b are both true or both false (exclusive nor).
Definition: PlaneGeo.cxx:381
Float_t x1[n_points_granero]
Definition: compare.C:5
Float_t Y
Definition: plot.C:37
geo::PlaneGeo::WidthDepthDisplacement_t Vector_t
Definition: PlaneGeo.cxx:93
static constexpr std::size_t kLastWireStart
Definition: PlaneGeo.cxx:100
static constexpr std::size_t kFirstWireStart
Definition: PlaneGeo.cxx:98
PlaneGeo const & plane
Plane to work on.
Definition: PlaneGeo.cxx:103
Projection_t wireEnds[4]
Cache: wire end projections.
Definition: PlaneGeo.cxx:109
Range_t width
Range along width direction.
Definition: SimpleGeo.h:429
constexpr auto dot(Vector const &a, OtherVector const &b)
Return cross product of two vectors.
static constexpr std::size_t kLastWireEnd
Definition: PlaneGeo.cxx:101
Range_t depth
Range along depth direction.
Definition: SimpleGeo.h:430
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:359
Vector_t const & GetIncreasingWireDirection() const
Returns the direction of increasing wires.
Definition: PlaneGeo.h:418
static constexpr std::size_t kFirstWireEnd
Definition: PlaneGeo.cxx:99
static bool equal(T a, T b, T tol=T(1e-5))
Returns whether the two numbers are the same, lest a tolerance.
Definition: PlaneGeo.cxx:385
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:358
Float_t X
Definition: plot.C:37
recob::tracking::Vector_t Vector_t
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
Definition: PlaneGeo.h:378
geo::PlaneGeo::Rect activeArea
Result.
Definition: PlaneGeo.cxx:106
void geo::details::ActiveAreaCalculator::applyMargin ( )
inlineprivate

Definition at line 341 of file PlaneGeo.cxx.

References lar::util::simple_geo::Rectangle< Data >::depth, dMargin, lar::util::simple_geo::Range< Data >::lower, lar::util::simple_geo::Range< Data >::upper, lar::util::simple_geo::Rectangle< Data >::width, and wMargin.

Referenced by recomputeArea().

342  {
343  if (wMargin != 0.0) {
346  }
347  if (dMargin != 0.0) {
350  }
351  } // applyMargin()
double const dMargin
Margin subtracted from each side of depth.
Definition: PlaneGeo.cxx:105
Range_t width
Range along width direction.
Definition: SimpleGeo.h:429
Range_t depth
Range along depth direction.
Definition: SimpleGeo.h:430
double const wMargin
Margin subtracted from each side of width.
Definition: PlaneGeo.cxx:104
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:359
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:358
geo::PlaneGeo::Rect activeArea
Result.
Definition: PlaneGeo.cxx:106
template<typename T >
static bool geo::details::ActiveAreaCalculator::equal ( a,
b,
tol = T(1e-5) 
)
inlinestaticprivate

Returns whether the two numbers are the same, lest a tolerance.

Definition at line 385 of file PlaneGeo.cxx.

References util::abs().

Referenced by adjustCorners().

386  {
387  return std::abs(a - b) <= tol;
388  }
constexpr auto abs(T v)
Returns the absolute value of the argument.
void geo::details::ActiveAreaCalculator::includeAllWireEnds ( )
inlineprivate

Definition at line 136 of file PlaneGeo.cxx.

References lar::util::simple_geo::Rectangle< Data >::depth, lar::util::simple_geo::Range< Data >::extendToInclude(), and lar::util::simple_geo::Rectangle< Data >::width.

Referenced by recomputeArea().

137  {
138  //
139  // Find the basic area containing all the coordinates.
140  //
141 
142  // include all the coordinates of the first and last wire
143  for (auto const& aWireEnd : wireEnds) {
144  activeArea.width.extendToInclude(aWireEnd.X());
145  activeArea.depth.extendToInclude(aWireEnd.Y());
146  }
147 
148  } // includeAllWireEnds()
void extendToInclude(Data_t)
Extends the range to include the specified point.
Definition: SimpleGeo.h:484
Projection_t wireEnds[4]
Cache: wire end projections.
Definition: PlaneGeo.cxx:109
Range_t width
Range along width direction.
Definition: SimpleGeo.h:429
Range_t depth
Range along depth direction.
Definition: SimpleGeo.h:430
geo::PlaneGeo::Rect activeArea
Result.
Definition: PlaneGeo.cxx:106
void geo::details::ActiveAreaCalculator::initializeWireEnds ( )
inlineprivate

Definition at line 111 of file PlaneGeo.cxx.

References geo::PlaneGeo::FirstWire(), geo::WireGeo::GetEnd(), geo::WireGeo::GetStart(), kFirstWireEnd, kFirstWireStart, kLastWireEnd, kLastWireStart, geo::PlaneGeo::LastWire(), geo::PlaneGeo::PointWidthDepthProjection(), and X.

Referenced by recomputeArea().

112  {
113  //
114  // Collect the projections of the relevant points.
115  //
116  // Sorted so that start points have width not larger than end points.
117  //
118  // PointWidthDepthProjection() erroneously returns a vector rather
119  // than a point, so a conversion is required
120  auto makeProjection = [](auto v) { return Projection_t(v.X(), v.Y()); };
121 
131  makeProjection(plane.PointWidthDepthProjection(plane.LastWire().GetEnd()));
134  } // initializeWireEnds()
static constexpr std::size_t kLastWireStart
Definition: PlaneGeo.cxx:100
WidthDepthProjection_t PointWidthDepthProjection(geo::Point_t const &point) const
Returns the projection of the specified point on the plane.
Definition: PlaneGeo.h:1000
static constexpr std::size_t kFirstWireStart
Definition: PlaneGeo.cxx:98
Point_t GetStart() const
Returns the world coordinate of one end of the wire [cm].
Definition: WireGeo.h:226
Point_t GetEnd() const
Returns the world coordinate of one end of the wire [cm].
Definition: WireGeo.h:231
PlaneGeo const & plane
Plane to work on.
Definition: PlaneGeo.cxx:103
Projection_t wireEnds[4]
Cache: wire end projections.
Definition: PlaneGeo.cxx:109
const WireGeo & FirstWire() const
Return the first wire in the plane.
Definition: PlaneGeo.h:312
static constexpr std::size_t kLastWireEnd
Definition: PlaneGeo.cxx:101
static constexpr std::size_t kFirstWireEnd
Definition: PlaneGeo.cxx:99
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
const WireGeo & LastWire() const
Return the last wire in the plane.
Definition: PlaneGeo.h:318
Float_t X
Definition: plot.C:37
ROOT::Math::PositionVector2D< ROOT::Math::Cartesian2D< double >, geo::PlaneGeo::WidthDepthReferenceTag > Projection_t
Definition: PlaneGeo.cxx:92
static bool geo::details::ActiveAreaCalculator::none_or_both ( bool  a,
bool  b 
)
inlinestaticprivate

Returns true if a and b are both true or both false (exclusive nor).

Definition at line 381 of file PlaneGeo.cxx.

Referenced by adjustCorners().

381 { return a == b; }
geo::details::ActiveAreaCalculator::operator geo::PlaneGeo::Rect ( )
inline

Definition at line 88 of file PlaneGeo.cxx.

References recomputeArea().

88 { return recomputeArea(); }
geo::PlaneGeo::Rect recomputeArea()
Definition: PlaneGeo.cxx:353
geo::PlaneGeo::Rect geo::details::ActiveAreaCalculator::recomputeArea ( )
inlineprivate

Definition at line 353 of file PlaneGeo.cxx.

References activeArea, adjustCorners(), applyMargin(), includeAllWireEnds(), and initializeWireEnds().

Referenced by operator geo::PlaneGeo::Rect().

354  {
355  activeArea = {};
356 
357  //
358  // 0. collect the projections of the relevant point
359  //
361 
362  //
363  // 1. find the basic area containing all the coordinates
364  //
366 
367  //
368  // 2. adjust area so that no corner is father than half a wire pitch
369  //
370  adjustCorners();
371 
372  //
373  // 3. apply an absolute margin
374  //
375  applyMargin();
376 
377  return activeArea;
378  } // computeArea()
geo::PlaneGeo::Rect activeArea
Result.
Definition: PlaneGeo.cxx:106

Member Data Documentation

geo::PlaneGeo::Rect geo::details::ActiveAreaCalculator::activeArea
private

Result.

Definition at line 106 of file PlaneGeo.cxx.

Referenced by recomputeArea().

double const geo::details::ActiveAreaCalculator::dMargin = 0.0
private

Margin subtracted from each side of depth.

Definition at line 105 of file PlaneGeo.cxx.

Referenced by applyMargin().

constexpr std::size_t geo::details::ActiveAreaCalculator::kFirstWireEnd = 1
staticprivate

Definition at line 99 of file PlaneGeo.cxx.

Referenced by initializeWireEnds().

constexpr std::size_t geo::details::ActiveAreaCalculator::kFirstWireStart = 0
staticprivate

Definition at line 98 of file PlaneGeo.cxx.

Referenced by initializeWireEnds().

constexpr std::size_t geo::details::ActiveAreaCalculator::kLastWireEnd = 3
staticprivate

Definition at line 101 of file PlaneGeo.cxx.

Referenced by initializeWireEnds().

constexpr std::size_t geo::details::ActiveAreaCalculator::kLastWireStart = 2
staticprivate

Definition at line 100 of file PlaneGeo.cxx.

Referenced by initializeWireEnds().

PlaneGeo const& geo::details::ActiveAreaCalculator::plane
private

Plane to work on.

Definition at line 103 of file PlaneGeo.cxx.

Projection_t geo::details::ActiveAreaCalculator::wireEnds[4]
private

Cache: wire end projections.

Definition at line 109 of file PlaneGeo.cxx.

double const geo::details::ActiveAreaCalculator::wMargin = 0.0
private

Margin subtracted from each side of width.

Definition at line 104 of file PlaneGeo.cxx.

Referenced by applyMargin().


The documentation for this struct was generated from the following file: