diff --git a/DDSegmentation/include/DDSegmentation/Segmentation.h b/DDSegmentation/include/DDSegmentation/Segmentation.h index 37562a67235ace2be999778780595efbae66c38e..84f477bb156c5f19115f336c8fc4b20b83c1c325 100644 --- a/DDSegmentation/include/DDSegmentation/Segmentation.h +++ b/DDSegmentation/include/DDSegmentation/Segmentation.h @@ -71,6 +71,8 @@ public: /// Determine the cell ID based on the position virtual CellID cellID(const Position& localPosition, const Position& globalPosition, const VolumeID& volumeID) const = 0; + /// Determine the volume ID from the full cell ID by removing all local fields + virtual VolumeID volumeID(const CellID& cellID) const; /// Calculates the neighbours of the given cell ID and adds them to the list of neighbours virtual void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const; /// Access the encoding string diff --git a/DDSegmentation/src/Segmentation.cpp b/DDSegmentation/src/Segmentation.cpp index 8b12a4c9edf9388e4dc6e8b537b7466c98e93caf..2995828cd995a199ae2fc34872311c8be52cee4b 100644 --- a/DDSegmentation/src/Segmentation.cpp +++ b/DDSegmentation/src/Segmentation.cpp @@ -10,6 +10,7 @@ #include <iostream> #include <sstream> #include <stdexcept> +#include <cmath> namespace DD4hep { namespace DDSegmentation { @@ -47,6 +48,17 @@ Segmentation::~Segmentation() { } } +/// Determine the volume ID from the full cell ID by removing all local fields +VolumeID Segmentation::volumeID(const CellID& cellID) const { + map<string, StringParameter>::const_iterator it; + _decoder->setValue(cellID); + for (it = _indexIdentifiers.begin(); it != _indexIdentifiers.end(); ++it) { + string identifier = it->second->typedValue(); + (*_decoder)[identifier] = 0; + } + return _decoder->getValue(); +} + /// Calculates the neighbours of the given cell ID and adds them to the list of neighbours void Segmentation::neighbours(const CellID& cellID, std::set<CellID>& neighbours) const { map<string, StringParameter>::const_iterator it; @@ -129,7 +141,7 @@ int Segmentation::positionToBin(double position, double cellSize, double offset) if (cellSize == 0.) { throw runtime_error("Invalid cell size: 0.0"); } - return int((position + 0.5 * cellSize - offset) / cellSize); + return int(floor((position + 0.5 * cellSize - offset) / cellSize)); } } /* namespace DDSegmentation */