From 9492117a6e49ca8e6a5706a0b783a4b133974a09 Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Wed, 29 Mar 2017 17:34:46 +0200 Subject: [PATCH] add utility dumpBfield.cpp --- UtilityApps/CMakeLists.txt | 2 + UtilityApps/src/dumpBfield.cpp | 98 ++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 UtilityApps/src/dumpBfield.cpp diff --git a/UtilityApps/CMakeLists.txt b/UtilityApps/CMakeLists.txt index 5104c8824..bb3fda060 100644 --- a/UtilityApps/CMakeLists.txt +++ b/UtilityApps/CMakeLists.txt @@ -19,6 +19,8 @@ dd4hep_add_executable( geoConverter src/converter.cpp ) #----------------------------------------------------------------------------------- dd4hep_add_executable( geoPluginRun src/plugin_runner.cpp ) #----------------------------------------------------------------------------------- +dd4hep_add_executable( dumpBfield src/dumpBfield.cpp ) +#----------------------------------------------------------------------------------- dd4hep_add_executable( print_materials src/print_materials.cpp USES DDRec ) #----------------------------------------------------------------------------------- dd4hep_add_executable( materialScan src/materialScan.cpp USES DDRec ) diff --git a/UtilityApps/src/dumpBfield.cpp b/UtilityApps/src/dumpBfield.cpp new file mode 100644 index 000000000..0d5b6f0dc --- /dev/null +++ b/UtilityApps/src/dumpBfield.cpp @@ -0,0 +1,98 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +//========================================================================== +// +// Simple program to dump the B-field of the world volume in a cartesian grid +// +// Author : F.Gaede, DESY +// Date : 29 Mar 2017 +//========================================================================== + +// Framework include files +#include "DD4hep/LCDD.h" +#include "DD4hep/DD4hepUnits.h" + +using namespace std ; +using namespace DD4hep ; +using namespace DD4hep::Geometry; + +//============================================================================= + + +static int invoke_dump_B_field(int argc, char** argv ){ + + if( argc != 8 ) { + std::cout << " usage: dumpBfield compact.xml x y z dx dy dz [in cm]" + << " will dump the B-field in volume [-x:x,-y:y,-z,z] with steps [dx,dy,dz] " + << std::endl ; + + exit(1) ; + } + + std::string inFile = argv[1] ; + + std::stringstream sstr ; + sstr << argv[2] << " " << argv[3] << " " << argv[4] << " " << argv[5] << " " << argv[6] << " " << argv[7] ; + + float xRange , yRange , zRange , dx , dy, dz ; + sstr >> xRange ; + sstr >> yRange ; + sstr >> zRange ; + sstr >> dx ; + sstr >> dy ; + sstr >> dz ; + + + + LCDD& lcdd = LCDD::getInstance(); + lcdd.fromCompact( inFile ); + + DetElement world = lcdd.world() ; + + + std::cout << "#######################################################################################################" << std::endl ; + std::cout << " x[cm] y[cm] z[cm] Bx[Tesla] By[cm] Bz[cm] " << std::endl ; + + + for( float x = -xRange ; x <=xRange ; x += dx ){ + for( float y = -yRange ; y <=yRange ; y += dy ){ + for( float z = -zRange ; z <=zRange ; z += dz ){ + + double posV[3] = { x, y, z } ; + double bfieldV[3] ; + lcdd.field().magneticField( { 0., 0., 0. } , bfieldV ) ; + + printf(" %+15.8e %+15.8e %+15.8e %+15.8e %+15.8e %+15.8e \n", posV[0], posV[1], posV[2], bfieldV[0]/dd4hep::tesla , bfieldV[1]/dd4hep::tesla, bfieldV[2]/dd4hep::tesla ) ; + + } + } + } + + std::cout << "#######################################################################################################" << std::endl ; + + return 0; +} + + + +int main(int argc, char** argv ){ + try { + return invoke_dump_B_field(argc,argv); + } + catch(const std::exception& e) { + std::cout << "Got uncaught exception: " << e.what() << std::endl; + } + catch (...) { + std::cout << "Got UNKNOWN uncaught exception." << std::endl; + } + return EINVAL; +} + +//============================================================================= -- GitLab