Skip to content

feat(analysis/offline):Added a filter for good events#1280

Draft
pgrusell wants to merge 4 commits intoR3BRootGroup:devfrom
pgrusell:tofdhit
Draft

feat(analysis/offline):Added a filter for good events#1280
pgrusell wants to merge 4 commits intoR3BRootGroup:devfrom
pgrusell:tofdhit

Conversation

@pgrusell
Copy link
Contributor

@pgrusell pgrusell commented Oct 10, 2025

refactor(r3bdata/tofdHitData): TofdHitData no longer inherits R3BHit, as it's not used by any other detector data. Moreover, method to get the plane id has been change from DetId to PlaneId

feat(analysis/offline): Class to filter events according to AoQ at FRS and Q at ToFD

feat(analysis/online): added method to select the charge selection algorithm


Checklist:

@pgrusell pgrusell force-pushed the tofdhit branch 3 times, most recently from b042b04 to c7ffddf Compare October 10, 2025 10:36
@pgrusell pgrusell force-pushed the tofdhit branch 2 times, most recently from 388767d to c7ffddf Compare October 20, 2025 20:36
jose-luis-rs and others added 4 commits November 11, 2025 18:53
refactor(r3bdata/tofdHitData): TofdHitData no longer inherits R3BHit, as it's not used by any other detector data. Moreover, method to get the plane id has been change from DetId to PlaneId

feat(analysis/offline): Class to filter events according to AoQ at FRS and Q at ToFD

feat(analysis/online): added method to select the charge selection algorithm

style(analysis/online): Clang format applied

fix(analysis): clang-tidy

feat(analysis/online): change double array to std::vector

style(analysis/online): clang-format
Copilot AI review requested due to automatic review settings January 12, 2026 13:29
@pgrusell pgrusell marked this pull request as draft January 12, 2026 13:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the R3BTofdHitData class to no longer inherit from R3BHit and renames the method GetDetId() to GetPlaneId() for better semantic clarity. It also introduces a new event filter class R3BEventFilter for offline analysis that filters events based on FRS A/Q and ToFD charge selections.

Changes:

  • Refactored R3BTofdHitData to inherit directly from TObject instead of R3BHit, with inline getters and modern C++ features
  • Renamed GetDetId() to GetPlaneId() across all usages in tracking and online analysis files
  • Added new R3BEventFilter class for filtering events based on FRS and ToFD criteria
  • Updated header guards to use #pragma once in several files
  • Code formatting improvements in R3BFiberTrackingOnlineSpectra.cxx

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
r3bdata/tofData/R3BTofdHitData.h Complete refactoring: removed R3BHit inheritance, added inline getters, changed GetDetId to GetPlaneId, added deprecated methods for backward compatibility
r3bdata/tofData/R3BTofdHitData.cxx Updated constructor to initialize member variables directly, removed old method implementations
tracking/R3BTrackingS515.cxx Updated method call from GetDetId() to GetPlaneId()
tracking/R3BTrackingG249.cxx Updated method call from GetDetId() to GetPlaneId()
tofd/online/R3BTofDOnlineSpectra.cxx Updated method call from GetDetId() to GetPlaneId()
analysis/online/R3BTofDvsTttxOnlineSpectra.cxx Updated method call from GetDetId() to GetPlaneId()
analysis/online/R3BFibervsTofDOnlineSpectra.cxx Updated method call from GetDetId() to GetPlaneId()
analysis/online/R3BFiberTrackingOnlineSpectra.cxx Updated method call from GetDetId() to GetPlaneId() and code formatting improvements
analysis/online/R3BCalifavsTofDOnlineSpectra.cxx Updated method call from GetDetId() to GetPlaneId() and converted C-style arrays to std::vector
analysis/offline/R3BEventFilter.h New event filter class header
analysis/offline/R3BEventFilter.cxx New event filter class implementation
r3bdata/frsData/R3BFrsData.h Changed header guard to #pragma once
analysis/offline/R3BIncomingBeta.h Changed header guard to #pragma once
analysis/AnaLinkDef.h Added R3BEventFilter to ROOT dictionary

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Deprecated methods
[[deprecated("Use GetPlaneId() instead.")]] UInt_t GetDetId() const { return fPlaneId; }
[[deprecated]] UInt_t GetHitId() const { return -1; }
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The deprecated GetHitId() method returns -1, but the return type is UInt_t (unsigned integer). This will cause -1 to be converted to a large unsigned value (typically 4294967295 on 32-bit systems). Consider either changing the return type to Int_t or returning 0 instead.

Suggested change
[[deprecated]] UInt_t GetHitId() const { return -1; }
[[deprecated]] UInt_t GetHitId() const { return 0; }

Copilot uses AI. Check for mistakes.
Comment on lines +118 to +125
if (planes13ok || planes24ok)
return true;
else
return false;
}

inline bool CheckFireConditionsAllPlanes(const std::vector<int>& v)
{
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Simplified return statement recommended. The if-else can be replaced with a direct return of the boolean expression.

Suggested change
if (planes13ok || planes24ok)
return true;
else
return false;
}
inline bool CheckFireConditionsAllPlanes(const std::vector<int>& v)
{
return planes13ok || planes24ok;
}
inline bool CheckFireConditionsAllPlanes(const std::vector<int>& v)
{
inline bool CheckFireConditionsAllPlanes(const std::vector<int>& v)
{

Copilot uses AI. Check for mistakes.
void R3BEventFilter::Exec(Option_t*)
{
bool fValidEvent = false;

Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Potential null pointer dereference. The fHeader pointer is used without null checking on line 141. If fHeader is nullptr, this will cause a crash. Add a null check for fHeader before accessing GetExpId().

Suggested change
if (!fHeader)
{
R3BLOG(error, "R3BEventFilter: Event header not available, skipping event");
StoreEvent(false);
return;
}

Copilot uses AI. Check for mistakes.
Comment on lines +148 to +150
auto frsdata = dynamic_cast<R3BFrsData*>(fFrsData->At(ihit));
auto charge = frsdata->GetZ();
auto aoq = frsdata->GetAq();
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Missing null check after dynamic_cast. If the cast fails, frsdata will be nullptr and calling GetZ() or GetAq() on it will cause a crash. Add a null check after the dynamic_cast.

Copilot uses AI. Check for mistakes.
Comment on lines +183 to +187
auto tofdhit = dynamic_cast<R3BTofdHitData*>(fTofdHit->At(ihit));
auto plane = tofdhit->GetPlaneId();

// Add a method to calculate the charge in each plane
chargeSelected[plane - 1] = isSelectedCharge(plane, tofdhit->GetChargeZ());
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Missing null check after dynamic_cast. If the cast fails, tofdhit will be nullptr and calling GetPlaneId() or GetChargeZ() on it will cause a crash. Add a null check after the dynamic_cast.

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +116
inline bool CheckFireConditionsTwoPlanes(const std::vector<int>& v)
{

bool planes13ok = false;
bool planes24ok = false;

if ((v[0] == 1) && (v[2] == 1))
planes13ok = true;

if ((v[1] == 1) && (v[3] == 1))
planes24ok = true;
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Missing bounds check. The function accesses v[0], v[1], v[2], and v[3] without verifying that the vector has at least 4 elements. Add a size check similar to CheckFireConditionsAllPlanes to prevent out-of-bounds access.

Copilot uses AI. Check for mistakes.
}
}

// Function to determinate the charge in terms of the limits
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Typo in comment: "determinate" should be "determine".

Suggested change
// Function to determinate the charge in terms of the limits
// Function to determine the charge in terms of the limits

Copilot uses AI. Check for mistakes.
Comment on lines +184 to +187
auto plane = tofdhit->GetPlaneId();

// Add a method to calculate the charge in each plane
chargeSelected[plane - 1] = isSelectedCharge(plane, tofdhit->GetChargeZ());
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Potential out-of-bounds access. The plane ID from GetPlaneId() is used to index into chargeSelected and fChargeLimits without validation. If plane is 0 or greater than 4, this will cause out-of-bounds access. Consider adding bounds checking to ensure plane is within the valid range (1-4) before using it as an array index.

Copilot uses AI. Check for mistakes.
Comment on lines +159 to +164
auto isSelectedCharge = [&](int plane, double charge)
{
if ((charge > fChargeLimits[plane - 1][0]) && (charge < fChargeLimits[plane - 1][1]))
return 1;
else
return 0;
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The lambda function isSelectedCharge accesses fChargeLimits[plane - 1] without validating that the index is within bounds. If plane is 0 or if fChargeLimits has fewer than 'plane' elements, this will cause undefined behavior. Add bounds checking before accessing the vector.

Copilot uses AI. Check for mistakes.
}

Int_t nHits = fHitItemsCalifa->GetEntriesFast();
UInt_t nHits = fHitItemsCalifa->GetEntriesFast();
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Type mismatch: nHits is declared as UInt_t but the loop counter ihit on line 166 is Int_t. This can cause a signed/unsigned comparison warning. Consider making ihit also UInt_t or keeping nHits as Int_t for consistency with GetEntriesFast() which returns Int_t.

Suggested change
UInt_t nHits = fHitItemsCalifa->GetEntriesFast();
Int_t nHits = fHitItemsCalifa->GetEntriesFast();

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants