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.

Thank you, I went over the code too sloppily so I didn’t see this difference in the code. Thanks for highlighting.

But this wouldn’t affect the code above as I’m not using a G4ThreeVector there, right? I tried something like

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

a lot but, yet, it didn’t work. And in the code from the gamma knife you can see that they didn’t even use the fourth parameter for alpha to make the objects transparent. I wonder how they did instead? I also can’t see any commands in the .mac files…?

Nevertheless, I guess my issue arises from the situation that I am placing objects within a solid other one. I’m rectifying this now as I had no time until now. I will keep you updated :slight_smile:

Maybe you mean wireframe?

/vis/viewer/set/style wireframe

Maybe, will try out! But in general, I would like to make my objects look transparent/shiny like this:

gammaknife_3

I guess the alpha parameter is indeed working (meanwhile?) but, as guessed before, any volumes or daughter volumes I position within another object take on the same color:

When these little boxes are outside of the bigger (red) one they look blue:

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

G4VisAttributes * red= new G4VisAttributes(G4Colour(0.8 ,0.3 ,0.5, 0.1));
red-> SetVisibility(true);
red-> SetForceSolid(true);

real_box_log → SetVisAttributes(red);
logicDetector → SetVisAttributes(blueCobalt);

But when I look at the gamma knife example it looks just transparent as one would expect. I still don’t know how/where they set the transparency in the code?