Open xanfus opened 1 week ago
_Detectorvlv defines it's z axis direction opposite to world's. Why so?
Rotations are then also inverted.
Thanks for raising an issue. Please can you reformulate the issue with a complete code fragment and the behaviour you expect.
import pyg4ometry
import math
import pyg4ometry.geant4 as _g4
reg = pyg4ometry.geant4.Registry()
ws = pyg4ometry.geant4.solid.Box("ws",1000,1000,1000,reg)
wl = pyg4ometry.geant4.LogicalVolume(ws,"G4_Galactic","wl",reg)
reg.setWorld(wl)
nc = 24
support_h = 49.8
support_s = pyg4ometry.geant4.solid.Tubs("support",169/2,352/2,support_h,0,2*math.pi,reg,"mm","rad",nc)
support_l = pyg4ometry.geant4.LogicalVolume(support_s,"G4_Al","support_l",reg)
support_p = pyg4ometry.geant4.PhysicalVolume([0,0,0],[0,0,support_h/2],support_l,"support_p",wl,reg)
m_K2SO4 = 501.3#grams
r_bottom = 105.3/2
r_mid = 345.2/math.pi/2
r_top = 370.0/math.pi/2
h_top = 9.1
h_bot = 31.1
V_K2SO4 = (0.5*h_bot*math.pi*(r_bottom**2 + r_mid**2) + r_top**2*math.pi*h_top)/1000#cm3
rho_K2SO4 = m_K2SO4/V_K2SO4
sm = _g4.MaterialCompound("Potassium_Sulfate",rho_K2SO4, 3,reg)
ke = _g4.ElementSimple("potassium","K", 19, 39.0983)
se = _g4.ElementSimple("sulfur","S", 16, 32.065)
oe = _g4.ElementSimple("oxygen","O", 8,16.0)
sm.add_element_natoms(ke,2)
sm.add_element_natoms(se,1)
sm.add_element_natoms(oe,4)
SourceBodyCone_s = pyg4ometry.geant4.solid.Polycone("SourceBodyCone", 0.0, 2*math.pi, [0.0, h_bot, h_bot, h_bot+h_top], [0.0, 0.0, 0.0, 0.0], [r_bottom, r_mid, r_top, r_top], reg, "mm", "rad", nc)
SourceBodyCone_l = pyg4ometry.geant4.LogicalVolume(SourceBodyCone_s, sm, "SourceBodyCone_l",reg)
SourceBodyCone_p = pyg4ometry.geant4.PhysicalVolume([0,0,0],[0,0,4.2],SourceBodyCone_l,"SourceBodyCone_p",wl,reg)
rCrystal = pyg4ometry.gdml.Constant("rCrystal",75, reg)
hCrystal = pyg4ometry.gdml.Constant("hCrystal",99.5,reg)
rGlass = pyg4ometry.gdml.Constant("rGlass" ,79.9,reg)
dGlass = pyg4ometry.gdml.Constant("dGlass" ,5, reg)
dCas1 = pyg4ometry.gdml.Constant("dCas1",1.4,reg)
hCas1 = pyg4ometry.gdml.Constant("hCas1",4.2,reg)
rCas1max = pyg4ometry.gdml.Constant("rCas1max",154.75/2,reg)
rCasTop = pyg4ometry.gdml.Constant("rCasTop",159.8/2,reg)
rCas1min = rCas1max - dCas1
rCas1min.eval()
dRefTopFace = pyg4ometry.gdml.Constant("dRefTopFace",4.5,reg)
dRefSide = pyg4ometry.gdml.Constant("dRefSide",3.5,reg)
DTFL = dGlass + hCrystal + dRefTopFace + dCas1
DTFL.eval()
ConnectorsHeight = pyg4ometry.gdml.Constant("ConnectorsHeight",50.0,reg)
CrystalCenter = pyg4ometry.gdml.Position("CrystalCenter",0,0, -DTFL + dGlass + hCrystal/2,"mm",reg)
GlassCenter = pyg4ometry.gdml.Position("GlassCenter", 0,0, -DTFL + dGlass/2,"mm",reg)
print(-DTFL.eval()+dGlass.eval()/2)
ReflectorSideCenter = pyg4ometry.gdml.Position("ReflectorSideCenter", 0, 0, -DTFL + dGlass + hCas1 + dCas1 + (hCrystal - hCas1 - dCas1)/2,"mm",reg)
ReflectorTopFaceCenter = pyg4ometry.gdml.Position("ReflectorTopFaceCenter", 0, 0, -dCas1 - dRefTopFace/2,"mm",reg)
Casing1Center = pyg4ometry.gdml.Position("Casing1Center", 0,0,-DTFL + dGlass + hCas1/2,"mm",reg)
CasingSideCenter = pyg4ometry.gdml.Position("CasingSideCenter", 0,0,-dCas1 - (hCrystal + dRefTopFace - hCas1)/2,"mm",reg)
CasingTopFaceCenter = pyg4ometry.gdml.Position("CasingTopFaceCenter",0,0,-dCas1/2,"mm",reg)
Crystal_s = _g4.solid.Tubs("Crystal",0,rCrystal,hCrystal,0,2*math.pi,reg,"mm","rad",nc)
Glass_s = _g4.solid.Tubs("Glass", 0,rGlass, dGlass, 0,2*math.pi,reg,"mm","rad",nc)
ReflectorSide = _g4.solid.Tubs("ReflectorSide",rCrystal,rCrystal+dRefSide, hCrystal - hCas1 - dCas1,0,2*math.pi,reg,"mm","rad",nc)
ReflectorTopFace = _g4.solid.Tubs("ReflectorTopFace",0,rCrystal+dRefSide, dRefTopFace, 0,2*math.pi,reg,"mm","rad",nc)
Casing1 = _g4.solid.Tubs("Casing1", rCas1min, rCas1max, hCas1, 0,2*math.pi,reg,"mm","rad",nc)
CasingSide = _g4.solid.Tubs("CasingSide", rCrystal+dRefSide, rCrystal+dRefSide+dCas1, hCrystal + dRefTopFace - hCas1, 0, 2*math.pi, reg,"mm","rad",nc)
CasingTopFace = _g4.solid.Tubs("CasingTopFace", 0, rCasTop, dCas1, 0, 2*math.pi, reg,"mm","rad",nc)
Crystal_l = _g4.LogicalVolume(Crystal_s,"G4_CESIUM_IODIDE","Crystal_l",reg)
Glass_l = _g4.LogicalVolume(Glass_s, "G4_SILICON_DIOXIDE","Glass_l",reg)
ReflectorSide_l = _g4.LogicalVolume(ReflectorSide,"G4_MAGNESIUM_OXIDE","ReflectorSide_l",reg)
ReflectorTopFace_l = _g4.LogicalVolume(ReflectorTopFace,"G4_MAGNESIUM_OXIDE","ReflectorTopFace_l",reg)
Casing1_l = _g4.LogicalVolume(Casing1,"G4_Al","Casing1_l",reg)
CasingSide_l = _g4.LogicalVolume(CasingSide,"G4_Al","CasingSide_l",reg)
CasingTopFace_l = _g4.LogicalVolume(CasingTopFace,"G4_Al","CasingTopFace_l",reg)
Crystal_p = _g4.PhysicalVolume([0,0,0],CrystalCenter,Crystal_l,"Crystal_p",wl,reg)
Glass_p = _g4.PhysicalVolume([0,0,0],GlassCenter,Glass_l,"Glass_p",wl,reg)
ReflectorSide_p = _g4.PhysicalVolume([0,0,0],ReflectorSideCenter,ReflectorSide_l,"ReflectorSide_p",wl,reg)
ReflectorTopFace_p = _g4.PhysicalVolume([0,0,0],ReflectorTopFaceCenter,ReflectorTopFace_l,"ReflectorTopFaceCenter_p",wl,reg)
Casing1_p = _g4.PhysicalVolume([0,0,0],Casing1Center,Casing1_l,"Casing1_p",wl,reg)
CasingSide_p = _g4.PhysicalVolume([0,0,0],CasingSideCenter,CasingSide_l,"CasingSide_p",wl,reg)
CasingTopFace_p = _g4.PhysicalVolume([0,0,0],CasingTopFaceCenter,CasingTopFace_l,"CasingTopFace_p",wl,reg)
Detector54 = _g4.AssemblyVolume("Detector54",reg)
Detector54.add(Crystal_p)
Detector54.add(Glass_p)
Detector54.add(ReflectorSide_p)
Detector54.add(ReflectorTopFace_p)
Detector54.add(Casing1_p)
Detector54.add(CasingSide_p)
Detector54.add(CasingTopFace_p)
Detector54_vlv = Detector54.logicalVolume("G4_Galactic","Detector54_vs")
Detector54_vlv.transformDaughters([math.pi,0,0],[0,0,51])
v = pyg4ometry.visualisation.VtkViewer()
v = pyg4ometry.visualisation.VtkViewerColouredMaterial()
v.addLogicalVolume(wl)
v.view()
When i increase z in Detector54_vlv.transformDaughters([math.pi,0,0],[0,0,z])
, i expect Detector54 AssemblyVolume to move along positive direction of world's z axis. What i see instead, detector moves along negative direction of world's z axis.
This might be an old piece of code used for replacement of the outer solid. In Geant4 there isn't a post-facto reorientation of daughter volumes. The convention the transform has also does not any convention within Geant4. I'll take a longer look as to why this code has this weird convention.
If you would like to transform the daughter volumes, it should be like the following
Crystal_p = _g4.PhysicalVolume([math.pi,0,0],CrystalCenter,Crystal_l,"Crystal_p",wl,reg)
If you would like to rotate all the daughters within the world. I would also consider making Detector54
a LogicalVolume
in a larger world and then rotate it appropriately.
I'll leave this issue open until I resolve the weird behaviour in transformDaughters
@xanfus any update on this or can I close the issue?
No updates coming soon, unfortunately. Close the issue.
Would this do the job? Visualisation seems to show it does.