\chapter{SpaCal Calibration}
\label{Cspacalib}

As it was mentioned in the last chapter, the measurement of the proton
structure function is only possible if the event kinematic is correct
and precise reconstructed. The resolution of the reconstruction methods rely
directly on the precision of the measurement of the angles and
energies of the scattered electron and of the hadronical final state. 
%Therefore the calibration of the SpaCal and LAr calorimeters has special
%importance.
 
Since the energy measurement represent the 
largest systematic source for the measurement of $F_2$ in the high $x$ 
region, it is important in analysis level to perform a detailed 
calibration of the energy measured by the SpaCal calorimeter.
In this chapter the calibration of the SpaCal calorimeter and the
determination of its uncertainty is explained.

\section{Calibration Method}
\label{SecCalibmethod}

\begin{figure}[t]
\begin{center}
\includegraphics[height=8.0cm]{./spacal/figures/egenrec.eps}
\includegraphics[height=8.0cm]{./spacal/figures/energyq2xv2.eps}
\caption{(a) Scattered electron energy distribution for DIS
  events at generator level (b) Kinematical plane trayectories for
  different scattered electron energies} 
\label{Figkinpeak}
\end{center}
\end{figure}

In DIS events at low values of $Q^2$, the energy distribution of the
scattered electron has a characteristic shape with a maximum close to
the electron beam energy and commonly is known as the {\it kinematic
  peak}. In Fig. \ref{Figkinpeak}(a) the energy distribution of the
scattered electron at generated level for a DIS selection is shown. 

The kinematical properties of events located in the kinematic peak
region, are unique and are used to determine the scale of the electron
energy measurement. In Fig. \ref{Figkinpeak}(b), the $Q^2-x$ plane is
shown with different contours of constant electron scattered energies.
If the energy of the scattered electron coincides with the energy of
the incoming electron, then the contour line does not depend on $Q^2$
for values of $x=E_{inc}/E_{p}=0.032$. This kinematic region is only
accesible for larger electron scattering angles as can be appreciate from
Fig. \ref{}. At this high value of $x$, the proton structure function
$F_2$ is approximately flat (see Fig. \ref{}), therefore events
located in the kinematic peak region are allmost independent of
structure function assumption and thus is an appropiate region to
perform calibration studies. 
%The kinematic peak region is exploited to calibrate the SpaCal calorimeter.  

The calibration of the SpaCal calorimeter begins in the data taking stage.
Variation of the gains of the photomultipliers are measured with the
help of the light-emiting-diode (LED) system situaded at the back side
of the calorimeter. Each photomultiplier recieves well defined constant
light pulses and afterwards photodiodes are used to identify
inestabilities of the LED intensity and thus any change of the
photomultiplier gain can be detected and corrected offline. 

After apply the correction factors of the LED system, the inner cells of 
the calorimeter are calibrated with events localized in the ``kinematic 
peak'' region \ref{}. Due to the decreasing statistic at larger $Q^2$
the outer  part of the calorimeter is calibrated with cosmic muons and proton
beam halo muons events \ref{}. 

Nevertheless a better calibration of the SpaCal calorimeter able to
reduce the uncertainty of the $F_2$ measurement at high values of $x$ 
can only be achieved in the analysis level. The energy calibration has
to provide: 

\begin{itemize}
  \item good energy resolution, therefore is vital to have a
  relative equalization of the response of the calorimeter
  cells.
  \item correct reconstruction of the event kinematic, therefore the
  absolute energy scale has to be determined.
\end{itemize}

The method used here to calibrate the Spacal calorimeter was
introduced in \ref{} and use events localized in the kinematic peak
region. The Spacal energy measurement is compared with a reference
energy obtained with the DA reconstruction method. 

There are another calibration procedures, one compares the energy
distribution of the data and the MC simulation in the kinematic peak
region, in a region where both distributions are of gaussian shape
\ref{}. Nevertheless this method is restricted by statistic due to the
degradation of the resolution of the event kinematic at large values
of $x$. This method is used in this analysis only as a cross check of
the calibration with the DA method.

\section{Calibration with the Double angle method}
\label{Secdacalibration}

As we have seen in section \ref{SubSecdamethod} the event kinematic
can be completely reconstructed using the angle of the scattered
electron $\theta_e$ and of the hadronic final state
$\theta_{had}$. This allows to derive the energy of the scattered
electron independently of the SpaCal measurement. The reference energy
is given by: 

\begin{equation}
E_{DA} = E_{inc} \frac{1-y_{DA}}{\sin ^{2} \theta_e /2}
\label{eqeda}
\end{equation}

where $Y_{DA}$ is given by Eq. \ref{kinda}. In order to reconstruct
the DA energy in the kinematic peak region, larger electron scattering
angles and low $y$ events are necessary (see Eq. \ref{eqeda}). 

The scattered electron angle $\theta_e$ is reconstructed by the BST or
by the BDC, therefore a well reconstructed vertex around $30\,$cm is
required.  


\begin{figure}[h]
\begin{center}
%\includegraphics[height=7.0cm]{./spacal/psnoise/edaresolnoise.eps}
\includegraphics[width=14.0cm]{./spacal/psnoise/edaresolnoise.eps}
\caption{}
\label{Figedanoise}
\end{center}
\end{figure}

Events at low $y$ are selected applying a cut on the hadronic angle
$\theta_{h} < 80 ^{\circ}$, this allows to have a maximum value of $y$ of
$\approx 0.15$. The influence of events at very low $y$ where the 
hadronic final state escape the detection in the forward direction was
suppresed requiring $\theta_{h}>15^{\circ}$. 

Since the DA method is sensitive to the level of noise in the
calorimeter, the hadronical angle is obtained, substracting the energy
which is identified as noise in the LAr calorimeter. In
Fig. \ref{Figedanoise} is shown the deviation of $E_{DA}$ 
from the generated energy when the noise substraction is
used (a) and not used (b). If the identified noise is not substracted,
the DA energy tends to be reconstructed to lower energies as it was
generated, this can creates a bias in the DIS selection, since the
reconstruction of the kinematic variables exclude the noise
contribution. The long tail of the distribution in
Fig. \ref{Figedanoise} is due to showering and to final state
radiation events, in such events the 
scattered electron radiates a photon but both the electron and the
photon build one cluster on the SpaCal. 

The calibration sample comprises in addition to the DA selection,
events where only one cluster in the SpaCal calorimeter is found and 
its energy lies in the kinematic peak region $20\,$GeV$<E_{e}<32\,$Gev
and have a Moliere radius less than $4\,$cm. The resolution between
the generated energy and the reconstructed energy measured by SpaCal
for the DA selection is shown in Fig. \ref{Figspakinrec}(b). A
deviation up to $2\%$ of the generated variable $E_{gen}$ is observed
in case of the SpaCal reconstruction, meanwhile the DA has a precision
up to $0.2\%$.  

\begin{figure}[t]
\begin{center}
%\includegraphics[height=7.0cm]{./spacal/figures/egenrec.eps}
\includegraphics[width=12.0cm]{./spacal/psnoise/edaresol.eps}
\caption{(a) Generated and Reconstructed Energy distribution of the
  scattered electron. (b) Resolution of the reconstructed energy
  measured by SpaCal (area distribution) and determined by the Double 
  angle method (solid line)}
\label{Figspakinrec}
\end{center}
\end{figure}

The calibration procedure is an iterative process, where the reference
energy $E_{DA}$ is compared to the measured energy $E_{SpaCal}$ for
the DA selection. The calibration gain factors 
are thus obtained as the deviation of $\delta = E_{DA}/E_{SpaCal}$ to
one. In order to ensure homogeneity over the whole
spacal plane the following calibration factors are required:

\begin{itemize}
\item Gains factors for each cell of the calorimeter.
\item Calibration factors which correct for the losses of energy due
  to the SpaCal 16-cell module geometry.
\item Calibration factors as function of the transversal distance of
  the impact point of the scattered electron to the beam pipe $R_{Spa}$.
\end{itemize}

\subsection{Cell Gains}

The first calibration constants are derived for each cell of the
SpaCal calo\-rimeter. As we have seen from section X, the energy
measured by SpaCal is constructed as the sum of the energies of
the cells which take part of the electron cluster. 

\begin{equation}
E_{SpaCal} = \sum_{cell_i} E(cell_i)
\label{EqenergySpa}
\end{equation}

\begin{figure}[t]
\begin{center}
\includegraphics[height=7.0cm]{./spacal/figures/celldelta.eps}
\caption{$\delta$ pull distributions for two cells of the SpaCal
  calorimeter. The dashed line correspond to the first gain determation
  meanwhile the solid line is the pull distribution obtained after
  eight iterations}
\label{Figpulliter1}
\end{center}
\end{figure}

For each event of the calibration selection, the $\delta$ pull
distribution 

\begin{equation}
\delta = \frac{E_{DA}}{E_{SpaCal}}w_{i} \hspace{2cm} w_{i} =
\frac{E_{i}}{E_{SpaCal}} 
\label{Eqpulldist}
\end{equation}

for each cell which belongs to the electron cluster is constructed.

Each cell contributes to the pull distributions of the entire sample,
with a weight $w_{i}$ given by the fraction of its measured energy to the
total energy of the cluster. The deviation of the pull 
distributions to $1$ give the gain with which the cell has to be
corrected. Fig. \ref{Figpulliter1} show the pull
distribution for two cells of the SpaCal calorimeter. The deviation of
$\delta_{cell_i}$ to one is obtained using a robust fit which removes 
the outliers of the distribution.

\begin{figure}[t]
\begin{center}
\includegraphics[height=7.0cm,width=12cm]{./spacal/figures/gainsvalplot.eps}
\includegraphics[height=7.0cm]{./spacal/figures/eoldnew_mc.eps}
\includegraphics[height=7.0cm]{./spacal/figures/eoldnew_data.eps}
\caption{Calibrated and uncalibrated energy distributions for (a)
  MC and (b) data of the shifted vertex period.}
\label{Figgainsdatamc}
\end{center}
\end{figure}

In order to ensure convergence of the calibration method, an iterative
gain determination of the cells is performed. The gains of the second 
iteration use the gains obtained by the first one, thus the weight of
the pull distribution change according:

\begin{equation}
\delta_{cell_i}^{it+1} = \frac{E_{DA}}{\sum_{i} E_{i}(1+g_{i}^{it})}
\, w_{i}^{it} \hspace{2cm} w_{i}^{it} =
\frac{E_i(1+g_{i}^{it})}{\sum_{i} E_{i}(1+g_{i}^{it})} 
\label{Eqdeltai}
\end{equation}

Usually 3 or 4 iterations are needed to obtain a stable gain factor. 
In Fig. \ref{Figpulliter1} are shown the pull distributions of the same
cells of (a) (b), after 8 iterations.  
The gain factors correct the energy measurement between $2\%$ and
$3\%$ and its value as function of the cell number are
shown in Fig. \ref{Figgainsdatamc}(a). In Fig. \ref{Figgainsdatamc}(b)
the energy distributions of the electron candidate for Data and MC are
shown before and after the gains are applied. 

\subsection{Inbox Corrections}

\begin{figure}[t]
\begin{center}
\includegraphics[width=5.0cm]{./spacal/figures/spamodule.eps} 
\caption{Schematic view of one module of the SpaCal calorimeter. Cells in the
  middle, corner and border define the topology 1,2 and 3 respectively.}
\label{Figspamodulecol}
\end{center}
\end{figure}

As we have seen in section \ref{Secspacalcalorimeter}, the Spacal
calorimeter is constructed of super\-mo\-dules containing
16-cells. Therefore, energy losses due to the dead material present
between the supermodules is expected. Cells placed in the corner of
the module are more afected by energy losses than the cells
situated in the middle of the 16-cell module.

In order to compasate for this losses, the measurement of the energy
is corrected as function of the impact point of the electron candidate
inside the cell. The cell is divided in a grid with spacing of
$8\,$mm. In order to determine the position of the electron candidate
inside the cell, the coordinates in the spacal plane of the hottest
cell are used.   

Three inbox corrections depending of its position inside the module
are defined. In  Fig. \ref{Figspamodulecol} are shown the three types of cell
configuration used. The cells situated in the middle, corner and border
defines the topology 1,2 and 3.

\begin{figure}[t]
\begin{center}
\includegraphics[width=14.0cm,height=7.5cm]{./spacal/figures/inboxcorr.eps}
\caption{Calibration factors for the different cell topology inside
  the module.}
\label{Figinboxcor}
\end{center}
\end{figure}

\begin{figure}[t]
\begin{center}
\includegraphics[width=6.5cm]{./spacal/figures/ps/gains_calib.eps}
\includegraphics[width=6.5cm]{./spacal/figures/ps/inbox_calib.eps}
\includegraphics[width=6.5cm]{./spacal/figures/ps/crack_calib.eps}
\includegraphics[width=6.5cm]{./spacal/figures/ps/all_calib.eps}
\caption{Uncalibrated and calibrated $E_{DA}/E_{SpaCal}$ distribution
  as function of $R_{spa}$.}
\label{Figgainresult}
\end{center}
\end{figure}

The corrections are derived using the same DA selection as in the
the gain determination. Since the insert module have cells with
different geometry and are afected by leakage, a radius centimeter cut
was in addition applied. The inbox corrections are obtained again
as the deviation of the pull distribution $\delta$ to one, as a
function of the impact point inside the cell. 

In Fig. \ref{Figinboxcor} are shown the correction factors for Data
and MC due to the cracks between the modules. For Data, cells in the
corner are corrected up to $2\%$ menwhile $1\%$ of correction is
obtained by the border cells and up to $0.5\%$ for the cells located
in the middle of the module. 

Another source of energy losses in the calorimeter are due to the
inhomogeneity of the SpaCal cells inside the module. Since the variable 
$R_{box} = abs(x_{cell},y_{cell})$ cover the calorimeter surface in
squares, it was used to correct the energy losses between the
cells. This procedure correct the energy measurement only $0.5\%$ in addition.
Fig. \ref{Figgainresult} show the deviation of the energy measurement
from the reference energy $E_{DA}$ as a function of $R_{SpaCal}$ after
each calibration step. 

\subsection{Radial Corrections}

\begin{figure}[t]
\begin{center}
\includegraphics[width=14.0cm,height=7.5cm]{./spacal/figures/radial_check.eps}
%\includegraphics[width=14.0cm,height=7.5cm]{./spacal/figures/energytotal.eps}
\caption{$\pi^{0}$ mass reconstruction on Spacal calorimeter, before
  and after the energy calibration is applied.}
\label{Figradialcheck}
\end{center}
\end{figure}

As we can see from Fig. \ref{Figgainresult}(a)-(c) after the gains and
inbox calibration factors are applied, a significant improvement of
the measured energy is achieved. Nevertheless a radial dependence,
of the calibrated $\delta$ pull quantity up to $1.2\%$ is
observed. Such deviation is probably due to the dead material located
in front of the Spacal calorimeter. This dependence is cured
obtaining the last calibration factors as function of the measured
radius $R_{SpaCal}$. In Fig. \ref{Figradialcheck} (a)
is shown the radial dependence of $\delta$ after the total
calibration procedure is applied, differences between data and MC does
not exceed $0.2\%$ allmost for all the covered radius in spacal. 

In Fig. \ref{Figtotenergy} is shown the comparison of data and MC for
the energy measurement before and after the calibration is applied.


\section{Hottest cell calibration}

The hottest cell calibration method uses as well the kinematic peak
region to derive individual cell calibration factors. In contrary to
the DA method, the Spacal measurement of the electron cluster is
directly compared with the MC simulation.

In order to have a electron energy distribution with a gaussian
shape allmost free of tails, the calibration sample uses the
following selection:

\begin{itemize}
\item Events in which the electron cluster has a energy between $20$
  and $30\,$GeV and a cluster radius less than $4\,$cm.
\item Radiative events are reduced allowing a maximum value
  of $y$ of $0.05$.
\item The noise contribution is supressed applying $y>0.005$.
\end{itemize}

With such selection, one obtains energy distributions as the ones
showed in Fig. \ref{}. The calibration factors are derived as:  

\begin{equation}
g_{i} = \frac{<E_{cl,i}^{MC}>}{E_{cl,i}^{Data}}
\end{equation}

where $<E_{cl,i}>$ is the mean of the electron cluster energy, which 
is assigned to the hottest cell $i$.  Nevertheless, the statistic of
the sample decreases considerably and individual calibration factors
can be determined only for the inner cells.

Since in the last sections, Data and MC were calibrated with the DA
method, the Hottest cell calibration selection is used only to probe the DA
calibration in a different kinematic region where the effect of the
tails due to radiative events is reduced.

In Fig. \ref{} the cell distributions for the hottest cell calibration
selection are shown. It is remarkable that there is no shift between
Data and MC for allmost all cells. Cells 26,31,29 has to be excluded
of the analysis due the bad shape distribution.

\section{Energy measurement at low Energies}

As was shown in the previous sections, the DA calibration is performed
with electron clusters which energy lies in the kinematical peak
region. Comparison between the data and the MC simulation reveleas that 
the energy measurement has a scale uncertainty of $0.2\%$ in kinematic
peak. A natural question is how the scale uncertainty changes for cluster
with energies lower than $27.5\;$GeV, and how is the behaviour of
the scale uncertainty over the SpaCal plane. 

\begin{figure}[t]
\begin{center}
\includegraphics[width=14.0cm,height=7.5cm]{./spacal/figures/studyp0/studyp0_050815_1246_invmass.eps}
\caption{$\pi^{0}$ mass reconstruction on Spacal calorimeter, before
  and after the energy calibration is applied.}
\label{Figp0peak}
\end{center}
\end{figure}

One method used to study the scale uncertainty of the 
energy measurement of the SpaCal calorimeter towards lower energies,
uses the reconstruction of the invariant mass of $\pi^{0}$ decays.
The invariant mass is calculated according to:

\begin{equation}
m_{\pi^{0}} = \sqrt{2E_{\gamma 1}E_{\gamma 2}(1-\cos \theta_{\gamma \gamma})}
\label{Eqp0}
\end{equation}

\noindent where $E_{\gamma 1}$ and $E_{\gamma 2}$ are the energies of
the photons and $\theta_{\gamma \gamma}$ is the opening angle.
In order to supress background from random coincidences in the
$\pi^{0}$ mass reconstruction sample, the following selection was
applied:

\begin{itemize}
\item Events having only two clusters in the spacal calorimeter and
  trigerred by S9 are used, therefore one of the clusters has to have
  as minimal energy $0.7$GeV. 
\item In order to measure a precise separation angle, just events
  having a good reconstructed vertex around $30\,$cm are used.
\item A minimal distance of $10\;$cm between the clusters is applied
  to avoid overlap between the selected clusters 

% In order to avoid overlap between the selected clusters a minimal
%  distance of $10\;$cm between the clusters is applied.
\end{itemize}

In Fig. \ref{} are shown the control distributions of the selected
events, normalized with area. We can observe a resonable agreement between
the data and monte carlo selected events.
In Fig. \ref{Figp0peak} is shown the reconstructed mass of the
$\pi^{0}$ decays for Data and Django MC before and after the kinematik
peak calibration is applied. The comparison between the
two curves reveals a shift of the data reconstructed mass distribution. The
shift is studied using the Kolmogorov-Smirnov (KS) test of the
invariant mass sample as function of three variables:  

\begin{itemize}
\item The separation of the photon cluster. 
\item The minimal energy of the cluster 
\item The maximal energy of the cluster 
\end{itemize}

The KS-Test move the MC distribution. A shift of $1.8\%$ is
observed. Correcting the Data for this shift, the agreement between
the two invariant mass distributions improves. In order to determine
the error on this scale uncertainty, several checks to the $\pi$
invariant mass selection are performed. 

Since the $\pi ^{0}$ is a two body decay process, a reweight
on the minimal energy to the $\pi$ selection is applied. The agreement
between data and MC improves as can be observed in Fig. \ref{}. The remaining
discrepancies defines the uncertainty of the scale at $\pi$ mass and
does not exceed $1\%$.   

\begin{figure}[h]
\begin{center}
\includegraphics[width=14.0cm,height=5.5cm]{./spacal/figures/studyp0/studyp0_050815_1246_sep_invmass.eps}
\caption{}
\label{Figp0sep}
\end{center}
\end{figure}

\begin{figure}[h]
\begin{center}
\includegraphics[width=14.0cm,height=5.5cm]{./spacal/figures/studyp0/studyp0_050815_1246_mine_invmass.eps}
\caption{}
\label{Figp0sep}
\end{center}
\end{figure}

\begin{figure}[t]
\begin{center}
\includegraphics[width=14.0cm,height=5.5cm]{./spacal/figures/studyp0/studyp0_050815_1246_maxe_invmass.eps}
\caption{}
\label{Figp0sep}
\end{center}
\end{figure}


\section{Energy measurement Uncertainty}

The spacal uncertainty measurement is given by 

\begin{itemize}
  \item $0\% \pm 0.2 \%$ at kinematic peak
  \item $2.5 \%$ at $\pi$ Energy
\end{itemize}

the energy is corrected linearly.


