Commit 355d4fa7 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'get_earliest_pixel' into 'master'

Cluster: add function to retrieve earliest pixel + split getSeedPixel()

See merge request !433
parents f839fb60 3ffa8e37
Pipeline #2692109 passed with stages
in 22 minutes and 36 seconds
......@@ -51,41 +51,41 @@ std::vector<const Pixel*> Cluster::pixels() const {
const Pixel* Cluster::getSeedPixel() const {
Pixel* seed = nullptr;
// If cluster has non-zero charge, return pixel with largest charge,
// else return earliest pixel.
double maxcharge = -1;
// If charge != 0 (use epsilon to avoid errors in floating-point arithmetic):
if(m_charge > std::numeric_limits<double>::epsilon()) {
// loop overall pixels and find the one with the largest charge:
for(auto& px : m_pixels) {
auto pxl = dynamic_cast<Pixel*>(px.GetObject());
if(pxl == nullptr) {
throw MissingReferenceException(typeid(*this), typeid(Pixel));
}
if(pxl->charge() > maxcharge) {
maxcharge = pxl->charge();
seed = pxl;
}
// loop overall pixels and find the one with the largest charge:
for(auto& px : m_pixels) {
auto pxl = dynamic_cast<Pixel*>(px.GetObject());
if(pxl == nullptr) {
throw MissingReferenceException(typeid(*this), typeid(Pixel));
}
} else { // return the earliest pixel:
double earliestTimestamp = std::numeric_limits<double>::max();
for(auto& px : m_pixels) {
auto pxl = dynamic_cast<Pixel*>(px.GetObject());
if(pxl == nullptr) {
throw MissingReferenceException(typeid(*this), typeid(Pixel));
}
if(pxl->timestamp() < earliestTimestamp) {
earliestTimestamp = pxl->timestamp();
seed = pxl;
}
if(pxl->charge() > maxcharge) {
maxcharge = pxl->charge();
seed = pxl;
}
}
return seed;
}
const Pixel* Cluster::getEarliestPixel() const {
Pixel* earliest = nullptr;
double earliestTimestamp = std::numeric_limits<double>::max();
for(auto& px : m_pixels) {
auto pxl = dynamic_cast<Pixel*>(px.GetObject());
if(pxl == nullptr) {
throw MissingReferenceException(typeid(*this), typeid(Pixel));
}
if(pxl->timestamp() < earliestTimestamp) {
earliestTimestamp = pxl->timestamp();
earliest = pxl;
}
}
return earliest;
}
void Cluster::print(std::ostream& out) const {
out << "Cluster " << this->m_local.x() << ", " << this->m_local.y() << ", " << this->m_global << ", " << this->m_charge
<< ", " << this->m_split << ", " << this->m_pixels.size() << ", " << this->m_columnWidth << ", " << this->m_rowWidth
......
......@@ -67,12 +67,19 @@ namespace corryvreckan {
/**
* @brief Retrieve the seed pixel of the cluster.
*
* The seed pixel is defined as the one with the highest charge. In case all pixels have zero charge, return the
* pixel with the earliest timestamp..
* The seed pixel is defined as the one with the highest charge. In case all pixels have the same charge return a
* random pixel.
*
* @return Seed pixel of the cluster
*/
const Pixel* getSeedPixel() const;
/**
* @brief Retrieve the earliest pixel of the cluster. In case all pixels have the same timstamp return a random
* pixel.
*
* @return Earliest pixel of the cluster
*/
const Pixel* getEarliestPixel() const;
// Set cluster parameters
void setColumn(double col) { m_column = col; }
......@@ -108,7 +115,7 @@ namespace corryvreckan {
std::map<int, bool> m_columnHits;
// ROOT I/O class definition - update version number when you change this class!
ClassDefOverride(Cluster, 12)
ClassDefOverride(Cluster, 13)
};
// Vector type declaration
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment