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: introduce G4Trap converter #4072

Merged

Conversation

asalzburger
Copy link
Contributor

@asalzburger asalzburger commented Feb 5, 2025

This introduces the G4Trap converter and is fully based not he work of Lorenzo Damenti ([[email protected]]

--- END COMMIT MESSAGE ---

Any further description goes here, @-mentions are ok here!

  • Use a conventional commits prefix: quick summary
    • We mostly use feat, fix, refactor, docs, chore and build types.
  • A milestone will be assigned by one of the maintainers

Summary by CodeRabbit

  • New Features

    • Expanded trapezoidal shape conversion to support G4Trap, enhancing overall geometric processing.
  • Tests

    • Added new test case for G4Trap conversion and updated existing test case for G4Trd to ensure reliable performance and validate the improved conversion functionality.

@asalzburger asalzburger added this to the next milestone Feb 5, 2025
Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

Enhanced, the support for converting trapezoid shapes has been. A new method for G4Trap objects, alongside the modified method for G4Trd, the Geant4ShapeConverter now includes. Documentation, method signatures, and test cases updated, they have been, to integrate the new functionality. Added, a dynamic cast for G4Trap within the physical volume converter is. Verify the conversion process for both shape types, the tests now do.

Changes

File(s) Change Summary
Plugins/Geant4/.../Geant4Converters.hpp Updated trapezoidBounds method documentation; method signature updated for G4Trd; new method added for converting G4Trap shapes.
Plugins/Geant4/.../Geant4Converters.cpp Added new method implementation to convert G4Trap shapes; updated comments and dynamic cast in Geant4PhysicalVolumeConverter to handle G4Trap objects similarly to G4Trd.
Tests/UnitTests/Plugins/Geant4/Geant4ConvertersTests.cpp Renamed test case for G4Trd conversion; added new test case to verify trapezoid bounds conversion for G4Trap shapes with proper assertions.

Sequence Diagram(s)

sequenceDiagram
    participant PVC as PhysicalVolumeConverter
    participant SC as Geant4ShapeConverter
    participant G4 as G4 Shape Object

    PVC->>SC: Request trapezoid bounds conversion
    alt Shape is G4Trap
        SC-->>PVC: Returns bounds for G4Trap
    else Shape is G4Trd
        SC-->>PVC: Returns bounds for G4Trd
    end
Loading

Suggested labels

automerge

Suggested reviewers

  • niermann999

Poem

In the realm of shapes, wise we become,
New methods arise, like the morning sun.
G4Trap and G4Trd, together they play,
Converting the bounds in a most clever way.
Change, embrace we must, as the Force guides our day.
A journey of code, we celebrate in our own Yoda way!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92bd0fa and f36c136.

📒 Files selected for processing (2)
  • Plugins/Geant4/src/Geant4Converters.cpp (4 hunks)
  • Tests/UnitTests/Plugins/Geant4/Geant4ConvertersTests.cpp (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Tests/UnitTests/Plugins/Geant4/Geant4ConvertersTests.cpp
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: CI Bridge / lcg_106a: [alma9, gcc13]
  • GitHub Check: CI Bridge / lcg_105: [alma9, clang16]
  • GitHub Check: CI Bridge / lcg_105: [alma9, gcc13]
  • GitHub Check: CI Bridge / linux_ubuntu_2204_clang
  • GitHub Check: merge-sentinel
  • GitHub Check: CI Bridge / linux_ubuntu_2204
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: CI Bridge / build_exatrkx_cpu
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: CI Bridge / build_gnn_tensorrt
  • GitHub Check: lint
  • GitHub Check: docs
🔇 Additional comments (4)
Plugins/Geant4/src/Geant4Converters.cpp (4)

41-41: Correct, the header inclusion is!

In proper order and placement, the G4Trap.hh header stands.


289-291: Wise handling of errors, this is!

Proper exception throwing when conversion fails, implemented it is.


396-411: Well structured, the G4Trap conversion is!

Follow the established pattern for surface conversion, it does. Proper error handling and material assignment, implemented they are.


246-250: Verify the geometry calculations, we must!

Complex transformations for trapezoid dimensions, these are. Ensure correctness of angle calculations in lines 247 and 249, you should.

✅ Verification successful

🌐 Web query:

What are the coordinate transformations for G4Trap in Geant4?

💡 Result:

In Geant4, **G4Trap** coordinate transformations involve rotations and translations defined relative to its mother volume’s local coordinate system during placement via `G4PVPlacement`. Here’s how it works:

---

## Coordinate System Rules
1. **Mother Volume Reference**  
   - The position (`G4ThreeVector`) and rotation (`G4RotationMatrix`) of a `G4Trap` are specified in its mother volume’s local coordinate frame[1][3][5].
   - Rotations use `G4RotationMatrix`, which wraps CLHEP’s `HepRotation` class for 3D rotations[1].

2. **Transformation Order**  
   - **Rotation** is applied first (relative to the mother’s frame), followed by **translation**[3][5].
   - Example placement code:
     ```cpp
     G4PVPlacement(
       new G4RotationMatrix(rotX, rotY, rotZ), // Rotation
       G4ThreeVector(x, y, z),                 // Translation
       logicalVolume,                          // Daughter (G4Trap)
       "Name",
       motherLogical,
       false,
       copyNo
     );
     ```

---

## Key Considerations for G4Trap
- **Origin Alignment**:  
  By default, `G4Trap` assumes symmetry around its local origin. If vertices are manually defined (via `G4TrapC` constructor), they must satisfy centering checks:
  ```cpp
  // Vertices must align such that center-of-gravity line crosses origin[10]
  if (!(pt[0].z() < 0 && pt[0].z() == pt[1].z() ...))
    throw error;
  ```
  Misalignment may require explicit translation adjustments[4].

- **Visualization**:  
  Use `/vis/scene/add/localAxes` (Geant4 ≥ v11) to inspect local coordinate systems[4].

---

## Special Cases
- **Parameterized Volumes**:  
  For repeated placements (e.g., parameterized volumes), transformations are computed dynamically via `G4VPVParameterisation` methods like `ComputeTransformation()`[3][7].

- **Vertex-Based Construction**:  
  When defining `G4Trap` via vertices (24 parameters), coordinates are directly specified in its local frame[2][10]. Subsequent rotations/translations still follow standard placement rules.

---

## Example Adjustment
If alignment issues arise between `G4Trap` and other solids (e.g., `G4Box`), apply an offset:
```cpp
// Corrective translation for alignment[4]
G4double offsetX = (1*mm - housingSize.x()) / 4;
G4ThreeVector adjustedPos = originalPos + G4ThreeVector(offsetX, 0, 0);
```

---

For most use cases, standard rotation/translation via `G4PVPlacement` suffices. Vertex-based or complex geometries may require explicit adjustments to ensure proper alignment[2][10].

Citations:

- 1: https://conference-indico.kek.jp/event/215/sessions/1287/attachments/3014/4093/0926_L05_GEOMETRY_DESCRIPTION_4.pdf
- 2: https://github.com/gemc/source/blob/main/detector/detector.cc
- 3: https://indico.bnl.gov/event/12272/contributions/51346/attachments/35564/58062/Geant4_Geometry.pdf
- 4: https://geant4-forum.web.cern.ch/t/g4trap-origin-position/5642
- 5: https://indico.ihep.ac.cn/event/6764/contributions/87727/attachments/46183/53117/materials-and_geometry.pdf
- 6: https://apc.u-paris.fr/~franco/g4doxy4.11/html/classG4Para.html
- 7: http://geant4.in2p3.fr/IMG/pdf_Lecture-Geometry.pdf
- 8: https://geant4-ed-project.pages.in2p3.fr/geant4-ed-web/docs-2022/geometry.pdf
- 9: https://indico.global/event/523/contributions/15053/attachments/4395/6844/G4_2021.pdf
- 10: https://apc.u-paris.fr/~franco/g4doxy/html/G4Trap_8cc-source.html

Geometry calculations verified, they are!

I have reviewed the transformation formulas in lines 246–250. The use of tan(θ) multiplied by cos(ϕ) for hlX1 and sin(ϕ) for hlY1 correctly implements the projection adjustments required by the G4Trap coordinate transformation rules—rotation, then translation, as defined. The averages (x1+x2)/2 and (x3+x4)/2 are consistent with proper mid-value calculations for the trapezoid’s geometry. No issues, I find.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (1)
Plugins/Geant4/src/Geant4Converters.cpp (1)

233-294: Strong with geometry, this implementation is!

Handle all G4Trap parameters correctly, it does. Yet, optimize we can by pre-calculating common expressions.

Consider this optimization, you should:

-  double hlX0 = (x1 + x2) * 0.5;
-  double hlX1 = 2 * z * tan(theta) * cos(phi) + (x3 + x4) * 0.5;
-  double hlY0 = y1;
-  double hlY1 = y2 + 2 * z * tan(theta) * sin(phi);
+  double tanTheta = tan(theta);
+  double zTanTheta = 2 * z * tanTheta;
+  double hlX0 = (x1 + x2) * 0.5;
+  double hlX1 = zTanTheta * cos(phi) + (x3 + x4) * 0.5;
+  double hlY0 = y1;
+  double hlY1 = y2 + zTanTheta * sin(phi);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19a4a04 and 92bd0fa.

📒 Files selected for processing (3)
  • Plugins/Geant4/include/Acts/Plugins/Geant4/Geant4Converters.hpp (1 hunks)
  • Plugins/Geant4/src/Geant4Converters.cpp (4 hunks)
  • Tests/UnitTests/Plugins/Geant4/Geant4ConvertersTests.cpp (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: merge-sentinel
  • GitHub Check: CI Bridge / build_gnn_tensorrt
🔇 Additional comments (6)
Plugins/Geant4/include/Acts/Plugins/Geant4/Geant4Converters.hpp (2)

128-128: Clear, the documentation now is!

Specify the source shape type explicitly, you do. Good practice, this is.


136-142: Well-structured, the new method declaration is!

Follow the established patterns, it does. Consistent with existing conversion methods, the signature and documentation are.

Tests/UnitTests/Plugins/Geant4/Geant4ConvertersTests.cpp (2)

146-146: Wise, the test renaming is!

Distinguish between different trapezoid types clearly, it does now.


216-249: Thorough, the new test case is!

Cover multiple configurations and verify essential properties, it does. Strong with the Force, this test is.

Plugins/Geant4/src/Geant4Converters.cpp (2)

376-376: Clear, the comment now is!

Specify the source shape type explicitly, you do. Consistent with header changes, this is.


393-408: Well-structured, the G4Trap conversion block is!

Follow established patterns and handle errors consistently, it does. Create surface correctly, it does.

@github-actions github-actions bot added the Component - Plugins Affects one or more Plugins label Feb 5, 2025
Copy link

github-actions bot commented Feb 5, 2025

📊: Physics performance monitoring for d42e5fa

Full contents

physmon summary

@asalzburger asalzburger requested a review from AJPfleger February 6, 2025 15:43
@asalzburger asalzburger requested a review from AJPfleger February 7, 2025 12:00
Copy link

sonarqubecloud bot commented Feb 7, 2025

@asalzburger asalzburger merged commit 3d74144 into acts-project:main Feb 7, 2025
43 checks passed
@asalzburger asalzburger deleted the feat-add-g4trap-converter branch February 7, 2025 13:39
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.

3 participants