Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
d20fce8
warm up porting
lastgeorge Oct 28, 2025
a457e9e
continue validation
lastgeorge Oct 28, 2025
eb3190d
continue validation
lastgeorge Oct 28, 2025
c7021b2
continue validation
lastgeorge Oct 28, 2025
8211d9b
continue validation
lastgeorge Oct 28, 2025
2ced978
fix a bug in the Box Recombination Model
lastgeorge Oct 28, 2025
277fd15
fix a bug in the Box Recombination Model
lastgeorge Oct 28, 2025
122ad0b
fix a bug
lastgeorge Oct 28, 2025
6a446b4
catch up
lastgeorge Oct 28, 2025
26db774
update logic
lastgeorge Oct 28, 2025
9653eaf
update code
lastgeorge Oct 28, 2025
089a471
implement algorithm for the break_segment_at_point
lastgeorge Oct 28, 2025
16da43d
continue validation
lastgeorge Oct 29, 2025
cf5d832
catch up
lastgeorge Oct 29, 2025
0e32d88
add validation to multi-track fitting
lastgeorge Nov 4, 2025
a75fd20
fix a bug
lastgeorge Nov 4, 2025
ad02e81
catch up
lastgeorge Nov 5, 2025
fca0f7c
continue dbug
lastgeorge Nov 6, 2025
49421f1
fix another bug
lastgeorge Nov 6, 2025
1e430e0
fix bug validation
lastgeorge Nov 6, 2025
7b37aab
add a function
lastgeorge Nov 27, 2025
8bb4783
add a function of check_direction
lastgeorge Nov 27, 2025
8d485e5
implement check_connectivity function
lastgeorge Nov 27, 2025
7444f5a
implement the connect_graph_overclustering_projection as connect_grap…
lastgeorge Nov 27, 2025
d999e6a
implement the new graph
lastgeorge Nov 27, 2025
3397df4
prepare files for Pattern Recognition
lastgeorge Nov 29, 2025
4a37136
add a function
lastgeorge Nov 29, 2025
b531f0a
implement some functions
lastgeorge Nov 29, 2025
87aea6e
put in a template
lastgeorge Nov 30, 2025
df694df
catch up
lastgeorge Nov 30, 2025
dea665a
implement init_first_segment
lastgeorge Nov 30, 2025
c0b0091
check the code
lastgeorge Nov 30, 2025
70d4033
catch code
lastgeorge Nov 30, 2025
6ddfa36
add proto_extend_point
lastgeorge Nov 30, 2025
19ff94b
implement function proto_break_tracks
lastgeorge Dec 1, 2025
ae3556f
implement the replace_segment_and_vertex function
lastgeorge Dec 1, 2025
ab4fcba
break_segment_into_two
lastgeorge Dec 1, 2025
a0572c3
implement break_segments function
lastgeorge Dec 1, 2025
8573112
update code
lastgeorge Dec 1, 2025
067122e
merge two segments into one
lastgeorge Dec 1, 2025
1b71a1e
add merge vertices
lastgeorge Dec 1, 2025
7ceced7
implement two examine_structure functions
lastgeorge Dec 5, 2025
a806d4b
add examine_structure_4
lastgeorge Dec 5, 2025
a07e55b
implement the find_other_segments
lastgeorge Dec 5, 2025
f59f3e9
implement the find_other_segments
lastgeorge Dec 5, 2025
3807877
clean up
lastgeorge Dec 6, 2025
3fa9812
catch up
lastgeorge Dec 6, 2025
c26940d
implement crawl_segment
lastgeorge Dec 7, 2025
911e339
add examine_segment
lastgeorge Dec 7, 2025
367cb73
implement the examine_vertices_1p
lastgeorge Dec 7, 2025
1ee2b3b
implement examine_Vertices_1
lastgeorge Dec 7, 2025
a1f3781
implement examine_vertices_2
lastgeorge Dec 7, 2025
883b9a9
implement examine_vertices_4
lastgeorge Dec 7, 2025
5305889
implement examine_vertices
lastgeorge Dec 7, 2025
d82f180
implement the examine partial identical segments
lastgeorge Dec 7, 2025
28fc7db
get_local_extension
lastgeorge Dec 7, 2025
c5cabfd
implement the examine_vertices_3 function
lastgeorge Dec 8, 2025
88c95a7
implement find_proto_vertex
lastgeorge Dec 8, 2025
7c17ed8
implement the init_point_segment
lastgeorge Dec 8, 2025
c58c0f7
implement the first function of examine_structure_final_1
lastgeorge Dec 16, 2025
ffd4f50
implement the examine_structure_final functions
lastgeorge Dec 16, 2025
e8ea63a
improve implementations
lastgeorge Dec 16, 2025
d5b4ada
implement the search_for_vertex_activities
lastgeorge Dec 17, 2025
d0f1673
catch up
lastgeorge Dec 17, 2025
9498c3b
catch up
lastgeorge Dec 17, 2025
32b80f3
add the local to global indices mapping
lastgeorge Dec 17, 2025
5bbb93d
update code
lastgeorge Dec 17, 2025
12142ef
add a function to transfer information from segment to cluster
lastgeorge Dec 17, 2025
7e91ac6
add sufficient code for transfer information from segment to cluster
lastgeorge Dec 17, 2025
f59a2da
implement determine_direction
lastgeorge Dec 18, 2025
b4a159a
implement examine_good_tracks
lastgeorge Dec 18, 2025
6901400
implement examine_good_tracks
lastgeorge Dec 18, 2025
e443a5d
implement another improve maps function
lastgeorge Dec 18, 2025
c1d02a0
implement the examine_maps function
lastgeorge Dec 18, 2025
717489f
implement the examine_all_showers
lastgeorge Dec 18, 2025
b928b5c
implement EM shower related
lastgeorge Dec 19, 2025
e8e3ea3
implement more functions
lastgeorge Jan 2, 2026
5275d78
implement find_cont_muon_segment function
lastgeorge Jan 2, 2026
e22c0c4
implement the examine_direction
lastgeorge Jan 2, 2026
85b0c8d
implement the eliminate_short_vertex_activities
lastgeorge Jan 2, 2026
368986c
update MyFCN
lastgeorge Jan 2, 2026
057db7c
fully implement MyFCN
lastgeorge Jan 2, 2026
6b66163
implement the fit_vertex function
lastgeorge Jan 2, 2026
38be7a0
implement the improve_vertex function
lastgeorge Jan 2, 2026
06bf9f5
implement the determine_main_vertex function
lastgeorge Jan 2, 2026
d0bf918
implement the examine_main_vertices
lastgeorge Jan 3, 2026
a69dd91
implement moer functions
lastgeorge Jan 3, 2026
e089ca5
update code
lastgeorge Jan 3, 2026
f131e01
add more functions
lastgeorge Jan 4, 2026
d5ee192
add more functions
lastgeorge Jan 4, 2026
f505bb8
continue working on the PRShower
lastgeorge Jan 4, 2026
0b12568
update code
lastgeorge Jan 4, 2026
e9de719
fully implement the PRShower
lastgeorge Jan 4, 2026
5c9e617
update code
lastgeorge Jan 4, 2026
5cae6b9
catch up
lastgeorge Jan 6, 2026
675ce54
implement the deghost_clusters fucntion
lastgeorge Jan 6, 2026
e233d86
implement deghost_segments function
lastgeorge Jan 6, 2026
95009cf
update code
lastgeorge Jan 6, 2026
49442c6
implement two functions
lastgeorge Jan 6, 2026
9ac39f1
add one more function
lastgeorge Jan 7, 2026
1675fa4
update prepare for kinematics calculation
lastgeorge Jan 7, 2026
e61de59
catch up
lastgeorge Jan 7, 2026
85d4498
update code
lastgeorge Jan 8, 2026
f820e20
implement the collect_2d_charge
lastgeorge Jan 9, 2026
aa26356
implement the cal_kine_Charge(shower function
lastgeorge Jan 10, 2026
89f6b68
implement cal_kine_charge function
lastgeorge Jan 10, 2026
0a5fa7e
add code
lastgeorge Jan 10, 2026
95a804a
implement the examine_merged_showers
lastgeorge Jan 10, 2026
dfa78f3
implement the shower_clustering_in_other_clusters function
lastgeorge Jan 10, 2026
7613ea7
implement the examine_shower_1
lastgeorge Jan 10, 2026
0997cc1
implement examine_showers
lastgeorge Jan 10, 2026
189175f
implement the id_pi0_without_vertex function
lastgeorge Jan 11, 2026
1db8316
implement the shower_clustering_with_nv function
lastgeorge Jan 11, 2026
7ae81a3
example helper functions with ROOT
Feb 11, 2026
d6c3203
add track fitting into the bee output
Feb 12, 2026
006e5ee
add files
Feb 12, 2026
c244dc9
structure change, save TrackFitting inside the Grouping
Feb 12, 2026
bf8a7f3
update code
Feb 12, 2026
1c38029
update code
Feb 12, 2026
17b6af5
add some dumping code for intermediate date and loading them in a new…
Feb 16, 2026
b532f17
commit test data and configuration
Feb 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update code
  • Loading branch information
lastgeorge committed Jan 4, 2026
commit 0b125685a7bbcdc409a38219380c4f6c38713c0e
16 changes: 12 additions & 4 deletions clus/inc/WireCellClus/PRShowerFunctions.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#ifndef WIRECELL_CLUS_PR_SHOWER_FUNCTIONS
#define WIRECELL_CLUS_PR_SHOWER_FUNCTIONS

#include "WireCellClus/PRShower.h"
#include "WireCellUtil/Units.h"


namespace WireCell::Clus::PR {

/** Modify shower assuming shower kinematics.
*
* This free function is is equivalent to the method of WCP's
* WCShower::calculate_kinematics().
*/
void shower_kinematics(ShowerPtr shower);

void update_particle_type(ShowerPtr shower);

void longmuon_kinematics(ShowerPtr shower);
std::pair<double, WireCell::Point> shower_get_closest_point(Shower& shower, const WireCell::Point& point, const std::string& cloud_name = "fit");

double shower_get_closest_dis(Shower& shower, SegmentPtr seg, const std::string& cloud_name = "fit");

double shower_get_dis(Shower& shower, SegmentPtr seg, const std::string& cloud_name = "fit");

WireCell::Vector shower_cal_dir_3vector(Shower& shower, const WireCell::Point& p, double dis_cut = 15*units::cm);

}

#endif
180 changes: 179 additions & 1 deletion clus/src/PRShowerFunctions.cxx
Original file line number Diff line number Diff line change
@@ -1,2 +1,180 @@
#include "WireCellClus/PRShower.h"
#include "WireCellClus/PRShowerFunctions.h"
#include "WireCellClus/PRSegmentFunctions.h"
#include "WireCellClus/DynamicPointCloud.h"

using namespace WireCell::Clus::PR;

namespace WireCell::Clus::PR {

std::pair<double, WireCell::Point> shower_get_closest_point(Shower& shower, const WireCell::Point& point, const std::string& cloud_name /* = "fit" */){
// Get the dynamic point cloud from the shower
auto pcloud = shower.get_pcloud(cloud_name);

// If no point cloud exists, return invalid result
if (!pcloud) {
return std::make_pair(-1.0, WireCell::Point(0, 0, 0));
}

// Get the 3D KD-tree
auto& kd3d = pcloud->kd3d();

// Prepare query point
std::vector<double> query = {point.x(), point.y(), point.z()};

// Find the nearest neighbor
auto results = kd3d.knn(1, query);

// Check if we found a point
if (results.empty()) {
return std::make_pair(-1.0, WireCell::Point(0, 0, 0));
}

// Get the result
const size_t idx = results[0].first;
const double distance = sqrt(results[0].second); // KD-tree returns squared distance

// Get the actual point from the point cloud
const auto& points = pcloud->get_points();
const auto& closest_pt = points[idx];

return std::make_pair(distance, WireCell::Point(closest_pt.x, closest_pt.y, closest_pt.z));
}

double shower_get_closest_dis(Shower& shower, SegmentPtr seg, const std::string& cloud_name /* = "fit" */){
// Get the first point from segment's DynamicPointCloud
auto seg_dpc = seg->dpcloud(cloud_name);
if (!seg_dpc) {
return -1.0;
}

const auto& seg_points = seg_dpc->get_points();
if (seg_points.empty()) {
return -1.0;
}

// Use the first point from segment's point cloud
WireCell::Point first_point(seg_points.front().x, seg_points.front().y, seg_points.front().z);

// Step 1: Get closest point in shower to the first point of the segment
WireCell::Point test_p = shower_get_closest_point(shower, first_point, cloud_name).second;

// Step 2: Get closest point in segment to that point (uses segment's DPC with KD-tree)
test_p = segment_get_closest_point(seg, test_p, cloud_name).second;

// Step 3: Get closest point in shower to that point
test_p = shower_get_closest_point(shower, test_p, cloud_name).second;

// Step 4: Get closest distance in segment to that point
return segment_get_closest_point(seg, test_p, cloud_name).first;
}

double shower_get_dis(Shower& shower, SegmentPtr seg, const std::string& cloud_name /* = "fit" */){
double min_dis = 1e9;
WireCell::Point min_point;

// Get the first point from the input segment's DynamicPointCloud
auto seg_dpc = seg->dpcloud(cloud_name);
if (!seg_dpc) {
return -1.0;
}

const auto& seg_points = seg_dpc->get_points();
if (seg_points.empty()) {
return -1.0;
}

WireCell::Point test_p(seg_points.front().x, seg_points.front().y, seg_points.front().z);

// Get the view graph to access segments
const auto& view = shower.view_graph();

// First iteration: find the closest point in any shower segment to test_p
for (auto edesc : shower.edges()) {
SegmentPtr sg = view[edesc].segment;
if (!sg) continue;

auto results = segment_get_closest_point(sg, test_p, cloud_name);
if (results.first < min_dis) {
min_dis = results.first;
min_point = results.second;
}
}

// Get closest point in input segment to that minimum point
auto results1 = segment_get_closest_point(seg, min_point, cloud_name);
test_p = results1.second;

// Second iteration: find the closest distance from any shower segment to the new test point
for (auto edesc : shower.edges()) {
SegmentPtr sg = view[edesc].segment;
if (!sg) continue;

auto results = segment_get_closest_point(sg, test_p, cloud_name);
if (results.first < min_dis) {
min_dis = results.first;
min_point = results.second;
}
}

return min_dis;
}

WireCell::Vector shower_cal_dir_3vector(Shower& shower, const WireCell::Point& p, double dis_cut /* = 15*units::cm */){
WireCell::Point p_sum(0, 0, 0);
int ncount = 0;

// Get the view graph to access segments
const auto& view = shower.view_graph();

// Loop through all segments in the shower
for (auto edesc : shower.edges()) {
SegmentPtr seg = view[edesc].segment;
if (!seg) continue;

// Get the segment's fits
const auto& fits = seg->fits();

// Check each fit point in the segment
for (const auto& fit : fits) {
// Calculate distance from this fit point to p
double dis = sqrt(pow(fit.point.x() - p.x(), 2) +
pow(fit.point.y() - p.y(), 2) +
pow(fit.point.z() - p.z(), 2));

// If within distance cutoff, accumulate the point
if (dis < dis_cut) {
p_sum = WireCell::Point(p_sum.x() + fit.point.x(),
p_sum.y() + fit.point.y(),
p_sum.z() + fit.point.z());
ncount++;
}
}
}

// If no points were found, return zero vector
if (ncount == 0) {
return WireCell::Vector(0, 0, 0);
}

// Calculate the average point and direction vector
WireCell::Point p_avg(p_sum.x() / ncount,
p_sum.y() / ncount,
p_sum.z() / ncount);

// Direction vector from p to average point
WireCell::Vector dir(p_avg.x() - p.x(),
p_avg.y() - p.y(),
p_avg.z() - p.z());

// Normalize the vector
double magnitude = dir.magnitude();
if (magnitude > 0) {
dir = dir.norm();
}

return dir;
}



} // namespace WireCell::Clus::PR