Pixel Cluster Perimeter Calculation

Hello I am looking to calculate the perimeter of a cluster of charges collected at the anode using the PixelHit object. I wanted to traverse a set of surrounding pixels and determine if they are empty or not to move over the boundary and calculate the perimeter. Is it possible to see if a specific pixel has charges collected or not? Will I need to construct a Pixel and check using the getCharge method?

Hi @oobie2142

are you looking for the perimeter only on the level of “how many pixels are in the cluster”? Then you would only have to look if you find any neighboring PixelHit objects.

There is also the possibility to see from where these charges collected at the electrode come, for this you would have to take the DepositedCharge information as well as your PixelHit and traverse the MC truth chain backwards, see Object History | Allpix Squared

Since we had a similar use case recently, we have implemented a (yet unreleased) function for the PixelCharge object that lets us find all PropagatedCharge objects based on a DepositedCharge:

std::vector<const PropagatedCharge*> PixelCharge::find(const DepositedCharge* deposit) const {
    // FIXME: This is not very efficient unfortunately
    std::vector<const PropagatedCharge*> propagated_charges;
    for(const auto& propagated_charge : propagated_charges_) {
        const auto* charge = propagated_charge.get();
        if(charge != nullptr && charge->getDepositedCharge() == deposit) {
            propagated_charges.emplace_back(propagated_charge.get());
        }
    }
    return propagated_charges;
}

You could attempt something similar in your analysis to link the necessary information together.

Best regards,
Simon

I think traversing neighboring PixelHit objects is sufficient. At the moment I am trying to replicate the circularity measurement similar to what is implemented in MATLAB’s regionprops calculations mentioned here. The perimeter seems to be in terms of pixels such that a shape close to a circle gives a circularity of 1.

In that case you can likely harness some of the clustering code e.g. from here:

Sounds great I will take a look. Do the pixel methods work in the loop over the pixel hits to check the indices of the hits as you add them to the cluster? Thanks!

In this case they use the DetectorModel::areNeighbors() method to make it independent of the sensor geometry. But if you only need this for your regular pixel grid, it’s just index checking, yes.

@simonspa Is it possible to get the detector model inside of an analysis script? or is it only accessible at simulation run time?

It is only available during simulation time, but in principle you can include and link the relevant files - but I guess it would be quicker to look at the logic and copy the part you need for your detector into your script. :slight_smile: