From 87da6d83095f46018c2bcc1f7614c912349a6007 Mon Sep 17 00:00:00 2001 From: Markus Frank <markus.frank@cern.ch> Date: Fri, 12 Oct 2012 16:32:46 +0000 Subject: [PATCH] Fix Geant4 interface --- DDExamples/CLICSiD/compact/compact.xml | 4 ++-- DDG4/src/Geant4Converter.cpp | 29 +++++++++++++++++++++----- ReadMe.txt | 2 ++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/DDExamples/CLICSiD/compact/compact.xml b/DDExamples/CLICSiD/compact/compact.xml index e8dc2c841..3ac58d35d 100644 --- a/DDExamples/CLICSiD/compact/compact.xml +++ b/DDExamples/CLICSiD/compact/compact.xml @@ -1555,8 +1555,8 @@ </readouts> <fields> <field name="GlobalSolenoid" type="SolenoidMagnet" - inner_field="5.0" - outer_field="-1.5" + inner_field="5.0*tesla" + outer_field="-1.5*tesla" zmax="SolenoidCoilOuterZ" outer_radius="SolenoidalFieldRadius"> </field> diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 522acb52e..ca141091d 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -75,6 +75,7 @@ using namespace DD4hep; using namespace std; namespace { + static TGeoNode* s_topPtr; static string indent = ""; struct MyTransform3D : public G4Transform3D { MyTransform3D(double XX, double XY, double XZ, double DX, @@ -403,12 +404,12 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) G4GeometryInfo& info = data(); G4PVPlacement* g4 = info.g4Placements[node]; if ( !g4 ) { - TGeoMatrix* trafo = node->GetMatrix(); + TGeoMatrix* trafo = node->GetMatrix(); + int copy = node->GetNumber(); + G4LogicalVolume* vol = info.g4Volumes[node->GetVolume()]; + G4LogicalVolume* mot = info.g4Volumes[node->GetMotherVolume()]; if ( trafo ) { const Double_t* trans = trafo->GetTranslation(); - int copy = node->GetNumber(); - G4LogicalVolume* vol = info.g4Volumes[node->GetVolume()]; - G4LogicalVolume* mot = info.g4Volumes[node->GetMotherVolume()]; const Value<TGeoNodeMatrix,PlacedVolume::Object>* obj = dynamic_cast<const Value<TGeoNodeMatrix,PlacedVolume::Object>* >(node); if ( 0 == vol ) { @@ -440,6 +441,19 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) } data().g4Placements[node] = g4; } + else if ( node == s_topPtr ) { + G4ThreeVector pos(0,0,0); + g4 = new G4PVPlacement(0, // no rotation + pos, // translation position + vol, // its logical volume + name, // its name + mot, // its mother (logical) volume + false, // no boolean operations + copy, // its copy number + m_checkOverlaps); + data().g4Placements[node] = g4; + cout << "Attempt to convert TOP Detector node failed." << endl; + } } else { cout << "Attempt to DOUBLE-place physical volume:" << name << " No:" << node->GetNumber() << endl; @@ -674,9 +688,14 @@ void Geant4Converter::create(DetElement top) { G4GeometryInfo& geo = *(m_dataPtr=new G4GeometryInfo); m_data->clear(); collect(top,geo); - + s_topPtr = top.placement().ptr(); m_checkOverlaps = false; + // Ensure that all required materials are present in the Geant4 material table + const LCDD::HandleMap& mat = lcdd.materials(); + for(LCDD::HandleMap::const_iterator i=mat.begin(); i!=mat.end(); ++i) + geo.materials.insert((TGeoMedium*)(*i).second.ptr()); + // We do not have to handle defines etc. // All positions and the like are not really named. // Hence, start creating the G4 objects for materials, solids and log volumes. diff --git a/ReadMe.txt b/ReadMe.txt index 0e0637f3f..3466447bd 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -103,3 +103,5 @@ DDExamples/CLICSiD/CLICSiDtest file:../DD4hep/DDExamples/CLICSiD/compact/compact - CLICSid example with all SiD sub-detectors DDExamples/CLICSiDDisplay/CLICSiDtest file:../DD4hep/DDExamples/CLICSiD/compact/compact.xml +- Geant4 example with SiD (careful, need to set Geant4 variables in addition) +./DDExamples/CLICSiDSimu/CLICSiDSimu file:../DD4hep/DDExamples/CLICSiD/compact/compact.xml file:../DD4hep/DDExamples/CLICSiD/compact/sensitive_detectors.xml -- GitLab