Commit 15565f2b authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'getNeighboringPixel' into 'master'

Get neighboring pixel

Closes #214

See merge request allpix-squared/allpix-squared!527
parents d8692f38 60c5825a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -103,9 +103,10 @@ The following authors, in alphabetical order, have developed or contributed to A
* Moritz Kiehn, Université de Genève, @msmk
* Stephan Lachnit, Heidelberg University, @stephanlachnit
* Salman Maqbool, CERN Summer Student, @smaqbool
* Stefano Mersi, CERN, @mersi
* Ryuji Moriya, CERN Summer Student, University of Glasgow, @rmoriya
* Sebastien Murphy, ETHZ, @smurphy
* Andreas Matthias Nürnberg, KIT, @nurnberg
* Stefano Mersi, CERN, @mersi
* Sebastian Pape, TU Dortmund University, @spape
* Marko Petric, CERN, @mpetric
* Radek Privara, Palacky University Olomouc, @rprivara
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ The following authors, in alphabetical order, have developed or contributed to \
\item Stephan Lachnit, Heidelberg University
\item Salman Maqbool, CERN Summer Student
\item Stefano Mersi, CERN
\item Ryuji Moriya, CERN Summer Student, University of Glasgow
\item Sebastien Murphy, ETHZ
\item Andreas Matthias Nürnberg, KIT
\item Sebastian Pape, TU Dortmund University
+20 −0
Original line number Diff line number Diff line
@@ -225,3 +225,23 @@ std::pair<int, int> DetectorModel::getPixelIndex(const ROOT::Math::XYZPoint& pos
    auto pixel_y = static_cast<int>(std::round(position.y() / pixel_size_.y()));
    return {pixel_x, pixel_y};
}

std::set<Pixel::Index> DetectorModel::getNeighbors(const Pixel::Index& idx, const size_t distance) const {
    std::set<Pixel::Index> neighbors;

    for(int x = static_cast<int>(idx.x() - distance); x <= static_cast<int>(idx.x() + distance); x++) {
        for(int y = static_cast<int>(idx.y() - distance); y <= static_cast<int>(idx.y() + distance); y++) {
            if(!isWithinPixelGrid(x, y)) {
                continue;
            }
            neighbors.insert({static_cast<unsigned int>(x), static_cast<unsigned int>(y)});
        }
    }

    return neighbors;
}

bool DetectorModel::areNeighbors(const Pixel::Index& seed, const Pixel::Index& entrant, const size_t distance) const {
    auto pixel_distance = [](unsigned int lhs, unsigned int rhs) { return (lhs > rhs ? lhs - rhs : rhs - lhs); };
    return (pixel_distance(seed.x(), entrant.x()) <= distance && pixel_distance(seed.y(), entrant.y()) <= distance);
}
+20 −1
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@ namespace allpix {
         * @warning The grid has zero thickness
         * @note This is basically a 2D method, but provided in 3D because it is primarily used there
         */
        ROOT::Math::XYZVector getGridSize() const {
        virtual ROOT::Math::XYZVector getGridSize() const {
            return {getNPixels().x() * getPixelSize().x(), getNPixels().y() * getPixelSize().y(), 0};
        }

@@ -410,6 +410,25 @@ namespace allpix {
         */
        virtual std::pair<int, int> getPixelIndex(const ROOT::Math::XYZPoint& position) const;

        /**
         * @brief Return a set containing all pixels neighboring the given one with a configurable maximum distance
         * @param idx       Index of the pixel in question
         * @param distance  Distance for pixels to be considered neighbors
         * @return Set of neighboring pixel indices, including the initial pixel
         *
         * @note The returned set should always also include the initial pixel indices the neighbors are calculated for
         */
        virtual std::set<Pixel::Index> getNeighbors(const Pixel::Index& idx, const size_t distance) const;

        /**
         * @brief Check if two pixel indices are neighbors to each other
         * @param  seed    Initial pixel index
         * @param  entrant Entrant pixel index to be tested
         * @param distance  Distance for pixels to be considered neighbors
         * @return         Boolean whether pixels are neighbors or not
         */
        virtual bool areNeighbors(const Pixel::Index& seed, const Pixel::Index& entrant, const size_t distance) const;

    protected:
        std::string type_;

+2 −7
Original line number Diff line number Diff line
@@ -615,7 +615,7 @@ void DetectorHistogrammerModule::finalize() {
/**
 * @brief Perform a sparse clustering on the PixelHits
 */
std::vector<Cluster> DetectorHistogrammerModule::doClustering(std::shared_ptr<PixelHitMessage>& pixels_message) {
std::vector<Cluster> DetectorHistogrammerModule::doClustering(std::shared_ptr<PixelHitMessage>& pixels_message) const {
    std::vector<Cluster> clusters;
    std::map<const PixelHit*, bool> usedPixel;

@@ -634,13 +634,8 @@ std::vector<Cluster> DetectorHistogrammerModule::doClustering(std::shared_ptr<Pi
        LOG(TRACE) << "Creating new cluster with seed: " << pixel_hit->getPixel().getIndex();

        auto touching = [&](const PixelHit* pixel) {
            auto pxi1 = pixel->getIndex();
            for(const auto& cluster_pixel : cluster.getPixelHits()) {

                auto distance = [](unsigned int lhs, unsigned int rhs) { return (lhs > rhs ? lhs - rhs : rhs - lhs); };

                auto pxi2 = cluster_pixel->getIndex();
                if(distance(pxi1.x(), pxi2.x()) <= 1 && distance(pxi1.y(), pxi2.y()) <= 1) {
                if(detector_->getModel()->areNeighbors(cluster_pixel->getIndex(), pixel->getIndex(), 1)) {
                    return true;
                }
            }
Loading