Skip to content

ADD: Full suite of unit tests - #247

Merged
zoglauer merged 10 commits into
cositools:develop/emfrom
zoglauer:feature/full-unit-test-suite
Oct 27, 2026
Merged

zoglauer merged 10 commits into
cositools:develop/emfrom
zoglauer:feature/full-unit-test-suite

Conversation

@zoglauer

Copy link
Copy Markdown
Collaborator

*** MEGAlib update required ***

This PR drops the full unit test suite for nuclearizer.
All tests are a collaboration between Claude Opus 5.5, GPT-6.1-Sol, and Andreas.

The tests uncovered 60-70 bugs where 25-35 affect data correctness. I (or probably Claude) will add issues for them next.

Lot's of tests fail. Those are marked with ExpectedToFail() (161 checks): they are reported as KNOWN FAILURE without failing the run, and as UNEXPECTED PASS once fixed failing the run. I made it that way so that github is happy while we fix the bugs.

This PR adds ~20,000 !! lines of code and ~2,400 tests -- I absolutely do not expect anybody to review it. The PR is intentionally made in a way that 0 production code is touched.

@zoglauer zoglauer self-assigned this Oct 18, 2026
@zoglauer

Copy link
Copy Markdown
Collaborator Author

Just check with Arch - and getting some crashes - investigating

@fhagemann

Copy link
Copy Markdown

Let us know once you're done troubleshooting and want us to look at this :)

@zoglauer

Copy link
Copy Markdown
Collaborator Author

Different things fail on different OSes...

@zoglauer

Copy link
Copy Markdown
Collaborator Author

Everything is working on macOS Tahoe, Ubuntu 24.05, and the latest Arch - it is just not working here...

@zoglauer

Copy link
Copy Markdown
Collaborator Author

All checks passed! Ready of review!

This was referenced Oct 18, 2026
This was referenced Oct 19, 2026
@fhagemann

Copy link
Copy Markdown

Tested this locally on my laptop and all tests pass.
How should we deal with the unit tests that were added in #239 and now cause merge conflicts?

@zoglauer

zoglauer commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

@fhagemann I fixed all issues and dropped my duplicate unit test

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

Disclaimer: I didn't look through the DEE submodules yet, because I want to give them a closer look when tackling the new issues that were created as a result of this.

I had a very quick look through all other unittests for files/modules that I have worked with before (not by any means a thorough review, just a quick overlook) and commented/flagged some things.

Let me know if I should look through the DEE submodule unit tests BEFORE merging this or only when tackling the issues assigned to me.

Comment thread unittests/UTNAssembly.cxx

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How does this file relate to the unit tests added in #191 ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will redo #191 - the issues associates to Assemble should already be fixed.

Comment thread unittests/UTNAssembly.cxx
Comment on lines +202 to +208
MString Input = MString("module ") + M->GetXmlTag();
Passed = EvaluateTrue("MAssembly()", Input, "The XML tag of the module is unique", Tags.insert(M->GetXmlTag()).second) && Passed;
Passed = EvaluateTrue("MAssembly()", Input, "The name of the module is unique", Names.insert(M->GetName()).second) && Passed;
Passed = EvaluateFalse("MAssembly()", Input, "The XML tag is not empty", M->GetXmlTag().IsEmpty()) && Passed;
Passed = EvaluateTrue("MAssembly()", Input, "The module provides at least one module type", M->GetNModuleTypes() > 0) && Passed;
}
Passed = EvaluateTrue("MAssembly()", "available modules", "All available modules are non-null", AllValid) && Passed;

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

Not sure if we should make this a requirement, but add a test to check if the XML tag starts with XmlTag (following the discussion in #193 / #197 ) ?

@zoglauer zoglauer Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let me think about that.

Comment thread unittests/UTNAssembly.cxx
A test must never read or write the user's files. The `MUnitTest`
constructor therefore creates a private temporary directory with a
randomized name (e.g. `MEGAlib_aB3xYz9Qp1_home`) inside its temporary root,
points `HOME` to it, and changes the working directory into it. Neither is

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

About pointing HOME somewhere else for the unittests:
When running the end-to-end tests for 406-1 and 542-1, they are still generating the cross-sections directories in resource/unittestdata when running this locally(zoglauer/megalib#123). Can this somehow be avoided by having the unit tests create those directories also in a temporary directory instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I know. That requires MEGAlib changes.

Comment thread unittests/UTNGuardringHit.cxx
////////////////////////////////////////////////////////////////////////////////


bool UTNModuleTrappingCorrection::TestInterpolate()

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 feel like the Interpolate function we have in MModuleChargeTrapping right now might be useful elsewhere, and might therefore live in some utility module instead (how to we interpolate CTD-to-depth splines in the depth calibration module)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good with me.

Comment thread unittests/UTNReadOutDataEnergy.cxx
Comment thread unittests/UTNReadOutDataTAC.cxx
Comment thread unittests/UTNReadOutElementVoxel3D.cxx
Comment thread unittests/UTNTemplate.cxx

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 don't think we need unit tests for the template ^^
Is the template compiled when running make - if so, we might want to update the Makefile to not compile/test it.

@fhagemann fhagemann added the test Tests and code coverage label Oct 20, 2026
Comment thread unittests/UTNSubModuleChargeTransport.cxx
Comment thread unittests/UTNSubModuleChargeTransport.cxx
Comment thread unittests/UTNSubModuleChargeTransport.cxx
Comment thread unittests/UTNSubModuleChargeTransport.cxx
Comment thread unittests/UTNSubModuleChargeTransport.cxx
Comment thread unittests/UTNSubModuleDepthReadout.cxx Outdated
Comment on lines +375 to +376
Passed = EvaluateNear("AnalyzeEvent()", "LV strip 10", "The timing is 4200 - 1200 = 3000 ns", L10.m_Timing, 3000.0, 1e-9) && Passed;
Passed = Evaluate("AnalyzeEvent()", "LV strip 10", "The TAC is (3000 + 500) / 0.5 = 7000", L10.m_TAC, 7000u) && Passed;

@fhagemann fhagemann Oct 22, 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.

I guess it's documented here, but as said: not sure if this is the final configuration we want in the long run.

Comment thread unittests/UTNSubModuleDepthReadout.cxx Outdated
{
bool Passed = true;

// The TAC calibration only covers LV strips 32-63 of detector 0, as in the committed unit-level calibrations

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

????

TAC calibration should cover all strips
This might be due to the strip map, where STRIP_ID 0-31 are LV strips 32-63, but then followed by STRIP_ID 32-63, which are LV strips 0-31. I'm not sure we EVER expect partial TAC calibrations (?)

Comment on lines +125 to +136
MString UTNSubModuleStripReadout::WriteThresholds(unsigned int NStrips)
{
// Hardware threshold 1600 ADC (800 keV) for all strips
MString C = "STRIP_ID,Detector,side,strip,threshold_adc,threshold_keV\n";
for (unsigned int s = 0; s < NStrips; ++s) {
C += MString("") + s + ",0,l," + s + ",1600,800.0\n";
C += MString("") + (100 + s) + ",0,h," + s + ",1600,800.0\n";
}
MString FileName = GetTemporaryFileName("sr.thresholds.csv");
if (WriteTextFile(FileName, C) == false) return "";
return FileName;
}

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 expect the hardware thresholds for the DEE to have the same issue as what was fixed for the TAC cal in #239
--> we might need to apply the strip map also to the hardware threshold file or make sure that the Detector/side/strip notation is correct.

}

// FWHM at 1000 keV is 3 keV => sigma = 3 / 2.355
gRandom->SetSeed(4711);

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 there something special about the random seed 4711? 😅

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 module might go anyway

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

I'm done reviewing :)

@fhagemann

Copy link
Copy Markdown

You commented „Done“ on some comments, but never posted anything (?) 😅

@zoglauer

zoglauer commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

I addressed most of the meant to be addressed comments I think.

@zoglauer
zoglauer merged commit 6c37249 into cositools:develop/em Oct 27, 2026
1 check passed

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

Looks great, thanks so much!

Comment on lines +116 to 120
unsigned int UTNSubModuleDepthReadout::GetDIB(unsigned int DetID) const
{
// Deliberately different from the detector ID: the DIB column of the TAC calibration file must not be used as detector ID
return DetID + 4;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Tests and code coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants