diff --git a/Simulation/G4Utilities/GeoMaterial2G4/GeoMaterial2G4/Geo2G4MaterialFactory.h b/Simulation/G4Utilities/GeoMaterial2G4/GeoMaterial2G4/Geo2G4MaterialFactory.h index f8ca8be782e6a13f90bfb5058b2b9460e68f7747..d8f3f8ac199388e8d814a196817bd130fc669130 100644 --- a/Simulation/G4Utilities/GeoMaterial2G4/GeoMaterial2G4/Geo2G4MaterialFactory.h +++ b/Simulation/G4Utilities/GeoMaterial2G4/GeoMaterial2G4/Geo2G4MaterialFactory.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMATERIAL2G4_Geo2G4MaterialFactory_h @@ -22,8 +22,8 @@ public: /// Check whether the logging system is active at the provided verbosity level bool msgLvl( MSG::Level lvl ) const { return m_msg.get().level() <= lvl; } private: - matList m_definedMaterials; - matNames m_definedMatNames; + matList m_geoMaterialToG4Material; + matNames m_geoMaterialNameToObject; /// Private message stream member mutable Athena::MsgStreamMember m_msg; }; diff --git a/Simulation/G4Utilities/GeoMaterial2G4/src/Geo2G4MaterialFactory.cxx b/Simulation/G4Utilities/GeoMaterial2G4/src/Geo2G4MaterialFactory.cxx index 86e94648f4b2d8d0526371b64bc6b5fbe47d0aab..c57663d04100456cf44c3f81df24dd2db10486ad 100644 --- a/Simulation/G4Utilities/GeoMaterial2G4/src/Geo2G4MaterialFactory.cxx +++ b/Simulation/G4Utilities/GeoMaterial2G4/src/Geo2G4MaterialFactory.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "GeoMaterial2G4/Geo2G4MaterialFactory.h" @@ -18,7 +18,7 @@ Geo2G4MaterialFactory::Geo2G4MaterialFactory(): m_msg("Geo2G4MaterialFactory") { } -G4Material* Geo2G4MaterialFactory::Build(const GeoMaterial* theMat) +G4Material* Geo2G4MaterialFactory::Build(const GeoMaterial* geoMaterial) { static Geo2G4ElementFactory eFactory; Geo2G4MatPropTableFactory* tFactory = Geo2G4MatPropTableFactory::instance(); @@ -26,18 +26,18 @@ G4Material* Geo2G4MaterialFactory::Build(const GeoMaterial* theMat) // // Check if this material has already been defined. // - std::string nam = theMat->getName(); - - if(m_definedMaterials.find(theMat) != m_definedMaterials.end()) - return m_definedMaterials[theMat]; + if(m_geoMaterialToG4Material.find(geoMaterial) != m_geoMaterialToG4Material.end()) { + return m_geoMaterialToG4Material[geoMaterial]; + } - int nelements = theMat->getNumElements(); + const std::string& geoMaterialName = geoMaterial->getName(); + const int nelements = geoMaterial->getNumElements(); // Different actions depending whether we are dealing with // standard or extended materials - const GeoExtendedMaterial* extMat = dynamic_cast<const GeoExtendedMaterial*>(theMat); - G4Material* newmaterial = 0; + const GeoExtendedMaterial* extMat = dynamic_cast<const GeoExtendedMaterial*>(geoMaterial); + G4Material* g4Material{}; if(extMat) { G4State state = kStateUndefined; @@ -60,43 +60,63 @@ G4Material* Geo2G4MaterialFactory::Build(const GeoMaterial* theMat) break; } - double temperature = extMat->getTemperature(); - double pressure = extMat->getPressure(); + const double temperature = extMat->getTemperature(); + const double pressure = extMat->getPressure(); - newmaterial= new G4Material(nam, - extMat->getDensity(), - nelements, - state, - temperature, - pressure); + g4Material= new G4Material(geoMaterialName, + extMat->getDensity(), + nelements, + state, + temperature, + pressure); // Build G4MaterialPropertiesTable if needed GeoMaterialPropertiesTable* geoPropTable = extMat->GetMaterialPropertiesTable(); if(geoPropTable) { G4MaterialPropertiesTable* g4PropTable = tFactory->Build(geoPropTable); - if(g4PropTable) - newmaterial->SetMaterialPropertiesTable(g4PropTable); + if(g4PropTable) { + g4Material->SetMaterialPropertiesTable(g4PropTable); + } } } - else - newmaterial= new G4Material(nam, - theMat->getDensity(), - nelements); + else { + g4Material= new G4Material(geoMaterialName, + geoMaterial->getDensity(), + nelements); + } for (int ii = 0; ii< nelements; ii++) { - G4Element* theG4Ele = eFactory.Build(theMat->getElement(ii)); - newmaterial->AddElement(theG4Ele, theMat->getFraction(ii)); + G4Element* g4Element = eFactory.Build(geoMaterial->getElement(ii)); + g4Material->AddElement(g4Element, geoMaterial->getFraction(ii)); + } + + const G4MaterialTable & theMaterialTable = *(g4Material->GetMaterialTable()); + const G4String& g4MaterialName = g4Material->GetName(); + std::vector<size_t> copyIndex{}; + for(size_t i=0; i< theMaterialTable.size(); ++i) { + if(theMaterialTable[i]->GetName() == g4MaterialName) { + copyIndex.push_back(i); + } + } + if ( copyIndex.size() > 1 ) { + ATH_MSG_INFO ( "Details of all G4Materials named " << g4MaterialName << " in the G4MaterialTable."); + for (const auto& index : copyIndex) { + ATH_MSG_INFO ( "G4Material at position "<< index<<" in the G4MaterialTable: \n" << *(theMaterialTable[index])); + } } - m_definedMaterials[theMat]=newmaterial; + + m_geoMaterialToG4Material[geoMaterial]=g4Material; // Check if we have the situation when on GeoModel side two different // materials share the same name. // Print an INFO message if so. - if(m_definedMatNames.find(nam)==m_definedMatNames.end()) - m_definedMatNames[nam] = theMat; - else if(m_definedMatNames[nam] != theMat) - ATH_MSG_INFO ( "!!! On GeoModel side two different materials share the name: " << nam ); - return newmaterial; + if(m_geoMaterialNameToObject.find(geoMaterialName)==m_geoMaterialNameToObject.end()) + m_geoMaterialNameToObject[geoMaterialName] = geoMaterial; + else if(m_geoMaterialNameToObject[geoMaterialName] != geoMaterial) { + ATH_MSG_INFO ( "!!! On GeoModel side two different materials share the name: " << geoMaterialName ); + } + + return g4Material; }