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

New way to color tracks. #1579

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

DanielWielanek
Copy link
Contributor

Currently the tracks coloring depens on node MCTrack colors, and the color scheme is configured by FairEventManager.
In this commit I propose the following changes:

  1. FairEventManager only provide the pointer to XML node with configuration
  2. In examples there are different nodes for coloring of Geo and MC tracks (thank to the new policy)
  3. Old coloring shame is marked as depreacted
  4. The XML config for Event Display was updated (at some point the names of the last layers of examples was changed - the configuration was not working for last 4 stations of detector)

Checklist:

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

Comment on lines 19 to 57
void FairXMLDetectorColor::ColorizeNode(TGeoNode* node, FairXMLNode* xml, Int_t depth) const
{
TString name = xml->GetAttrib("name")->GetValue();
TString node_name = node->GetName();
Bool_t recursive = (xml->GetAttrib("recursive")->GetValue().Length() != 0 && !name.EqualTo(node_name));
if (recursive && depth == 0)
return;
TString transparency = xml->GetAttrib("transparency")->GetValue();
TString color = xml->GetAttrib("color")->GetValue();
if (!color.EqualTo("")) {
node->GetVolume()->SetFillColor(FairXMLEveConf::StringToColor(color));
node->GetVolume()->SetLineColor(FairXMLEveConf::StringToColor(color));
}
if (!transparency.EqualTo("")) {
node->GetVolume()->SetTransparency((Char_t)(transparency.Atoi()));
}
if (xml->GetAttrib("recursive")->GetValue().Length() > 0) {
TString val = xml->GetAttrib("recursive")->GetValue();
Int_t xml_depth = val.Atoi();
if (recursive) {
xml_depth = depth - 1;
}
for (int i = 0; i < node->GetNdaughters(); i++) {
TGeoNode* daughter_node = node->GetDaughter(i);
ColorizeNode(daughter_node, xml, xml_depth);
}
}
if (xml->GetNChildren() > 0 && !recursive) {
for (int i = 0; i < node->GetNdaughters(); i++) {
TString subdetector_name = node->GetDaughter(i)->GetName();
for (int j = 0; j < xml->GetNChildren(); j++) {
FairXMLNode* subnode = xml->GetChild(j);
TString subnode_name = subnode->GetAttrib("name")->GetValue();
if (subnode_name == subdetector_name) {
ColorizeNode(node->GetDaughter(i), subnode, 0);
}
}
}
}
Copy link

Choose a reason for hiding this comment

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

Consider refactoring for readability and performance.

The method ColorizeNode is functionally correct but can be refactored for better readability and performance. Specifically:

  • The recursive logic can be simplified.
  • The repeated calls to xml->GetAttrib("recursive")->GetValue() can be optimized.
void FairXMLDetectorColor::ColorizeNode(TGeoNode* node, FairXMLNode* xml, Int_t depth) const
{
    TString name = xml->GetAttrib("name")->GetValue();
    TString node_name = node->GetName();
    Bool_t recursive = (xml->GetAttrib("recursive")->GetValue().Length() != 0 && !name.EqualTo(node_name));
    if (recursive && depth == 0)
        return;
    TString transparency = xml->GetAttrib("transparency")->GetValue();
    TString color = xml->GetAttrib("color")->GetValue();
    if (!color.EqualTo("")) {
        node->GetVolume()->SetFillColor(FairXMLEveConf::StringToColor(color));
        node->GetVolume()->SetLineColor(FairXMLEveConf::StringToColor(color));
    }
    if (!transparency.EqualTo("")) {
        node->GetVolume()->SetTransparency((Char_t)(transparency.Atoi()));
    }
    if (recursive) {
        Int_t xml_depth = xml->GetAttrib("recursive")->GetValue().Atoi();
        if (depth > 0) {
            xml_depth = depth - 1;
        }
        for (int i = 0; i < node->GetNdaughters(); i++) {
            TGeoNode* daughter_node = node->GetDaughter(i);
            ColorizeNode(daughter_node, xml, xml_depth);
        }
    } else if (xml->GetNChildren() > 0) {
        for (int i = 0; i < node->GetNdaughters(); i++) {
            TString subdetector_name = node->GetDaughter(i)->GetName();
            for (int j = 0; j < xml->GetNChildren(); j++) {
                FairXMLNode* subnode = xml->GetChild(j);
                TString subnode_name = subnode->GetAttrib("name")->GetValue();
                if (subnode_name == subdetector_name) {
                    ColorizeNode(node->GetDaughter(i), subnode, 0);
                }
            }
        }
    }
}

Copy link

coderabbitai bot commented Jul 21, 2024

Walkthrough

Walkthrough

The recent changes improve the event display framework's color management system by implementing a modular, XML-based approach for track and detector color assignments. Significant enhancements include the introduction of new classes for color handling, improved memory management practices, and a more flexible assignment mechanism that allows for dynamic configuration. This results in a more maintainable and user-friendly system for visualizing particle tracks and detector components.

Changes

Files Change Summary
.../FairEveMCTracks.cxx
.../FairEveMCTracks.h
Updated track color handling to utilize FairXMLPdgColor, enhancing configurability through XML. Added member variable fPdgColor.
.../FairEventManager.cxx
.../FairEventManager.h
Introduced methods for XML configuration (SetXMLConfig, GetXMLConfigNode), deprecated the old color method, and improved memory management with smart pointers.
.../FairEveGeoTracks.cxx
.../FairEveGeoTracks.h
Added fPdgColor for track color coding, integrated XML for color retrieval from configuration.
.../FairXMLDetectorColor.cxx
.../FairXMLDetectorColor.h
Implemented FairXMLDetectorColor class for applying color to detector nodes based on XML configurations, including methods for recursive color application.
.../CMakeLists.txt Included FairXMLDetectorColor.cxx in the build configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FairEventManager
    participant FairXMLPdgColor
    participant FairEveMCTracks

    User->>FairEventManager: SetXMLConfig("config.xml")
    FairEventManager->>FairXMLPdgColor: Load configuration
    FairEventManager->>FairEveMCTracks: Initialize
    FairEveMCTracks->>FairXMLPdgColor: GetColor(pdgCode)
    FairEveMCTracks->>User: DrawTrack(color)
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8a1980e and 65ae245.

Files selected for processing (2)
  • fairroot/eventdisplay/xml/FairXMLDetectorColor.cxx (1 hunks)
  • fairroot/eventdisplay/xml/FairXMLDetectorColor.h (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • fairroot/eventdisplay/xml/FairXMLDetectorColor.cxx
  • fairroot/eventdisplay/xml/FairXMLDetectorColor.h

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@ChristianTackeGSI ChristianTackeGSI changed the base branch from nightly_dev to dev July 21, 2024 18:10
Copy link
Member

@ChristianTackeGSI ChristianTackeGSI left a comment

Choose a reason for hiding this comment

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

Please take a look at our Coding guidelines.

Especially G.3, G.4, and G.5.

I've added a few comments around. Those are just random.

fairroot/eventdisplay/FairEventManager.cxx Outdated Show resolved Hide resolved
@@ -151,7 +156,6 @@ class FairEventManager : public TEveEventManager
TEveProjectionAxes* GetRPhiAxes() const { return fAxesPhi; };
TEveProjectionAxes* GetRhoZAxes() const { return fAxesRho; };
virtual void LoadXMLSettings();
void LoadXMLDetector(TGeoNode* node, FairXMLNode* xml, Int_t depth = 0);
Copy link
Member

Choose a reason for hiding this comment

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

This is a public member function. So you're removing public API.

This is a breaking change.

If you really want this breaking change, then please write an appropriate CHANGELOG entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if I made change corretly, please check :)

fairroot/eventdisplay/xml/FairXMLDetectorColor.cxx Outdated Show resolved Hide resolved
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

fairroot/eventdisplay/xml/FairXMLDetectorColor.cxx Outdated Show resolved Hide resolved
Comment on lines 55 to 87
void FairXMLDetectorColor::ColorizeNode(TGeoNode& node, const FairXMLNode& xml, Int_t depth) const
{
switch (depth) {
case 0: { // recursive mode of
return;
} break;
case -1: { // standard mode
Int_t newDepth = ApplyToNode(node, xml);
if (newDepth) {
for (int i = 0; i < node.GetNdaughters(); i++) {
ColorizeNode(*node.GetDaughter(i), xml, newDepth);
}
} else {
for (int i = 0; i < node.GetNdaughters(); i++) {
TString subdetector_name = node.GetDaughter(i)->GetName();
for (int j = 0; j < xml.GetNChildren(); j++) {
FairXMLNode* subnode = xml.GetChild(j);
TString subnode_name = subnode->GetAttrib("name")->GetValue();
if (subnode_name.EqualTo(subdetector_name)) {
ColorizeNode(*node.GetDaughter(i), *subnode, -1);
}
}
}
}
} break;
default: { // recusrive mode
ApplyToNode(node, xml);
for (int i = 0; i < node.GetNdaughters(); i++) {
ColorizeNode(*node.GetDaughter(i), xml, depth - 1);
}
} break;
}
}
Copy link

Choose a reason for hiding this comment

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

Consider refactoring the ColorizeNode method for readability and performance.

The method can be simplified by reducing redundant checks and improving the recursive logic.

void FairXMLDetectorColor::ColorizeNode(TGeoNode& node, const FairXMLNode& xml, Int_t depth) const
{
    if (depth == 0) {
        return;
    }

    Int_t newDepth = ApplyToNode(node, xml);
    if (newDepth) {
        for (int i = 0; i < node.GetNdaughters(); i++) {
            ColorizeNode(*node.GetDaughter(i), xml, newDepth);
        }
    } else {
        for (int i = 0; i < node.GetNdaughters(); i++) {
            TString subdetector_name = node.GetDaughter(i)->GetName();
            for (int j = 0; j < xml.GetNChildren(); j++) {
                FairXMLNode* subnode = xml.GetChild(j);
                TString subnode_name = subnode->GetAttrib("name")->GetValue();
                if (subnode_name.EqualTo(subdetector_name)) {
                    ColorizeNode(*node.GetDaughter(i), *subnode, -1);
                }
            }
        }
    }
}

Comment on lines +95 to +100
void FairXMLDetectorColor::Colorize(TGeoNode* node)
{
if (!node)
return;
ColorizeNode(*node, fNode, -1);
}
Copy link

Choose a reason for hiding this comment

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

Add a check to ensure fNode is valid.

The method should include a check to ensure fNode is valid before calling ColorizeNode.

void FairXMLDetectorColor::Colorize(TGeoNode* node)
{
    if (!node || !fNode)
        return;
    ColorizeNode(*node, fNode, -1);
}


### Breaking Changes
* Event display
* Removed void FairEventManager::LoadXMLDetector(TGeoNode* node, FairXMLNode* xml, Int_t depth = 0)
Copy link

Choose a reason for hiding this comment

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

Fix markdownlint issue.

Remove spaces inside emphasis markers.

-  * Removed     void FairEventManager::LoadXMLDetector(TGeoNode* node, FairXMLNode* xml, Int_t depth = 0)
+  * Removed void FairEventManager::LoadXMLDetector(TGeoNode* node, FairXMLNode* xml, Int_t depth = 0)
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
* Removed void FairEventManager::LoadXMLDetector(TGeoNode* node, FairXMLNode* xml, Int_t depth = 0)
* Removed void FairEventManager::LoadXMLDetector(TGeoNode* node, FairXMLNode* xml, Int_t depth = 0)
Tools
Markdownlint

11-11: null
Spaces inside emphasis markers

(MD037, no-space-in-emphasis)

Comment on lines +305 to +313
auto colors = GetXMLConfigNode("MCTracksColors");
auto detectors = GetXMLConfigNode("Detectors");
if (colors)
fPDGColor = FairXMLPdgColor(colors);
if (detectors) {
auto cave = detectors->GetChild(0);
if (cave) {
FairXMLDetectorColor detCol(cave);
detCol.Colorize(gGeoManager->GetTopNode());
Copy link

Choose a reason for hiding this comment

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

Consider adding error handling in LoadXMLSettings.

The method should include error handling to manage cases where XML nodes are not found.

void FairEventManager::LoadXMLSettings()
{
    auto colors = GetXMLConfigNode("MCTracksColors");
    auto detectors = GetXMLConfigNode("Detectors");
    if (colors) {
        fPDGColor = FairXMLPdgColor(colors);
    } else {
        // Handle error
    }
    if (detectors) {
        auto cave = detectors->GetChild(0);
        if (cave) {
            FairXMLDetectorColor detCol(cave);
            detCol.Colorize(gGeoManager->GetTopNode());
        } else {
            // Handle error
        }
    } else {
        // Handle error
    }
    gEve->Redraw3D();
}

@@ -84,7 +84,7 @@ void FairEventManager::Init(Int_t visopt, Int_t vislvl, Int_t maxvisnds)
fWorldSizeY = box->GetDY();
fWorldSizeZ = box->GetDZ();
}
if (!fXMLConfig.EqualTo(""))
if (fXMLFile)
Copy link

Choose a reason for hiding this comment

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

Add a check to ensure fXMLFile is valid before calling LoadXMLSettings.

The method should include a check to ensure fXMLFile is valid before calling LoadXMLSettings.

if (fXMLFile && fXMLFile->IsValid()) {
    LoadXMLSettings();
}

fairroot/eventdisplay/FairEventManager.cxx Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants