Skip to content

Commit

Permalink
Add Cluster Print function (fchinu#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiorgioAlbertoLucia authored Apr 2, 2024
2 parents 90b9396 + fdb35fa commit 43098e0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 46 deletions.
42 changes: 3 additions & 39 deletions Clustering/include/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <array>
#include <bitset>
#include <cstdint>
#include <iostream>
class Cluster {

public:
Expand All @@ -30,6 +31,8 @@ class Cluster {
inline unsigned GetClusterSize() const { return fClusterSize; }
inline unsigned GetClusterID() const { return fClusterID; }

void PrintCluster() const;

private:
unsigned fChipID;
unsigned fEventID;
Expand All @@ -43,42 +46,3 @@ class Cluster {

inline static unsigned fClusterCounter = 0;
};

Cluster::Cluster(
unsigned chipID, unsigned eventID, unsigned clusterPositionX,
unsigned clusterPositionY,
std::array<std::bitset<MAX_CLUSTER_COLS>, MAX_CLUSTER_ROWS> arrayShape)
: fChipID(chipID), fEventID(eventID), fClusterPositionX(clusterPositionX),
fClusterPositionY(clusterPositionY), fClusterSize(0), fShape(arrayShape),
fClusterID(fClusterCounter++) {

for (unsigned i = 0; i < MAX_CLUSTER_ROWS; i++) {
for (unsigned j = 0; j < MAX_CLUSTER_COLS; j++) {
if (fShape[i][j]) {
fMeanX += i;
fMeanY -= j; // fClusterPositionY is top row, so we need to
// subtract the row number to get the correct
// position
fClusterSize++;
}
}
}
fMeanX /= fClusterSize;
fMeanY /= fClusterSize;
fMeanX += fClusterPositionX;
fMeanY += fClusterPositionY;
}

Cluster::Cluster(
unsigned chipID, unsigned eventID, float meanX, float meanY,
unsigned clusterPositionX, unsigned clusterPositionY,
std::array<std::bitset<MAX_CLUSTER_COLS>, MAX_CLUSTER_ROWS> arrayShape)
: fChipID(chipID), fEventID(eventID), fMeanX(meanX), fMeanY(meanY),
fClusterPositionX(clusterPositionX), fClusterPositionY(clusterPositionY),
fClusterSize(0), fShape(arrayShape), fClusterID(fClusterCounter++) {

for (unsigned i = 0; i < MAX_CLUSTER_ROWS; i++)
for (unsigned j = 0; j < MAX_CLUSTER_COLS; j++)
if (fShape[i][j])
fClusterSize++;
}
File renamed without changes.
62 changes: 62 additions & 0 deletions Clustering/src/Cluster.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "../../Clustering/include/Cluster.h"

Cluster::Cluster(
unsigned chipID, unsigned eventID, unsigned clusterPositionX,
unsigned clusterPositionY,
std::array<std::bitset<MAX_CLUSTER_COLS>, MAX_CLUSTER_ROWS> arrayShape)
: fChipID(chipID), fEventID(eventID), fClusterPositionX(clusterPositionX),
fClusterPositionY(clusterPositionY), fClusterSize(0), fShape(arrayShape),
fClusterID(fClusterCounter++) {

for (unsigned i = 0; i < MAX_CLUSTER_ROWS; i++) {
for (unsigned j = 0; j < MAX_CLUSTER_COLS; j++) {
if (fShape[i][j]) {
fMeanX += i;
fMeanY -= j; // fClusterPositionY is top row, so we need to
// subtract the row number to get the correct
// position
fClusterSize++;
}
}
}
fMeanX /= fClusterSize;
fMeanY /= fClusterSize;
fMeanX += fClusterPositionX;
fMeanY += fClusterPositionY;
}

Cluster::Cluster(
unsigned chipID, unsigned eventID, float meanX, float meanY,
unsigned clusterPositionX, unsigned clusterPositionY,
std::array<std::bitset<MAX_CLUSTER_COLS>, MAX_CLUSTER_ROWS> arrayShape)
: fChipID(chipID), fEventID(eventID), fMeanX(meanX), fMeanY(meanY),
fClusterPositionX(clusterPositionX), fClusterPositionY(clusterPositionY),
fClusterSize(0), fShape(arrayShape), fClusterID(fClusterCounter++) {

for (unsigned i = 0; i < MAX_CLUSTER_ROWS; i++)
for (unsigned j = 0; j < MAX_CLUSTER_COLS; j++)
if (fShape[i][j])
fClusterSize++;
}

void Cluster::PrintCluster() const {
std::cout << "Cluster ID: " << fClusterID << std::endl;
std::cout << "Chip ID: " << fChipID << std::endl;
std::cout << "Event ID: " << fEventID << std::endl;
std::cout << "Cluster Position: (" << fClusterPositionX << ", "
<< fClusterPositionY << ")" << std::endl;
std::cout << "Mean Position: (" << fMeanX << ", " << fMeanY << ")"
<< std::endl;
std::cout << "Cluster Size: " << fClusterSize << std::endl;
std::cout << "Cluster Shape:" << std::endl;
for (unsigned i = 0; i < MAX_CLUSTER_ROWS; i++) {
for (unsigned j = 0; j < MAX_CLUSTER_COLS; j++) {
if (fShape[i][j])
std::cout << "X";
else
std::cout << ".";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
9 changes: 2 additions & 7 deletions Clustering/src/clusterer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <iostream>
#include <unordered_map>

#include "../../Clustering/include/clusterer.h"
#include "../../Utils/include/fileManager.h"
#include "clusterer.h"

/* PUBLIC */

Expand Down Expand Up @@ -134,13 +134,8 @@ void Clusterer::EventClustering(FileManager &inputData, const int ievent) {

fClusters.push_back(cluster);

/*
// visualize cluster on terminal
std::cout << "Cluster size " << cluster.GetClusterSize() << std::endl;
for (auto i : cluster.GetShape()) {
std::cout << i << std::endl;
}
*/
cluster.PrintCluster();

indices.erase(std::remove_if(indices.begin(), indices.end(),
[&clusterIndeces](int i) {
Expand Down
1 change: 1 addition & 0 deletions Controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ROOT
ROOT.gInterpreter.ProcessLine('#include "Clustering/src/clusterer.cxx"')
ROOT.gInterpreter.ProcessLine('#include "Clustering/src/Cluster.cxx"')
ROOT.gInterpreter.ProcessLine('#include "Utils/include/fileManager.cxx"')

from ROOT import Clusterer
Expand Down

0 comments on commit 43098e0

Please sign in to comment.