Re: Level of a TGeoNode/TGeoVolume

From: Andrei Gheata <Andrei.Gheata_at_cern.ch>
Date: Wed, 30 Nov 2005 15:22:17 +0100


Hi Christian,

I do not really see the point for such a complex query in your case. Indeed, a "geometry iterator" may do the job, but such a search by name may be always error prone. Generally one knows a priory the depth of any node in his geometry since he has to build it. I agree that there might be cases when the depth may not be constant (e.g. positioning the same volume in containers at different depths), but if this is the case the iterator will not necessary give you the right answer... The argument with complicated volume made by composition does not stand since there you do not use volumes, but shapes so you can provide a different identifier (name).
Anyway, if the relative depth that you need is really a variable that you can identify only run time, any sort of iterators like this will give you a severe penalty in simulation time, so you better think of something else.

Cheers,
Andrei

Christian Holm Christensen wrote:

>Hi there,
>
>Is there a way to get the level (depth) of a given TGeoNode/TGeoVolume
>in a geometry? What I'd like to do is to get the level of some
>nodes/volumes and then calculate the relative depth of the
>nodes/volumes. For example
>
> Int_t a_level = gGeoManager->GetLevel("A_1");
> Int_t b_level = gGeoManager->GetLevel("B_1");
> Int_t depth = b_level - a_level;
>
>This number `depth' will then be used in a stepping routine in a
>simulation (using VMC) to get ID's of parent volumes.
>
>Note, that depending on the actual the geometry, the relative depth may
>vary. For example, you may implement two kinds of geometries: One
>where you do an effective volume, and one where you make a complicated
>volume using intersections and so on. Hence, the depth may not be
>known a priori, at least not until the geometry has been closed.
>
>Perhaps something like the attached?
>
>Yours,
>
>
>
>------------------------------------------------------------------------
>
>#include <TGeoManager.h>
>#include <TGeoVolume.h>
>#include <TObjArray.h>
>#include <iostream>
>
>//____________________________________________________________________
>Int_t CheckNodes(TGeoNode* node, const char* name, Int_t& lvl)
>{
> // If there's no node here.
> if (!node) return -1;
> // Check if it this one
> TString sname(name);
> if (sname == node->GetName()) return lvl;
>
> // Check if the node is an immediate daugther
> TObjArray* nodes = node->GetNodes();
> if (!nodes) return -1;
> // Increase the level, and search immediate sub nodes.
> lvl++;
> TGeoNode* found = static_cast<TGeoNode*>(nodes->FindObject(name));
> if (found) return lvl;
>
> // Check the sub node, if any of their sub-nodes match.
> for (Int_t i = 0; i < nodes->GetEntries(); i++) {
> TGeoNode* sub = static_cast<TGeoNode*>(nodes->At(i));
> if (!sub) continue;
> // Recurive check
> if (CheckNodes(sub, name, lvl) >= 0) return lvl;
> }
> // If not found, decrease the level
> lvl--;
> return -1;
>}
>//____________________________________________________________________
>Int_t
>FindNodeDepth(const char* name)
>{
> TGeoNode* node = gGeoManager->GetTopNode();
> Int_t lvl = 0;
> return CheckNodes(node, name, lvl);
>}
>//____________________________________________________________________
>Int_t CheckVolumes(TGeoVolume* vol, const char* name, Int_t& lvl)
>{
> // If there's no node here.
> if (!vol) return -1;
> // Check if it this one
> TString sname(name);
> if (sname == vol->GetName()) return lvl;
>
> // Check if the node is an immediate daugther
> TObjArray* nodes = vol->GetNodes();
> if (!nodes) return -1;
>
> // Increase level
> lvl++;
> // Check the sub node, if any of their sub-nodes match.
> for (Int_t i = 0; i < nodes->GetEntries(); i++) {
> TGeoNode* node = static_cast<TGeoNode*>(nodes->At(i));
> if (!node) continue;
> TGeoVolume* sub = node->GetVolume();
> if (!sub) continue;
> if (sname == sub->GetName()) return lvl;
> // Recurive check
> if (CheckVolumes(sub, name, lvl) >= 0) return lvl;
> }
> // If not found, decrease the level
> lvl--;
> return -1;
>}
>//____________________________________________________________________
>Int_t
>FindDepth(const char* name)
>{
> TGeoVolume* top = gGeoManager->GetTopVolume();
> Int_t lvl = 0;
> return CheckVolumes(top, name, lvl);
>}
>//____________________________________________________________________
>//
>// EOF
>//
>
>
>
>
Received on Wed Nov 30 2005 - 15:20:23 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET