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…