Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GeoShapes to DetectorVolumes and GeoMaterial Converters #3268

Closed
wants to merge 37 commits into from

Conversation

Matthewharri
Copy link
Contributor

@Matthewharri Matthewharri commented Jun 7, 2024

This PR introduces a converter to convert geoShapes to DetectorVolumes. Some of the shapes added are very simple converters, i.e. simple bounding boxes which will probably be changed later on. I also bump the GeoModel version from 4.6.0 to 6.0.0 since Athena is using a much newer version. I also change (with the help of @paulgessinger) how cmake looks for the system installation of GeoModel.

I also include a way to convert GeoMaterial to Acts::Material

@junggjo9

blocked by

Summary by CodeRabbit

  • New Features

    • Introduced new functions for converting GeoModel shapes into detector volumes and for converting GeoMaterial objects into Acts materials.
    • Added support for multiple geometric shapes in the conversion process, enhancing compatibility with the Acts framework.
  • Bug Fixes

    • Improved error handling for unsupported geometric shapes during conversion.
  • Documentation

    • New header files added with detailed function declarations and usage instructions.

@github-actions github-actions bot added Infrastructure Changes to build tools, continous integration, ... Component - Plugins Affects one or more Plugins labels Jun 7, 2024
@Matthewharri Matthewharri changed the title Feat: Convert geoShapes to DetectorVolumes feat: Convert geoShapes to DetectorVolumes Jun 7, 2024
Copy link

github-actions bot commented Jun 7, 2024

📊: Physics performance monitoring for 7608689

Full contents

physmon summary

Copy link

codecov bot commented Jun 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 47.31%. Comparing base (859e7af) to head (6b016ca).
Report is 43 commits behind head on main.

Current head 6b016ca differs from pull request most recent head cd12571

Please upload reports for the commit cd12571 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3268      +/-   ##
==========================================
- Coverage   47.37%   47.31%   -0.06%     
==========================================
  Files         511      512       +1     
  Lines       30249    30437     +188     
  Branches    14677    14795     +118     
==========================================
+ Hits        14329    14400      +71     
- Misses       5386     5404      +18     
- Partials    10534    10633      +99     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AJPfleger AJPfleger added this to the next milestone Jun 7, 2024
Copy link
Member

@paulgessinger paulgessinger left a comment

Choose a reason for hiding this comment

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

Generally, this seems sensible to me.

  1. Do we have any way to test this in an isolated way in CI?
  2. Medium term, I'll likely want to reuse the volume bounds creation, as that will translate 1:1 into the Gen3 geometry model.

CMakeLists.txt Outdated Show resolved Hide resolved
Plugins/GeoModel/src/GeoModelToDetVol.cpp Outdated Show resolved Hide resolved
Plugins/GeoModel/src/GeoModelToDetVol.cpp Outdated Show resolved Hide resolved
@Matthewharri Matthewharri changed the title feat: Convert geoShapes to DetectorVolumes feat: GeoShapes to DetectorVolumes and GeoMaterial Converters Jul 4, 2024
@github-actions github-actions bot added the Infrastructure Changes to build tools, continous integration, ... label Aug 2, 2024
@Matthewharri
Copy link
Contributor Author

Apparently there was, but I think it should be fixed now.

@Matthewharri
Copy link
Contributor Author

Ok, So this is now failing because there are warnings in the geomodel compilation, and it is treating those as errors. Any suggestions @noemina or @andiwand

@andiwand
Copy link
Contributor

andiwand commented Aug 2, 2024

Ok, So this is now failing because there are warnings in the geomodel compilation, and it is treating those as errors. Any suggestions @noemina or @andiwand

Looking at the compile command

ccache /usr/bin/c++ -DGeoModelKernel_EXPORTS -I/__w/acts/acts/build/_deps/geomodel-src/GeoModelCore/GeoModelKernel -I/__w/acts/acts/build/_deps/geomodel-src/GeoModelCore/GeoGenericFunctions -isystem /__w/acts/acts/cmake/assert_include -isystem /usr/include/eigen3 -Wall -Wextra -Wpedantic -Wshadow -Wno-unused-local-typedefs -Werror -Wno-deprecated-declarations -O3 -DNDEBUG -std=c++20 -fPIC -MD -MT _deps/geomodel-build/GeoModelCore/GeoModelKernel/CMakeFiles/GeoModelKernel.dir/src/GeoNodeAction.cxx.o -MF _deps/geomodel-build/GeoModelCore/GeoModelKernel/CMakeFiles/GeoModelKernel.dir/src/GeoNodeAction.cxx.o.d -o _deps/geomodel-build/GeoModelCore/GeoModelKernel/CMakeFiles/GeoModelKernel.dir/src/GeoNodeAction.cxx.o -c /__w/acts/acts/build/_deps/geomodel-src/GeoModelCore/GeoModelKernel/src/GeoNodeAction.cxx

It seems that GeoModel is not included using -isystem but just -I which will cause the compiler to raise warnings in the included files. This means GeoModel is not integrated correctly in ACTS via CMake

@andiwand andiwand added the 🛑 blocked This item is blocked by another item label Aug 6, 2024
@andiwand
Copy link
Contributor

andiwand commented Aug 6, 2024

This is blocked by #3476 which is blocked by having an external build for GeoModel

paulgessinger added a commit that referenced this pull request Aug 14, 2024
Bumps GeoModel version and deals with the necessary changes. This is a
subset of #3268 which isolates
the version change and tackles the CI errors faced there.

---------

Co-authored-by: Paul Gessinger <[email protected]>
@github-actions github-actions bot removed the Infrastructure Changes to build tools, continous integration, ... label Aug 19, 2024
@Matthewharri
Copy link
Contributor Author

With #3476 merged in, the issue with the builds is fixed. Is this now good to be merged in? @noemina or @andiwand

Copy link
Contributor

@andiwand andiwand left a comment

Choose a reason for hiding this comment

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

A couple of nitpicks from my side. Otherwise looks good to go

@Matthewharri
Copy link
Contributor Author

@andiwand Ok, I addressed your things, so assuming nothing got messed up the CI should be fine, and then this is good to go

@andiwand andiwand removed the 🛑 blocked This item is blocked by another item label Aug 19, 2024
andiwand
andiwand previously approved these changes Aug 19, 2024
@andiwand
Copy link
Contributor

should we override sonarcloud in this case @paulgessinger ?

Copy link

sonarcloud bot commented Aug 19, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 25%)
0.0% Line Coverage on New Code (required ≥ 50%)

See analysis details on SonarCloud

@github-actions github-actions bot added the Stale label Sep 18, 2024
@github-actions github-actions bot removed the Stale label Oct 30, 2024
@github-actions github-actions bot added the Stale label Nov 29, 2024
Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

New source and header files added to the ActsPluginGeoModel library. Two source files, GeoModelToDetectorVolume.cpp and GeoModelMaterialConverter.cpp, are introduced for geometric conversions and material handling. Corresponding header files define the functions geoMaterialConverter and convertVolume, which facilitate the conversion of materials and shapes within the Acts framework. No other configurations or modifications made.

Changes

File Change Summary
Plugins/GeoModel/CMakeLists.txt Added source files: GeoModelToDetectorVolume.cpp, GeoModelMaterialConverter.cpp to the ActsPluginGeoModel library.
Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp New header file added with function geoMaterialConverter to convert GeoMaterial to Acts::Material.
Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp New header file added with function convertVolume to convert GeoShape to DetectorVolume.
Plugins/GeoModel/src/GeoModelMaterialConverter.cpp New source file added with implementation of geoMaterialConverter.
Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp New source file added with implementation of convertVolume for various geometric shapes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GeoModel
    participant DetectorVolume

    User->>GeoModel: Request material conversion
    GeoModel->>GeoModel: geoMaterialConverter(GeoMaterial)
    GeoModel-->>User: Return Acts::Material

    User->>GeoModel: Request volume conversion
    GeoModel->>GeoModel: convertVolume(GeoShape)
    GeoModel->>DetectorVolume: Create DetectorVolume
    GeoModel-->>User: Return DetectorVolume
Loading

In the realm of code, new functions arise,
Converting shapes and materials, oh what a surprise!
With geoMaterialConverter, and convertVolume too,
The Acts framework grows, as we bid adieu!
🌌✨ A galaxy of changes, bright and new!

Warning

Rate limit exceeded

@github-actions[bot] has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 29 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8e768 and 7608689.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

🧹 Outside diff range and nitpick comments (11)
Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp (3)

13-13: Specify namespace for forward declaration, hmmmm.

Improve clarity and prevent potential naming conflicts, we must. Add namespace specification to forward declaration, I suggest.

-class GeoMaterial;
+namespace GeoModel { class GeoMaterial; }

17-21: Documentation incomplete, it is. Missing parameter details, I sense.

Document the useMolarDensity parameter and its effects, we must. Help users understand the conversion behavior better, this will.

 /// @brief Convert GeoMaterial to Acts::Material
 ///
 /// @param gm The GeoMaterial to be converted
+/// @param useMolarDensity Whether to use molar density in conversion
 /// @return the Acts::Material

21-22: Excessive indentation, I observe.

Align parameters with more conventional spacing, we should. Improve readability, this will.

-Material geoMaterialConverter(const GeoMaterial* gm,
-                              bool useMolarDensity = true);
+Material geoMaterialConverter(const GeoMaterial* gm,
+                            bool useMolarDensity = true);
Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp (1)

19-26: Incomplete documentation and specifications, the Force reveals.

Improve the documentation and function specifications, we must:

  • Missing @param for 'name' parameter, it is
  • Return value description, needs more detail it does
  • Thread safety and ownership transfer, unclear they remain

Apply these changes, you should:

 /// @brief Convert a GeoModel shape to a DetectorVolume
 ///
 /// @param shape the GeoModel shape
+ /// @param context the geometry context
+ /// @param name the volume name
 /// @param transform the transform to be applied
- /// @return the DetectorVolume
+ /// @return shared pointer to the created DetectorVolume
+ ///
+ /// @note Thread-safe: yes
+ /// @note The returned volume takes ownership of all created components
 std::shared_ptr<Experimental::DetectorVolume> convertVolume(
     const GeometryContext& context, const GeoShape* shape,
-    const std::string& name, const GeoTrf::Transform3D transform);
+    const std::string& name, const GeoTrf::Transform3D transform) noexcept;
Plugins/GeoModel/src/GeoModelMaterialConverter.cpp (3)

18-18: Document the density conversion factor, we must!

Mysterious, this conversion factor is. Add a comment explaining its purpose and units, you should.

+  // Convert density from GeoModel units (g) to Acts units (g/cm³)
   constexpr double densityCnvFactor = 1. / GeoModelKernelUnits::gram;

24-32: Improve the loop's readability and safety, we shall!

More descriptive comments and range-based loop, beneficial they are. Magic numbers, avoid we must.

-  // Get number elements
-  int numberOfElements = gm->getNumElements();
-  // Loop
-  for (int iEl = 0; iEl < numberOfElements; ++iEl) {
-    const GeoElement* geoEl = gm->getElement(iEl);
-    double fraction = gm->getFraction(iEl);
+  // Accumulate atomic mass and number weighted by element fractions
+  const auto numberOfElements = gm->getNumElements();
+  for (auto iEl = 0; iEl < numberOfElements; ++iEl) {
+    const auto* geoEl = gm->getElement(iEl);
+    const auto fraction = gm->getFraction(iEl);

16-38: Consider thread safety and caching, you must!

Thread-safe, this converter is, as no shared state it maintains. Yet, for performance, cache frequently converted materials, you might. A singleton cache, helpful it could be, if same materials converted often they are.

Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp (4)

83-83: Careful with floating-point comparisons, you must be.

Directly comparing floating-point values using <=, you are. Due to precision errors, unexpected results may occur. Use an epsilon tolerance for comparison, consider.

Apply this diff to adjust the comparison:

-          if (x1 <= x2) {
+          if (x1 <= x2 + epsilon) {

Define epsilon as a small value appropriately.


159-164: Consistent, the conditional structure is not.

An if condition outside the else if chain, there is. Include it within the chain, you should, for consistency and readability.

Apply this diff to adjust the conditional structure:

-  if (shape->typeID() == GeoShapeShift::getClassTypeID()) {
+  else if (shape->typeID() == GeoShapeShift::getClassTypeID()) {

129-129: Improve the error message, you should.

More informative, the error message could be. Include dimensions or shape details, you might, to aid in debugging.

Apply this diff to enhance the error message:

-      throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed");
+      throw std::runtime_error("FATAL: Translating GeoTrd to ACTS failed. Unsupported configuration with x1 != x2 and y1 != y2.");

165-165: Include the shape typeID in the error message, you should.

When throwing for unsupported shapes, include shape->typeID() in the message, you should, to aid in debugging.

Apply this diff to enhance the error message:

-  throw std::runtime_error("FATAL: Unsupported GeoModel shape");
+  throw std::runtime_error("FATAL: Unsupported GeoModel shape with typeID: " + std::to_string(shape->typeID()));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8e768 and 7608689.

📒 Files selected for processing (5)
  • Plugins/GeoModel/CMakeLists.txt (1 hunks)
  • Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp (1 hunks)
  • Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp (1 hunks)
  • Plugins/GeoModel/src/GeoModelMaterialConverter.cpp (1 hunks)
  • Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp (1 hunks)
🔇 Additional comments (6)
Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelMaterialConverter.hpp (1)

21-22: Verify the usage of this converter function across the codebase, we must.

Search for potential callers and ensure consistent usage patterns, we shall.

Plugins/GeoModel/include/Acts/Plugins/GeoModel/GeoModelToDetectorVolume.hpp (1)

1-9: Correct, the header protection is, hmmmm.

Strong with the Force, this header protection is. Well-structured license header, I see.

Plugins/GeoModel/CMakeLists.txt (2)

Line range hint 29-35: Sufficient these dependencies are, but verify we must!

Public dependencies declared correctly they are:

  • ActsCore
  • GeoModelCore::GeoModelKernel
  • GeoModelIO::GeoModelDBManager
  • GeoModelIO::GeoModelRead

But check for version compatibility, we should!

✅ Verification successful

Verified the dependencies are, clear version requirements we found!

Found the GeoModel version requirements we have:

  • GeoModelCore 6.3.0 required it is
  • GeoModelIO 6.3.0 required it is
  • Properly managed through CMake variable _acts_geomodel_version these dependencies are

In harmony with the Force these dependencies are, properly declared and versioned they remain. No disturbance in the version compatibility I sense.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check GeoModel version requirements

# Search for version requirements in CMake files
echo "=== GeoModel version requirements, searching for we are ==="
rg -t cmake "find_package.*GeoModel" || echo "No explicit version requirements found, concerning this is"

Length of output: 341


Script:

#!/bin/bash
# Search for the value of _acts_geomodel_version variable
echo "=== The GeoModel version variable, seeking we are ==="
rg -t cmake "_acts_geomodel_version" -B 2 -A 2

# Check if there are any other version-related variables or requirements
echo -e "\n=== Additional version requirements, searching for we are ==="
rg -t cmake "GeoModel.*VERSION|VERSION.*GeoModel"

Length of output: 921


8-8: Hmmmm, proper additions these source files are!

Align with the PR objectives, these new files do. For shape and material conversion, essential they are.

Verify the dependencies we must, hmmmm:

Also applies to: 12-12

✅ Verification successful

In balance, the dependencies are, young padawan!

Examined the Force flowing through the code, I have. The dependencies in CMakeLists.txt, sufficient they are! Hmmmm.

  • ActsCore provides the geometry and material components, it does
  • GeoModelKernel supports all shape conversions, yes
  • GeoModelDBManager and GeoModelRead for proper functionality, present they are

All required headers in the new files, properly included they are:

  • For shape conversion, geometry bounds and navigation, the Force is strong
  • For material conversion, the necessary components present they are

No disturbance in the Force, I sense. The CMake configuration, complete and balanced it is!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if new files have additional dependencies

# Search for includes in new files
echo "=== Dependencies in new files, searching for we are ==="
rg -t cpp --no-filename "^#include" src/GeoModelToDetectorVolume.cpp src/GeoModelMaterialConverter.cpp || echo "No includes found, suspicious this is"

Length of output: 457


Script:

#!/bin/bash
# Search for the correct path of source files, we must
echo "=== Search for the source files location, we shall ==="
fd -t f "GeoModelToDetectorVolume.cpp|GeoModelMaterialConverter.cpp"

echo "=== Structure of the plugin directory, examine we must ==="
ls -R Plugins/GeoModel/

Length of output: 1672


Script:

#!/bin/bash
# Examine the includes in the correct path, we must
echo "=== Dependencies in GeoModelToDetectorVolume.cpp, reveal we shall ==="
rg -t cpp --no-filename "^#include" Plugins/GeoModel/src/GeoModelToDetectorVolume.cpp

echo "=== Dependencies in GeoModelMaterialConverter.cpp, investigate we must ==="
rg -t cpp --no-filename "^#include" Plugins/GeoModel/src/GeoModelMaterialConverter.cpp

echo "=== CMake dependencies, check we shall ==="
cat Plugins/GeoModel/CMakeLists.txt

Length of output: 2826

Plugins/GeoModel/src/GeoModelMaterialConverter.cpp (2)

1-15: Correct, the header organization is, hmmmm!

Well-structured, the includes are. In proper order, they flow - from local to external dependencies, they do.


33-38: Wise choice of factory methods, this is!

Clear and concise, the creation of Material objects is. Proper use of factory methods, you have shown.

Comment on lines +11 to +15
#include "Acts/Detector/DetectorVolume.hpp"

#include "GeoModelKernel/GeoDefinitions.h"

class GeoShape;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing includes, I sense.

Required for your journey, these includes are:

  • GeometryContext, used in function signature it is
  • Transform3D from GeoTrf namespace, needed it appears

Add these includes, you must:

#include "Acts/Detector/DetectorVolume.hpp"
+#include "Acts/Geometry/GeometryContext.hpp"

#include "GeoModelKernel/GeoDefinitions.h"
+#include "GeoModelKernel/GeoTrf.h"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#include "Acts/Detector/DetectorVolume.hpp"
#include "GeoModelKernel/GeoDefinitions.h"
class GeoShape;
#include "Acts/Detector/DetectorVolume.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "GeoModelKernel/GeoDefinitions.h"
#include "GeoModelKernel/GeoTrf.h"
class GeoShape;

Comment on lines +24 to +26
std::shared_ptr<Experimental::DetectorVolume> convertVolume(
const GeometryContext& context, const GeoShape* shape,
const std::string& name, const GeoTrf::Transform3D transform);
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Limited shape handling, I sense in this code.

In GeoModelToDetectorVolume.cpp, handle only these shapes, the implementation does:

  • GeoShapeUnion
  • GeoShapeSubtraction
  • GeoPcon
  • GeoShapeShift

But many more shapes in the GeoModel universe, there are. A default error throwing for unsupported shapes, I see. Dangerous this path is.

  • Missing handling for basic shapes like boxes, tubes, and trapezoids, the implementation is
  • Default error message "FATAL: Unsupported GeoModel shape" provides little guidance to young padawans
  • Consider implementing converters for all fundamental GeoModel shapes, you must
🔗 Analysis chain

Verify shape handling completeness, we must.

Ensure that all GeoModel shapes, handled they are. Search the implementation, we shall.


The search continues, young padawan. More information about shape handling, we must find. The implementation of convertVolume and shape converters, reveal they will.


Hmm, elusive the implementation is. Through different paths, search we must. The Force guides us to look deeper into the GeoModel plugin's implementation files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all GeoShape derived classes and verify implementation handles them

# Find all GeoShape derived classes
echo "=== GeoShape derived classes ==="
ast-grep --pattern 'class $_ : public GeoShape'

# Find shape handling in implementation
echo -e "\n=== Shape handling in implementation ==="
rg "dynamic_cast.*GeoShape" -A 5

Length of output: 2378


Script:

#!/bin/bash
# Search for implementation of convertVolume
echo "=== Implementation of convertVolume ==="
rg "convertVolume.*GeoShape.*transform" -A 20

# Find all shape converters
echo -e "\n=== Shape converters ==="
fd "converter" --exec rg "class.*Converter" {}

Length of output: 443


Script:

#!/bin/bash
# Search for implementation files in GeoModel plugin
echo "=== GeoModel implementation files ==="
fd "GeoModelTo.*cpp$"

# Search for shape handling in implementation
echo -e "\n=== Shape handling patterns ==="
rg "GeoShape.*\{" -A 10 --type cpp

Length of output: 9474

Comment on lines +16 to +22
Acts::Material Acts::GeoModel::geoMaterialConverter(const GeoMaterial* gm,
bool useMolarDensity) {
constexpr double densityCnvFactor = 1. / GeoModelKernelUnits::gram;
double x0 = gm->getRadLength();
double l0 = gm->getIntLength();
double density = gm->getDensity() * densityCnvFactor;
double A = 0.;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Validate the input pointer, we must!

Dangerous, null pointers are. Check them, we should, before proceeding.

 Acts::Material Acts::GeoModel::geoMaterialConverter(const GeoMaterial* gm,
                                                     bool useMolarDensity) {
+  if (gm == nullptr) {
+    throw std::invalid_argument("Null GeoMaterial pointer provided");
+  }
   constexpr double densityCnvFactor = 1. / GeoModelKernelUnits::gram;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Acts::Material Acts::GeoModel::geoMaterialConverter(const GeoMaterial* gm,
bool useMolarDensity) {
constexpr double densityCnvFactor = 1. / GeoModelKernelUnits::gram;
double x0 = gm->getRadLength();
double l0 = gm->getIntLength();
double density = gm->getDensity() * densityCnvFactor;
double A = 0.;
Acts::Material Acts::GeoModel::geoMaterialConverter(const GeoMaterial* gm,
bool useMolarDensity) {
if (gm == nullptr) {
throw std::invalid_argument("Null GeoMaterial pointer provided");
}
constexpr double densityCnvFactor = 1. / GeoModelKernelUnits::gram;
double x0 = gm->getRadLength();
double l0 = gm->getIntLength();
double density = gm->getDensity() * densityCnvFactor;
double A = 0.;

Comment on lines +67 to +74
double xmin{0}, xmax{0}, ymin{0}, ymax{0}, zmin{0}, zmax{0};
brep->extent(xmin, ymin, zmin, xmax, ymax, zmax);
std::shared_ptr<CuboidVolumeBounds> bounds =
std::make_shared<CuboidVolumeBounds>(
(xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2);
return Experimental::DetectorVolumeFactory::construct(
portalGenerator, context, name, transform, bounds,
Experimental::tryAllPortalsAndSurfaces());
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor the duplicated code, you should.

Duplicate code for calculating CuboidVolumeBounds from shape extents, I see. A helper function, create, to improve maintainability and reduce repetition.

@github-actions github-actions bot removed the Stale label Nov 30, 2024
@andiwand
Copy link
Contributor

how do we proceed with this @Matthewharri @noemina @junggjo9 @paulgessinger ?

@Matthewharri
Copy link
Contributor Author

I will close this as it was merged in with a different PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Plugins Affects one or more Plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants