# Conversion from Geant4 to TGeo classes with VGM

Dear rooters,

I converted a Geant4 geometry in TGeo classes using VGM and I am trying to compare the position of the single nodes/volumes to understand if anything got wrong in the conversion.

Sadly, most of the volumes have different positions, even if the rotation matrix and the translation are the same.

This is how I get the position for Geant4 volumes:

``````void print_volume(G4VPhysicalVolume *vol, G4RotationMatrix &motrot, G4ThreeVector &mottrans)
{
G4RotationMatrix rot   = *(vol->GetObjectRotation());
G4ThreeVector    trans = vol->GetObjectTranslation()/cm;
G4ThreeVector pos = mottrans + motrot.inverse()*trans;
cout << Form(" {%.3f, %.3f, %.3f};", pos[0], pos[1], pos[2]);
rot   *= motrot;
trans += mottrans;

G4LogicalVolume *log_vol = vol->GetLogicalVolume();

for (int ivol = 0; ivol < log_vol->GetNoDaughters(); ++ivol)
{
print_volume(log_vol->GetDaughter(ivol), rot, trans);
}
}

/* after the construction of the detector geometry in Geant4 */
G4RotationMatrix motrot;
G4ThreeVector    mottrans;
// top is the top volume in Geant4 geometry; G4VPhysicalVolume *top
print_volume(top, motrot, mottrans);``````

This is how I get the position for TGeo volumes:

``````void print_node(TGeoNode *node, string path)
{
string str = "";

if (node != NULL)
{
const Char_t *node_name = node->GetName();
path += Form("/%s", node_name);

TGeoVolume *volume = node->GetVolume();
if (volume != NULL)
{
TGeoBBox *shape = (TGeoBBox *)volume->GetShape();
if (shape != NULL)
{
// shape properties
Double_t master[3];
const Double_t *local    = shape->GetOrigin();
gGeoManager->cd(path.c_str());
gGeoManager->LocalToMaster(local, master);

str += Form("{%.3f, %.3f, %.3f}", master[0], master[1], master[2]);
}
}

cout << str << endl;

TIter next(node->GetNodes());

while (TGeoNode *n = (TGeoNode *)next())
{
print_node_tree(n, path);
}
}
}

int main()
{
TFile *geo_file = new TFile("geom.root");
TGeoManager *geom =(TGeoManager *)geo_file->Get("VGM Root geometry");

print_node(geom->GetTopNode(), "");
}``````

Am I computing the positions in a wrong way?

PS: I am posting here and not on geant4 forum, because I still need to receive the login authorizationâ€¦

Hi,

I am not sure about the correctess of how you compute the global object position in GEANT4, but this certainly does not match with how you extract the information in ROOT. You convert to the master frame the center of the bounding box of the volume, while in G4 you convert the origin of the local reference frame for the volume. These are not the same. In TGeo, you should rather apply LocalToMaster to the (0,0,0) point to get something similar with G4.

Regards,

I thought this could be the problem, but the difference does not depend on the shape: even some TGeoBBox have different coordinates, while I thought that in case of G4Box the center of the shape and the center of the bounding box had to be the same.

Like this?

``````const Double_t local[3] = { 0., 0., 0. };
gGeoManager->cd(path.c_str());
gGeoManager->LocalToMaster(local, master);``````

Actually, this way I have less volumes with different coordinates (~200), but the majority (~118000) is still different.
Also, some volumes with previous code had only 1 coordinate different, while now they have 3, and viceversa.

It looks to me that there is not a clear and compatible definition of position of a volume between Geant4 and TGeo or, probably, I misunderstood something.

Hi,

Well, it could be that the way you do the conversion in G4 is not correct - you could try with a geometry with a single placement in the world volume to check it out. I suggest to write also directly to the author of VGM (ivana.hrivnacova@cern.ch) and ask, but I doubt that there is a problem with the conversion. You could also export directly the geometry in gdml and import directly in TGeo then compare with the geometry produced with VGM.

Regards,
Andrei