Skip to content

Conversation

@sungbinoh
Copy link
Contributor

@sungbinoh sungbinoh commented Oct 20, 2025

Description

Updating CAF making codes to add likelihood-based PID variables.

  • sbncode/CAFMaker/CAFMakerParams.h: a new label TrackLikePidLabel
  • sbncode/CAFMaker/FillReco.cxx/h: adding FillTrackLikePID and FillPlaneLikePID. They have almost the same shape with FillTrackChi2PID and FillPlaneChi2PID but uses Likelihood (larana link) as input and SRTrkLikePID (sbnanaobj PR link) as output.
  • sbncode/CAFMaker/CAFMaker_module.cc: adding art::FindManyP<anab::ParticleID> fmLikePID and calling FillTrackLikePID

Please note that

  • Reconstruction related fcl files should be updated for each of icaruscode and sbndcode to measure likelihood PID variables. Examples in sbndcode can be found in PR849.

  • Cafmaker fcl files should be updated in either of icaruscode and sbndcode too to assign correct fmLikePID.

  • Have you added a label? (bug/enhancement/physics etc.)

  • Have you assigned at least 1 reviewer?

  • Is this PR related to an open issue / project?

  • Does this PR affect CAF data format? If so, please assign a CAF maintainer as additional reviewer.

  • Does this PR require merging another PR in a different repository (such as sbnanobj/sbnobj etc.)? If so, please link it in the description.

Yes. PR 168 in sbnanaobj should be merged first.

  • Are you submitting this PR on behalf of someone else who made the code changes? If so, please mention them in the description.

Copy link
Member

@henrylay97 henrylay97 left a comment

Choose a reason for hiding this comment

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

Looks fine to me! Thanks @sungbinoh.

One small q.

Comment on lines 899 to 902
srlikepid.lambda_muon = 0.;
srlikepid.lambda_pion = 0.;
srlikepid.lambda_proton = 0.;
srlikepid.pid_ndof = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we change from the previous defaults here?

The object fills the defaults as -5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @henrylay97 ,
Thank you for the review!
That is a good catch. I did kind of no-brain copy of chi2pid part.
I agree that the default value should be distinguishable from the actual values.
Updating default values for lambdas to -9999. and ndof to -5!

Copy link
Member

@henrylay97 henrylay97 left a comment

Choose a reason for hiding this comment

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

Thanks Sungbin. Another comment on defaults (sorry!). Also not sure that this will run currently? Looks like we're passing a SRTrack rather than an SRTrkLikelihoodPID to the function?

srlikepid.lambda_pion = -9999.;
srlikepid.lambda_proton = -9999.;
srlikepid.pid_ndof = -5;

Copy link
Member

Choose a reason for hiding this comment

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

I would remove this completely.

The values will be set to be the defaults by the default constructor anyway so let's avoid multiple points of maintenance. (See my comment here for more thoughts SBNSoftware/sbnanaobj#168 (comment))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @henrylay97 , I've removed these lines following your comment in the SBNSoftware/sbnanaobj#168 (comment). Thank you!

Copy link
Member

@henrylay97 henrylay97 left a comment

Choose a reason for hiding this comment

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

Thanks for responding so quick. I'm happy with this now 😀

Copy link
Member

@PetrilloAtWork PetrilloAtWork left a comment

Choose a reason for hiding this comment

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

I have left some coding comments.
The changes to avoid copies are required, while the coding style ones are up to you.

caf::SRTrack& srtrack,
bool allowEmpty = false);
void FillPlaneLikePID(const anab::ParticleID &particle_id, caf::SRTrkLikelihoodPID &srlikepid);
void FillTrackLikePID(const std::vector<art::Ptr<anab::ParticleID>> particleIDs,
Copy link
Member

Choose a reason for hiding this comment

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

You forgot the reference:

Suggested change
void FillTrackLikePID(const std::vector<art::Ptr<anab::ParticleID>> particleIDs,
void FillTrackLikePID(const std::vector<art::Ptr<anab::ParticleID>>& particleIDs,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added &.

}
}

void FillTrackLikePID(const std::vector<art::Ptr<anab::ParticleID>> particleIDs,
Copy link
Member

Choose a reason for hiding this comment

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

Pass the particle ID pointer objects by reference ([CF-112]):

Suggested change
void FillTrackLikePID(const std::vector<art::Ptr<anab::ParticleID>> particleIDs,
void FillTrackLikePID(const std::vector<art::Ptr<anab::ParticleID>>& particleIDs,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added &.

Comment on lines 925 to 926
for (unsigned i = 0; i < particleIDs.size(); i++) {
const anab::ParticleID &particle_id = *particleIDs[i];
Copy link
Member

Choose a reason for hiding this comment

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

You can compact this avoiding i:

Suggested change
for (unsigned i = 0; i < particleIDs.size(); i++) {
const anab::ParticleID &particle_id = *particleIDs[i];
for (art::Ptr<anab::ParticleID> const& pidPtr: particleIDs) {
const anab::ParticleID &particle_id = *pidPtr;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to the suggested change.

// Loop over algorithm scores and extract the ones we want.
// Get the ndof from any likelihood pid algorithm

std::vector<anab::sParticleIDAlgScores> AlgScoresVec = particle_id.ParticleIDAlgScores();
Copy link
Member

Choose a reason for hiding this comment

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

Capture it by reference, avoid copies ([CF-111]):

Suggested change
std::vector<anab::sParticleIDAlgScores> AlgScoresVec = particle_id.ParticleIDAlgScores();
std::vector<anab::sParticleIDAlgScores> const& AlgScoresVec = particle_id.ParticleIDAlgScores();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to the suggested change.

Comment on lines 901 to 902
for (size_t i_algscore=0; i_algscore<AlgScoresVec.size(); i_algscore++){
anab::sParticleIDAlgScores AlgScore = AlgScoresVec.at(i_algscore);
Copy link
Member

Choose a reason for hiding this comment

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

Avoid copying the objects, and also compact the notation:

Suggested change
for (size_t i_algscore=0; i_algscore<AlgScoresVec.size(); i_algscore++){
anab::sParticleIDAlgScores AlgScore = AlgScoresVec.at(i_algscore);
for (anab::sParticleIDAlgScores const& AlgScore: AlgScoresVec){

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to the suggested change.

Comment on lines 904 to 915
if (TMath::Abs(AlgScore.fAssumedPdg) == 13) { // lambda_mu
srlikepid.lambda_muon = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
}
else if (TMath::Abs(AlgScore.fAssumedPdg) == 211) { // lambda_pi
srlikepid.lambda_pion = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
}
else if (TMath::Abs(AlgScore.fAssumedPdg) == 2212) { // lambda_pr
srlikepid.lambda_proton = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
}
Copy link
Member

Choose a reason for hiding this comment

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

Since the cases are known integral numbers, it's more efficient to use switch:

Suggested change
if (TMath::Abs(AlgScore.fAssumedPdg) == 13) { // lambda_mu
srlikepid.lambda_muon = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
}
else if (TMath::Abs(AlgScore.fAssumedPdg) == 211) { // lambda_pi
srlikepid.lambda_pion = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
}
else if (TMath::Abs(AlgScore.fAssumedPdg) == 2212) { // lambda_pr
srlikepid.lambda_proton = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
}
switch (std::abs(AlgScore.fAssumedPdg)) {
case 13: // lambda_mu
srlikepid.lambda_muon = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
break;
case 211: // lambda_pi
srlikepid.lambda_pion = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
break;
case 2212: // lambda_pr
srlikepid.lambda_proton = AlgScore.fValue;
srlikepid.pid_ndof = AlgScore.fNdf;
break;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to the suggested change.

@sungbinoh
Copy link
Contributor Author

sungbinoh commented Oct 28, 2025

Hi @PetrilloAtWork , thanks a lot for your review!
I have updated codes following the comments.

For default values for the SRTrkLikelihoodPID, adding srlikepid.setDefault(); in FillReco.cxx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants