HOWTO Convert a B-field Map from Excel
Currently, the B-field maps are produced by Floyd Martin using Ansys and dumped into an Excel Spreadsheet file. This HOWTO describes how to convert one of these Excel files into a format that can be used by the reconstruction software and from there, into a ROOT file that can be used for plotting the field.
Location
The files are kept on the Hall-D group disk in a subdirectory of the <solenoid/MagneticFieldAnalysis/MagFieldPlots directory. The subdirectory is named based on the date the maps were produced. The Excel files and any ROOT files should be stored in these directories. The ASCII format currently used (indirectly) by the simulation/reconstruction should be kept in the calibration directory tree on the group disk. Specifically, calib/Magnets/Solenoid with names like solenoid_1500_20090312-2.
Converting from Excel to ASCII
At the time of this writing, the GlueX simulation and reconstruction software reads the magnetic field map in from an ASCII file in a table format. The first sheet of the Excel file contains the data you need to export. The following instructions work with Excel2008 on Mac OS X but should hopefully be a guide for other platforms as well.
- Open the Excel file and make sure sheet 1 is selected
- Delete the "Total Magnetic Flux" column (column "D").
- Save As... "Windows Formatted Text (.txt)". Name the file using a syntax like solenoid_1500_20090312-2 where the "1500" indicates the current and the "20090312-2" indicates the date and version taken from the Excel file name.
- Edit the saved ASCII file and comment out the header lines at the top using a "#" symbol as the first character on the line. The first several lines will already have # symbols so you only need to add them to the ones before the actual numbers. This includes commenting out the line with the column names.
- To make the file available for using by the Hall-D software (including the bfield2root program described below) move it over to the calib/Magnets/Solenoid directory on the halld group disk.
Creating a ROOT file
The bfield2root program can be used to create a ROOT file of the magnetic field map as is used by the simulation/reconstruction code. The ROOT file will contain a TTree with entries from several points in the map. It is important to note that the values going into the TTree come from interpolating the map whose grid is determined by the ASCII file. The bfield2root program has default settings to match the default grid of the ASCII files. If a map with different grid spacing is generated then the bfield2root program will still work but one should be aware that the resulting ROOT file will contain interpolated values.
Another "gotcha" is that the origin of the lab coordinate system used by the original field maps is not in the same location as is currently used. The TOSCA generated maps have the origin close to the center of the target, 26 inches (=66.04 cm) offset from the modern coordinate system. As of svn revision 5316 on June 22, 2009, the reconstruction code no longer assumes this offset is there and so one must correct for it when using a TOSCA map. In the mean time, the bfield2root program must be told about this offset via a command line parameter (see below).
The following instructions are for doing this on the JLab CUE system (e.g. ifarml3). However, one can of course do this on another system where the Hall-D software is compiled and the desired map is located in the directory indicated by the JANA_CALIB_URL environment variable (note: this is set in step 1 below for the CUE).
- Make sure bfield2root is in your path. If it's not, then source a setup script for a pre-built Hall-D software release.
- e.g. source /group/halld/Software/builds/release-2009-05-27/setenv.csh
- Run bfield2root specifying the specific map
- e.g. bfield2root -PBFIELD_MAP=Magnets/Solenoid/solenoid_1500_20090312-2
- Run bfield2root using an older, TOSCA generated map
- e.g. bfield2root -PBFIELD_MAP=Magnets/Solenoid/solenoid_1500 -Z0 -66.04