%format: latex  %hyphen: english
%
%
%              LEAR Crystal Barrel Experiment, PS 197
%
%               CRYSTAL DATA RECONSTRUCTION SOFTWARE
%               ====================================
%
%         This documentation is available as CB-Note 92 Rev.12
%
%  used format:
%  banks: {\bf BANK}
%  commons,variables: {\sc /common/} {\sc var}
%  subroutine: NAME
%
\documentstyle[12pt,twoside]{article}


%   DINA4 format DESY
\newlength{\dinwidth}
\newlength{\dinmargin}
\setlength{\dinwidth}{21.0cm}
\textheight24.2cm \textwidth17.0cm
\setlength{\dinmargin}{\dinwidth}
\addtolength{\dinmargin}{-\textwidth}
\setlength{\dinmargin}{0.5\dinmargin}
\oddsidemargin -1.0in
\addtolength{\oddsidemargin}{\dinmargin}
\setlength{\evensidemargin}{\oddsidemargin}
\setlength{\marginparwidth}{0.9\dinmargin}
\marginparsep 8pt \marginparpush 5pt
\topmargin -42pt
\headheight 12pt
\headsep 30pt \footheight 12pt \footskip
24pt
% end dina4p definition

\title{ \makebox[\textwidth][r]{\normalsize CB-Note 92 Rev.12}\\[2cm]
        LEAR Crystal Barrel Experiment, PS 197\\
        Crystal Data Reconstruction Software Ver. 2.02/01}
 \author{F.-H. Heinsius\\
         T. Kiel\\
         P. Schmidt\\
         I.\,Institut f\"ur Experimentalphysik\\
         Universit\"at Hamburg}
\date{January 23, 1995}
\begin{document}
%
 \maketitle
\newpage
%
 \tableofcontents
%
 \listoftables
\markboth{Crystal Data Reconstruction Software}{Crystal Data
Reconstruction Software}
 \listoffigures
\markboth{Crystal Data Reconstruction Software}{Crystal Data
Reconstruction Software}
\pagestyle{myheadings}
\newpage
%
 \section{Introduction}
\markboth{Crystal Data Reconstruction Software}{Crystal Data
Reconstruction Software}
\pagestyle{myheadings}
This document describes the {\em crystal data reconstruction software}.
This software analyses one event only on the basis of the crystal data.
The main results are the data of the Particle Energy Depositions (short
PED\footnote{It was decided to use this term on July 13, 1988 at the
software meeting in Karlsruhe.}), that is energy (in MeV), direction
cosines, etc. These are stored in the {\bf TBTK} linear structure which
is described in chapter \ref{chaptbtk}. Note that the global
identification character for the {\em crystal data reconstruction
software} is 'BC' (exceptions: BGTNBR, BITOPT).

Energies are quoted in MeV, angles in rad. Except routine BCANGL, which returns
angles in degree.
Two numbering schemes are used for the
crystals: {\em ($\varphi$,$\vartheta$)} with {\em $\varphi =1,60$} and
{\em
$\vartheta =1,26$} and as a shorter form\footnote{The short form is only
used in the {\bf TBCL} and {\bf TBEN} banks, which are rarely used for
physics analysis. It gives certain advantages in storage usage and
coding.}: {\em index $= \varphi + (\vartheta -1)\cdot 60$}.
Transformation from index to {\em ($\varphi$,$\vartheta$)} is done with
subroutine BITOPT.

\begin{center}
{\bf Warning:}
\end{center}
\begin{quote}
ECLUBC and EPEDBC set to 20 MeV by default, old value was 10 MeV.
This should result in less electromagnetic split offs.
A new energy correction method is introduced, see routine BCEGAM. This
is used for new calibrations.
A new variable (MOKFBC) allows a higher threshold for FERAs if the
corresponding 2282 is ok. (Version 1.43)

Due to an error in the covariance error matrix it is needed to call routine
BCTTKS for all data produced before version 1.41/01.
Energy resolution default changed to 2.8\% (Version 1.41).
This can be changed in already produced data by calling BCTTKS (see the
description of it).
Energy dependent errors for direction cosines.
Lower cutoff energy for the FERA (20 ADC counts) (Version 1.4).
Lower cutoff energy for the 2282 ADCs introduced (in Version 1.1).
The cuts ECLUBC and EPEDBC are done before the energy correction!
So the minimum photon energy is slightly above 20 MeV.
\end{quote}

\begin{center}
{\bf Note:}
\end{center}
\begin{quote}
For version 2.00/03
a {\bf new algorithm} for the calculation of PED directions has been
{\em optionally} included (subroutines {\sc bcnped}).
It determines the four-momentum by the energy of the sum of nine
crystals instead of the sum of all crystals in the cluster. Furthermore all
crystals involved are weighted due to their topology and PED energy.
 Additionally in case of n PEDs in one cluster the energy of the
overlapping crystals (i.e. crystals neighbouring two or more local maxima) is
divided according to the energies of the n local maxima (in {\sc
bcnped}). Include this algorithm with the additional '{\bf PDRG}'
parameter.
Alternatively N.Hesseys PED-smoothing algorithm  can be incorporated by
using the additional
'{\bf PDSM}' parameter. PED-smoothing includes the following
subroutines {\sc bcpoly,bcpcor, bcsini, xyzrtp, rtpxyz}. Please note, that
at this moment people are not advised to use both codes simultaneously.
So, when using one of these algorithms, your {\bf XTAL} card should read
like this:

XTAL 'DECF' 'DECL' 'TRAK' 'ALCE' 'CLST' 'PEDS' {\bf 'PDSM' (or 'PDRG')}

Further note:
to distinguish different production methods some bits are set in
IQ(LTBTK):\\
Bit 0: Event has PED with crystal type 13 \\
Bit 1: New energy correction used\\
Bit 2: PED smoothing enabled\\
Bit 3: New algorithm for one and n PED/cluster enabled 'PDRG'\\

Above all the direction of each crystal, determined in {\sc bcosxt} is
calculated due to the centre of area instead of its geometrical centre.
{\sc bcpeds} has been duly updated, another new subroutine has been
added {\sc bcosx9} replacing {\sc bcoscl}, which has been kept in in the
software paket in case of need.

New subroutines for the {\sc dolby} split-off recognition by N.Hessey
are included in the code (for detailed description see CB - Note 199):
{\sc dbccoa, dbcini, dbcnos, dbcspl} and the {\sc smart} algorithm by
J.Salk (see CB-Note 182, performance studies of {\sc dolby-c, smart}
CB-Note 216). The {\sc smart} code involves the following routines:
{\sc bsmart, bcnxtp, bcosc2}.

New user routine BCVROC to do the inverse of the vertex correction
routine BCVCOR.
Subroutine BCALCE changed to allow for gain correction from lightpulser.
(Version 1.43)
New routines to handle covariance error matrices added for use with
PI0FND (Version 1.42).
In addition to the vertex for neutral particles a z-disalignment between
the two barrel halfs is allowed.
See common {\sc /bcvrtx/}.
Function BCVRSN is now obsolete; the version number is taken directly
from CMZ (Version 1.41). (If you still use PATCHY you might get an old
version number and a missing sequence, but that does not affect the
code.)
The energy calculation in BCALCE was modified to allow to correct for
electronic problems e.g. nonlinearity (see BCLINE).
Subroutine to recalculate errors with given energy resolution
in global track bank (BCTTKS).
User callables subroutines MCKINE and MCVERT to print the
{\bf VERT} and {\bf KINE} banks. (Version 1.4)

This production release includes an energy correction function for the PEDs to
give correct energies. (Its tested for GCB 4.02 Monte Carlo single photons.)
To analyze Monte Carlo data produced {\em before} GCB version 4.02 you have to
apply the patchy flag {\tt MC}.
(This feature will be deleted in a future release, as the old MC data is wrong).
The usercallable subroutine BCMCOR tries to correlate reconstructed
PEDs with the particles created in the Monte Carlo.

\end{quote}

Please report any errors found in the
software immediately to:
\begin{description}
\item[Michael Doser] (DOSER@CERNVM)
\item[Fritz-Herbert Heinsius] (F31HEI@DHHDESY3)
\item[Torsten Kiel] (I04KIE@DHHDESY3)
\end{description}

The structure of this document is copied from the {\em chamber
reconstruction software} description written by Curtis A. Meyer.

This software is part of the Crystal Barrel offline software. It is available
on the general group accounts on the CB-DECstations,
VSXTAL Vax and on CERNVM (Ask the
Softwaremanager Michael Doser for more information).
Send comments to the authors of this document.

 \section{Data Banks for the Barrel Calorimeter}
This section describes all Zebra banks used by the crystal data
reconstruction software. Figure~\ref{banks} shows the main connections
of the banks {\em created} by this software. These banks contain only
the data of one event. (Not shown are the calibration banks.)
The first word of the {\bf HTBC} bank is the integer version number of
the software. It has 5 down links: -1 points to the {\bf TBEN} bank, -2
to the {\bf TBCL}, -3 to the {\bf TBTK}, -4 to the {\bf TBEF} and -5 to
the {\bf TBEL} bank.
\setlength{\unitlength}{0.8cm}
\begin{figure}[htbp]
\centering
\begin{picture}(18,9)
\put( 5.0, 7.0){\vector(0,-1){ 1.0}}
\put( 4.0, 5.0){\framebox(2,1){\bf HTBC}}
\put( 5.0, 5.0){\vector(0,-1){ 1.0}}
\put( 1.0, 4.0){\line(1, 0){16.0}}

\put( 1.0, 4.0){\vector(0,-1){ 1.0}}
\put( 0.0, 2.0){\framebox(2,1){\bf TBEN}}
\put( 5.0, 4.0){\vector(0,-1){ 1.0}}
\put( 4.0, 2.0){\framebox(2,1){\bf TBCL}}
\put( 9.0, 4.0){\vector(0,-1){ 1.0}}
\put( 8.0, 2.0){\framebox(2,1){\bf TBTK}}

\put(13.0, 4.0){\vector(0,-1){ 1.0}}
\put(12.0, 2.0){\framebox(2,1){\bf TBEF}}
\put(17.0, 4.0){\vector(0,-1){ 1.0}}
\put(16.0, 2.0){\framebox(2,1){\bf TBEL}}
%
\put( 9.0, 2.0){\vector(0,-1){ 1.0}}
\put( 8.0, 0.0){\framebox(2,1){\bf TBTK}}
\put(10.0, 0.5){\vector(1, 0){ 2.0}}
\put(12.0, 0.0){\framebox(2,1){\bf TBTK}}
\put(14.0, 0.5){\vector(1, 0){ 2.0}}
\put(16.0, 0.0){\framebox(2,1){\bf TBTK}}
%
%
\end{picture}
\caption{Structure of the banks}
\label{banks}
\end{figure}
\setlength{\unitlength}{1mm}

\newpage
 \subsection{Description of the Barrel Calorimeter Calibration Banks}
The calibration banks are loaded from the
database into the ZEBRA store at the beginning of each run.
 \subsubsection{CBPF and CBPL}
In the {\bf CBPF} and {\bf CBPL} banks are the pedestals for the FERA
and for the LeCroy 2282 ADC systems stored, see table \ref{tablecbpl}.
\begin{table}[htb]
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} \\ \hline
 $+\varphi + (\vartheta -1)\cdot 60$ & {\sc real} &
                        {\it Pedestal} [ADC-Channel] \\
$\vdots$ & $\vdots$ & $\vdots$ \\ \hline
$ +1561 $ & {\sc real} & {\it Threshold} [ADC-Channel] \\ \hline
\end{tabular}
\caption{Data stored in the {\bf CBPL} and {\bf CBPF} bank (Pedestals LeCroy,
FERA)}
\label{tablecbpl}
\end{table}

 \subsubsection{CBTF}
The {\bf CBTF} bank is temporary over one run and holds the thresholds above the
pedestal for the FERA ADC System, see table \ref{tablecbtf}. If the rounded
value of the pedestal plus threshold is less than 255 then (-1) $\times$
threshold is stored in
the bank otherwise the pedestal is stored (because then the FERA data is not
pedestal subtracted, but this should be only in case of bad hardware).
\begin{table}[htb]
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} \\ \hline
 $+\varphi + (\vartheta -1)\cdot 60$ & {\sc integer} &
                        {\it negative offset to pedestal} [ADC-Channel] \\
$\vdots$ & $\vdots$ & $\vdots$ \\ \hline
\end{tabular}

\caption{Data stored in the {\bf CBTF} bank (Thresholds for FERA)}
\label{tablecbtf}
\end{table}

 \subsubsection{CBEF and CBEL}
In the {\bf CBEF} and {\bf CBEL} banks are the energy
constants for the FERA and for the LeCroy 2282 ADC systems stored, see
table \ref{tablecbel}.

\begin{table}[htb]
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} \\ \hline
 $+\varphi + (\vartheta -1)\cdot 60$ & {\sc real} & {\it Slope
 (Energy/ADC-Channel)} [MeV] \\
$\vdots$ & $\vdots$ & $\vdots$ \\ \hline
\end{tabular}
\caption{Data stored in the {\bf CBEL} and {\bf CBEF} bank (Calibration
constants LeCroy, FERA)}
\label{tablecbel}
\end{table}

 \subsubsection{CBXF and CBXL}
The {\bf CBXF} and {\bf CBXL} banks contain a list of the
the FERA and LeCroy 2282 ADCs which are not used for energy
calculation, see table \ref{tablecbxl}.

\begin{table}[htb]
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} \\ \hline
 +1 & {\sc integer} & {\it Number of bad channels N} \\
 +2 & {\sc integer} & {\it ($\varphi$,$\vartheta$) of first bad channel} \\
$\vdots$ & $\vdots$ & $\vdots$ \\
 +N+1 & {\sc integer} & {\it ($\varphi$,$\vartheta$) of last bad channel} \\
 \hline
\end{tabular}
\caption{Data stored in the {\bf CBXL} and {\bf CBXF} bank (Bad unused
channels LeCroy, FERA)}
\label{tablecbxl}
\end{table}

 \subsubsection{CBCF and CBCL}
In the {\bf CBCF} and {\bf CBCL} banks are correction functions
for nonlinear channels of
the FERA and LeCroy 2282 ADC channels stored
(table \ref{tablecbcl}). For a description of the correction function see
subroutine BCLINE.

\begin{table}[htb]
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} \\ \hline
 -K & {\sc reference link} & {\it Pointer to type of correction
                                function} N\\
$\vdots$ & $\vdots$ & $\vdots$ \\
 -1 & {\sc reference link} & {\it Pointer to type of correction
                                function} 1\\ \hline
{\sc lq($\uparrow$)} & & \\ \hline \hline
{\sc iq($\downarrow$)} & & \\ \hline
 +1 & {\sc integer} & {\it Number of correction functions N} \\
 +2 & {\sc integer} & {\it ($\varphi$,$\vartheta$) for first
                                correction function} \\
$\vdots$ & $\vdots$ & $\vdots$ \\
 +N+1 & {\sc integer} & {\it ($\varphi$,$\vartheta$)
                                  for Nth correction function} \\ \hline
 +N+2 +0 & {\sc integer} & {\it type of first correction function} \\
 +N+2 +1& {\sc integer} & {\it number of real parameters K} \\
 +N+2 +2& {\sc real} & {\it parameter 1} \\
 +N+2 +K+2 & {\sc real} & {\it parameter K} \\
$\vdots$ & $\vdots$ & next correction functions \\ \hline
\end{tabular}
\caption{Data stored in the {\bf CBCL} and {\bf CBCF} bank (Nonlinear
channels LeCroy, FERA)}
\label{tablecbcl}
\end{table}

 \subsection{Description of the Barrel Calorimeter Data Banks}
 \subsubsection{TBEL and TBEF}
In the {\bf TBEL} bank are pedestal subtracted ADC counts from the 2282 ADC
system stored, in the {\bf TBEF} bank from the FERA ADC system. They are
calculated from the {\bf RBCL} and {\bf RBCF} banks with the subroutines BCDECL
and BCDECF. Note that in the {\bf TBEL} bank is no entry if the 2282 ADC is in
overflow (i.e. greater than {\sc maxlbc} of common {\sc /bccuts/}) or
less than the threshold {\sc minlbc} of common {\sc /bccuts/}.
\begin{table}[htb]
\label{tabletbel}
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} \\ \hline
 +1 & {\sc integer} & {\it Number of crystals} N \\ \hline\hline
\multicolumn{3}{|c|}{The following block is repeated {\it N} times for
every crystal (I=1,N)} \\ %
                                                                \hline
 $+2 \cdot I  $ & {\sc integer} & {\it ($\varphi$,$\vartheta$)} \\
 $+2 \cdot I+1$ & {\sc integer} & {\it ADC counts pedestal subtracted} %
       \\ \hline
\end{tabular}
\caption{Data stored in the {\bf TBEL} and {\bf TBEF} bank (ADC counts, pedestal
subtracted)}
\end{table}
\begin{itemize}
\item {\it Number of Crystals} for which are entries in this bank.
\item {\it ($\varphi$,$\vartheta$)} coordinates of crystals as
 index $=\varphi + (\vartheta -1)\cdot 60$
\item {\it ADC counts pedestal subtracted} is the pedestal subtracted ADC count
(in integer) of crystal ($\varphi$, $\vartheta$).
\end{itemize}

 \subsubsection{TBEN}
In the {\bf TBEN} bank are the calibrated crystal energies stored, as
calculated from the {\bf TBEL (RBCL)} and {\bf TBEF (RBCF)} bank
with subroutine
BCALCE. It will be created also if no crystal energy data exists, but
then the first data word (number of crystals) will be 0.
The first bit of the status bits (i.e. word IQ(LTBEN)) is set to 1 for
new calibrations which requires the usage of the BCEGAM energy
correction.
\begin{table}[htb]
\label{tabletben}
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} \\ \hline
 +1 & {\sc integer} & {\it Number of crystals} N \\ \hline\hline
\multicolumn{3}{|c|}{The following block is repeated {\it N} times for
every crystal (I=1,N)} \\ %
                                                                \hline
 $+2 \cdot I  $ & {\sc integer} & {\it ($\varphi$,$\vartheta$)} \\
 $+2 \cdot I+1$ & {\sc real   } & {\it Energy of crystal} I [MeV]\\\hline
\end{tabular}
\caption{Data stored in the {\bf TBEN} bank (crystal energies)}
\end{table}
\begin{itemize}
\item {\it Number of Crystals} for which are entries in this bank.
\item {\it ($\varphi$,$\vartheta$)} coordinates of crystals as
 index $=\varphi + (\vartheta -1)\cdot 60$
\item {\it Energy of crystal} is the deposited energy in crystal
($\varphi$, $\vartheta$) in MeV.
\end{itemize}

 \subsubsection{TBCL}
The {\bf TBCL} bank contains for every cluster a list of the crystals in
that cluster. See table \ref{tabletbcl}, an example can be found
in table \ref{tabletbclex}.
\begin{table}[htb]
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} \\ \hline
 -K & {\sc reference link} & {\it Pointer to Number of crystals}\\
    &                      & {\it in cluster} K\\
$\vdots$ & $\vdots$ & $\vdots$ \\
 -1 & {\sc reference link} & {\it Pointer to Number of crystals}\\
    &                      & {\it in cluster} 1\\ \hline
{\sc lq($\uparrow$)} & & \\ \hline \hline
{\sc iq($\downarrow$)} & & \\ \hline
 +1 & {\sc integer} & {\it Number of clusters} K \\ \hline\hline
\multicolumn{3}{|c|}{The following block is repeated {\it K} times for
every cluster (J=1,K)}\\%
                                                                \hline
LQ(LTBCL-J)+0 & {\sc integer} & {\it Number of crystals} N \\
 +1 & {\sc integer} & {\it ($\varphi$,$\vartheta$)} \\
$\vdots$ & $\vdots$ & $\vdots$ \\
 +N & {\sc integer} & {\it ($\varphi$,$\vartheta$)} \\ \hline
\end{tabular}
\caption{Data stored in the {\bf TBCL} bank (list of clusters)}
\label{tabletbcl}
\end{table}

The reference link J of the {\bf TBCL} bank points to the
number of crystals in cluster J.
                    A cluster is defined as a group of crystals
where each crystal has the same edge or same corner as the next crystal.
There is a minimum energy for a single crystal and for one whole
cluster defined in common {\sc /bccuts/}.
The {\bf TBCL} bank is filled in subroutine BCLUST. If there are no
clusters the first data word of the bank will be 0.

\begin{itemize}
\item {\it Number of clusters} is the total number of clusters found.
\item {\it Number of crystals} is the number of crystals in one special
cluster. The {\it Offset} {\tt JTBCL} for the cluster {\it J} can be
calculated using:
\begin{verbatim}
       JTBCL  = LQ(LTBCL-J)
\end{verbatim}
\item {\it ($\varphi$,$\vartheta$)} coordinates of crystals as
 index $=\varphi + (\vartheta -1)\cdot 60$
\end{itemize}
\begin{table}[htb]
\centering
\begin{tabular}{|r|c|l|}
                                                   \hline
{\it Offset} & {\sc value} & {\it Quantity} \\ \hline
 -2 &  LTBCL+6    & {\it Pointer to cluster 2} \\
 -1 &  LTBCL+2    & {\it Pointer to cluster 1} \\ \hline
{\sc lq($\uparrow$)} & & \\ \hline \hline
{\sc iq($\downarrow$)} & & \\ \hline
 +1 &  2            & {\it Number of clusters} \\ \hline\hline
 +2 &  3            & {\it Number of crystals} \\ \hline
 +3 &  610          & {\it ($\varphi=10$,$\vartheta=11$)} \\
 +4 &  670          & {\it ($\varphi=10$,$\vartheta=12$)} \\
 +5 &  611          & {\it ($\varphi=11$,$\vartheta=11$)} \\\hline\hline
 +6 &  1            & {\it Number of crystals} \\ \hline
 +7 &  410          & {\it ($\varphi=50$,$\vartheta= 7$)} \\ \hline
\end{tabular}
\caption{Example data for the {\bf TBCL} bank}
\label{tabletbclex}
\end{table}

 \subsubsection{TBTK}
\label{chaptbtk}
The top {\bf TBTK} bank contains only one data word: number of PEDs.
The status bit number 1 (rightmost) is set to 1 if the events has a
PED with the center crystal in $\vartheta$ 1 or 26.
The reference links (number equal to number of PEDs) points to
the  linear structure of the {\bf TBTK} banks. They contain the
results from one analysed Particle Energy
Deposition. At least one PED is created for every cluster.

The format is described in table \ref{tabletbtk}.
\begin{table}[htb]
\centering
\begin{tabular}{|r|c|l|c|}
                                                   \hline
{\it Offset} & {\sc type} & {\it Quantity} &{\it filled$^a$}%
\\ \hline
 +1 & {\sc integer} & {\it $\varphi$ of central crystal}&$\bullet$ \\
 +2 & {\sc integer} & {\it $\vartheta$ of central crystal}&$\bullet$ \\
 +3 & {\sc integer} & {\it Number of cluster in which PED is in}
   & $\bullet$ \\
 +4 & {\sc integer} & {\it Number of PEDs in the cluster}&$\bullet$ \\
 +5 & {\sc real   } & {\it $u$ direction cosine} %
$\cos\phi \sin\theta$ &$\bullet$\\
 +6 & {\sc real   } & {\it $v$ direction cosine} %
$\sin\phi \sin\theta$ &$\bullet$\\
 +7 & {\sc real   } & {\it $w$ direction cosine} %
$\cos\theta$ &$\bullet$\\
 +8 & {\sc real   } & {\it Corrected energy of PED [MeV]} &$\bullet$ \\
 +9 & {\sc real   } & {\it Error $\Delta u$ of direction cosine} %
&$\bullet$\\
+10 & {\sc real   } & {\it Error $\Delta v$ of direction cosine} %
&$\bullet$\\
+11 & {\sc real   } & {\it Error $\Delta w$ of direction cosine} %
&$\bullet$\\
+12 & {\sc real   } & {\it Error in energy of PED [MeV]}& $\bullet$\\
+13 & {\sc real   } & {\it Energy of Cluster [MeV]}&$\bullet$ \\
+14 & {\sc real   } & {\it Energy of central crystal [MeV]}&$\bullet$ \\
+15 & {\sc real   } & {\it Energy sum of 9 [MeV]} &$\bullet$\\
+16 & {\sc real   } & {\it Invariant showermass [MeV]} &$\bullet$\\
+17 & {\sc real   } & {\it Second moment of shower} & $\bullet$\\
+18 & {\sc real   } & {\it Angle $\Phi$ [rad 0..2$\pi$]} &$\bullet$\\
+19 & {\sc real   } & {\it Angle $\Theta$ [rad]} &$\bullet$\\
+20 & {\sc real   } & {\it $\sqrt{E \mbox{[MeV]}}$}&$\bullet$\\
+21 & {\sc real   } & {\it $(\Delta \Phi)^2$} & $\bullet$\\
+22 & {\sc real   } & {\it $\Phi -\Theta$ correlation} & $\circ$\\
+23 & {\sc real   } & {\it $(\Delta \Theta)^2$} & $\bullet$\\
+24 & {\sc real   } & {\it $\Phi -\sqrt{E}$ correlation} & $\circ$\\
+25 & {\sc real   } & {\it $\Theta -\sqrt{E}$ correlation} &$\circ$ \\
+26 & {\sc real   } & {\it $(\Delta  \sqrt{E})^2$} & $\bullet$\\ \hline
\multicolumn{4}{l}{$^a$ Meaning of {\it filled}:} \\
\multicolumn{4}{l}{$\bullet$ Entry correct and final} \\
\multicolumn{4}{l}{$\circ$ Entry not final,
only approximately correct}\\
\end{tabular}
\caption{Data stored in the {\bf TBTK} banks (ParticleEnergyDeposits)}
\label{tabletbtk}
\end{table}

You can loop through all PEDs using the following code:
\begin{verbatim}
       JTBTK = LTBTK
       IF (JTBTK .NE. 0) JTBTK = LQ(LTBTK-1)
    10 IF (JTBTK .NE. 0) THEN
          .
          . (this code is executed for every PED)
          . (PED number is IQ(JTBTK-5) )
          .
          JTBTK = LQ(JTBTK)
          GOTO 10
       END IF
\end{verbatim}
You can reach the PED with number {\tt N (N $\leq$ IQ(LTBTK+1))}:
\begin{verbatim}
       JTBTK = LQ(LTBTK-IQ(LTBTK-2) - N)
\end{verbatim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \section{Common Blocks used for PED Analysis}
 \subsection{Description of the Barrel Calorimeter Common Blocks}
All common blocks can be included with the patchy {\tt +SEQ,{\em name}.}
command. Only the {\sc bcener} and {\sc bcvrtx} common blocks should be
accessed from user routines.

 \subsubsection{BCBADX}
In the {\sc /bcbadx/} common block are lists of crystals which should
not be used or which are nonlinear stored:
\begin{verbatim}
      COMMON /BCBADX/ QBXLCB(1560), QBXFCB(1560)
     &                IBCLCB(1560), IBCFCB(1560)
      LOGICAL QBXLCB, QBXFCB
      INTEGER IBCLCB, IBCFCB
\end{verbatim}
\begin{itemize}
\item {\sc qbxlcb} is true for all LeCroy ADC which should not be used.
\item {\sc qbxfcb} is true for all FERA ADC which should not be used.
\item {\sc qbclcb(I)} is the number of the correction function used for
LeCroy 2282 ADC I. 0 if no correction.
\item {\sc qbcfcb(I)} is the number of the correction function used for
FERA ADC I. 0 if no correction.
\end{itemize}

 \subsubsection{BCCUTS}
In the {\sc /bccuts/} common block are some constants stored:
\begin{verbatim}
      INTEGER MINLBC,MAXLBC,MINFBC,MOKFBC
      REAL EMINBC,EXTLBC,ECLUBC,EPEDBC,ECLSBC
      LOGICAL QSUBBC
      COMMON /BCCUTS/ MINLBC,MAXLBC,MINFBC,MOKFBC
     &                EMINBC,EXTLBC,ECLUBC,EPEDBC,ECLSBC,QSUBBC
\end{verbatim}
\begin{itemize}
\item {\sc minlbc} is the minimum ADC count in the LeCroy ADC to be
stored in the TBEL bank (pedestal subtracted, zero supression)
\item {\sc maxlbc} is equal the maximum counts in the LeCroy ADC (pedestal
unsubtracted)
\item {\sc minfbc} is the minimum ADC count of the FERA to be used
for energy calculation (pedestal subtracted)
\item {\sc mokfbc} is the minimum counts in FERA
\item {\sc eminbc} is the minimum energy of one crystal used for
analysis ({\bf TBEN} bank)
\item {\sc extlbc} is the minimum energy of one crystal in one cluster
({\bf TBCL} bank)
\item {\sc eclubc} is the minimum energy of one cluster
\item {\sc epedbc} is the minimum energy of the central xtal of one PED
(not for first PED in a cluster)
\item {\sc eclsbc} is minimum energy needed in a crystal to start a
cluster
\item {\sc qsubbc} is a logical which defines that the subroutines BCDECL and
BCDECF do pedestal subtraction if the value is true (default).
\end{itemize}

 \subsubsection{BCENER}
The {\sc /bcener/} common block contains the array of the calibrated
crystal energies for one event. It is filled in routine BCALCE or BCTRAK
independent of the existence of the {\bf TBEN} bank.
\begin{verbatim}
      REAL ENERBC
      COMMON /BCENER/ ENERBC(60,26)
\end{verbatim}
\begin{itemize}
\item {\sc enerbc}($\varphi,\vartheta$) contains the energy in MeV for
crystal ($\varphi,\vartheta$).
\end{itemize}

 \subsubsection{BCFLAG}
The {\sc /bcflag/} common holds the flags needed for steering the reconstruction
of the crystal data. The common is filled in subroutine CBFFGO according
to the values of the data card 'XTAL'.
\begin{verbatim}
      LOGICAL        TRAKBC, DECFBC, DECLBC, ALCEBC, CLSTBC, PEDSBC,
     &               PDSMBC, PDRGBC
      COMMON/BCFLAG/ TRAKBC, DECFBC, DECLBC, ALCEBC, CLSTBC, PEDSBC,
     &               PDSMBC, PDRGBC
\end{verbatim}
\begin{itemize}
\item {\sc trakbc} if true analyze crystal data.
\item {\sc decfbc} if true decode FERA data.
\item {\sc declbc} if true decode LeCroy 2282 data.
\item {\sc alcebc} if true calculate energies from ADC data.
\item {\sc clstbc} if true find clusters.
\item {\sc pedsbc} if true search for PEDs.
\item {\sc pdsmbc} flag for PED-smoothing algorithm
\item {\sc pdrgbc} flag for polynomial PED position algorithm
\end{itemize}

 \subsubsection{BCFORM}
In the {\sc /bcform/} common are the characteristics for the bank
formats stored. These are filled by MZFORM and used by MZBOOK.
\begin{verbatim}
      INTEGER MTBEBC,MTBTBC
      COMMON /BCFORM/ MTBEBC,MTBTBC
\end{verbatim}
\begin{itemize}
\item {\sc mtbebc} contains the format for the {\bf TBEN} bank.
\item {\sc mtbtbc} contains the format for the {\bf TBTK} bank.
\end{itemize}

 \subsubsection{BCLOOK}
The data in the {\sc /bclook/} common connects the hardware numbers of the ADCs
to the software crystal coordinates.
\begin{verbatim}
      INTEGER MVSN,MAX22
      INTEGER LOOKBC,LK22BC
      PARAMETER (MVSN=90,MAX22=30*48)
      COMMON /BCLOOK/ LOOKBC(3,0:15,0:MVSN-1), LK22BC(3,0:MAX22-1)
\end{verbatim}
\begin{itemize}
\item {\sc mvsn} are the maximum virtual station numbers of the FERA ADCs.
\item {\sc max22} is the maximum number of 2282 ADCs.
\item {\sc lookbc(i,subaddress,vsn)} i=1: phi,i=2: theta, i=3: compound crystal
index of FERA ADC with virtual station number {\sc vsn} and {\sc subaddress}.
\item {\sc lk22bc(i,channel)} i=1: phi,i=2: theta, i=3: compound crystal
index of 2282 ADC with number {\sc channel} (numbered according to the readout
sequence!).
\end{itemize}

 \subsubsection{BCNBRS}
The {\sc /bcnbrs/} common block contains arrays to calculate the
neighbours of one crystal. It is used by the routine BGTNBR.
\begin{verbatim}
      INTEGER IPNEBC,NEIGBC
      COMMON /BCNBRS/ IPNEBC(60,26), NEIGBC(2,280)
\end{verbatim}
\begin{itemize}
\item {\sc ipnebc} is a pointer to {\sc neigbc} for every crystal
\item {\sc neigbc(ipnebc())} contains the number of neighbours for
a given crystal and in the following storage positions the relative
positions of the neighbour crystals as seen from the central crystal.
\end{itemize}

 \subsubsection{BCSTAT}
In the {\sc /bcstat/} common block is the statistics of the analysis stored.
\begin{verbatim}
      INTEGER ICALBC,IEVTBC,IPEDBC,MPEDBC,IERFBC,IERLBC,IVERBC
      COMMON /BCSTAT/ ICALBC(6),IEVTBC(4),IPEDBC,MPEDBC,
     &   IERFBC(5),IERLBC(5),IVERBC
\end{verbatim}
\begin{itemize}
\item {\sc icalbc} stores the number of calls to the different reconstruction
routines.
\item {\sc ievtbc} counts number of events passed to different analysis steps.
\item {\sc ipedbc} counts the total number of PEDs.
\item {\sc mpedbc} gives the maximum number of PEDs in one event.
\item {\sc ierfbc} counts the number of FERA errors.
\item {\sc ierlbc} counts the number of 2282 errors.
\item {\sc iverbc} is the BCTRAK version number.
\end{itemize}

 \subsubsection{BCVRTX}
The {\sc /bcvrtx/} common block holds the vertex, which will be used to
reconstruct the direction of the PEDs.
\begin{verbatim}
      REAL            VRTXBC,VRZOBC
      COMMON /BCVRTX/ VRTXBC(3),VRZOBC(2)
\end{verbatim}
\begin{itemize}
\item {\sc vrtxbc(3)} stores (x,y,z) of the vertex to be used for PED
recontruction (in cm).
\item {\sc vrzobc(1)} z-offset of the downstream half of the barrel.
\item {\sc vrzobc(2)} z-offset of the upstream half of the barrel.
\end{itemize}

 \subsubsection{BCBCPC}
This is the common block used by the PED-smoothing algorithm. It stores
the PED position smearing coefficients.
\begin{verbatim}
      COMMON /BCBCPC/ BCPCNP, BCPCTH, BCPCPH
      INTEGER BCPCNT, BCPCMP
      PARAMETER (BCPCNT = 52, BCPCMP = 21)
      INTEGER BCPCNP(2, BCPCNT)
      REAL BCPCTH(BCPCMP, 2 BCPCNT), BCPCPH(BCPCNT, 2, BCPCNT)
\end{verbatim}
\begin{itemize}
\item {\sc bcpcnt} is the number of theta divisions the corrections are
split into
\item {\sc bcpcmp} is the max. number of coefficients per correction
\item {\sc bcpcnp} is the number of coefficients used for each theta
\item {\sc bcpcth, bcpcph} are arrays of correction coefficients
\end{itemize}

\subsubsection{BCSPLI}
This common block stores the spline coefficients used by the polynomial
PED position algorithm (PDRG)
\begin{verbatim}
      INTEGER MENEBC,MSPLBC,MTYPBC
      PARAMETER (MENEBC=10,MSPLBC=4,MTYPBC=13)
      REAL RFUNBC, RFUMBC, RFUOBC, RENEBC
      COMMON /BCSPLI/ RFUNBC(MSPLBC,0:MENEBC-1,1:3,MTYPBC),
     &                RFUMBC(MSPLBC,0:MENEBC-1,7:9,MTYPBC),
     &                RFUOBC(MSPLBC,0:MENEBC-1,13:15,MTYPBC),
     &                RENEBC(0:MENEBC)
\end{verbatim}
\begin{itemize}
\item {\sc msplbc} is the number of spline coefficients (cubic)
\item {\sc menebc} is the number of energy intervalls used for spline
fitting
\item {\sc mtypbc} is the number of xtal - types
\item {\sc rfunbc, rfumbc, rfuobc} are the spline parameter for
calculation of weight with the following meaning: 0 = **1, M = **2,
N = **3, dim 1 = spline coefficient, dim 2 = energy interval, dim 3 =
coefficient for neighbouring xtal - type (+/- theta), dim 4 = xtal - type
\item {\sc renebc} is the array storing the energy intervals
\end{itemize}
\subsubsection{DBC}
This is the common block used by the DOLBY - C method (see CB-Note 199
for further details).
\begin{verbatim}
      REAL CTE, CTASYM, CTCOPA, CTEPI, CTNONG
      COMMON /DBC/ CTE, CTASYM, CTCOPA, CTEPI, CTNONG
      INTEGER GOODG, CHARGD, NONG
      PARAMETER (GOODG = 0, CHARGD = -1, NONG = -2)
\end{verbatim}
%%%%%%%%%%%%%%%%%%% Subroutines description
 \section{Particle Energy Deposition Reconstruction Software}
This section gives a brief overview of each subroutine used in the
{\em crystal data reconstruction software}. The software flow
is shown in
figure \ref{flow}.

An asterisk (*) in front of a call argument indicates that this
variable is changed by the subroutine. Unless specifically mentioned
all variable types correspond to the FORTRAN defaults.

The subroutines described in section \ref{usersubs} can be called from
the user routines.
 \subsection{Description of the Subroutines}

 \subsubsection{SUBROUTINE BCTRAK}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 20 July, 1988 \\
{\bf Call Arguments:}  (*IERR)       \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv, cbcntl, bcstat}\\
{\bf Subroutines Referenced:} {\sc bcdecf, bcdecl, bcalce, bclust, bcpeds,
                                                    usevnt}

This subroutine is the main entry into the crystal data reconstruction software.
>From here are the other subroutines called (BCDECF, BCDECL, BCALCE, BCLUST,
BCPEDS). If the energy calculation is not yet done first BCDECF is called to
decode the FERA data (enabled with option 'DECF' on card XTAL), then BCDECL
decodes the LeCroy 2282 data (enabled with option 'DECL' on card XTAL), and
BCALCE is called to calculate the energies (enabled with option 'ALCE' on card
XTAL).

If the energy calculation is done the {\tt ENERBC} array is filled with the
energies from the {\bf TBEN} bank. BCLUST is called only when the calculations
of the clusters is not already done (enabled with option 'CLST' on card XTAL).
BCPEDS called when the PED calculation is not yet done (enabled with option
'PEDS' on card XTAL); if there are no clusters only an empty {\bf TBTK} bank is
created.

An error code {\sc ierr} not equal to zero is returned when a problem
occurs in the decoding of either the FERA or the 2282 ADC information.

USEVNT is called at entry to the routine with parameter 10 and then with the
following parameters: 11 after BCDECF, 12 after BCDECL, 13 after BCALCE, 14
after BCLUST, 15 after BCPEDS.

Reminder: If data is already calculated it will not be recalculated. To do a
reanalysis you have to drop the banks with the old data or call the analysis
routines (e.g. BCPEDS) from the USEVNT routine (e.g. {\tt IF (I.EQ.15) CALL
BCPEDS}, with {\tt I} the parameter of USEVNT).

 \subsubsection{SUBROUTINE BCALCE}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 18 July, 1988 \\
{\bf Call Arguments:} (*IERR) \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv, bcbadx,
                           bccuts, bcener, bcform, bcstat}\\
{\bf Subroutines Referenced:} {\sc (zebra)  mzbook, mzpush}\\
{\bf Functions Referenced:} {\sc bcline}

This routine transforms the ADC-counts of the LeCroy 2282 and    FERA ADCs to
energy. Input is taken from the Zebra banks {\bf TBEL}  and {\bf TBEF}.
Output is stored in the Zebra bank {\bf TBEN}, if the energy is greater {\sc
eminbc}.

Calibration constants are taken from the Zebra banks
{\bf CBEF}, {\bf CBEL}. These constants are multiplied by the gain
corrections taken from the lightpulser banks {\bf CLGE}.

Nonlinearity is corrected by function BCLINE (in case of electronic
failures). Only ADCs which are not marked as bad are used {\sc qbxlcb,
qbxfcb}.

If the ADC count of the LeCroy 2282 is greater than {\sc minlbc} above pedestal
and less than {\sc maxlbc} (not pedestal subtracted)
the LeCroy data is used; the FERA data is used if the 2282 data is not used
and the ADC count of the FERA is greater {\sc minfbc} above the pedestal.
If the corresponding 2282 is ok (array {\sc qbxlcb}) the ADC count is
the FERA must be greater {\sc mokfbc} above the pedestal.
This routine fills also the {\sc /bcener/} common.

 \subsubsection{SUBROUTINE BCDECF}
{\bf Author:} G. Folger       \\
{\bf Creation Date:} December, 1988 \\
{\bf Call Arguments:} (*IERR) \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv,
                           bccutss, bclook}\\
{\bf Subroutines Referenced:} {\sc cbdate, errmes (zebra)  mzbook, mzpush,
                              (kernlib) jbit, jbyt}

This subroutine decodes the FERA raw data from {\bf RBCF} bank into the
{\bf TBEF} bank. Packed FERA data with and without pedestal subtraction can be
decoded ('H0' and 'H1'). If the variable {\sc qsubbc} from common {\sc /bccuts/}
is not set to false the resulting data will be pedestal subtracted ADC counts.

Error return codes:\\
{\sc ierr = 1:} no {\bf RBCF} bank \\
{\sc ierr = 2:} expected FERA header, did not get one. \\
{\sc ierr = 3:} found FERA header,expected data. \\
{\sc ierr = 4:} reading data beyond limit. \\
{\sc ierr = 5:} Attempt to write beyond end of bank. \\

 \subsubsection{SUBROUTINE BCDECL}
{\bf Author:} G. Folger       \\
{\bf Creation Date:} December, 1988 \\
{\bf Call Arguments:} (*IERR) \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv,
                           bccuts, bclook}\\
{\bf Subroutines Referenced:} {\sc cbdate, errmes (zebra)  mzbook, mzpush,
                              (kernlib) jbyt}

This subroutine decodes the LeCroy 2282 raw data from {\bf RBCL} bank into the
{\bf TBEL} bank. Up to now only unpacked data can be decoded.
If the variable {\sc qsubbc} from common {\sc /bccuts/}
is not set to false the resulting data will be pedestal subtracted ADC counts.
Note that no entry is put in the {\bf TBEL} bank if the 2282 ADC is in
overflow (i.e. greater than {\sc maxlbc} of common {\sc /bccuts/}) or less
than the threshold value ({\sc minlbc} of common {\sc /bccuts/}).

Error return codes:\\
{\sc ierr = 1:} no {\bf RBCL} bank \\
{\sc ierr = 4:} reading data beyond limit. \\

 \subsubsection{SUBROUTINE BCDONE}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 25 January, 1990 \\
{\bf Call Arguments:} (ICODE) \\
{\bf Common Blocks Used:} {\sc bcstat}\\
{\bf Subroutines Referenced:}

This routine is called once at the end of a job to write out information to the
log file on diagnostics/summaries of the barrel recontruction code. The value of
ICODE is a severity code which identifies if the job terminated normally or
not.

 \subsubsection{FUNCTION BCECOR}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 23 February, 1990 \\
{\bf Call Arguments:} (ENER, ITHE) \\
{\bf Common Blocks Used:} none.\\
{\bf Subroutines Referenced:}



This function returns a corrected energy for a given PED energy {\sc ener} and
the theta {\sc ithe} of the center crystal of the PED.
It corrects the most propable gamma energy deposit to the right gamma
energy for Monte Carlo data.
$$E_{\gamma} = \mbox{ENER}\times C_m C_t(\mbox{ITHE}) C_r(\mbox{ENER}) $$
\begin{itemize}
\item $C_m$ = 1.038
\item $C_t$ = 1.05 (ITHE=1,26), 1.005 (ITHE=13,14),
1.004 (ITHE=2,3,24,25), 1. (ITHE=4--12,15--23)
\item $C_r$ = $ 1+ \frac{\mbox{$0.6$}}{\mbox{ENER [MeV]}}$
\end{itemize}

 \subsubsection{FUNCTION BCEGAM}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 20 June, 1991 \\
{\bf Call Arguments:} (ENER, ITHE) \\
{\bf Common Blocks Used:} none.\\
{\bf Subroutines Referenced:}

This function returns a corrected energy for a given PED energy {\sc ener} and
the theta {\sc ithe} of the center crystal of the PED.
It corrects the {\em mean} gamma energy deposit to the right gamma
energy for Monte Carlo data. See Nigel Hesseys talk on june 1991
meeting. The usage of this function rquires the calibration to be
performed with it. See the source for the used function.

 \subsubsection{SUBROUTINE BCERRS}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 15 August, 1990 \\
{\bf Call Arguments:} (JTBTK) \\
{\bf Common Blocks Used:} {\sc cblink}\\
{\bf Subroutines Referenced:}

This subroutine calculates the errors of the direction cosines, direction
angles and energy and fills these values in the {\bf TBTK} bank pointed to by
the link {\sc jtbtk}.

 \subsubsection{SUBROUTINE BCHCEN}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 11 January, 1989 \\
{\bf Call Arguments:} (ENER, CNAME, *IERR, *QWRN, *QERR, *CTEXT) \\
{\bf Common Blocks Used:} none.\\
{\bf Subroutines Referenced:}

This Subroutine is used by BCHECK.
Checks the energy {\sc ener} for being in a correct range. Warning if
energy equal zero. {\sc qwrn} (warning), {\sc qerr} (error) are LOGICAL
and {\sc cname} (name of bank), {\sc ctext} (description of error)
are CHARACTER*(*).

 \subsubsection{SUBROUTINE BCHCPT}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 9 January, 1989 \\
{\bf Call Arguments:} (*QFIRST, IPHI, ITHE, CNAME, *IERR, *QERR, *CTEXT)\\
{\bf Common Blocks Used:}  \\
{\bf Subroutines Referenced:}

This Subroutine is used by BCHECK.
Checks the numbers {\sc iphi, ithe} for representing correct and
existing crystal numbers. Also checks for double defined crystals. (Must
be called before first test with {\sc qfirst} = .TRUE.). {\sc qfirst,
qerr} (error) are LOGICAL and {\sc cname} (name of bank), {\sc ctext}
(description of error) are CHARACTER*(*).

 \subsubsection{SUBROUTINE BCINIT}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 20 July, 1988 \\
{\bf Call Arguments:} None.        \\
{\bf Common Blocks Used:} {\sc bcbadx, bccuts, bcform, bcnbrs, bcstat,
bcvrtx, bcener, bclook, bcflag, cbbank, cblink, cbxdiv, cbunit}\\
{\bf Subroutines Referenced:} {\sc (zebra) mzform}

This subroutine is called once at the start of the program. It initializes
the {\sc bcbadx}, {\sc bccuts}, {\sc bcform},
{\sc bcstat} and {\sc bcvrtx} common. Also the banks for the
calibration constants ({\bf CBEF}, {\bf CBEL}, {\bf CBPF}, {\bf CBPL},
{\bf CBTF})
are created and filled with constants for usage with the GCB-Monte-Carlo
data (This is only done if the banks are not yet defined).

Also prints an identification of the software version and the date of
the last CMZ run.

 \subsubsection{FUNCTION BCLINE}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 22 October, 1990 \\
{\bf Call Arguments:} {\sc jcbc, iadc}    \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv}\\
{\bf Subroutines Referenced:} None.

This function calculates a corrected value of the ADC counts given by
{\sc iadc}. The correction function is stored in the ZEBRA array IQ at
position {\sc iq(jcbc)}. It can be a maximum number of ADC counts or a
polyline function. For details see the inline documentation.

 \subsubsection{SUBROUTINE BCLUST}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 15 April, 1988 \\
{\bf References:} Crystal Ball CONREG routine \\
{\bf Call Arguments:} None.        \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv, bccuts, bcener, bcstat}\\
{\bf Subroutines Referenced:} {\sc bgtnbr, (zebra) mzbook, mzpush}

The BCLUST routine finds the clusters of crystals with energy.
All crystals in one {\em cluster} must share at least one edge or corner with
another crystal of the same cluster. The minimum energy of one
crystal in a cluster is {\sc extlbc}, the minimum energy of one cluster
is {\sc eclubc} (Both variables are taken from common {\sc /bccuts/}).
The result is stored in the {\bf TBCL} bank.

 \subsubsection{SUBROUTINE BCOSCL}
{\bf Author:} T. Kiel              \\
{\bf Creation Date:} 13 May, 1988 \\
{\bf Call Arguments:} (ICL,*RX,*RY,*RZ,*RMASS) \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv, bcener}\\
{\bf Subroutines Referenced:} {\sc bcosxt}

For the energy cluster number {\sc icl} is the geometrical centre
calculated. Returned are the direction cosines {\sc (rx, ry, rz)} of
the center of gravity using the following formula (for {\sc rx}):
$$ R_x = \frac{\sum_{Crystals} E_i \cdot x_i}%
{\sqrt{ (\sum_{Crystals} E_i \cdot x_i)^2+%
(\sum_{Crystals} E_i \cdot y_i)^2+%
(\sum_{Crystals} E_i \cdot z_i)^2}}%
$$
Also the invariant mass of the cluster will be calculated.
$$ R_{\mbox{mass}} = \sqrt{\left(\sum_{Crystals} E_i\right)^2
 - \left(\sum_{Crystals} \vec{p}_i\right)^2} $$

 \subsubsection{SUBROUTINE BCOSX9}
{\bf Author:} R.Glantz              \\
{\bf Creation Date:} 10 August, 1992 \\
{\bf Call Arguments:} (ICL,*RX,*RY,*RZ,*RMASS) \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv, bcener}\\
{\bf Subroutines Referenced:} {\sc bcosxt, bc1ped}

As opposed to {\sc bcoscl} for the energy cluster number {\sc icl} the
centre of area is calculated. Returned are the direction cosines ({\sc
rx,ry,rz}) after they have been corrected due to their topological and
energy dependency in {\sc bcnped}.
The invariant mass is calculated as in {\sc bcoscl}. Note: this routine
is called only for one PED in the cluster.

 \subsubsection{SUBROUTINE BCPEDS}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 25 July, 1988 \\
{\bf References:} T.Skwarnicki, DESY F31-86-02, App. A \\
{\bf Call Arguments:} None.        \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv,
                                bccuts, bcform, bcener, bcstat, pi2pi}\\
{\bf Subroutines Referenced:} {\sc bcerrs, bcosx9, bcosxt, bcvcor, bgtnbr,
                             bcecor, bcegam, bcnped, (zebra) mzbook}

This subroutine searches for local maxima in all clusters
and defines every local maxima as one PED. For every cluster there will
be at least one PED defined. Note: The second, third etc. PEDs in one cluster
must have at least {\sc epedbc} Energy (common {\sc /bccuts/}) in the central
crystal. The {\bf TBTK} bank is created, it supports the linear structure of the
PEDs. This is also created and filled. See the description of the {\bf TBTK}
banks for the calculated data. This routine has been updated according
to a new method for calculating PED directions.

Specification of algorithm:
\begin{enumerate}
\item For all clusters do
\begin{enumerate}
\item Calculate the energy of the cluster
\item Flag all crystals in the cluster
\item Repeat until no more flagged crystals:
\begin{enumerate}
\item Find the crystal with the highest energy of all flagged crystals
(for secondary PEDs energy greater than EPEDBC)
\item Unflag this crystal
\item Loop over all neighbour crystals
\begin{enumerate}
\item If neighbour crystal has more energy go to 1.(c) (no local
maximum)
\item Unflag neighbour crystal
\item Calculate energy sum over neighbours (sum of 9)
\end{enumerate}
\item Create the {\bf TBTK} bank for this PED and fill with the
following items:
\begin{itemize}
\item $\varphi, \vartheta$ of maximum crystal
\item cluster number
\item energy of maximum crystal, sum of 9, cluster
\item invariant showermass, second moment
\end{itemize}
\item Increment counter for number of PEDs in this cluster
\item In case Logical {\sc pdrgbc} is set true (i.e. 'PDRG' has been
chosen):
\begin{itemize}
\item check which crystals are neighbours to more than one
local maximum (overlap)
\item store sum of local maxima in overlap crystal in array {\sc enrdiv}
\end{itemize}
\end{enumerate}
\end{enumerate}
\item For all PEDs in the {\bf TBTK} banks do
\begin{enumerate}
\item Fill number of PEDs in the cluster to {\bf TBTK} bank
\item Calculate the energy and error, correct the energy using BCECOR
or, if bit 1 of IQ(LTBEN) is 1 correct using BCEGAM.
\begin{enumerate}
\item One PED in a cluster: $E=E_{Cluster}$
\item For n PEDs in a cluster (with {\sc pdrgbc} set .TRUE. ): %
recalculate $E_9$ in case of overlapping neighbour crystals.
The energy of the overlap crystal is split in n parts depending on the
number of local maxima it is a neighbour to.
$$ E_{overlap/split}^{i} = \frac{E_{loc.max}^{i}}{\sum E_{loc.max} }
E_{overlap/total}$$
\item For n PEDs in a cluster (with {\sc pdrgbc} = .TRUE. take new
determined sum of nine mentioned above)
$$ E = \frac{E_9}{\sum_{PEDs} E_9} E_{cluster}$$
Energy is stored in array {\sc renped} needed in {\sc bcnped}.
\end{enumerate}
\item For calculating the direction of PED; for one PED per cluster
and/or for n PED per cluster {\sc bcnped} if {\sc pdrgbc} is .TRUE.:
\begin{enumerate}
\item Flag neighbouring crystals of local maxima
\item Calculation of PED energy follows the fomulas mentioned above.
Crystals being neighbours to n local maxima in case of more than one
PED/cluster, their energy $E_{overlap}$ is divided due to the energies
of these n maxima according to the formula:
\[REN = \frac{E_{overlap} \cdot E_{local max}}{\sum_{loc. max}E} \]
With $\sum_{loc. max}E$ being the sum of the energies of n local
maxima crystals.
\end{enumerate}
\item Calculate the direction cosine and errors
\item if flag {\sc pdsmbc} (using the 'PDSM' parameter) is set .TRUE. the
PED-smoothing algorithm will be invoked, and thus the direction cosine
and errors calculated accordingly
\end{enumerate}
\end{enumerate}

For merged $\pi^0$'s use PI0FND with QMRGPI=.true..


  \subsubsection{SUBROUTINE BCNPED}
{\bf Author:} R.Glantz       \\
{\bf Creation Date:} 10 August, 1992 \\
{\bf Call Arguments:} (*INRBS,*IMXTL,*IPHI,*ITHE,*RENPED,*REN,RX,RY,\\
RZ) \\
{\bf Common Blocks Used:} {\sc /cblink/bcener/} \\
{\bf Subroutines Referenced:} {\sc bcosxt}

The output parameters {\sc rx,ry,rz} returned by this
subroutine are the PED directions.
To calculate these values {\sc bcnped} needs both central crystals with local
maxima {\sc imxtl}, their neighbours {\sc inbrs} with their crystal
indices {\sc iphi,ithe}. The energy of the PEDs, stored in array {\sc renped},
being another input argument, is calculated according
to the formula given in {\sc bcpeds}.
The energy of each crystal neighbouring the n local maxima is stored
in array {\sc ren} (see {\sc bcpeds}). The detailed formula for the
determination of the direction cosines is:
\begin{equation}
\vec{r}_{PED x,y,z} = \frac{ \sum_{i \in \Sigma_9} f(E_i/E_{max})E_i
\vec{x_i} }
{\left| \sum_{i \in \Sigma_9}f(E_i/E_{max}) E_i
\vec{x_i} \right|}
\end{equation}
The weight function $f(E_i/E_{max})$ takes care of the energy and
topology dependency of the spatial resolution and follows the algoritm:
\begin{equation}
f(E_i/E_{max})=1+p_l\left(1-\frac{E_i}{E_{max}}\right)
                +p_q\left(1-\frac{E_i}{E_{max}}\right)^2
                +p_k\left(1-\frac{E_i}{E_{max}}\right)^3
\end{equation}
$x_{i}$ being the directions of the crystals of the sum of nine
determined in {\sc bcosxt}. The coefficients $p_l,p_q,p_k$ are given by
a spline-function which is determined for an energy range of 1 GeV
divided into twelve nonlinear intervals.

  \subsubsection{SUBROUTINE BCVCOR}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 11 May, 1990 \\
{\bf Call Arguments:} (*RX, *RY, *RZ, ITHE) \\
{\bf Common Blocks Used:} {\sc /bcvrtx/} \\
{\bf Subroutines Referenced:} {\sc bcxtal}

This subroutines calculates from the given direction cosines {\sc rx, ry, rz}
assuming a vertex at {\sc (vrtxbc(1), vrtxbc(2), vrtxbc(3))}. The vertex
can be set in common {\sc /bcvrtx/}.
For the inverse operation see description of subroutine {\sc bcvroc}.

The showermaximum is taken at 4 cm from the face of the crystals
(average for a 250 MeV photon). (See review of paricle porperties
for formula or proposal for picture.) Note that it may vary between
2 and 6 cm for different energies, but the error in the correction
is less than 10\% due to this uncertainty   ($<$ 2 mrad).

  \subsubsection{FUNCTION BCVRSN}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 13 June, 1990 \\
{\bf Call Arguments:} (CTIT, LENG) \\
{\bf Common Blocks Used:} {\sc slate (kernlib)} \\
{\bf Subroutines Referenced:} {\sc (kernlib) csqmbl, icnext, icfind}

{\bf Obsolete since version 1.41/01.}

This integer function returns 10000 times the major version id plus the minor
version id as given in the PAM title in the character variable {\sc ctit} of
length {\sc leng}.

 \subsection{Description of the User Callable Subroutines}
\label{usersubs}
 \subsubsection{SUBROUTINE BCANGL}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 26 July, 1988 \\
{\bf Call Arguments:} (RX,RY,RZ,*RPHI,*RTHE,*IPHI,*ITHE)\\
{\bf Common Blocks Used:} {\sc bcvrtx}\\
{\bf Subroutines Referenced:}

This routine returns for a given directions cosine {\sc (rx, ry, rz)}    (or
momentum vector) the corresponding  angles {\sc (rphi, rthe)} in degree and
the crystal numbers {\sc (iphi, ithe)}. If the direction does not hit    any
crystal, (0,0) will be returned for {\sc (iphi, ithe)}.
Results are corrected for barrel disalignment in z-direction according
to values given in common {\sc /bcvrtx/}

 \subsubsection{SUBROUTINE BCCCTP}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 20 February, 1991 \\
{\bf Call Arguments:} (VXYZ,CXYZ,*VRTP,*CRTP)\\
{\bf Common Blocks Used:} \\
{\bf Subroutines Referenced:}{\sc mtxmlt, mtxmbt}

This routine transforms a momentum vector {\sc vxyz(3)} and the corresponding
covariance matrix {\sc cxyz(6)} of a {\bf C}harged particle from
{\bf C}artesian {\bf T}o {\bf P}olar coordinates {\sc vrtp(3), crtp(6)}.
The covariance matrix must be in lower triangular form.

 \subsubsection{SUBROUTINE BCCPTC}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 20 February, 1991 \\
{\bf Call Arguments:} (VRTP,CRTP,*VXYZ,*CXYZ)\\
{\bf Common Blocks Used:} \\
{\bf Subroutines Referenced:}{\sc mtxmlt, mtxmbt}

This routine transforms a vector {\sc vrtp(3)} and the corresponding
covariance matrix {\sc crtp(6)} of a {\bf C}harged particle from
{\bf P}olar {\bf T}o {\bf C}artesian coordinates {\sc vxyz(3), cxyz(6)}.
The covariance matrix must be in lower triangular form.

 \subsubsection{SUBROUTINE BCDUMP}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 3 January, 1989 \\
{\bf Call Arguments:} (IUNIT, LINK, *QBAD) \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv}\\
{\bf Subroutines Referenced:} {\sc bitopt, (kernlib) uhtoc}

This subroutine can be used by the user to dump a bank or linear
structure pointed to by {\sc link}. Output is written to FORTRAN unit
{\sc iunit} in a human readable format. This routine can dump the
following banks: {\bf TBEF, TBEL, TBEN, TBCL, TBTK}. In case of the {\bf
TBTK} bank, all corresponding  {\bf TBTK} banks
are also dumped.
When it is called with {\sc link} equal zero or with a link pointing to
a bank, whose name is not mentioned
above it will return the LOGICAL {\sc qbad} equal
true. {\sc qbad} equal false is the normal return code.

 \subsubsection{SUBROUTINE BCHECK}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 3 January, 1989 \\
{\bf Call Arguments:} (LINK, CNAME, *IERR, *QWRN, *QERR, *CTEXT)
 \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv}\\
{\bf Subroutines Referenced:} {\sc bchcen, bchcpt, bitopt,
                                (kernlib) uhtoc} \\
{\bf Functions Referenced:} none.

{\sc qwrn, qerr} are LOGICAL and {\sc cname, ctext} are CHARACTER*(*).

This subroutine checks the data of the bank pointed to by {\sc link} and
with the name {\sc cname} for being consistent. (Tests can be performed
for the following banks: {\bf TBEF, TBEL, TBEN, TBCL, TBTK}.)
If everything (reference
links, numeric bank identifier, hollerith bank identifier, total number
of links, number of data words and the data words) seems ok {\sc ierr}
returns 0, {\sc qwrn} and {\sc qerr} false.

For warnings (unusual data, wrong bank name, {\sc link} equal 0) {\sc
ierr} returns a positive number, {\sc qwrn} is true and {\sc qerr}
returns false. For errors (wrong data, links etc.)  {\sc
ierr} returns a negative number, {\sc qwrn} is false and {\sc qerr}
returns true. In any case a descriptive text is returned in {\sc ctext}.

% IERR return codes:

Note that the structural links are not tested. You can use the ZEBRA
routine DZVERI to check the chaining of banks and the validity of the
links (structural, next, up, origin links) in a whole division (Options
'CLU' and 'S' for store parameter).

 \subsubsection{SUBROUTINE BCISPI}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 15 August, 1990 \\
{\bf Call Arguments:} (JTBTK) \\
{\bf Common Blocks Used:} {\sc cblink}\\
{\bf Subroutines Referenced:} {\sc bcerrs, bcvcor}

This subroutine is useful for $\pi^0$'s with two merged photons.

It calculates new direction and energy of one PED based on the
whole cluster and not only one PED. Also the errors of the direction cosines,
direction angles and energy are calculated. Results are filled
in the {\bf TBTK} bank pointed to by the link {\sc jtbtk}.
{\sc jtbtk} should point to the PED with maximum energy.
The other {\bf TBTK} banks of this cluster might be dropped.


 \subsubsection{SUBROUTINE BCMCOR}
{\bf Author:} F.-H.Heinsius              \\
{\bf Creation Date:} 11 January, 1989 \\
{\bf Call Arguments:} (*IPA,*ITR,*EP,NMAX,*NCO,*NPART,*NPEDS) \\
{\bf Common Blocks Used:} {\sc cbbank, cblink, cbxdiv, bcener, bccuts} \\
{\bf Subroutines Referenced: {\sc bitopt}}

This subroutine is still under developement. Please send any suggestions to the
author. See also subroutines MCKINE and MCVERT.

The subroutine tries to correlate the reconstructed PEDs with the tracks
(particles) given by the Monte Carlo bank {\tt MBEN}. In the array {\sc
ipa(nmax) } is for every PED the number of the correlated particle stored.
In the array {\sc itr(nmax)} is for every MC-particle the resulting PED number
stored, or 0 if there is no correlation, -1 if the particle has no energy
deposited or -2 if the particle has less than 1.05 times the minimum cluster
energy deposited. {\sc nco} gives the total number of correlated PEDs with
particles. {\sc NPART} is equal the number of generated MC-particles which have
more than 1.05 times the minimum cluster energy deposited. {\sc NPEDs} gives the
total number of PEDs.

One PED is correlated to a particle if the crystal with the maximum deposited
energy is for both the same.

 \subsubsection{SUBROUTINE BCNCTP}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 20 February, 1991 \\
{\bf Call Arguments:} (MSQRD,VXYZ,CXYZ,*VRTP,*CRTP)\\
{\bf Common Blocks Used:} \\
{\bf Subroutines Referenced:}{\sc mtxmlt, mtxmbt}

This routine transforms a momentum vector {\sc vxyz(3)} and the corresponding
covariance matrix {\sc cxyz(6)} of a {\bf N}eutral particle from
{\bf C}artesian {\bf T}o {\bf P}olar coordinates {\sc vrtp(3), crtp(6)}.
The covariance matrix must be in lower triangular form.
{\sc msqrd (real)} is the mass of the neutral particle.

 \subsubsection{SUBROUTINE BCNPTC}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 20 February, 1991 \\
{\bf Call Arguments:} (MSQRD,VRTP,CRTP,*VXYZ,*CXYZ)\\
{\bf Common Blocks Used:} \\
{\bf Subroutines Referenced:}{\sc mtxmlt, mtxmbt}

This routine transforms a vector {\sc vrtp(3)} and the corresponding
covariance matrix {\sc crtp(6)} of a {\bf N}eutral particle from
{\bf P}olar {\bf T}o {\bf C}artesian coordinates {\sc vxyz(3), cxyz(6)}.
The covariance matrix must be in lower triangular form.
{\sc msqrd (real)} is the mass of the neutral particle.

 \subsubsection{SUBROUTINE BCOSXT}
{\bf Author:} T. Kiel              \\
{\bf Creation Date:} 10 May, 1988 \\
{\bf Call Arguments:} (IPHI,ITHE,*DCX,*DCY,*DCZ) \\
{\bf Common Blocks Used:}  {\sc bcbadx} \\
{\bf Subroutines Referenced:}

Returns the direction cosines {\sc (dcx, dcy, dcz)} of the centre of the
crystal {\sc (iphi, ithe)}. The centre of the crystal being the
centre of area.
If the values of {\sc (iphi, ithe)} are
uncorrect it will return in {\sc (dcx, dcy, dcz)} (0,0,0).
Corrects also for barrel z-disalignment.

 \subsubsection{SUBROUTINE BCTBTK}
{\bf Author:} F.-H.Heinsius              \\
{\bf Creation Date:} 30 January, 1990 \\
{\bf Call Arguments:} (MXTRK,*NTRK,*P4(4,MXTRK)) \\
{\bf Common Blocks Used:} {\sc cblink} \\
{\bf Subroutines Referenced:}

Returns the four vectors ($p_x/p,p_y/p,p_z/p,E$) of all found PEDs as
obtained on the
{\tt TBTK} banks in array {\sc p4}. Number of PEDs is given in {\sc ntrk}, {\sc
p4} is filled up to PED {\sc mxtrk} if {\sc ntrk}$>${\sc mxtrk}.

 \subsubsection{SUBROUTINE BCTTKS}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:} 13 September, 1990 \\
{\bf Call Arguments:} (JTTKS, DE) \\
{\bf Common Blocks Used:} {\sc cblink}\\
{\bf Subroutines Referenced:}

This subroutine is needed, if you use DST-data, which was not produced with
the correct error definitions.
As the parameter {\sc de} you have to supply the energy resolution, e.g.
0.03 (0.025) for data and 0.02 for Monte Carlo.
This subroutine calculates then errors of the direction cosines, direction
angles and energy and fills these values in the {\bf TTKS} bank pointed to by
the link {\sc jttks}. It also fills the covariance matrix needed for kinematic
fitting.

  \subsubsection{SUBROUTINE BCVROC}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 21 January, 1992 \\
{\bf Call Arguments:} (*RX, *RY, *RZ, ITHE, RVRTX(3)) \\
{\bf Common Blocks Used:} \\
{\bf Subroutines Referenced:} {\sc bcxtal }

This subroutines calculates from the given direction cosines {\sc rx, ry, rz}
assuming vertex at {\sc (rvrtx(1), rvrtx(2), rvrtx(3))}
new direction cosines (output to {\sc rx, ry, rz})
assuming a vertex at (0,0,0).
This is the inverse operation to the call of subroutine {\sc bcvcor}.

The showermaximum is taken at 4 cm from the face of the crystals
(average for a 250 MeV photon). (See review of paricle porperties
for formula or proposal for picture.) Note that it may vary between
2 and 6 cm for different energies, but the error in the correction
is less than 10\% due to this uncertainty   ($<$ 2 mrad).

\subsubsection{FUNCTION BCXTAL}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 25 May, 1988 \\
{\bf Call Arguments:} (IPHI, ITHE, ISEL) \\
{\bf Common Blocks Used:} {\sc bcvrtx}                       \\
{\bf Subroutines Referenced:}

This function return various individual crystal parameters of the
crystal {\sc (iphi, ithe)} according to the value of {\sc isel}:\\
{\sc isel = 1:} crystal volume in cm$^3$ \\
{\sc isel = 2:} radius distance of crystal face to the center of the
detector \\
{\sc isel = 3:} front face area in cm$^2$\\
{\sc isel = 4:} rear face area in cm$^2$ \\
{\sc isel = 5:} radius distance of crystal face to the center of the
detector corrected for barrel z-disalignment\\
{\sc isel = -1:} dimension $H$ (see proposal) \\
{\sc isel = -4:} dimension $D$ (see proposal) \\
{\sc isel = -5:} dimension $B$ (see proposal) \\
{\sc isel = -6:} dimension $A$ (see proposal) \\
{\sc isel = -8:} dimension $D'$ (see proposal) \\
{\sc isel = -9:} dimension $B'$ (see proposal) \\
{\sc isel = -10:} dimension $A'$ (see proposal)

 \subsubsection{SUBROUTINE BGTNBR}
{\bf Author:} G. Folger       \\
{\bf Creation Date:} 11 August, 1987 \\
{\bf Call Arguments:}  (IPHI, ITH, *NNBR, *IPHNB, *ITHNB)\\
{\bf Common Blocks Used:} {\sc bcnbrs}\\
{\bf Subroutines Referenced:} None.

Finds the adjacent crystals to the given crystal {\sc (iphi,ith)}.
The number of neighbours  (5-9) are returned in {\sc nnbr}.
{\sc nnbr} will be set to 0, if the crystal {\sc (iphi,ith)} is a none
existing crystal of {\sc ith}=1,2,3,24,25,26. The list of
the neighbours are given in {\sc iphnb(1..nnbr)}
and {\sc ithnb(1..nnbr)}.
Calculation is done using a list in common {\sc /bcnbrs/}.

 \subsubsection{SUBROUTINE BITOPT}
{\bf Author:} F.-H. Heinsius       \\
{\bf Creation Date:}  1 August, 1988 \\
{\bf Call Arguments:} (IXTL,*IPHI,*ITHE)\\
{\bf Common Blocks Used:}None. \\
{\bf Subroutines Referenced:} None.

This subroutine transforms the {\bf B}arrel {\bf I}ndex {\bf TO P}hi and
{\bf T}heta (used in the {\bf TBEN} and {\bf TBCL} bank).
The crystal coordinates {\sc (iphi, ithe)} are calculated from
the crystal index {\sc ixtl} using the inverse of the formula
$$ \mbox{\sc ixtl} = \mbox{\sc iphi} + (\mbox{\sc ithe} - 1)\cdot 60.$$

 \subsubsection{SUBROUTINE MCKINE}
{\bf Author:} R. Brun/F.-H. Heinsius       \\
{\bf Creation Date:} 9 January, 1990 \\
{\bf References:} GEANT subroutine GPKINE \\
{\bf Call Arguments:} (LUN,IT) \\
{\bf Common Blocks Used:} {\sc cblink}\\
{\bf Subroutines Referenced:}

Prints kinematics bank {\bf KINE} for track number {\sc it}. If {\sc it} equal 0
prints all kinematics banks. Output on unit {\sc LUN}.

 \subsubsection{SUBROUTINE MCVERT}
{\bf Author:} R. Brun/F.-H. Heinsius       \\
{\bf Creation Date:} 9 January, 1990 \\
{\bf References:} GEANT subroutine GPVERT \\
{\bf Call Arguments:} (LUN,IV) \\
{\bf Common Blocks Used:} {\sc cblink}\\
{\bf Subroutines Referenced:}

Prints vertex bank {\bf VERT} for vertex number {\sc iv}. If {\sc iv} equal 0
prints all vertex banks. Output on unit {\sc LUN}.

 \subsubsection{SUBROUTINE MTXMLT}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 9 April, 1985 \\
{\bf References:} S. Brandt, Datenanalyse,BI-Verlag, 2. Aufl., Anhang B
             ISBN 3-411-01591-8 \\
{\bf Call Arguments:} (A,B,R,M,L,N) \\
{\bf Common Blocks Used:} \\
{\bf Subroutines Referenced:}

 \subsubsection{SUBROUTINE MTXMBT}
{\bf Author:} T. Kiel       \\
{\bf Creation Date:} 9 April, 1985 \\
{\bf References:} S. Brandt, Datenanalyse,BI-Verlag, 2. Aufl., Anhang B
             ISBN 3-411-01591-8 \\
{\bf Call Arguments:} (A,B,R,M,L,N) \\
{\bf Common Blocks Used:} \\
{\bf Subroutines Referenced:}


 \subsection{Description of the Block Data Routines}
 \subsubsection{BLOCK DATA BCBLCK}
{\bf Author:} G. Folger       \\
{\bf Creation Date:} 10 August, 1987 \\
{\bf Common Blocks filled:} {\sc bcnbrs}

In this block data is a list of neighbouring crystals for each crystal
stored. It should only be referenced using the subroutine BGTNBR.
For more information see the header of the block data.


 \subsection{Flow Chart of the Software}
\setlength{\unitlength}{0.8cm}
\begin{figure}[hbp]
\centering
\begin{picture}(17,28.0)
{\scriptsize
\put( 0.0,28.0){\framebox(2,1){CBINIT$^*$}}
\put( 2.0,28.5){\vector(1, 0){ 2.0}}
\put( 4.0,28.0){\framebox(2,1){BCINIT}}
%
\put( 0.0,26.0){\framebox(2,1){CBPHYS$^*$}}
\put( 2.0,26.5){\vector(1, 0){ 2.0}}
\put( 4.0,26.0){\framebox(2,1){BCTRAK}}
\put( 5.0,26.0){\line(0,-1){24.0}}
\put( 5.0, 2.0){\circle*{ 0.1}}
%
\put( 5.0,25.0){\vector(1, 0){ 1.5}}
\put( 6.5,24.5){\framebox(3.0,1){USEVNT(10)$^*$}}
%
\put( 5.0,23.5){\vector(1, 0){ 2.0}}
\put( 7.0,23.0){\framebox(2,1){BCDECF$^*$}}
%
\put( 5.0,22.0){\vector(1, 0){ 1.5}}
\put( 6.5,21.5){\framebox(3.0,1){USEVNT(11)$^*$}}
%
\put( 5.0,20.5){\vector(1, 0){ 2.0}}
\put( 7.0,20.0){\framebox(2,1){BCDECL$^*$}}
%
\put( 5.0,19.0){\vector(1, 0){ 1.5}}
\put( 6.5,18.5){\framebox(3.0,1){USEVNT(12)$^*$}}
%
\put( 5.0,17.5){\vector(1, 0){ 2.0}}
\put( 7.0,17.0){\framebox(2,1){BCALCE}}
%
\put( 5.0,16.0){\vector(1, 0){ 1.5}}
\put( 6.5,15.5){\framebox(3.0,1){USEVNT(13)$^*$}}
%
\put( 5.0,14.5){\vector(1, 0){ 2.0}}
\put( 7.0,14.0){\framebox(2,1){BCLUST}}
%
\put( 9.0,14.5){\vector(1, 0){ 1.0}}
\put(10.0,14.0){\framebox(2,1){BGTNBR}}
%
\put( 5.0,13.0){\vector(1, 0){ 1.5}}
\put( 6.5,12.5){\framebox(3.0,1){USEVNT(14)$^*$}}
%
\put( 5.0,11.5){\vector(1, 0){ 2.0}}
\put( 7.0,11.0){\framebox(2,1){BCPEDS}}
\put( 8.0,11.0){\line(0,-1){7.5}}
\put( 8.0, 3.5){\circle*{ 0.1}}
%
\put( 8.0,10.0){\vector(1, 0){ 2.0}}
\put(10.0, 9.5){\framebox(2,1){BGTNBR}}
%
\put( 8.0, 8.5){\vector(1, 0){ 2.0}}
\put(10.0, 8.0){\framebox(2,1){BCOSCL}}
\put(12.0, 8.5){\vector(1, 0){ 1.0}}
\put(13.0, 8.0){\framebox(2,1){BCOSXT}}
%
\put( 8.0, 7.0){\vector(1, 0){ 2.0}}
\put(10.0, 6.5){\framebox(2,1){BCOSXT}}
%
\put( 8.0, 5.5){\vector(1, 0){ 2.0}}
\put(10.0, 5.0){\framebox(2,1){BCVCOR}}
%
\put( 8.0, 4.0){\vector(1, 0){ 2.0}}
\put(10.0, 3.5){\framebox(2,1){BCERRS}}
%
\put( 5.0, 2.5){\vector(1, 0){ 1.5}}
\put( 6.5, 2.0){\framebox(3.0,1){USEVNT(15)$^*$}}
%
\put( 0.0, 0.0){\framebox(2,1){ZEND$^*$}}
\put( 2.0, 0.5){\vector(1, 0){ 2.0}}
\put( 4.0, 0.0){\framebox(2,1){BCDONE}}
}
\end{picture}
%
\caption[Flow chart, reconstruction software]{Crystal data reconstruction
software flow chart. Initialization and calculation routines. The routines
marked with * are not described in this document. They are part of the main
offline package.}
\label{flow}
\end{figure}

\begin{figure}[htbp]
\centering
\begin{picture}(14,24.0)
{\scriptsize
%
\put( 0.0,24.0){\vector(1, 0){ 2.0}}
\put( 2.0,23.5){\framebox(2,1){BCANGL}}
%
\put( 0.0,22.0){\vector(1, 0){ 2.0}}
\put( 2.0,21.5){\framebox(2,1){BCDUMP}}
%
\put( 0.0,20.0){\vector(1, 0){ 2.0}}
\put( 2.0,19.5){\framebox(2,1){BCHECK}}
\put( 3.0,19.5){\line(0,-1){4.5}}
\put( 3.0,15.0){\circle*{ 0.1}}
%
\put( 3.0,18.0){\vector(1, 0){ 2.0}}
\put( 5.0,17.5){\framebox(2,1){BCHCEN}}
%
\put( 3.0,16.0){\vector(1, 0){ 2.0}}
\put( 5.0,15.5){\framebox(2,1){BCHCPT}}
%
\put( 0.0,13.0){\vector(1, 0){ 2.0}}
\put( 2.0,12.5){\framebox(2,1){BCISPI}}
\put( 4.0,13.0){\vector(1, 0){ 2.0}}
\put( 6.0,12.5){\framebox(2,1){BCERRS}}
%
\put( 0.0,11.0){\vector(1, 0){ 2.0}}
\put( 2.0,10.5){\framebox(2,1){BCMCOR}}
%
\put( 0.0, 9.0){\vector(1, 0){ 2.0}}
\put( 2.0, 8.5){\framebox(2,1){BCTBTK}}
%
\put( 0.0, 7.0){\vector(1, 0){ 2.0}}
\put( 2.0, 6.5){\framebox(2,1){BCTTKS}}
%
\put( 0.0, 5.0){\vector(1, 0){ 2.0}}
\put( 2.0, 4.5){\framebox(2,1){BITOPT}}
%
\put( 0.0, 3.0){\vector(1, 0){ 2.0}}
\put( 2.0, 2.5){\framebox(2,1){MCKINE}}
%
\put( 0.0, 1.0){\vector(1, 0){ 2.0}}
\put( 2.0, 0.5){\framebox(2,1){MCVERT}}
}
\end{picture}
%
\caption[Flow chart, user routines]{Crystal data reconstruction software flow
chart. Only user callable routines.}
\label{flow2}
\end{figure}
\end{document}             % End of document.
