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

Hiding subtraction volumes from Geant4 visualization #43

Merged
merged 2 commits into from
Oct 16, 2024
Merged

Conversation

ggalgoczi
Copy link
Collaborator

Added code to check if any solids are subtraction solids. Hide these volumes from visualization (NOT deleting anything)

This is needed as QT and OGL fails to plot these properly.

…volumes from visualization (NOT deleting anything)
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Cpp-linter Review

Used clang-format v12.0.1

Only 7 out of 8 clang-format concerns fit within this pull request's diff.

Click here for the full clang-format patch
diff --git a/src/g4app.h b/src/g4app.h
index 4f2db12..771938c 100644
--- a/src/g4app.h
+++ b/src/g4app.h
@@ -4,2 +3,0 @@
-#include "G4SubtractionSolid.hh"
-#include "G4LogicalVolumeStore.hh"
@@ -7,0 +6 @@
+#include "G4LogicalVolumeStore.hh"
@@ -12,0 +12 @@
+#include "G4SubtractionSolid.hh"
@@ -36,2 +36 @@
-
-bool IsSubtractionSolid(G4VSolid* solid)
+bool IsSubtractionSolid(G4VSolid *solid)
@@ -43 +42 @@ bool IsSubtractionSolid(G4VSolid* solid)
-    if (dynamic_cast<G4SubtractionSolid*>(solid))
+    if (dynamic_cast<G4SubtractionSolid *>(solid))
@@ -47 +46 @@ bool IsSubtractionSolid(G4VSolid* solid)
-    G4BooleanSolid* booleanSolid = dynamic_cast<G4BooleanSolid*>(solid);
+    G4BooleanSolid *booleanSolid = dynamic_cast<G4BooleanSolid *>(solid);
@@ -50,2 +49,2 @@ bool IsSubtractionSolid(G4VSolid* solid)
-        G4VSolid* solidA = booleanSolid->GetConstituentSolid(0);
-        G4VSolid* solidB = booleanSolid->GetConstituentSolid(1);
+        G4VSolid *solidA = booleanSolid->GetConstituentSolid(0);
+        G4VSolid *solidB = booleanSolid->GetConstituentSolid(1);
@@ -78,23 +77,23 @@ struct DetectorConstruction : G4VUserDetectorConstruction
-	G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
-
-    	static G4VisAttributes invisibleVisAttr(false);
-
-       	// Check if the store is not empty
-    	if (lvStore && !lvStore->empty())
-    	{
-        // Iterate over all logical volumes in the store
-        for (auto& logicalVolume : *lvStore)
-        	{
-            	G4VSolid* solid = logicalVolume->GetSolid();
-
-            	// Check if the solid uses subtraction
-            	if (IsSubtractionSolid(solid))
-            		{
-                	// Assign the invisible visual attributes to the logical volume
-                	logicalVolume->SetVisAttributes(&invisibleVisAttr);
-
-                	// Optionally, print out the name of the logical volume
-                	G4cout << "Hiding logical volume: " << logicalVolume->GetName() << G4endl;
-            		}
-        	}
-    	}	
+        G4LogicalVolumeStore *lvStore = G4LogicalVolumeStore::GetInstance();
+
+        static G4VisAttributes invisibleVisAttr(false);
+
+        // Check if the store is not empty
+        if (lvStore && !lvStore->empty())
+        {
+            // Iterate over all logical volumes in the store
+            for (auto &logicalVolume : *lvStore)
+            {
+                G4VSolid *solid = logicalVolume->GetSolid();
+
+                // Check if the solid uses subtraction
+                if (IsSubtractionSolid(solid))
+                {
+                    // Assign the invisible visual attributes to the logical volume
+                    logicalVolume->SetVisAttributes(&invisibleVisAttr);
+
+                    // Optionally, print out the name of the logical volume
+                    G4cout << "Hiding logical volume: " << logicalVolume->GetName() << G4endl;
+                }
+            }
+        }

Have any feedback or feature suggestions? Share it here.

src/g4app.h Outdated
Comment on lines 4 to 5
#include "G4SubtractionSolid.hh"
#include "G4LogicalVolumeStore.hh"
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format suggestion

Please remove the line(s)

  • 4
  • 5

src/g4app.h Show resolved Hide resolved
src/g4app.h Outdated
Comment on lines 36 to 37

bool IsSubtractionSolid(G4VSolid* solid)
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
bool IsSubtractionSolid(G4VSolid* solid)
bool IsSubtractionSolid(G4VSolid *solid)

src/g4app.h Outdated
return false;

// Check if the solid is directly a G4SubtractionSolid
if (dynamic_cast<G4SubtractionSolid*>(solid))
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
if (dynamic_cast<G4SubtractionSolid*>(solid))
if (dynamic_cast<G4SubtractionSolid *>(solid))

src/g4app.h Outdated
return true;

// If the solid is a Boolean solid, check its constituent solids
G4BooleanSolid* booleanSolid = dynamic_cast<G4BooleanSolid*>(solid);
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
G4BooleanSolid* booleanSolid = dynamic_cast<G4BooleanSolid*>(solid);
G4BooleanSolid *booleanSolid = dynamic_cast<G4BooleanSolid *>(solid);

src/g4app.h Outdated
Comment on lines 50 to 51
G4VSolid* solidA = booleanSolid->GetConstituentSolid(0);
G4VSolid* solidB = booleanSolid->GetConstituentSolid(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
G4VSolid* solidA = booleanSolid->GetConstituentSolid(0);
G4VSolid* solidB = booleanSolid->GetConstituentSolid(1);
G4VSolid *solidA = booleanSolid->GetConstituentSolid(0);
G4VSolid *solidB = booleanSolid->GetConstituentSolid(1);

src/g4app.h Outdated
Comment on lines 78 to 100
G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();

static G4VisAttributes invisibleVisAttr(false);

// Check if the store is not empty
if (lvStore && !lvStore->empty())
{
// Iterate over all logical volumes in the store
for (auto& logicalVolume : *lvStore)
{
G4VSolid* solid = logicalVolume->GetSolid();

// Check if the solid uses subtraction
if (IsSubtractionSolid(solid))
{
// Assign the invisible visual attributes to the logical volume
logicalVolume->SetVisAttributes(&invisibleVisAttr);

// Optionally, print out the name of the logical volume
G4cout << "Hiding logical volume: " << logicalVolume->GetName() << G4endl;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format suggestion

Suggested change
G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
static G4VisAttributes invisibleVisAttr(false);
// Check if the store is not empty
if (lvStore && !lvStore->empty())
{
// Iterate over all logical volumes in the store
for (auto& logicalVolume : *lvStore)
{
G4VSolid* solid = logicalVolume->GetSolid();
// Check if the solid uses subtraction
if (IsSubtractionSolid(solid))
{
// Assign the invisible visual attributes to the logical volume
logicalVolume->SetVisAttributes(&invisibleVisAttr);
// Optionally, print out the name of the logical volume
G4cout << "Hiding logical volume: " << logicalVolume->GetName() << G4endl;
}
}
}
G4LogicalVolumeStore *lvStore = G4LogicalVolumeStore::GetInstance();
static G4VisAttributes invisibleVisAttr(false);
// Check if the store is not empty
if (lvStore && !lvStore->empty())
{
// Iterate over all logical volumes in the store
for (auto &logicalVolume : *lvStore)
{
G4VSolid *solid = logicalVolume->GetSolid();
// Check if the solid uses subtraction
if (IsSubtractionSolid(solid))
{
// Assign the invisible visual attributes to the logical volume
logicalVolume->SetVisAttributes(&invisibleVisAttr);
// Optionally, print out the name of the logical volume
G4cout << "Hiding logical volume: " << logicalVolume->GetName() << G4endl;
}
}
}

clang-format --style=microsoft -i src/g4app.h
@github-actions github-actions bot dismissed their stale review October 16, 2024 15:01

outdated suggestion

@plexoos
Copy link
Member

plexoos commented Oct 16, 2024

Thank you for the patch Gabor! I am now able to visualize pfRICH_complex.gdml when skipping the mesh construction:

GEOM=fakegeom build/src/simg4ox -g esi-g4ox/geom/pfRICH_complex.gdml -m esi-g4ox/vis.mac -i

@plexoos plexoos merged commit 666cc0f into main Oct 16, 2024
2 checks passed
@plexoos plexoos deleted the GDML_checker branch October 16, 2024 15:31
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