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

chore: Some magnetic field code cleanup #3982

Merged

Conversation

andiwand
Copy link
Contributor

@andiwand andiwand commented Dec 13, 2024

  • cleanup includes
  • cleanup some using namespace

pulled out of #3951

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new classes for enhanced magnetic field handling in Python.
    • Added methods for creating magnetic field maps from files.
  • Bug Fixes

    • Improved error handling in getField function to provide clearer feedback on failures.
  • Documentation

    • Enhanced comments for clarity in several files.
  • Chores

    • Removed unused include directives across multiple files to streamline code.

@andiwand andiwand added this to the next milestone Dec 13, 2024
Copy link

coderabbitai bot commented Dec 13, 2024

Walkthrough

Changes made to various header and source files focus on removing unnecessary include directives and simplifying dependencies across the codebase. Notable modifications include the InterpolatedBFieldMap, MagneticFieldProvider, and DetectorNavigator classes, which maintain their core functionalities while streamlining their interfaces. New functionalities and error handling enhancements have been introduced in the SympyStepper and MagneticField files, along with the addition of new classes for Python bindings. Overall, the updates aim to refine the code structure without altering the fundamental behavior of the components.

Changes

File Path Change Summary
Core/include/Acts/MagneticField/InterpolatedBFieldMap.hpp Removed #include "Acts/Utilities/Grid.hpp"; class and methods unchanged.
Core/include/Acts/MagneticField/MagneticFieldProvider.hpp Removed <array> and <memory> includes; class unchanged.
Core/include/Acts/Material/SurfaceMaterialMapper.hpp Removed includes for MaterialInteractor.hpp, SurfaceCollector.hpp, and VolumeCollector.hpp; class unchanged.
Core/include/Acts/Navigation/DetectorNavigator.hpp Removed includes for Units.hpp, BoundarySurfaceT.hpp, and Propagator.hpp; class unchanged.
Core/include/Acts/Propagator/StraightLineStepper.hpp Removed #include <algorithm>; class unchanged.
Core/src/MagneticField/SolenoidBField.cpp Removed <algorithm> include; added comments; updated method signature for clarity in getField.
Core/src/Propagator/SympyStepper.cpp Removed <cstdint> include; updated constructor and methods for state management and error handling.
Core/src/Vertexing/HelicalTrackLinearizer.cpp Removed Acts/Surfaces/PerigeeSurface.hpp include; method unchanged.
Examples/Io/Root/include/ActsExamples/Io/Root/RootBFieldWriter.hpp Removed multiple includes and namespace declaration; class unchanged.
Examples/Io/Root/src/RootBFieldWriter.cpp Removed #include "Acts/MagneticField/InterpolatedBFieldMap.hpp"; clarified namespace usage in run.
Examples/Python/src/MagneticField.cpp Enhanced error handling and added new classes and methods for magnetic fields; expanded functionality.
Tests/UnitTests/Core/MagneticField/ConstantBFieldTests.cpp Removed <utility> include; tests unchanged.
Tests/UnitTests/Core/MagneticField/InterpolatedBFieldMapTests.cpp Removed several includes; refined test logic while preserving functionality.
Tests/UnitTests/Core/MagneticField/SolenoidBFieldTests.cpp Removed <fstream> include; commented out unused file output code; test unchanged.
Tests/UnitTests/Core/Propagator/ExtrapolatorTests.cpp Removed multiple includes; tests unchanged.
Tests/UnitTests/Core/Utilities/BFieldMapUtilsTests.cpp Removed <utility> include; tests unchanged.

Possibly related PRs

Suggested labels

Component - Core, Component - Examples, automerge

Suggested reviewers

  • paulgessinger

In the code's realm, changes abound,
Simplifying paths where clutter was found.
With headers removed, clarity reigns,
In magnetic fields, the logic remains.
New methods and classes, a robust embrace,
In the code's dance, we find our place! 🌌✨


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. (Experiment)
  • @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.

@github-actions github-actions bot added Component - Core Affects the Core module Component - Examples Affects the Examples module Vertexing labels Dec 13, 2024
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

🧹 Outside diff range and nitpick comments (4)
Core/include/Acts/Material/SurfaceMaterialMapper.hpp (2)

Line range hint 39-65: Documentation enhancement, suggest I do.

Clear the process steps are, but examples of usage, help young padawans they would. A code snippet showing material track creation and mapping, valuable would be.

Consider adding example usage like this:

// Example usage
GeometryContext gctx;
MagneticFieldContext mctx;
auto state = mapper.createState(gctx, mctx, trackingGeometry);

// Create and map a material track
RecordedMaterialTrack track;
// ... populate track ...
mapper.mapMaterialTrack(state, track);

// Finalize the mapping
mapper.finalizeMaps(state);

Line range hint 66-108: Move semantics, optimize State struct we should.

Strong with RAII, this class is. Yet for State struct, move operations explicitly declare we could. Performance benefits, bring this would.

 struct State {
     State(const GeometryContext& gctx, const MagneticFieldContext& mctx)
         : geoContext(gctx), magFieldContext(mctx) {}
+    
+    // Enable move operations
+    State(State&&) noexcept = default;
+    State& operator=(State&&) noexcept = default;
+    
+    // Disable copy operations
+    State(const State&) = delete;
+    State& operator=(const State&) = delete;
Examples/Io/Root/src/RootBFieldWriter.cpp (2)

Line range hint 176-186: Consider extracting field value conversion, you should.

Repeated unit conversions, I see. A helper function, beneficial it would be.

+ // Helper function to convert field values to desired units
+ Acts::Vector3 convertFieldToUnits(const Acts::Vector3& rawField) {
+   return rawField / Acts::UnitConstants::T;
+ }

  Acts::Vector3 bField = config.bField->getFieldUnchecked(position);
- Bx = bField.x() / Acts::UnitConstants::T;
- By = bField.y() / Acts::UnitConstants::T;
- Bz = bField.z() / Acts::UnitConstants::T;
+ auto convertedField = convertFieldToUnits(bField);
+ Bx = convertedField.x();
+ By = convertedField.y();
+ Bz = convertedField.z();

Line range hint 1-277: Architecture advice for future improvements, share I will.

Large function with multiple responsibilities, this is. Consider splitting into smaller functions for:

  • Configuration validation
  • Cartesian coordinate handling
  • Cylindrical coordinate handling
  • File operations

Easier to maintain and test, it would be.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2d5ed72 and ac720ee.

📒 Files selected for processing (16)
  • Core/include/Acts/MagneticField/InterpolatedBFieldMap.hpp (0 hunks)
  • Core/include/Acts/MagneticField/MagneticFieldProvider.hpp (0 hunks)
  • Core/include/Acts/Material/SurfaceMaterialMapper.hpp (1 hunks)
  • Core/include/Acts/Navigation/DetectorNavigator.hpp (0 hunks)
  • Core/include/Acts/Propagator/StraightLineStepper.hpp (0 hunks)
  • Core/src/MagneticField/SolenoidBField.cpp (0 hunks)
  • Core/src/Propagator/SympyStepper.cpp (0 hunks)
  • Core/src/Vertexing/HelicalTrackLinearizer.cpp (0 hunks)
  • Examples/Io/Root/include/ActsExamples/Io/Root/RootBFieldWriter.hpp (0 hunks)
  • Examples/Io/Root/src/RootBFieldWriter.cpp (3 hunks)
  • Examples/Python/src/MagneticField.cpp (0 hunks)
  • Tests/UnitTests/Core/MagneticField/ConstantBFieldTests.cpp (0 hunks)
  • Tests/UnitTests/Core/MagneticField/InterpolatedBFieldMapTests.cpp (0 hunks)
  • Tests/UnitTests/Core/MagneticField/SolenoidBFieldTests.cpp (0 hunks)
  • Tests/UnitTests/Core/Propagator/ExtrapolatorTests.cpp (0 hunks)
  • Tests/UnitTests/Core/Utilities/BFieldMapUtilsTests.cpp (0 hunks)
💤 Files with no reviewable changes (14)
  • Core/include/Acts/MagneticField/MagneticFieldProvider.hpp
  • Tests/UnitTests/Core/MagneticField/SolenoidBFieldTests.cpp
  • Tests/UnitTests/Core/MagneticField/ConstantBFieldTests.cpp
  • Tests/UnitTests/Core/Utilities/BFieldMapUtilsTests.cpp
  • Core/src/Vertexing/HelicalTrackLinearizer.cpp
  • Core/include/Acts/Propagator/StraightLineStepper.hpp
  • Core/include/Acts/MagneticField/InterpolatedBFieldMap.hpp
  • Core/src/MagneticField/SolenoidBField.cpp
  • Tests/UnitTests/Core/Propagator/ExtrapolatorTests.cpp
  • Core/include/Acts/Navigation/DetectorNavigator.hpp
  • Examples/Io/Root/include/ActsExamples/Io/Root/RootBFieldWriter.hpp
  • Core/src/Propagator/SympyStepper.cpp
  • Tests/UnitTests/Core/MagneticField/InterpolatedBFieldMapTests.cpp
  • Examples/Python/src/MagneticField.cpp
🔇 Additional comments (4)
Core/include/Acts/Material/SurfaceMaterialMapper.hpp (1)

Line range hint 1-225: Hmmmm... Verify the removal of includes, we must.

Removed, three includes have been. Yet ensure we must, that no remnants of their usage remain. Through the Force, sense no immediate issues I do, but verify we shall.

Examples/Io/Root/src/RootBFieldWriter.cpp (3)

178-178: Approve namespace qualification, hmmmm.

Explicit namespace qualification, added you have. Clearer and safer, the code becomes. Prevent naming conflicts, this will.


267-267: Approve namespace qualification for VectorHelpers, I do.

Wise choice it is, to qualify VectorHelpers with Acts namespace. Consistency with codebase standards, this maintains.


265-268: Verify field conversion in cylindrical coordinates, we must.

In cylindrical coordinates, consistent unit conversion for both Br and Bz components, ensure we should.

✅ Verification successful

Let me examine the field conversion implementations in more detail, I must. Consistent patterns across the codebase, we shall find.


Consistent and correct, the field unit conversions are, young padawan.

Through the Force, I sense that both Br and Bz components are properly converted using Acts::UnitConstants::T. The codebase reveals a harmonious pattern where magnetic field components in cylindrical coordinates consistently use the same unit conversion:

  • In RootBFieldWriter.cpp:
Bz = bField.z() / Acts::UnitConstants::T;
Br = Acts::VectorHelpers::perp(bField) / Acts::UnitConstants::T;

Throughout the codebase, this pattern of conversion is maintained with great discipline. The Force is strong with these unit conversions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other instances of field unit conversion in cylindrical coordinates
rg "UnitConstants::T" --type cpp

Length of output: 2732


Script:

#!/bin/bash
# Search for field conversion implementations in cylindrical coordinates
ast-grep --pattern 'perp($field)'

Length of output: 35


Script:

#!/bin/bash
# Search for VectorHelpers usage
rg "VectorHelpers" -A 3 --type cpp

Length of output: 66041


Script:

#!/bin/bash
# Look for field unit conversion functions or utilities
rg "convertField|BFieldUnit" --type cpp -A 2

Length of output: 10624

Copy link

📊: Physics performance monitoring for ac720ee

Full contents

physmon summary

@kodiakhq kodiakhq bot merged commit 9a2b74d into acts-project:main Dec 13, 2024
48 checks passed
@andiwand andiwand deleted the chore-clean-some-magneticfield-code branch December 13, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaks Athena build This PR breaks the Athena build Component - Core Affects the Core module Component - Examples Affects the Examples module Vertexing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants