Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend usage to asymmetric ranges. #1170

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 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] "
dhevang marked this conversation as resolved.
Show resolved Hide resolved
<< std::endl ;

exit(1) ;
Expand All @@ -41,12 +41,43 @@ 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(':');

float minX=0, maxX=0, minY=0, maxY=0, minZ=0, maxZ=0;

if( colon_posX == std::string::npos || colon_posY == std::string::npos || colon_posZ == std::string::npos ) {
dhevang marked this conversation as resolved.
Show resolved Hide resolved
// symmetric intervals
std::cout << "Intervals not specified as xmin:xmax ymin:ymax zmin:zmax" << std::endl
<< " setting xmin = -xmax, ymin = -ymax, zmin = -zmax " << std::endl;
maxX = std::stof( RangeX );
maxY = std::stof( RangeY );
maxZ = std::stof( RangeZ );
minX = -maxX;
minY = -maxY;
minZ = -maxZ;
}
else { // asymmetric intervals
minX = std::stof( RangeX.substr(0, colon_posX) );
maxX = std::stof( RangeX.substr(colon_posX+1) );
minY = std::stof( RangeY.substr(0, colon_posY) );
maxY = std::stof( RangeY.substr(colon_posY+1) );
minZ = std::stof( RangeZ.substr(0, colon_posZ) );
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 +88,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
Loading