DecompLib
A simple library for decomposition of spectra using a response matrix.
|
DecompLib is a small header only template library for decomposing a spectrum into a set of weighted response functions. The decomposition processes is necessary because the response of a detector to mono-energetic incident radiation is not necessarily mono-energetic, let alone at the same energy. Therefore to determine the radiation incident on the detector the detected spectrum must be decomposed using the response matrix (each row encodes the response to a particular mono-energetic input.)
This decomposition can be stated as the following fitting problem:
\[ S = \sum\limits_{\alpha}f_{\alpha}\times{}\vec{R}_{\alpha} \]
Where \(S\) is the input spectrum \(\vec{R}_{\alpha}\) are the rows of the response matrix (response functions), and \(f_{\alpha}\) are the weights of the response functions (the incident spectrum). Here though the the various response functions may have a great deal of similarity, causing normal linear algreba methods to fail. The algorithm used in DecompLib will yield positive definite results in a numerically stable fashion. Please see the second half technical report in the DecompLib doc directory for more details.
I ask that if you use DecompLib in work that you are publishing, that you cite it.
Because DecompLib is a header only library it is unnecessary to build anything prior to installing it. The only things that need to be built are the documentation and the example. The next section tells how to build the example and documentation, if you merely wish to install the headers and start using them you can skip straight to the install subsection
If you wish to only build the example and its attendant utilities you need only run make example
. Contrariwise, if you wish to only build the documentation simply run make doc
. To make both the example and documentation simply run make all
or make
. This will then build the Example program and the three associated utilities with it. Then it will build the documentation, running doxygen which outputs html and LaTeX, building the doxygen LaTeX output, then building the LaTeX technical report.
Installation of DecompLib is fairly easy, but . In most unix systems you need only decided if you wish to install the library globally across the whole system (requires sudo
or root permissions) or if you want to install the library locally.
If you wish to install system wide:
/usr/include
is the correct system header location.Global_Header_Loc=/usr/include
to the correct locationsudo make install
If you wish to install locally:
${HOME}/include
edit the line containing Local_Header_Loc=~/include
to the prefered location.make local_install
Usage of the library is simple. One need only instantiate one of each of the three classes, fill them with data, then call the performDecomposition function to decompose the spectrum. Since code is worth more than prose for this a semi-pseudocode example is below.
For more information about the usage and member functions of DataVector, RespMatrix, and DecompVector check out the Input/Output Classes module.
To learn more about performDecomposition check out the Decomposition Functions module.
Documentation is available in a few forms. For the full documenation of DecompLib's objects and functions please see the Input/Output Classes and Decomposition Functions modules. For more about usage of the algorithm itself and the potential alternative uses and pitfalls associated with it, see the second half of the technical report in the doc directory.
DecompLib contains a directory called Example. This directory contains a program demonstrating the usage of DecompLib as well as four utility functions to assist with the input and output to the example.
The Example/DecomposeSpectrum subdirectory contains the actual usage example. In addition to the program decompose
it contains a sample input spectrum in csv format and a sample response matrix in a gzip compressed csv format (it will need to be uncompressed for use). After being built you can run the example as follows ./decompose <spectrumCsvFile> <responseMatrixCsvFile> <outputFileBase>
.
Notes: outputFileBase is prefixed onto "_init.csv" (the initial decomposition values spectrum), "_final.csv" (the final decomposition values spectrum), "_sum.csv" (the sum of response functions from the matrix weighted by the final decomposition values), and "_resid.csv" (the weighted sum subtracted from the input spectrum).
Before decompose
performs the decomposition it asks several quesions about the parameters that go into the decomposition. How to set the initial DecompVector guess, what is the threshold for ignoring parameters when checking convergence, what is the convergence criterion. It also asks what limits of bin numbers it should use for the spectrum and response matrix. For the sample response matrix and spectrum included the X-axis limits that will pass the safety checks are [0, 3049] and the Y-axis limits that will pass the safety checks are [4, 1499], narrower limits can be chosen, but not broader. Additionally, the X-axis limits for the response matrix and the limits for the spectrum should always be the same.
The Example/RootTh1ToCsv contains a utility that will take a root file and the name of any TH1(F,D,I...) in that file and output it to a specified csv format file. After being built it can be invoked as follows: ./convert1d <inputRootFile> <Th1Name> <outputFile>
The Example/RootTh2ToCsv contains a utility that will take a root file and the name of any TH2(F,D,I...) in that file and output it to a specified csv format file. After being built it can be invoked as follows: ./convert2d <inputRootFile> <Th2Name> <outputFile>
The Example/CsvToRootTh1 contains a utility that a 1D histogram in a csv file and write it into TH1D format in a root file you select. After being built it can be invoked as follows: convert1dCsv <1dHistogramCsv> <outputRootFile> <Th1Name>
The Example/CsvToRootTh1 contains a utility that a 2D histogram in a csv file and write it into TH2F format in a root file you select. After being built it can be invoked as follows: convert2dCsv <2dHistogramCsv> <outputRootFile> <Th2Name>
This is a greatly expanded version of the usage pseudocode from above. It includes comments explaining more about choices as well as showing where default parameters were chosen in function calls above.
To learn more about the particular pitfalls that are possible with the algorithm please see the second half technical report in the DecompLib doc directory.