Skip to content

updated with calorimeter, to be checked#11

Open
matclim wants to merge 10 commits intoShipSoft:mainfrom
matclim:addcalo
Open

updated with calorimeter, to be checked#11
matclim wants to merge 10 commits intoShipSoft:mainfrom
matclim:addcalo

Conversation

@matclim
Copy link
Copy Markdown

@matclim matclim commented Apr 15, 2026

Please check that it works as expected, tests are passed but I am not sure what they entail

Summary by CodeRabbit

Release Notes

  • New Features

    • Calorimeter geometry is now configurable via external configuration file, replacing fixed parameters.
    • Added new detector materials: Lead, PVT, and Polystyrene.
    • Introduced modular calorimeter layer structures for enhanced flexibility.
  • Tests

    • Added validation tests for calorimeter structure and configuration parsing.

@matclim matclim requested a review from olantwin April 15, 2026 19:32
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR introduces a config-driven calorimeter geometry system. It adds material definitions (Lead, PVT, Polystyrene), defines a CalorimeterConfig struct and TOML parser, creates modular layer placement utilities, refactors CalorimeterFactory to consume the config, integrates tomlplusplus into the build system, and extends tests to validate config-driven Z-height calculations.

Changes

Calorimeter Config-Driven Geometry Refactoring

Layer / File(s) Summary
Material Definitions
src/SHiPGeometry.cpp, src/SHiPMaterials.cpp
Add Lead element (Pb, Z=82) and three new materials: Lead (11.34 g/cm³), PVT C9H10 (1.032 g/cm³), and Polystyrene C8H8 (1.05 g/cm³). Update calorimeter construction comments to reference ECAL+HCAL structure driven by calo.toml.
Configuration Data Contract
subsystems/Calorimeter/include/Calorimeter/CalorimeterConfig.h, subsystems/Calorimeter/src/CalorimeterConfig.cpp, subsystems/Calorimeter/calo.toml
Define CalorimeterConfig struct holding layer sequences, component thicknesses, module tiling, and offsets. Implement readCaloConfig(path) TOML parser using toml++ with support for legacy comma-separated integer lists and boolean/int/string conversions. Provide example calo.toml with layer-code documentation and default geometry values.
Layer Placement Utilities
subsystems/Calorimeter/include/Calorimeter/CaloBarLayer.h, subsystems/Calorimeter/src/CaloBarLayer.cpp, subsystems/Calorimeter/include/Calorimeter/CaloFibreHPLayer.h, subsystems/Calorimeter/src/CaloFibreHPLayer.cpp
Introduce CaloBarLayer::place for pitch-spaced scintillator bar arrays along X or Y axis. Introduce CaloFibreHPLayer::build for three-sublayer fibre HPL assemblies with X/Y orientation selection and computed packing parameters.
Factory Refactoring
subsystems/Calorimeter/include/Calorimeter/CalorimeterFactory.h, subsystems/Calorimeter/src/CalorimeterFactory.cpp
Accept configurable TOML path in constructor. Add public resolvedConfigPath() and static totalStackZ(cfg). Implement config-aware build() that loads geometry, validates Z-stack and module-array bounds, and delegates layer placement to new buildStack(...) helper. Remove fixed ECAL/HCAL layer constants; keep only container envelope half-sizes.
Build System
subsystems/Calorimeter/CMakeLists.txt
Fetch tomlplusplus (v3.4.0) via FetchContent. Expand Calorimeter library to multi-source target including CalorimeterConfig.cpp, CaloBarLayer.cpp, CaloFibreHPLayer.cpp. Link tomlplusplus privately (BUILD_INTERFACE only). Stage calo.toml to build and install directories. Add compile-time fallback paths. Update test working directory to ${CMAKE_CURRENT_BINARY_DIR}.
Tests
subsystems/Calorimeter/test_calorimeter.cpp
Update CalorimeterBuilds to use factory alias. Add CalorimeterHasChildren to verify container has child volumes. Add TotalStackZPositive to validate totalStackZ(cfg) equals 46.0 for minimal config with floating-point tolerance.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'updated with calorimeter, to be checked' is vague and generic, using non-descriptive terms that do not clearly convey the specific nature of the calorimeter changes being introduced. Provide a more specific and descriptive title that clearly summarizes the main change, such as 'Add calorimeter geometry implementation with TOML configuration' or 'Implement configurable calorimeter subsystem with layer support'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
subsystems/Calorimeter/test_calorimeter.cpp (1)

32-39: Make the child-count assertion stronger.

getNChildVols() >= 1 only proves the container is non-empty. This refactor can still drop most layers/modules and keep the test green. Please assert the expected count from the staged calo.cfg, or at least a lower bound derived from module_nx * module_ny * populated_layer_count.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@subsystems/Calorimeter/test_calorimeter.cpp` around lines 32 - 39, Update the
test CalorimeterHasChildren to assert a stronger expected child count: instead
of CHECK(calo->getNChildVols() >= 1u), compute or hardcode the expected lower
bound from the staged configuration and assert equality or a tighter >=, e.g.
read module_nx, module_ny and populated_layer_count (or the expected total
layers from calo.cfg) and assert calo->getNChildVols() >= module_nx * module_ny
* populated_layer_count (or == expected_total_children); modify the test to
access SHiPMaterials/CalorimeterFactory configuration values (or parse calo.cfg)
and replace the loose check on calo->getNChildVols() with the computed stronger
assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/SHiPMaterials.cpp`:
- Around line 194-208: The PVT and Polystyrene materials are being added with
raw atom counts (stoichiometry) instead of normalized mass fractions; update the
GeoMaterial creation for "PVT" and "Polystyrene" to compute mass fractions from
atomic masses (use m_elements["Carbon"] and m_elements["Hydrogen"] to get each
element's atomic weight), compute the molecule molecular weight (e.g., MW =
9*AW_C + 10*AW_H for PVT), then add normalized fractions (count*AW_element / MW)
to the GeoMaterial before lock(), and keep storing them in m_materials["PVT"]
and m_materials["Polystyrene"] as before.

In `@subsystems/Calorimeter/CMakeLists.txt`:
- Around line 34-43: The compile-time fallback CALO_CFG_DEFAULT_PATH currently
embeds the source-tree path but the installed calo.cfg is not probed; update the
build and runtime lookup so installed data is found: add a second compile
definition (or an exported header) that contains the install data directory path
(the ${CMAKE_INSTALL_DATADIR}/SHiPGeometry location) when installing the
Calorimeter target, and modify resolveCfgPath() in CalorimeterFactory.cpp to
check that install-time data-dir path in addition to the working directory and
CALO_CFG_DEFAULT_PATH (use the unique symbol CALO_CFG_DEFAULT_PATH and the
resolveCfgPath function name to locate the places to change). Ensure the
install-time path is only set when performing an install so local development
still falls back to the source-tree path.

In `@subsystems/Calorimeter/src/CalorimeterFactory.cpp`:
- Around line 261-315: The loop in CalorimeterFactory.cpp that iterates
cfg.layers2 accepts codes 1,2,5,6,7,8 but not 3 or 4, causing a runtime throw
while totalStackZ() treats 1..4 as valid; fix by either (A) adding explicit
branches for codes 3 and 4 that create the expected thin-PS scintillator layers
(mirror the pattern used for code 1/2: build an env via makeEnv and call the
appropriate placement/build routine, increment zCursor and indices like sl/gl),
or (B) validate/normalize cfg.layers2 earlier (e.g. in totalStackZ() caller or
CalorimeterFactory constructor) to reject or translate codes 3 and 4 and throw a
clear config error; reference the loop over cfg.layers2, totalStackZ(), makeEnv,
CaloBarLayer::place and CaloFibreHPLayer::build when making the change.
- Around line 83-107: Before placing modules, validate that the calorimeter
stack and tiled footprint fit inside the fixed container: compute total Z extent
using totalStackZ(cfg) and compute full X/Y extents from cfg.module_nx,
cfg.module_ny and effective pitch (use same logic as pitchX/pitchY:
cfg.module_pitch_x_mm>0 ? cfg.module_pitch_x_mm : cfg.plate_xy_mm), then compare
half-extents against s_containerHalfZ and s_containerHalfX/s_containerHalfY
respectively; if any extent exceeds the container, throw a clear runtime_error
(or appropriate config exception) with a descriptive message referencing the
offending dimension and the computed vs allowed size before the loop that calls
buildStack(containerPhys, cfg, ...).

---

Nitpick comments:
In `@subsystems/Calorimeter/test_calorimeter.cpp`:
- Around line 32-39: Update the test CalorimeterHasChildren to assert a stronger
expected child count: instead of CHECK(calo->getNChildVols() >= 1u), compute or
hardcode the expected lower bound from the staged configuration and assert
equality or a tighter >=, e.g. read module_nx, module_ny and
populated_layer_count (or the expected total layers from calo.cfg) and assert
calo->getNChildVols() >= module_nx * module_ny * populated_layer_count (or ==
expected_total_children); modify the test to access
SHiPMaterials/CalorimeterFactory configuration values (or parse calo.cfg) and
replace the loose check on calo->getNChildVols() with the computed stronger
assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 33c8398b-10cc-494d-a272-1a3039478fd2

📥 Commits

Reviewing files that changed from the base of the PR and between 23b6102 and ba663b0.

📒 Files selected for processing (11)
  • .clang-format
  • .github/dependabot.yml
  • .github/workflows/build-test.yml
  • .gitignore
  • .pre-commit-config.yaml
  • src/SHiPGeometry.cpp
  • src/SHiPMaterials.cpp
  • subsystems/Calorimeter/CMakeLists.txt
  • subsystems/Calorimeter/include/Calorimeter/CalorimeterFactory.h
  • subsystems/Calorimeter/src/CalorimeterFactory.cpp
  • subsystems/Calorimeter/test_calorimeter.cpp
💤 Files with no reviewable changes (5)
  • .github/dependabot.yml
  • .clang-format
  • .gitignore
  • .github/workflows/build-test.yml
  • .pre-commit-config.yaml

Comment thread src/SHiPMaterials.cpp Outdated
Comment thread subsystems/Calorimeter/CMakeLists.txt
Comment thread subsystems/Calorimeter/src/CalorimeterFactory.cpp Outdated
Comment thread subsystems/Calorimeter/src/CalorimeterFactory.cpp
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@subsystems/Calorimeter/src/CalorimeterFactory.cpp`:
- Around line 185-197: layerId is reset to 0 inside buildStack(), so
GeoIdentifierTag instances created by makeEnv are duplicated across modules
(mx,my) when all layers are placed under the same container; change the code so
identifiers are globally unique per module by either (A) making a per-module
parent GeoPhysVol and attach layers to that parent instead of the shared
container, or (B) incorporate module coordinates into the identifier before
creating GeoIdentifierTag (e.g. compute a base offset using mx,my and add local
layerId), updating references in build(), buildStack(), makeEnv, and any code
that reads GeoIdentifierTag so it expects the encoded identifier; ensure layerId
incrementing still produces unique values and apply same fix to the other
occurrence around lines ~293-296.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0173ed9e-1d2f-4c37-94a7-31da7b805cc1

📥 Commits

Reviewing files that changed from the base of the PR and between ba663b0 and a513030.

📒 Files selected for processing (3)
  • src/SHiPMaterials.cpp
  • subsystems/Calorimeter/CMakeLists.txt
  • subsystems/Calorimeter/src/CalorimeterFactory.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/SHiPMaterials.cpp
  • subsystems/Calorimeter/CMakeLists.txt

Comment thread subsystems/Calorimeter/src/CalorimeterFactory.cpp
@matclim
Copy link
Copy Markdown
Author

matclim commented Apr 15, 2026

I don't understand the pre-commit ci error ?

@olantwin
Copy link
Copy Markdown
Contributor

I don't understand the pre-commit ci error ?

Because you deleted the pre-commit config file (and a bunch of other files!) in your PR.

Please revert these unrelated changes. I'll review the calorimeter changes tomorrow.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@subsystems/Calorimeter/src/CalorimeterFactory.cpp`:
- Around line 269-271: The ECAL branch for code == 8 updates zCursor but does
not increment gl, while the HCAL branch increments gl; make the behavior
explicit and consistent: either add "++gl" immediately after "zCursor +=
airGapZ;" in the ECAL branch to match HCAL, or (if air gaps intentionally count
as geometry layers only for HCAL) add a short clarifying comment in both
branches explaining the difference; update the code paths handling code == 8
(zCursor, airGapZ, gl) in CalorimeterFactory.cpp accordingly so the intent is
unambiguous.
- Around line 185-200: layerId is reset per buildStack(), causing duplicate
GeoIdentifierTag values across modules; modify the code so identifiers are
globally unique by either (A) making layerId a persistent counter (e.g. a member
or static counter used by buildStack()) or (B) encoding module indices into the
id when creating GeoIdentifierTag (e.g. compute id = mx*<scale1> + my*<scale2> +
layerId where <scale1>/<scale2> are chosen to avoid collisions); update the
makeEnv lambda to use the new id calculation or the shared counter when calling
container->add(new GeoIdentifierTag(...)) and keep GeoNameTag usage (mtag)
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4ed00c30-7d24-4015-87a0-de097a6e2244

📥 Commits

Reviewing files that changed from the base of the PR and between a513030 and 3612caf.

📒 Files selected for processing (6)
  • src/SHiPGeometry.cpp
  • src/SHiPMaterials.cpp
  • subsystems/Calorimeter/CMakeLists.txt
  • subsystems/Calorimeter/include/Calorimeter/CalorimeterFactory.h
  • subsystems/Calorimeter/src/CalorimeterFactory.cpp
  • subsystems/Calorimeter/test_calorimeter.cpp
✅ Files skipped from review due to trivial changes (2)
  • src/SHiPGeometry.cpp
  • src/SHiPMaterials.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • subsystems/Calorimeter/CMakeLists.txt

Comment thread subsystems/Calorimeter/src/CalorimeterFactory.cpp
Comment thread subsystems/Calorimeter/src/CalorimeterFactory.cpp
@olantwin
Copy link
Copy Markdown
Contributor

#include "Calorimeter/CaloBarLayer.h"		
#include "Calorimeter/CaloFibreHPLayer.h"
#include "Calorimeter/CalorimeterConfig.h"

These files all seem to be missing.

@olantwin
Copy link
Copy Markdown
Contributor

Could you please add the missing files?

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@subsystems/Calorimeter/src/CaloBarLayer.cpp`:
- Around line 18-27: In CaloBarLayer::place validate inputs up-front: check
tagPrefix is non-null before calling std::string(tagPrefix) (or accept empty
string), ensure barLog is non-null before constructing GeoPhysVol(barLog), and
ensure mother is non-null before calling mother->add(...); also validate nBars>0
and handle invalid values by throwing a descriptive std::invalid_argument or
logging an error and returning early. Include clear error messages naming the
failing parameter (e.g., "CaloBarLayer::place: null tagPrefix", "null barLog",
"null mother", "nBars <= 0") so callers can diagnose the cause.

In `@subsystems/Calorimeter/src/CaloFibreHPLayer.cpp`:
- Around line 39-55: The code in CaloFibreHPLayer attaches the casing to the
geometry tree (calls to mother->add with GeoNameTag/GeoTransform/casingPhys)
before validating fiberCoreDiam_mm (rCore), which can leave a partially built
geometry on error; move the validation of rCore (the check using
fiberCoreDiam_mm and rOuter) to the top of the function or at least before any
mother->add calls, or alternatively construct the casing and fibre volumes into
local temporary GeoPhysVol objects and only call mother->add(casingPhys) and
subsequent adds after the rCore validation succeeds so an exception cannot leave
a partially mutated geometry tree.

In `@subsystems/Calorimeter/src/CalorimeterConfig.cpp`:
- Around line 92-96: The "center_stack" branch currently lowercases val without
removing a trailing semicolon, so values like "true;" become "true;" and
cfg.center_stack is false; before transforming/normalizing val in the else if
(key == "center_stack") block, strip any trailing semicolon (same normalization
used for the numeric keys), then lowercase and set cfg.center_stack based on the
cleaned string (compare to "1", "true", "yes", "on") so cfg.center_stack is
parsed correctly; locate the branch handling key == "center_stack" and apply the
same trailing-semicolon trimming used elsewhere in CalorimeterConfig.cpp.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2612f7e8-68b7-4cb6-800c-c0d880f9bc42

📥 Commits

Reviewing files that changed from the base of the PR and between f757f1c and 094d135.

📒 Files selected for processing (6)
  • subsystems/Calorimeter/include/Calorimeter/CaloBarLayer.h
  • subsystems/Calorimeter/include/Calorimeter/CaloFibreHPLayer.h
  • subsystems/Calorimeter/include/Calorimeter/CalorimeterConfig.h
  • subsystems/Calorimeter/src/CaloBarLayer.cpp
  • subsystems/Calorimeter/src/CaloFibreHPLayer.cpp
  • subsystems/Calorimeter/src/CalorimeterConfig.cpp

Comment on lines +18 to +27
void CaloBarLayer::place(GeoVPhysVol* mother,
GeoLogVol* barLog,
double pitch_mm,
int nBars,
double zCenter_mm,
const char* tagPrefix,
int layerIndex,
BarAxis axis,
const std::string& nameSuffix)
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add defensive validation for API inputs before placement.

Line 39 (std::string(tagPrefix)) and Lines 44–47 (GeoPhysVol(barLog), mother->add(...)) assume all pointers are valid. A null tagPrefix, barLog, or mother will hard-fail at runtime; nBars <= 0 silently builds nothing.

Proposed fix
 `#include` "Calorimeter/CaloBarLayer.h"
@@
 `#include` <string>
+#include <stdexcept>
@@
 void CaloBarLayer::place(GeoVPhysVol*       mother,
                          GeoLogVol*         barLog,
                          double             pitch_mm,
                          int                nBars,
@@
                          BarAxis            axis,
                          const std::string& nameSuffix)
 {
+    if (mother == nullptr) throw std::invalid_argument("CaloBarLayer::place: mother is null");
+    if (barLog == nullptr) throw std::invalid_argument("CaloBarLayer::place: barLog is null");
+    if (tagPrefix == nullptr) throw std::invalid_argument("CaloBarLayer::place: tagPrefix is null");
+    if (nBars <= 0) throw std::invalid_argument("CaloBarLayer::place: nBars must be > 0");
+
     const double pitch = pitch_mm * mm;
     const double s0    = -0.5 * (nBars - 1) * pitch;

Also applies to: 38-47

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@subsystems/Calorimeter/src/CaloBarLayer.cpp` around lines 18 - 27, In
CaloBarLayer::place validate inputs up-front: check tagPrefix is non-null before
calling std::string(tagPrefix) (or accept empty string), ensure barLog is
non-null before constructing GeoPhysVol(barLog), and ensure mother is non-null
before calling mother->add(...); also validate nBars>0 and handle invalid values
by throwing a descriptive std::invalid_argument or logging an error and
returning early. Include clear error messages naming the failing parameter
(e.g., "CaloBarLayer::place: null tagPrefix", "null barLog", "null mother",
"nBars <= 0") so callers can diagnose the cause.

Comment thread subsystems/Calorimeter/src/CaloFibreHPLayer.cpp
Comment thread subsystems/Calorimeter/src/CalorimeterConfig.cpp Outdated
@matclim
Copy link
Copy Markdown
Author

matclim commented May 2, 2026

I'm not too sure what is wrong with the ci? It says something about gersemi not finding the rust compiler?

@olantwin
Copy link
Copy Markdown
Contributor

olantwin commented May 3, 2026

I'm not too sure what is wrong with the ci? It says something about gersemi not finding the rust compiler?

That's unrelated, fixed already in FairShip, but forgot to also apply the fix here.

@olantwin
Copy link
Copy Markdown
Contributor

olantwin commented May 4, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
subsystems/Calorimeter/src/CaloFibreHPLayer.cpp (1)

31-47: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validation occurs after geometry mutation.

The casing is attached to mother at Lines 36-38 before the fibre diameter validation at Lines 44-47. If rCore <= 0 or rCore > rOuter, the function throws but leaves a partially built HPL (the casing) in the geometry tree. Move the validation to before the first mother->add(...) call.

Proposed fix
 void CaloFibreHPLayer::build(GeoVPhysVol* mother, GeoMaterial* aluminiumMat, GeoMaterial* fibreMat,
                              const std::string& layerTag, double zCenter_mm, int layerIndex,
                              double casingXY_mm, double casingZ_mm, double fiberDiam_mm,
                              double fiberCoreDiam_mm, bool fibresAlongY,
                              const std::string& nameSuffix) {
     const double casingXY = casingXY_mm * mm;
     const double casingZ = casingZ_mm * mm;

+    // ── validate fibre geometry before mutating the tree ──────────────────
+    const double rOuter = 0.5 * fiberDiam_mm * mm;
+    const double rCore = 0.5 * fiberCoreDiam_mm * mm;
+
+    if (rCore <= 0.0 || rCore > rOuter)
+        throw std::runtime_error(
+            "CaloFibreHPLayer: invalid core diameter "
+            "(must be >0 and <= outer diameter)");
+
     // ── aluminium casing ──────────────────────────────────────────────────
     auto* casingShape = new GeoBox(0.5 * casingXY, 0.5 * casingXY, 0.5 * casingZ);
     auto* casingLog = new GeoLogVol("HPL_CasingLog", casingShape, aluminiumMat);
     auto* casingPhys = new GeoPhysVol(casingLog);

     mother->add(new GeoNameTag((layerTag + "_HPL_Casing" + nameSuffix).c_str()));
     mother->add(new GeoTransform(GeoTrf::Translate3D(0.0, 0.0, zCenter_mm * mm)));
     mother->add(casingPhys);

-    // ── fibre geometry ────────────────────────────────────────────────────
-    const double rOuter = 0.5 * fiberDiam_mm * mm;
-    const double rCore = 0.5 * fiberCoreDiam_mm * mm;
-
-    if (rCore <= 0.0 || rCore > rOuter)
-        throw std::runtime_error(
-            "CaloFibreHPLayer: invalid core diameter "
-            "(must be >0 and <= outer diameter)");
-
     // GeoTube axis is Z; rotate so fibres run along Y or X
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@subsystems/Calorimeter/src/CaloFibreHPLayer.cpp` around lines 31 - 47, The
validation of fibre radii (rCore and rOuter) is happening after the casing
geometry (casingShape/casingLog/casingPhys) is already attached to the geometry
tree via mother->add; move the check for rCore <= 0 or rCore > rOuter to before
any mutation of mother (i.e., before creating/adding
casingShape/casingLog/casingPhys and before the first mother->add call) so that
the function throws without leaving a partially-built GeoPhysVol in the tree;
ensure the variables rOuter and rCore are computed prior to that validation and
only proceed to construct and add the GeoBox/GeoLogVol/GeoPhysVol and
GeoNameTag/GeoTransform when the validation passes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@subsystems/Calorimeter/test_calorimeter.cpp`:
- Line 4: The test build fails because test_calorimeter.cpp includes
"Calorimeter/CalorimeterConfig.h" but the header is not visible to the test
target; fix by wiring the Calorimeter library as a dependency or exporting its
include directories to the test target: ensure the test CMake target calls
target_link_libraries(<test target> PRIVATE|PUBLIC Calorimeter) or
target_include_directories(<test target> PRIVATE
$<TARGET_PROPERTY:Calorimeter,INTERFACE_INCLUDE_DIRECTORIES>) so that
CalorimeterConfig.h (from the Calorimeter target) is available; alternatively,
if the header is supposed to be local to the test, change the include to a
relative path to the header, but prefer linking the Calorimeter target so
symbols like CalorimeterConfig.h resolve consistently in test builds.

---

Duplicate comments:
In `@subsystems/Calorimeter/src/CaloFibreHPLayer.cpp`:
- Around line 31-47: The validation of fibre radii (rCore and rOuter) is
happening after the casing geometry (casingShape/casingLog/casingPhys) is
already attached to the geometry tree via mother->add; move the check for rCore
<= 0 or rCore > rOuter to before any mutation of mother (i.e., before
creating/adding casingShape/casingLog/casingPhys and before the first
mother->add call) so that the function throws without leaving a partially-built
GeoPhysVol in the tree; ensure the variables rOuter and rCore are computed prior
to that validation and only proceed to construct and add the
GeoBox/GeoLogVol/GeoPhysVol and GeoNameTag/GeoTransform when the validation
passes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 30df109d-6c5d-4fcf-9726-2f8c29b95dc2

📥 Commits

Reviewing files that changed from the base of the PR and between f757f1c and 8950b1f.

📒 Files selected for processing (12)
  • src/SHiPGeometry.cpp
  • src/SHiPMaterials.cpp
  • subsystems/Calorimeter/CMakeLists.txt
  • subsystems/Calorimeter/include/Calorimeter/CaloBarLayer.h
  • subsystems/Calorimeter/include/Calorimeter/CaloFibreHPLayer.h
  • subsystems/Calorimeter/include/Calorimeter/CalorimeterConfig.h
  • subsystems/Calorimeter/include/Calorimeter/CalorimeterFactory.h
  • subsystems/Calorimeter/src/CaloBarLayer.cpp
  • subsystems/Calorimeter/src/CaloFibreHPLayer.cpp
  • subsystems/Calorimeter/src/CalorimeterConfig.cpp
  • subsystems/Calorimeter/src/CalorimeterFactory.cpp
  • subsystems/Calorimeter/test_calorimeter.cpp
✅ Files skipped from review due to trivial changes (1)
  • src/SHiPMaterials.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/SHiPGeometry.cpp
  • subsystems/Calorimeter/CMakeLists.txt

// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) CERN for the benefit of the SHiP Collaboration

#include "Calorimeter/CalorimeterConfig.h"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Build blocker: CalorimeterConfig.h is not resolvable in this test target.

Static analysis reports a hard compile error here ('Calorimeter/CalorimeterConfig.h' file not found). Please fix the target include/export wiring (preferred) or adjust the include path so this header resolves consistently in test builds.

🧰 Tools
🪛 Clang (14.0.6)

[error] 4-4: 'Calorimeter/CalorimeterConfig.h' file not found

(clang-diagnostic-error)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@subsystems/Calorimeter/test_calorimeter.cpp` at line 4, The test build fails
because test_calorimeter.cpp includes "Calorimeter/CalorimeterConfig.h" but the
header is not visible to the test target; fix by wiring the Calorimeter library
as a dependency or exporting its include directories to the test target: ensure
the test CMake target calls target_link_libraries(<test target> PRIVATE|PUBLIC
Calorimeter) or target_include_directories(<test target> PRIVATE
$<TARGET_PROPERTY:Calorimeter,INTERFACE_INCLUDE_DIRECTORIES>) so that
CalorimeterConfig.h (from the Calorimeter target) is available; alternatively,
if the header is supposed to be local to the test, change the include to a
relative path to the header, but prefer linking the Calorimeter target so
symbols like CalorimeterConfig.h resolve consistently in test builds.

@olantwin
Copy link
Copy Markdown
Contributor

olantwin commented May 8, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@olantwin
Copy link
Copy Markdown
Contributor

olantwin commented May 8, 2026

@matclim could you please update the global and subsystem readme?

@olantwin
Copy link
Copy Markdown
Contributor

olantwin commented May 8, 2026

Could you please update the commit message or suggest a commit message if you'd like this to be squashed?

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
subsystems/Calorimeter/src/CaloBarLayer.cpp (1)

18-40: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Null-pointer and invalid-input validation still absent (previously raised).

The past review flagged that mother, barLog, and tagPrefix are dereferenced at lines 33, 36-39 without null-checks, and that nBars <= 0 is silently ignored. The code is unchanged in this regard.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@subsystems/Calorimeter/src/CaloBarLayer.cpp` around lines 18 - 40, The
CaloBarLayer::place function must validate inputs before use: check that mother,
barLog, and tagPrefix are not null and that nBars > 0; if any check fails,
either throw a std::invalid_argument (or log and return) with a clear message
referencing the failing parameter. Add these guards at the top of
CaloBarLayer::place (before any dereferencing or loop) and include the function
name in the error text so callers can trace failures; keep existing behavior
unchanged otherwise (still create GeoNameTag/GeoTransform/GeoPhysVol when inputs
are valid).
🧹 Nitpick comments (1)
subsystems/Calorimeter/src/CaloBarLayer.cpp (1)

6-10: ⚡ Quick win

Add a direct #include for GeoVPhysVol.h.

mother->add(...) requires the full definition of GeoVPhysVol, which is currently satisfied only through a transitive include via GeoPhysVol.h. Any header reorganisation in GeoModelKernel would silently break this TU.

♻️ Proposed fix
 `#include` <GeoModelKernel/GeoLogVol.h>
 `#include` <GeoModelKernel/GeoNameTag.h>
 `#include` <GeoModelKernel/GeoPhysVol.h>
 `#include` <GeoModelKernel/GeoTransform.h>
+#include <GeoModelKernel/GeoVPhysVol.h>
 `#include` <GeoModelKernel/Units.h>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@subsystems/Calorimeter/src/CaloBarLayer.cpp` around lines 6 - 10, The
translation unit uses GeoVPhysVol (via calls like mother->add(...)) but only
relies on a transitive include through GeoPhysVol.h; add a direct `#include` for
GeoVPhysVol.h so the full definition of GeoVPhysVol is guaranteed (e.g., insert
`#include` <GeoModelKernel/GeoVPhysVol.h>) to avoid breakage if GeoModelKernel
headers are reorganized.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@subsystems/Calorimeter/src/CalorimeterConfig.cpp`:
- Around line 152-155: The code currently assigns cfg.module_nx and
cfg.module_ny by truncating the numeric result of readNumeric; instead, when
table["module_nx"] or table["module_ny"] is present call readNumeric to get a
numeric value, verify it is an integer (e.g. value == std::floor(value)) and
strictly positive (> 0), and if the check fails reject the config by throwing or
returning an error rather than casting; update the parsing code that references
table["module_nx"], table["module_ny"], cfg.module_nx, cfg.module_ny and
readNumeric to perform these checks and produce a clear error message on
failure.

---

Duplicate comments:
In `@subsystems/Calorimeter/src/CaloBarLayer.cpp`:
- Around line 18-40: The CaloBarLayer::place function must validate inputs
before use: check that mother, barLog, and tagPrefix are not null and that nBars
> 0; if any check fails, either throw a std::invalid_argument (or log and
return) with a clear message referencing the failing parameter. Add these guards
at the top of CaloBarLayer::place (before any dereferencing or loop) and include
the function name in the error text so callers can trace failures; keep existing
behavior unchanged otherwise (still create GeoNameTag/GeoTransform/GeoPhysVol
when inputs are valid).

---

Nitpick comments:
In `@subsystems/Calorimeter/src/CaloBarLayer.cpp`:
- Around line 6-10: The translation unit uses GeoVPhysVol (via calls like
mother->add(...)) but only relies on a transitive include through GeoPhysVol.h;
add a direct `#include` for GeoVPhysVol.h so the full definition of GeoVPhysVol is
guaranteed (e.g., insert `#include` <GeoModelKernel/GeoVPhysVol.h>) to avoid
breakage if GeoModelKernel headers are reorganized.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b978e91c-2495-42c8-87af-2a4ca440edf1

📥 Commits

Reviewing files that changed from the base of the PR and between 8950b1f and 374795c.

📒 Files selected for processing (12)
  • src/SHiPMaterials.cpp
  • subsystems/Calorimeter/CMakeLists.txt
  • subsystems/Calorimeter/calo.toml
  • subsystems/Calorimeter/include/Calorimeter/CaloBarLayer.h
  • subsystems/Calorimeter/include/Calorimeter/CaloFibreHPLayer.h
  • subsystems/Calorimeter/include/Calorimeter/CalorimeterConfig.h
  • subsystems/Calorimeter/include/Calorimeter/CalorimeterFactory.h
  • subsystems/Calorimeter/src/CaloBarLayer.cpp
  • subsystems/Calorimeter/src/CaloFibreHPLayer.cpp
  • subsystems/Calorimeter/src/CalorimeterConfig.cpp
  • subsystems/Calorimeter/src/CalorimeterFactory.cpp
  • subsystems/Calorimeter/test_calorimeter.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • subsystems/Calorimeter/CMakeLists.txt
  • src/SHiPMaterials.cpp
  • subsystems/Calorimeter/src/CalorimeterFactory.cpp

Comment thread subsystems/Calorimeter/src/CalorimeterConfig.cpp Outdated
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.

2 participants