Skip to content

Commit

Permalink
Fixed input arguments, chacked incomplete_cells in Clusterize
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerio Pia committed Feb 5, 2025
1 parent 3ab8010 commit e1b2811
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ target_link_libraries(eventDisplay PUBLIC Utils SANDEventDisplay "-lEG -lGui")

# Creates SANDECALClustering executable.
add_executable(SANDECALClustering src/SANDECALClustering.cpp)
target_link_libraries(SANDECALClustering PUBLIC Utils SANDClustering)
target_link_libraries(SANDECALClustering PUBLIC Struct Utils SANDClustering)

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "default install path" FORCE )
Expand Down
4 changes: 2 additions & 2 deletions include/SANDClustering.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ std::tuple<double, double, double, double> fit_ls(int, double[], double[],
double[]);

std::pair<std::vector<dg_cell>, std::vector<dg_cell>> ProcessMultiHits(
std::vector<dg_cell>, std::vector<dg_cell>);
std::vector<dg_cell>);
std::pair<std::vector<dg_cell>, std::vector<int>> GetNeighbours(
std::vector<dg_cell>, int, std::vector<int>, std::vector<dg_cell>);


std::vector<cluster> Clusterize(const SANDGeoManager* sand_geo, std::vector<dg_cell>*);
std::vector<cluster> Clusterize(const SANDGeoManager* sand_geo, const std::vector<dg_cell>&);
void Clust_info(cluster);
std::vector<cluster> TrackFit(std::vector<cluster>);
std::vector<cluster> Merge(std::vector<cluster>);
Expand Down
2 changes: 1 addition & 1 deletion include/SANDECALCellInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SANDECALCellInfo : public TObject
void length(double arg_length);
void orientation(Orient arg_orientation);
// Getter methods for the attributes
int id();
int id() const;
double x() const;
double y() const;
double z() const;
Expand Down
49 changes: 17 additions & 32 deletions src/SANDClustering.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
#include "SANDClustering.h"
#include "utils.h"

std::vector<cluster> Clusterize(const SANDGeoManager* sand_geo, std::vector<dg_cell>* vec_cellraw)
std::vector<cluster> Clusterize(const SANDGeoManager* sand_geo, const std::vector<dg_cell>& cells)
{
std::vector<dg_cell> complete_cells, broken_cells, multicomplete_cells;
std::vector<cluster> vec_clust;

for (auto const& cell : *vec_cellraw) {
if (cell.ps1.size() == 0 && cell.ps2.size() == 0) {

continue;
} else if (cell.ps1.size() == 0 || cell.ps2.size() == 0) {

broken_cells.push_back(cell);
} else if ((cell.ps1.size() != 0 && cell.ps2.size() != 0)) {
// Complete cell

complete_cells.push_back(cell);
}
}

std::pair<std::vector<dg_cell>, std::vector<dg_cell>> processed_cells =
ProcessMultiHits(complete_cells, broken_cells);
multicomplete_cells = processed_cells.first;
broken_cells = processed_cells.second;

std::pair<std::vector<dg_cell>, std::vector<dg_cell>> processed_cells = ProcessMultiHits(cells);
std::vector<dg_cell> complete_cells = processed_cells.first;
std::vector<dg_cell> incomplete_cells = processed_cells.second;

std::vector<int> checked_array;
std::vector<int> vec_cell;
std::vector<int> chck;

for (uint i = 0; i < multicomplete_cells.size(); i++) {
std::vector<cluster> vec_clust;
for (uint i = 0; i < complete_cells.size(); i++) {

std::vector<dg_cell> v_cell;

Expand All @@ -39,10 +20,10 @@ std::vector<cluster> Clusterize(const SANDGeoManager* sand_geo, std::vector<dg_c
chck.push_back(i);
}

v_cell.push_back(multicomplete_cells.at(i));
v_cell.push_back(complete_cells.at(i));

std::pair<std::vector<dg_cell>, std::vector<int>> Neighbours =
GetNeighbours(multicomplete_cells, i, chck, v_cell);
GetNeighbours(complete_cells, i, chck, v_cell);
v_cell = Neighbours.first;
chck = Neighbours.second;
struct cluster Clust;
Expand All @@ -51,6 +32,7 @@ std::vector<cluster> Clusterize(const SANDGeoManager* sand_geo, std::vector<dg_c

vec_clust.push_back(Clust);
}

// SPLIT
int n_clu = 0;

Expand All @@ -61,14 +43,14 @@ std::vector<cluster> Clusterize(const SANDGeoManager* sand_geo, std::vector<dg_c
vec_clust = Split(vec_clust, HasSplit);
iteration++;
} while (HasSplit);

// MERGE

vec_clust = Merge(vec_clust);

// Track Fit
vec_clust = TrackFit(vec_clust);

vec_clust = RecoverIncomplete(sand_geo, vec_clust, broken_cells);
vec_clust = RecoverIncomplete(sand_geo, vec_clust, incomplete_cells);

return vec_clust;
}
Expand All @@ -92,11 +74,12 @@ void Clust_info(cluster clus)
}

std::pair<std::vector<dg_cell>, std::vector<dg_cell>> ProcessMultiHits(
std::vector<dg_cell> og_cell, std::vector<dg_cell> incomplete_cells)
std::vector<dg_cell> cells)
{

std::vector<dg_cell> complete_cells;
for (auto const& cell : og_cell) {
std::vector<dg_cell> incomplete_cells;
for (auto const& cell : cells) {
double delta = cell.l * sand_reco::ecal::scintillation::vlfb /
sand_reco::conversion::m_to_mm;

Expand Down Expand Up @@ -185,6 +168,8 @@ std::vector<cluster> RecoverIncomplete(const SANDGeoManager* sand_geo, std::vect
std::cout << "incomplete_cell.mod: " << incomplete_cell.mod << std::endl;
isbarrel = 2;
}

// TODO: This should be in the geo_cell or in the geoManager
double cell_phi =
atan((incomplete_cell.z - 23910.00) / (incomplete_cell.y + 2384.73)) * 180 /
TMath::Pi();
Expand Down
2 changes: 1 addition & 1 deletion src/SANDECALCellInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void SANDECALCellInfo::orientation(Orient arg_orientation)
}

// Getter methods for the attributes
int SANDECALCellInfo::id() { return id_; }
int SANDECALCellInfo::id() const { return id_; }
double SANDECALCellInfo::x() const { return x_; }
double SANDECALCellInfo::y() const { return y_; }
double SANDECALCellInfo::z() const { return z_; }
Expand Down
22 changes: 18 additions & 4 deletions src/SANDECALClustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int clustering(std::string const& input, std::string const& edep_input)

for (int i = 0; i < nEvents; i++) {
t->GetEntry(i);
std::vector<cluster> clust = Clusterize(&sand_geo, std::move(cell));
std::vector<cluster> clust = Clusterize(&sand_geo, *cell);

f_clust = clust;
tout.Fill();
Expand All @@ -49,7 +49,7 @@ int clustering(std::string const& input, std::string const& edep_input)
return 0;
}

bool initializeFiles(int argc, char* argv[], std::string& digitFileName)
bool initializeFiles(int argc, char* argv[], std::string& digitFileName, std::string& edepFileName)
{

for (int i = 1; i < argc; i += 2) {
Expand All @@ -58,6 +58,8 @@ bool initializeFiles(int argc, char* argv[], std::string& digitFileName)

if (flag == "-d") {
digitFileName = fileName;
} else if (flag == "-e") {
edepFileName = fileName;
} else {
std::cerr << "Error: Unknown flag: " << flag << std::endl;
return false;
Expand All @@ -70,13 +72,25 @@ bool initializeFiles(int argc, char* argv[], std::string& digitFileName)
<< std::endl;
return false;
}
if (edepFileName.empty()) {
std::cerr << "Error: Missing required flags. Please use '-e' with "
"corresponding file name."
<< std::endl;
return false;
}

if (!endsWith(digitFileName, ".digit.root")) {
std::cerr << "Error: Invalid arguments. Please use '-d' before the "
".digit.root file"
<< std::endl;
return false;
}
if (!endsWith(edepFileName, ".edep.root")) {
std::cerr << "Error: Invalid arguments. Please use '-e' before the "
".edep.root file"
<< std::endl;
return false;
}

return true;
}
Expand All @@ -85,12 +99,12 @@ int main(int argc, char* argv[])
{

if (argc < 2) {
std::cerr << "Usage: SANDECALClustering" << " -d <file.digit.root>" << std::endl;
std::cerr << "Usage: SANDECALClustering -d <file.digit.root> -e <file.edep.root>" << std::endl;
return 1;
}
std::string digitFileName;
std::string ecalFileName;
if (!initializeFiles(argc, argv, digitFileName)) {
if (!initializeFiles(argc, argv, digitFileName, ecalFileName)) {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/reconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ void Reconstruct(std::string const& fname_hits, std::string const& fname_digits,
// Filter(vec_cl);
//PidBasedClustering(ev, vec_cell, vec_cl);
//Merge(vec_cl);
vec_cl = Clusterize(&sand_geo, vec_cell);
vec_cl = Clusterize(&sand_geo, *vec_cell);
break;
}
tout.Fill();
Expand Down

0 comments on commit e1b2811

Please sign in to comment.