Converting Geant4 geometry to ROOT

Hi all, I have a codebase that simulates some things in Geant4.

I am creating and defining volumes like so:

  G4Tubs* Cover = new G4Tubs("Cover",0.,0.49*MagnetOutOD,0.5*MagnetCover,0.*deg,360.*deg);
  solidMagnetCover = new G4SubtractionSolid("solidMagnetCover", Cover, Bore, 0, 
					    G4ThreeVector(0.,OVCVtOffset,0.));
  logicMagnetCover = new G4LogicalVolume(solidMagnetCover,Aluminium,"logicMagnetCovers");
  physiMagnetCover[0] = new G4PVPlacement(0,G4ThreeVector(0.,0.,-0.5*MagnetOutL+0.5*MagnetCover),
					  logicMagnetCover,"MagnetCover01",
  					  logicCT,false,0,checkOverlaps);
  physiMagnetCover[1] = new G4PVPlacement(0,G4ThreeVector(0.,0.,0.5*MagnetOutL-0.5*MagnetCover),
					  logicMagnetCover,"MagnetCover02",
  					  logicCT,false,1,checkOverlaps);

The other codebase creates it’s geometry like so:


    //------------------------------ 
	// magnetInner
	//------------------------------
    double magnetInner_size[3];
    magnetInner_size[0] =  0.;
    magnetInner_size[1] =  0.5*MagnetInOD;
    magnetInner_size[2] =  0.5*MagnetInL;
    double magnetInner_pos[3];
    magnetInner_pos[0] = 0.;
    magnetInner_pos[1] = 0.;
    magnetInner_pos[2] = 0+CTOffset;
    ///< Geometrical volume
    TGeoVolume *magnetInner = gGeoManager->Volume("magnetInner","TUBE",fmedLiqHe, magnetInner_size, 3);
	magnetInner->SetLineColor(kBlue); magnetInner->SetTransparency(80);
    ///< Physical volume (positioning the geometrical volume)
    TGeoCombiTrans *combimagnetInner = new TGeoCombiTrans("combimagnetInner", magnetInner_pos[0], magnetInner_pos[1], magnetInner_pos[2], nullRot);
    top->AddNode(magnetInner, 0, combimagnetInner);

Which I guess is like the Geant3 way. My question is: how best to go about getting my Geant4 code to match? Is there a converter out there that can parse code (unlikely) how about a resources that easily allows me to see the root style?

For example with creating cylinders I was just by hand making my style match the old style. But now with this off centered cylinder I don’t know how to handle it…?

Cheers.


Please read tips for efficient and successful posting and posting code

_ROOT Version:6+
Platform: Not Provided
Compiler: Not Provided


Hello,

You can use GDML format to export geometry from Geant4 and import it in ROOT.

The other possibility is to use in memory conversion via VGM:
https://vmc-project.github.io/vgm-documentation/

Best regards,

So using GDML to import a GDML file like so:

TGeoVolume* interconnect = gGeoManager->Import("SimpleCrossHighRes_Q235.gdml")->GetVolume("SimpleCrossHighRes_Q235");

Actually seems to remove all my other geometry when I draw. I assume the “Import” overwrites my whole world or something?

Lets say I have a project will many pieces but just want to add a single piece that I have in GDML into the world. How would I go about this? Haven’t been able to find a resource explaining this either.

TIA

So I’m now able to do this:

    TGDMLParse parse;
    TGeoVolume *interconnect = parse.GDMLReadFile("../SimpleCrossHighRes_Q235.gdml");

but get the following error trying to place it:

Converting Root geometry to Geant4 via VGM ...
    RootGM::Factory::ImportSolid:
    Unsupported solid type (solid "SimpleCrossHighRes_Q235-SOL"   type "TGeoTessellated")
*** Warning: Using a box instead  ***
G4Material WARNING: duplicate name of material Copper
Geant4GM::Factory::CreateVolume:
   Medium dummy not found.

Hi @lgolino ,

maybe @agheata can help, and if not he might know who can help :slight_smile: Let’s ping him.

Cheers,
Enrico

Hi, which version of ROOT are you using? Correctly importing tessellated volumes using ROOT GDML reader has been possible since v6-22. I’m not sure about the requirements for the VGM version. You should note that even if being able to import a tessellated volume, ROOT is not able to use navigation functionality with it. Still, for visualization purposes, it should be fine.

1 Like

ROOT 6.24/02
but
G4VMCVER=5.3.0
VGMVER=4.8.0
VMCVER=1.0.3

I also have the stp file, is there a way I can incorperate this piece and have it interact? Or is that not possible with GDML import?

Hi,

I confirm, that VGM does not yet support the tessellated solid, as I overlooked that it’s support has been added in ROOT.

On the other hand, you do not need VGM for going via GDML files, as Geant4 has its G4GDMLParser, that can read the GDML file exported from ROOT.

Best regards,

1 Like

Unfortunately I am adding to a pre existing project, one where everything is written in root with a TGeoManager. It seems I am able to import with

    G4GDMLParser parser;
    parser.Read("SimpleCrossOnlyHighRes.gdml");

but when I try I get:

G4GDML: Reading 'SimpleCrossOnlyHighRes.gdml'...
G4GDML: VALIDATION ERROR! unable to open primary document entity '/home/lgolino/alphasofts/alphasoft-simulations/simulation/a2mc/SimpleCrossOnlyHighRes.gdml' at line: 0

I assume this is simply not possible.

Hi,

I tried export/import with a simple geometry (from the VGM Solids test) and the GDML file exported from ROOT loads fine in Geant4 extended/persistency/gdml/G01 example (after excluding xtru2 solid, with Z-sections with the same z position not supported directly in Geant4), so the problem is probably on your side. (See more details below.)

I have added in meantime the support for Root tessellated solids in the VGM master.

Best regards,


The test:
Export in ROOT:

root [0]  TGeoManager**::Import("Solids.root");
root [0]  gGeoManager**->Export("Solids.gdml";

Import in Geant4:

./load_gdml Solids.gdml

Output:

Usage: load_gdml <intput_gdml_file:mandatory> <output_gdml_file:optional>

G4GDML: Reading 'solids.gdml'...
G4GDML: Reading definitions...
G4GDML: Reading materials...
 G4Material WARNING: define a material with density=0 is not allowed. 
 The material Vacuum will be constructed with the default minimal density: 1e-25g/cm3
G4GDML: Reading solids...
G4GDML: Reading structure...
Checking overlaps for volume box_PV:0 (G4Box) ... OK! 
Checking overlaps for volume cons_PV:0 (G4Cons) ... OK! 
Checking overlaps for volume eltu_PV:0 (G4EllipticalTube) ... OK! 
Checking overlaps for volume para_PV:0 (G4Para) ... OK! 
Checking overlaps for volume pcone_PV:0 (G4Polycone) ... OK! 
Checking overlaps for volume phedra_PV:0 (G4Polyhedra) ... OK! 
Checking overlaps for volume sphere_PV:0 (G4Sphere) ... OK! 
Checking overlaps for volume torus_PV:0 (G4Torus) ... OK! 
Checking overlaps for volume trap_PV:0 (G4Trap) ... OK! 
Checking overlaps for volume trd_PV:0 (G4Trd) ... OK! 
Checking overlaps for volume tubs_PV:0 (G4Tubs) ... OK! 
Checking overlaps for volume ctubs_PV:0 (G4CutTubs) ... OK! 
Checking overlaps for volume hype_PV:0 (G4Hype) ... OK! 
Checking overlaps for volume paraboloid_PV:0 (G4Paraboloid) ... OK! 
Checking overlaps for volume tessellated_PV:0 (G4TessellatedSolid) ... OK! 
G4GDML: Reading setup...
G4GDML: Reading 'solids.gdml' done!
Stripping off GDML names of materials, solids and volumes ...

Hi, thanks for your response.

Unfortunately I am trying to import a gdml into ROOT, not export from ROOT into Geant4.

I have a .stp file that I converted to a GDML with some online tool.

I am able to import it into Geant4 with a material, and I import it into ROOT as the whole world. But I can’t seem to import it into a pre-existing world as just a single piece where I would like to include some BOX and TUBEs around it.

Thank you for looking though.

Hi,

From your example above, where you call G4GDMLParser::read, I misunderstood that you are interested in import into Geant4. Anyway, the opposite way should work as well.

So your problem is rather how to combine the existing ROOT geometry with a partial geometry defined in a file. Maybe @agheata would have a tip how to do this.

Best regards,

Yes exactly this seems to be the issue, having both at once and not overwritting my “world” volume.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.