Skip to content

Implementing NN into Strip Pairing - #183

Draft
julianmgerber wants to merge 28 commits into
cositools:develop/emfrom
julianmgerber:StripPairingNN
Draft

Implementing NN into Strip Pairing#183
julianmgerber wants to merge 28 commits into
cositools:develop/emfrom
julianmgerber:StripPairingNN

Conversation

@julianmgerber

@julianmgerber julianmgerber commented Jul 24, 2026

Copy link
Copy Markdown

Previously, there was nothing about NN in the strip pairing, so if someone tried the strip pairing with NN included then it'd try to group NN + triggered strips together and add in all the energy on the NN strips. Perhaps eventually we'll want to add in some of the NN energy, but for now I thought it made sense to keep them separate.

Changes:

  • Separate out NN/triggered strips so that only the triggered strips are actually paired and grouped into hits
  • After the pairing, NN strips are linked to their neighboring hit through a new function: AddNearestNeighborStripHit
  • If it's ambiguous which hit a NN strip hit should be associated with (like if there are two hits separated by only one strip), then the NN strip is linked to both

Questions:

  • Should there be a way to read out the NN strip hits into a .dat file (since right now, only the actual triggered SH making up a hit will be read out)?
    - Update 7/28: Reading out NN strip hits to .dat file as "NN" rather than "SH"
  • Should there be a separate flag for those ambiguous NN strip hits that are linked to two different hits?
    - Update 7/28: New IsAmbiguousNearestNeighbor flag added to MStripHit class to flag NNs that are linked to multiple hits

@julianmgerber
julianmgerber requested a review from ckierans July 24, 2026 01:10
@fieldrog

Copy link
Copy Markdown

@julianmgerber I woud definitely like to have a flag for NN hits ambiguously attached to two different hits !

@julianmgerber

Copy link
Copy Markdown
Author

@julianmgerber I woud definitely like to have a flag for NN hits ambiguously attached to two different hits !

@fieldrog Just added the new flag, IsAmbiguousNearestNeighbor to MStripHit!

@julianmgerber
julianmgerber marked this pull request as ready for review July 28, 2026 23:38
Comment thread src/MStripHit.cxx
<<m_ReadOutElement->GetDetectorID()<<" "
<<((m_ReadOutElement->IsLowVoltageStrip() == true) ? "l" : "h")<<" "
<<m_ReadOutElement->GetStripID()<<" "
<<m_HasTriggered<<" "

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just wondering: is m_HasTriggered correlated with the strip being a NN?
Maybe this here might be redundant then, as we can "reconstruct" NN from SH that did not trigger.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Andreas has removed the m_HasTriggered flag in PR #171 .

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

m_HasTriggered seems to not have been removed in #171.

Copy link
Copy Markdown
Author

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, m_HasTriggered isn't actually assigned anywhere. Like in the .dat file output, all the strip hits (triggered or otherwise) just have 0 for the HasTriggered parameter.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this when you read data from HDF5?
Maybe, the HDF5 reader module does not assign values to m_HasTriggered? (but should?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, looks like the HDF5 reader never assigns a m_HasTriggered value:

if (m_StripMap.HasReadOutID(StripID) == true) {
MStripHit* H = new MStripHit();
H->SetDetectorID(m_StripMap.GetDetectorID(StripID));
H->SetStripID(m_StripMap.GetStripNumber(StripID));
H->IsLowVoltageStrip(m_StripMap.IsLowVoltage(StripID));
H->SetADCUnits(ADCs);
H->SetTAC(TACs);
// Set boolean flags based on HitType and TimingType
H->IsGuardRing(HitType == 2);
if (H->IsGuardRing() == true) {
Event->SetGuardRingVeto(true);
}
H->IsNearestNeighbor(HitType == 1);
H->HasFastTiming(TimingType == 1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, I spoke with confidence when I didn't actually check the PR #171 code! Sorry about that.

I'm pretty sure we agreed we didn't need the HasTriggered boolean because it is completely redundant with (but opposite to) the IsNearestNeighbor flag. As far as I can tell, no one is using this flag anywhere so I'd vote for removing it entirely to avoid confusion going forward.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But that doesn't need to happen in this PR, to be clear.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I agree (both removing HasTriggered and that it doesn't have to happen in this PR).

@fhagemann fhagemann assigned fhagemann and parshadkp and unassigned fhagemann Aug 4, 2026
@ckierans

ckierans commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

@julianmgerber Can you resolve the conflicts with the changes in MStripHit and then I'll review?

@ckierans ckierans left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, Julian. I think we need to be a bit more careful about being clear when the StripHit list is only triggered strips or also includes NN strip hits as well. Perhaps this can just be better comments, but we might consider changing some of the names to include "TriggeredStripHits" so there's no confusion.


//! Divide an event's strip hits by detector and LV/HV side
vector<vector<vector<MStripHit*>>> CollectStripHits(MReadOutAssembly* Event);
tuple<vector<vector<vector<MStripHit*>>>, bool> CollectStripHits(MReadOutAssembly* Event);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are these now only triggered strip hits? Maybe make that clear in the comment?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, I see below these are only the triggered strip hits. You should update the comment to reflect this change.

"//! Divide an event's triggered strip hits by detector and LV/HV side"

Comment thread include/MHit.h
//! Ownership stays elsewhere
MStripHit* GetStripHit(unsigned int i);
//! Return nearest neighbor strip hit i or nullptr if i is out of bounds
MStripHit* GetNearestNeighborStripHit(unsigned int i);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm wondering about any potential confusion/overlap with NN strip hits listed here vs in the StripHit list that then have the IsNearestNeightbor flag. Do we expect NN strip hits to also be listed in the standard GetStripHit list or is that now exclusively for triggered strips? If so, let's make that clear.

}
}
else {
IncludingNearestNeighbors = true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It took me a moment to understand what you're trying to do with this boolean. Maybe add a comment for this else statement: "If nearest neighbor strips are found in the event, set flag to properly account for them when strip pairing"

We have the boolean Get/SetIncludeNearestNeighbors in the MModuleLeaderMeasurementHDF module, which theoretically should be the same as this boolean here, except you're deriving it from the data, and not the GUI. I'm wondering if it will be less confusing (an potentially less prone to mistakes) to instead use that user-defined variable.

Comment thread include/MHit.h
// Strip hits:

//! Return the number of strip hits
unsigned int GetNStripHits() const { return m_StripHits.size(); }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this now only triggered strip hits? Or both triggered and untriggered?

bool AssignedDetector = false;
int DetectorID; // Define detector ID where hit took place
for (unsigned int sh = 0; sh < Event->GetHit(h)->GetNStripHits(); sh++) {
// Collect all the strip hits in a hit and split them by side

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I assume that whenever this function is called, the Hit only has triggered strips assigned to it. So this GetNStripHits will only return the number of triggered strip hits. Make that clear in the comment?

Once you assign Nearest Neighbor strip hits to the event, do you expect GetNStripHits to count all associated strip hits, or only triggered strips?

Comment thread src/MStripHit.cxx
<<m_ReadOutElement->GetDetectorID()<<" "
<<((m_ReadOutElement->IsLowVoltageStrip() == true) ? "l" : "h")<<" "
<<m_ReadOutElement->GetStripID()<<" "
<<m_HasTriggered<<" "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, I spoke with confidence when I didn't actually check the PR #171 code! Sorry about that.

I'm pretty sure we agreed we didn't need the HasTriggered boolean because it is completely redundant with (but opposite to) the IsNearestNeighbor flag. As far as I can tell, no one is using this flag anywhere so I'd vote for removing it entirely to avoid confusion going forward.

Comment thread src/MStripHit.cxx
<<m_ReadOutElement->GetDetectorID()<<" "
<<((m_ReadOutElement->IsLowVoltageStrip() == true) ? "l" : "h")<<" "
<<m_ReadOutElement->GetStripID()<<" "
<<m_HasTriggered<<" "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But that doesn't need to happen in this PR, to be clear.

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.

6 participants