This is the development folder for Templfit. Templfit is similar to unkfit (..\robfit\srobfit\Srobfit.htm). It is normally called from the code Cambio. This code is at https://hekili.ca.sandia.gov/Cambio/. However, because the use of Templfit in Cambio is not yet fully tested, developed, or supported with a manual, it is not yet available except for a limited beta test group. If you wish to use the templfit part of Cambio in beta-test form, request permission to access curve fitting for Cambio by sending email to George Lasche gplasch@sandia.gov.
The templfit in Cambio is a Pascal procedure. It utilizes extended precision and is designed for speed. The version documented in this folder is a Fortran version that is used for testing. The robmin differs slightly from the multiple precision version used in ..\..\nlfit\Welcome.htm .doc. It can be found at ..\..\..\optimization\Robmin\Cambio\Welcome.htm ..\..\..\optimization\Robmin\Cambio\robmin.for . The Watcom ide is templfit.wpj.
Cambio writes a .cml file as part of its normal restart capability. Templfit reads its input information from this file and ends by replacing appropriate parts of the .cml file. Progdet\XMLRR\Welcome.htm – This involves reading and writing binary files. Watfor, the best debugger, does not do this well. Consequently there are three stand alone files for this
These read, replace and clean the cml file. They are part of the code except for the watfor version of the code. The fileclean code removes extraneous <cr><lf>’s and replaces the Fortran D± exponent for large and small double precision numbers with the more universally accepted E±.
A relevant section of input is
<NucFit>
<Nuc>K-40 61 Yes 1 0.5 0 </Nuc>
<Nuc>~Th-232 62 Yes 1 0.5 0 </Nuc>
<Nuc>~Ra-226 63 Yes 1 0.5 0 </Nuc>
<Nuc>Eu-152 64 Yes 1 0.5 0 </Nuc>
</NucFit>
The output in test mode is
- <NucFit>
<Nuc>K-40 61 Yes 1 0.700000E-01 0.500000E-02</Nuc>
<Nuc>~Th-232 62 Yes 1 0.140000 0.500000E-02</Nuc>
<Nuc>~Ra-226 63 Yes 1 0.210000 0.500000E-02</Nuc>
<Nuc>Eu-152 64 Yes 1 0.280000 0.500000E-02</Nuc>
</NucFit>
The chi-square that is minimized by Templfit is
The ei2 is an average of the nearest 5 points. What is the inverse of ei2. This and the substitution are made in the read/write tempfit.for code. For graphical accuracy a should be on the order of 1%. For Log equivalence probably on the order of 10%, but this will require explanation. The continuum is subtracted out after the modification above so that Templfit minimizes
The value of ei is approximately given by the square root of fA, but this can lead to strange results. ..\..\Weights\Welcome.htm .doc. In the present work a peak can have a height more than 104 times an interesting small peak. When the data is plotted on a log scale the small and large peaks both show up, but features on the large peak too small to see in the plot make a naïve fit favor a better fit to the large peak over a much more visible improvement in the small peak. This is investigated in some detail in NuclidesWeightsLimiter.doc .htm.
The continuum is fitted to a spline (..\CnmFit\Welcome.htm ..\..\..\interpolation\SplineFitting\Welcome.htm). The file Run.cml contains x,y, and y2 as needed by splint to produce a value for any x.

Figure 1 Continuum from Cambio and data-continuum ready for templfit CNM.GRF
The efficiency is given as 4 columns of data containing
energy, eff, single-escape-efficiency, and double escape-efficiency. These can be interpolated by a “natural”
spline of the type given by Press, et al [W.H. Press, B.P. Flannery, S.A.
Teukolsky, W.T. Vetterling, Numerical
Recipes,

Figure 2 Log-Log plot of the efficiency used in testing templfit. The blue line is a natural spline interpolation. Eff.grf
Figure 1 illustrates that the spline interpolation in templfit is working. The efficiency data is 0 at 20 KeV and extrapolates to 0 at above 15000 KeV. The highest energy for a data point is 11000 KeV.
There is an IIS file corresponding to each nuclide. This file contains the energy and relative intensity of every gamma ray known to be emitted in the decay of this nuclide. In run.cml
<NucFit>
<Nuc> K-40 61 Yes 1 0.5 0 </Nuc>
<Nuc>~Th-232 62 Yes 1 0.5 0 </Nuc>
<Nuc>~Ra-226 63 Yes 1 0.5 0 </Nuc>
<Nuc> Eu-152 64 Yes 1 0.5 0 </Nuc>
</NucFit>
The IIS on the input file is implicit. The yes implies T in Fortran. The 0.5 is the initial starting point for a fit to c2. The values listed below are internal Fortran values, those returned are in #The .cml file
J I IT, Catt, Cons, Vary –
2 1 61 K-40.IIS 0.500000E+00 T
2 2 62 ~Th-232.IIS 0.500000E+00 T
2 3 63 ~Ra-226.IIS 0.500000E+00 T
2 4 64 Eu-152.IIS 0.500000E+00 T
The J=2 is Fortran which goes from 1 to 3. It corresponds to the 1 in the list above which goes from 0 to 2. Each nuclide in the list above contains a number of peaks which is currently dimensioned 1 £ np £ 10001. These are read in by the subroutine runpks (runpks.for) and stored in the common /iisinfo/ in the order that they appear in the appropriate iis files. This common also appears in the main code tempfit.for where it basically reserves space and in ptempl.for where it calclates the derivatives with respect to the cons, with Vary set to true as listed above. The derivatives with respect to the first 60 constants representing energy calibration, resolution calibration, two different attenuations, three skew values, and three jumps as functions of energy are also found in ptempl.for. The Pascal version of the code is designed for fast plotting, while the peaks are read in in the same way, they are then sorted so that the peaks in Pascal are records in order of energy with extra parameters that give the attenuation type and nuclide.
The Robfit code made an initial fit (stgen) to a peak type that could by a Gaussian, Lorentzian, Voigt (convolution of Lorentzian with Gaussian), or most frequently simply a large peak in the spectrum. This standard peak had three parameters, height, location, and width that were varied to give the best fit to the data. Templfit is designed to fit gamma ray peaks in the range from 20 KeV to 10000 KeV. The peak shape would be a Gaussian determined by the detector characteristics, but the detected gamma rays have been scattered a bit while going through the material and thus there is a low energy tail on the peaks. The peaks fall into three categories, attenuation 0, 1, and 2 corresponding roughly to three different sets of material that the gamma rays may have travelled through. There are three sets of skew(E;c), and jump(E;c) determining the low energy tails on the peaks. More peak details and some pictures are in ..\PkPoly\Welcome.htm.
As the gamma rays pass through a material on the way to the detector, low energy gamma rays are deflected out of the signal faster than high energy gamma rays. This gives rise to three different attenuation terms.
The efficiency and attenuation are not easily separated. In Templfit, it is assumed that the efficiency has been determined beforehand. This attenuation is determined by the material through which the gamma rays pass before encountering the detector. If there are enough well placed peaks, the attenuation can be determined by minimizing the chi-square with respect to parameters in the attenuation. Eu-152 has a large number of peaks well placed between 121 and 1409 KeV. The result is in Timing.htm.
As explained in ..\..\FitData.doc .htm, making a fit to the date involves finding an approximating function fA(x) and its partial derivatives ¶fA(x)/¶ck with respect to the constants beign varied. The code for doing this is described in Ptemple.doc .htm.