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: introduction obj simhit writer #3180

Merged
merged 13 commits into from
Dec 4, 2024

Conversation

asalzburger
Copy link
Contributor

@asalzburger asalzburger commented May 8, 2024

This PR adds a wavefront .obj sim hit writer to the Examples.

Added (optional) spline fit based on Eigen::Spline

In addition it corrects the include path of Obj based writers to Io/Ob it still was legacy Plugins/Obj.

Summary by CodeRabbit

  • New Features

    • Introduced ObjSimHitWriter class for writing simulation hit data to OBJ files.
    • Added optional parameter outputDirObj to several simulation functions for enhanced output management.
    • Enhanced argument parser in full_chain_odd.py for more granular control over particle gun configurations.
  • Bug Fixes

    • Improved error handling during file operations in the ObjSimHitWriter.
  • Chores

    • Restructured file organization for better clarity and modularity.
    • Removed the sim_digi_odd.py script as part of cleanup.

ttbar-mu20000

Screenshot 2024-05-13 at 14 54 35

@asalzburger asalzburger added the 🛑 blocked This item is blocked by another item label May 8, 2024
@asalzburger asalzburger added this to the next milestone May 8, 2024
@github-actions github-actions bot added the Component - Examples Affects the Examples module label May 8, 2024
Copy link

github-actions bot commented May 8, 2024

📊: Physics performance monitoring for 8ded30c

Full contents

physmon summary

@asalzburger asalzburger removed the 🛑 blocked This item is blocked by another item label May 13, 2024
@github-actions github-actions bot added the Stale label Jun 15, 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

A new source file, ObjSimHitWriter.cpp, has been added to the ActsExamplesIoObj library, along with its corresponding header file ObjSimHitWriter.hpp. This new class, ObjSimHitWriter, is designed for writing simulation hit data to OBJ files. Additionally, several functions in simulation.py were updated to include a new optional parameter for specifying output directories for object files. The Output.cpp file has been modified to include the new writer in Python bindings, while the full_chain_odd.py script has been enhanced with new command-line arguments for improved configurability. The file sim_digi_odd.py has been deleted.

Changes

File Change Summary
Examples/Io/Obj/CMakeLists.txt Added src/ObjSimHitWriter.cpp to the ActsExamplesIoObj library.
Examples/Io/Obj/include/ActsExamples/Io/Obj/ObjSimHitWriter.hpp Introduced ObjSimHitWriter class and Config struct with methods for writing simulation hits.
Examples/Io/Obj/src/ObjSimHitWriter.cpp Implemented ObjSimHitWriter class methods for writing OBJ files and managing simulation hits.
Examples/Io/Obj/src/ObjTrackingGeometryWriter.cpp Updated include path for ObjTrackingGeometryWriter.hpp.
Examples/Python/python/acts/examples/simulation.py Updated functions to include outputDirObj parameter for object file output.
Examples/Python/src/Output.cpp Added includes for new writers and updated Python bindings for ObjSimHitWriter.
Examples/Scripts/Python/full_chain_odd.py Enhanced argument parser with new options for particle gun configuration and output management.
Examples/Scripts/Python/sim_digi_odd.py Deleted the file responsible for simulating and digitizing particle interactions.

Possibly related PRs

  • refactor: Reworked HitSelector in Examples #3836: Changes in the HitSelector class involve modifications to configuration parameters and functionality related to hit selection, which may intersect with the ObjSimHitWriter class's role in processing simulation hits.

Suggested labels

automerge

Suggested reviewers

  • benjaminhuth

In the realm of code, new paths we weave,
With ObjSimHitWriter, data to achieve.
Functions enhanced, and options galore,
In the galaxy of scripts, we open new doors.
So let us rejoice, with a cheer and a grin,
For the magic of coding, together we win! 🌌✨

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 54 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 eccba9f.


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: 7

🧹 Outside diff range and nitpick comments (5)
Examples/Python/python/acts/examples/simulation.py (1)

591-603: Proper implementation of OBJ writer configuration, I sense!

Follows the same pattern as CSV and ROOT writers, this implementation does. Directory creation and writer configuration, handled correctly they are.

A suggestion for defensive programming, I have:

 if outputDirObj is not None:
     outputDirObj = Path(outputDirObj)
     if not outputDirObj.exists():
         outputDirObj.mkdir()
+    if simHits is None:
+        return
     s.addWriter(
         acts.examples.ObjSimHitWriter(
             level=customLogLevel(),
Examples/Io/Obj/src/ObjSimHitWriter.cpp (2)

84-84: Typo in comment, there is: 'immplementation' should be 'implementation'.

Correct the spelling, you must.

Apply this diff to fix the typo:

-    // Write data from internal immplementation
+    // Write data from internal implementation

119-119: Use 'try_emplace', you should, to improve performance.

Unnecessary searching before insertion, there is. Replace with try_emplace, we can.

Apply this diff to enhance the code:

-        particleHits[simHit.particleId().value()] = {};
+        particleHits.try_emplace(simHit.particleId().value(), {});
🧰 Tools
🪛 cppcheck (2.10-2)

[performance] 119-119: Searching before insertion is not necessary. Instead of 'particleHits[simHit.particleId().value()]={}' consider using 'particleHits.try_emplace(simHit.particleId().value(), {});'.

(stlFindInsert)

Examples/Scripts/Python/full_chain_odd.py (2)

82-87: Input validation for '--gun-eta-range', add you should.

Assumption that two values provided are, dangerous it is. Error handling for incorrect number of arguments, implement you must. Users' mistakes, gracefully handle you should.

Consider adding a check after parsing arguments:

if len(args.gun_eta_range) != 2:
    parser.error("--gun-eta-range requires exactly two values")

89-94: Input validation for '--gun-pt-range', necessary it is.

Ensure that two values for pt range provided are. Validation, add to prevent errors from incorrect inputs.

Add this check:

if len(args.gun_pt_range) != 2:
    parser.error("--gun-pt-range requires exactly two values")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

📒 Files selected for processing (8)
  • Examples/Io/Obj/CMakeLists.txt (1 hunks)
  • Examples/Io/Obj/include/ActsExamples/Io/Obj/ObjSimHitWriter.hpp (1 hunks)
  • Examples/Io/Obj/src/ObjSimHitWriter.cpp (1 hunks)
  • Examples/Io/Obj/src/ObjTrackingGeometryWriter.cpp (1 hunks)
  • Examples/Python/python/acts/examples/simulation.py (8 hunks)
  • Examples/Python/src/Output.cpp (2 hunks)
  • Examples/Scripts/Python/full_chain_odd.py (7 hunks)
  • Examples/Scripts/Python/sim_digi_odd.py (0 hunks)
💤 Files with no reviewable changes (1)
  • Examples/Scripts/Python/sim_digi_odd.py
✅ Files skipped from review due to trivial changes (1)
  • Examples/Io/Obj/src/ObjTrackingGeometryWriter.cpp
🧰 Additional context used
🪛 cppcheck (2.10-2)
Examples/Io/Obj/src/ObjSimHitWriter.cpp

[performance] 119-119: Searching before insertion is not necessary. Instead of 'particleHits[simHit.particleId().value()]={}' consider using 'particleHits.try_emplace(simHit.particleId().value(), {});'.

(stlFindInsert)

🔇 Additional comments (11)
Examples/Io/Obj/CMakeLists.txt (1)

3-3: Hmmmm, proper integration of the new source file, I sense.

Correctly added to the shared library, the new ObjSimHitWriter.cpp is. With the Force of proper CMake practices, aligned this change is.

Verify the source file's existence and structure, we must:

✅ Verification successful

Verified the source files and their structure are, hmmmm.

Found both the source and header files in their proper places, I have. Well-structured the ObjSimHitWriter class is, inheriting from WriterT<SimHitContainer> with proper configuration and implementation patterns, it does. Matches the CMake integration perfectly, this does.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and basic structure of the new source file and its header

# Check if the source and header files exist
echo "Checking for source and header files..."
fd "ObjSimHitWriter" --type f

# Verify basic structure of the files
echo "Verifying class definition..."
ast-grep --pattern 'class ObjSimHitWriter'

Length of output: 5120

Examples/Python/src/Output.cpp (2)

28-30: LGTM! Well organized, the headers are, hmm.

In proper order and consistent style, these new includes follow. A good addition to our Jedi archives, they are.


113-115: LGTM! Balanced and harmonious, this writer declaration is.

Like other writers in our temple, this one follows the sacred patterns. The Force flows strong through its parameters, it does.

Verify the usage of these parameters elsewhere, we must.

✅ Verification successful

Verified, the parameters are. Balanced in the Force, they remain.

Through the Force, I sense the parameters flow naturally:

  • inputSimHits: Used consistently across writers and algorithms for simulation hit input
  • outputDir: Common path for writing files, used throughout the codebase
  • outputStem: Base name for output files, properly utilized
  • outputPrecision: Controls floating-point precision in output
  • drawConnections: Specific to ObjSimHitWriter for visualization control

Strong with the Force, these parameters are. In harmony with the rest of the codebase, they exist.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ObjSimHitWriter usage in Python files
rg -t py "ObjSimHitWriter" 

# Search for parameter usage
rg "inputSimHits|outputDir|outputStem|outputPrecision|drawConnections" --type cpp

Length of output: 22841

Examples/Python/python/acts/examples/simulation.py (3)

425-425: Consistent parameter addition, hmm, yes!

Well-documented and properly typed, the new parameter is. Follows the established pattern of other output parameters, it does.

Also applies to: 450-451


537-537: Consistent propagation of parameter through function chain, observe I do!

Through the chain of functions, the new parameter flows smoothly. From addGeant4 to addSimWriters, properly passed it is. Documentation matches established patterns, yes.

Also applies to: 653-653, 681-682, 782-782


Line range hint 1-900: Verify the integration with ObjSimHitWriter class, we must!

The force guides me to verify the proper integration of the new writer class.

✅ Verification successful

Properly integrated, the ObjSimHitWriter is, hmmmm.

Verified the implementation have I, and strong with the Force it is! The writer class:

  • Complete Python bindings it has, in Examples/Python/src/Output.cpp
  • Proper class definition with configuration options it shows
  • Robust implementation with hit visualization and trajectory interpolation it possesses
  • Thread-safe writing with mutex protection it maintains
  • Clear error handling and proper file management it demonstrates

In the simulation.py file, correctly used the writer is, through the addSimWriters function. Matches the class interface perfectly, it does.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ObjSimHitWriter class definition and usage
echo "=== Searching for ObjSimHitWriter class definition ==="
rg -l "class ObjSimHitWriter"

echo "=== Searching for ObjSimHitWriter includes ==="
rg -l "#include.*ObjSimHitWriter"

Length of output: 424


Script:

#!/bin/bash
# Check ObjSimHitWriter class definition and implementation
echo "=== ObjSimHitWriter Class Definition ==="
cat Examples/Io/Obj/include/ActsExamples/Io/Obj/ObjSimHitWriter.hpp

echo "=== ObjSimHitWriter Python Bindings ==="
cat Examples/Python/src/Output.cpp | grep -A 10 -B 10 "ObjSimHitWriter"

echo "=== ObjSimHitWriter Implementation ==="
cat Examples/Io/Obj/src/ObjSimHitWriter.cpp

Length of output: 11915

Examples/Io/Obj/include/ActsExamples/Io/Obj/ObjSimHitWriter.hpp (2)

37-84: Well-structured your class is, approve it I do.

The ObjSimHitWriter class and its Config are well-defined. Conforms to best practices, it does.


36-36: ⚠️ Potential issue

Misplaced code within comments, found it is.

At line 36, the class declaration appears within a comment block. This may cause parsing errors. Ensure code and comments are correctly separated.

Apply this diff to correct the placement:

-///     ...class ObjSimHitWriter final : public WriterT<SimHitContainer> {
+///
+class ObjSimHitWriter final : public WriterT<SimHitContainer> {

Likely invalid or redundant comment.

Examples/Scripts/Python/full_chain_odd.py (3)

235-236: Consistency in particle configuration, verify you must.

'args.gun_particles' used for number of particles per vertex, it seems. 'args.gun_multiplicity' for number of vertices is. Confusion between the two, ensure there is not. Description clarity, improve you should.

Review the usage of 'args.gun_particles' and 'args.gun_multiplicity' to ensure they align with intended behavior.


228-229: Units application in 'MomentumConfig', double-check you should.

With defaults corrected, 'args.gun_pt_range' now in GeV they are. Multiplying by 'u.GeV', units correct this makes. Carefully ensure that units consistent they remain.

Confirm that 'args.gun_pt_range' values multiplied by 'u.GeV' result in correct units within 'MomentumConfig'.


228-231: ⚠️ Potential issue

Duplicate unit multiplication in 'MomentumConfig', avoid you must.

Already in GeV, 'args.gun_pt_range' values are, after adjusting defaults. Multiplying by 'u.GeV' again, incorrect it is. Units, only once apply you should.

Apply this diff to correct the unit handling:

 MomentumConfig(
-    args.gun_pt_range[0] * u.GeV,
-    args.gun_pt_range[1] * u.GeV,
+    args.gun_pt_range[0] * u.UnitConstants.GeV,
+    args.gun_pt_range[1] * u.UnitConstants.GeV,
     transverse=True,
 ),

Likely invalid or redundant comment.

Examples/Scripts/Python/full_chain_odd.py Outdated Show resolved Hide resolved
Examples/Scripts/Python/full_chain_odd.py Outdated Show resolved Hide resolved
Examples/Scripts/Python/full_chain_odd.py Show resolved Hide resolved
Examples/Scripts/Python/full_chain_odd.py Outdated Show resolved Hide resolved
Examples/Scripts/Python/full_chain_odd.py Outdated Show resolved Hide resolved
Examples/Scripts/Python/full_chain_odd.py Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the Stale label Nov 30, 2024
@asalzburger asalzburger force-pushed the feat-obj-simhit-writer branch from eccba9f to 44e59d3 Compare December 4, 2024 10:05
@asalzburger asalzburger requested a review from AJPfleger December 4, 2024 12:04
Copy link
Contributor

@AJPfleger AJPfleger left a comment

Choose a reason for hiding this comment

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

Looks good. Would it be possible to do the move from Plugins to Io in a separate PR?

Examples/Io/Obj/src/ObjSimHitWriter.cpp Outdated Show resolved Hide resolved
Examples/Io/Obj/src/ObjSimHitWriter.cpp Outdated Show resolved Hide resolved
Examples/Io/Obj/src/ObjSimHitWriter.cpp Outdated Show resolved Hide resolved
Examples/Io/Obj/src/ObjSimHitWriter.cpp Outdated Show resolved Hide resolved
Examples/Io/Obj/src/ObjSimHitWriter.cpp Outdated Show resolved Hide resolved
Examples/Io/Obj/src/ObjSimHitWriter.cpp Outdated Show resolved Hide resolved
Examples/Io/Obj/src/ObjSimHitWriter.cpp Outdated Show resolved Hide resolved
@asalzburger
Copy link
Contributor Author

Looks good. Would it be possible to do the move from Plugins to Io in a separate PR?

Possible, but the IO code is so contained and almost not exposed that it would probably be an overkill. I would prefer to do it once as the PR is not very big.

@asalzburger asalzburger requested a review from AJPfleger December 4, 2024 15:14
@asalzburger asalzburger requested a review from AJPfleger December 4, 2024 15:34
Copy link

sonarqubecloud bot commented Dec 4, 2024

@kodiakhq kodiakhq bot merged commit 7efad56 into acts-project:main Dec 4, 2024
50 checks passed
@github-actions github-actions bot removed the automerge label Dec 4, 2024
timadye pushed a commit to timadye/acts that referenced this pull request Dec 5, 2024
@paulgessinger paulgessinger modified the milestones: next, v38.1.0 Dec 6, 2024
kodiakhq bot pushed a commit that referenced this pull request Dec 11, 2024
* support `--output-obj` like #3180. Can also still use `-cc` to output all formats.
* Fuse initial and final sim particles when `--edm4hep` input specified (sync with #3804)

Next, we should remove the command-line options for `full_chain_odd.py`.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Introduced a new `--output-obj` argument for enabling object file output.

- **Improvements**
	- Updated help text for the `--output-csv` argument to clarify output options.
	- Enhanced output directory handling to support multiple output formats.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Examples Affects the Examples module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants