Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/3D Kalman Filter #122

Closed
wants to merge 5 commits into from
Closed

Feature/3D Kalman Filter #122

wants to merge 5 commits into from

Conversation

LiamOS
Copy link
Member

@LiamOS LiamOS commented Jul 11, 2024

Have merged current main into this branch just now.

Current behaviour:

  • Assumes p=0 at track end, propagates backwards only
  • All reconstructed positions saved in the TMS_Track obj
  • Returns single value for momentum (need to check this is reasonable)
  • Can be switched on in config
  • Seems to just keep running if something terrible happens (good thing?)

Please give a scan over the Reco and TreeWriter files to make sure I haven't destroyed anything unintentionally.

@LiamOS LiamOS requested review from jdkio and AsaNehm July 11, 2024 13:18
@LiamOS LiamOS self-assigned this Jul 11, 2024
@LiamOS LiamOS mentioned this pull request Jul 11, 2024
7 tasks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusting you on this one

src/TMS_Kalman.h Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusting you on this one

Copy link
Contributor

@AsaNehm AsaNehm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my side

@jdkio
Copy link
Contributor

jdkio commented Jul 24, 2024

I'm testing this branch to compare with main. I ran these three tests (with a limit of 5k files):

# Nersc files
ConvertToTMSTree.exe /pnfs/dune/persistent/users/abooth/Production/MiniProdN1p2-v1r1/run-spill-build/output/MiniProdN1p2_NDLAr_1E19_RHC.spill/EDEPSIM_SPILLS/00000/MiniProdN1p2_NDLAr_1E19_RHC.spill.00049.EDEPSIM_SPILLS.root
# events on TMS and LAr
ConvertToTMSTree.exe /pnfs/dune/persistent/users/kleykamp/nd_production/2024-04-18_rhc_test/edep/RHC/00m/00/antineutrino.0_1713482441.edep.root
# Lar-only but not from nersc
ConvertToTMSTree.exe /pnfs/dune/persistent/users/kleykamp/nd_production/2024-05-13_lar_only_rhc/edep/RHC/00m/00/antineutrino.0_1715654453.edep.root

They all process in main (tagged kleykamp_2024-07-24_main_test). I tried the same with this branch (tagged kleykamp_2024-07-24_3D-Kalman-fitter_test), and it gets stuck the second one which is TMS/LAr events: /pnfs/dune/persistent/users/kleykamp/nd_production/2024-04-18_rhc_test/edep/RHC/00m/00/antineutrino.0_1713482441.edep.root
The output stops at Processing slice 1 of event number 861 / 1842. I tried gdb's backtrace to see where it gets stuck, and it's consistently inside various parts of TrackMatching3D. Eg:

0x00007ffff7b1e3b4 in TMS_TrackFinder::TrackMatching3D (this=this@entry=0x16367c0 <TMS_TrackFinder::GetFinder()::Instance>)
    at TMS_Reco.cpp:1054
1054	                  || UTracks[itU].GetZ() < 11000 || UTracks[itU].GetZ() > 20000) --itU;
(gdb) bt
#0  0x00007ffff7b1e3b4 in TMS_TrackFinder::TrackMatching3D (this=this@entry=0x16367c0 <TMS_TrackFinder::GetFinder()::Instance>)
    at TMS_Reco.cpp:1054
#1  0x00007ffff7b288d6 in TMS_TrackFinder::FindTracks (this=this@entry=0x16367c0 <TMS_TrackFinder::GetFinder()::Instance>, event=...)
    at TMS_Reco.cpp:594
#2  0x0000000000408c4d in ConvertToTMSTree (filename=..., output_filename=...) at ../src/TMS_Reco.h:192
#3  0x0000000000407bd6 in main (argc=<optimized out>, argv=<optimized out>) at ConvertToTMSTree.cpp:251

I tried changing Run = false for the kalman filter and it gets stuck in the same location. I do see some changes in that code compared to main that are unaffected by the kalman filter, so maybe it's an issue with that logic. I'd be happy to run the test again if that helps

@LiamOS
Copy link
Member Author

LiamOS commented Jul 25, 2024

@AsaNehm good chance the above issue is related to the changes you made recently

@AsaNehm
Copy link
Contributor

AsaNehm commented Jul 25, 2024

It might very well be.
@jdkio could you try whether the problem is still there if you add an if condition for all --itU and --itV for it to be above 0 (if (itV or itU > 0) --itV or --itU;) in my changed part of TMS_Reco.cpp [commits fixing matching with two hits per plane and potentially the one afterwards as well]. I had a problem with this yesterday as well and this seems to fix it for me

@jdkio
Copy link
Contributor

jdkio commented Jul 25, 2024

It might very well be. @jdkio could you try whether the problem is still there if you add an if condition for all --itU and --itV for it to be above 0 (if (itV or itU > 0) --itV or --itU;) in my changed part of TMS_Reco.cpp [commits fixing matching with two hits per plane and potentially the one afterwards as well]. I had a problem with this yesterday as well and this seems to fix it for me

I'm not sure what you mean. Would you please submit the change?

@AsaNehm
Copy link
Contributor

AsaNehm commented Jul 25, 2024

Did that. Please try it out

@jdkio
Copy link
Contributor

jdkio commented Jul 31, 2024

This works now. I was able to test all 3 files and there was no infinite loop. Test files in
/exp/dune/data/users/kleykamp/dune-tms/simple_processing_test/kleykamp_2024-07-31_3D-Kalman-fitter_test

Copy link
Contributor

@jdkio jdkio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just some minor comments about verbosity and branch names

src/TMS_Geom.h Outdated
Comment on lines 204 to 208
TVector3 vec = TVector3(x,y,z);
//if (!IsInsideNearDetectorVolume(vec))
//std::cout << "Not in a detector?? " << x << ", " << y << ", " << z << std::endl;
//return NULL;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is doing nothing

src/TMS_Geom.h Outdated
Comment on lines 218 to 221
// std::cout << "[TMS_Geom.h] Getting materials between the points:" << std::endl
// << " point1: " << point1.X() << ", "<< point1.Y() << ", "<< point1.Z() << std::endl
// << " point2: " << point2.X() << ", "<< point2.Y() << ", "<< point2.Z() << std::endl;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this

src/TMS_Reco.cpp Outdated
size_t nHits = xz_hits.size();
if (nHits < 1) continue;
KalmanFitter = TMS_Kalman(xz_hits);
std::cout << "Kalman filter start pos : " << KalmanFilter.Start[0] << ", " << KalmanFilter.Start[1] << ", " << KalmanFilter.Start[2] << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want it this verbose?

Reco_Tree->Branch("KalmanPos", RecoTrackKalmanPos, "TrackHitPos[nTracks][200][3]/F");
Reco_Tree->Branch("KalmanTruePos", RecoTrackKalmanTruePos, "TrackHitTruePos[nTracks][200][3]/F");
Reco_Tree->Branch("StartPos", RecoTrackStartPos, "StartPos[nTracks][3]/F");
Reco_Tree->Branch("StartDirection",RecoTrackStartDirection,"StartDirection[nTracks][3]/F");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, we need to be careful about changing branch names. Downstream code uses Direction for StartDirection so it'll break scripts

Reco_Tree->Branch("nHits", nHitsIn3DTrack, "nHits[nTracks]/I");
Reco_Tree->Branch("TrackHitPos", RecoTrackHitPos, "TrackHitPos[nTracks][200][3]/F");
Reco_Tree->Branch("nKalmanNodes", nKalmanNodes, "nKalmanNodes[nTracks]/I");
Reco_Tree->Branch("KalmanPos", RecoTrackKalmanPos, "TrackHitPos[nTracks][200][3]/F");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed TrackHitPos is repeated. Should it be
Reco_Tree->Branch("KalmanPos", RecoTrackKalmanPos, "KalmanPos[nTracks][200][3]/F");

@jdkio
Copy link
Contributor

jdkio commented Aug 1, 2024

Looks like tracks start with unusual hit positions. Here are all hits on a track as an example. The first hit should be close to the second hit but the first hit has x outside the detector, and y = 0.

Looping over hits for track 0
(x, y, z)=(18314, 0, 15993)
(x, y, z)=(-1349.11, -1693.37, 15913)
(x, y, z)=(-1331.81, -1699.28, 15833)
(x, y, z)=(-1266.57, -1705.3, 15753)
(x, y, z)=(-1260.28, -1711.25, 15673
Looping over hits for track 0
(x, y, z)=(18314, 0, 18153)
(x, y, z)=(601.075, -1326.34, 18073)
(x, y, z)=(619.419, -1302.9, 17993)
(x, y, z)=(626.825, -1279.26, 17913)

The code is setting x is z_tms_end and y defaults to zero for the first hit of each track

@jdkio
Copy link
Contributor

jdkio commented Aug 1, 2024

I also noticed the ends of tracks can be strange sometimes too

(x, y, z)=(1367.96, -61.3745, 13673)
(x, y, z)=(-1474.08, -778.715, 11643)
(x, y, z)=(-1474.08, -754.316, 11588)

@jdkio
Copy link
Contributor

jdkio commented Aug 28, 2024

I made this comparison between PR 122 and PR 134: comparison.pdf. It's looking at plots from Tracking_Validation.cpp for this PR and what is currently main basically. Both have their pros and cons that need to be worked out. Direction became StartDirection and so the Direction and matching angle plots are bugged

I'm still concerned about hits that aren't on the track. I think that explains why we get this behavior:
image
But I do like the y comparison:
image

@AsaNehm
Copy link
Contributor

AsaNehm commented Sep 10, 2024

Looking through the code on main there shouldn't be a problem with the shift to a PlaneByZ with coordinates instead of the plane number

@LiamOS LiamOS closed this Oct 22, 2024
@LiamOS
Copy link
Member Author

LiamOS commented Oct 22, 2024

Closing as this branch has become stale and isn't worth recovering. Not sure what happened and when, couldn't figure it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants