First, I think this question is better suited for the Physics Stack Exchange or the Math Stack Exchange because you're not asking a coding related question.
Second, the trace is literally defined as the sum of the diagonal elements of a matrix.
Third, your other question is about the inner product and Dirac notation. Dirac called the <a|
"bra" and the |b>
"ket". The inner product is basically the dot product but for higher dimensional space. In physics, Dirac notation is a shorthand we use to make writing matrix operations for quantum systems cleaner. You'll see bra's and ket's used to represent wave functions and spin states, and the inner product is then the energy of the system in that state and the spin of that state. Again, this question is really better suited for the Physics Stack Exchange.