From 36bf5911da95f4c0fad4b30544aee7bdb3c83dc5 Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Thu, 17 Oct 2024 05:02:55 -0500 Subject: [PATCH 1/4] Fix the not filled StartDirection without Kalman filter --- src/TMS_Reco.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/TMS_Reco.cpp b/src/TMS_Reco.cpp index eeee284..b22a3cf 100644 --- a/src/TMS_Reco.cpp +++ b/src/TMS_Reco.cpp @@ -1660,20 +1660,22 @@ std::vector TMS_TrackFinder::TrackMatching3D() { #ifdef DEBUG std::cout << "Added TrackEnergyDeposit: " << aTrack.EnergyDeposit << std::endl; #endif -// // Track Direction -// if (TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_DirectionDistance() >= aTrack.Hits.size()) { -// aTrack.Direction[0] = aTrack.Start[0] - aTrack.End[0]; -// aTrack.Direction[1] = aTrack.Start[1] - aTrack.End[1]; -// aTrack.Direction[2] = aTrack.Start[2] - aTrack.End[2]; -// } else { -// aTrack.Direction[0] = aTrack.Start[0] - aTrack.Hits[TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_DirectionDistance()].GetRecoX(); -// aTrack.Direction[1] = aTrack.Start[1] - aTrack.Hits[TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_DirectionDistance()].GetRecoY(); -// aTrack.Direction[2] = aTrack.Start[2] - aTrack.Hits[TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_DirectionDistance()].GetZ(); -// } + // Track Direction + if (TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_DirectionDistance() >= aTrack.Hits.size()) { + double direction_x = aTrack.Start[0] - aTrack.End[0]; + double direction_y = aTrack.Start[1] - aTrack.End[1]; + double direction_z = aTrack.Start[2] - aTrack.End[2]; + aTrack.SetStartDirection(direction_x, direction_y, direction_z); + } else { + double direction_x = aTrack.Start[0] - aTrack.Hits[TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_DirectionDistance()].GetRecoX(); + double direction_y = aTrack.Start[1] - aTrack.Hits[TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_DirectionDistance()].GetRecoY(); + double direction_z = aTrack.Start[2] - aTrack.Hits[TMS_Manager::GetInstance().Get_Reco_TRACKMATCH_DirectionDistance()].GetZ(); + aTrack.SetStartDirection(direction_x, direction_y, direction_z); + } #ifdef DEBUG std::cout << "Start: " << aTrack.Start[0] << " | " << aTrack.Start[1] << " | " << aTrack.Start[2] << std::endl; std::cout << "End: " << aTrack.End[0] << " | " << aTrack.End[1] << " | " << aTrack.End[2] << std::endl; - std::cout << "Added Direction: " << aTrack.Direction[0] << " | " << aTrack.Direction[1] << " | " << aTrack.Direction[2] << std::endl; + std::cout << "Added Direction: " << aTrack.StartDirection[0] << " | " << aTrack.StartDirection[1] << " | " << aTrack.StartDirection[2] << std::endl; #endif returned.push_back(aTrack); From aaa87920af033b63916437e4240fb6291ce4e68c Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Thu, 17 Oct 2024 10:40:03 -0500 Subject: [PATCH 2/4] Changing the values in the config file --- config/TMS_Default_Config.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/TMS_Default_Config.toml b/config/TMS_Default_Config.toml index 167f86f..a24c7d1 100644 --- a/config/TMS_Default_Config.toml +++ b/config/TMS_Default_Config.toml @@ -46,7 +46,7 @@ # dist = sqrt(xplanes*xplanes + zplanes*zplanes) MinDist = 4.0 # Do we run DBSCAN clustering before the Hough transform and then run Hough on each cluster? - FirstCluster = true #false + FirstCluster = false # Do we merge adjacent tracks afterwards? MergeTracks = true # Do we run AStar afterwards on start and end points @@ -81,7 +81,7 @@ # Y difference for expectation of reconstruction from UV and from X hit [mm] YDifference = 3000.0 # Distance from start to calculate track direction for [Number of planes]. Track matching done in plane pairs -> do not set to 1 - DirectionDistance = 10 + DirectionDistance = 14 [Recon.AStar] #CostMetric = "Manhattan" From 543be5797e8cb4c507877928fb2a4459e629529a Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Tue, 22 Oct 2024 09:04:46 -0500 Subject: [PATCH 3/4] Commit before merging fix in --- config/TMS_Default_Config.toml | 2 +- src/TMS_Kalman.cpp | 2 +- src/TMS_Track.cpp | 18 ++++++++++++++++++ src/TMS_Track.h | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config/TMS_Default_Config.toml b/config/TMS_Default_Config.toml index a24c7d1..a21b0cd 100644 --- a/config/TMS_Default_Config.toml +++ b/config/TMS_Default_Config.toml @@ -81,7 +81,7 @@ # Y difference for expectation of reconstruction from UV and from X hit [mm] YDifference = 3000.0 # Distance from start to calculate track direction for [Number of planes]. Track matching done in plane pairs -> do not set to 1 - DirectionDistance = 14 + DirectionDistance = 10 [Recon.AStar] #CostMetric = "Manhattan" diff --git a/src/TMS_Kalman.cpp b/src/TMS_Kalman.cpp index 005d3f0..94b457d 100644 --- a/src/TMS_Kalman.cpp +++ b/src/TMS_Kalman.cpp @@ -126,7 +126,7 @@ void TMS_Kalman::RunKalman() { //std::cout << "filter end pos : " << KalmanNodes.at(1).CurrentState.x << ", " << KalmanNodes.at(1).CurrentState.y << ", " << KalmanNodes.at(1).CurrentState.z << std::endl; SetEndPosition(KalmanNodes.at(1).CurrentState.x, KalmanNodes.at(1).CurrentState.y, KalmanNodes.at(1).CurrentState.z); - //std::cout << "filter start dir: " << KalmanNodes.back().CurrentState.dxdz << ", " << KalmanNodes.back().CurrentState.dydz << std::endl; + std::cout << "filter start dir: " << KalmanNodes.back().CurrentState.dxdz << ", " << KalmanNodes.back().CurrentState.dydz << std::endl; SetStartDirection(KalmanNodes.back().CurrentState.dxdz, KalmanNodes.back().CurrentState.dydz); //std::cout << "filter end dir: " << KalmanNodes.at(1).CurrentState.dxdz << ", " << KalmanNodes.at(1).CurrentState.dydz << std::endl; SetEndDirection(KalmanNodes.at(1).CurrentState.dxdz, KalmanNodes.at(1).CurrentState.dydz); diff --git a/src/TMS_Track.cpp b/src/TMS_Track.cpp index b445d92..c8aae4b 100644 --- a/src/TMS_Track.cpp +++ b/src/TMS_Track.cpp @@ -4,3 +4,21 @@ void TMS_Track::Print() { //0x90; // TODO: add a function here }; + +// Set the start direction of the track object, normalised so magnitude == 1 +void TMS_Track::SetStartDirection(double ax, double ay, double az) { + double mag = ax*ax + ay*ay + az*az; + + Start[0] = ax/mag; + Start[1] = ay/mag; + Start[2] = az/mag; +}; + +// Set the end direction of the track object, normalised so magnitude == 1 +void TMS_Track::SetEndDirection(double ax, double ay, double az) { + double mag = ax*ax + ay*ay + az*az; + + End[0] = ax/mag; + End[1] = ay/mag; + End[2] = az/mag; +}; diff --git a/src/TMS_Track.h b/src/TMS_Track.h index af5d01a..580fa34 100644 --- a/src/TMS_Track.h +++ b/src/TMS_Track.h @@ -40,8 +40,8 @@ class TMS_Track { void SetMomentum (double val) {Momentum = val;}; // Set direction unit vectors from only x and y slope - void SetStartDirection(double ax, double ay, double az) {StartDirection[0]=ax; StartDirection[1]=ay; StartDirection[2]=az;}; - void SetEndDirection (double ax, double ay, double az) {EndDirection[0]=ax; EndDirection[1]=ay; EndDirection[2]=az;}; + void SetStartDirection(double ax, double ay, double az);// {StartDirection[0]=ax; StartDirection[1]=ay; StartDirection[2]=az;}; + void SetEndDirection (double ax, double ay, double az);// {EndDirection[0]=ax; EndDirection[1]=ay; EndDirection[2]=az;}; // Set position unit vectors void SetStartPosition(double ax, double ay, double az) {Start[0]=ax; Start[1]=ay; Start[2]=az;}; From 88fa84aee03915f90c2c10db7f81644d7e7e78ab Mon Sep 17 00:00:00 2001 From: Asa Nehm Date: Tue, 22 Oct 2024 11:10:53 -0500 Subject: [PATCH 4/4] Kalman filter fixes for StartDirection --- config/TMS_Default_Config.toml | 4 ++-- src/TMS_Kalman.cpp | 2 +- src/TMS_Reco.cpp | 2 +- src/TMS_Track.cpp | 16 ++++++++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/config/TMS_Default_Config.toml b/config/TMS_Default_Config.toml index a21b0cd..907b929 100644 --- a/config/TMS_Default_Config.toml +++ b/config/TMS_Default_Config.toml @@ -81,7 +81,7 @@ # Y difference for expectation of reconstruction from UV and from X hit [mm] YDifference = 3000.0 # Distance from start to calculate track direction for [Number of planes]. Track matching done in plane pairs -> do not set to 1 - DirectionDistance = 10 + DirectionDistance = 14 [Recon.AStar] #CostMetric = "Manhattan" @@ -91,7 +91,7 @@ IsGreedy = false [Recon.Kalman] - Run = true # Whether we run the Kalman filter or not + Run = true #false # Whether we run the Kalman filter or not [Recon.Stopping] nLastHits = 5 # The number of hits at the end of track to look at for stopping diff --git a/src/TMS_Kalman.cpp b/src/TMS_Kalman.cpp index 60735c9..fe7f8e4 100644 --- a/src/TMS_Kalman.cpp +++ b/src/TMS_Kalman.cpp @@ -126,7 +126,7 @@ void TMS_Kalman::RunKalman() { //std::cout << "filter end pos : " << KalmanNodes.at(1).CurrentState.x << ", " << KalmanNodes.at(1).CurrentState.y << ", " << KalmanNodes.at(1).CurrentState.z << std::endl; SetEndPosition(KalmanNodes.at(1).CurrentState.x, KalmanNodes.at(1).CurrentState.y, KalmanNodes.at(1).CurrentState.z); - std::cout << "filter start dir: " << KalmanNodes.back().CurrentState.dxdz << ", " << KalmanNodes.back().CurrentState.dydz << std::endl; + //std::cout << "filter start dir: " << KalmanNodes.back().CurrentState.dxdz << ", " << KalmanNodes.back().CurrentState.dydz << std::endl; SetStartDirection(KalmanNodes.back().CurrentState.dxdz, KalmanNodes.back().CurrentState.dydz); //std::cout << "filter end dir: " << KalmanNodes.at(1).CurrentState.dxdz << ", " << KalmanNodes.at(1).CurrentState.dydz << std::endl; SetEndDirection(KalmanNodes.at(1).CurrentState.dxdz, KalmanNodes.at(1).CurrentState.dydz); diff --git a/src/TMS_Reco.cpp b/src/TMS_Reco.cpp index b22a3cf..867cb73 100644 --- a/src/TMS_Reco.cpp +++ b/src/TMS_Reco.cpp @@ -1676,7 +1676,7 @@ std::vector TMS_TrackFinder::TrackMatching3D() { std::cout << "Start: " << aTrack.Start[0] << " | " << aTrack.Start[1] << " | " << aTrack.Start[2] << std::endl; std::cout << "End: " << aTrack.End[0] << " | " << aTrack.End[1] << " | " << aTrack.End[2] << std::endl; std::cout << "Added Direction: " << aTrack.StartDirection[0] << " | " << aTrack.StartDirection[1] << " | " << aTrack.StartDirection[2] << std::endl; -#endif +#endif returned.push_back(aTrack); } diff --git a/src/TMS_Track.cpp b/src/TMS_Track.cpp index c8aae4b..f72a564 100644 --- a/src/TMS_Track.cpp +++ b/src/TMS_Track.cpp @@ -7,18 +7,18 @@ void TMS_Track::Print() // Set the start direction of the track object, normalised so magnitude == 1 void TMS_Track::SetStartDirection(double ax, double ay, double az) { - double mag = ax*ax + ay*ay + az*az; + double mag = sqrt(ax*ax + ay*ay + az*az); - Start[0] = ax/mag; - Start[1] = ay/mag; - Start[2] = az/mag; + StartDirection[0] = ax/mag; + StartDirection[1] = ay/mag; + StartDirection[2] = az/mag; }; // Set the end direction of the track object, normalised so magnitude == 1 void TMS_Track::SetEndDirection(double ax, double ay, double az) { - double mag = ax*ax + ay*ay + az*az; + double mag = sqrt(ax*ax + ay*ay + az*az); - End[0] = ax/mag; - End[1] = ay/mag; - End[2] = az/mag; + EndDirection[0] = ax/mag; + EndDirection[1] = ay/mag; + EndDirection[2] = az/mag; };