Commit 4a65be59 by dauncey

### Many changes from the last four months

parent e74839d6
doc/Float.xlsx 0 → 100644
 ... ... @@ -174,9 +174,12 @@ where the positive sign is required for $q>100$\,fC. \section{Link data representation} The selected trigger cell data on the link need to be represented in a small number of bits $n$, data are calculated to a large number of bits, typically 16-18. On the links, they need to be represented in a small number of bits $n$, typically $\sim 8$. This could be linear or logarithmic. This could be linear or logarithmic or floating. \subsection{Linear representation} For linear, then in general it can be linear betwen $x_\mathrm{min}$ and $x_\mathrm{max}$ and 0 or $2^n-1$ outside this range. This can be represented within the range by ... ... @@ -187,8 +190,10 @@ which can be inverted to give x = x_\mathrm{min} + \frac{y(x_\mathrm{max}-x_\mathrm{min})}{2^n-1} \subsection{Logarithmic representation} For logarithmic, the general case would be $y=a\log(x)+b$ but with $c=b/a$ and $x_\mathrm{min}=e^-c$, then $c=b/a$ and $x_\mathrm{min}=e^{-c}$, then y = a\log(x)+b = a\log(x)+ac = a(\log(x)+c) = a(\log(x)-\log(x_\mathrm{min})) = a \log(x/x_\mathrm{min}) ... ... @@ -202,6 +207,142 @@ This can be inverted to give x = x_\mathrm{min}\left(\frac{x_\mathrm{max}}{x_\mathrm{min}}\right)^{y/(2^n-1)} \subsection{Float representation} Here, the $2^n$ values are split into an exponent of $E$ bits and a mantissa of $M$ bits. The naive approach is simply to take the actual value as the mantissa shifted up by $E$ bits. For example, for $E=2$ and $M=2$, then the 16 possible values would give the table below. \bigskip \begin{center} \begin{tabular}{c|c|c|c} \hline Representation & Exponent & Mantissa & Value \cr\hline 0 & 0b00 & 0b00 & 0b00000 = \phantom{2}0\cr 1 & 0b00 & 0b01 & 0b00001 = \phantom{2}1\cr 2 & 0b00 & 0b10 & 0b00010 = \phantom{2}2\cr 3 & 0b00 & 0b11 & 0b00011 = \phantom{2}3\cr 4 & 0b01 & 0b00 & 0b00000 = \phantom{2}0\cr 5 & 0b01 & 0b01 & 0b00100 = \phantom{2}2\cr 6 & 0b01 & 0b10 & 0b01000 = \phantom{2}4\cr 7 & 0b01 & 0b11 & 0b01100 = \phantom{2}6\cr 8 & 0b10 & 0b00 & 0b00000 = \phantom{2}0\cr 9 & 0b10 & 0b01 & 0b00100 = \phantom{2}4\cr 10 & 0b10 & 0b10 & 0b01000 = \phantom{2}8\cr 11 & 0b10 & 0b11 & 0b01100 = 12 \cr 12 & 0b11 & 0b00 & 0b00000 = \phantom{2}0\cr 13 & 0b11 & 0b01 & 0b01000 = \phantom{2}8\cr 14 & 0b11 & 0b10 & 0b10000 = 16 \cr 15 & 0b11 & 0b11 & 0b11000 = 24 \cr \hline \end{tabular} \end{center} It is clear this is neither monotonic nor efficient, as the same values appear for several representations. A better representation is made by realising that for all but the lowest exponent representations, there is always a leading bit. Hence, this does not have to be stored explicitly. This means this leading bit must be added to the mantissa before the bit shift, and since this increments the length by one bit, then the shift up needed is only $E-1$. The table below shows this improved representation. It is monotonic, there are no duplicates, and the lowest two exponent ranges give an exact representation. \bigskip \begin{center} \begin{tabular}{c|c|c|c} \hline Representation & Exponent & Mantissa & Value \cr\hline 0 & 0b00 & 0b00 & 0b00000 = \phantom{2}0\cr 1 & 0b00 & 0b01 & 0b00001 = \phantom{2}1\cr 2 & 0b00 & 0b10 & 0b00010 = \phantom{2}2\cr 3 & 0b00 & 0b11 & 0b00011 = \phantom{2}3\cr 4 & 0b01 & 0b00 & 0b00100 = \phantom{2}4\cr 5 & 0b01 & 0b01 & 0b00101 = \phantom{2}5\cr 6 & 0b01 & 0b10 & 0b00110 = \phantom{2}6\cr 7 & 0b01 & 0b11 & 0b00111 = \phantom{2}7\cr 8 & 0b10 & 0b00 & 0b01000 = \phantom{2}8\cr 9 & 0b10 & 0b01 & 0b01010 = 10 \cr 10 & 0b10 & 0b10 & 0b01100 = 12 \cr 11 & 0b10 & 0b11 & 0b01110 = 14 \cr 12 & 0b11 & 0b00 & 0b10000 = 16 \cr 13 & 0b11 & 0b01 & 0b10100 = 20 \cr 14 & 0b11 & 0b10 & 0b11000 = 24 \cr 15 & 0b11 & 0b11 & 0b11100 = 28 \cr \hline \end{tabular} \end{center} In this improved representation, the mantissa has $M+1$ bits (except in the lowest exponent range). The exponent can represent numbers up to $2^E-1$ and hence will bit shift by a maximum of $2^E-2$ bits. Hence, the number of bits in the representation is $M+E$ bits, while the maximum number represented has $M+1+2^E-2 = M+2^E-1$ bits, i.e. is is less than $2^{M+2^E-1}$. The reduction is $2^E-E-1$ bits. For the example of $M=2$, $E=2$ in the table above, this gives $2-1+4=5$ bits, i.e. numbers up to $2^5=32$ as shown and the reduction is 1 bit. For the extreme values of $E$, then $E=0$ and $E=1$ both give an exact representation as they only use the lowest range or two lowest ranges, respectively. The reduction is $2^0-0-1=0$ and $2^1-1-1=0$ bits in both cases. Explicitly, for $E=0$, then the representation has $M$ bits while the value represented has $M$ bits also, i.e. the reduction is 0 bits. For $E=1$, the representation has $M+1$ bits, while the value represented has $M+1$ bits also, again with a reduction of 0 bits. For the extreme value of $M=0$, then the representation is just the number of bits in the input word. E.g. for $M=0$, $E=4$, then the table is given below. The value range is less thn $2^{15}=32768$. \bigskip \begin{center} \begin{tabular}{c|c|c|c} \hline Representation & Exponent & Mantissa & Value \cr\hline 0 & 0b0000 & 0 & 0b000000000000000 = \phantom{1222}0\cr 1 & 0b0001 & 0 & 0b000000000000001 = \phantom{1222}1\cr 2 & 0b0010 & 0 & 0b000000000000010 = \phantom{1222}2\cr 3 & 0b0011 & 0 & 0b000000000000100 = \phantom{1222}4\cr 4 & 0b0100 & 0 & 0b000000000001000 = \phantom{1222}8\cr 5 & 0b0101 & 0 & 0b000000000010000 = \phantom{122}16\cr 6 & 0b0110 & 0 & 0b000000000100000 = \phantom{122}32\cr 7 & 0b0111 & 0 & 0b000000001000000 = \phantom{122}64\cr 8 & 0b1000 & 0 & 0b000000010000000 = \phantom{12}128\cr 9 & 0b1001 & 0 & 0b000000100000000 = \phantom{12}256 \cr 10 & 0b1010 & 0 & 0b000001000000000 = \phantom{12}512 \cr 11 & 0b1011 & 0 & 0b000010000000000 = \phantom{1}1024 \cr 12 & 0b1100 & 0 & 0b000100000000000 = \phantom{1}2048 \cr 13 & 0b1101 & 0 & 0b001000000000000 = \phantom{1}4096 \cr 14 & 0b1110 & 0 & 0b010000000000000 = \phantom{1}8192 \cr 15 & 0b1111 & 0 & 0b100000000000000 = 16384 \cr \hline \end{tabular} \end{center} The maximum bit lengths of the value, i.e. $M+2^E-1$, for various values of $M$ and $E$ are shown in the table below. \bigskip \begin{center} \begin{tabular}{r||c|c|c|c|c|c|c|c|c} \hline $M=$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \cr\hline $E=0$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \cr 1 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \cr 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \cr 3 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \cr 4 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 \cr 5 & 31 & 32 & 33 & 34 & 35 & 36 & 37 & 38 & 39 \cr 6 & 63 & 64 & 65 & 66 & 67 & 68 & 69 & 70 & 71 \cr 7 & 127 & 128 & 129 & 130 & 131 & 132 & 133 & 134 & 135 \cr 8 & 255 & 256 & 257 & 258 & 259 & 260 & 261 & 262 & 263 \cr \hline \end{tabular} \end{center} \section{Template fit of energy in depth} Assume a template shape for a photon of $P_l$ per photon energy GeV ... ...