diff --git a/mcxtrace-comps/examples/NBI/NBI_Lab_TOMO/NBI_Lab_TOMO.instr b/mcxtrace-comps/examples/NBI/NBI_Lab_TOMO/NBI_Lab_TOMO.instr index d39785c81..79dc1a537 100644 --- a/mcxtrace-comps/examples/NBI/NBI_Lab_TOMO/NBI_Lab_TOMO.instr +++ b/mcxtrace-comps/examples/NBI/NBI_Lab_TOMO/NBI_Lab_TOMO.instr @@ -101,7 +101,7 @@ ROTATED (0,Omega,0) RELATIVE Origin //chess king COMPONENT king =Filter( - material_datafile="Glass.dat", geometry="king.off",xwidth=1.5e-2,yheight=1.5e-2,zdepth=1.5e-2) + material_datafile="Glass.dat", mu_col=1, geometry="king.off",xwidth=1.5e-2,yheight=1.5e-2,zdepth=1.5e-2) AT(0,0,0) RELATIVE sample_mnt ROTATED (rx,ry,rz) RELATIVE sample_mnt @@ -111,7 +111,7 @@ COMPONENT e_mon1 = E_monitor( AT(0,0,d_sample_det-15e-3) RELATIVE sample_mnt COMPONENT filter_air=Filter( - material_datafile="FilterAir_1mm.dat",xwidth=detw,yheight=deth,zdepth=1e-3*10) + material_datafile="FilterAir_1mm.dat", mu_col=1,xwidth=detw,yheight=deth,zdepth=1e-3*10) AT(0,0,d_sample_det-20e-3+1e-3-0.2) RELATIVE sample_mnt COMPONENT filter_Al=Filter( diff --git a/mcxtrace-comps/examples/Tests_optics/Test_Filter/Test_Filter.instr b/mcxtrace-comps/examples/Tests_optics/Test_Filter/Test_Filter.instr index 2b5be7003..c6b856257 100644 --- a/mcxtrace-comps/examples/Tests_optics/Test_Filter/Test_Filter.instr +++ b/mcxtrace-comps/examples/Tests_optics/Test_Filter/Test_Filter.instr @@ -16,24 +16,25 @@ * Test instrument for checking the Filter.comp component * * %Parameters -* filter_mat: [] Chemical symbol of the filter material -* thickness: [m] thickness of the filter block -* L0: [AA] centre wavlength of the source -* DL: [AA] half width of the (uniform) wavelength distribution -* F2: [1] add a 2nd filter component further away +* filter_mat: [] Chemical symbol / datafile of the filter material +* thickness: [m] thickness of the filter block +* L0: [AA] centre wavlength of the source +* DL: [AA] half width of the (uniform) wavelength distribution +* F2: [1] add a 2nd filter component further away +* mu_col: [idx] Index of mu-column (from 0) in datafile (required for some inputs). * * %Example: DL=4.9 L0=5 filter_mat="Si.txt" Detector: l_mon1_I=1.31502e-07 * %Example: DL=4.9 L0=5 filter_mat="Rh.txt" Detector: l_mon1_I=4.04921e-29 * %Example: -n5e6 DL=4.9 L0=5 filter_mat="Ti.txt" F2=1 Detector: l_mon1_I=1.14111e-08 * %Example: DL=4.9 L0=5 filter_mat="Al.txt" Detector: l_mon1_I=1.04427e-07 -* %Example: DL=4.9 L0=5 filter_mat="Glass.dat" Detector: l_mon1_I=1.645e-06 +* %Example: DL=4.9 L0=5 filter_mat="Glass.dat" mu_col=1 Detector: l_mon1_I=1.645e-06 * %Example: DL=4.9 L0=5 filter_mat="Be.txt" Detector: l_mon1_I=0.000412661 -* %Example: DL=4.9 L0=5 filter_mat="FilterAir_1mm.dat" Detector: l_mon1_I=4.96145e-05 +* %Example: DL=4.9 L0=5 filter_mat="FilterAir_1mm.dat" mu_col=1 Detector: l_mon1_I=4.96145e-05 * * %End *******************************************************************************/ -DEFINE INSTRUMENT Test_Filter(string filter_mat="Rh.txt",thickness=100e-6,L0=1,DL=0.1, F2=0) +DEFINE INSTRUMENT Test_Filter(string filter_mat="Rh.txt",thickness=100e-6,L0=1,DL=0.1, F2=0, int mu_col=-1) DECLARE %{ @@ -61,12 +62,12 @@ COMPONENT l_mon0 = L_monitor( AT (0,0,1e-6) RELATIVE Source COMPONENT filter = Filter( - material_datafile=filter_mat, xwidth=0.1,yheight=0.1,zdepth=thickness + material_datafile=filter_mat, mu_col=mu_col, xwidth=0.1, yheight=0.1, zdepth=thickness ) AT (0,0,0.5) RELATIVE Source COMPONENT filter2 = Filter( - material_datafile=filter_mat,xwidth=0.1, yheight=0.1, zdepth=thickness + material_datafile=filter_mat, mu_col=mu_col, xwidth=0.1, yheight=0.1, zdepth=thickness ) WHEN(F2) AT (0,0,0.5+thickness+1e-3) RELATIVE Source diff --git a/mcxtrace-comps/optics/Filter.comp b/mcxtrace-comps/optics/Filter.comp index be8e6e5c9..e18918147 100644 --- a/mcxtrace-comps/optics/Filter.comp +++ b/mcxtrace-comps/optics/Filter.comp @@ -42,26 +42,22 @@ * material_datafile: [str] File where the material parameters for the filter may be found. Format is similar to what may be found off the NIST website. [Be.txt] * geometry: [str] File containing the polygon definition of a general shape object. When xwidth is also given, the object is rescaled accordingly (OFF/PLY) * fixed_delta:[0/1] Use a fixed delta to compute refraction - useful for debugging. -* refraction: [0/1] If nonzero, refraction is enabled. (Only functional for box-geometery.) +* mu_col: [idx] Column index to pick up absorption length mu, counted from 0. Use with non-standard input file, e.g. 2-3 column files. -1 means attempt autodetect. +* refraction: [0/1] If nonzero, refraction is enabled. (Only functional for basic geometries, does not yet work for OFF) * * %Link -* Meshlab https://www.meshlab.net/ -* %Link -* Geomview and Object File Format (OFF) -* %Link -* Java version of Geomview (display only) jroff.jar -* %Link -* qhull -* %Linkink -* Powercrust https://www.cs.ucdavis.edu/~amenta/powercrust.html -* %Link -* material datafile obtained from http://physics.nist.gov/cgi-bin/ffast/ffast.pl +* Meshlab - viewer for OFF files +* Geomview and Object File Format (OFF) - OFF file definition and examples +* jroff.jar - Java version of Geomview (display only) +* Qhull - for calculating a convex hull from points. +* Powercrust - for reconstructing a solid geometry from a point cloud. +* Most material datafile inpus may obtained from NIST FFast * %End *******************************************************************************/ DEFINE COMPONENT Filter SETTING PARAMETERS (refraction=0,fixed_delta=0,string material_datafile="Be.txt", - string geometry=0,xwidth=0,yheight=0,zdepth=0,radius=0) + string geometry=0,xwidth=0,yheight=0,zdepth=0,radius=0, int mu_col=-1) /* X-ray parameters: (x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p) */ @@ -163,23 +159,28 @@ INITIALIZE fprintf (stderr, "Warning(%s): %s not found in header of %s, set to 1\n", NAME_CURRENT_COMP, "rho", material_datafile); rho = 1; } - if (table.columns == 2) { - /*If we are using a 2 column format assume only attenuation and read from last column. - I.e. set the delta prefactor to 0*/ - mu_c = 1; - delta_prefactor = 0; - } else if (table.columns == 3) { - /*If we are using a 3 column format assume only attenuation and read from second column. - I.e. set the delta prefactor to 0*/ - mu_c = 1; - delta_prefactor = 0; - } else if (table.columns == 4) { - /*If we are using a 4 column format assume only attenuation and read from last column. - I.e. set the delta prefactor to 0*/ - mu_c = 3; - delta_prefactor = 0; - } else { - mu_c = 5; + if (table.columns < 6) { + // "Few or many" columns, use mu_col to pinpoint mu column location + if (mu_col == -1 || mu_col >= table.columns) { + fprintf (stderr, + "Error(%s): Found %i columns in %s. Did NOT detect known NIST file format. Please give a relevant mu_col value to define the mu-column! Exit!\n", + NAME_CURRENT_COMP, table.columns, material_datafile); + exit (-1); + } else { + mu_c = mu_col; + delta_prefactor = 0; + } + } else if (table.columns >= 6) { + // ... fingers crossed this is "Legacy" NIST format + if (mu_col == -1) { + mu_c = 5; + } else if (mu_col < table.columns) { + mu_c = mu_col; + } else { + fprintf (stderr, "Error(%s): Found %i columns in %s and you gave a mu_col of %i. Please correct. Exit!\n", NAME_CURRENT_COMP, table.columns, + material_datafile, mu_col); + exit (-1); + } delta_prefactor = NA * (rho * 1e-24) / Ar * 2.0 * M_PI * RE; } if (10 * (double)mcget_ncount () > (table.max_x - table.min_x) / (table.step_x)) { @@ -191,7 +192,7 @@ INITIALIZE if (shape != CUBE) { if (refraction) { fprintf (stderr, "Warning(%s): refraction=1 not supported with chosen geometry\n", NAME_CURRENT_COMP); - refraction=0; + refraction = 0; } } %}