Geometry Package & GDML

OS: Linux Red Hat Enterprise 6.7
ROOT: 5.34/21

I am attempting a simple GDML Import/Export test with ROOT. I started by following a few tutorials (link) on how to create a world and add nodes to volumes, and how to export the world to a GDML file.

I wrote a macro “worldMake.c” to create a world with a box at the centre, and export it to “world.gdml”. Fig. 1 shows the result of Draw() with no options, or with “ogle”. Fig. 2 shows Draw() with options “ogl”. I think “ogl” means OpenGL, but I’m not sure what the “e” means.

[code]
void worldMake() {
gSystem->Load(“libGeom”);
gSystem->Load(“libGdml”);

new TGeoManager("world", "the simplest geometry");

TGeoMaterial *mat = new TGeoMaterial("Vacuum", 0, 0, 0 );
mat->SetTransparency( 50 );
TGeoMedium *med = new TGeoMedium("Vacuum", 1, mat );

TGeoVolume *top = gGeoManager->MakeBox("Top", med, 10., 10., 10. );
gGeoManager->SetTopVolume( top );
top->SetLineColor( kMagenta );

TGeoVolume *box = gGeoManager->MakeBox("Box", med, 2., [attachment=0]draw_ogl_worldDraw.png[/attachment]2., 2. );
box->SetLineColor( kRed );

TGeoTranslation *tr1 = new TGeoTranslation( .4, .4, .4 );
top->AddNode( box, 1, tr1 );

gGeoManager->CloseGeometry();

gGeoManager->SetTopVisible();
top->Draw(); // add "ogle" for OpenGL (not sure what the e means)

gGeoManager->Export("world.gdml");

}
[/code]File 1: “worldMake.c”

[code]

<?xml version="1.0"?> [/code][i]File 2: "world.gdml"[/i]




I wrote another macro “worldDraw.c” to import the GDML file and recreate the world. However, Draw() with no options, or “ogle”, produces a blank canvas with no wireframe (Fig. 3). Draw() with options “ogl” (Fig. 4) produces a blank canvas and an OpenGL window in monochrome and opaque volumes, despite the transparency set in “worldMake.c”.

void worldDraw() { gSystem->Load("libGeom"); gSystem->Load("libGdml"); TGeoManager *geom = TGeoManager::Import("world.gdml"); TGeoVolume *top = gGeoManager->GetTopVolume(); //geom-> //top->SetLineColor( kRed ); top->Draw(); } File 3: “worldDraw.c”




I understand that GDML does not store colour and transparency data, as that’s up to the renderer to define, so I would like to know how to identify and reference the materials and volumes in order to define colours etc in “worldDraw.c”. I imagine I need to call something like GetTopVolume() to access the materials and volumes, but the documentation and reference manuals are hard to follow. :frowning:

Some other things I’ve noticed about the documentation: I cannot find a list of accepted arguments for the Draw() options (link). I only heard about “ogle” from world of mouth/other forums!

This is my first time using ROOT (and this forum), and would appreciate any advice you can give! Please let me know if there’s too much information, and I’ll try to refine it.

Many thanks,
Peter
:smiley:

Hi Peter,

You can lookup materials and volumes by name or id using gGeoManager pointer ( see GetMaterial() and GetVolume() functions). GDML does not carry indeed colour/transparency information - you would have to export in ROOT format for that. The options to be passed to Draw() are not only geometry specific, but more general - as far as I recall “e” from “ogle” was standing for GL in the pad, but I forgot how to activate it.

Cheers,

HI Andrei,

Thanks for your help! :slight_smile:

Here’s a screenshot of it working:


void worldDraw() {
    gSystem->Load("libGeom");
    gSystem->Load("libGdml");
    TGeoManager *geom = TGeoManager::Import("world.gdml");
    TGeoMaterial *mat = geom->GetMaterial("Vacuum");
    mat->SetTransparency( 50 );
    TGeoVolume *top = gGeoManager->GetTopVolume();
    top->SetLineColor( kRed );
    geom->SetTopVisible();
    TGeoVolume *box =  geom->GetVolume("Box");
    box->SetLineColor( kGreen );
    top->Draw("ogl");
}

Some more questions:

:question: Is there a way to parse a GDML file so that you don’t have to know the names of the materials and volumes in order to Get() them? I’d like to be able to read an arbitrary GDML file and display the contents.
:question: How do IDs work?

:question: Could you preserve settings like transparency and colour to do with displaying the contents of a GDML file by writing them to a data file that could be parsed by ROOT? e.g.

-- file "world.dat" --
transparency "Vacuum" 50
lineColor "Top" kRed
lineColor "Box" kGreen
-- end "world.dat" --

:bulb: Perhaps an XML file? (I guess it would make sense to have it look similar to GDML)

<?xml version="1.0">
<data>
	<materials>
		<material name="Vacuum">
			<transparency value="50"/>
		</material>
	</materials>
	<structure>
	<volume name="Top">
			<lineColor value="kRed">
		</volume>
		<volume name="Box">
			<lineColor value="kGreen">
		</volume>
	</structure>
</data>

Thanks,
Peter
:smiley:

Hi Peter,

You can do this after the GDML has been read, using TGeoManager interface: GetListOfMaterials() and GetListOfVolumes()

The id’s can be used as a faster way to access geometry elements once you know which id corresponds to which element.

The idea is that the gdml file generated by root has to be readable by Geant4, so the xml schema can be indeed extended in such a way that the reader/writer of root uses it while the reader/writer of G4 ignores it. Contributions along this line require modifying the TGDMLRead and TGDMLWrite and would be very appreciated =D>
Best,

Hi Andrei,

I’m trying to use TList to set all materials to 50% transparency, but the tutorial/example here is confusing. :confused:

Even though there’s only one material, I think it’s easier to refer to it as the 1st item in a list than by name.

:bulb: here’s some pseudocode of C++/Java and ROOT to help explain what I want to do:

TList<TGeoMaterial> matList = geom->GetListOfMaterials();
for( int i = 0; i < matList.size(); i++ ) {
	matList.getItem(i).SetTransparency( 50 );
}

here’s some attempts I’ve made by trying to follow the examples

void worldDraw() {
    gSystem->Load("libGeom");
    gSystem->Load("libGdml");
    TGeoManager *geom = TGeoManager::Import("world.gdml");

    TList *matList = geom->GetListOfMaterials();

    // 2nd example method *doesn't work*
    /*struct SSetMaterial {
        bool operator()( TObject *aObj ) {
            aObj->SetTransparency( 50 );
            return true;
        }
    }
    TIter iter(matList);
    for_each( iter.Begin(), TIter::End(), SSetMaterial() );*/

    // 3rd exmaple method *doesn't work*
    /*TIter next( matList );
    while( ( TGeoMaterial *mat = next() ) ) { // Error: Symbol TGeoMaterial is not defined in current scope
        mat->SetTransparency( 50 );
    }
    */

    // manual, using name
    /*TGeoMaterial *mat = geom->GetMaterial("mat_vacuum");
      mat->SetTransparency( 50 );*/
    
    TGeoVolume *top = gGeoManager->GetTopVolume();
    top->SetLineColor( kRed );
    geom->SetTopVisible();
    TGeoVolume *box =  geom->GetVolume("vol_box");
    box->SetLineColor( kGreen );
    top->Draw("ogl");
}

Thanks,
Peter
:smiley:

Hi Peter,

    TIter next( matList );
    TGeoMaterial *mat; // cannot do declarations in a while loop
    while( (mat = next() ) ) mat->SetTransparency( 50 );

Note that transparency>=50 makes the volume invisible in the pad draw (Draw("") with no option), but transparent with “ogl”

Best,

Hi Andrei,

I found that casting from TObject to TGeoMaterial helps, but the while loop still doesn’t work. I get the following error: :frowning:

Limitation: Cint does not support full iostream functionality in this platform worldDraw.c:16:
void worldDraw() {
    gSystem->Load("libGeom");
    gSystem->Load("libGdml");
    TGeoManager *geom = TGeoManager::Import("world.gdml");

    TList *matList = geom->GetListOfMaterials();
    //cout << matList << endl;
    TIter next( matList );
    //TObject *mat;
    TGeoMaterial *mat;
    
    // this works
    /*mat = (TGeoMaterial) next();
    cout << mat << endl;
    mat = (TGeoMaterial) next();
    cout << mat << endl;*/
    
    // this doesn't work
    while( mat = (TGeoMaterial) next() ) { mat->SetTransparency( 50 ); } // line 16
}

Thanks,
Peter
:smiley:

Hi Peter,

Look at the attached example:
.L materials.C
materials()

Cheers,
materials.C (375 Bytes)