\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 reference energy is obtained with the DA reconstruction
method. 


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


Another calibration procedure 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$. In this
analysis this method is used as a cross check of the calibration with
the DA method.

%For another hand the kinematic peak region is restricted by statistic due
%to the degradation of the resolution of the event kinematic at large
%values of $x$ and this is the reason why here the reference energy
%used to calibrate is obtained by means of the DA method.

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

\begin{figure}[t]
\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}

As we have seen in section \ref{SubSecdamethod} the event kinematic
can be completely reconstructed using the scattered electron and hadronic
angles. This allows to derive the energy of the scattered electron
independently of the SpaCal measurement. The energy determined by the
double angle method 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} and depend only on the
measurement of $\theta_e$ and $\theta_h$.

The calibration sample comprises events which energy lies in the
kinematic peak region $20\,$GeV$<E_{e}<32\,$Gev. 


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

In order to select low $y$ events, the region where the $DA$ method is
better precise, a cut on $\theta_{h} < 80 ^{\circ}$ was applied. 
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, in the cases where the noise substraction is
used (a) and not used (b).


\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}

In Fig. \ref{Figspakinrec}(a) the energy distribution of
the scattered electron for the DA selection for Django MC is
shown. The full line corresponds at generator level and the dashed
line represent the 
SpaCal calorimeter measurement. One can clearly see that once the
detector response is applied, the energy of the scattered electron 
is reconstructed to higher energies in comparison as it was generated.
The resolution between the generated energy and the reconstructed
energy measured by SpaCal
for the DA selection is shown in 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\%$.  

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 a good calibration 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 reconstructed 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, $\delta$ pull distributions
of the cells which belongs to the electron cluster are constructed. 
Each cell contributes to the pull distributions of the entire sample,
with a weight 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. The dashed lines in 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 also shown the gains obtained 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 hottest cell is used to determine the position
of the electron candidate inside the cell. 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 and as a function of the impact point
inside the cell. The cell is divided in a grid of $8\,$mm, having then
$25$ calibration factors for each cell configuration. 

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 $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 vary
between $0.2\%$ and $0.6\%$ depending the position in the 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. Therefore 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$. In order to have a distribution
of the electron with a gauss shape, allmost free of tails, the
following selection is applied:

\begin{itemize}
\item radius lcluster cut -? reduce proton beam background
\item $y<0.05$ region to reduce radiative events and $y>0.005$ to
  supress noise 
\end{itemize}

Since in the last section, Data and MC were calibrated with the DA
method, the Hottest cell calibration selection is used to probe the DA
calibration and to check the resolution of the individual SpaCal cells. 


\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\%$. 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}$ 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 between 30 cm are used.
\item 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 good 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. 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}

In order to study the 


\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}


\subsection{Energy Uncertainty at $\pi ^{0}$ mass}

The uncertainty of this $2.5\%$ was studied variyng differentes
quantities of the reconstructed invariant mass sample. This conduces
to a uncertainty of $1\%$



\section{Energy Scale}


%The reconstruction of the invariant mass of $\pi^{0} \rightarrow
%\gamma \gamma$ decays, is used to study the scale uncertainty of the
%energy measurement for low energetic clusters. 

