Draw world during the visualization

Hello, is there a way to draw the world volume during the visualization? I’m interested to get photons out of the world but, as you can read here Getting particles out of the world I tried more codes, but I can’t get them. Then, I would like to see by visualization if there are particles out of the world (i.e. it’s just a problem of the code) or really there aren’t particles out of the world). It means I need a way to see the world and trajectories ot of the world (if it’s possibile to do it).
Thank you

Somewhere in your code, or in a macro file, you must be making the world invisible. Remove that or

/vis/geometry/set/visibility <world-logical-volume-name> 0 true

Thank you @allison it worked

Hi allison,

is it possible to give certain objects some transparency?

Set the fourth component of colour to something less than 1.

See exampleB1

# "Envelope" is transparent blue to represent water
/vis/geometry/set/colour Envelope 0 0 0 1 .3

You may also set the colour (including transparency) in the vis attributes of the logical volume in your C++ code.

You should really get into the habit of reading the documentation and looking at examples so you don’t have to post such basic questions on the forum.

1 Like

Thank you!

When I look into the gamma knife example where the colors are defined:

G4VisAttributes * grayFe = new G4VisAttributes(G4Colour(0.5 ,0.5 ,0.5));
grayFe → SetVisibility(true);
grayFe → SetForceSolid(true);

G4VisAttributes * blueCobalt = new G4VisAttributes(G4Colour(0. ,0. ,0.7));
blueCobalt → SetVisibility(true);
blueCobalt → SetForceSolid(true);

G4VisAttributes * graySS = new G4VisAttributes(G4Colour(0.9 ,0.9 ,0.9));
graySS → SetVisibility(true);
graySS → SetForceSolid(true);

G4VisAttributes * grayAl = new G4VisAttributes(G4Colour(0.7 ,0.7 ,0.7));
grayAl → SetVisibility(true);
grayAl → SetForceSolid(true);

G4VisAttributes * blackLead = new G4VisAttributes(G4Colour(0.2 ,0.2 ,0.2));
blackLead → SetVisibility(true);
blackLead → SetForceSolid(true);

G4VisAttributes * colorTungsten = new G4VisAttributes(G4Colour(0.3 ,0.3 ,0.3));
colorTungsten → SetVisibility(true);
colorTungsten → SetForceSolid(true);

I don’t see a fourth parameter representing any alpha values? And indeed, when I add a fourth parameter in my own code, it doesn’t affect anything.

In the source code it is given:

Definition at line 43 of file G4Colour.cc.

00043 :
00044 red (v.x()), green (v.y()), blue (v.z()), alpha (1.)
00045 {
00046 if( red > 1.0 ){red = 1.0;} if( red < 0.0 ){red = 0.0;}
00047 if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
00048 if( blue > 1.0 ){blue = 1.0;} if( blue < 0.0 ){blue = 0.0;}
00049 }

Well, I figured out there is something odd in general. Indeed, when I add a fourth value, something is changing but it seems like it is making some sections of the object invisible:

Front when I run:

When I change the perspective:

Issue could also be that the object within the larger box has the same color (which it shouldn’t…). Might be due to Replica I used, have to figure out…
That’s why I didn’t see any changes…

Ok, I checked. I didn’t use Replica but it seems that objects which are placed inside the box have the same color. I guess I created a solid box which I didn’t want to but I didn’t realize as I saw only the edges all the time before… :smiley:

see here:

Say you add transparency:

G4VisAttributes * grayFe = new G4VisAttributes(G4Colour(0.5 ,0.5 ,0.5,0.5));

This invokes the constructor at line 35, not line 44. You misread the code.

     35 G4Colour::G4Colour (G4double r, G4double gr, G4double b, G4double a):
     36 red (r), green (gr), blue (b), alpha (a)
     37 {
     38   if( red   > 1.0 ){red   = 1.0;} if( red   < 0.0 ){red   = 0.0;}
     39   if( green > 1.0 ){green = 1.0;} if( green < 0.0 ){green = 0.0;}
     40   if( blue  > 1.0 ){blue  = 1.0;} if( blue  < 0.0 ){blue  = 0.0;}
     41   if( alpha > 1.0 ){alpha = 1.0;} if( alpha < 0.0 ){alpha = 0.0;}
     42 }

(You must learn how to read C++ code.)

Anyway, great! I see you have marked the problem solved.