Skip to content

Added flag for events with an ADC value higher than 14000. - #200

Open
nlopez-code wants to merge 9 commits into
cositools:develop/emfrom
nlopez-code:updateMaxADC
Open

Added flag for events with an ADC value higher than 14000.#200
nlopez-code wants to merge 9 commits into
cositools:develop/emfrom
nlopez-code:updateMaxADC

Conversation

@nlopez-code

Copy link
Copy Markdown

Included in unit test as well
( #40 )

@fhagemann fhagemann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is one of the most beautifully written PRs I've ever seen.
I have one tiny comment on your code, and will follow with instructions how to get the unit tests to pass :)

@fhagemann

fhagemann commented Aug 19, 2026

Copy link
Copy Markdown

If you look at the test logs, you can see the following:

PASS UTNDEEStripHit (Passed tests: 40, Failed tests: 0)
UTNEndToEnd_406-1 (1/7 failed)
UTNEndToEnd_542-1 (1/7 failed)
PASS UTNHit (Passed tests: 139, Failed tests: 0)
PASS UTNModuleLoaderMeasurementsHDF (Passed tests: 118, Failed tests: 0)
PASS UTNReadOutAssembly (Passed tests: 255, Failed tests: 0)
PASS UTNStripHit (Passed tests: 145, Failed tests: 0)
PASS UTNStripMap (Passed tests: 236, Failed tests: 0)

which states that something in the end-to-end tests for detectors 406-1 and 542-1 failed.

You can run those tests on your local machine by running

make -j16
make -j16 unittests
UTNEndToEnd_406-1

Which in my case yields the following output:

FAILED: End-to-end test 406-1  <-- output file
   Description: The generated output is numerically equivalent to the reference
   Expected:    numerically equivalent files
   Output:      
      line 1340:
        expected:  QA StripPairing (Best reduced chi square is not below 25 (466.978427)) (GR Hit: Detector ID 0 and Energy 294.916417)
        test:      QA HighADC (High ADC value 15804 for Detector: 0, side: LV, strip: 20) (High ADC value 16013 for Detector: 0, side: LV, strip: 21) (High ADC value 16006 for Detector: 0, side: LV, strip: 22) (High ADC value 15449 for Detector: 0, side: LV, strip: 23) (High ADC value 15058 for Detector: 0, side: HV, strip: 53) (High ADC value 16015 for Detector: 0, side: HV, strip: 54) (High ADC value 16038 for Detector: 0, side: HV, strip: 55)

Unit test: UTNEndToEnd_406-1
Passed tests: 7
Failed tests: 1

Essentially this means that, if we run nuclearizer using the updated code in this PR, we would get a different output (which makes sense here: we're now producing additional quality flags, and they will end up appearing in the final .tra file.

Some background information:
In the unit tests, we automatically run nuclearizer using the config files in resource/unittestdata/406-1 (or 542-1 respectively) via nuclearizer -c hdf5-to-tra.nuclearizer.cfg -a and compare the output to hdf5-to-tra.reference.tra.
You're now getting the (expected) error that the newly generated .tra file does not match the reference .tra file.
To resolve this, you might need to update those reference files, such that they include the quality flags that you are adding in this PR. You can achieve this by manually running nuclearizer -c hdf5-to-tra.nuclearizer.cfg -a in both the 406-1 and 542-1 directories yourself, renaming the created output file hdf5-to-tra.tra to hdf5-to-tra.reference.tra to update the reference file, and pushing the updated reference file to this PR.

Let me know if you run into any issues tackling this, always happy to help! :)

@fhagemann fhagemann added the enhancement New feature or request label Aug 19, 2026
@fhagemann fhagemann linked an issue Aug 19, 2026 that may be closed by this pull request

@fhagemann fhagemann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, looks like my comment didn't go through ^^

Comment thread src/MModuleEnergyCalibration.cxx Outdated
if (g_Verbosity >= c_Warning) {
cout << m_XmlTag << ": Warning: High ADC value " << SH->GetADCUnits() << " for read-out element " << R << endl;
}
Event->SetHighADC_QualityFlag("High ADC value " + to_string(SH->GetADCUnits()) + " for " + R.ToString().Data());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tiny comment when composing the QualityFlag Text: you might want to convert the ADC value to an (unsigned) int to avoid a lot of unnecessary zeros in the message:

Suggested change
Event->SetHighADC_QualityFlag("High ADC value " + to_string(SH->GetADCUnits()) + " for " + R.ToString().Data());
if (g_Verbosity >= c_Warning) {
cout << m_XmlTag << ": Warning: High ADC value " << (int) SH->GetADCUnits() << " for read-out element " << R << endl;
}
Event->SetHighADC_QualityFlag("High ADC value " + to_string((int) SH->GetADCUnits()) + " for " + R.ToString().Data());

This will be resolved by itself once we tackle #176, but we can hack this here for now ;)

Before:

QA HighADC (High ADC value 15804.000000 for Detector: 0, side: LV, strip: 20) (High ADC value 16013.000000 for Detector: 0, side: LV, strip: 21) (High ADC value 16006.000000 for Detector: 0, side: LV, strip: 22) (High ADC value 15449.000000 for Detector: 0, side: LV, strip: 23) (High ADC value 15058.000000 for Detector: 0, side: HV, strip: 53) (High ADC value 16015.000000 for Detector: 0, side: HV, strip: 54) (High ADC value 16038.000000 for Detector: 0, side: HV, strip: 55)

After:

QA HighADC (High ADC value 15804 for Detector: 0, side: LV, strip: 20) (High ADC value 16013 for Detector: 0, side: LV, strip: 21) (High ADC value 16006 for Detector: 0, side: LV, strip: 22) (High ADC value 15449 for Detector: 0, side: LV, strip: 23) (High ADC value 15058 for Detector: 0, side: HV, strip: 53) (High ADC value 16015 for Detector: 0, side: HV, strip: 54) (High ADC value 16038 for Detector: 0, side: HV, strip: 55)

@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.

Nice work on your first Nuclearizer PR, @nlopez-code !!!

That said, I think you overdid the flags a bit :). The QualityFlag in MReadOutAssembly is probably sufficient, where as the flag in the MStripHit class is probably too much, at least in my interpretation of the purpose of those flags.

We also need to decide if we should do anything with the ADC values if they are measured >14000. Should we treat 14000 ADC truly like a software overflow bin and reassign the high ADC values to be 14000, or do we just keep it as is and treat these events with caution to be potentially filtered out in revan/mimrec? This probably needs to be investigated further with some high energy data to determine the best approach, but that of course can be a TODO.

Perhaps for now just add a comment in the code when you raise the High ADC warning that we might want to revisit how we handle the high ADC values.

Comment thread include/MStripHit.h Outdated
//! Set whether the strip has a high ADC value (close to the ADC saturation limit)
void HasHighADC(bool HighADC) { m_HasHighADC = HighADC; }
//! Return whether the strip has a high ADC value (close to the ADC saturation limit)
bool HasHighADC() const { return m_HasHighADC; }

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 if it's appropriate to be defining a StripHit flag for HighADC?

StripHits with the > HighADC value should be treated with caution, but I think the HighADC quality flag for an event, as you have defined it in MReadoutAssembly, might be enough?

The flags here for StripHits, such as HasFastTiming, IsGuardRing, etc, are derived from the raw data and describe the type of strip hit but not necessarily the quality of the strip hit. I think the HighADC flag is most similar to the SlowThresholdCut (other then us not removing the strip hit), so we should more closely follow that example. And if that's the case, then I think you did a lot more work then you needed to.

Comment thread src/MStripHit.cxx Outdated
// 0b111u

unsigned int Flags = 0b000u;
// Currently, 4 bits:

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.

This gives me pause. I don't think we want HighADC to be looped in with these higher-level flags.

@fhagemann

Copy link
Copy Markdown

Is this missing the updated MModuleEnergyCalibration.cxx?
In the current version of the files, we are not setting the flag anywhere (?)

Comment thread src/MModuleEnergyCalibration.cxx Outdated
if (SH->GetADCUnits() > m_HighADCThreshold) {
SH->HasHighADC(true);
if (g_Verbosity >= c_Warning) {
cout << m_XmlTag << ": Warning: High ADC value " << SH->GetADCUnits() << " for read-out element " << R << endl;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You might also want to add the (int) in this line:

Suggested change
cout << m_XmlTag << ": Warning: High ADC value " << SH->GetADCUnits() << " for read-out element " << R << endl;
cout << m_XmlTag << ": Warning: High ADC value " << (int) SH->GetADCUnits() << " for read-out element " << R << endl;

Comment thread src/MModuleEnergyCalibration.cxx Outdated
// Flag strip hits whose ADC value is close to the ADC saturation limit, since their
// calibrated energy is not trustworthy. The hit is kept, it is only marked.
if (SH->GetADCUnits() > m_HighADCThreshold) {
SH->HasHighADC(true);

@fhagemann fhagemann Aug 20, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should be Event->HasHighADC(true);?

@fhagemann fhagemann Aug 20, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Edit: Actually, this line can completely be removed (the StripHit has no m_HasHighADC anymore), as Event->SetHighADC_QualityFlag later in the code takes care of that

Suggested change
SH->HasHighADC(true);

…his was supposed to be a beautifully written PR

@fhagemann fhagemann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unit tests pass, looks good to me! :)

@fhagemann

Copy link
Copy Markdown

While I love the commit messages, we might want to squash them when merging ^^
image

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.

Handle non-linear gain/ADC overflow

3 participants