BLCMDprintfield Class Reference

Inheritance diagram for BLCMDprintfield:

BLCommand BLCallback

List of all members.


Detailed Description

class BLCMDprintfield is a command to print E or B fields

If type=print (the default), prints a 2-d array to stdout.

If type=grid or type=cylinder, BLCMDprintfield will write to a file, in the format of BLFieldMap. This can be used to combine multiple overlapping magnets/solenoids into a single map, which will be more efficient in particle tracking. All nonzero field components are included.

Public Member Functions

 BLCMDprintfield ()
 ~BLCMDprintfield ()
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
void callback (int type)
 callback() from BLCallback.

Private Member Functions

void do_print ()
void do_points ()
void do_grid ()
void do_cylinder ()

Private Attributes

G4String type
G4int exit
G4String field
G4String layout
G4double x
G4double y
G4double z
G4double t
G4double drow
G4double dcol
G4int nrow
G4int ncol
G4String file
G4String comment
G4double X0
G4double Y0
G4double Z0
G4int nX
G4int nY
G4int nZ
G4double dX
G4double dY
G4double dZ
G4int nR
G4double dR


Constructor & Destructor Documentation

BLCMDprintfield::BLCMDprintfield (  ) 

References BLCMDTYPE_DATA, dcol, dR, drow, dX, dY, dZ, exit, field, layout, ncol, nR, nrow, nX, nY, nZ, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), t, type, x, X0, y, Y0, z, and Z0.

Referenced by command().

00112 {
00113         registerCommand(BLCMDTYPE_DATA);
00114         setSynopsis("Prints E or B fields, or writes FieldMap file.");
00115         setDescription("Prints the value of the electromagnetic field components.\n"
00116                 "For type=print, prints one component of the field\n"
00117                 "in a 2-d table.\n"
00118                 "Any coordinate plane can be printed (XY ... ZT).\n"
00119                 "For type=grid or type=cylinder, writes a file in fieldmap\n"
00120                 "format.\n"
00121                 "Global coordinates are used.\n"
00122                 "Units are Tesla for B and MV/meter for E.\n"
00123                 "\nNOTE: This command cannot handle time dependency in the "
00124                 "output BLFieldMap file, but can in the printout.\n\n"
00125                 "Note: if you want to plot field vs position or time, the "
00126                 "'fieldntuple' command is probably better, as it is not "
00127                 "limited to the 2-d paper, is easier to use, and lets "
00128                 "you use existing NTuple plotting tools. If you just "
00129                 "want to test a few points, the 'probefield' command lets "
00130                 "you do that interactively.");
00131 
00132         type = "print";
00133         exit = 0;
00134         field = "By";
00135         layout = "zx";
00136         x = y = z = t = 0.0;
00137         drow = dcol = 1.0*cm;
00138         nrow = ncol = 1;
00139         X0 = Y0 = Z0 = 0.0;
00140         nX = nY = nZ = 0;
00141         dX = dY = dZ = 0.0;
00142         nR = 0;
00143         dR = 0.0;
00144 }

BLCMDprintfield::~BLCMDprintfield (  )  [inline]

00078 { }


Member Function Documentation

G4String BLCMDprintfield::commandName (  )  [inline, virtual]

Implements BLCommand.

00080 { return "printfield"; }

int BLCMDprintfield::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

Implements BLCommand.

References BLCMDprintfield(), BLManager::getObject(), BLCommand::handleNamedArgs(), BLCommand::printError(), and BLManager::registerCallback().

00147 {
00148         if(argv.size() > 0) {
00149                 printError("printfield: Invalid argument\n");
00150                 return -1;
00151         }
00152 
00153         BLCMDprintfield *p = new BLCMDprintfield(defaultPrintField);
00154         int retval = p->handleNamedArgs(namedArgs);
00155 
00156         // register the object to be called back to do its print.
00157         // 1 => after reference particle is tracked.
00158         BLManager::getObject()->registerCallback(p,1);
00159 
00160         return retval;
00161 }

void BLCMDprintfield::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argMode, BLCommand::argString(), comment, dcol, dR, drow, dX, dY, dZ, exit, field, file, BLCommand::HELP, layout, ncol, nR, nrow, nX, nY, nZ, t, type, x, X0, y, Y0, z, and Z0.

00164 {
00165         argString(type,"type","print, grid, or cylinder.");
00166         argInt(exit,"exit","Set nonzero to exit after printing field");
00167 
00168         if(argMode == HELP) printf("             Arguments for type=print:\n");
00169         argString(field,"field","The field to print (Bx,By,Bz,Ex,Ey,Ez,Btot,Etot).");
00170         argString(layout,"layout","Layout (RowCol) - 2 chars 'AB' each of {xyzt}.");
00171         argDouble(x,"x","The starting value of x (mm).");
00172         argDouble(y,"y","The starting value of y (mm).");
00173         argDouble(z,"z","The starting value of z (mm).");
00174         argDouble(t,"t","The starting value of time (ns).");
00175         argDouble(drow,"drow","The incr between points in each row (mm|ns).");
00176         argDouble(dcol,"dcol","The incr between points in each column (mm|ns).");
00177         argInt(nrow,"nrow","The number of rows.");
00178         argInt(ncol,"ncol","The number of columns.");
00179 
00180         if(argMode == HELP) printf("             Arguments for type=grid:\n");
00181         argString(file,"file","Filename to write fieldmap to.");
00182         argString(comment,"comment","Comment for fieldmap.");
00183         argDouble(X0,"X0","Initial value of X (mm, default=0).");
00184         argDouble(Y0,"Y0","Initial value of Y (mm, default=0).");
00185         argDouble(Z0,"Z0","Initial value of Z (mm, default=0).");
00186         argInt(nX,"nX","Number of points in X.");
00187         argInt(nY,"nY","Number of points in Y.");
00188         argInt(nZ,"nZ","Number of points in Z.");
00189         argDouble(dX,"dX","Interval in X between points (mm).");
00190         argDouble(dY,"dY","Interval in Y between points (mm).");
00191         argDouble(dZ,"dZ","Interval in Z between points (mm).");
00192 
00193         if(argMode == HELP) printf("             Arguments for type=cylinder:\n");
00194         argString(file,"file","Filename to write fieldmap to.");
00195         argString(comment,"comment","Comment for fieldmap.");
00196         argDouble(Z0,"Z0","Initial value of Z (mm, default=0).");
00197         argInt(nR,"nR","Number of points in R.");
00198         argDouble(dR,"dR","Interval in R between points (mm).");
00199         argInt(nZ,"nZ","Number of points in Z.");
00200         argDouble(dZ,"dZ","Interval in Z between points (mm).");
00201 }

void BLCMDprintfield::callback ( int  type  )  [virtual]

callback() from BLCallback.

Reimplemented from BLCallback.

References do_cylinder(), do_grid(), do_points(), do_print(), exit, g4bl_exit(), BLCommand::printError(), Printf(), and type.

00204 {
00205         if(type == "print")
00206                 do_print();
00207         else if(type == "points")
00208                 do_points();
00209         else if(type == "grid")
00210                 do_grid();
00211         else if(type == "cylinder")
00212                 do_cylinder();
00213         else
00214                 printError("printfield: invalid type '%s'\n",type.c_str());
00215 
00216         if(exit) {
00217                 Printf("BLCMDprintfield: exit\n");
00218                 G4cout.flush();
00219                 g4bl_exit(0);
00220         }
00221 }

void BLCMDprintfield::do_print (  )  [private]

References dcol, drow, field, BLGlobalField::GetFieldValue(), BLGlobalField::getObject(), index, layout, ncol, nrow, BLCommand::printError(), Printf(), t, x, y, and z.

Referenced by callback().

00224 {
00225         int index=-1; 
00226         if(field == "Bx") index = 0;
00227         else if(field == "By") index = 1;
00228         else if(field == "Bz") index = 2;
00229         else if(field == "Ex") index = 3;
00230         else if(field == "Ey") index = 4;
00231         else if(field == "Ez") index = 5;
00232         else if(field == "Btot") index = 6;
00233         else if(field == "Etot") index = 7;
00234         else printError("printfield: invalid field '%s'\n",field.c_str());
00235 
00236         int irow=-1,icol=-1;
00237         char rowname, colname;
00238         rowname = layout.c_str()[0];
00239         colname = layout.c_str()[1];
00240         switch(rowname) {
00241         case 'x': case 'X':     irow = 0;       break;
00242         case 'y': case 'Y':     irow = 1;       break;
00243         case 'z': case 'Z':     irow = 2;       break;
00244         case 't': case 'T':     irow = 3;       break;
00245         }
00246         switch(colname) {
00247         case 'x': case 'X':     icol = 0;       break;
00248         case 'y': case 'Y':     icol = 1;       break;
00249         case 'z': case 'Z':     icol = 2;       break;
00250         case 't': case 'T':     icol = 3;       break;
00251         }
00252 
00253         if(index < 0 || irow < 0 || icol < 0) {
00254                 printError("printfield: Invalid field name or layout\n");
00255                 return;
00256         }
00257 
00258         BLGlobalField *gf = BLGlobalField::getObject();
00259 
00260         G4double pos[4];
00261         pos[0]=x, pos[1]=y, pos[2]=z, pos[3]=t;
00262         G4double col0 = pos[icol];
00263 
00264         Printf("\n%s (%s):  ",field.c_str(),(index<=2||index==6 ? "Tesla" : "MV/meter"));
00265         G4double unit = (index<=2||index==6 ? tesla : megavolt/meter);
00266         for(int i=0; i<4; ++i) {
00267                 if(i == irow || i == icol) continue;
00268                 Printf("%c=%.3f ","xyzt"[i],pos[i]);
00269         }
00270         Printf("\n           ");
00271         for(int col=0; col<ncol; ++col) {
00272                 char tmp[16];
00273                 sprintf(tmp,"%c=%.3f",colname,pos[icol]);
00274                 Printf("%11.11s",tmp);
00275                 pos[icol] += dcol;
00276         }
00277         Printf("\n");
00278         for(int row=0; row<nrow; ++row) {
00279                 Printf("%c=%-8.3f ",rowname,pos[irow]);
00280                 pos[icol] = col0;
00281                 for(int col=0; col<ncol; ++col) {
00282                         G4double field[6];
00283                         gf->GetFieldValue(pos,field);
00284                         if(index == 6)
00285                                 Printf(" %10.4f",sqrt(field[0]*field[0]+field[1]*field[1]+field[2]*field[2])/unit);
00286                         else if(index == 7)
00287                                 Printf(" %10.4f",sqrt(field[3]*field[3]+field[4]*field[4]+field[5]*field[5])/unit);
00288                         else
00289                                 Printf(" %10.4f",field[index]/unit);
00290                         pos[icol] += dcol;
00291                 }
00292                 Printf("\n");
00293                 pos[irow] += drow;
00294         }
00295 
00296         Printf("\n");
00297 
00298         G4cout.flush();
00299 }

void BLCMDprintfield::do_points (  )  [private]

References dcol, drow, exit, field, g4bl_exit(), BLGlobalField::GetFieldValue(), BLGlobalField::getObject(), layout, ncol, nrow, BLCommand::printError(), Printf(), t, x, y, and z.

Referenced by callback().

00302 {
00303         int irow=-1,icol=-1;
00304         char rowname, colname;
00305         rowname = layout.c_str()[0];
00306         colname = layout.c_str()[1];
00307         switch(rowname) {
00308         case 'x': case 'X':     irow = 0;       break;
00309         case 'y': case 'Y':     irow = 1;       break;
00310         case 'z': case 'Z':     irow = 2;       break;
00311         case 't': case 'T':     irow = 3;       break;
00312         }
00313         switch(colname) {
00314         case 'x': case 'X':     icol = 0;       break;
00315         case 'y': case 'Y':     icol = 1;       break;
00316         case 'z': case 'Z':     icol = 2;       break;
00317         case 't': case 'T':     icol = 3;       break;
00318         }
00319 
00320         if(irow < 0 || icol < 0) {
00321                 printError("printfield: Invalid field name or layout\n");
00322                 return;
00323         }
00324 
00325         BLGlobalField *gf = BLGlobalField::getObject();
00326 
00327         G4double pos[4];
00328         pos[0]=x, pos[1]=y, pos[2]=z, pos[3]=t;
00329         G4double col0 = pos[icol];
00330 
00331         Printf("# B field: x y z Bx By Bz\n");
00332         for(int row=0; row<nrow; ++row) {
00333                 pos[icol] = col0;
00334                 for(int col=0; col<ncol; ++col) {
00335                         G4double field[6];
00336                         gf->GetFieldValue(pos,field);
00337                         Printf("%.1f %.1f %.1f %.4f %.4f %.4f\n",
00338                                 pos[0],pos[1],pos[2],
00339                                 field[0]/tesla,field[1]/tesla,field[2]/tesla);
00340                         pos[icol] += dcol;
00341                 }
00342                 pos[irow] += drow;
00343         }
00344 
00345         if(exit) {
00346                 Printf("printfield: exit\n");
00347                 extern void g4bl_exit(int);
00348                 g4bl_exit(0);
00349         }
00350 }

void BLCMDprintfield::do_grid (  )  [private]

References comment, BLFieldMap::createGridMap(), dX, dY, dZ, file, BLGlobalField::getObject(), nX, nY, nZ, BLCommand::printError(), BLFieldMap::writeFile(), X0, Y0, and Z0.

Referenced by callback().

00353 {
00354         if(file == "" || nX <= 0 || nY <= 0 || nZ <= 0 || 
00355            dX <= 0.0 || dY <= 0.0 || dZ <= 0.0) {
00356                 printError("printfield type=grid: invalid arguments\n");
00357                 return;
00358         }
00359         BLFieldMap fm;
00360         fm.createGridMap(X0,Y0,Z0,dX,dY,dZ,nX,nY,nZ,BLGlobalField::getObject());
00361         fm.writeFile(file, comment);
00362 }

void BLCMDprintfield::do_cylinder (  )  [private]

References comment, BLFieldMap::createCylinderMap(), dR, dZ, file, BLGlobalField::getObject(), nR, nZ, BLCommand::printError(), BLFieldMap::writeFile(), and Z0.

Referenced by callback().

00365 {
00366         if(file == "" || nR <= 0 || nZ <= 0 || dR <= 0.0) {
00367                 printError("printfield type=cylinder: invalid arguments\n");
00368                 return;
00369         }
00370         BLFieldMap fm;
00371         fm.createCylinderMap(Z0,dR,dZ,nR,nZ, BLGlobalField::getObject());
00372         fm.writeFile(file, comment);
00373 }


Member Data Documentation

G4String BLCMDprintfield::type [private]

Reimplemented from BLCommand.

Referenced by BLCMDprintfield(), callback(), and defineNamedArgs().

G4int BLCMDprintfield::exit [private]

G4String BLCMDprintfield::field [private]

G4String BLCMDprintfield::layout [private]

G4double BLCMDprintfield::x [private]

G4double BLCMDprintfield::y [private]

G4double BLCMDprintfield::z [private]

G4double BLCMDprintfield::t [private]

G4double BLCMDprintfield::drow [private]

G4double BLCMDprintfield::dcol [private]

G4int BLCMDprintfield::nrow [private]

G4int BLCMDprintfield::ncol [private]

G4String BLCMDprintfield::file [private]

G4String BLCMDprintfield::comment [private]

G4double BLCMDprintfield::X0 [private]

G4double BLCMDprintfield::Y0 [private]

G4double BLCMDprintfield::Z0 [private]

G4int BLCMDprintfield::nX [private]

G4int BLCMDprintfield::nY [private]

G4int BLCMDprintfield::nZ [private]

G4double BLCMDprintfield::dX [private]

G4double BLCMDprintfield::dY [private]

G4double BLCMDprintfield::dZ [private]

G4int BLCMDprintfield::nR [private]

G4double BLCMDprintfield::dR [private]


The documentation for this class was generated from the following file:
g4beamline