Move TGeoVolumes around

Hello everybody,
I’m using ROOT 4.03.02 to build a very simple geometry with a top volume and a module volume inside. Now I want to move around the module quite often to calculate different intersections with a track. So I do something like

top->ClearNodes();

ph->Clear();   //a TGeoCombiTrans*
ph->SetTranslation(x,y,z);
ph->RotateZ(gamma/degree);
ph->RotateY(beta/degree);
ph->RotateX(alpha/degree);
	
top->AddNode(module,1, ph);

which gives a big memory leak. To avoid this I tried to free some memory when I ClearNodes by using

TObjArray* del=top->GetNodes();
if (del) del->SetOwner(kTRUE); //I guess otherwise matrices would keep being around
top->ClearNodes();
if (del) delete del;

This fixes about 90% of memory usage, but somehow can’t be used on more complicated geometries.

Is there a supposed way to move around existing volumes in a geometry? Can’t you just alter the transformation matrix and let the geometry manager know?

Thx
Tobias

Hi Tobias,

In the geometry package there are unfortunatelly still several methods that should be private or protected but they are not because they have to be called by external classes for internal purposes. TGeoVolume::ClearNodes() is one of them (as well as getting the pointer of the nodes array and deleting by hand).

Yes, there is an easier way of doing what you want:

// Create a "physical node" by specifying the path to your module
TGeoPhysicalNode *physical = gGeoManager->MakePhysicalNode("/TOP_1/MODULE_1");
// Get the pointer to the current local matrix of MODULE w.r.to TOP
TGeoMatrix *matrix = physical->GetNode()->GetMatrix();
// Change the matrix yourself or define a new one (you do not have to delete the old one)
...
// Now re-align your module with this matrix
physical->Align(matrix);

Your geometry now will have a new position for MODULE_1 and you can ask for crossing distance or whatever. You can do the Align part in a loop if you want, without deleting the physical node object. See also: $ROOTSYS/tutorials/geodemo.C in methods ideal() and align()
[
Hope this helps,

Yes, it helps partly.
Now I know how to do it properly; once I saw it in the geoDemo but forgot about it.
Thanks very much for your help.

So it works correctly, but the big memleak is back. Doing it ~3million times consumes more than 1GB of memory!
This is what I wrote:

if (node->IsAligned())
	combi = (TGeoCombiTrans*)node->GetNode()->GetMatrix();
else
	combi = new TGeoCombiTrans();

combi->Clear();
combi->RotateZ(gamma/degree);
combi->RotateY(beta/degree);
combi->RotateX(alpha/degree);
combi->SetTranslation(x,y,z);

node->Align(combi);

geometry creation is done once:

top=gGeoManager->MakeBox("TOP",Vac,1*m,1*m,1*m);
module=gGeoManager->MakeBox("MODULE",Si,0.5*DetSizeX,0.5*DetSizeY,0.5*DetSizeZ);
gGeoManager->SetTopVolume(top);
top->AddNode(module,1);
gGeoManager->CloseGeometry();

node = gGeoManager->MakePhysicalNode("/TOP_1/MODULE_1");

Is this a bug in ROOT or is there something wrong with the cast combi = (TGeoCombiTrans*) …?

Greetings
Tobias

Hi Tobias,

The memory leak comes from the Align() method. I will fix it tomorrow and let you know.
Thanks for reporting this.

Hi Tobias,

Fix in CVS. Please checkout geom and geompainter modules, check again your stuff and let me know if you still have problems.
Regards,

sorry to bother you again,
I checked out the two packages. Can I just compile those two seperately on my local directory and use the rest of ROOT from the institute-wide installation? (For example by setting the LD_LIBRARY_PATH variable)
Or do I have to install my own complete copy of ROOT?
Are these Module.mk makefiles that can be used standalone?

Thanks
Tobias

Hi Tobias,

The Module.mk is not standalone, but of course you might be able to change it to do what you want.
However, is it so difficult for you to make a local installation from CVS? It would make things a bit easier…

Cheers,