TGeoIterator
A geometry iterator that sequentially follows all nodes of the geometrical
hierarchy of a volume. The iterator has to be initiated with a top volume
pointer:
TGeoIterator next(myVolume);
One can use the iterator as any other in ROOT:
TGeoNode *node;
while ((node=next())) {
}
The iterator can perform 2 types of iterations that can be selected via:
next.SetType(Int_t type);
Here TYPE can be:
0 (default) - 'first daughter next' behavior
1 - iteration at the current level only
Supposing the tree structure looks like:
TOP ___ A_1 ___ A1_1 ___ A11_1
| | |___ A12_1
| |_____A2_1 ___ A21_1
| |___ A21_2
|___ B_1 ...
The order of iteration for TYPE=0 is: A_1, A1_1, A11_1, A12_1, A2_1, A21_1,
A21_2, B_1, ...
The order of iteration for TYPE=1 is: A_1, B_1, ...
At any moment during iteration, TYPE can be changed. If the last iterated node
is for instance A1_1 and the iteration type was 0, one can do:
next.SetType(1);
The next iterated nodes will be the rest of A daughters: A2,A3,... The iterator
will return 0 after finishing all daughters of A.
During iteration, the following can be retreived:
- Top volume where iteration started: TGeoIterator::GetTopVolume()
- Node at level I in the current branch: TGeoIterator::GetNode(Int_t i)
- Iteration type: TGeoIterator::GetType()
- Global matrix of the current node with respect to the top volume:
TGeoIterator::GetCurrentMatrix()
The iterator can be reset by changing (or not) the top volume:
TGeoIterator::Reset(TGeoVolume *top);
Example:
We want to find out a volume named "MyVol" in the hierarchy of TOP volume.
TIter next(TOP);
TGeoNode *node;
TString name("MyVol");
while ((node=next()))
if (name == node->GetVolume()->GetName()) return node->GetVolume();