Skip to content
Snippets Groups Projects
Commit 0a677daf authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2:
Browse files

Merge branch 'fslAir-sizeableWorld' into 'main'

Resize world volume functionality

See merge request !256
parents 4cd130c0 dcb60818
No related branches found
No related tags found
1 merge request!256Resize world volume functionality
Pipeline #6779196 passed with warnings
Showing
with 150 additions and 50 deletions
......@@ -4,12 +4,12 @@
#include "GeoModelFuncSnippets/GeoShapeUtils.h"
#include "GeoModelFuncSnippets/TransformToStringConverter.h"
/// Boolean volume shapes
#include "GeoModelKernel/GeoShapeUnion.h"
#include "GeoModelKernel/GeoShapeSubtraction.h"
#include "GeoModelKernel/GeoShapeIntersection.h"
#include "GeoModelKernel/GeoShapeShift.h"
#include "GeoModelKernel/GeoShape.h"
/// Ordinary shapes
#include "GeoModelKernel/GeoBox.h"
#include "GeoModelKernel/GeoTrd.h"
......
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
#include "GeoModelFuncSnippets/defineWorld.h"
#include "GeoModelKernel/GeoElement.h"
#include "GeoModelKernel/GeoMaterial.h"
#include "GeoModelKernel/GeoBox.h"
#include "GeoModelKernel/GeoPhysVol.h"
#include "GeoModelKernel/GeoFullPhysVol.h"
#include "GeoModelKernel/GeoVolumeCursor.h"
#include "GeoModelKernel/GeoAlignableTransform.h"
#include "GeoModelKernel/Units.h"
GeoIntrusivePtr<GeoPhysVol> createGeoWorld(const double worldBoxX,
const double worldBoxY,
const double worldBoxZ) {
constexpr double gr = GeoModelKernelUnits::gram;
constexpr double mole = GeoModelKernelUnits::mole;
constexpr double cm3 = GeoModelKernelUnits::cm3;
// Define the chemical elements
GeoIntrusivePtr<GeoElement> Nitrogen{new GeoElement ("Nitrogen" ,"N" , 7.0 , 14.0031 *gr/mole)};
GeoIntrusivePtr<GeoElement> Oxygen{new GeoElement ("Oxygen" ,"O" , 8.0 , 15.9949 *gr/mole)};
GeoIntrusivePtr<GeoElement> Argon{new GeoElement ("Argon" ,"Ar" , 18.0 , 39.9624 *gr/mole)};
GeoIntrusivePtr<GeoElement> Hydrogen{new GeoElement ("Hydrogen" ,"H" , 1.0 , 1.00782503081372 *gr/mole)};
constexpr double densityOfAir=0.001290 *gr/cm3;
GeoIntrusivePtr<GeoMaterial> air{new GeoMaterial("GeoModelAir", densityOfAir)};
air->add(Nitrogen , 0.7494);
air->add(Oxygen, 0.2369);
air->add(Argon, 0.0129);
air->add(Hydrogen, 0.0008);
air->lock();
GeoIntrusivePtr<GeoBox> worldBox{new GeoBox(worldBoxX, worldBoxY, worldBoxZ)};
GeoIntrusivePtr<GeoLogVol> worldLog{new GeoLogVol("WorldLog", worldBox, air)};
GeoIntrusivePtr<GeoPhysVol> world{new GeoPhysVol(worldLog)};
return world;
}
GeoIntrusivePtr<GeoPhysVol> resizeGeoWorld(GeoIntrusivePtr<GeoPhysVol> world)
{
if (world)
{
//resize the world volume to the real needed volume
// get number of children volumes
unsigned int nChild=world->getNChildVols();
//Dimensions of the bounding boxes
double xmin=0.,ymin=0.,zmin=0.,xmax=0.,ymax=0.,zmax=0.;
double xworld=0.,yworld=0.,zworld=0.;
// loop over all children volumes
for (unsigned int i=0; i<nChild; i++)
{
PVConstLink nodeLink = world->getChildVol(i);
if ( dynamic_cast<const GeoVPhysVol*>( &(*( nodeLink ))) )
{
const GeoVPhysVol *childVolV = &(*( nodeLink ));
if ( dynamic_cast<const GeoPhysVol*>(childVolV) ) {
const GeoPhysVol* childVol = dynamic_cast<const GeoPhysVol*>(childVolV);
childVol->getLogVol()->getShape()->extent(xmin, ymin, zmin, xmax, ymax, zmax);
}
else if ( dynamic_cast<const GeoFullPhysVol*>(childVolV) ) {
const GeoFullPhysVol* childVol = dynamic_cast<const GeoFullPhysVol*>(childVolV);
childVol->getLogVol()->getShape()->extent(xmin, ymin, zmin, xmax, ymax, zmax);
}
xworld=std::max({xworld,std::abs(xmin),std::abs(xmax)});
yworld=std::max({yworld,std::abs(ymin),std::abs(ymax)});
zworld=std::max({zworld,std::abs(zmin),std::abs(zmax)});
}
}
GeoIntrusivePtr<GeoPhysVol> resizedWorld{createGeoWorld(xworld, yworld, zworld)};
for (unsigned int i=0; i< world->getNChildNodes(); i++){
const GeoGraphNode * node = *(world->getChildNode(i));
if (dynamic_cast<const GeoVPhysVol*>( node ))
{
if ( dynamic_cast<const GeoFullPhysVol*>(node) ){
const GeoFullPhysVol* nodeFullPhysVol = dynamic_cast<const GeoFullPhysVol*>(node);
resizedWorld->add((GeoGraphNode *)nodeFullPhysVol);
}
else if ( dynamic_cast<const GeoPhysVol*>(node) ){
const GeoPhysVol* nodePhysVol = dynamic_cast<const GeoPhysVol*>(node);
resizedWorld->add((GeoGraphNode *)nodePhysVol);
}
}
else if (dynamic_cast<const GeoNameTag*>( node )){
const GeoNameTag* nodeTag = dynamic_cast<const GeoNameTag*>(node);
resizedWorld->add((GeoGraphNode *)nodeTag);
}
else if (dynamic_cast<const GeoAlignableTransform*>( node )){
const GeoAlignableTransform* nodeAT = dynamic_cast<const GeoAlignableTransform*>(node);
resizedWorld->add((GeoGraphNode *)nodeAT);
}
else if (dynamic_cast<const GeoSerialTransformer*>( node )){
const GeoSerialTransformer* nodeST = dynamic_cast<const GeoSerialTransformer*>(node);
resizedWorld->add((GeoGraphNode *)nodeST);
}
else if (dynamic_cast<const GeoSerialDenominator*>( node )){
const GeoSerialDenominator* nodeSD = dynamic_cast<const GeoSerialDenominator*>(node);
resizedWorld->add((GeoGraphNode *)nodeSD);
}
else if (dynamic_cast<const GeoTransform*>( node )){
const GeoTransform* nodeTransform = dynamic_cast<const GeoTransform*>(node);
resizedWorld->add((GeoGraphNode *)nodeTransform);
}else if (dynamic_cast<const GeoIdentifierTag*>( node )){
const GeoIdentifierTag* nodeIT = dynamic_cast<const GeoIdentifierTag*>(node);
resizedWorld->add((GeoGraphNode *)nodeIT);
}
}
return resizedWorld;
}
return world;
}
......@@ -97,7 +97,7 @@ int main(int argc, char* argv[]) {
std::cout << "ReadGeoModel set.\n";
/* build the GeoModel geometry */
GeoPhysVol* world =
const GeoVPhysVol* world =
readInGeo.buildGeoModel(); // builds the whole GeoModel tree in memory
// and get an handle to the 'world' volume
std::cout << "ReadGeoModel::buildGeoModel() done.\n";
......
......@@ -47,7 +47,6 @@ include( GNUInstallDirs )
# Set up the build of the libraries of the project.
add_subdirectory( GeoModelXML )
add_subdirectory( GeoModelFuncSnippets )
add_subdirectory( GeoModelXMLParser )
add_subdirectory( GeoModelJSONParser )
add_subdirectory( ExpressionEvaluator )
......
......@@ -3,7 +3,7 @@
# Declare the package's executable.
add_executable( gmcat src/gmcat.cxx src/publishMetaData.cpp)
target_link_libraries( gmcat PRIVATE GeoModelCore::GeoModelKernel
GeoModelTools::GeoModelFuncSnippets
GeoModelCore::GeoModelFuncSnippets
GeoModelIO::GeoModelRead
GeoModelIO::GeoModelWrite
GeoModelIO::GeoModelDBManager )
......
......@@ -115,9 +115,10 @@ int main(int argc, char ** argv) {
//
// Create elements and materials for the "World" volume, which is the container:
// Create the "GeoWorld" volume, which is the container:
//
GeoIntrusivePtr<GeoVPhysVol> world{createGeoWorld()};
GeoIntrusivePtr<GeoPhysVol> world{createGeoWorld()};
//
// Loop over plugins, create the geometry and put it under the world:
......@@ -188,9 +189,12 @@ int main(int argc, char ** argv) {
std::cerr << "gmcat -- Error opening the output file: " << outputFile << std::endl;
return 7;
}
//resize the world volume to the needed one
GeoIntrusivePtr<GeoPhysVol> resizedWorld = resizeGeoWorld(world);
GeoModelIO::WriteGeoModel dumpGeoModelGraph(db);
world->exec(&dumpGeoModelGraph);
resizedWorld->exec(&dumpGeoModelGraph);
if (vecPluginsPublishers.size() > 0) {
dumpGeoModelGraph.saveToDB(vecPluginsPublishers);
......
......@@ -6,7 +6,7 @@ target_link_libraries( gmstatistics PRIVATE GeoModelCore::GeoModelKernel
GeoModelIO::GeoModelRead
GeoModelIO::GeoModelWrite
GeoModelIO::GeoModelDBManager
GeoModelTools::GeoModelFuncSnippets )
GeoModelCore::GeoModelFuncSnippets )
# Tweak how debug information should be attached to the executable, in Debug
# builds.
......
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
#include "GeoModelFuncSnippets/defineWorld.h"
#include "GeoModelKernel/GeoElement.h"
#include "GeoModelKernel/GeoMaterial.h"
#include "GeoModelKernel/GeoBox.h"
#include "GeoModelKernel/GeoPhysVol.h"
#include "GeoModelKernel/Units.h"
GeoIntrusivePtr<GeoPhysVol> createGeoWorld(const double worldBoxX,
const double worldBoxY,
const double worldBoxZ) {
constexpr double gr = GeoModelKernelUnits::gram;
constexpr double mole = GeoModelKernelUnits::mole;
constexpr double cm3 = GeoModelKernelUnits::cm3;
// Define the chemical elements
GeoIntrusivePtr<GeoElement> Nitrogen{new GeoElement ("Nitrogen" ,"N" , 7.0 , 14.0067 *gr/mole)};
GeoIntrusivePtr<GeoElement> Oxygen{new GeoElement ("Oxygen" ,"O" , 8.0 , 15.9995 *gr/mole)};
GeoIntrusivePtr<GeoElement> Argon{new GeoElement ("Argon" ,"Ar" , 18.0 , 39.948 *gr/mole)};
GeoIntrusivePtr<GeoElement> Hydrogen{new GeoElement ("Hydrogen" ,"H" , 1.0 , 1.00797 *gr/mole)};
constexpr double densityOfAir=0.001214 *gr/cm3;
GeoIntrusivePtr<GeoMaterial> air{new GeoMaterial("Air", densityOfAir)};
air->add(Nitrogen , 0.7494);
air->add(Oxygen, 0.2369);
air->add(Argon, 0.0129);
air->add(Hydrogen, 0.0008);
air->lock();
GeoIntrusivePtr<GeoBox> worldBox{new GeoBox(worldBoxX, worldBoxY, worldBoxZ)};
GeoIntrusivePtr<GeoLogVol> worldLog{new GeoLogVol("WorldLog", worldBox, air)};
GeoIntrusivePtr<GeoPhysVol> world{new GeoPhysVol(worldLog)};
return world;
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ find_package( ZLIB REQUIRED )
# Create the library.
add_library( GeoModelXml SHARED ${HEADERS} ${SOURCES} )
# link libraries
target_link_libraries( GeoModelXml PUBLIC GeoModelCore::GeoModelKernel GeoModelTools::GeoModelFuncSnippets GeoModelTools::ExpressionEvaluator XercesC::XercesC PRIVATE ZLIB::ZLIB )
target_link_libraries( GeoModelXml PUBLIC GeoModelCore::GeoModelKernel GeoModelCore::GeoModelFuncSnippets GeoModelTools::ExpressionEvaluator XercesC::XercesC PRIVATE ZLIB::ZLIB )
target_include_directories( GeoModelXml PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include> )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment