Skip to content

Commit

Permalink
feat: Bin adjustment for rectangluar bounds (#705)
Browse files Browse the repository at this point in the history
* Added a function adjustBinUtility() for rectangle bounds to BinAdjustment.hpp and modified BinUtility adjustBinUtility(const BinUtility& bu, const Surface& surface) accordingly.  This is to make material mapping on renctangle layers possible.
Modified the envelope from 1 mm to 0 mm in the TGeoLayerBuilder.hpp (otherwise I get a Radialbounds error when executing ActsExampleGeometryTGeo).

* added a check to the plane surface in adjustBinUtility(const BinUtility& bu, const Surface& surface) for rectangular bounds.

* added a unit test for the BinAdjustment of the rectangular plane.
also split the if that checks for a plane surface and rectangular bounds in two.

* changed the envelope of r and z in the TGeoLayerBuilder back to 1 mm.

* commit after running ./CI/check_format_local

Co-authored-by: Bernadette Kolbinger <bernadette.kolbinger@cern.ch>
Co-authored-by: Paul Gessinger <paul.gessinger@cern.ch>
  • Loading branch information
3 people committed Feb 10, 2021
1 parent b1fc4e7 commit 1e69ac6
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Core/include/Acts/Utilities/BinAdjustment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Surfaces/CylinderBounds.hpp"
#include "Acts/Surfaces/RadialBounds.hpp"
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/BinUtility.hpp"

Expand Down Expand Up @@ -122,6 +123,55 @@ BinUtility adjustBinUtility(const BinUtility& bu, const CylinderBounds& cBounds,
return uBinUtil;
}

/// @brief adjust the BinUtility bu to the dimensions of plane bounds
///
/// @param bu BinUtility at source
/// @param pBounds the Rectangle bounds to adjust to
///
/// @return new updated BinUtiltiy
BinUtility adjustBinUtility(const BinUtility& bu,
const RectangleBounds& pBounds,
const Transform3& transform) {
// Default constructor
BinUtility uBinUtil(transform);

// The parameters from the cylinder bounds
double minX = pBounds.get(RectangleBounds::eMinX);
double minY = pBounds.get(RectangleBounds::eMinY);
double maxX = pBounds.get(RectangleBounds::eMaxX);
double maxY = pBounds.get(RectangleBounds::eMaxY);

// Retrieve the binning data
const std::vector<BinningData>& bData = bu.binningData();
// Loop over the binning data and adjust the dimensions
for (auto& bd : bData) {
// The binning value
BinningValue bval = bd.binvalue;
// Throw exceptions if stuff doesn't make sense:
// - not the right binning value
// - not equidistant
if (bd.type == arbitrary) {
throw std::invalid_argument("Arbitrary binning can not be adjusted.");
} else if (bval != binX and bval != binY) {
throw std::invalid_argument("Rectangle binning must be: x, y. ");
}
float min, max = 0.;
// Perform the value adjustment
if (bval == binX) {
min = minX;
max = maxX;
} else {
min = minY;
max = maxY;
}
// Create the updated BinningData
BinningData uBinData(bd.option, bval, bd.bins(), min, max);
uBinUtil += BinUtility(uBinData);
}

return uBinUtil;
}

/// @brief adjust the BinUtility bu to a surface
///
/// @param bu BinUtility at source
Expand All @@ -141,6 +191,17 @@ BinUtility adjustBinUtility(const BinUtility& bu, const Surface& surface) {
auto rBounds = dynamic_cast<const RadialBounds*>(&(surface.bounds()));
// Return specific adjustment
return adjustBinUtility(bu, *rBounds, surface.transform(GeometryContext()));
} else if (surface.type() == Surface::Plane) {
if (surface.bounds().type() == SurfaceBounds::eRectangle) {
// Cast to Plane bounds and return
auto pBounds = dynamic_cast<const RectangleBounds*>(&(surface.bounds()));
// Return specific adjustment
return adjustBinUtility(bu, *pBounds,
surface.transform(GeometryContext()));
} else {
throw std::invalid_argument(
"Bin adjustment not implemented for this type of plane surface yet!");
}
}

throw std::invalid_argument(
Expand Down
16 changes: 16 additions & 0 deletions Tests/UnitTests/Core/Utilities/BinAdjustmentTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Surfaces/CylinderBounds.hpp"
#include "Acts/Surfaces/RadialBounds.hpp"
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Utilities/BinAdjustment.hpp"
#include "Acts/Utilities/BinUtility.hpp"

Expand Down Expand Up @@ -51,5 +52,20 @@ BOOST_AUTO_TEST_CASE(BinAdjustment_Cylinder) {
BOOST_CHECK_EQUAL(buAdjust.binningData()[1].max, 50);
}

// Test Rectangule
BOOST_AUTO_TEST_CASE(BinAdjustment_Rectangle) {
RectangleBounds bound(20, 30);
BinUtility bu;
bu += BinUtility(1, 0, 1, Acts::open, Acts::binX);
bu += BinUtility(1, 0, 1, Acts::open, Acts::binY);

BinUtility buAdjust = adjustBinUtility(bu, bound, Transform3::Identity());

BOOST_CHECK_EQUAL(buAdjust.binningData()[0].min, -20);
BOOST_CHECK_EQUAL(buAdjust.binningData()[0].max, 20);
BOOST_CHECK_EQUAL(buAdjust.binningData()[1].min, -30);
BOOST_CHECK_EQUAL(buAdjust.binningData()[1].max, 30);
}

} // namespace Test
} // namespace Acts

0 comments on commit 1e69ac6

Please sign in to comment.