Skip to content

Commit

Permalink
Extend usage to asymmetric ranges.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhevang committed Sep 18, 2023
1 parent df64551 commit fa63b53
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions UtilityApps/src/dumpBfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ using namespace dd4hep::detail;
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]" << std::endl
<< " will dump the B-field in volume [-x:x,-y:y,-z,z] with steps [dx,dy,dz] "
std::cout << " usage: dumpBfield compact.xml xmin:xmax ymin:ymax zmin:zmax dx dy dz [in cm]" << std::endl
<< " will dump the B-field in volume [xmin:xmax, ymin:ymax, zmin:zmax] with steps [dx,dy,dz] "
<< std::endl ;

exit(1) ;
Expand All @@ -41,12 +41,33 @@ static int invoke_dump_B_field(int argc, char** argv ){
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 >> yRange >> zRange >> dx >> dy >> dz;
std::string RangeX , RangeY , RangeZ;
float dx , dy, dz ;

xRange *= dd4hep::cm;
yRange *= dd4hep::cm;
zRange *= dd4hep::cm;
sstr >> RangeX >> RangeY >> RangeZ >> dx >> dy >> dz;

size_t colon_posX = RangeX.find(':');
size_t colon_posY = RangeY.find(':');
size_t colon_posZ = RangeZ.find(':');

if( colon_posX == std::string::npos || colon_posY == std::string::npos || colon_posZ == std::string::npos ) {
std::cout << " usage: dumpBfield compact.xml xmin:xmax ymin:ymax zmin:zmax dx dy dz [in cm]" << std::endl;
exit(1);
}

float minX = std::stof( RangeX.substr(0, colon_posX) );
float maxX = std::stof( RangeX.substr(colon_posX+1) );
float minY = std::stof( RangeY.substr(0, colon_posY) );
float maxY = std::stof( RangeY.substr(colon_posY+1) );
float minZ = std::stof( RangeZ.substr(0, colon_posZ) );
float maxZ = std::stof( RangeZ.substr(colon_posZ+1) );

minX *= dd4hep::cm;
maxX *= dd4hep::cm;
minY *= dd4hep::cm;
maxY *= dd4hep::cm;
minZ *= dd4hep::cm;
maxZ *= dd4hep::cm;
dx *= dd4hep::cm;
dy *= dd4hep::cm;
dz *= dd4hep::cm;
Expand All @@ -57,9 +78,9 @@ static int invoke_dump_B_field(int argc, char** argv ){
printf("#######################################################################################################\n");
printf(" x[cm] y[cm] z[cm] Bx[Tesla] By[Tesla] Bz[Tesla] \n");

for( float x = -xRange ; x <=xRange ; x += dx ){
for( float y = -yRange ; y <=yRange ; y += dy ){
for( float z = -zRange ; z <=zRange ; z += dz ){
for( float x = minX ; x <= maxX ; x += dx ){
for( float y = minY ; y <= maxY ; y += dy ){
for( float z = minZ ; z <= maxZ ; z += dz ){

double posV[3] = { x, y, z } ;
double bfieldV[3] ;
Expand Down

0 comments on commit fa63b53

Please sign in to comment.