# SIRENA description¶

## Purpose¶

SIRENA (*Software Ifca for Reconstruction of EveNts for Athena X-IFU*) is a software package developed to reconstruct the energy of the incoming X-ray photons after their detection in the X-IFU TES detector. It is integrated in the SIXTE end-to-end simulations environment where it currently runs over SIXTE simulated data. This is done by means of a tool called tesreconstruction, which is mainly a wrapper to pass a data file to the SIRENA tasks.

## Files¶

### Auxiliary Files¶

All the reconstruction methods used by SIRENA software rely on the existence of a *library* created from a set of data calibration files. In addition, some methods require also a file with the *noise data*. Let’s describe these auxiliary files in detail.

#### Noise file¶

The detector **noise file** is currently obtained from a long stream of pulse-free (noise) simulated data. This stream is ingested in the tool gennoisespec, which generates the spectrum of this simulated noise.

**1) Calibration Stream Simulation**

The simulation of the noise stream is performed by these SIXTE tools:

`tesconstpileup`

: which creates a piximpact file of zero-energy events.`tessim`

([Wilms+16]): which simulates these fake impacts through the detector’s physics and creates data stream splitted into records (use option triggertype=noise).

The sequence of commands that must be run is as follows:

```
> tesconstpileup PixImpList=noise.piximpact XMLFile=tes.XML tstop=simulationTime energy=0 \
pulseDistance=1 triggersize=10000
```

```
> tessim PixID=pixelNumber PixImpList=noise.piximpact Streamfile=noise.fits tstart=0. \
tstop=simulationTime triggertype=noise triggersize=10000 prebuffer=1000 \
PixType='file:newpixels[SPA]' acbias=yes
```

**2) Noise spectrum and weight matrices generation**

In gennoisespec, the data is analysed record by record: if there are events present, this tool finds and rejects them, keeping only the pulse-free intervals of a size given by the input parameter `--intervalMinSamples`

. If no events are present, the record is divided into pulse-free intervals sized also by this parameter.

Once the pulse-free intervals have been defined, a long noise interval is built by putting together these pulse-free intervals in order to calculate the noise baseline. Then, the baseline is subtracted from each pulse-free interval.

On one hand, the tool calculates the FFT of the pulse-free intervals (over the unfiltered data) and averages them. Only a specific number of intervals (input parameter `--nintervals`

) will be used. The noise spectrum density is stored in the HDUs *NOISE* and *NOISEALL* in the *noise data* file.

```
> gennoisespec --inFile=noise.fits --outFile=noiseSpec.fits --intervalMinSamples=pulseLength \
--nintervals=1000 --pulse_length=pulseLength
```

On the other hand, if `--weightMS`

= *yes* the tool calculates the covariance matrix of the noise, , whose elements are expectation values () of two-point products for a pulse-free data sequence (over the unfiltered data) ([FowlerAlpertDoriese+15])

The weight matrix is the inverse of the covariance matrix, . The weight matrixes, **Wx**, for different lenghts are stored in the HDU *WEIGHTMS* in the *noise data* file. The lengths x will be base-2 values and will vary from the base-2 system value closest-lower than or equal-to the `--intervalMinSamples`

decreasing until 2.

gennoisespec also adds the `BASELINE`

and `NOISESTD`

keywords to the HDU *NOISE* in the *noise data* file. They store the mean and the standard deviation of the noise (by working with the long noise interval).

If the noise spectrum or the weight matrixes are to be created from a data stream containing pulses, care should be taken with the parameters `--scaleFactor`

, `--samplesUp`

and `--nSgms`

responsible of the detection process.

#### Template Library¶

The **library** purpose is to store detector pulse magnitudes (templates, covariance matrices, optimal filters) at different calibration energies, so that they could be used afterwards for the
reconstruction of input pulses of unknown energy.

To build this library, a bunch of monochromatic pulses at different energies are simulated by `tesconstpileup`

(which now creates a *piximpact* file with pairs of constant separation pulses) and `tessim`

(which simulates the detector physics).

**1) Calibration Files simulation**

Typical run commands to create these calibration files for a given energy *monoEkeV* and a
given (large) *separation* in samples between the pulses would be:

```
> tesconstpileup PixImpList=calib.piximpact XMLFile=tes.XML tstop=simulationTime \
energy=monoEkeV pulseDistance=separation TriggerSize=tsize
```

where *tsize* is the size of every simulation stream containing the two separated pulses.

```
> tessim PixID=pixelNumber PixImpList=calib.piximpact Streamfile=calib.fits tstart=0. \
tstop=simulationTime triggertype='diff:3:100:supress' triggerSize=recordSize \
PixType=newpixels[SPA] acbias=yes
```

where *suppress* is the time (in samples) after the triggering of an event, during which tessim will avoid triggering again (see figure below).

These simulated calibration files are now FITS files with only one HDU called **RECORDS** populated with four columns: **TIME** (arrival time of the event), **ADC** (digitized current), **PIXID** (pixel identification) and **PH_ID** (photon identification, for debugging purposes only).

**2) Library construction**

Once the calibration files (for all the 1..N calibration energies) have been created, the library is built through the wrapper tool `tesreconstruction`

. To run it using SIRENA code:

```
> tesreconstruction Recordfile=calib.fits TesEventFile=evtcal.fits Rcmethod=SIRENA \
PulseLength=pulseLength LibraryFile=library.fits mode=0 clobber=yes monoenergy=monoEeV_1 \
EventListSize=1000 NoiseFile=noiseSpec.fits scaleFactor=sF samplesUp=sU nSgms=nS \
largeFilter=maxlengthfixedfilter hduPRECALWN=yes/no hduPRCLOFWM=yes/no
[.....]
> tesreconstruction Recordfile=calib.fits TesEventFile=evtcal.fits Rcmethod=SIRENA \
PulseLength=pulseLength LibraryFile=library.fits mode=0 clobber=yes monoenergy=monoEeV_N \
EventListSize=1000 NoiseFile=noiseSpec.fits scaleFactor=sF samplesUp=sU nSgms=nS \
largeFilter=maxlengthfixedfilter hduPRECALWN=yes/no hduPRCLOFWM=yes/no
```

The relevant parameters of `tesreconstruction`

for the library creation process are:

`mode`

: should be set to**0**if tool is used for library creation`PulseLength`

: length of the pulses to create the pulse templates. If the pulse length used to create the noise is larger that this value, noise will be decimated accordingly when used to pre-calculate the optimal filters or the covariance matrices. If it is shorter, an error will be raised.`largeFilter`

: length of the longest fixed filter`monoenergy`

: the monochromatic energy of the calibration pulses used to create the current row in the library`scaleFactor`

,`samplesUp`

and`nSgms`

: parameters involved in the pulse detection process.`hduPRECALWN`

and`hduPRCLOFWM`

: parameters to create or not the corresponding HDUs.

**3) Library structure**

The library FITS file has 3 HDUs called **LIBRARY**, **FIXFILTT**, **FIXFILTF** which are always present, and other 2 HDUs **PRECALWN** and **PRCLOFWM** which are optional depending on the input parameters `hduPRECALWN`

and `hduPRCLOFWM`

.

**LIBRARY** contains the following columns:

**ENERGY**: energies (in eV) in the library**PHEIGHT**: pulse heights of the templates**PLSMXLFF**: long templates according to`largeFilter`

(obtained averaging many signals) with baseline. If`largeFilter`

is equal to`PulseLength`

it does not appear**PULSE**: templates (obtained averaging many signals) with baseline**PULSEB0**: baseline subtracted templates**MF**: matched filters (energy normalized templates)**MFB0**: baseline subtracted matched filters**COVARM**: covariance matrices (`PulseLength`

x`PulseLength`

in shape ) stored in the FITS column as vectors of size`PulseLength`

*`PulseLength`

. It appears if`hduPRECALWN`

=yes**WEIGHTM**: weight matrices (`PulseLength`

x`PulseLength`

in shape) stored in the FITS column as vectors of size`PulseLength`

*`PulseLength`

. It appears if`hduPRECALWN`

=yes**WAB**: matrices stored as vectors (`PulseLength`

*`PulseLength`

), being weight matrixes and and two consecutive energies in the library. It appears if`hduPRECALWN`

=yes**TV**: vectors being the template at energy. It appears if`hduPRECALWN`

=yes**tE**: scalars . It appears if`hduPRECALWN`

=yes**XM**: matrices stored as vectors (`PulseLength`

*`PulseLength`

). It appears if`hduPRECALWN`

=yes**YV**: vectors . It appears if`hduPRECALWN`

=yes**ZV**: vectors . It appears if`hduPRECALWN`

=yes**rE**: scalars . It appears if`hduPRECALWN`

=yes**PAB**: vectors , in first order approach**PABMXLFF**:**PAB**according to`largeFilter`

. If`largeFilter`

is equal to`PulseLength`

it does not appear**DAB**: vectors , in first order approach

The **FIXFILTT** HDU contains pre-calculated optimal filters in the time domain for different lengths, calculated from the matched filters (*MF* or *MFB0* columns) in **Tx** columns, or from the *DAB* column, in the **ABTx** columns. The lengths *x* will be base-2 values and will vary from the base-2 system value closest-lower than or equal-to the pulse length decreasing until 2. Moreover, **Txmax** and **ABTxmax** columns being *xmax* = `largeFilter`

are added.

The **FIXFILTF** HDU contains pre-calculated optimal filters in frequency domain for different lengths calculated from the matched filters (*MF* or *MFB0* columns), in columns **Fx**, or from the *DAB* column, in **ABFx** columns. The lengths *x* will be base-2 values and will vary from the base-2 system value closest-lower than or equal-to the pulse length decreasing until 2. Moreover, **Fxmax** and **ABFxmax** columns being *xmax* = `largeFilter`

are added.

The **PRECALWN** HDU contains pre-calculated values by using the noise weight matrix from the subtraction of model from pulses for different lengths, **PRCLx**. The lengths *x* will be base-2 values and will vary from the base-2 system value closest-lower than or equal-to the pulse length decreasing until 2.

The **PRCLOFWM** HDU contains pre-calculated values by using the noise weight matrix from noise intervals for different lengths, **OFWx**. The lengths *x* will be base-2 values and will vary from the base-2 system value closest-lower than or equal-to the decreasing `largeFilter`

until 2.

### Input Files¶

The input data (simulated) files, currently required to be in FITS format, are a sequence of variable length `RECORDS`

, containing at least a column for the **TIME** of the digitalization process and a column for the detector current (**ADC**) at these samples. Every record (file row) is the result of an initial triggering process done by the SIXTE simulation tool `tessim`

.

### Output Files¶

The reconstructed energies for all the detected events are saved into an output FITS file (governed by the `tesreconstruction`

input parameter `TesEventFile`

). It stores one event per row with the following information, in the HDU named **EVENTS**:

**TIME**: arrival time of the event (in s).**SIGNAL**: energy of the event in keV.**AVG4SD**: average of the first 4 samples of the derivative of the pulse.**GRADE1**: length of the filter used, i.e., the distance to the following pulse (in samples) or the pulse length if the next event is further than this value or if there are no more events in the same record.**GRADE2**: distance to the end of the preceding pulse (in samples). If pulse is the first event in the record, this is fixed to the`PulseLength`

value.**PIX_ID**: pixel number**PH_ID**: photon number identification for cross matching with the impact list (currently not in use).**GRADING**: Pulse grade (HighRes=1, MidRes=2, LimRes=3, LowRes=4, Rejected=-1, Pileup=-2).

## Reconstruction Process¶

The energy reconstruction of the energies of the input pulses is performed with the tool `tesreconstruction`

along three main blocks:

- Event Detection
- Event Grading
- Energy Determination

### Event Detection¶

The first stage of SIRENA processing is a fine detection process performed over every *RECORD* in the input file, to look for missing (or secondary) pulses that can be on top of the primary (initially triggered) ones. Two algorithms can be used for this purpose, the *Adjusted derivative* (**AD**) (see [Boyce+99]) and what has been called *Single Threshold Crossing* (**STC**) (which has been implemented in the code with the aim of reducing the complexity and the computer power of the AD scheme) (`detectionMode`

).

#### Adjusted Derivative¶

It follows these steps:

1.- The record is differentiated and a *median kappa-clipping* process is applied to the data, so that the data values larger than the median plus *kappa* times the quiescent-signal standard deviation, are replaced by the median value in an iterative process until no more data points are left. Then the threshold is established at the clipped-data mean value plus `nSgms`

times the standard deviation.

2.- A pulse is detected whenever the derivarive signal is above this threshold.

3.- Based on the first sample of the signal derivative which passes the threshold level, a template is selected from the library. The 25-samples-long dot product of the pre-detected pulse and the template is then calculated at different positions (lags) around the initial starting time of the pulse to better determine its correct starting point. Usually a dot product in 3 different **lags** [1] around the sample of the initial detection is adequate to find a maximum and the following steps will depend on whether a maximum of the dot product has been found or not:

- If a maximum of the dot product has not been found, the starting time of the pulse is fixed to the time when the derivative gets over the threshold (in this case, the
*tstart*matches a digitized sample without taking the possible jitter into account). - If a maximum of the dot product has been found, a new starting time f the pulse is going to be established (by using the 3-dot-product results around the maximum to analytically define a parabola and locate its maximum). Then, an iterative process begins in order to select the best template from the library, resulting each time in a new starting time with a different jitter. As due to the jitter, the pulses are placed out of a digitized sample clock, the first sample of the derivative of the pulse itself is not exactly the value of the first sample getting over the threshold and it would need to be corrected depending on the time shift with respect to the digitized samples (
*samp1DER correction*).

[1] | Nevertheless, when the residual signals are large, the maximum of the dot product moves towards the secondary pulse, missing the primary detection. This is why currently the maximum number of the dot product lags is limited to 5. |

4.- Every time a sample is over the threshold, a check is performed for the slope of the straight line defined by this sample, its preceding one and its following one. If the slope is lower than the minimum slope of the templates in the calibration library, the pulse is discarded (it is likely a residual signal) and start a new search. If the slope is higher than the minimum slope of the templates in the calibration library, the pulse is labeled as detected.

5.- Once a primary pulse is detected in the record, the system starts a secondary detection to look for missing pulses that could be hidden by the primary one. For this purpose, a model template is chosen from the auxiliary library and subtracted at the position of the detected pulse. The first sample of the detected pulse derivative (possibly different from the initial one after the realocation done by the dot product in the previous step) is used to select again the appropriate template from the library. After the *samp1DER correction* and also due to the jitter, the 100-samples-long template needs to be aligned with the pulse before subtraction (*template correction*). Then the search for samples above the threshold starts again.

This is an iterative process, until no more pulses are found.

If the noise is large, input data can be low-pass filtered for the initial stage of the event detection. For this purpose, the input parameter `scaleFactor`

() is used. The low-pass filtering is applied as a box-car function, a temporal average window. If the cut-off frequency of the filter is , the box-car length is , where is the value of the sampling rate in Hz (inverse of the input file keyword `DELTAT`

).

for

If the parameter `scaleFactor`

is too large, the low-pass filter band is too narrow, and not only noise is rejected during the filtering, but also the signal.

Note

A proper cut-off frequency of the low-pass filter must be chosen in order to avoid piling-up the first derivative and to detect as many pulses as possible in the input FITS file. However, filtering gives rise to a spreading in the signal so, the pulses start time calculated from the first derivative of the low-pass filtered event (which is spread by the low-pass filtering) has to be transformed into the start time of the non-filtered pulse.

#### Single Threshold Crossing¶

1.- This alternative detection method also compares the derivative signal to a threshold (established in the same way as in the step 1 of the previous algorithm).

2.- If `samplesUp`

samples of the derivative are above this threshold a pulse is detected.

3.- After the detection, the first sample of the derivative that crosses the threshold is taken as the Start Time of the detected pulse.

4.- If `samplesDown`

samples of the derivative are below the threshold, the process of looking for a new pulse starts again.

In contrast to apply either of the last two detection algorithms, for testing and debugging purposes SIRENA code can be run in **perfect detection** mode, leaving out the detection stage, provided the (pairs or triplets of) simulated pulses are at the same position in all the RECORDS. In this case the start sample of the first/second/third pulse in the record is taken from the input parameter(s) `tstartPulse1`

, `tstartPulse2`

, `tstartPulse3`

(parameters `scaleFactor`

, `samplesUp`

or `nSgms`

would then not be required). Currently no subsample pulse rising has been implemented in the simulations nor in the reconstruction code (future development).

### Event Grading¶

The *Event Grading* stage qualifies the pulses according to the proximity of other events in the same record.

Once the events in a given record have been detected and their start times established, **grades** are assigned to every event taking into account the proximity of the following and previous pulses. This way, pulses are classified as *High*, *Medium*, *Limited* or *Low* resolution and as *Rejected* and *Pileup* pulses. Currently the grading is performed following the information in the input `XMLFile`

.

### Event Energy Determination: methods¶

Once the input events have been detected and graded, their energy content can be determined. Currently all the events (independently of their grade) are processed with the same reconstruction method, but in the future, a different approach could be taken, for example simplifying the reconstruction for the lowest resolution events.

The SIRENA input parameter that controls the reconstruction method applied is `EnergyMethod`

that should take values of *OPTFILT* for Optimal Filtering in Current space, *WEIGHT* for Covariance Matrices, *WEIGHTN* for first order approach of Covariance matrices method and *I2R*, *I2RALL*, *I2RNOL* or *I2RFITTED* for Optimal Filtering implementation in (quasi)Resistance space. If optimal filtering and `OFNoise`

is *WEIGHTM* tthe noise weightt matrix from noise intervals is employed instead the noise spectral density (`OFNoise`

is *NSD*).

#### Optimal Filtering by using the noise spectral density¶

This is the baseline standard technique commonly used to process microcalorimeter data streams. It relies on two main assumptions. Firstly, the detector response is linear; that is, the pulse shapes are identical regardless of their energy and thus, the pulse amplitude is the scaling factor from one pulse to another [Boyce+99], [Szymkowiak+93].

In the frequency domain (as noise can be frequency dependent), the raw data can be expressed as , where is the normalized model pulse shape (matched filter), is the noise and is the scalar amplitude for the photon energy.

The second assumption is that the noise is stationary, i.e. it does not vary with time. The amplitude of each pulse can then be estimated by minimizing (weighted least-squares sense) the difference between the noisy data and the model pulse shape, being the condition to be minimized:

In the time domain, the amplitude is the best weighted (optimally filtered) sum of the values in the pulse.

where is the time domain expression of optimal filter in frequency domain

and is the normalization factor to give in units of energy

Optimal filtering reconstruction can be currently performed in two different implementations:

baseline subtraction(B0 in SIRENA wording), where the baseline value read from the`BASELINE`

keyword in the noise file is subtracted from the signal, andfrequency bin 0(F0), where the frequency bin atf=0 Hzis discarded for the construction of the optimal filter. The final filter is thus zero summed, which produces an effective rejection of the signal baseline (see [Doriese+09] for a discussion about the effect of this approach on the TES energy resolution). This option is controlled by the parameter`FilterMethod`

.

As the X-IFU detector is a non-linear one, the energy estimation after any filtering method has been applied, has to be transformed to an unbiased estimation by the application of a gain scale obtained by the application of the same method to pulse templates at different energies (not done inside SIRENA).In SIRENA, optimal filters can be calculated

on-the-flyor read as pre-calculated values from the calibration library. This option is selected with the input parameter`OFLib`

. If`OFLib`

=1, fixed-length pre-calculated optimal filters (TxorFx) will be read from the library (the length selectedxwill be the base-2 system value closest -lower than or equal- to that of the event being reconstructed or`largeFilter`

). If`OFLib`

=0, optimal filters will be calculated specifically for the pulse length of the event under study. This length calculation is determined by the parameter`OFStrategy`

. This way`OFStrategy`

=FREEwill optimize the length of the filter to the maximum length available (let’s call this valuefltmaxlength), given by the position of the following pulse, or the pulse length if this is shorter. If`OFStrategy`

=BASE2the filter length will be the base-2 system value closest-lower than or equal-tofltmaxlength.`OFStrategy`

=BYGRADEwill choose the filter length to use, according to the grade of the pulse (currently read from the`XMLFile`

) and`OFStrategy`

=FIXEDwill take a fixed length (given by the parameter`OFLength`

) for all the pulses. These last 3 options are only for checking and development purposes; a normal run withon-the-flycalculations with be done with`OFStrategy`

=FREE. Note that if`OFLib`

=0, a noise file must be provided through parameter`NoiseFile`

(not in the case of`OFLib`

=1), since in this case the optimal filter must be computed for each pulse at the required length.In order to reconstruct all the events using filters at a single monochromatic energy, the input library should only contain one row with the calibration columns for that specific energy. If the input library is made of several monochromatic calibration energies, the optimal filters used in the reconstruction process can be tunned to the initially estimated energy of the event being analysed. For this purpose, a first order expansion of the temporal expression of a pulse at the unknown energy

Ewill be taken into account:where is the baseline level, and are pulse templates (

PULSEBOcolumns) at the corresponding energies which embrace the energy . Operating here and grouping some terms:then

This expression resembles the one above for the optimal filtering if now the data is given by and the role of normalized template is played by . This way, the optimal filters can be built over .

Again,

`OFLib`

will control whether the required (interpolated) optimal filter (built from ) is read from the library (at any of the several fixed lengths stored,ABFxorABTx) or whether an adequate filter is calculatedon-the-fly(`OFLib`

=0).The optimal filtering technique (selected through the input parameter

`EnergyMethod`

) can be applied in the frequency or in the time domain with the option`FilterDomain`

.The misalignement between the triggered pulse and the template applied for the optimal filter can affect the energy estimate. As the response will be maximum when the data and the template are coincident, an option has been implemented in SIRENA to calculate the energy at three different fixed lags between both, and estimate the final energy to better than the sample frequency ([Adams+09]). This possibility is driven by input

`LagsOrNot`

.

#### Optimal Filtering by using the noise weight matrix from noise intervals¶

By choosing the input parameter

`OFNoise`

asWEIGHTMthe optimal filtering method is going to use the noise weight matrix calculated from noise intervals (rather than the noise spectral density as in first order approach). Using the noise power spectrum (FFT) is also possible, but it introduces an additional wrong assumption of periodicity. The signal-to-noise cost for filtering in the Fourier domain may be small in some cases but it is worth while checking the importance of this cost ([FowlerAlpertDoriese+15]).Being the noise covariance matrix, the best estimate energy is (see mathematical development):

where is the unit vector to select only the term that corresponds to the energy (amplitude) of the pulse. is a model matrix whose first column is the pulse shape and the second column is a column of ones in order to can calculate the baseline. is the measured data.

#### Quasi Resistance Space¶

A new approach aimed at dealing with the non-linearity of the signals, is the transformation of the current signal before the reconstruction process to a (quasi) resistance space ([Bandler+06], [Lee+15]). It should improve the linearity by removing the non-linearity due to the bias circuit, although the non-linearity from the R-T transition still remains. A potential additional benefit could also be a more uniform noise across the pulse.

This type of transformations are currently implemented in SIRENA and can be accessed through the

`EnergyMethod`

command line option. Some of them, considers linearization as a linear scale in the height of the pulses with energy (I2RALL,I2RNOL,I2R) while the last one is also able to get a linear gain scale when the signal is reconstructed with a simple filter (I2RFITTED).Let’s see first some definitions given by columns and keywords in

`tessim`

simulated data files.

PXLnnnnn: column that stores the data signal in pixel nnnnn[ADC]PULSEnnnnn: column for the data signal in pixel nnnnnover the bias current [Amp]`ADUCNV`

:ADU conversion factor [Amp/ADU] `I0_START`

:Initial bias current [Amp] `IMIN`

:Current corresponding to 0 ADU [Amp] I: Data signal in Current space [Amp] `R0`

:Operating point resistance [Ohm] `TTR`

:Transformer Turns Ratio `LFILTER`

:Filter circuit inductance [H] `RPARA`

:Parasitic resistor value [Ohm]

`ADUCNV`

+`IMIN`

=`I0_START`

- I

I2RALLtransformation

`tessim`

([Wilms+16]) is based on a generic model of the TES/absorber pixel with a first stage read-out circuit. The overall setup of this model is presented in the figure below.`tessim`

performs the numerical solution of the differential equations for the time-dependent temperature, , and the current, , in the TES using [Irw05] :In the electrical equation, is the effective inductance of the readout circuit, is the effective load resistor and is the constant voltage bias. Under AC bias conditions,

`LFILTER`

/`TTR²`

`RPARA`

/`TTR²`

`I0_START`

(`R0`

and thus the transformation to resistance space is:

I2RNOLtransformationIn the previous transformation

I2RALL, the addition of a derivative term increases the noise and thus degrades the resolution. Therefore, a new transformationI2RNOLis done where the circuit inductance is neglected ( [Lee+15] ), thus suppressing the main source on non-linearity of the detector that comes from the first stage read-out circuit:

I2RtransformationA different linearization (in the sense of pulse height vs. energy) has been implemented in SIRENA for developing purposes:

I2RFITTEDtransformationLooking for a simple transformation that would produce also a linear gain scale, a new transformation

I2RFITTEDhas been proposed in [Peille+16]:

The optimalwas found to be .*

#### Covariance matrices¶

In real detectors, none of the above assumptions (linearity and stationary noise) is strictly correct, so a different approach is required in the presence of non-stationary noise along the signal event, which has to be optimal also when the detector is non-linear. In this method a set of calibration points constructed by many pulse repetitions (), is defined at different energies . At these energy points, a pulse model (

PULSEB0column in library) is obtained averaging the data pulses , and the deviations of these pulses from the data model are used to build a covariance matrix (the weight matrix , inverse of the covariance matrix, is also calculated). The non-stationary noise is better described by a full noise covariance matrix rather than a simpler Fourier transform [Fixsen+04].An initial estimation of the energy of the unknown signal data is sufficient to determine the calibration points which straddle it. Then with a linear interpolation of the weight matrix and the signal, the best energy estimate is just a function of the energies of the embracing calibration points, the unknown signal and some other magnitudes that can be pre-calculated with the calibration data (see Eq. 2 in [Fixsen+04]):

where , being the unknown data signal ( and are signals without baseline, i.e., we are assuming that the baseline is known or that the baseline is constant from calibration to the measurement time). Some of these terms are precalculated with calibration data and included in the library to be read during the reconstruction process. In particular: , , , , and .

Energy reconstruction with

Covariance Matricesis selected with input option`EnergyMethod`

=WEIGHT.

#### Covariance matrices 0(n)¶

A first order approximation can be used for the Covariance Matrices method from a first order expansion of the pulse expression at a iven

t:where is the baseline level, and are pulse templates (column

PULSEB0in the library) at the corresponding energies which embrace the unknown energy .resembles an equation of condition in matrix notation that for a problem with the covariance matrices used as weights ():

where is the unit vector to select only the term that corresponds to the energy (amplitude) of the pulse.

Energy reconstruction withCovariance Matrices 0(n)is selected with input option`EnergyMethod`

=WEIGHTN. If parameter`OFLib`

=1, some components can be used from the precalculated values at the libraryColumns (HDUPRECALWN).

#### Principal Component Analysis (PCA)¶

As the assumptions of the optimal filter technique (linearity and stationary noise) are not strictly correct and the covariance matrix methods are highly resource-demanding, energy reconstruction with

Principal Component Analysishas been explored ([Busch+15] and [Yan+16]).According to [Yan+16], taking a set of non piled-up pulses from the detector (), each one sampled in time (), a data matrix

can be represented through the basis set with

Scharacteristics pulse shape factors. is the weigthing of members of this basis set.The basis set can be calculated from the data time covariance square matrix. Unlike the (residuals) covariance matrix created for

`EnergyMethod`

=WEIGHTorWEIGHTN, thepulseaverage(i.e. model) is not subtracted in`weightMatrix()`

.Since this time covariance matrix is symetric, it can be represented it in terms of a set of eigenvectors (and eigenvalues weightings). The eigenvectors of the data covariance matrix are the principal components to characterise the information.

If a subset (

S’) of eigenvectors can be found (finding patterns depending on the values of the eigenvalues), each pulse could be more compactly represented, not with all the time pointsTbut in terms of just itsS’weighting factors, i.e., the chosen eigenvectors. Once the matrix has been determined and inverted, the weighting factors of each pulse can be found byIf the matrix is constructed to have orthogonal vectors to ease matrix inversion, these eigenvectors could be sorted in order of decreasing statistical significance and a reduced basis set could be easily separated from the full basis set . This reduced set of eigenvectors can describe all the significant characteristic pulse shape components.

A compressed (and noise-filtered) version of the original data can also then be generated:

The next step is understanding how to extract energy information from these 2D scatter plot. In [Yan+16], PCA method is applied to a real dataset with Mn and Mn lines of the Fe-55 source and very different pulse shapes. In order to extract energy information, the weighting matrix , restricted to

S’=2 for simplicity, is examined (see their fig.4 below). Two clusters (elongated by the pulse shape variation) can be seen associated with the Mn (black) and Mn (blue) lines. By fitting a line (red) to the Mn cluster, an axis is generated and used to rotate the 2D scatter plot of the weighting matrix so that the clusters are vertical. From the projection onto the X-axis, the energy histogram (right subfigure) is built and thus, the energy can be correlated to a linear combination of the first two PCA components.In order to show more clearly how to follow the process, we have simulated (using

`tessim`

) a data set containing pulses of two different energies, 0.5 and 1 keV (ADC units), that we trim at samples. The first 50 eigenvalues of this dataset are shown in the left subfigure below. According to the eigenvalues, this dataset contains two primary eigenvectors (see the right subfigure below), giving essentially the averages of the pulse shapes (there are two different pulse shapes in the data for two different energies). Higher order eigenvevectors give corrections to these averages and noise correlations.The next subfigure on the left shows the distribution of elements from the weighting matrix , where components 1 and 2, respectively, are the weighting factors of the first and second eigenvectors. The right subfigure is simply a zoom showing only the 0.5 keV (ADC units) events.

In the next figure, the line represents the direction of variable energies and the line the perpendicular direction which is used to rotate the 2D scatter plot. From the projection onto the X-axis (clusters in red), the energy histograms are built. Since we know the energy difference in eV (the two energies are provided as input parameters

`energyPCA1`

and`energyPCA2`

), it is possible to calculate a conversion factor between arbitrary units to eV.PCA has not yet been implemented as a full-functionality

`EnergyMethod`

(only for testing and development purposes). For the time being, input FITS files to PCA method must have pulses of two different energies which must be provided as input parameters. If it would be necessary, future developments will be done in order to implement this approach in a real-time software.

### Use of library columns in the different reconstruction methods¶

**1) Optimal filtering and NSD**

**2) Optimal filtering and WEIGHTM**

**3) Covariance matrices**

**4) Covariance matrices O(n)**

### Examples¶

- Full Energy reconstruction performed with the (F0) optimal filtering algorithm (filters calculated on-the-fly) in the current space (including detection) for the detector described in the XMLFile:

```
>tesreconstruction Recordfile=inputEvents.fits TesEventFile=outputEvents.fits
Rcmethod='SIRENA' OFLib=no OFStrategy=FREE PulseLength=1024 nSgms=10 \
LibraryFile=libraryMultiE.fits mode=1 NoiseFile=noise1024samplesADC.fits \
FilterMethod=F0 clobber=yes intermediate=0 EnergyMethod=OPTFILT \
XMLFile=xifu_detector_hex_baseline.xml
```

- Energy reconstruction performed with the (F0) optimal filtering algorithm (filters extracted from the library) in the current space (known event position) for the detector described in the XMLFile:

```
>tesreconstruction Recordfile=inputEvents.fits TesEventFile=outputEvents.fits \
Rcmethod='SIRENA' PulseLength=1024 LibraryFile=libraryMultiE.fits mode=1 OFLib=yes\
FilterMethod=F0 clobber=yes intermediate=0 EnergyMethod=OPTFILT tstartPulse1=1000
tstartPulse2=21000 XMLFile=xifu_detector_hex_baseline.xml
```

- Energy reconstruction performed with the Covariance matrices algorithm in the current space (known event position) for the detector described in the XMLFile:

```
>tesreconstruction Recordfile=inputEvents.fits TesEventFile=outputEvents.fits
Rcmethod='SIRENA' PulseLength=1024 LibraryFile=libraryMultiE.fits mode=1
NoiseFile=noise1024samplesADC.fits clobber=yes intermediate=0 EnergyMethod=WEIGHT
tstartPulse1=1000 tstartPulse2=21000 XMLFile=xifu_detector_hex_baseline.xml
```

- Energy reconstruction performed with the (F0) optimal filtering algorithm in the
*I2RFITTED*Resistance space (known event position) for the detector described in the XMLFile, with filters calculates for every event:

```
>tesreconstruction Recordfile=inputEvents.fits TesEventFile=outputEvents.fits \
Rcmethod='SIRENA' PulseLength=1024 LibraryFile=libraryMultiE.fits mode=1 \
NoiseFile=noise1024samplesR.fits FilterMethod=F0 clobber=yes intermediate=0 \
EnergyMethod=I2R tstartPulse1=1000 tstartPulse2=21000 \
XMLFile=xifu_detector_hex_baseline.xml OFLib=no OFStrategy=FREE
```