Suppose $H$ is a Hermitian matrix. Then it may diagonalised by a unitary matrix $U$, such that $D = U^\dagger H U$ where $D$ is diagonal with elements the eigenvalues of $H$. We may construct $U$ by taking its columns to be the orthonormalised eigenvectors of $H$, but as I understand there are then two possible causes of arbitrariness in $U$: the sign of the orthonormalised eigenvectors, and the order one puts them in (which affects the order the eigenvalues appear in $D$.
Is it possible to find the order and sign convention which maximises the real part of the trace of $U$ with some algorithm except exhaustion? Will the answer be unique?
An example to make the lines I am thinking along clear. Suppose:
$$H = \begin{pmatrix} 1 & 0 \\ 0 & 2\end{pmatrix} $$
Then the full set of unitary $U$ which diagonalise $H$ (well, leave it diagonal) are (I believe):
$$ \begin{align} U =& \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}, \,\begin{pmatrix} -1 & 0 \\ 0 & -1\end{pmatrix}, \,\begin{pmatrix} -1 & 0 \\ 0 & 1\end{pmatrix},\, \begin{pmatrix} 1 & 0 \\ 0 & -1\end{pmatrix} \\ \\ & \begin{pmatrix} 0 & 1 \\ 1 & 0\end{pmatrix}, \,\begin{pmatrix} 0 & -i\\ i & 0\end{pmatrix}, \,\begin{pmatrix} 0 & i \\ -i & 0\end{pmatrix},\, \begin{pmatrix} 0 & -1 \\ -1 & 0\end{pmatrix}\end{align}$$
Of these the identity has the greatest real part of the trace. For matrices which are already diagonal obviously the identity is always going to have the greatest real part of the trace, but is it possible for general $N\times N$ not diagonal $H$ to find the $U$ with the greatest $\textrm{Re}(\textrm{Tr}( U))$ and is it unique?