Skip to content

Conversation

@aantonakis
Copy link

Description

Please provide a detailed description of the changes this pull request introduces. If available, also link to a docdb link where the issue/change have been presented on/discussed.

This PR adds the SBND CRT Veto from reco2 to CAF. It needs a Standard Record CRT Veto class to propagate the Veto variables. This adds branches to the recTree that consist of boolean values at the Event level and limited information related to the CRT SpacePoints that were involved in triggering the analysis veto. Here is a link to the original PR for reco2: SBNSoftware/sbndcode#707

Additionally, here is a docdb entry: SBN Document 40318-v1

Checklist Items:

  • [yes] Have you added a label? (bug/enhancement/physics etc.)
  • [yes] Have you assigned at least 1 reviewer?
  • [maybe] Is this PR related to an open issue / project?
  • May be part of the Spring Production ?
  • [yes] Does this PR affect CAF data format? If so, please assign a CAF maintainer as additional reviewer.
  • May need to update reviewers?
  • [yes] Does this PR require merging another PR in a different repository (such as sbnanobj/sbnobj etc.)? If so, please link it in the description.
  • It requires sbnanobj: Feature/aantonak crtveto caf sbnanaobj#159
  • [No] Are you submitting this PR on behalf of someone else who made the code changes? If so, please mention them in the description.

@aantonakis aantonakis self-assigned this Sep 18, 2025
@aantonakis aantonakis added the enhancement New feature or request label Sep 18, 2025
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 this work Alex, very grateful this is making it to CAF now!

Looks like there are a few merge conflict resolutions have left a few missing curly brackets.

Also a couple of suggestions for cleaning up the main section that accesses the products. Arguably picky but it's better to make it resilient now.

Comment on lines 1706 to 1707
// And associated SpacePoint objects
art::FindManyP<sbnd::crt::CRTSpacePoint> spAssoc(sbndcrtveto_handle, evt, fParams.SBNDCRTVetoLabel());
Copy link
Member

Choose a reason for hiding this comment

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

Sort indentation

Copy link
Author

Choose a reason for hiding this comment

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

Code structure has changed a bit in the latest commit but I believe this issue is gone

Comment on lines 1711 to 1712
// Assume there is only one Veto per event
const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>> veto_sp_v(spAssoc.at(0));
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like the hard-coded use of 0 as the key even if we know one is produced.

Would it be possible to check the size of the handle and then get the art::Ptr<> to the veto object and use the key from that?

Copy link
Member

Choose a reason for hiding this comment

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

Is there only one associated pointer? then use art::FindOneP (CL-04); or art::FindOne if you don't care of the art pointer but only of the data product.

Copy link
Author

Choose a reason for hiding this comment

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

In the latest commit I check the size of the veto vector and pass the key at index 0 from the vector of veto Ptrs. I stuck with FindManyP for the moment. Will FindOne or FindOneP work if there are multiple space points per veto? If so I can try to make that work but it seemed like it would grab just a single space point from my first attempt. Latest commit still uses FindManyP

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, FindOneP is indeed not appropriate here due to the 1-to-many relationship between CRTVeto and CRTSpacePoints. The handling of the single CRTVeto-per-event is now improved though, thank you!

Comment on lines 1717 to 1721
// TODO ? Need to decide how to handle this
// This version seems to work in skipping empty associations. It does break the rec.sbnd_crt_veto.sp_pe..length and
// rec.sbnd_crt_veto.sp_time..length branches? However, the rec.sbnd_crt_veto.sp_position..length still works and can be used?
std::cout << "No Veto Space Points" << std::endl;
//vetoSpacePoints.emplace_back(); // nullptr
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this - shouldn't need a special case, the vector branches should just be size 0?

Copy link
Member

Choose a reason for hiding this comment

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

Also in the final version remove the print statement :)

Copy link
Author

Choose a reason for hiding this comment

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

Should be resolved. I have a few new debug statements momentarily that will be removed soon. I was testing the functionality of passing the vector of space point Ptrs directly. That block of code might change with new comments and I'll remove any print out statements after that

Comment on lines 1725 to 1729
for (auto const& sp: veto_sp_v) {

vetoSpacePoints.push_back(*sp);

}
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 need this? We can pass the vector of art::Ptr<>'s

Copy link
Author

Choose a reason for hiding this comment

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

should be resolved

rec.ncrt_spacepoints = srcrtspacepoints.size();
rec.sbnd_crt_tracks = srsbndcrttracks;
rec.nsbnd_crt_tracks = srsbndcrttracks.size();
rec.sbnd_crt_veto = srsbndcrtveto;
Copy link
Member

Choose a reason for hiding this comment

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

This is me nit-picking but can you align = as all the others are ;P

Copy link
Author

Choose a reason for hiding this comment

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

Yes of course, good catch thanks!

Copy link
Author

Choose a reason for hiding this comment

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

should be resolved

bool allowEmpty = false);

void FillSBNDCRTVeto(const sbnd::crt::CRTVeto &veto,
const std::vector<sbnd::crt::CRTSpacePoint> &points,
Copy link
Member

Choose a reason for hiding this comment

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

Indentation

@linyan-w linyan-w moved this to Wait for last validation I patch (for MC) in SBND 2025 Fall Production - Validation Sep 18, 2025
@linyan-w linyan-w linked an issue Sep 18, 2025 that may be closed by this pull request
@linyan-w linyan-w moved this from Wait for next validation I patch (for MC) to Wait for validation II in SBND 2025 Fall Production - Validation Sep 23, 2025
@kjplows kjplows moved this to Open pull requests in SBN software development Sep 24, 2025
if (spAssoc.isValid()) {
// There is one vector of SpacePoints per Veto --> can be empty if no veto condition was satisfied
const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>> veto_sp_v(spAssoc.at(vetoPtrs[0].key()));
FillSBNDCRTVeto(sbndcrtvetos[0], veto_sp_v, srsbndcrtveto);
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why you can just pass vetoPtrs[0] here? Save having a vector of pointers and a vector of non-pointers?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I was actually thinking the same thing but tried to make minimal changes first to see what feedback I would get. I will try to get this changed today, thanks Henry!

Comment on lines 1711 to 1712
// Assume there is only one Veto per event
const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>> veto_sp_v(spAssoc.at(0));
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, FindOneP is indeed not appropriate here due to the 1-to-many relationship between CRTVeto and CRTSpacePoints. The handling of the single CRTVeto-per-event is now improved though, thank you!

Comment on lines 1712 to 1715
// And associated SpacePoint objects
art::FindManyP<sbnd::crt::CRTSpacePoint> spAssoc(sbndcrtveto_handle, evt, fParams.SBNDCRTVetoLabel());
if (spAssoc.isValid()) {
// There is one vector of SpacePoints per Veto --> can be empty if no veto condition was satisfied
Copy link
Member

Choose a reason for hiding this comment

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

Across quite a few locations there are still quite a few indentation issues, this probably comes from tab size in the editor you are using - try and untabify to solve.

Copy link
Author

Choose a reason for hiding this comment

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

I think you're right. I see something completely different on my end. The indentation shown here doesn't look like what's shown in my text editor (I've been using vim)

Copy link
Member

Choose a reason for hiding this comment

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

Still needs resolving

@linyan-w linyan-w moved this from Wait for validation II to Waiting on Reviewer in SBND 2025 Fall Production - Validation Sep 29, 2025
@linyan-w linyan-w moved this from Waiting on Reviewer to Wait for next patch in SBND 2025 Fall Production - Validation Sep 29, 2025
@linyan-w linyan-w moved this from Wait for next patch to Wait for validation II in SBND 2025 Fall Production - Validation Oct 7, 2025
@linyan-w linyan-w moved this from Wait for validation II to Waiting on Reviewer in SBND 2025 Fall Production - Validation Oct 7, 2025
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.

I'm now happy with this subject to sorting indentation issues.

Thanks for working on the review comments @aantonakis!

Comment on lines 1712 to 1715
// And associated SpacePoint objects
art::FindManyP<sbnd::crt::CRTSpacePoint> spAssoc(sbndcrtveto_handle, evt, fParams.SBNDCRTVetoLabel());
if (spAssoc.isValid()) {
// There is one vector of SpacePoints per Veto --> can be empty if no veto condition was satisfied
Copy link
Member

Choose a reason for hiding this comment

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

Still needs resolving

Comment on lines 281 to 285

void FillSBNDCRTVeto(const art::Ptr<sbnd::crt::CRTVeto> &veto,
const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>> &points,
caf::SRSBNDCRTVeto &srsbndcrtveto,
bool allowEmpty = false);
Copy link
Member

Choose a reason for hiding this comment

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

More indentation

Comment on lines +191 to +194
void FillSBNDCRTVeto(const art::Ptr<sbnd::crt::CRTVeto> &veto,
const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>> &points,
caf::SRSBNDCRTVeto &srsbndcrtveto,
bool allowEmpty)
Copy link
Member

Choose a reason for hiding this comment

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

Indentation

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 request the removal of art::Ptr vector in the implementation.
Creating those vectors causes a overhead and in most of the cases is not necessary and then becomes a bad example (in fact, if you could tell where you have seen that used, we may also consider fixing the inspiring code as needed).

Also the indentation needs to be fixed, but @henrylay97 has already covered that.

Comment on lines 1791 to 1796
std::vector<art::Ptr<sbnd::crt::CRTVeto>> vetoPtrs;
// fill into event
if (sbndcrtveto_handle.isValid()) {
art::fill_ptr_vector(vetoPtrs, sbndcrtveto_handle);
// Only one valid veto per event
if (vetoPtrs.size() == 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Please do not create art pointers unless they are really necessary.
Here:

Suggested change
std::vector<art::Ptr<sbnd::crt::CRTVeto>> vetoPtrs;
// fill into event
if (sbndcrtveto_handle.isValid()) {
art::fill_ptr_vector(vetoPtrs, sbndcrtveto_handle);
// Only one valid veto per event
if (vetoPtrs.size() == 1) {
// fill into event
if (sbndcrtveto_handle.isValid()) {
// Only one valid veto per event
if (sbndcrtveto_handle->size() == 1) {

and then pass to the function a simple sbnd::crt::CRTVeto const* pointer (&sbndcrtveto_handle->front()) or, better, a reference sbnd::crt::CRTVeto const& (sbndcrtveto_handle->front()).
The reference is "better" than a pointer in that the latter would convey the message that the object could be absent (null pointer), which is not the case in your code.

art::FindManyP<sbnd::crt::CRTSpacePoint> spAssoc(sbndcrtveto_handle, evt, fParams.SBNDCRTVetoLabel());
if (spAssoc.isValid()) {
// There is one vector of SpacePoints per Veto --> can be empty if no veto condition was satisfied
const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>> veto_sp_v(spAssoc.at(vetoPtrs[0].key()));
Copy link
Member

Choose a reason for hiding this comment

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

You are asking the key() of the art pointer created from the first element of a data product. The value of such key is always 0.
Also, avoid copying the vector of space point pointers: use a reference.

Suggested change
const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>> veto_sp_v(spAssoc.at(vetoPtrs[0].key()));
const std::vector<art::Ptr<sbnd::crt::CRTSpacePoint>>& veto_sp_v(spAssoc.at(0));

Comment on lines +205 to +206
srsbndcrtveto.sp_time.emplace_back(sp->Ts0()); /// ns for SBND CRT SpacePoints
srsbndcrtveto.sp_pe.emplace_back(sp->PE());
Copy link
Member

Choose a reason for hiding this comment

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

I suggest the use of good old push_back() when the purpose is just to copy the argument into the vector. emplace_back() works too, but it has the slightly different purpose of creating a new object into the vector rather than copying an existing one.

Suggested change
srsbndcrtveto.sp_time.emplace_back(sp->Ts0()); /// ns for SBND CRT SpacePoints
srsbndcrtveto.sp_pe.emplace_back(sp->PE());
srsbndcrtveto.sp_time.push_back(sp->Ts0()); /// ns for SBND CRT SpacePoints
srsbndcrtveto.sp_pe.push_back(sp->PE());

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

Status: Open pull requests
Status: Waiting on Reviewer

Development

Successfully merging this pull request may close these issues.

CRT Veto in CAFs

3 participants