Skip to content

Commit 19c62a8

Browse files
sawenzelclaude
andcommitted
Do not encode a label for a signal without an MC particle
This fixes a problem in MCCompLabel and adds a unit test. - A hit whose track was pruned carries trackID -1, and the constructor encoded that into the 31 bit track field. - Decoding then gave trackID 2147483647 with isValid() true, so the label looked like a correctly identified particle. - The constructor now leaves the label unset for a negative trackID, which is the state a decoder already handles. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 9ee36c5 commit 19c62a8

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

DataFormats/simulation/include/SimulationDataFormat/MCCompLabel.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ class MCCompLabel
5252
// mask for all used fields
5353
static constexpr uint64_t maskFull = (ul0x1 << (nbitsTrackID + nbitsEvID + nbitsSrcID)) - 1;
5454

55-
MCCompLabel(int trackID, int evID, int srcID, bool fake = false) { set(trackID, evID, srcID, fake); }
55+
MCCompLabel(int trackID, int evID, int srcID, bool fake = false)
56+
{
57+
// a negative trackID means no MC particle is attached to this signal;
58+
// the label stays unset rather than encoding a track that does not exist
59+
if (trackID >= 0) {
60+
set(trackID, evID, srcID, fake);
61+
}
62+
}
5663
MCCompLabel(bool noise = false)
5764
{
5865
if (noise) {

DataFormats/simulation/test/testMCCompLabel.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ BOOST_AUTO_TEST_CASE(MCCompLabel_test)
5353
MCCompLabel dummy;
5454
BOOST_CHECK(dummy.isEmpty() && !dummy.isNoise() && dummy.isFake() && !dummy.isValid());
5555
}
56+
57+
// A hit whose track was pruned carries trackID -1 and has no MC particle
58+
BOOST_AUTO_TEST_CASE(MCCompLabel_no_particle_test)
59+
{
60+
MCCompLabel unmapped(-1, 200, 10);
61+
BOOST_CHECK(!unmapped.isValid());
62+
}

0 commit comments

Comments
 (0)