% $Id$
\documentclass[twoside]{article}

\usepackage[english]{babel}
\usepackage{a4}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{float}
\usepackage{hyperref}
\usepackage{xspace}
\usepackage{rotating}
\usepackage{dcolumn}

\setlength{\topmargin}{10mm}
\setlength{\topmargin}{-13mm}
% \setlength{\oddsidemargin}{0.5cm}
% \setlength{\evensidemargin}{0cm}
\setlength{\oddsidemargin}{1cm}
\setlength{\evensidemargin}{1cm}
\setlength{\textwidth}{14.5cm}
\setlength{\textheight}{23.8cm}

\pagestyle{fancyplain}
\addtolength{\headwidth}{0.6cm}
\fancyhead{}%
\fancyhead[RE,LO]{\bf Functions used in conjunction with LEM spin valve
experiments}%
\fancyhead[LE,RO]{\thepage}
\cfoot{--- Andreas Suter -- \today ---}
\rfoot{\includegraphics[width=6.4cm]{PSI_Logo_wide_blau.pdf}}

\DeclareMathAlphabet{\bi}{OML}{cmm}{b}{it}

\newcommand{\mean}[1]{\langle #1 \rangle}
\newcommand{\lem}{LE-$\mu$SR\xspace}
\newcommand{\musr}{$\mu$SR\xspace}
\newcommand{\etal}{\emph{et al.\xspace}}

\newcolumntype{d}[1]{D{.}{.}{#1}}

\begin{document}
% Header info --------------------------------------------------
\thispagestyle{empty}
\noindent
\begin{tabular}{@{\hspace{-0.7cm}}l@{\hspace{6cm}}r}
\noindent\includegraphics[width=6.4cm]{PSI_Logo_wide_blau.pdf} &
  {\Huge\sf Memorandum}
\end{tabular}
%
\vskip 1cm
%
\begin{tabular}{@{\hspace{-0.5cm}}ll@{\hspace{4cm}}ll}
Datum:   & \today        &     & \\[3ex]
Von:     & Andreas Suter & An: & \\
Telefon: & +41\, (0)56\, 310\, 4238        &     & \\
Raum:    & WLGA / 119    & cc: & \\
e-mail:  & \verb?andreas.suter@psi.ch? & & \\
\end{tabular}
%
\vskip 0.3cm
\noindent\hrulefill
\vskip 1cm
%

\section{Spin Valve related functions used in LEM}

\subsection{Skewed Lorentzian}

The skewed Lorentzian asymmetry is defined as

\begin{equation}\label{eq:skewedLorentzian}
  A(t) = A_0 \, \frac{1}{N} \, \sum_{j=0}^{M}
\frac{1}{1+\left[\displaystyle\frac{B_j-B_{\rm
ext}}{\beta(1\pm\Delta)}\right]^2}\,\cos(\gamma_\mu B_j t + \phi),
\end{equation}

\noindent where the sign of $\pm\Delta$ is `$+$' for $B_j>B_{\rm ext}$ and `$-$'
for $B_j<B_{\rm ext}$. The norm $N$ is

\begin{equation}\label{eq:skewedLorentzianNorm}
 N = \sum_{j=0}^{M} \frac{1}{1+\left[\displaystyle\frac{B_j-B_{\rm
ext}}{\beta(1\pm\Delta)}\right]^2}.
\end{equation}

\noindent $M$ is the number of field values which can be adjusted by the user
(see file \verb!spinValve_startup.xml! tag \verb!number_of_fields!). 
The spacing between $B_j$'s is different for $B_j<B_{\rm ext}$ and $B_j>B_{\rm
ext}$, namely

\begin{equation}\label{eq:fieldSpacing}
 \Delta B_{\pm} = B_j - B_{j+1} = R \cdot \beta(1\pm\Delta),
\end{equation}

\noindent where $R$ is a user adjustable parameter, set to a default value of
$R=10$ (see file \verb!spinValve_startup.xml! tag \verb!range!). 

According to the supplementary material of \cite{drew2009}, the value $R=7$ has
been chosen, no information is given for $M$! These numbers need to be evaluated
somehow. In order to be able for the user to tweak these parameters they were 
out-sourced into file called at the startup of the fit (for details see Sec.\ref{sec:skewedLorentzainAndMusrfit}).

To test this I generated a synthetic data set (\texttt{09001.root}) which can be used to
check the needed number of $M$. $R$ has been fixed to 10 (not 7, as in \cite{drew2009}) since the Lorentzian has
quite extended wings. The synthetic data set follows the function

\begin{equation}\label{eq:syntheticData}
 A(t) = A_0 \exp(-\lambda t) \cos(\gamma_\mu B_{\rm ext} t + \varphi)
\end{equation}

\noindent with $A_0=0.22$ per segement (in the following fit results 2 segments will be combined and hence $A_0$ reduced to $0.2$), 
$\lambda = 0.5\, (1/\mu\mathrm{sec}) \Rightarrow \beta = 5.87\, (\mathrm{G})$, $B_{\rm ext} = 200\,(\mathrm{G})$.

\begin{table}[h]
 \centering
 \begin{tabular}{l|l|l|l|l|l}
   $M$ & Asymmetry & $\beta$ (G) & $\Delta$   & $B_{\rm ext}$ (G) & $\chi^2$ \\ \hline\hline
    7  & 0.121(6)  & 2.25(3)     & $+0.01(1)$ & 200.18(6)         & 6.703 \\
   37  & 0.191(1)  & 5.85(7)     & $-0.00(2)$ & 200.10(9)         & 1.317 \\
   67  & 0.191(1)  & 5.86(7)     & $-0.00(2)$ & 200.10(9)         & 1.317 \\
   97  & 0.191(1)  & 5.86(7)     & $-0.00(2)$ & 200.10(9)         & 1.317
 \end{tabular}
 \caption{Parameters obtained for the synthetic exponetially damped signal (\texttt{09001.root}).}\label{tab:syntheticData}
\end{table}

\begin{table}[h]
 \centering
 \begin{tabular}{l|l|l|l|l|l}
   $M$ & Asymmetry & $\beta$ (G) & $\Delta$   & $B_{\rm ext}$ (G) & $\chi^2$ \\ \hline\hline
    7  & 0.050(1)  & 20.6(2)     & 0.55(1)    & 191.5(2)          & 2.564 \\
   37  & 0.111(2)  & 12.4(3)     & 0.20(2)    & 194.7(3)          & 1.262 \\
   67  & 0.123(2)  & 17.1(7)     & 0.42(3)    & 196.5(3)          & 1.197 \\
   97  & 0.126(4)  & 19.0(1.0)   & 0.48(4)    & 197.0(5)          & 1.190 \\
  127  & 0.127(3)  & 19.8(9)     & 0.50(2)    & 197.1(4)          & 1.187 \\
  157  & 0.128(3)  & 20.1(1.0)   & 0.51(3)    & 197.2(4)          & 1.187 \\
  187  & 0.128(3)  & 20.5(8)     & 0.52(3)    & 197.3(4)          & 1.186 \\
  207  & 0.129(3)  & 20.5(1.0)   & 0.52(3)    & 197.4(4)          & 1.186
 \end{tabular}
 \caption{Parameters obtained for 2012 run 4966.}\label{tab:year2012run4966}
\end{table}

\noindent From Tab.\ref{tab:syntheticData} and \ref{tab:year2012run4966} it is quite obvious that $M$ needs to be adopted to the problem. 
The default settings will be: $M=201$ and $R=10$.

\subsubsection{Skewed Lorentzian --- how to call it from \texttt{musrfit}}\label{sec:skewedLorentzainAndMusrfit}

The source code for the user function can be found under \verb!<musfit-home>/src/external/libSpinValve!, where also this description is found.
The file \verb!spinValve_startup.xml! (see Appendix \ref{app:spinValve_startup}) should be place in the directory where the analysis takes place.
It holds the value for $M$ (see tag \verb!<number_of_fields>!) and $R$ (see tag \verb!<range>!).

To call the user function from the msr-file you need a in the \texttt{THEORY} block a line like

\begin{verbatim}
userFcn  libPSpinValve.so PSkewedLorentzian 4 2 3 map1 
\end{verbatim}

\noindent The parameters for this function are \verb!PSkewedLorentzian <B_ext> <beta> <Delta> <phase>! where \verb!<B_ext>! is the applied field, \verb!<beta>! is 
the width $\beta$ as given in Eq.(\ref{eq:skewedLorentzian}), \verb!<Delta>! is the skewness $\Delta$, and \verb!<phase>! is the detector phase.

In the directory \verb!<musfit-home>/src/external/libSpinValve/test! some example files are given.

\appendix

\section{Technical description for the skewed Lorentzian}

\subsection{The file \texttt{spinValve\_startup.xml}}\label{app:spinValve_startup}

\begin{verbatim}
<?xml version="1.0" encoding="UTF-8"?>
<spin_valve_proximity xmlns="http://nemu.web.psi.ch/musrfit/libSpinValve">
  <comment>
    $Id$
    number_of_fields: number of sampling points in field around the Lorentzian peak
    range: range in which the sampling points are placed, given in units of \beta(1\pm\Delta)
  </comment>
  <skewed_lorentzian_parameters>
    <number_of_fields>251</number_of_fields>
    <range>10.0</range>
  </skewed_lorentzian_parameters>
</spin_valve_proximity> 
\end{verbatim}

\subsection{msr-file example section for the skewed Lorentzian}

\small
\begin{verbatim}
SV1139, 0mV, FC T=24.99 K, E=15.85 keV, B=~194(G)/6.00(A), Tr/Sa=16.51/0.00 kV, RAL-RAR=-0.26 kV, SR=-10.00
###############################################################
FITPARAMETER
#      Nr. Name       Value     Step      Pos_Error Boundaries   
        1 Asy         0.1284    -0.0034     0.0023      0       none    
        2 Beta        20.47     -1.26       0.72        
        3 Delta       0.516     -0.031      0.022       
        4 Field       197.27    -0.44       0.34        
        5 N0_L        963.74    -0.87       0.86        
        6 Bkg_L       12.81     -0.15       0.15        
        7 Phase_L     2.3       -1.3        1.3         
        8 alpha_LR    1.1659    -0.0014     0.0014      
        9 Bkg_R       16.74     -0.16       0.16        
       10 Phase_R     177.1     -1.2        1.2         

###############################################################
THEORY
asymmetry      1
userFcn  libPSpinValve.so PSkewedLorentzian 4 2 3 map1

############################################################### 
\end{verbatim}
\normalsize

\subsection{Parameters used to generate \texttt{09001.root}}

The file \texttt{09001.root} represents a \texttt{MusrRoot}-file with synthetic data. A detector system, consisting of 8 detectors
has been assumed. The asymmetry follows Eq.(\ref{eq:syntheticData}). The used parameters are:

\small
\begin{verbatim}
t0's               : 3519.0, 3420.0, 3520.0, 3621.0, 3417.0, 3518.0, 3422.0, 3423.0
N0's per bin       : 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0
Bkg's per bin      : 1.3, 1.5, 1.0, 1.3, 1.2, 1.1, 1.0, 1.4
A0's per segment   : 0.2201, 0.22, 0.2202, 0.2198, 0.22, 0.2199, 0.22, 0.2203
phases per segment : 5, 50, 95, 140, 185, 230, 275, 320
\end{verbatim}
\normalsize

\noindent And the other parameters as given after Eq.(\ref{eq:syntheticData}).

\begin{thebibliography}{99}
 \bibitem{drew2009} A.J. Drew, \emph{et al.}, Nature Materials \textbf{8}, 109
(2009). 
\end{thebibliography}

\end{document}
