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: Allow tracksummary plots on detector subparts #4058

Conversation

benjaminhuth
Copy link
Member

@benjaminhuth benjaminhuth commented Jan 29, 2025

Adds some infrastructure to produce additonal plots for detector regions (specified with a list of volume ids) in the TrackFinderPerformanceWriter. Also adjusts some log levels to be less verbose in DEBUG mode.

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

Release Notes

  • New Features

    • Enhanced track performance writer with support for sub-detector volume tracking.
    • Added configurable prefix for track summary plot tool.
  • Improvements

    • Improved logging and tracking statistics for performance analysis.
    • Increased flexibility in histogram naming and track summary generation.
  • Technical Updates

    • Modified method signatures to support additional configuration options.
    • Introduced new configuration parameters for more detailed track analysis.

@benjaminhuth benjaminhuth added this to the next milestone Jan 29, 2025
@benjaminhuth benjaminhuth requested a review from andiwand January 29, 2025 10:45
Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

Hmm, changes to tracking and performance writing, we have! Modifications span multiple files in the Examples framework, they do. Logging adjustments, method signatures expanded, new configuration options for sub-detector tracking introduced. Subtle yet significant improvements to track analysis capabilities, these changes represent.

Changes

File Change Summary
Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/TrackTruthMatcher.cpp Debug logging level changed from ACTS_DEBUG to ACTS_VERBOSE
Examples/Framework/include/ActsExamples/Validation/TrackSummaryPlotTool.hpp book() method signature updated with optional prefix parameter
Examples/Framework/src/Validation/TrackSummaryPlotTool.cpp Implemented prefix-based histogram naming logic
Examples/Io/Root/include/ActsExamples/Io/Root/TrackFinderPerformanceWriter.hpp Added subDetectorTrackSummaryVolumes and m_subDetectorSummaryCaches
Examples/Io/Root/src/TrackFinderPerformanceWriter.cpp Enhanced sub-detector volume tracking and summary processing
Examples/Python/src/Output.cpp Updated TrackFinderPerformanceWriter declaration with new parameter

Possibly related PRs

Suggested Labels

automerge, Track Finding, Changes Performance

Suggested Reviewers

  • paulgessinger

Poem

Tracks dancing through volumes bright,
Logging whispers, data's delight
Prefixes bloom like code's sweet flower 🌱
Performance writer gains new power! 🚀
Tracking wisdom, subtle and keen

✨ 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)
Examples/Io/Root/src/TrackFinderPerformanceWriter.cpp (1)

234-257: Refactor the track state processing logic, we should!

Complex, this section has become. Extract track state processing to a separate method, we must. Improve readability and maintainability, it will.

+  private:
+    void processTrackStatesForVolumes(
+        const Track& track,
+        const Acts::BoundTrackParameters& fittedParameters,
+        const std::string& key,
+        const std::set<int>& volumes) {
+      std::size_t nTrackStates{}, nMeasurements{}, nOutliers{}, nHoles{},
+          nSharedHits{};
+      
+      for (auto state : track.trackStatesReversed()) {
+        if (!state.hasReferenceSurface() ||
+            !volumes.contains(state.referenceSurface().geometryId().volume())) {
+          continue;
+        }
+        
+        nTrackStates++;
+        nMeasurements += static_cast<std::size_t>(
+            state.typeFlags().test(Acts::MeasurementFlag));
+        nOutliers +=
+            static_cast<std::size_t>(state.typeFlags().test(Acts::OutlierFlag));
+        nHoles +=
+            static_cast<std::size_t>(state.typeFlags().test(Acts::HoleFlag));
+        nSharedHits += static_cast<std::size_t>(
+            state.typeFlags().test(Acts::SharedHitFlag));
+      }
+      
+      m_trackSummaryPlotTool.fill(m_subDetectorSummaryCaches.at(key),
+                                  fittedParameters, nTrackStates, nMeasurements,
+                                  nOutliers, nHoles, nSharedHits);
+    }

Replace the existing loop with:

     for (const auto& [key, volumes] : m_cfg.subDetectorTrackSummaryVolumes) {
       ACTS_VERBOSE("Fill track summary stats for subset " << key);
-      std::size_t nTrackStates{}, nMeasurements{}, nOutliers{}, nHoles{},
-          nSharedHits{};
-      for (auto state : track.trackStatesReversed()) {
-        if (!state.hasReferenceSurface() ||
-            !volumes.contains(state.referenceSurface().geometryId().volume())) {
-          continue;
-        }
-
-        nTrackStates++;
-        nMeasurements += static_cast<std::size_t>(
-            state.typeFlags().test(Acts::MeasurementFlag));
-        nOutliers +=
-            static_cast<std::size_t>(state.typeFlags().test(Acts::OutlierFlag));
-        nHoles +=
-            static_cast<std::size_t>(state.typeFlags().test(Acts::HoleFlag));
-        nSharedHits += static_cast<std::size_t>(
-            state.typeFlags().test(Acts::SharedHitFlag));
-      }
-      m_trackSummaryPlotTool.fill(m_subDetectorSummaryCaches.at(key),
-                                  fittedParameters, nTrackStates, nMeasurements,
-                                  nOutliers, nHoles, nSharedHits);
+      processTrackStatesForVolumes(track, fittedParameters, key, volumes);
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e61fa2d and 841eb03.

📒 Files selected for processing (6)
  • Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/TrackTruthMatcher.cpp (1 hunks)
  • Examples/Framework/include/ActsExamples/Validation/TrackSummaryPlotTool.hpp (1 hunks)
  • Examples/Framework/src/Validation/TrackSummaryPlotTool.cpp (1 hunks)
  • Examples/Io/Root/include/ActsExamples/Io/Root/TrackFinderPerformanceWriter.hpp (2 hunks)
  • Examples/Io/Root/src/TrackFinderPerformanceWriter.cpp (5 hunks)
  • Examples/Python/src/Output.cpp (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/TrackTruthMatcher.cpp
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: merge-sentinel
🔇 Additional comments (8)
Examples/Framework/include/ActsExamples/Validation/TrackSummaryPlotTool.hpp (1)

62-64: Approve the method signature change, I do!

Well-documented and backward compatible, this change is. Support for sub-detector tracking plots, it provides.

Examples/Io/Root/include/ActsExamples/Io/Root/TrackFinderPerformanceWriter.hpp (2)

66-68: Wise addition to the Config struct, this is!

Clear documentation and flexible configuration for detector regions, you provide. The Force is strong with this design.


104-105: Balanced and symmetrical, this member variable is!

Mirror the Config structure, it does. Proper organization of sub-detector caches, it maintains.

Examples/Framework/src/Validation/TrackSummaryPlotTool.cpp (2)

28-32: Elegant solution for prefix handling, you have created!

Lambda function addPrefix, clarity it brings. Debug logging, improved it is.


34-71: Consistent and clean, the histogram creation remains!

Wisely applied, the prefix handling is. Unchanged, the core functionality stays.

Examples/Io/Root/src/TrackFinderPerformanceWriter.cpp (2)

77-79: Balanced initialization and cleanup, achieved you have!

Properly managed, the sub-detector caches are. Constructor and destructor, in harmony they work.

Also applies to: 87-89


176-177: Improved logging wisdom, you have shown!

Clear visibility into track processing, these messages provide. Help in debugging, they will.

Also applies to: 272-278

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

401-407: Approve the changes, I do! Yet verify parameter ordering, we must.

Hmm, correctly placed the new parameter subDetectorTrackSummaryVolumes is, grouped with other plot configurations it remains. Yet ensure consistent with C++ class declaration, the parameter ordering must be.

✅ Verification successful

Correct, the parameter ordering is! Strong with the Force, this implementation is.

In perfect harmony with the C++ Config struct, the Python bindings are. Each parameter, in its rightful place it stands, from inputTracks to writeMatchingDetails. The new parameter subDetectorTrackSummaryVolumes, wisely placed it is, among its plot configuration companions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify parameter ordering consistency between Python bindings and C++ class declaration

# Search for TrackFinderPerformanceWriter class declaration
ast-grep --pattern 'class TrackFinderPerformanceWriter {
  $$$
  struct Config {
    $$$
  };
  $$$
}'

Length of output: 104


Script:

#!/bin/bash
# Search for TrackFinderPerformanceWriter class and its Config struct
rg -l "class TrackFinderPerformanceWriter" 

# Once we find the file, we'll examine the Config struct
rg "struct Config" -A 20 -B 2 "TrackFinderPerformanceWriter"

Length of output: 253


Script:

#!/bin/bash
# Examine the Config struct in the header file
cat "Examples/Io/Root/include/ActsExamples/Io/Root/TrackFinderPerformanceWriter.hpp"

Length of output: 4780

@github-actions github-actions bot added the Component - Examples Affects the Examples module label Jan 29, 2025
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: 1

🧹 Nitpick comments (4)
Examples/Io/Root/src/TrackFinderPerformanceWriter.cpp (4)

87-89: Safe cleanup, ensure we must!

Throwing exceptions during cleanup, dangerous it is. Use operator[] instead of .at(), we should.

   for (const auto& [key, _] : m_cfg.subDetectorTrackSummaryVolumes) {
-    m_trackSummaryPlotTool.clear(m_subDetectorSummaryCaches.at(key));
+    m_trackSummaryPlotTool.clear(m_subDetectorSummaryCaches[key]);
   }

140-143: Handle write failures, we must!

Hmm, silent failures in writing, dangerous they are. Check write status, we should.

   for (const auto& [key, _] : m_cfg.subDetectorTrackSummaryVolumes) {
-    m_trackSummaryPlotTool.write(m_subDetectorSummaryCaches.at(key));
+    if (!m_trackSummaryPlotTool.write(m_subDetectorSummaryCaches[key])) {
+      ACTS_WARNING("Failed to write summary cache for volume " << key);
+    }
   }

176-177: Improved logging messages, provide we should!

More context in debug messages, helpful it would be. Track processing progress, show we must.

-  ACTS_DEBUG("Collect information from " << tracks.size() << " tracks");
+  ACTS_DEBUG("Begin processing " << tracks.size() << " tracks for event " << ctx.eventNumber);
   std::size_t unmatched = 0, missingRefSurface = 0;
   for (const auto& track : tracks) {
     // ... existing code ...
     if (!track.hasReferenceSurface()) {
-      ACTS_VERBOSE("No fitted track parameters for track, index = "
-                   << track.index() << " tip index = " << track.tipIndex());
+      ACTS_VERBOSE("Track " << track.index() << " (tip: " << track.tipIndex() 
+                  << ") missing fitted parameters at reference surface");

Also applies to: 184-186


255-261: Debug information, enhance we shall!

More detailed statistics, provide we must. Help in debugging track matching issues, it will.

   if (unmatched > 0) {
-    ACTS_DEBUG("No matching information found for " << unmatched << " tracks");
+    ACTS_DEBUG("Track matching summary: " << unmatched << "/" << tracks.size() 
+              << " tracks unmatched (" 
+              << (100.0 * unmatched / tracks.size()) << "%)");
   }
   if (missingRefSurface > 0) {
-    ACTS_DEBUG("Reference surface was missing for " << missingRefSurface
-                                                    << " tracks");
+    ACTS_DEBUG("Reference surface missing for " << missingRefSurface << "/" 
+              << tracks.size() << " tracks ("
+              << (100.0 * missingRefSurface / tracks.size()) << "%)");
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 841eb03 and c4403c5.

📒 Files selected for processing (1)
  • Examples/Io/Root/src/TrackFinderPerformanceWriter.cpp (5 hunks)
🔇 Additional comments (1)
Examples/Io/Root/src/TrackFinderPerformanceWriter.cpp (1)

77-79: Validate the sub-detector volumes configuration, you must!

Hmm, missing validation of volumes configuration, I sense. Empty volumes list, handle gracefully we should.

Add validation before the loop:

+  if (!m_cfg.subDetectorTrackSummaryVolumes.empty()) {
     for (const auto& [key, _] : m_cfg.subDetectorTrackSummaryVolumes) {
       m_trackSummaryPlotTool.book(m_subDetectorSummaryCaches[key], key);
     }
+  }

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.

Looks fine to me. I wonder if it would be easier to schedule the writer twice than unrolling this inside the writer. But maybe I also don't quite understand the use case.

@benjaminhuth
Copy link
Member Author

Hmm so I think the issue is that you never want efficiency/fakerate/duprate plots on subparts of the detector, right? But only hit content plots e.g... So multiple writer does not make as much sense I think...

@andiwand
Copy link
Contributor

Hmm so I think the issue is that you never want efficiency/fakerate/duprate plots on subparts of the detector, right? But only hit content plots e.g... So multiple writer does not make as much sense I think...

Potentially this is not the best writer to add it to I guess. Maybe the track state summary with a volume constrain it more suitable?

@benjaminhuth
Copy link
Member Author

Hmm but that does not do plots right? that only makes flat TTrees, right?

@benjaminhuth
Copy link
Member Author

I actually think that this is quite suited here, since when investigating the finding performance, one usually wants to look at all those hit content plots together, right? Like in IDPVM, where all these plots are under the same category.

@andiwand
Copy link
Contributor

True for plotting this makes sense I think.

I guess for finding performance this only tells you one side of the coin which is about the tracks you found but not about those you did not find

I am just a bit worried that we add a bunch of semi-generic region specifier to our writers and they become unmaintainable again. I spent quite some time cleaning them up in the past

@benjaminhuth
Copy link
Member Author

Of course the new plots don't show the full truth (as none single plot does), but I think they are fairly common metrics, and I think it is good if we support those kind of plots. Of course one can alway handcraft those, but its kind of cumbersome.

I see your fear of making the whole thing more convoluted, but I think that makes relatively good use of the existing infrastructure...

Copy link

github-actions bot commented Jan 29, 2025

📊: Physics performance monitoring for db1b97b

Full contents

physmon summary

@kodiakhq kodiakhq bot merged commit d00fea9 into acts-project:main Jan 29, 2025
42 checks passed
paulgessinger pushed a commit to paulgessinger/acts that referenced this pull request Jan 30, 2025
Adds some infrastructure to produce additonal plots for detector regions (specified with a list of volume ids) in the `TrackFinderPerformanceWriter`. Also adjusts some log levels to be less verbose in `DEBUG` mode.
@paulgessinger paulgessinger modified the milestones: next, v39.0.0 Feb 5, 2025
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