diff --git a/DDCore/include/XML/XMLElements.h b/DDCore/include/XML/XMLElements.h index e5dd0f19ecd8cb8ee324cf85947d2d5de90e2e0c..e90aa38df15d982c67da8c9d2355c93b3623e887 100644 --- a/DDCore/include/XML/XMLElements.h +++ b/DDCore/include/XML/XMLElements.h @@ -569,6 +569,8 @@ namespace DD4hep { /// Access to XmlElement pointer Elt_t ptr() const { return m_element; } + /// Access the tag name of this DOM element + std::string tag() const { return m_element.tag(); } /// Access the tag name of this DOM element const XmlChar* tagName() const { return m_element.rawTag(); } /// Append a new element to the existing tree diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp index 901510d67ca5f81160a917d2ca1e087a59617497..cd0f742d06541706d499935a9fabe10bd7849dcf 100644 --- a/DDCore/src/plugins/LCDDConverter.cpp +++ b/DDCore/src/plugins/LCDDConverter.cpp @@ -474,29 +474,18 @@ xml_h LCDDConverter::handleSolid(const string& name, const TGeoShape* shape) c obj.setAttr(_U(y),tr[1]*CM_2_MM); obj.setAttr(_U(z),tr[2]*CM_2_MM); } - if ( lm->Inverse().IsRotation() ) { - XYZRotation rot = getXYZangles(lm->Inverse().GetRotationMatrix()); + if ( lm->IsRotation() ) { + TGeoMatrix& linv = lm->Inverse(); + XYZRotation rot = getXYZangles(linv.GetRotationMatrix()); if ((rot.X() != 0.0) || (rot.Y() != 0.0) || (rot.Z() != 0.0)) { first.append(obj=xml_elt_t(geo.doc,_U(firstrotation))); - if ( lm->IsA() == TGeoCombiTrans::Class() ) { - TGeoRotation rot; - rot.SetMatrix(lm->Inverse().GetRotationMatrix()); - rot.GetAngles(phi,theta,psi); - obj.setAttr(_U(x),theta*DEGREE_2_RAD); - obj.setAttr(_U(y),psi*DEGREE_2_RAD); - obj.setAttr(_U(z),phi*DEGREE_2_RAD); - obj.setAttr(_U(unit),"rad"); - } - else { - obj.setAttr(_U(name),name); - obj.setAttr(_U(x),rot.X()); - obj.setAttr(_U(y),rot.Y()); - obj.setAttr(_U(z),rot.Z()); - obj.setAttr(_U(unit),"rad"); - } + obj.setAttr(_U(name),name); + obj.setAttr(_U(x),rot.X()); + obj.setAttr(_U(y),rot.Y()); + obj.setAttr(_U(z),rot.Z()); + obj.setAttr(_U(unit),"rad"); } } - TGeoMatrix& rinv = rm->Inverse(); tr = rm->GetTranslation(); solid.append(second=xml_elt_t(geo.doc,_U(second))); second.setAttr(_U(ref),rs->GetName()); @@ -507,7 +496,8 @@ xml_h LCDDConverter::handleSolid(const string& name, const TGeoShape* shape) c xml_ref_t pos = handlePosition(rnam+"pos",rm); solid.setRef(_U(positionref),pos.name()); } - if ( rinv.IsRotation() ) { + if ( rm->IsRotation() ) { + TGeoMatrix& rinv = rm->Inverse(); XYZRotation rot = getXYZangles(rinv.GetRotationMatrix()); if ((rot.X() != 0.0) || (rot.Y() != 0.0) || (rot.Z() != 0.0)) { xml_ref_t rot = handleRotation(rnam+"rot",&rinv); @@ -564,24 +554,11 @@ xml_h LCDDConverter::handleRotation(const std::string& name, const TGeoMatrix* t if ( !(r.X() == 0.0 && r.Y() == 0.0 && r.Z() == 0.0) ) { geo.checkRotation(name,trafo); geo.doc_define.append(rot=xml_elt_t(geo.doc,_U(rotation))); - if ( true && trafo->IsA() == TGeoCombiTrans::Class() ) { - double phi=0., theta=0., psi=0.; - TGeoRotation r; - r.SetMatrix(trafo->GetRotationMatrix()); - r.GetAngles(phi,theta,psi); - rot.setAttr(_U(name),name); - rot.setAttr(_U(x),psi*DEGREE_2_RAD); - rot.setAttr(_U(y),theta*DEGREE_2_RAD); - rot.setAttr(_U(z),phi*DEGREE_2_RAD); - rot.setAttr(_U(unit),"rad"); - } - else { - rot.setAttr(_U(name),name); - rot.setAttr(_U(x),r.X()); - rot.setAttr(_U(y),r.Y()); - rot.setAttr(_U(z),r.Z()); - rot.setAttr(_U(unit),"rad"); - } + rot.setAttr(_U(name),name); + rot.setAttr(_U(x),r.X()); + rot.setAttr(_U(y),r.Y()); + rot.setAttr(_U(z),r.Z()); + rot.setAttr(_U(unit),"rad"); } else if ( geo.identity_rot ) { rot = geo.identity_rot; @@ -751,14 +728,16 @@ xml_h LCDDConverter::handlePlacement(const string& name, const TGeoNode* node) c place.setRef(_U(positionref),pos.name()); place.setRef(_U(rotationref),rot.name()); } - if ( dynamic_cast<const PlacedVolume::Object*>(node) ) { - PlacedVolume p = Ref_t(node); - const PlacedVolume::VolIDs& ids = p.volIDs(); - for(PlacedVolume::VolIDs::const_iterator i=ids.begin(); i!=ids.end(); ++i) { - xml_h pvid = xml_elt_t(geo.doc,_U(physvolid)); - pvid.setAttr(_U(field_name),(*i).first); - pvid.setAttr(_U(value),(*i).second); - place.append(pvid); + if ( geo.doc_root.tag() != "gdml" ) { + if ( dynamic_cast<const PlacedVolume::Object*>(node) ) { + PlacedVolume p = Ref_t(node); + const PlacedVolume::VolIDs& ids = p.volIDs(); + for(PlacedVolume::VolIDs::const_iterator i=ids.begin(); i!=ids.end(); ++i) { + xml_h pvid = xml_elt_t(geo.doc,_U(physvolid)); + pvid.setAttr(_U(field_name),(*i).first); + pvid.setAttr(_U(value),(*i).second); + place.append(pvid); + } } } geo.xmlPlacements[node] = place; diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index d8f198ef2b07929755fb6992cf9c1a9ce7d95e40..e8a71875046d38637b315ec47289799235abc70a 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -31,13 +31,16 @@ SET_TARGET_PROPERTIES( DD4hepG4 PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION $ dd4hep_generate_rootmap(DD4hepG4) -#--- install target------------------------------------- +#----------------------------------------------------------------------------------- +add_executable(g4gdmlDisplay g4gdmlDisplay.cpp) +target_link_libraries(g4gdmlDisplay DD4hepG4 DD4hepCore) +#--- install target------------------------------------- install(DIRECTORY include/DDG4 DESTINATION include PATTERN ".svn" EXCLUDE ) -install(TARGETS DD4hepG4 +install(TARGETS DD4hepG4 g4gdmlDisplay RUNTIME DESTINATION bin LIBRARY DESTINATION lib ) diff --git a/DDG4/g4gdmlDisplay.cpp b/DDG4/g4gdmlDisplay.cpp new file mode 100644 index 0000000000000000000000000000000000000000..130940f6e7adcc79c1a79d1250d0853113d89bbf --- /dev/null +++ b/DDG4/g4gdmlDisplay.cpp @@ -0,0 +1,89 @@ +//#define G4UI_USE +//#define G4VIS_USE +//#define G4INTY_USE_XT +#define G4VIS_USE_OPENGL +//#define G4UI_USE_TCSH + +#include "G4PVPlacement.hh" +#include "G4RunManager.hh" +#include "G4UImanager.hh" +#include "G4UIsession.hh" +#include "Randomize.hh" + +#ifdef G4VIS_USE_OPENGLX +#include "G4OpenGLImmediateX.hh" +#include "G4OpenGLStoredX.hh" +#endif + +#include "G4VisManager.hh" +#include "G4VisExecutive.hh" +#include "G4UIExecutive.hh" +#include "G4VUserPhysicsList.hh" +#include "G4ParticleTypes.hh" +#include "globals.hh" + +#include "DDG4/Geant4GDMLDetector.h" +#include <cerrno> +#include <stdexcept> + +using namespace std; +using namespace DD4hep::Simulation; + +namespace { + class EmptyPhysicsList: public G4VUserPhysicsList { + public: + EmptyPhysicsList() { } + ~EmptyPhysicsList() { } + // Construct particle and physics process + void ConstructParticle() { G4Geantino::GeantinoDefinition(); } + void ConstructProcess() { AddTransportation(); } + void SetCuts() { SetCutsWithDefault(); } + }; +} + +static const char* get_arg(int argc, char** argv,int which) { + if ( which>0 && which < argc ) return argv[which]; + throw runtime_error("Invalid argument sequence"); +} + +int main(int argc, char** argv) { + string gdml = argv[1]; + string setup = argv[2]; + const char* args[] = {"cmd"}; + for(int i=1; i<argc;++i) { + string nam = get_arg(argc,argv,i); + if ( argv[i][0]=='-' ) { + string nam = argv[i]+1; + if ( strncmp(nam.c_str(),"gdml",4) == 0 ) + gdml = get_arg(argc,argv,++i); + else if ( strncmp(nam.c_str(),"guisetup",3) == 0 ) + setup = get_arg(argc,argv,++i); + } + } + if ( gdml.empty() || setup.empty() ) { + cout << " usage: g4gdmlDisplay -gdml <file-name> -guisetup <g4 macro>" << endl; + return EINVAL; + } + + G4RunManager * run = new G4RunManager; + run->SetUserInitialization(new Geant4GDMLDetector(gdml)); + run->SetUserInitialization(new EmptyPhysicsList()); + // + // Initialize G4 kernel + run->Initialize(); + // + // Initialize visualization + G4VisManager* vis = new G4VisExecutive; + vis->Initialize(); + // + // Get the pointer to the User Interface manager + G4UImanager* uiman = G4UImanager::GetUIpointer(); + G4UIExecutive* ui = new G4UIExecutive(1,(char**)args); + uiman->ApplyCommand("/control/execute "+setup); + ui->SessionStart(); + // end ... + delete ui; + delete vis; + delete run; + return 0; +} diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 27a4762fdf36b6847b997c24f9e2b67d4bf6fff0..a770979faab5ea4bec3d4aac73b6bb92c5eff4fb 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -482,7 +482,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) node,node->GetName(),node->IsA()->GetName(),vol->IsA()->GetName(),vol); } else if ( is_rot ) { - const Double_t* rot = trafo->GetRotationMatrix(); + const Double_t* rot = trafo->GetRotationMatrix(); MyTransform3D transform(rot[0],rot[1],rot[2],trans[0]*CM_2_MM, rot[3],rot[4],rot[5],trans[1]*CM_2_MM, rot[6],rot[7],rot[8],trans[2]*CM_2_MM);