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

Fwd Track matching to FCS clusters #398

Closed
wants to merge 15 commits into from

Conversation

jdbrice
Copy link
Contributor

@jdbrice jdbrice commented Sep 13, 2022

Akio's Fwd track match maker for FCS clusters

Depends on
#396
and
#397

@akioogawa
Copy link
Contributor

akioogawa commented Sep 14, 2022

I think StFwdTrack and StFwdTrackCollection to StEvent should be in asap (396 and 397). But don't we need a formal code review for the new StFwdTrackMaker & StFcsTrackMatchMaker? Or are we doing the code review at this PR right here now? Also StFcsTrackMatchMaker is sort of work in progress and I have not yet "cleaned up" for PR, thinking PR for it will come after all forward tracking code merged to STAR main git... I'll have closer look and will clean it up as needed here in the PR I guess.

@plexoos
Copy link
Member

plexoos commented Sep 14, 2022

But don't we need a formal code review for the new StFwdTrackMaker & StFcsTrackMatchMaker?

StFwdTrackMaker was initially reviewed more than two years ago. You can see the package under StRoot/

Or are we doing the code review at this PR right here now? Also StFcsTrackMatchMaker is sort of work in progress and I have not yet "cleaned up" for PR, thinking PR for it will come after all forward tracking code merged to STAR main git... I'll have closer look and will clean it up as needed here in the PR I guess.

It can be reviewed in this PR if that is preferred. If you have someone in mind who you would like to see as a reviewer, the request can be done via the PR page. I'd also recommend to add the respective change in .github/CODEOWNERS directly on this PR branch (it would make it somewhat more formal). If there are no volunteers I can review but the first look reveals that the code needs more work indeed, the maker leaks memory like a sieve. I'd suggest to mark this PR as draft for now.

@jdbrice
Copy link
Contributor Author

jdbrice commented Sep 15, 2022

Right, I was expecting that this PR would initiate the official review (maybe now or once #396 and #397 are merged)
I will provide reviewer suggestions asap.
@plexoos do we have a list of possible reviewers. Maybe the code owners file is a good list of acceptable people?

@plexoos
Copy link
Member

plexoos commented Sep 15, 2022

Maybe the code owners file is a good list of acceptable people?

Yes, of course. But don't hesitate to invite new members from the collaboration too (I thought you had a helper student/postdoc interested in the forward analysis). From the NPPS side I think Victor @perevbnlgov is back, in case you need a pair of experienced eyes

@starsdong
Copy link
Member

Yes, we should try to get 2-3 reviewers to proceed with the official review for this new maker. Will follow on this asap. Thanks

@starsdong
Copy link
Member

Added Zilong Chang as a reviewer for the new maker.

@starsdong
Copy link
Member

Zilong and Victor are invited to review the new StFcsTrackMatchMaker in this PR.
Zilong, Victor, thank you for agreeing to help on this. Your timely comments / approvals to this PR would be much appreciated. Thanks

@akioogawa
Copy link
Contributor

akioogawa commented Sep 21, 2022

.github/CODEOWNERS has @fisyak who does not exist??? I guess this is nothing to do with line I've added...

@plexoos
Copy link
Member

plexoos commented Sep 21, 2022

.github/CODEOWNERS has @fisyak who does not exist???

For some reason he does not want to join

Screen Shot 2022-09-21 at 9 56 24 AM

@perevbnlgov
Copy link
Contributor

I do not know how speed is important there. If it is important then it could
be optimized. In proposed code:

  StThreeVectorD xyz=mFcsDb->getStarXYZfromColumnRow(det,clu->x(),clu->y());
  double dx = xyz.x() - proj.x();
  double dy = xyz.y() - proj.y();
  double dr = sqrt(dx*dx + dy*dy);

//I removed debug here
if(dr<mMaxDistance[ehp]){
if(ehp==0){trk->addEcalCluster(clu);}
if(ehp==1){trk->addHcalCluster(clu);}
clu->addTrack(trk);
nMatch[ehp]++;
}
But the following will be faster because for the wrong case dx or dy is already too big

  double maxDr = mMaxDistance[ehp])
  double dx = fabs(xyz.x() - proj.x()); if (dx)> maxDr) break;
  double dy = fabs(xyz.y() - proj.y()); if (dy > maxDr) break;
  double dr = sqrt(dx*dx + dy*dy);     if (dr > maxDr) break;

  if(ehp==0){trk->addEcalCluster(clu);} else {trk->addHcalCluster(clu);}
  clu->addTrack(trk);
  nMatch[ehp]++;

@klendathu2k
Copy link
Contributor

Looking at this code I see a dependence on genfit objects which should not be stored in StEvent. This issues has already been noted in PR#397:
#397 (comment)


//North or south from track
int ns=0;
if(trk->mProjections[0].XYZ.x()>0.0) ns=1;
Copy link
Contributor

Choose a reason for hiding this comment

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

mProjections should not be public on StFwdTrack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is wrong in this case by making it public on StFwdTrack?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe our coding standards require member variables to not be publicly accessible.

Copy link
Member

Choose a reason for hiding this comment

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

The coding guidelines suggest to make data members private except in structs https://star-bnl.github.io/star-coding-guidelines/codingguide.xml#Access_Control
It also looks like Akio has fixed this in the followup commit. However, I don't see where the StFwdTrack::mProjections are being set in the submitted code. There appears to be no setter.


class StFcsCluster;

struct StFwdTrackProjection {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a class, rather than a struct, and should properly protect its data. Also, should follow STAR naming conventions. "cov" --> mCov. XYZ --> mXyz.

StPtrVecFwdTrack& tracks();
const StPtrVecFwdTrack& tracks() const;
void addTrack(StFwdTrack* p);
void sortTrackByPT();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to have sortTrackByPT() defined on StFcsCluster? If you need the tracks sorted in some order,
just sort them... you already have the reference to the track vector...
void inSomeAnalysis() {
auto& tracks = mCluster->tracks();
std::sort(tracks.begin(), tracks.end(), [](StFwdTrack* a, StFwdTrack* b) {
return b->momentum().perp() < a->momentum().perp();
});
}

}

void StFcsCluster::sortTrackByPT() {
std::sort(mTracks.begin(), mTracks.end(), [](StFwdTrack* a, StFwdTrack* b) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::sort(mTracks.begin(), mTracks.end(), [](StFwdTrack* a, StFwdTrack* b) {
std::sort(mTracks.begin(), mTracks.end(), [](const StFwdTrack* a, const StFwdTrack* b) {

Copy link
Member

Choose a reason for hiding this comment

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

Add const qualifier to the compare function

@akioogawa
Copy link
Contributor

akioogawa commented Sep 23, 2022

(On dr calc in StFcsTrackMatchMaker.cxx) I do not know how speed is important there. If it is important then it could be optimized.

Speed is important. But speed gain from the suggested code seems minimal, and modified code seems bad to me. But I need dR for debug and histograms... Please suggest other solution if you agree with me that the modified code looks bad.

StFcsTrackMatchMaker::Finish(){
if(mEpdgeo) delete mEpdgeo;
causes
warning: deleting object of polymorphic class type 'StEpdGeom' which
has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
I'm not sure what to do with this...

I think other comments are implemented, besides having genFit track, which I leave it to Daniel and S&C meeting discussions.

@plexoos
Copy link
Member

plexoos commented Sep 23, 2022

StFcsTrackMatchMaker::Finish(){
if(mEpdgeo) delete mEpdgeo;
causes
warning: deleting object of polymorphic class type 'StEpdGeom' which
has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
I'm not sure what to do with this...

How do you use the private member mEpdgeo in your code? All I can see is that you allocate an object and then delete it.

@perevbnlgov
Copy link
Contributor

perevbnlgov commented Sep 23, 2022 via email

@akioogawa
Copy link
Contributor

Speed is important. But speed gain from the suggested code seems minimal,
... and modified code seems bad to me.
Are you kidding?

No. But it is NOT your proposed code which looks bad to me. It is my modified code which looks bad to me.

If my code is bad for you

No. Your code looks ok without debugging lines. It is my code with debug & histogram filling which looks bad.

Please have a look at new commit and tell me if it looks ok for you.

@akioogawa
Copy link
Contributor

akioogawa commented Sep 23, 2022

Which is better?

  if(Debug()){
    double dx = xyz.x() - proj[ehp]->x();
    double dy = xyz.y() - proj[ehp]->y();
    double dr = sqrt(dx*dx + dy*dy);
    if(Debug()) LOG_INFO << Form("EHP=%1d dx = %6.2f - %6.2f  = %6.2f dy = %6.2f - %6.2f  = %6.2f dr=%6.2f",
				 ehp,xyz.x(),proj[ehp]->x(),dx,xyz.y(),proj[ehp]->y(),dy,dr) << endm;
  }
  if(mFile){
    double dx = xyz.x() - proj[ehp]->x();
    double dy = xyz.y() - proj[ehp]->y();
    double dr = sqrt(dx*dx + dy*dy);	    
    if(fabs(dy)<mMaxDistance[ehp]) mHdx[ehp]->Fill(dx);
    if(fabs(dx)<mMaxDistance[ehp]) mHdy[ehp]->Fill(dy);
    mHdr[ehp]->Fill(dr);
  }
  double dx = xyz.x() - proj[ehp]->x();  if(dx > mMaxDistance[ehp]) continue;
  double dy = xyz.y() - proj[ehp]->y();  if(dy > mMaxDistance[ehp]) continue;
  double dr = sqrt(dx*dx + dy*dy); if(dr > mMaxDistance[ehp]) continue;
  if(ehp==0){trk->addEcalCluster(clu);}
  else      {trk->addHcalCluster(clu);}

Or

      double dx = xyz.x() - proj[ehp]->x();
      double dy=0,dr=mMaxDistance[ehp];
      if(Debug() || mFile || dx < mMaxDistance[ehp]){
        dy = xyz.y() - proj[ehp]->y();
        if(Debug() || mFile || dy < mMaxDistance[ehp]){
            dr= sqrt(dx*dx + dy*dy);
        }
      }
      if(Debug()){
        if(Debug()) LOG_INFO << Form("EHP=%1d dx = %6.2f - %6.2f  = %6.2f dy = %6.2f - %6.2f  = %6.2f dr=%6.2f",
                                     ehp,xyz.x(),proj[ehp]->x(),dx,xyz.y(),proj[ehp]->y(),dy,dr) << endm;
      }
      if(mFile){
        if(fabs(dy)<mMaxDistance[ehp]) mHdx[ehp]->Fill(dx);
        if(fabs(dx)<mMaxDistance[ehp]) mHdy[ehp]->Fill(dy);
        mHdr[ehp]->Fill(dr);
      }
      if(dr < mMaxDistance[ehp]){
        if(ehp==0){trk->addEcalCluster(clu);}
        else      {trk->addHcalCluster(clu);}
     }

Former is commit this morning. Later Is still in my private file...

Comment on lines 152 to 153
double dx = xyz.x() - proj[ehp]->x(); if(dx > mMaxDistance[ehp]) continue;
double dy = xyz.y() - proj[ehp]->y(); if(dy > mMaxDistance[ehp]) continue;
Copy link
Member

Choose a reason for hiding this comment

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

Do we need these two lines? The third line "dr" cut will automatically satisfy these cuts. If so, do we need to calculate dx = TMath::Abs(dx) and dy = TMath::Abs(dy) before comparing to the max distance?

@perevbnlgov
Copy link
Contributor

perevbnlgov commented Oct 21, 2022 via email

@plexoos plexoos requested a review from veprbl as a code owner January 16, 2023 01:41
@jdbrice
Copy link
Contributor Author

jdbrice commented Feb 4, 2023

OK. Previously this branch depended #397 which used the StFwdTrack addition to StEvent with dependency on GenFit.
Now the branch has been overwritten with a new history, depending on the new #492 which adds StFwdTrack to StEvent without any external dependencies.

The changes to THIS code (StFcsTrackMatchMaker) are very minimal - only a few variable name changes and the use of a helper function to access track projections instead of accessing them directly from the underlying vector.

So based on the past review, this should be ready to merge as soon as its parent branch is merged in.

@plexoos plexoos mentioned this pull request Aug 23, 2023
plexoos pushed a commit that referenced this pull request Aug 23, 2023
Squashed #398 and rebased onto main. The resolution of conflicts leaned
towards the code present in the main branch.
No significant changes left so, I think #398 can be closed
plexoos added a commit that referenced this pull request Aug 23, 2023
The resolution of conflicts leaned towards the code present in the main
branch. No significant changes left so, I think #398 can be closed
@jdbrice
Copy link
Contributor Author

jdbrice commented Sep 27, 2023

Merged in as part of #492

@jdbrice jdbrice closed this Sep 27, 2023
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.

None yet

7 participants