\documentclass[11pt]{article}

\addtolength{\textwidth}{4cm}
\addtolength{\oddsidemargin}{-2cm}
\addtolength{\evensidemargin}{-2cm}
\addtolength{\topmargin}{-3cm}
\addtolength{\textheight}{6cm}

% $Id$

\title{ALICE TRD Raw Data Format Specification}
\author{K.~Oyama, C.~Adler, V.~Angelov, D.~Emschermann, and C.~Lippmann}
\date{Last update: Dec 28, 2007}

\begin{document}

\maketitle

\abstract{
This document describes the data format produced by the ALICE TRD.
The data corresponds to the payload packed into the DDL data stream
from the TRD Global Tracking Units to the DAQ.
}

\section{Introduction}

This document describes the data format produced by ALICE Transition Radiation Detector (TRD).
TRD chamber produces two types of data; tracklet data and raw data.
Both tracklet and raw data are sent through ORI and collected in Global Tracking Unit (GTU).
The tracklet data is sent for each Level-0 trigger accept and raw data is sent for each
Level-1 trigger accept.
The tracklet data is kept until corresponding Level-1 decision comes.
If there is no corresponding Level-1 decision, the tracklet data will be discarded.
If there is corresponding Level-1 trigger accept, the GTU will find appropriate tracklet data
from its memory, combine with raw data and ship them to DAQ system through DDL connection.
This document describes about the data format contained in DDL data stream.
The data format is described in top-down hierarchy where the overall data format from GTU to DAQ
are described first and description about finer structures follow.

\section{Acronyms and Technical Terms}

\begin{description}
\item[DAQ] The Data Acquisition system.
\item[GTU] Global Tracking Unit. Receives the data from TRD chambers.
           It makes Level-1 local trigger decision,
           and also forward the raw data to the DAQ system.
\item[ORI] Optical Readout Interface mounted on the TRD chamber.
           It receives data from MCMs and send to the GTU.
\item[HC]  Half Chamber ... Half of one TRD chamber corresponds to
           3 or 4 readout boards for C0 and C1 chamber,
           respectively. One ORI corresponds always to one HC.
\item[TRAP] Tracklet Processor. The digital part of the MCM.
\item[MCM]  Multichip Module. Consists of the analog PASA and the digital TRAP and ADC.
\item[PASA] Preamplifier Shaper Amplifier.
\item[tracklet] Particle track information calculated in TRAP chip
                using the straight line fit for the ADC data.
                Tracklet is used in GTU for local Level-1 trigger decision.
\end{description}

\section{GTU to DAQ Data Format}

The data packed into the DDL data stream from GTU to DAQ system for an event 
has the structure shown in the Table~\ref{T:GTU_DATA_FORMAT}
where ``v'' means that size is not fixed (variable) and ``n.f.'' means contents are not constant.
Size of the data is given always in number of 32 bits words.

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|l|}
  \hline
  Size     &  Value      & Content \\\hline
  5        &  n.f.       & GtuLinkMask \\\hline
  v        &  n.f.       & HcData for L0S0\\\hline
  v        &  n.f.       & HcData for L1S0\\\hline
  v        &  n.f.       & HcData for L2S0\\\hline
  :        &  :          & : \\\hline
  v        &  n.f.       & HcData for L5S4 \\\hline
\end{tabular}
\end{center}
\caption{TRD GTU Data Format. The order of HcData here is stack oriented however
it is not requirement. The raw data reader software must be prepared so that it can accept any order.}
\label{T:GTU_DATA_FORMAT}
\end{table}

The data contains only the data to be packed in DDL format as a payload.
Necessary header and so on attached by DDL before and after the payload is not shown.
Precise description about the DDL header and so on are found in the DATE manual.

The half chamber data (HcData) are sent from all active half chambers (nominally 60 per super-module).
Number of half chamber can be obtained from GtuLinkMask described below.
The ordering of the HcData are not guaranteed to be in the order of layer and stack.
The producer of the HcData can be obtained by HcData itself.
The detail of data contents in GtuLinkMask and HcData are given in the sections below.

\section{GTU Link Mask}

These five 32bit data words are introduced by the GTU into the data stream. Each of these
five words mark for a certain chamber stack (0:4) the status of the corresponding optical
links from each of the ORI boards on the half chambers:

\begin{equation}
GTULinkMask = 1110 : 0000 : 0000 : 0000 : 0000 : gggg : gggg : gggg \ .
\end{equation}

Here the LSB corresponds to layer 0, side A, LSB+1 to layer 0, side B and finally bit 11 corresponds
to layer 5, side B. If the bit is set, this means that the GTU receives optical power from the ORI board
through the optical fibers from the super module.
The first word corresponds to stack 0, the fifth word to stack 4.

\section{Data Format from Half Chamber}

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|l|}
  \hline
  Size     &  Value      & Content \\\hline
  v        &  n.f.       & TrackletData \\\hline
  1        &  0x10001000 & EndOfTracklet\\\hline
  1        &  0x10001000 & EndOfTracklet\\\hline
  1 - 8    &  n.f.       & HC-Header\\\hline
  v        &  n.f.       & TrapData (first MCM)\\\hline
  :        &  :          & :\\\hline
  v        &  n.f.       & TrapData (last MCM)\\\hline
  1        &  0x00000000 & EndOfRawData\\\hline
  1        &  0x00000000 & EndOfRawData\\\hline
\end{tabular}
\end{center}
\caption{The data format produced by a half chamber (HcData).}
\label{T:HC_FORMAT}
\end{table}

Table \ref{T:HC_FORMAT} shows the format of the HcData from one half chamber (HC).
The data stream starts from tracklet data without prior header.
Tracklet is terminated by EndOfTracklet marker, and then header for this half chamber (HC-Header) is sent.
TrapData contains raw data from MCM described below.
For long time the value of the EndOfTracklet marker was 0xAAAAAAAA.
Number of Track MCM depends on chamber type and number of disabled MCM, but not given in the HC-Header.
EndOfRawData shows that there is no more MCM data coming.
Both end markers are programmed in the TRAP chip as 16 bit parameters. In order to have more reliability
in case of bit errors, the end markers are sent 4 times (x 16 bit) from the TRAP output port. The internal
TRAP logic strips the end marker, so they do not propagate in the readout tree. The end markers coming to
the GTU are sent by the HC merger.

\section{Half Chamber Headers Format}

Half Chamber (HC) headers consists of at least two data words: $h[0]$ and $h[1]$,
with the possibility to use more.
They have the following data structure.

\subsection{$h[0]$ Format}

The first word of HC header ($h[0]$) is defined by

\begin{equation}
h[0] = xmmm : mmmm : nnnn : nnnq : qqss : sssp : ppcc : ci01,
\end{equation}

where right hand of the expression is the digits expression.
Colons are put just for easier bit position identification.

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|l|}
  \hline
  Name   & n-bits   & bit pos & Value   & Content \\\hline
  $x$    & 1        & 31      & 1       & Raw Version Special Number \\\hline
  $m$    & 7        & 30..24  & 0:127   & Raw Version Major Number\\\hline
  $n$    & 7        & 23..17  & 0:127   & Raw Version Minor Number\\\hline
  $q$    & 3        & 16..14  & 0:7     & Number of additional HC-header words\\\hline
  $s$    & 5        & 13..9   & 0:17    & Super-module Sector Number (ALICE numbering)\\\hline
  $p$    & 3        & 8..6    & 0:5     & Plane Number (same as layer)\\\hline
  $c$    & 3        & 5..3    & 0:4     & Chamber Number (same as stack)\\\hline
  $i$    & 1        & 2       & 0:1     & Side on chamber (0:A , 1:B)\\\hline
\end{tabular}
\end{center}
\caption{$h[0]$ HC header contents.}
\label{T:HC_HEADER_0}
\end{table}

The MSB ``$x$'' is to tell the reading software that this is new version of header. Old format
(2006 SM-I) can not have 1 as MSB because here was bit 12 (weight 2048) of the DCS serial number
which can not happen in SM-I.
DCS serial number is then omitted because it is useless.

Please see the Major ($m$) and Minor ($n$) numbers definitions of Raw Version in the later sections.
The values $m$ and $n$ form full raw version number as $V_r = m.n$.
The $V_r$ defines raw data format followed, including $h[1]$.
The $h[1]$ definitions in this document must be known as not for all versions but only for specific versions.
%
The value $q$ (number of additional HC-header words) shows the number of following
header words.
It should not count the $h[0]$ word itself.
This can be increased up to 7 (corresponds to total header size of 8)
Currently it is either 1 or 2 and $h[1]$, $h[2], h[3]$ are defined. As the three additional headers
can be reliably recognized by the bits 5..2, their order is not necessary to be fixed. Furthermore, it is
possible to send only a subset of them, provided the total number is given correctly in h[0].
%
Side is the side on the chamber where 0 means A side and 1 means B side. DCS board sits
on B side (2B readout board, in ALICE position 3).

\subsection{$h[1]$ Format}
\label{subsec:h1}

\begin{equation}
h[1] = tttt : ttbb : bbbb : bbbb : bbbb : bbpp : pphh : hh01 \ .
\end{equation}

This is valid for $V_r$=.....

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|l|}
  \hline
  Name   & n-bits   & bit pos & Value     & Content                \\\hline
  $t$    & 6        & 31..26  & 0 : 63    & Number of time-bins    \\\hline
  $b$    & 16       & 25..10  & 0 : 65535 & Bunch crossing counter \\\hline
  $p$    & 4        & 9..6    & 0 : 15    & Pretrigger counter     \\\hline
  $h$    & 4        & 5..2    & 0 : 11    & Pretrigger phase       \\\hline
\end{tabular}
\end{center}
\caption{$h[1]$ HC header contents.}
\label{T:HC_HEADER_1}
\end{table}

The Bunch crossing counter runs at 120 MHz and has 32 bits in the TRAP, however
only the lower 16 bits are transferred to raw data ($b$).
With 16 bit number, the revolution time is 546 us and it is
enough to check the alignment.
%
The Pretrigger counter ($p$) is the lower 4 bits of the pretrigger counter
in the TRAP.
Pretrigger Phase ($h$) is the phase of the pretrigger relative to the ADC sampling.
This parameter needs some calibration, because of possible offset and/or sign inversion.
The maximum number of time-bins is 30, because of the limited FIFO size in the NI output ports of the TRAP.
More time-bins (up to 63) are possible, but the readout in TRAP will require special software and
configurations and will definitely cost more electrical power.
%In case of zero suppression and
%time-bins $>$ 30, the ADC mask (see later) can not be sent according to the present specifications.

\subsection{$h[2]$ Format}

The optional header word $h[2]$ has the following contents:
%
\begin{equation}
h[2] = pgtc : nbaa : aaaa : xxxx : xxxx : xxxx : xx11 : 0001 \ .
\end{equation}

Note that the bits 5..2 are outside the possible range of the same bits in h[0], h[1] and h[3].

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|l|l|}
  \hline
  Name   & n-bits   & Value     & Content                            \\\hline
  $p$    & 1        & 0 : 1     & Pedestal  Filter setup (0:off 1:on) \\\hline
  $g$    & 1        & 0 : 1     & Gain      Filter setup (0:off 1:on) \\\hline
  $t$    & 1        & 0 : 1     & Tail      Filter setup (0:off 1:on) \\\hline
  $c$    & 1        & 0 : 1     & Crosstalk Filter setup (0:off 1:on) \\\hline
  $n$    & 1        & 0 : 1     & Non-lin   Filter setup (0:off 1:on) \\\hline
  $b$    & 1        & 0 : 1     & Raw data bypass filter (0:no 1:yes) \\\hline
  $a$    & 6        & 0 : 63    & Digital filter common additive     \\\hline
  $x$    &          &           & Undefined                          \\\hline
\end{tabular}
\end{center}
\caption{$h[2]$ HC header contents.}
\label{T:HC_HEADER_2}
\end{table}

Note: this header is not implemented in the TRAP software.

\subsection{$h[3]$ Format}

The optional header word $h[3]$ has the following contents:
%
\begin{equation}
h[3] = ssss : ssss : ssss : saaa : aaaa : aaaa : aa11 : 0101 \ .
\end{equation}

Note that the bits 5..2 are outside the possible range of the same bits in h[0], h[1] and h[2].

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|l|}
  \hline
  Name   & n-bits   & Value    & bit pos & Content                   \\\hline
  $s$    & 13       & 0 : 8191 & 31..19  & SVN Revision of the fit and readout program \\\hline
  $a$    & 13       & 0 : 8191 & 18..6   & SVN Revision of the assembler used for compilation\\\hline
\end{tabular}
\end{center}
\caption{$h[3]$ HC header contents.}
\label{T:HC_HEADER_3}
\end{table}


\section{Raw Data Version Definitions}

Raw data version is determined by $x$, and $V_r=m.n$ in th Table~\ref{T:HC_HEADER_0}.
This document describes only about $x=1$ case.
Supermodule-I in 2006 data corresponds to $x=0$ and all other
definitions (including $h[0]$ and $h[1]$ are completely different and obsolete.

Table~\ref{T:RAWVER_DEF} shows the current definitions of the raw data version
number for only $x=0$ case.

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|l|}
\hline
Major $m$ & Minor $n$ & Definition \\\hline
0          &      0    & Bogdan format with new header\\\hline
1          &      0    & Full-raw (FR) SM-I-2006 but with new header\\\hline
2          &      *    & Full-raw (FR) for production\\\hline
3          &      *    & Zero-suppressed (ZS) $\beta$              \\\hline
4          &      *    & Zero-suppressed (ZS) for production\\\hline
5          &      0    & Test pattern, counter mode\\\hline
5          &      1    & Test pattern, 10bit pseudo-random mode\\\hline
5          &      $>$1 & reserved for other test-patterns\\\hline
6$\sim$126 &      *    & Undefined\\\hline
127        &      *    & Play\\\hline
\end{tabular}
\end{center}
\caption{Raw data version ($V_r=m.n$) definitions.}
\label{T:RAWVER_DEF}
\end{table}

Except for exception, the odd number for Major version number should
be used while development and once it is stable, it should be
ported to even number.

The former definition in table \ref{T:RAWVER_DEF} of the major and minor version numbers was used until end of 2007. The next 
table \ref{T:RAWVER_BIT_DEF} shows how to create the major version numbers consequently, so that all important features of the
data format and readout mode can be directly extracted from these 7 bits. The TRAP program analyzes the major version and
behaves according to the following table \ref{T:RAWVER_BIT_DEF}.

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|}
\hline
Bit(s) in Major Ver. & Definition \\\hline
6          &      Test pattern (TP)\\\hline
5          &      Zero suppression (ZS)\\\hline
4          &      Disable tracklets (DT)\\\hline
3          &      Cosmics mode\\\hline
2..0       &      Options (OP), different meaning\\\hline
2..1       &      ZS: when 01/10/11 - send every 128/256/1024 event completely\\\hline
0          &      ZS: 1 - suppress MCM header/empty ADC mask\\\hline
0          &      no ZS, no TP: 1 - calculate ADC statistics in TRAP memory\\\hline
2..0       &      TP: Test Pattern type, currently implemented 0..3\\\hline
\end{tabular}
\end{center}
\caption{Raw data major version bit fields}
\label{T:RAWVER_BIT_DEF}
\end{table}

Note that \textit{Test pattern} and \textit{Zero suppression} are not compatible, so do not set both
simultaneously.

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|p{7.5cm}|}
\hline
Bit(s) in Minor Ver. & Name & Definition \\\hline
1..0       &   ZS\_TRACKL &   ZS: when 00 disable tracklet contribution to the ZS channel mask\\\hline
1..0       &   ZS\_TRACKL &   ZS: when 01 enable tracklet contribution to the ZS channel mask\\\hline
1..0       &   ZS\_TRACKL &   ZS: when 10 enable tracklet candidate contribution to the ZS channel mask\\\hline
2          &   ZS\_ADCMSK &   ZS: when 1 apply AND with ADCMSK register to the ZS channel mask\\\hline
\end{tabular}
\end{center}
\caption{Raw data minor version bit fields, available since SVN ver. 3813}
\label{T:RAWMINVER_BIT_DEF}
\end{table}

In order to be compatible to the previous definitions of the versions, the major versions 0, 3..5 should
be avoided in the future runs. This is not a problem, as the option field has up to now no special usage in case of no ZS, no
TP, no DT, except for the ADC statistics. The data reader software can in this case interpret the major version
according to the old table \ref{T:RAWVER_DEF}.
The \textit{ADC statistics} option tells to the TRAP CPUs to accumulate for each ADC channel the sum of the ADC
values and the sum of the squares of the ADC values. The sums are stored in the TRAP DMEM and can be read 
through the SCSN interface. This means, the ADC statistics doesn't change the data format. One might think
about, to send the actual sums instead of the ADC values through the readout tree. To be discussed.\\

\textbf{Test patterns}\\


\textbf{Common for all test patterns:} each CPU, exactly like in normal mode without ZS, sends the same number of
32 bit data words. For example if the number of samples is 30, each ADC channel is packed in 10 words. CPU
0,1,2 have 5 ADC channels to send, CPU3 has 6 channels to send. This means, CPU0..2 send 50 words, CPU3
sends 60 words. Note that this is the maximum, as the FIFO size of each CPU is 64 words long.

Except for patterns 1 and 6, the two LSBits in the raw data do not fulfill the rule in equation \ref{eq_adc_format}.

\subsection{Test pattern 0 Format}

Not recommended for future runs, as the other counter patterns (2 and 3) are better.

\subsection{Test pattern 1 Format}

In this case the ADC data are replaced by a 10 bit pseudo-random counter. The start 10 bit value for each
CPU is given by:

%\begin{equation}
data[0]=(1 $<<$ 9) or (rob $<<$ 6) or (mcm $<<$ 2) or cpu
%\end{equation}

%\begin{equation}
data[0] = 1r : rrmm : mmcc,
%\end{equation}

The next value is given by:

%\begin{equation}
data[i+1] = ( (data[i] $<<$ 1) or ( ( (data[i] $>>$ 9) xor (data[i] $>>$ 6) ) and 1) ) and 0x3FF
%\end{equation}

In the equations, $<<$ / $>>$ is logical bit-shift left/right, $or$, $xor$ and $and$ are bitwise operations.

Note that the start value is always different from 0. This ensures, that all generated pseudo-random
values are different from 0.

\subsection{Test pattern 2 Format}

\begin{equation}
p[2] = eeee : eess : sssp : ppcc : crrr : mmmm : uutt : tttt,
\end{equation}

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|l|}
  \hline
  Name   & n-bits   & bit pos & Value   & Content \\\hline
 $e$    & 6        & 31..26  & 0:63    & The lower 6 bits of the event counter\\\hline
 $s$    & 5        & 25..21  & 1:18    & Super-module Sector Number + 1\\\hline
 $p$    & 3        & 20..18  & 1:6     & Plane Number + 1\\\hline
 $c$    & 3        & 17..15  & 1:5     & Chamber Number + 1\\\hline
 $r$    & 3        & 14..12  & 0:7     & ROB\\\hline
 $m$    & 4        & 11..8   & 0:15    & MCM\\\hline
 $u$    & 2        & 7..6    & 0:3     & CPU\\\hline
 $t$    & 6        & 5..0    & 1:61    & counter++\\\hline
\end{tabular}
\end{center}
\caption{$p[2]$ pattern 2}
\label{T:TPATT_2}
\end{table}

Each CPU starts from counter=1 and increments the counter for each next word. The rest of the bits are
constant, except for the upper bits, which are part of the event counter. This pattern is may be the best
to search for breaks in the data structure. Note that the sector, plane and chamber are incremented by 1
and the counter starts from 1, in order to avoid sending of end marker.

\subsection{Test pattern 3 Format}

\begin{equation}
p[3] = eeee : eeee : eeee : ssss : sppp : cccr : rrmm : mmuu,
\end{equation}

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|l|}
  \hline
  Name   & n-bits   & bit pos & Value   & Content \\\hline
 $e$    & 12       & 31..20  & 0:4095  & The lower 12 bits of the event counter\\\hline
 $s$    & 5        & 19..15  & 1:18    & Super-module Sector Number + 1\\\hline
 $p$    & 3        & 14..12  & 1:6     & Plane Number + 1\\\hline
 $c$    & 3        & 11..9   & 1:5     & Chamber Number + 1\\\hline
 $r$    & 3        & 8..6    & 0:7     & ROB\\\hline
 $m$    & 4        & 5..2    & 0:15    & MCM\\\hline
 $u$    & 2        & 1..0    & 0:3     & CPU\\\hline
\end{tabular}
\end{center}
\caption{$p[3]$ pattern 3}
\label{T:TPATT_3}
\end{table}

This pattern is very similar to 2, but the field for the event counter is extended to 12 bits, the counter
is not send, but used internally to count the words send by each CPU.
This pattern is may be the best to search for larger breaks in the data structure.
Note that the sector, plane and chamber are incremented by 1, in order to avoid sending of end marker.

\subsection{Test pattern 6 Format}

\begin{equation}
p[6] = eeee : ssss : sppp : cccr : rrmm : mmuu : tttt : ttff,
\end{equation}

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|l|}
  \hline
  Name   & n-bits   & bit pos & Value   & Content \\\hline
 $e$    & 4        & 31..28  & 0:15    & The lower 4 bits of the event counter\\\hline
 $s$    & 5        & 27..23  & 1:18    & Super-module Sector Number + 1\\\hline
 $p$    & 3        & 22..20  & 1:6     & Plane Number + 1\\\hline
 $c$    & 3        & 19..17  & 1:5     & Chamber Number + 1\\\hline
 $r$    & 3        & 16..14  & 0:7     & ROB\\\hline
 $m$    & 4        & 13..10  & 0:15    & MCM\\\hline
 $u$    & 2        & 9..8    & 0:3     & CPU\\\hline
 $t$    & 6        & 7..2    & 1:61    & counter++\\\hline
 $f$    & 2        & 1..0    & 2:3     & 11 for even and 10 for odd adc channels\\\hline
\end{tabular}
\end{center}
\caption{$p[6]$ pattern 6}
\label{T:TPATT_6}
\end{table}

Each CPU starts from counter=1 and increments the counter for each next word. The rest of the bits are
constant, except for the upper bits, which are part of the event counter. This pattern is very similar to pattern 2,
with the only difference that the event counter has 4 bits and the last two (LS) bits fulfill the condition
(\ref{eq_adc_format}). Note that the sector, plane and chamber are incremented by 1
and the counter starts from 1.

\subsection{Test pattern 7 Format}

This is actually reserved for sending the compressed configuration over the readout tree. The format is outside the scope of this document.


\section{TRAP data without Zero Suppression - FR SM-I-2006 ($V_r=1.0$)}

Table \ref{T:TRAP_FORMAT_FR} shows the TrapData for without zero suppression (FullRaw:FR) for SM-I-2006
corresponding to $V_r=1.0$.

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|l|}
  \hline
  Size     &  Value      & Content \\\hline
  1        &  n.f.       & McmHeader\\\hline
  $N_{adc}$     &  n.f.       & AdcData, ADC channel 0\\\hline
  .        &  ...        & ...\\\hline
  $N_{adc}$     &  n.f.       & AdcData, ADC channel 20\\\hline
\end{tabular}
\end{center}
\caption{TRAP data format.}
\label{T:TRAP_FORMAT_FR}
\end{table}

McmHeader has the following bit pattern:

\begin{equation}
  {\rm MCMHeader} = xrrr : mmmm : eeee : eeee : eeee : eeee : eeee : 1100 \ ,
\end{equation}
%
where definitions of $r$, $m$, and $e$ are defined in Table~\ref{T:MCM_HEADER_CONT}.

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|l|}
  \hline
  Name   & n-bits   & bit pos & Value        & Content                \\\hline
  $x$    & 1        & 31      & 0 : 1          & 0 before, 1 since 10.2007\\\hline
  $r$    & 3        & 30..28  & 0 : 7          & Readout board position (ALICE numbering)\\\hline
  $m$    & 4        & 27..24  & 0 : 15         & MCM position           (ALICE numbering)\\\hline
  $e$    & 20       & 23..4   & 0 : $2^{20}-1$ & Event counter from 1\\\hline
\end{tabular}
\end{center}
\caption{MCM header contents.}
\label{T:MCM_HEADER_CONT}
\end{table}

Readout position and MCM position are given to TRAP chips from DCS software.
Event counter starts from 1 (it was 10 till $V_r=1.xx$). In the TRAP the event counter is 32 bit, 
here are only the lower 20 bits.

After McmHeader, the 21 channel ADC data are sent without any suppression.
Since ADC has 10 bits resolution, 3 ADC data can be packed into one 32 bits word.
The number of data words ($N_{adc}$) for one ADC channel depends on number of time bin ($N_t$) and written as:
%
\begin{equation}
  N_{adc} = \left( \frac{N_t-1}{3} +1 \right),
\end{equation}
%
where calculation must follow the normal integer calculation rule
where the number after the decimal point should be simply truncated.
Since $N_{adc}$ data words can contain $3N_{adc}$ time-bin data, there can be
$3*N_{adc} - N_t$ time-bin space left if $N_t$ is not multiple of 3.
In such case the space left will be filled by zero.

ADC data is ordered from lower channel (channel 0) to higher channel (channel 20).
Time-bin data is also ordered from lower time-bin (time-bin 0) to upper time bin (time-bin $N_t-1$).
One word $w$ containing time-bin data has the following format.
%
\begin{equation}
  w = xxxx : xxxx: xxyy : yyyy : yyyy : zzzz : zzzz : zzff \ ,
\label{eq_adc_format}
\end{equation}
%
where $x$, $y$, and $z$ corresponds to time-bin $3i+2$, $3i+1$, and $3i$, respectively
where $i$ is an integer number.
$ff$ should be 11 for even ADC channels and 10 for odd ADC channels.

\section{TRAP data with Zero Suppression - ZS $\beta$ ($V_r=3.0$)}

\subsection{TRAP data with Zero Suppression (ZS) and up to 30 samples}

Table \ref{T:TRAP_FORMAT_ZS} shows the TrapData with zero suppression (ZS) 
in $V_r=3.0$ definition.

\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|l|}
  \hline
  Size      &  Value      & Content \\\hline
  1         &  n.f.       & McmHeader\\\hline
  1         &  n.f.       & AdcMask\\\hline
  $N_{adc}$ &  n.f.       & AdcData, lowest channel with non-zero bit in the mask\\\hline
  ...       &  ...        & ...\\\hline
  $N_{adc}$ &  n.f.       & AdcData, highest channel with non-zero bit in the mask\\\hline
\end{tabular}
\end{center}
\caption{TRAP data format with zero suppression.}
\label{T:TRAP_FORMAT_ZS}
\end{table}

Here, McmHeader definition is same as for without Zero Suppression.
AdcMask $m$ is the map of the active ADC channels with the format of:
%
\begin{equation}
  AdcMask = nncc : cccm : mmmm : mmmm : mmmm : mmmm : mmmm : 1100 \ ,
\end{equation}
%

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|l|}
  \hline
  Name   & n-bits   & bit pos &  Value        & Content\\\hline
  $n$    & 2        & 31..30  & 11b            & Unused\\\hline
  $c$    & 5        & 29..25  & 11111b         & Unused\\\hline
  $m$    & 21       & 24..4   & 0 : $2^{21}-1$ & selected ADCs\\\hline
\end{tabular}
\end{center}
\caption{ADC Mask contents.}
\label{T:ADC_MASK_CONT}
\end{table}

1 as bit value in the mask means the ADC data is sent and 0 means not sent.
The MSB of the mask corresponds to ADC channel 20 and the LSB corresponds to ADC channel 0.
From the mask, the data reading software is able to get how many ADC data will follow.
The unused bits are specified additionaly to get some redundancy.
1) The 5 bits in $c$ are the number of 1 in the ADC mask. In order
to preserve the same empty ADC mask, the bits in $c$ are inverted.
2) nn=01 in order to distinguish between MCM header and ADC mask, as they have the same 4 LSBits.

In this format of raw data, the TRAP is expected to apply the following algorithm
to find active ADC.

\begin{enumerate}
\item Mark ADCs if there is at least one sample marked in the EBIn (event buffer indicator,
see the TRAP user manual). In this case the configuration registers of the built in zero suppression
EBIS, EBIT, EBIL, EBIN and the TRAP CPU program influence the selection. Some timebins can be excluded
from the EBIn, as the event buffer indicator will be AND-ed with the sample mask ZS\_SMASK stored in DMEM of the
TRAP (since SVN version 3813).

\item Mark ADCs if there is a tracklet associated to this ADC or neighboring ADC.
The tracklets that can be processed in the TRAP belong either to one channel (ch) or two ADC channels
(ch, ch+1). In the first case the ADC channels ch-1, ch, ch+1 will be selected.
In the second case the ADC channels ch-1, ch, ch+1 and ch+2 will be selected.
Since SVN version 3813 this basic algorithm can be modified by two parameters stored in the minor version (see Table~\ref{T:RAWMINVER_BIT_DEF}).
The bitfield ZS\_TRACKL can disable (when 00) the contribution of the tracklets to the channel mask.
By storing there 10 or 01 it is possible to distinguish between tracklet candidates (potential tracklets) and
tracklets actually sent to the GTU.
The final channel mask can be AND-ed with the ADCMSK register of the TRAP in order to prevent
sending masked channels. For this set the bit ZS\_ADCMSK in the minor version (see Table~\ref{T:RAWMINVER_BIT_DEF}).


\end{enumerate}

In the current format of the zero suppressed data,
the full time bin data will be sent for all selected ADCs in the ADC mask.
The ADC data format is exactly the same as in the case without zero suppression.

\subsection{TRAP data with Zero Suppression (ZS) and more than 32 samples}

The described data format for raw data readout doesn't allow to send more than 30 samples/ADC channel, see \ref{subsec:h1}. Using a slightly different data format allows working with number of samples $N_t$ up to 63.
The TRAP CPUs search for the first non-zero bit in the event buffer indicator starting from 0 and select the starting time bin $t_0$ two samples before it. Of course $t_0$ can not be negative, it will be clipped to 0 if necessary.
If $t_0$ is larger than the $N_t+1-3*N_{adc}$ it will be clipped there, so that the complete window lies within the correct range $0..N_t-1$. This procedure is done for each channel independently, so $t_0$ can be different.

The number of the 32-bit words $N_{adc}$ used to send one ADC channel is fixed and is part of the configuration. All ADC data from timebin $t_0$ to timebin $t_0+3*N_{adc}-2$ are sent 3 samples in a 32-bit word like in the other cases.
The first 10-bit field here is used not to send ADC data, but to code the offset $t_0$ and $N_{adc}$.

\begin{equation}
  w = xxxx : xxxx: xxyy : yyyy : yyyy : ssss : oooo : ooff \ ,
\label{eq_adc_format_32}
\end{equation}

where $o$ represent the offset $t_0$, $s$ is the size of the ADC packet $N_{adc}$ for one channel in 32-bit words, $y$ is the ADC data for timebin $t_0$, $x$ is the ADC data for timebin $t_0+1$. The last two bits $f$ are like in the normal ZS mode.
The next $N_{adc}-1$ 32-bit words contain the rest data for the same channel, the last word looks like:

\begin{equation}
  w = xxxx : xxxx: xxyy : yyyy : yyyy : zzzz : zzzz : zzff \ ,
\label{eq_adc_format_32last}
\end{equation}

where $z$ is ADC data for timebin $t_0+3*N_{adc}-4$, $y$ is ADC data for timebin $t_0+3*N_{adc}-3$ and $x$ is ADC data for the last timebin transmitted $t_0+3*N_{adc}-2$.

%Therefore the number of words for the AdcData for the MCM is expressed by:
%
%\begin{equation}
%  N = \frac{N_t * N_a - 1}{3} +1,
%\end{equation}
%
%where $N_t$ is the number of timebin and $N_a$ is the number of active ADCs
%which is number of bit with value 1 in ADC Mask.
%The calculation above must be done with normal integer calculation rule
%where the number after the decimal point should be simply truncated.
%Different from the data format without zero suppression,
%timebin data for different ADC can be contained in the same data word
%to have maximum packing factor.

%The following equations show the example format of AdcData for the case of number of time bin
%of 4 and number of active ADC of 2 where ADC channel 5 and 8 are active.
%In this case $4\times 2=8$ ADC data are packed into 3 words.

%\begin{eqnarray}
%  w[0] & = & d^5[0] << 22 \;|\; d^5[1] << 12 \;|\; d^5[2] << 2 \;|\; 10b \\
%  w[1] & = & d^5[3] << 22 \;|\; d^8[0] << 12 \;|\; d^8[1] << 2 \;|\; 10b\\
%  w[2] & = & d^8[2] << 22 \;|\; d^8[3] << 12 \;|\; 0 << 2     \;|\; 11b
%\end{eqnarray}

%$d^5[0..3]$ represents ADC channel 5 data, and $d^8[0..3]$ is channel 8.
%Each has 4 timebin with 10 bits data width.
%Since 3 words are spent for the data transmission, there will be a place
%empty and it is filled with zero.
%The last two bits of each word is determined by ADC channel number where
%the MSB side of the timebin data belongs.
%If the MSB side of the timebin data belongs to odd number of ADC channel,
%the last two bits should be 10 and otherwise 11.

%  For each channel, the following data are sent:
%
%  xxxx_xxxx_xxyy_yyyy_yyyy_zzzz_zzzz_zzff
%
%  where x , y, and z can be one of either:
%
%    olen = offset * 32 + (length - 1)*2 + r  (0:1023)
%    adc-data                                 (0:1023)
%
%  ff is same as for rawver=1.
%  The first data in ADC data is always olen.
%  offset is from 0 to 31, and length is from 1 to 16.
%  offset = 0 means data starts from timebin 0.
%  The maximum cluster size is 16.
%  If cluster is larger than 16, then it is split into 2 or more.
%  r = 0 shows the last data in this ADC.
%  r = 1 shows there is a next cluster in the same ADC.
%  If r=0 comes not at the position "z" but on "x" or "y",
%  the next ADC data should starts in the same word.
%
%
% Note: Zero-suppressed data supports only number of timebin
%       less than or equal to 32.

\section{Tracklet Data}

Here the Tracklet word definition is described. The tracklet words are again 32bit words, where each
describes one tracklet found in an MCM:
%                                                                                                               
\begin{equation}
  Tracklet = pppp : pppp : zzzz : dddd : dddy : yyyy : yyyy : yyyy \ ,
\end{equation}
%                                                                                                               
\begin{table}[h]
\begin{center}
\begin{tabular}{|l|l|l|l|l|}
  \hline
  Name   & n-bits  & Value              & Granularity  & Content              \\ \hline
  $p$    & 8       & $0:1$              & 0.39~\%      & Electron Probability \\ \hline
  $z$    & 4       & $0:15$             & 1            & Pad Row              \\ \hline
  $d$    & 7       & $-8.89:8.89$mm     & 140~$\mu$m   & Deflection length    \\ \hline
  $y$    & 13      & $-655.28:655.28$mm & 160~$\mu$m   & Pad Position         \\ \hline
\end{tabular}
\end{center}
\caption{Tracklet Word contents.}
\label{T:TRACKLET_CONT}
\end{table}

The values are obtained by a fit inside the TRAP chips. With the four given coordinates
$p$, $z$, $d$ and $y$ the position of the tracklet on a half chamber and its inclination
in phi direction (across pad columns along the wire direction) are defined.

\begin{thebibliography}{99}
\bibitem{TRAP_MANUAL} A TRAP Manual; http://www.kip.uni-heidelberg.de/ti/TRD/doc/
\bibitem{GUTFLEOSCH} M.~Gutfleisch, ``Local Signal Processing of the ALICE Transition Radiation Detector at LHC (CERN), Marcus Gutfleisch'' (PhD Thesis, 2006, KIP, Heidelberg)
\end{thebibliography}

\end{document}

% LocalWords:  GtuLinkMask HcData teh
