diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index beacc10776579d3aa6c334ce9b3b6cfba1e5207e..d3ca3f7787c1c6ef9d4f2a723e3c7df296c63784 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -103,11 +103,7 @@ install(DIRECTORY examples DESTINATION examples/DDG4 PATTERN ".svn" EXCLUDE ) -install(DIRECTORY python - DESTINATION python/DDG4 - PATTERN ".d" EXCLUDE - PATTERN ".so" EXCLUDE - PATTERN ".svn" EXCLUDE ) +install(FILES python/DD4hep.py python/DDG4.py python/DDG4Dict.C DESTINATION python) install(TARGETS DD4hepG4 DD4hepG4Plugins DD4hepG4Legacy g4gdmlDisplay RUNTIME DESTINATION bin diff --git a/DDG4/python/DD4hep.py b/DDG4/python/DD4hep.py new file mode 100644 index 0000000000000000000000000000000000000000..b270acacb51c56bb7f1dc921a33278ed335d8351 --- /dev/null +++ b/DDG4/python/DD4hep.py @@ -0,0 +1,177 @@ +#--------------------------------------------------------------------------- +# We compile the DDG4 plugin on the fly if it does not exist using the AClick mechanism: +def compileAClick(dictionary,g4=True): + from ROOT import gInterpreter, gSystem + import sys, imp, exceptions + import os.path + dd4hep = os.environ['DD4hepINSTALL'] + inc = ' -I'+os.environ['ROOTSYS']+'/include -I'+dd4hep+'/include ' + lib = ' -L'+dd4hep+'/lib -lDD4hepCore -lDD4hepG4 -lDDSegmentation ' + if g4: + geant4 = os.environ['G4INSTALL'] + inc = inc + ' -I'+geant4+'/include/Geant4 -Wno-shadow -g -O0 ' + lib = lib + ' -L'+geant4+'/lib -L'+geant4+'/lib64 -lG4event -lG4tracking -lG4particles ' + + gSystem.AddIncludePath(inc) + gSystem.AddLinkedLibs(lib) + #####print "Includes: ",gSystem.GetIncludePath(),"\n","Linked libs:",gSystem.GetLinkedLibs() + package = imp.find_module('DDG4') + dic = os.path.dirname(package[1])+os.sep+dictionary + ###print dic + gInterpreter.ProcessLine('.L '+dic+'+') + #####gInterpreter.Load('DDG4Dict_C.so') + from ROOT import DD4hep as module + return module + +def loadDD4hep(): + import os, sys + # Add ROOT to the python path in case it is not yet there.... + sys.path.append(os.environ['ROOTSYS']+os.sep+'lib') + import ROOT + from ROOT import gSystem + result = gSystem.Load("libDD4hepCore") + if 0 != result: + raise Exception('DDG4.py: Failed to load the Geant4 library libDD4hepCore: '+gSystem.GetErrorStr()) + from ROOT import DD4hep as module + return module + +# We are nearly there .... +name_space = __import__(__name__) +def import_class(ns,nam): + scope = getattr(name_space,ns) + setattr(name_space,nam,getattr(scope,nam)) + +def import_root(nam): + #print 'import ROOT class ',nam,str(name_space) + setattr(name_space,nam,getattr(ROOT,nam)) + +#--------------------------------------------------------------------------- +# +try: + DD4hep = loadDD4hep() + import ROOT +except Exception,X: + import sys + print '+--%-100s--+'%(100*'-',) + print '| %-100s |'%('Failed to load DDG4 library:',) + print '| %-100s |'%(str(X),) + print '+--%-100s--+'%(100*'-',) + sys.exit(1) + +class _Levels: + def __init__(self): + self.VERBOSE=1 + self.DEBUG=2 + self.INFO=3 + self.WARNING=4 + self.ERROR=5 + self.FATAL=6 + self.ALWAYS=7 + +OutputLevel = _Levels() +#--------------------------------------------------------------------------- +Core = DD4hep +Geo = DD4hep.Geometry +Geometry = DD4hep.Geometry +#--------------------------------------------------------------------------- +import_class('Core','NamedObject') +import_class('Core','run_interpreter') + +def import_geometry(): + import_class('Geo','LCDD') + import_class('Geo','VolumeManager') + import_class('Geo','OverlayedField') + + #// Objects.h + import_class('Geo','Author') + import_class('Geo','Header') + import_class('Geo','Constant') + import_class('Geo','Atom') + import_class('Geo','Material') + import_class('Geo','VisAttr') + import_class('Geo','AlignmentEntry') + import_class('Geo','Limit') + import_class('Geo','LimitSet') + import_class('Geo','Region') + + #// Readout.h + import_class('Geo','Readout') + import_class('Geo','Alignment') + import_class('Geo','Conditions') + + #// DetElement.h + import_class('Geo','DetElement') + import_class('Geo','SensitiveDetector') + + #// Volume.h + import_class('Geo','Volume') + import_class('Geo','PlacedVolume') + + #// Shapes.h + import_class('Geo','Polycone') + import_class('Geo','ConeSegment') + import_class('Geo','Box') + import_class('Geo','Torus') + import_class('Geo','Cone') + import_class('Geo','Tube') + import_class('Geo','Trap') + import_class('Geo','Trapezoid') + import_class('Geo','Sphere') + import_class('Geo','Paraboloid') + import_class('Geo','PolyhedraRegular') + import_class('Geo','BooleanSolid') + import_class('Geo','SubtractionSolid') + import_class('Geo','UnionSolid') + import_class('Geo','IntersectionSolid') + + +def import_tgeo(): + import_root('TGeoManager') + import_root('TGeoNode') + import_root('TGeoNodeMatrix') + + import_root('TGeoVolume') + import_root('TGeoVolumeMulti') + import_root('TGeoVolumeAssembly') + + import_root('TGeoMaterial') + import_root('TGeoMedium') + import_root('TGeoIsotope') + import_root('TGeoElement') + + import_root('TGeoMatrix') + import_root('TGeoHMatrix') + import_root('TGeoIdentity') + import_root('TGeoTranslation') + import_root('TGeoRotation') + import_root('TGeoScale') + import_root('TGeoCombiTrans') + + import_root('TGeoShape') + import_root('TGeoBBox') + import_root('TGeoArb8') + import_root('TGeoTrap') + import_root('TGeoGtra') + import_root('TGeoCompositeShape') + import_root('TGeoCone') + import_root('TGeoConeSeg') + import_root('TGeoTube') + import_root('TGeoTubeSeg') + import_root('TGeoCtub') + import_root('TGeoEltu') + import_root('TGeoHype') + import_root('TGeoHalfSpace') + import_root('TGeoPara') + import_root('TGeoParaboloid') + import_root('TGeoPcon') + import_root('TGeoPgon') + import_root('TGeoScaledShape') + import_root('TGeoShapeAssembly') + import_root('TGeoSphere') + import_root('TGeoTorus') + import_root('TGeoTrd1') + import_root('TGeoTrd2') + import_root('TGeoXtru') + +import_tgeo() +import_geometry() diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index 6d33d1e878588a4dd8edd723f012dd50cf7961cc..62c3b78031aa634046266769eb8ef6efacee49df 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -1,37 +1,7 @@ -import os, sys, imp, exceptions -# Add ROOT to the python path in case it is not yet there.... -sys.path.append(os.environ['ROOTSYS']+os.sep+'lib') -import ROOT -#--------------------------------------------------------------------------- -# We compile the DDG4 plugin on the fly if it does not exist using the AClick mechanism: -def compileAClick(dictionary,g4=True): - from ROOT import gInterpreter, gSystem - import os.path - dd4hep = os.environ['DD4hepINSTALL'] - inc = ' -I'+os.environ['ROOTSYS']+'/include -I'+dd4hep+'/include ' - lib = ' -L'+dd4hep+'/lib -lDD4hepCore -lDD4hepG4 -lDDSegmentation ' - if g4: - geant4 = os.environ['G4INSTALL'] - inc = inc + ' -I'+geant4+'/include/Geant4 -Wno-shadow -g -O0 ' - lib = lib + ' -L'+geant4+'/lib -L'+geant4+'/lib64 -lG4event -lG4tracking -lG4particles ' - - gSystem.AddIncludePath(inc) - gSystem.AddLinkedLibs(lib) - #####print "Includes: ",gSystem.GetIncludePath(),"\n","Linked libs:",gSystem.GetLinkedLibs() - package = imp.find_module('DDG4') - dic = os.path.dirname(package[1])+os.sep+dictionary - ###print dic - gInterpreter.ProcessLine('.L '+dic+'+') - #####gInterpreter.Load('DDG4Dict_C.so') - from ROOT import DD4hep as module - return module +from DD4hep import * def loadDDG4(): from ROOT import gSystem - import os.path - result = gSystem.Load("libDD4hepCore") - if 0 != result: - raise Exception('DDG4.py: Failed to load the Geant4 library libDD4hepCore: '+gSystem.GetErrorStr()) result = gSystem.Load("libDD4hepG4") if 0 != result: raise Exception('DDG4.py: Failed to load the Geant4 library libDD4hepG4: '+gSystem.GetErrorStr()) @@ -54,7 +24,7 @@ except Exception,X: print '| %-100s |'%(str(X),) print '| %-100s |'%('Try to compile AClick on the fly.',) print '+--%-100s--+'%(100*'-',) - DD4hep = compileAClick(dictionary='DDG4Dict.C',g4=True) + DD4hep = compileAClick(dictionary='DDG4Dict.C',g4=True) Core = DD4hep Sim = DD4hep.Simulation Simulation = DD4hep.Simulation @@ -62,24 +32,13 @@ Simulation = DD4hep.Simulation Kernel = Sim.KernelHandle Interface = Sim.Geant4ActionCreation -class _Levels: - def __init__(self): - self.VERBOSE=1 - self.DEBUG=2 - self.INFO=3 - self.WARNING=4 - self.ERROR=5 - self.FATAL=6 - self.ALWAYS=7 - -OutputLevel = _Levels() - def _registerGlobalAction(self,action): self.get().registerGlobalAction(Interface.toAction(action)) def _registerGlobalFilter(self,filter): self.get().registerGlobalFilter(Interface.toAction(filter)) #--------------------------------------------------------------------------- def _getKernelProperty(self, name): + import exceptions #print '_getKernelProperty:',str(type(self)),name ret = Interface.getPropertyKernel(self.get(),name) if ret.status > 0: @@ -104,7 +63,6 @@ Kernel.registerGlobalFilter = _registerGlobalFilter Kernel.__getattr__ = _getKernelProperty Kernel.__setattr__ = _setKernelProperty - ActionHandle = Sim.ActionHandle #--------------------------------------------------------------------------- def SensitiveAction(kernel,nam,det): return Interface.createSensitive(kernel,nam,det) @@ -195,57 +153,3 @@ _props('PhysicsListActionSequenceHandle') _props('SensDetActionSequenceHandle') _props('Geant4PhysicsListActionSequence') - -#--------------------------------------------------------------------------- -_import_class('Core','NamedObject') - -#--------------------------------------------------------------------------- -Geo = DD4hep.Geometry -Geometry = DD4hep.Geometry - -_import_class('Geo','LCDD') -_import_class('Geo','VolumeManager') -_import_class('Geo','OverlayedField') - -#// Objects.h -_import_class('Geo','Author') -_import_class('Geo','Header') -_import_class('Geo','Constant') -_import_class('Geo','Atom') -_import_class('Geo','Material') -_import_class('Geo','VisAttr') -_import_class('Geo','AlignmentEntry') -_import_class('Geo','Limit') -_import_class('Geo','LimitSet') -_import_class('Geo','Region') - -#// Readout.h -_import_class('Geo','Readout') -_import_class('Geo','Alignment') -_import_class('Geo','Conditions') - -#// DetElement.h -_import_class('Geo','DetElement') -_import_class('Geo','SensitiveDetector') - -#// Volume.h -_import_class('Geo','Volume') -_import_class('Geo','PlacedVolume') - -#// Shapes.h -_import_class('Geo','Polycone') -_import_class('Geo','ConeSegment') -_import_class('Geo','Box') -_import_class('Geo','Torus') -_import_class('Geo','Cone') -_import_class('Geo','Tube') -_import_class('Geo','Trap') -_import_class('Geo','Trapezoid') -_import_class('Geo','Sphere') -_import_class('Geo','Paraboloid') -_import_class('Geo','PolyhedraRegular') -_import_class('Geo','BooleanSolid') -_import_class('Geo','SubtractionSolid') -_import_class('Geo','UnionSolid') -_import_class('Geo','IntersectionSolid') - diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 500d2a110b7e4c46a39a24b88c065ad28b42569d..6d67a3b518e66988eac0acd7aad1438df1d76414 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -25,13 +25,14 @@ #include "TGeoNode.h" #include "TGeoShape.h" #include "TGeoCone.h" +#include "TGeoHype.h" #include "TGeoPcon.h" #include "TGeoPgon.h" #include "TGeoSphere.h" #include "TGeoTorus.h" -#include "TGeoTube.h" #include "TGeoTrd1.h" #include "TGeoTrd2.h" +#include "TGeoTube.h" #include "TGeoArb8.h" #include "TGeoMatrix.h" #include "TGeoBoolNode.h" @@ -53,7 +54,9 @@ #include "G4Box.hh" #include "G4Trd.hh" #include "G4Tubs.hh" +#include "G4Trap.hh" #include "G4Cons.hh" +#include "G4Hype.hh" #include "G4Torus.hh" #include "G4Sphere.hh" #include "G4Polycone.hh" @@ -383,6 +386,12 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c solid = new G4Trd(name, s->GetDx1() * CM_2_MM, s->GetDx2() * CM_2_MM, s->GetDy1() * CM_2_MM, s->GetDy2() * CM_2_MM, s->GetDz() * CM_2_MM); } + else if (shape->IsA() == TGeoHype::Class()) { + const TGeoHype* s = (const TGeoHype*) shape; + solid = new G4Hype(name, s->GetRmin() * CM_2_MM, s->GetRmax() * CM_2_MM, + s->GetStIn() * DEGREE_2_RAD, s->GetStOut() * DEGREE_2_RAD, + s->GetDz() * CM_2_MM); + } else if (shape->IsA() == TGeoPgon::Class()) { const TGeoPgon* s = (const TGeoPgon*) shape; double phi_start = s->GetPhi1() * DEGREE_2_RAD; @@ -426,6 +435,12 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c solid = new G4Torus(name, s->GetRmin() * CM_2_MM, s->GetRmax() * CM_2_MM, s->GetR() * CM_2_MM, s->GetPhi1() * DEGREE_2_RAD, s->GetDphi() * DEGREE_2_RAD); } + else if (shape->IsA() == TGeoTrap::Class()) { + const TGeoTrap* s = (const TGeoTrap*) shape; + solid = new G4Trap(name, s->GetDz() * CM_2_MM, s->GetTheta(), s->GetPhi(), + s->GetH1() * CM_2_MM, s->GetBl1() * CM_2_MM, s->GetTl1() * CM_2_MM, s->GetAlpha1() * DEGREE_2_RAD, + s->GetH2() * CM_2_MM, s->GetBl2() * CM_2_MM, s->GetTl2() * CM_2_MM, s->GetAlpha2() * DEGREE_2_RAD); + } else if (shape->IsA() == TGeoCompositeShape::Class()) { const TGeoCompositeShape* s = (const TGeoCompositeShape*) shape; const TGeoBoolNode* boolean = s->GetBoolNode();