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

New FWD tracking mode based on FST-track finding #571

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

jdbrice
Copy link
Contributor

@jdbrice jdbrice commented Jul 25, 2023

These updates provide a new FWD tracking mode in which the track finding is one with FST information.
Tracks are then fit to valid Seeds and then (optionally) any FTT hits are added to the track if found along the trajectory.

This mode is needed for any analysis of real data at this point. That would include fast offline for ongoing data taking.

@jdbrice jdbrice requested a review from klendathu2k as a code owner July 25, 2023 19:21
@jdbrice
Copy link
Contributor Author

jdbrice commented Jul 25, 2023

Note, this PR includes the changes from PR #569 but the only changes relevant here are those in StRoot/StFwdTrackMaker and StRoot/StFwdUtils/

@jdbrice
Copy link
Contributor Author

jdbrice commented Jul 25, 2023

Also the CI jobs seem to be failing on code unrelated to my changes (things in StEvent)

@plexoos
Copy link
Member

plexoos commented Jul 25, 2023

These errors should be fixed first:

2023-07-25T19:47:18.5349686Z #10 1453.7 g++ -m64 -fPIC -pipe -Wall -Woverloaded-virtual -std=c++0x -Wno-long-long -pthread -Wno-deprecated-declarations -Werror -O2 -g -falign-loops -falign-jumps -falign-functions -Dsl79_gcc485 -D__ROOT__ -DNEW_DAQ_READER -I. -IStRoot -I.sl79_gcc485/include -I/opt/software/linux-scientific7-x86_64/gcc-4.8.5/root-5.34.38-l3v6vso6qgojm4l2ctwjojs6trbt4hpn/include -c .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx -o .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.o
2023-07-25T19:47:19.4377677Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx: In member function 'void StFwdAnalysisMaker::ProcessFwdTracks()':
2023-07-25T19:47:19.4378676Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:191:54: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
2023-07-25T19:47:19.4379329Z #10 1454.6          for( int i = 0; i < fcs->clusters(iDet).size(); i++){
2023-07-25T19:47:19.4379659Z #10 1454.6                                                       ^
2023-07-25T19:47:19.4380367Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:245:68: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
2023-07-25T19:47:19.4381434Z #10 1454.6          for ( int iEcal = 0; iEcal < fwdTrack->ecalClusters().size(); iEcal++ ){
2023-07-25T19:47:19.4381970Z #10 1454.6                                                                     ^
2023-07-25T19:47:19.4382676Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:263:62: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
2023-07-25T19:47:19.4383319Z #10 1454.6                  for( int i = 0; i < fcs->clusters(iDet).size(); i++){
2023-07-25T19:47:19.4383665Z #10 1454.6                                                               ^
2023-07-25T19:47:19.4384345Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:301:62: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
2023-07-25T19:47:19.4384994Z #10 1454.6                  for( int i = 0; i < fcs->clusters(iDet).size(); i++){
2023-07-25T19:47:19.4385329Z #10 1454.6                                                               ^
2023-07-25T19:47:19.4385933Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:235:15: error: unused variable 'c' [-Werror=unused-variable]
2023-07-25T19:47:19.4386330Z #10 1454.6          float c[9];
2023-07-25T19:47:19.4386574Z #10 1454.6                ^
2023-07-25T19:47:19.4387294Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx: In member function 'void StFwdAnalysisMaker::ProcessFwdMuTracks()':
2023-07-25T19:47:19.4388295Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:413:55: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
2023-07-25T19:47:19.4388939Z #10 1454.6              for( int i = 0; i < fcs->numberOfClusters(); i++){
2023-07-25T19:47:19.4389281Z #10 1454.6                                                        ^
2023-07-25T19:47:19.4389984Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:437:70: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
2023-07-25T19:47:19.4390652Z #10 1454.6          for ( size_t i = 0; i < muFwdTrack->mEcalClusters.GetEntries(); i++ ){
2023-07-25T19:47:19.4391042Z #10 1454.6                                                                       ^
2023-07-25T19:47:19.4391851Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:455:70: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
2023-07-25T19:47:19.4392547Z #10 1454.6          for ( size_t i = 0; i < muFwdTrack->mHcalClusters.GetEntries(); i++ ){
2023-07-25T19:47:19.4392918Z #10 1454.6                                                                       ^
2023-07-25T19:47:19.4393526Z #10 1454.6 .sl79_gcc485/OBJ/StRoot/StFwdUtils/StFwdAnalysisMaker.cxx:402:15: error: unused variable 'c' [-Werror=unused-variable]
2023-07-25T19:47:19.4394034Z #10 1454.6          float c[9];
2023-07-25T19:47:19.4394264Z #10 1454.6                ^

Copy link
Contributor

@klendathu2k klendathu2k left a comment

Choose a reason for hiding this comment

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

Few initial comments made. Will review in more detail tomorrow.

StRoot/StEvent/StFttCluster.h Outdated Show resolved Hide resolved
StRoot/StEvent/StFttPoint.h Outdated Show resolved Hide resolved
StRoot/StEvent/StFwdTrack.h Outdated Show resolved Hide resolved
StRoot/StFttClusterMaker/StFttClusterMaker.cxx Outdated Show resolved Hide resolved
StRoot/StFttClusterMaker/StFttClusterMaker.h Outdated Show resolved Hide resolved
StRoot/StFttClusterMaker/StFttClusterMaker.h Outdated Show resolved Hide resolved
@jdbrice
Copy link
Contributor Author

jdbrice commented Jul 26, 2023

@klendathu2k I will remove everything StFtt related from this PR. Everything you suggest is valid - but it I've addressed it in PR #569 instead of here

@jdbrice
Copy link
Contributor Author

jdbrice commented Jul 26, 2023

Well, I thought that PR #538 (Add Fwd Tracks to MuDst) was already merged. It was submitted in May but has not received any review. So I removed MuDST from the PR also (done in ae1dae2)

@plexoos
Copy link
Member

plexoos commented Jul 26, 2023

Well, I thought that PR #538 (Add Fwd Tracks to MuDst) was already merged. It was submitted in May but has not received any review. So I removed MuDST from the PR also (done in ae1dae2)

I reviewed #538 just now. It looks good to me. I suggest we merge it before this one

@jdbrice
Copy link
Contributor Author

jdbrice commented Dec 18, 2023

I finally updated this PR to include only the needed changes for this feature (FST based tracking)
Review can go ahead now

@jdbrice
Copy link
Contributor Author

jdbrice commented Dec 19, 2023

commit e65362f made changes to verify everything works for the ideal simulation cases:

  • FTT seed finding + FST refit
  • FST seed finding + FTT refit

I added:
StRoot/StFwdTrackMaker/macro/sim/ideal_sim.C
StRoot/StFwdTrackMaker/macro/sim/gen

to make running the code in this way easy. It can be tested with:

cons
ln -s StRoot/StFwdTrackMaker/macro/sim/ .
./sim/gen 100
./sim/ideal_sim.C 100

@jdbrice
Copy link
Contributor Author

jdbrice commented Apr 18, 2024

OK with 99752c4
I think I have brought in all of the most important updates:

  • Many changes throughout the StFwdTrackMaker package to improve memory management and remove old code / ensure debug and code meant for simulation only runs when requested.
  • StEvent and StMuDst have minor updates to the St(Mu)FwdTrack classes to allow MC association information
  • Updates to macros for standard use of the fwd tracking on simulation files, mudst etc.

Copy link
Contributor

@genevb genevb left a comment

Choose a reason for hiding this comment

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

Just a few minor observations. I didn't dig through all the sim and Tracker changes, so I can't comment on those.

@@ -19,6 +19,9 @@ void StMuFwdTrack::set( StFwdTrack * evTrack) {
mCharge = evTrack->charge();
mPrimaryMomentum = TVector3( evTrack->momentum().x(), evTrack->momentum().y(), evTrack->momentum().z() );

mIdTruth = evTrack->idTruth();
mQATruth = evTrack->qaTruth();

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can tell, you rely on the default behavior of C++ to initialize the value of StEvent/StFwdTrack.cxx::mIdTruth to zero (for all real tracks), as it isn't explicitly initialized to have a default value neither there nor here. Is this the desired approach?

// needed since I use the StMuTrack
gSystem->Load("StarClassLibrary");
gSystem->Load("StStrangeMuDstMaker");
gSystem->Load("StMuDSTMaker");
Copy link
Contributor

Choose a reason for hiding this comment

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

loadSharedLibraries() already loads StarClassLibrary, StStrangeMuDstMaker, StMuDSTMaker, so not needed here. Not sure if I missed others, but this isn't critical.

cout << "LL1" << endl;
gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
loadSharedLibraries();
cout << "LL2" << endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

These three LL0/1/2 cout lines can probably be dropped off now?

@@ -121,6 +121,8 @@ class StMuFwdTrack : public TObject {

// Number of points used in the track seed step
short numberOfSeedPoints() const;
UShort_t idTruth() const { return mIdTruth; }
UShort_t qaTruth() const { return mQATruth; }


void setPrimaryMomentum( TVector3 mom ) { mPrimaryMomentum = mom; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest switching to StThreeVector for speed. TVector3 has an additional overhead b/c it inherits from TObject. Which means that every instance of every vector you create will be registered in a global ROOT map, and subsequently destroyed when you call the destructor.

Looking at the MuDST codes... I see that we are using both TVector3 and StThreeVector (with x=float or double) to store vector quantities.... so consider this a soft suggestion.

@@ -769,11 +828,12 @@ class TrackFitter {

// get the seed info from our hits
TVector3 seedMom, seedPos;
Copy link
Contributor

@klendathu2k klendathu2k Apr 18, 2024

Choose a reason for hiding this comment

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

[very small optimization...]

Since you are initializing these below... you can make these static variables and save the overhead of registering them with ROOT every time the ctor is called.

Copy link
Contributor

@klendathu2k klendathu2k left a comment

Choose a reason for hiding this comment

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

Just took a quick look, and commented on some possible optimizations. TVector3 is used several places and, where ever possible, you should avoid calling the constructor. TVector3 registers itself with ROOT, which introduces an overhead. (We ran into this slowing down Sti O(10%) in the past as I recall). Otherwise I think this looks good. I'll take a closer look tomorrow.

Comment on lines 815 to 818
// we use d+4 so that both FTT and FST start at 4
FwdHit *hit = new FwdHit(count++, x0, y0, vZ, d+4, 0, hitCov3, nullptr);
// Add the hit to the hit map
hitMap[d+4].push_back(hit);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is the case where you want to be a bit more explicit with the code. You may know that you use smart pointers but it does look scary to a casual reviewer who is not aware of the internals.

Suggested change
// we use d+4 so that both FTT and FST start at 4
FwdHit *hit = new FwdHit(count++, x0, y0, vZ, d+4, 0, hitCov3, nullptr);
// Add the hit to the hit map
hitMap[d+4].push_back(hit);
auto hit = std::make_unique<FwdHit>(count++, hitInfo.x, hitInfo.y, hitInfo.z, hitInfo.d + START_INDEX_FOR_FST, 0, hitCov3, nullptr);
hitMap[d + START_INDEX_FOR_FST].push_back(std::move(hit));

And BTW, why not create the hits on the stack?

Comment on lines 802 to 806
const float dz0 = fabs( vZ - 151.75 );
const float dz1 = fabs( vZ - 165.248 );
const float dz2 = fabs( vZ - 178.781 );

int d = 0 * ( dz0 < 1.0 ) + 1 * ( dz1 < 1.0 ) + 2 * ( dz2 < 1.0 );
Copy link
Member

Choose a reason for hiding this comment

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

Magic numbers... It took me a while to understand the meaning of 1.0 which is probably a pretty arbitrary value.

@@ -37,13 +37,15 @@ class FwdDataSource {
for ( auto kv : mFttHits ){
for ( auto h : kv.second ){
delete h;
h = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Oh, actually you are not using smart pointers for KiTrack hits... If you did

using HitMap_t = std::map<int, std::vector<std::unique_ptr<KiTrack::IHit>>>;

it would simplify the cleanup code

        for (auto& kv : mFttHits) {
            kv.second.clear();
        }
        for (auto& kv : mFstHits) {
            kv.second.clear();
        }
        mFttHits.clear();
        mFstHits.clear();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hits are now created on the stack and cleared each event by the StFwdTrackMaker

@fgeurts fgeurts requested review from plexoos, klendathu2k and genevb May 22, 2024 14:56
mForwardTracker->initialize( geoCache, mGenHistograms );
mForwardTracker->initialize( mGeoCache, mGenHistograms );

// geometry should be available from here (mForwardTracker will initialize cache if needed)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm slightly concerned about pulling the z-locations from the geometry and having fallback values hardcoded here.

Is there at least logging in place to keep track of when / if we fall back to the default?

Copy link
Contributor

@genevb genevb left a comment

Choose a reason for hiding this comment

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

I posted 3 minor comments on this earlier. May not be critical to fix, but that's it for my part of the review, and a quick note that they'll be addressed now/later/not at all would be good.

@plexoos
Copy link
Member

plexoos commented Jun 26, 2024

Thank you, Daniel, for addressing the comments! Everything looks good as far as I can tell.

As a last request we discussed, could you point me to a recent data file with raw FST data from this run? I would like to extend our CI tests at https://github.com/star-bnl/star-sw/blob/main/tests/joblist.json#L1126, which already include data from 2023.

- Improve memory management of FwdHits
- Add FST and FTT detection methods to FwdHit class and update FwdGeomUtils
- cleanup track fitter logic
- Add additional track seed modes
- use enums where possible for clearer intentions
- remove histogram and ttree output from FwdTrackMaker and TrackFitter
- Tests against data and simulation
@jdbrice
Copy link
Contributor Author

jdbrice commented Jul 5, 2024

@plexoos @iraklic Please let me know if anything more is needed before we can merge this PR. There are others that depend on this. From what I can tell the 2 tests that failed were due to network issues - @plexoos maybe knows better.

@iraklic
Copy link
Member

iraklic commented Jul 9, 2024

@plexoos @iraklic Please let me know if anything more is needed before we can merge this PR. There are others that depend on this. From what I can tell the 2 tests that failed were due to network issues - @plexoos maybe knows better.

Sorry for not answering so long. I am not ignoring your PR. I just have been super busy and this seems to be a substantial one, with the discussion that I have not really followed. I this it is better if I defer this to others, but I will go over this once I am back to the office if it is not done till then.

@jdbrice
Copy link
Contributor Author

jdbrice commented Jul 18, 2024

@fgeurts @plexoos Please let me know if I need to do anything more. The recent commits were mostly clean-up (albeit a lot because I removed almost all debug histograms/ttree output). I am not sure why test 125 fails, I wonder if it is a separate issue? Either way I am looking into it.

@plexoos
Copy link
Member

plexoos commented Jul 19, 2024

The last time all checks passed was with this commit: @jdbrice
Use FST z locations from geom to identify hit plane index
0e9b674

However, the next commit failed: @jdbrice
Cleanup of the StFwdTrackMaker code
0241f63

Let's try to revert it to see if it really introduced a bug.

@plexoos
Copy link
Member

plexoos commented Jul 19, 2024

The test job 125 completed successfully after reverting the changes in @jdbrice's commit.

Use FST z locations from geom to identify hit plane index
0e9b674

This is the only test that uses the FwdTrack option:

bfc.C(200, "pp2022,StiCA,BEmcChkStat,epdhit,FwdTrack", "/star/rcf/test/daq/2023/072/23072022//st_physics_23072022_raw_4000001.daq")

From this, I conclude that something in that commit causes the test to fail.

@jdbrice
Copy link
Contributor Author

jdbrice commented Jul 21, 2024

Thank you @plexoos - I will investigate and try to resolve.

@jdbrice jdbrice added the FWD Forward Upgrade label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FWD Forward Upgrade
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants