29 static int invoke_dump_B_field(
int argc,
char** argv ){
32 std::cout <<
" usage: dumpBfield compact.xml xmin[:xmax] ymin[:ymax] zmin[:zmax] dx dy dz [in cm]" << std::endl
33 <<
" will dump the B-field in volume (xmin:xmax, ymin:ymax, zmin:zmax) with steps (dx,dy,dz). All values are in cm."
34 <<
" If a single value is given for a range, symmetric boundaries are used"
40 std::string inFile = argv[1] ;
42 std::stringstream sstr ;
43 sstr << argv[2] <<
" " << argv[3] <<
" " << argv[4] <<
" " << argv[5] <<
" " << argv[6] <<
" " << argv[7] ;
45 std::string RangeX , RangeY , RangeZ;
48 sstr >> RangeX >> RangeY >> RangeZ >> dx >> dy >> dz;
50 size_t colon_posX = RangeX.find(
':');
51 size_t colon_posY = RangeY.find(
':');
52 size_t colon_posZ = RangeZ.find(
':');
54 float minX=0, maxX=0, minY=0, maxY=0, minZ=0, maxZ=0;
56 if( colon_posX == std::string::npos ) {
57 std::cout <<
"X Interval not specified as xmin:xmax" << std::endl
58 <<
" setting xmin = -xmax " << std::endl;
59 maxX = std::stof( RangeX );
63 minX = std::stof( RangeX.substr(0, colon_posX) );
64 maxX = std::stof( RangeX.substr(colon_posX+1) );
67 if( colon_posY == std::string::npos ) {
68 std::cout <<
"Y Interval not specified as ymin:ymax" << std::endl
69 <<
" setting ymin = -ymax " << std::endl;
70 maxY = std::stof( RangeY );
74 minY = std::stof( RangeY.substr(0, colon_posY) );
75 maxY = std::stof( RangeY.substr(colon_posY+1) );
78 if( colon_posZ == std::string::npos ) {
79 std::cout <<
"Z Interval not specified as zmin:zmax" << std::endl
80 <<
" setting zmin = -zmax " << std::endl;
81 maxZ = std::stof( RangeZ );
85 minZ = std::stof( RangeZ.substr(0, colon_posZ) );
86 maxZ = std::stof( RangeZ.substr(colon_posZ+1) );
99 Detector& description = Detector::getInstance();
102 printf(
"#######################################################################################################\n");
103 printf(
" x[cm] y[cm] z[cm] Bx[Tesla] By[Tesla] Bz[Tesla] \n");
105 for(
float x = minX ; x <= maxX ; x += dx ){
106 for(
float y = minY ; y <= maxY ; y += dy ){
107 for(
float z = minZ ; z <= maxZ ; z += dz ){
109 double posV[3] = { x, y, z } ;
113 printf(
" %+15.8e %+15.8e %+15.8e %+15.8e %+15.8e %+15.8e \n",
114 posV[0]/dd4hep::cm, posV[1]/dd4hep::cm, posV[2]/dd4hep::cm,
115 bfieldV[0]/dd4hep::tesla , bfieldV[1]/dd4hep::tesla, bfieldV[2]/dd4hep::tesla ) ;
120 printf(
"#######################################################################################################\n");
126 int main(
int argc,
char** argv ){
128 return invoke_dump_B_field(argc,argv);
131 std::cout <<
"Got uncaught exception: " << e.what() << std::endl;
134 std::cout <<
"Got UNKNOWN uncaught exception." << std::endl;