Dear GDML-Team, I want to simulate particle scattering in a beamline and therefore I need Quadrupoles/Sextupoles. Unfortunately G4QuadrupoleMagField uses the origin of the world volume to calculate the magnetic field (see Bugzilla/Geant4 – Problem 1085, John Apostolakis). I also want to implement ionoptics to calculate the trajectory. For this purpose I need ionoptical coordinates that are related to the reference trajectory in the middle of the volume. To solve this problem I need information about the position of the volume with magnetic field: G4VPhysicalVolume->GetObjectTranslation(), G4VPhysicalVolume->GetFrameTranslation(), G4VPhysicalVolume->GetTranslation(); Using GDML Modules it seems not to be possible to retrieve the needed position information with these methods. Thanks for your help and best regards, Björn Riese. --------------------------------------------------- The quadrupole is defined as modul in the main file esr.gdml ... <physvol> <file name="E01QS0D.gdml"/> <positionref ref="E01QS0D_pos"/> <rotationref ref="E01QS0D_rot"/> </physvol> ... and represents the whole quadrupole with its magnetic field ... <structure> <volume name="E01QS0D_Mag_vol"> <materialref ref="Vacuum"/> <solidref ref="E01QS0D_Mag_sol"/> <auxiliary auxtype="Quadrupole" auxvalue="GRADIENT"/> </volume> .... and placed as ... <physvol name="E01QS0D_Mag_phys"> <volumeref ref="E01QS0D_Mag_vol"/> </physvol> in the volume "E01QS0D". --------------------------------------------------- Here the output of my application: d01_tube_vol world d01_tube (0,0,2335.35) (-0,-0,-2335.35) (0,0,2335.35) ----- OK d02_tube_vol world d02_tube (0,0,4773.2) (-0,-0,-4773.2) (0,0,4773.2) ----- OK d03_tube_vol world d03_tube (0,0,4923.2) (-0,-0,-4923.2) (0,0,4923.2) ----- OK d04_tube_vol // (*lvciter)->GetName(); E01QS0D // (*pvciter)->GetMotherLogical()->GetName(); E01QS0D_Mag // (*pvciter)->GetName(); (0,0,0) // (*pvciter)->GetObjectTranslation() (-0,-0,-0) // (*pvciter)->GetFrameTranslation() (0,0,0) // (*pvciter)->GetTranslation() ----- error: -> d04_tube ist the beamline element after the first quadrupole! G4LogicalVolumeStore and G4PhysicalVolumeStore are not in same order! -> the position is wrong if I use a GDML-Module: <physvol> <file name="E01QS0D.gdml"/> <positionref ref="E01QS0D_pos"/> <rotationref ref="E01QS0D_rot"/> </physvol> ------------------------------------------------- A section of my DetectorConstruction class: G4VPhysicalVolume* fWorldPhysVol; // Reading GDML files, Volume Auxiliary Information // if(fChoice==0) { parser.Read(fReadFile); fWorldPhysVol = parser.GetWorldVolume(); //////////////////////////////////////////////////////// // Begin of Auxiliary Information block // const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); std::vector<G4LogicalVolume*>::const_iterator lvciter; const G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance(); std::vector<G4VPhysicalVolume*>::const_iterator pvciter; for( lvciter = lvs->begin(), pvciter = pvs->begin(); lvciter != lvs->end(); lvciter++, pvciter++ ) { G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter); std::vector<G4GDMLAuxPairType>::const_iterator ipair = auxInfo.begin(); for( ipair = auxInfo.begin(); ipair != auxInfo.end(); ipair++ ) { G4String lv_name=(*lvciter)->GetName(); G4String pv_name=(*pvciter)->GetName(); G4String mv_name=(*pvciter)-> GetMotherLogical()->GetName(); G4String type=ipair->type; G4double value=ipair->value; G4cout << lv_name << G4endl; G4cout << mv_name << G4endl; G4cout << pv_name << G4endl; G4cout << (*pvciter)->GetObjectTranslation() << G4endl; G4cout << (*pvciter)->GetFrameTranslation() << G4endl; G4cout << (*pvciter)->GetTranslation() << G4endl; G4cout << "-----" << G4endl; } }
The transformation printed from a pointer to the physical-volume refers to the coordinates -local- to the mother volume, which in this case for 'd04_tube_vol' seems not to be the 'world', as for the other elements. In order to retrieve the position in -global- coordinates system (i.e. reference system of the world) you need to apply all transformations in opposite order through the hierarchy of volumes (see also section 4.1.8.2 of the Users Guide for Application Developers). This may not be sufficient and not always possible though, in case of multiple copies of the same hierarchy, replicas or parametrised volumes... For your use-case, it is preferable to extract the information a-priori (eventually from the GDML structure implemented) and use it in your application.
An additional problem related to the use of GDML modules appears during the reading of matrices that are defined in the define section. G4double val = parser.GetMatrix("m").Get(1, 1); doesn't work if I define ion optical matrices in GDML modules (= beamline elements). Preliminary I'll define my 6x6 matrices in a seperate xml-file using <!ENTITY matrix SYSTEM "matrix.xml"> command. Thanks for your help, Björn Riese.
If you can provide us a simple toy-example which reproduces the problem claimed, it would be much easy for us to verify. We don't see any of the issues reported here as a problem related to the usage of modules in GDML, sorry!
Created attachment 55 [details] VolAuxInfo.hh In my GDML-Files I use the following Auxiliary Tags ... <auxiliary auxtype="Dipole" auxvalue="RADIUS"/> <auxiliary auxtype="IonOptics" auxvalue="ON"/> <auxiliary auxtype="Quadrupole" auxvalue="GRADIENT"/> <auxiliary auxtype="Color" auxvalue="YELLOW"/> <auxiliary auxtype="SensDet" auxvalue="ON"/> ... and save them (see code 1090) in a linked list consisting of ... struct VolAuxInfoData { G4String MotherLogVol; G4String PhysVol; G4String LogVol; G4String AuxType; G4double AuxValue; G4GDMLMatrix Matrix; G4ThreeVector Translation; VolAuxInfoData* Next; }; ... struct elements and belonging to the class "VolAuxInfo.cc/hh". "DetectorConstruction.cc" calls the following methods: AuxInfo->AddVolAuxInfoData(pv_name, mv_name, lv_name, type, value, Matrix, translation); AuxInfo->PrintVolAuxInfoData(); AuxInfo->SetVolAuxInfoQuadrupole(); AuxInfo->SetVolAuxInfoSextupole(); AuxInfo->SetVolAuxInfoColor(); AuxInfo->SetVolAuxInfoSensDet(); The geometry description consists of one main gdml file with drifts and modules. I use modules for detectors, dipoles, quadrupoles and sextupoles (see "setup.jpg"). I've also attached the classes "DetectorConstruction.cc/hh" and "VolAuxInfo.cc/hh" of the code and a gdml module of the dipole "E01MU1.gdml".
Created attachment 56 [details] VolAuxInfo.cc
Created attachment 57 [details] setup.jpg
Created attachment 58 [details] E01MU1.gdml
Created attachment 59 [details] DetectorConstruction.hh
Created attachment 60 [details] DetectorConstruction.cc