diff --git a/DDG4/include/DDG4/Geant4Converter.h b/DDG4/include/DDG4/Geant4Converter.h index 60ac541c2bb4baade8bd73d71f0477d39fdfd20d..d1729afd6a78a6d4a5fa4fd3a6cde00eb20f12bb 100644 --- a/DDG4/include/DDG4/Geant4Converter.h +++ b/DDG4/include/DDG4/Geant4Converter.h @@ -35,6 +35,8 @@ namespace DD4hep { bool debugMaterials = false; /// Property: Flag to debug elements during conversion mechanism bool debugElements = false; + /// Property: Flag to debug shapes during conversion mechanism + bool debugShapes = false; /// Property: Flag to debug volumes during conversion mechanism bool debugVolumes = false; /// Property: Flag to debug placements during conversion mechanism @@ -42,8 +44,15 @@ namespace DD4hep { /// Property: Flag to debug regions during conversion mechanism bool debugRegions = false; - bool m_checkOverlaps; - PrintLevel m_outputLevel; + /// Property: Flag to dump all placements after the conversion procedure + bool printPlacements = false; + /// Property: Flag to dump all sensitives after the conversion procedure + bool printSensitives = false; + + /// Property: Check geometrical overlaps for volume placements and G4 imprints + bool checkOverlaps; + /// Property: Output level for debug printing + PrintLevel outputLevel; /// Initializing Constructor Geant4Converter(LCDD& lcdd); diff --git a/DDG4/plugins/Geant4DetectorGeometryConstruction.cpp b/DDG4/plugins/Geant4DetectorGeometryConstruction.cpp index 9c0bf1515147b45c625e9459ffab7cdb29142a30..319fb02aad141edb2a386aa165270f2f2f162ed8 100644 --- a/DDG4/plugins/Geant4DetectorGeometryConstruction.cpp +++ b/DDG4/plugins/Geant4DetectorGeometryConstruction.cpp @@ -33,17 +33,25 @@ namespace DD4hep { */ class Geant4DetectorGeometryConstruction : public Geant4DetectorConstruction { /// Property: Dump geometry hierarchy - bool m_dumpHierarchy = false; + bool m_dumpHierarchy = false; /// Property: Flag to debug materials during conversion mechanism - bool m_debugMaterials = false; + bool m_debugMaterials = false; /// Property: Flag to debug elements during conversion mechanism - bool m_debugElements = false; + bool m_debugElements = false; + /// Property: Flag to debug shapes during conversion mechanism + bool m_debugShapes = false; /// Property: Flag to debug volumes during conversion mechanism - bool m_debugVolumes = false; + bool m_debugVolumes = false; /// Property: Flag to debug placements during conversion mechanism - bool m_debugPlacements= false; + bool m_debugPlacements = false; /// Property: Flag to debug regions during conversion mechanism - bool m_debugRegions = false; + bool m_debugRegions = false; + + /// Property: Flag to dump all placements after the conversion procedure + bool m_printPlacements = false; + /// Property: Flag to dump all sensitives after the conversion procedure + bool m_printSensitives = false; + /// Property: G4 GDML dump file name (default: empty. If non empty, dump) std::string m_dumpGDML; @@ -86,9 +94,14 @@ Geant4DetectorGeometryConstruction::Geant4DetectorGeometryConstruction(Geant4Con { declareProperty("DebugMaterials", m_debugMaterials); declareProperty("DebugElements", m_debugElements); + declareProperty("DebugShapes", m_debugShapes); declareProperty("DebugVolumes", m_debugVolumes); declareProperty("DebugPlacements", m_debugPlacements); declareProperty("DebugRegions", m_debugRegions); + + declareProperty("PrintPlacements", m_printPlacements); + declareProperty("PrintSensitives", m_printSensitives); + declareProperty("DumpHierarchy", m_dumpHierarchy); declareProperty("DumpGDML", m_dumpGDML=""); InstanceCount::increment(this); @@ -106,6 +119,7 @@ void Geant4DetectorGeometryConstruction::constructGeo(Geant4DetectorConstruction Geant4Converter conv(ctxt->lcdd, outputLevel()); conv.debugMaterials = m_debugMaterials; conv.debugElements = m_debugElements; + conv.debugShapes = m_debugShapes; conv.debugVolumes = m_debugVolumes; conv.debugPlacements = m_debugPlacements; conv.debugRegions = m_debugRegions; diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index ccf36a5e9f64978ffd680ed39f05ed51cf2a3799..6901cb250288a44e3fc74ad321a87fa966f71844 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -262,18 +262,18 @@ namespace { /// Initializing Constructor Geant4Converter::Geant4Converter(LCDD& lcdd_ref) - : Geant4Mapping(lcdd_ref), m_checkOverlaps(true) { + : Geant4Mapping(lcdd_ref), checkOverlaps(true) { this->Geant4Mapping::init(); m_propagateRegions = true; - m_outputLevel = PrintLevel(printLevel() - 1); + outputLevel = PrintLevel(printLevel() - 1); } /// Initializing Constructor Geant4Converter::Geant4Converter(LCDD& lcdd_ref, PrintLevel level) - : Geant4Mapping(lcdd_ref), m_checkOverlaps(true) { + : Geant4Mapping(lcdd_ref), checkOverlaps(true) { this->Geant4Mapping::init(); m_propagateRegions = true; - m_outputLevel = level; + outputLevel = level; } /// Standard destructor @@ -286,7 +286,7 @@ void* Geant4Converter::handleElement(const string& name, const Atom element) con if (!g4e) { g4e = G4Element::GetElement(name, false); if (!g4e) { - PrintLevel lvl = debugElements ? ALWAYS : m_outputLevel; + PrintLevel lvl = debugElements ? ALWAYS : outputLevel; double a_conv = (CLHEP::g / CLHEP::mole); if (element->GetNisotopes() > 0) { g4e = new G4Element(name, element->GetTitle(), element->GetNisotopes()); @@ -339,7 +339,7 @@ void* Geant4Converter::handleElement(const string& name, const Atom element) con void* Geant4Converter::handleMaterial(const string& name, Material medium) const { G4Material* mat = data().g4Materials[medium]; if (!mat) { - PrintLevel lvl = debugMaterials ? ALWAYS : m_outputLevel; + PrintLevel lvl = debugMaterials ? ALWAYS : outputLevel; mat = G4Material::GetMaterial(name, false); if (!mat) { TGeoMaterial* material = medium->GetMaterial(); @@ -405,6 +405,7 @@ void* Geant4Converter::handleMaterial(const string& name, Material medium) const void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) const { G4VSolid* solid = 0; if (shape) { + PrintLevel lvl = debugShapes ? ALWAYS : outputLevel; if (0 != (solid = data().g4Solids[shape])) { return solid; } @@ -478,8 +479,10 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c } else if (shape->IsA() == TGeoConeSeg::Class()) { const TGeoConeSeg* s = (const TGeoConeSeg*) shape; - solid = new G4Cons(name, s->GetRmin1() * CM_2_MM, s->GetRmax1() * CM_2_MM, s->GetRmin2() * CM_2_MM, - s->GetRmax2() * CM_2_MM, s->GetDz() * CM_2_MM, s->GetPhi1() * DEGREE_2_RAD, (s->GetPhi2()-s->GetPhi1()) * DEGREE_2_RAD); + solid = new G4Cons(name, s->GetRmin1() * CM_2_MM, s->GetRmax1() * CM_2_MM, + s->GetRmin2() * CM_2_MM, s->GetRmax2() * CM_2_MM, + s->GetDz() * CM_2_MM, + s->GetPhi1() * DEGREE_2_RAD, (s->GetPhi2()-s->GetPhi1()) * DEGREE_2_RAD); } else if (shape->IsA() == TGeoParaboloid::Class()) { const TGeoParaboloid* s = (const TGeoParaboloid*) shape; @@ -534,13 +537,13 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c if (oper == TGeoBoolNode::kGeoIntersection) { TGeoScaledShape* lls = (TGeoScaledShape *)ls; TGeoBBox* rrs = (TGeoBBox*)rs; - double sx = lls->GetScale()->GetScale()[0]; - double sy = lls->GetScale()->GetScale()[1]; + double sx = lls->GetScale()->GetScale()[0]; + double sy = lls->GetScale()->GetScale()[1]; double radius = ((TGeoSphere *)lls->GetShape())->GetRmax(); - double dz = rrs->GetDZ(); - double zorig = rrs->GetOrigin()[2]; - double zcut2 = dz + zorig; - double zcut1 = 2 * zorig - zcut2; + double dz = rrs->GetDZ(); + double zorig = rrs->GetOrigin()[2]; + double zcut2 = dz + zorig; + double zcut1 = 2 * zorig - zcut2; solid = new G4Ellipsoid(name, sx * radius * CM_2_MM, sy * radius * CM_2_MM, @@ -578,6 +581,10 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c string err = "Failed to handle unknown solid shape:" + name + " of type " + string(shape->IsA()->GetName()); throw runtime_error(err); } + else { + printout(lvl,"Geant4Converter","++ Successessfully converted shape [%p] of type:%s to %s.", + solid,shape->IsA()->GetName(),typeName(typeid(*solid)).c_str()); + } data().g4Solids[shape] = solid; } return solid; @@ -588,7 +595,7 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume Geant4GeometryInfo& info = data(); Geant4GeometryMaps::VolumeMap::const_iterator volIt = info.g4Volumes.find(volume); if (volIt == info.g4Volumes.end() ) { - PrintLevel lvl = debugVolumes ? ALWAYS : m_outputLevel; + PrintLevel lvl = debugVolumes ? ALWAYS : outputLevel; const TGeoVolume* v = volume; Volume _v = Ref_t(v); string n = v->GetName(); @@ -683,7 +690,7 @@ void* Geant4Converter::handleAssembly(const std::string& name, const TGeoNode* n Geant4AssemblyVolume* g4 = info.g4AssemblyVolumes[node]; if ( !g4 ) { - PrintLevel lvl = debugVolumes ? ALWAYS : m_outputLevel; + PrintLevel lvl = debugVolumes ? ALWAYS : outputLevel; g4 = new Geant4AssemblyVolume(); for(Int_t i=0; i < mot_vol->GetNdaughters(); ++i) { TGeoNode* d = mot_vol->GetNode(i); @@ -741,7 +748,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) node->IsA()->GetName(), vol); } else { - PrintLevel lvl = debugPlacements ? ALWAYS : m_outputLevel; + PrintLevel lvl = debugPlacements ? ALWAYS : outputLevel; int copy = node->GetNumber(); bool node_is_assembly = vol->IsA() == TGeoVolumeAssembly::Class(); bool mother_is_assembly = mot_vol ? mot_vol->IsA() == TGeoVolumeAssembly::Class() : false; @@ -773,7 +780,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) Geant4AssemblyVolume* ass = (Geant4AssemblyVolume*)info.g4AssemblyVolumes[node]; Geant4AssemblyVolume::Chain chain; chain.push_back(node); - ass->imprint(info,node,chain,ass,(*volIt).second, transform, copy, m_checkOverlaps); + ass->imprint(info,node,chain,ass,(*volIt).second, transform, copy, checkOverlaps); return 0; } else if ( node != gGeoManager->GetTopNode() && volIt == info.g4Volumes.end() ) { @@ -787,7 +794,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) g4mot, // its mother (logical) volume false, // no boolean operations copy, // its copy number - m_checkOverlaps); + checkOverlaps); } info.g4Placements[node] = g4; } @@ -801,7 +808,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) void* Geant4Converter::handleRegion(Region region, const set<const TGeoVolume*>& /* volumes */) const { G4Region* g4 = data().g4Regions[region]; if (!g4) { - PrintLevel lvl = debugRegions ? ALWAYS : m_outputLevel; + PrintLevel lvl = debugRegions ? ALWAYS : outputLevel; Region r = Ref_t(region); g4 = new G4Region(r.name()); // set production cut @@ -935,7 +942,7 @@ void Geant4Converter::handleProperties(LCDD::Properties& prp) const { if (result != 1) { throw runtime_error("Failed to invoke the plugin " + tag + " of type " + type); } - printout(m_outputLevel, "Geant4Converter", "+++++ Executed Successfully Geant4 setup module *%s*.", type.c_str()); + printout(outputLevel, "Geant4Converter", "+++++ Executed Successfully Geant4 setup module *%s*.", type.c_str()); } } @@ -997,18 +1004,18 @@ void* Geant4Converter::printPlacement(const string& name, const TGeoNode* node) stringstream str; str << "G4Cnv::placement: + " << name << " No:" << node->GetNumber() << " Vol:" << vol->GetName() << " Solid:" << sol->GetName(); - printout(m_outputLevel, "G4Placement", str.str().c_str()); + printout(outputLevel, "G4Placement", str.str().c_str()); str.str(""); str << " |" << " Loc: x=" << tr.x() << " y=" << tr.y() << " z=" << tr.z(); - printout(m_outputLevel, "G4Placement", str.str().c_str()); - printout(m_outputLevel, "G4Placement", printSolid(sol).c_str()); + printout(outputLevel, "G4Placement", str.str().c_str()); + printout(outputLevel, "G4Placement", printSolid(sol).c_str()); str.str(""); str << " |" << " Ndau:" << vol->GetNoDaughters() << " physvols." << " Mat:" << vol->GetMaterial()->GetName() << " Mother:" << (char*) (mot ? mot->GetName().c_str() : "---"); - printout(m_outputLevel, "G4Placement", str.str().c_str()); + printout(outputLevel, "G4Placement", str.str().c_str()); str.str(""); str << " |" << " SD:" << sd->GetName(); - printout(m_outputLevel, "G4Placement", str.str().c_str()); + printout(outputLevel, "G4Placement", str.str().c_str()); return g4; } @@ -1041,33 +1048,36 @@ Geant4Converter& Geant4Converter::create(DetElement top) { Geant4GeometryInfo& geo = this->init(); m_data->clear(); collect(top, geo); - m_checkOverlaps = false; + checkOverlaps = false; // 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. - //m_outputLevel = WARNING; + //outputLevel = WARNING; //setPrintLevel(VERBOSE); handle(this, geo.volumes, &Geant4Converter::collectVolume); handle(this, geo.solids, &Geant4Converter::handleSolid); - printout(m_outputLevel, "Geant4Converter", "++ Handled %ld solids.", geo.solids.size()); + printout(outputLevel, "Geant4Converter", "++ Handled %ld solids.", geo.solids.size()); handleRefs(this, geo.vis, &Geant4Converter::handleVis); - printout(m_outputLevel, "Geant4Converter", "++ Handled %ld visualization attributes.", geo.vis.size()); + printout(outputLevel, "Geant4Converter", "++ Handled %ld visualization attributes.", geo.vis.size()); handleMap(this, geo.limits, &Geant4Converter::handleLimitSet); - printout(m_outputLevel, "Geant4Converter", "++ Handled %ld limit sets.", geo.limits.size()); + printout(outputLevel, "Geant4Converter", "++ Handled %ld limit sets.", geo.limits.size()); handleMap(this, geo.regions, &Geant4Converter::handleRegion); - printout(m_outputLevel, "Geant4Converter", "++ Handled %ld regions.", geo.regions.size()); + printout(outputLevel, "Geant4Converter", "++ Handled %ld regions.", geo.regions.size()); handle(this, geo.volumes, &Geant4Converter::handleVolume); - printout(m_outputLevel, "Geant4Converter", "++ Handled %ld volumes.", geo.volumes.size()); + printout(outputLevel, "Geant4Converter", "++ Handled %ld volumes.", geo.volumes.size()); handleRMap(this, *m_data, &Geant4Converter::handleAssembly); // Now place all this stuff appropriately handleRMap(this, *m_data, &Geant4Converter::handlePlacement); //==================== Fields handleProperties(m_lcdd.properties()); - - //handleMap(this, geo.sensitives, &Geant4Converter::printSensitive); - //handleRMap(this, *m_data, &Geant4Converter::printPlacement); + if ( printSensitives ) { + handleMap(this, geo.sensitives, &Geant4Converter::printSensitive); + } + if ( printPlacements ) { + handleRMap(this, *m_data, &Geant4Converter::printPlacement); + } geo.setWorld(top.placement().ptr()); geo.valid = true; diff --git a/examples/ClientTests/scripts/SiliconBlock.py b/examples/ClientTests/scripts/SiliconBlock.py index fc1f5bd2aa3082d23e4e4506fc372458cd2afcce..c51b4b6df2aee04b9eecedfda327d34aaba154b8 100644 --- a/examples/ClientTests/scripts/SiliconBlock.py +++ b/examples/ClientTests/scripts/SiliconBlock.py @@ -41,7 +41,8 @@ def run(): seq,act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo") act.DebugMaterials = True act.DebugElements = False - act.DebugVolumes = False + act.DebugVolumes = True + act.DebugShapes = True # Configure I/O evt_root = geant4.setupROOTOutput('RootOutput','SiliconBlock_'+time.strftime('%Y-%m-%d_%H-%M')) diff --git a/examples/DDDB/CMakeLists.txt b/examples/DDDB/CMakeLists.txt index 83441d54239a5fcae70cad403dacfafb14b6ed12..1618ae912d21d7c931203c28dda44fded6212911 100644 --- a/examples/DDDB/CMakeLists.txt +++ b/examples/DDDB/CMakeLists.txt @@ -46,7 +46,7 @@ if (DD4HEP_USE_XERCESC) dd4hep_add_test_reg( test_DDDB_load_LONGTEST COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDDB.sh" EXEC_ARGS ${CMAKE_INSTALL_PREFIX}/bin/run_dddb.sh - REGEX_PASS "Converted 12851 placements" ) + REGEX_PASS "Converted 12852 placements" ) # #---Testing: Load the geometry + conditions from archive ---------------------- dd4hep_add_test_reg( test_DDDB_conditions_LONGTEST