Abstract
This contribution describes the computational methodology behind an optimization procedure for a scattered beam collimator. The workflow includes producing a file that can be manufactured via additive methods. A conical collimator, optimized for neutron diffraction experiments in a high pressure clamp cell, is presented as an example. In such a case the scattering from the sample is much smaller than that of the pressure cell. Monte Carlo Ray tracing in MCViNE was used to model scattering from a Si powder sample and the cell. A collimator was inserted into the simulation and the number and size of channels were optimized to maximize the rejection of the parasitic signal coming from the complex sample environment. Constraints, provided by the additive manufacturing process as well as a specific neutron diffractometer, were also included in the optimization. The source code and the tutorials are available in c3dp (Islam (2019)).
Introduction
Scattered beam collimation is an effective way to remove scattering from materials in the beam (e.g. sample environment equipment) that are not at the sample position [6]. Typically a collimator is designed for an instrument with the collimation chosen to work well for most standard equipment [10,18,29,34]. Once a collimator’s scientific specifications are chosen the device goes to engineering design and manufacture. However, background rejection, more tailored to a specific experiment, can be achieved by optimizing a collimator to a specific sample environment. For this to be practical, the effort from experiment design through to a usable device must be reduced. This contribution summarizes a way to reduce this effort.
Here we show a new avenue for custom-made collimators to overcome this challenge. Specifically, an automated work-flow has been developed to design a custom collimator, optimized for a given sample environment and manufacturing constraints. The end result is a file ready for 3D printing. To perform the optimization, the sample environment is included in a detailed model for a Monte Carlo ray tracing simulation of the instrument. A collimator is inserted into the beamline model and its parameters optimized to produce the best configuration for this application. Once the collimator has been optimized in the computer, the computer model is transformed directly into an .stl file for production via additive manufacturing.
To demonstrate this technique, the optimization of a collimator for a clamp cell [32] on the SNAP high pressure diffractometer [5] of the Spallation Neutron Source [27] is chosen. SNAP’s key advantages lie in the fact that the high flux beam is focused into a very small area, the detector positions can be adjusted, and its sample position is extremely accessible thus accommodating to complex sample environments. High pressure environments are ideal to demonstrate such collimation as they contain pressure cell material in the beam upstream of the sample and in the scattered beam between the sample and detectors. Particularly, the pressure cell, consists of more material than sample and completely surrounds the sample. Therefore, no unobstructed view of the sample is inherently possible. Hence every measurement is contaminated by scattered neutrons from the sample environment. Our approach to custom collimation modelling places the device much closer to the sample than one designed around the instrument alone, allowing for more effective collimation. Section 2 describes the details of the simulation.
The optimization parameters include number of channels, channel-size and materials of the collimator. An optimized collimator will maximize the sample signal to background ratio without sacrificing too much neutron flux. Thus, the optimization must strike a balance between improving relative sample signals and minimizing the loss of intensities, while staying within the constraints placed upon it by the 3D printing techniques and the neutron instrument. In Section 3, the design and optimization of the conic divergent collimator will be discussed, including the mounting facility of the collimator. Such an optimization workflow is composed of many parts that are summarized in Fig. 1.

Collimator optimization workflow.
Furthermore an intuitive understanding of the collimator operation can be obtained through examining the gauge volume of the sample observed by the detector via the collimator. Such a calculation and our specific implementation will be described in Section 4.
As with any manufacturing process, additive manufacturing provides unique constraints that must be considered in the design of a device. Section 5 describes the constraints and printing processes.
Finally initial comparisons between measurements and simulations with the collimator are shown in Section 6. These demonstrate the effectiveness of the collimator in reducing background scattering from complex sample environment.
As mentioned above, the optimization workflow uses simulations of a clamp cell on SNAP [5], a medium-resolution diffractometer optimized for small samples such as those in high pressure environments. A schematic of the SNAP instrument can be found in Fig. 2. The choppers were phased to provide a center wavelength of 2.1 Å with a bandwidth of 0.5–3.54 Å. The beamline is typically operated with its focusing guide in place to focus the beam into a
Monte Carlo neutron ray tracing simulations using MCViNE [22,24] and McStas [36] are performed to estimate the possible improvement in sample signal with an optimized collimator. All parameters (placement of components, chopper disc opening angles, etc.) were taken from engineering drawings of the installed components.

Simulated SNAP layout with sample and detector positions used in the calculation.
The statistics presented here correspond to
The incident beam on SNAP is modelled using McStas. As a source we used the component
A focusing guide, with the general formula
MCViNE is then used to model the neutron propagation from the sample to the detectors. The McStas .dat file format, saved in the previous step, is fed into the mcstas2mcvine utility function, included in MCViNE, to convert the neutrons exiting the guide for the subsequent MCViNE simulation.
One advantage of using MCViNE is that it can simulate sample assemblies of multiple materials and complex shapes [22,24,30]. MCViNE supports Constructive Solid Geometry (CSG) [19] to compose complex solid shapes such as the sample assembly. Specifically it uses logical operations on a limited set of simple solid shapes to create complex ones.
Here we used the constructive solid geometry available in MCViNE [17] to model such a complex shape of the collimator and the sample environment. Over the past decade MCViNE development has moved in a direction focusing on complex sample kernels, mostly for inelastic but also some elastic processes, and building the model of the detector from its definition in the Mantid [1] reduction software. In this way, it is optimized for use in analysis of neutron scattering results on existing instruments as is demonstrated in several publications, [9,22–24,28,30,33,37]. In a complimentary manner McStas [36] is a well documented code that runs extremely quickly and allows for quick changes of detector configurations [36]. These features are critical for fast optimization during neutron instrument design, a purpose for which this code has excelled for the past decade [36]. Recently, the
Here we describe step by step how the geometry of our clamp cell was modeled. Our cell design uses a CuBe insert pressed into an Al sleeve for increased stability [32]. Consequently both of these components are modeled in the simulations. In a measurement, the sample is loaded into a very thin Teflon tube, here only the sample (Si powder) was modeled. Absorption, transmission and scattering probabilities were considered whenever a neutron path intersected a component in the sample environment. The components of the clamp cell are differentiated in the simulation based on their material composition. All of them are cylindrical in shape and share the same axis as shown in Fig. 3(A). Two hollow cylinders are created for the sleeve and the insert and one solid cylinder is created for the sample. The subtraction operation is performed to create hollow cylinders. The geometry of the collimator is also modeled using CSG. The collimator is conical in shape with tightly spaced neutron absorbing blades which are stacked radially in both the vertical and horizontal directions to provide transmitting channels as shown in Fig. 3(B) and (C). The blade surfaces were simulated by rectangular block segments of constant thickness. Here the blades are repeated in both the vertical and horizontal directions which produces a crossed-blade pattern; in other words a grid. Each blade is pitched to focus to where the beam intersects with the center of the sample. These blades define channels of constant angular size along which neutrons may pass. More details of the geometry configuration of collimator is discussed in Section 4.

A). Simulated clamp cells. B) and C). Simulated collimator for clamp cell.
The Python geometry script exports an XML file. The XML file is used for multiple purposes as summarized in Fig. 4. First, it is used by the MCViNE simulation to control the ray tracing through the collimator and sample. Second the SCADGen module of MCViNE uses it to convert to a .scad file. Third it is used in the gauge volume calculation. Openscad [35] then can use this .scad file for visualizing the components or conversion to additive manufacturing data formats; specifically .stl, a standard format used for 3D printing.

Flowchart showing the uses of .xml file which contains the geometry of optimized collimator.
Unit cell structure
After the modeling of clamp cell geometry, the unit cell of the scatterer and diffraction scattering kernels are modeled. Table 1 [32] lists the scatterer information. All of them together are included in another XML file called the sample assembly file. The neutrons emitted from the guide, that are saved in the MCViNE .dat file, are fed into the sample assembly and the scattered neutrons are saved. By saving the scattered neutrons, the collimator can be optimized without having to rerun the full simulation. This makes the code more efficient. The scattered neutrons from the sample assembly are fed into the collimator and the neutrons that pass through the collimator are sent to the virtual detector system for reduction and analysis. The interception of simulated scattered neutrons by the SNAP detector system, as defined by the Mantid instrument definition file, were simulated and NeXus files were generated. The NeXus [17] files were reduced using Mantid [1] to obtain the diffraction pattern (I(d)). Similar to the clamp cell, there is another .XML file that defines the material in the collimator. These can be easily swapped so a collimator with either absorbing
As mentioned in the introduction, Fig. 1 summarizes the workflow used to optimize a collimator. In this example here, first the incident beam to sample for SNAP is modeled using McStas [36]. Next, the neutron interaction with the sample assembly, composed of the pressure cell and the sample, is modeled with MCViNE [22]. In the third step, the collimator for the scattered neutrons from sample assembly is modeled using MCViNE. Next, a comparison to the optimization metric, to be described shortly, is performed. If the optimum performance is not achieved, the neutrons coming from the collimator are saved. In the fifth step, data is reduced. The details of the simulation and reduction steps are described in Section 2. In the sixth step a differential evolution (DE) algorithm from the SciPy [15] library was used to optimize the collimator geometry with the objective of minimizing the integrated cell peaks to integrated sample peaks ratio. Once the optimized collimator geometry is determined, it is saved to an .xml file as the last step of the workflow. Further details about optimization are described below. The code used to perform the optimization is called c3dp [12].
The design of the conical collimator system used for this experiment is based on straightforward geometrical considerations, which we briefly discuss with the help of Fig. 5. A conical collimator can be described by 9 parameters: the length of the blades, (L); the horizontal acceptance angle, (
The collimator function analytically describes the acceptance angle as a function of detector area. However, the acceptance angle is limited to
In order to avoid cracking during the printing process, described below, a workable ratio of the channel gap to blade thickness has to be maintained. Specifically the minimum channel gap is ∼3 mm and the blade thickness is defined to be ∼1 mm. The channel shape is rectangular. These are constraints in the optimization loop.
The ratio of the channel length to its width or height is one of the key parameters determining the efficiency of the collimation. The larger the ratio is the better collimation can be achieved with a given structure (providing the neutron absorption cross section is sufficient). Thus the shorter the collimator, the narrower the transmitting channels must be to obtain the required performance. In order to produce optimal collimation and transmission the number of the channels and their lengths will be varied to be considered as the optimized parameters within the printing constraint of channel size being 3 mm × 3 mm and blade size being 1 mm × 1 mm.
The goal of the optimization of the collimation system is to reduce the pressure cell diffraction peaks intensities, while minimizing the impact on the sample peaks. The function of the optimized collimator is to provide a large surface area over which to detect scattered neutrons from the sample, while restricting the gauge volume to minimize the cell to sample ratio.
In this work we did a preliminary look at the Dakota optimizer [3] and its multiple methods but the ease and simplicity of the DE algorithm in scipy was chosen as it was sufficient for our needs. The workflow presented here could be further optimized by evaluating the performance of other optimization algorithms such as genetic algorithms [11], Particle swarm optimization (PSO) [8] and multi-parents crossover (MPC) [4] algorithms to yield further complementary and more robust results. However, these studies are beyond the scope of the work presented here.
A differential evolution optimization engine was used. The population size and maximum number of iterations were selected to be 5 and 20, respectively. The computer’s clock is tapped to obtain 10 different seeds to initialize the random state of 10 independent optimization runs to achieve the final version of the optimized collimator. The average optimal length of the channel is 152 mm with 0.5 mm standard deviation and the optimal number of channels is 25 in all runs. Therefore, the solution from our optimization procedure is highly reproducible. The optimum length and number of the channels obtained are shown in Fig. 6.

Cross section of conical collimator geometry and parameters: height of the collimator downstream (H), width of the collimator downstream (W), height of the collimator upstream (h), width of the collimator upstream (w), length of the blade (L), horizontal acceptance angle (

Optimizing curve looking for min
The collimator has a truss support on the top and bottom to mount the collimator to the cell. The purpose of using a truss rather than a solid geometry is to provide stability while printing. Specifically once material is extruded, it immediately starts to cool. If the internal portion of the part cools at a different rate, the part will crack from differential thermal contraction. Therefore the structures must not be too thick. This constraint has been added to the optimization loop.
Gauge volume [7] is defined by the extent of the sample that can be seen on the detector through the collimator. Points at collimator center can be seen 100%. If we move from this point either vertically, horizontally perpendicular to the beam or along the beam, the gauge volume will decrease because the view through some of the collimator channels is obstructed. It has a Gaussian intensity profile in 3D.
A Python library was written to calculate the Gauge volume. To illustrate how the code works, consider the horizontal plane. If we move perpendicular to the beam, point

The left figure shows the 3D view of the collimator and the right figure shows the properties to calculate the gauge volume.
From the model of a single channel the views from all the channels on the detector through collimation can be calculated by summing the contributions from n (number of the channels) rotated sample points (observation points) in front of the single channel which requires a rotation of the observation points about the origin for each channel.
How much of the sample and sample assembly points (cell) that can be viewed on the detector through the collimation is determined by the length of the collimator (
In order to minimize the view of the sample assembly and maximize the view of the sample, the collimator and sample centers must be coincident.
This Python library includes ray tracing code to visualize the Gauge volume. This was achieved through calculation of the detector visibility at each point in the sample region using the vector analysis method described above. Figure 8A shows the calculated gauge volume profile chosen for the optimized collimator. Figures 8B and C show the effect of translations in the vertical to and along the beam directions, respectively. The vertical collimation was designed to be broader than the horizontal collimation to allow for the cylindrical shape of the sample which, as shown in Fig. 3, has a larger height than the diameter. This difference explains the elongated diamond shape. In Fig. 8 A, when the collimator center is aligned to the sample center, integrating the increment in detector view over the sample region shows that it rises to 95% of the collimated value horizontally and 86% vertically.
Figures 8(B) and (C) demonstrate the stringent positioning requirements for the collimator. For example in Fig. 8(C), the sample view was reduced to 6% when placing the collimator 40 mm away from the sample along the beam axis. Placing the collimator as close as possible to the sample keeps the view of the sample’s surroundings on the detector to a minimum, thus retaining the gauge volume shape. In other words, the gauge volume shape is blurred when the collimator is placed further away from the sample. The effect of moving the collimator along the vertical axis is also examined in 8(B). As the sample is cylindrical in shape and has significant height, vertical movement of the collimator on gauge volume has less impact. The absolute value of the sample view did not change but the position is offset along the vertical axis. As long as the vertical movement of the collimator is kept within the sample volume and incident beam volume, it should have a minimal impact on the sample signal to cell signal ratio.

The gauge volume profile in YZ plane of sample region (clampcell + Si) for different configuration of the collimator. The solid line defines the sample region. The intensity scale is relative to maximum gauge volume at the central position of the collimator A) collimator center coincide with sample center. B) Collimator shifted to upward vertical direction C) Collimator is moved away along X axis. Axis configurations are shown in Fig. 3(B).
As mentioned in Section 2, the output of the optimization is a .stl file that is used for producing the collimator via additive manufacturing methods. Each additive manufacturing process has its own specific constraints and parameters that need to be varied. We used the constraints for binder jet printing with
As mentioned above, the .stl file generated by the optimization software was imported into a printer specific version of slic3r [16]. Slic3r is an open source application for converting .stl files into instructions (called g-code) understandable by a 3D printer. Slic3r Prusa Edition version 1.31.6 was used to generate g-code.
Experimental results and discussion of the collimator performance
The performance of these collimators was then evaluated on SNAP. The instrument was configured identically to the simulation mentioned in Section 2. As in the model outlined above, the beamline was operated with its guide in place to increase flux on sample. The “west” detector was placed at 50° and standard chopper settings were used (60 Hz, 2.1 Å center wavelength).
A Si sample, which is a NIST powder diffraction standard, was loaded into a 4 mm diameter Teflon tube which in turn, was placed inside the cell.
The clamp cell was placed into the beamline on a sample post and aligned using standard SNAP procedures. The collimator was clamped directly to the cell to ensure its correct alignment with respect to the sample. The collimator was moved to 55° to directly correspond to the simulations detailed above. Additionally an incident beam collimator, made from hBN, was placed directly in front of the cell to give a beam size of 1 mm diameter.
Resulting diffraction data were reduced using standard SNAP procedures. Normalization was thereby performed using a calculated vanadium created via a Mantid algorithm built into the SNAP data analysis procedures. It should be noted that the collimator used here did not cover the entire “west” detector. Thus, the irrelevant portions of the detector were masked during the data reduction.
Figure 9 shows the diffraction pattern obtained from the clamp cell and the Si powder both with (red line) and without (black line) the collimator.
The effect of the collimator is very clear. For example, the Al 111 peak from the cell, centered at 2.3 Å, is significantly suppressed and the Si 311 peak, centered at 1.6 Å, is more easily observed when the collimator is in place.

Experimental diffraction pattern with and without collimator for clampcell + Si(sample).
Comparing the integrated intensities of the normalized sample and cell peaks in Fig. 9 shows a decrease of cell to signal ratio of ∼80% which is higher than expected from simulation, shown in Fig. 10. This is partly due to variation in the wall thickness that is a consequence of the manufacturing process. Comparing the cell peaks with and without collimator shows ∼60% reduction in the cell peaks when the collimator is used. In addition the cell peaks at longer wavelength are reduced significantly. Whereas comparing the sample peaks with and without collimator shows the reduction in sample peaks of ∼ 30%.

Simulated diffraction pattern of clampcell + Si with and without collimator.
Clearly, the simulated results agree very well with the experimental evaluation of the collimator. However, small discrepancies remain between the experimental and simulated results, as shown in Fig. 9 and in Fig. 10. We have identified the possible major reasons for these discrepancies as imperfections arising from the manufacturing process of the collimator, misalignment of sample and collimator and materials differences (preferred orientation, texture, precipitates) that are not accounted for in the simulation. Of these three only the materials differences could potentially cause the optimization result to differ from the experimental configuration. In future work we will investigate a more detailed model of the phases of the CuBe cell and may benefit from incorporating the texture models from McStas [20,21] to further mitigate these concerns.
The imperfections from the manufacturing process are expected to be random. Therefore though they may affect the observed peak shape, thus broadening or sharpening the minimum in optimization space, they are not expected to affect the overall result. Misalignment is somewhat different in that it is really accounting for the uncertainty with which the parts can be assembled on the beamline. However, the gauge volume studies as shown in Fig. 8, demonstrated that the diffracted result is not that sensitive to minor misalignment. Moreover as a beamline optimized for the very small samples present in high pressure experiments, SNAP is exceptionally well set-up for careful alignment procedures.
Comparing Fig. 9 and 10, the relative peak intensities are very similar. Between the simulated and experimental results, there are some differences in peak shapes that are clearly visible. Again, the majority of these features can be attributed to variations in the materials of the cell away from the ideal. A detailed analysis of the peak shape is still under study and will be presented elsewhere [13].
In conclusion, a workflow to optimize collimators for additive manufacturing has been presented. This workflow includes a McStas simulation of the incident beam in a specific beamline, MCViNE simulations of the sample, sample environment and collimator uses Mantid to reduce the results and is incorporated in a SciPy optimizer loop. The output geometry of the optimization can be converted to a .scad file for further conversion for additive manufacturing. The workflow was used to optimize a collimator for a clamp cell used on the SNAP beamline at the SNS. Such a collimator has been printed in both plastic and
Footnotes
Acknowledgements
We gratefully acknowledge J.J. Molaison for his help during the experimental evaluation on SNAP. A portion of this research used resources at the SNAP beamline of the Spallation Neutron Source, a DOE Office of Science User Facility operated by the Oak Ridge National Laboratory. The optimization constraints were determined through the expert technical efforts of D. Goldsby and D. Siddel. This work is supported by Oak Ridge National Laboratory (ORNL), Laboratory Directed Research and Development funds under contract DE-AC05-00OR8828. This research used the ORNL CADES compute resources.
