Q: Is there any way to get pointer to a node by using path?

Hi,

Is there any way to get the pointer to a node by using path name?
For example, I have a volume and try to divide it along three axes in the order of x,y,z.
Then I’m going to select a node by using index (i,j,k), which looks like TOP_1 ->SLICEX_i ->SLICEY_j -> SLICEZ_k. I expected to find some methods such as gGeoManager->GetNode("/TOP_1/SLICEX_i/SLICEY_j/SLICEZ_k") but I couldn’t find one.

Could you please let me know an easy way to get that?

Thanks in advance,
Yun-Ha

Hi Yun-Ha,

Use:

gGeoManager->cd("/TOP_1/SLICEX_i/SLICEY_j/SLICEZ_k") ; gGeoManager->GetCurrentNode();

Cheers,

Hi Andrei,

Thank you so much for your help.

Yun-Ha

Hi,

Now I can get the pointer to a TGeoNode by using path.
Since TGeoNode represents positioned volume, it seemed that the attributes could be set separately. Thus I tried to divide a box in geodemo.C

TGeoVolume *sliceY = sliceX->Divide(“SLICEZ”, ndiv=8, start=0, step=0);

gGeoManager->cd("/TOP_1/BOX_1/SLICEX_1/SLICEY_1/SLICEZ_1");
gGeoManager->GetCurrentNode()->GetVolume()->SetLineColor(kBlue);

gGeoManager->cd("/TOP_1/BOX_1/SLICEX_1/SLICEY_2/SLICEZ_3");
gGeoManager->GetCurrentNode()->GetVolume()->SetLineColor(kBlue);
top->Draw();

As a result the whole box becomes green. Then I tried blindly to create TGeoPhysicalNode and tried again

TGeoPhysicalNode *node1 = gGeoManager->cd("/TOP_1/BOX_1/SLICEX_1/SLICEY_1/SLICEZ_1");
node1->GetVolume()->SetLineColor(kBlue);

node2->GetVolume()->SetLineColor(kGreen);

The result was the same. It seems that it has something to do with GetVolume() which returns volume group “SLICEZ”.

Could you please let me know how to get correct result; set attributes separately, for example, different color and visibility.

Thanks in advance,
Yun-Ha

Hi Yun-Ha,

Not true - the node as object is the combination from a volume and a matrix. It is the volume that holds the color property. In your case the 2 nodes are pointing to the same volume so you cannot give them different colors. Some properties (like visibility) can be set also for nodes but you should be aware that in case of replication of the parent volume this will apply also for replicas.
So you can set different colors only for different volumes; in case of a division on X/Y/Z all cells are represented by the same volume - so you can’t.

However, if using the GL viewer (e.g. canvas/View/ViewWith/OpenGL) you can shift-click on volumes and change colors individually or as a group. This is not persistent.

Cheers,

[quote=“agheata”]Hi Yun-Ha,

Not true - the node as object is the combination from a volume and a matrix. It is the volume that holds the color property. In your case the 2 nodes are pointing to the same volume so you cannot give them different colors. Some properties (like visibility) can be set also for nodes but you should be aware that in case of replication of the parent volume this will apply also for replicas.
So you can set different colors only for different volumes; in case of a division on X/Y/Z all cells are represented by the same volume - so you can’t.

However, if using the GL viewer (e.g. canvas/View/ViewWith/OpenGL) you can shift-click on volumes and change colors individually or as a group. This is not persistent.

Cheers,[/quote]

Hello, rooters,

I also tried to assign different colors to different physical notes, which are different placements of the same volume. What I am trying to do is to display hits in a PMT array by coloring PMTs according to the energies recorded by them. Now it turns out that I cannot do this, could you please suggest some other ways to display events? (Of course I can create one volume for each PMT, but that would make the construction of the PMT array much more difficult…)

thank you,

Jing

Hi Yun-Ha,

Please check this out: $ROOTSYS/tutorials/geom/runplugin.C
Cheers,

[quote=“agheata”]Hi Yun-Ha,

Please check this out: $ROOTSYS/tutorials/geom/runplugin.C
Cheers,[/quote]

Dear Andrei,

great, exactly want I am looking for. Thank you. Some more questions:

  1. an iterator is used, this means that every time I have to loop a certain amount of paths (strings) to get the node I want. But I know in advance the path. Is there a way to get the node directly by it’s path and set the color?

  2. the color is changed this way:

  TGeoVolume *vol = fIterator->GetNode(level)->GetVolume();
  vol->SetLineColor(fColor);

meaning that you still change the color of the VOLUME associated to the node. Presumably, all the nodes associated to the same volume will change color as we discussed before. Could you please explain why this time it only changes the color of one node?

Cheers, Jing

Hi again Yun-Ha,

In fact, there is a main painting loop that loops all nodes, checks if the current one should be drawn (according visibility settings), then takes the color of its volume to make it current. When you have an iterator plugin this is called within this main painting loop. The original volume color is backed-up so it is safe for you to change it (will be restored after the paint loop). If you know the path to your hit node, you just check this in your iterator plugin and change its color if the current node matches.

All this iterator plugin is in fact a trick to allow user actions during a hierarchy loop and it has this special usage when attached to the main painting loop. Hope it helps for your needs.

Cheers,

I am another guy :smiley: I just followed this subject after I got it from a search in this forum.

nice explanation. Thank you. Just for my further understanding, is it true that this painting loop is called even if the user changes the visibility (or color,etc.) of only one node (or rotate the geometry a little bit)? and I don’t need to worry about the efficiency at all because the loop is executed anyhow, right?

Cheers, Jing

Hi Jing,

[quote]I am another guy :smiley: I just followed this subject after I got it from a search in this forum.
[/quote]
Sorry about that :confused:

Right. Of course you should avoid doing lattice QCD calculations within this iterator plug-in :wink:

Cheers,

Dear Andrei,

thank you very much!

Cheers, Jing

[quote=“agheata”]The original volume color is backed-up so it is safe for you to change it (will be restored after the paint loop).
[/quote]

A quick follow up to this -

What’s the easiest way to restore the original volume colors to all the nodes using this volume? Since it’s backed up somewhere I assume there’s some gGeoManager->RestoreOriginalColors() or something similar?

Or should one use the customized iterator to iterate over every node and manually set them back to the original color?

Thanks,

Joe

Hi,
When using an iterator plugin to change node colors, you have to use the same plugin to restore them. In your plugin you can have a setter that does this, based on the volume original color (which is always there)

Regards,