Reaching Hecke eigenvalues from a trace formula I am interested in studying equidistribution of Hecke eigenvalues and proving statistical properties of arithmetical objects. On the road, I face the following problem: how to express sums of the form
$$\sum_{c(\pi)<X} a_n(\pi)$$
where $a_n(\pi)$ is the $n$-th coefficient of the Dirichlet series defining $L(s, \pi)$, and $c(\pi)<X$ is some truncating condition. The sum is over irreducible representations of a totally definite quaternion algebra $Z\backslash B^\times$. We know that those coefficients can be read as Hecke  eigenvalues $\lambda_n(\pi)$, so I am thinking in applying trace formulas to Hecke operators in order to reach such a sum, as in Serre's article on equidistribution.
In simple cases, such as compact groups, I can use the Selberg's trace formula, and it remains to find a suitable test-function in order to reach those coefficients/eigenvalues. Is there a standard approach, and if so are there easy ways to make those eigenvalues appear in the spectral side of the trace formula ? 
More generally, what are the common relations between trace formulas and Hecke operators (I suppose it is a fertile ground, for both Hecke eigenvalues and trace formulas are powerful tools, and both are "spectral" objects) ?
Any idea or reference would be of great help !
 A: Yes, this is a standard thing to do.  If you want to look at traces of Hecke operators on a definite quaternion algebra, this is the same as what are known as "traces of Brandt matrices."  These have been studied with trace formulas classically by Eichler, Shimizu, etc.  E.g., see the notes

The basis problem for modular forms and the traces of Hecke operators, by Eichler (MR)

I think the cleanest way to do it is adelically, though this may be personal bias.  I can't think of a reference off the top of my head that puts everything together precisely, but I can give you a couple of references that deal with the necessary components.  An adelic approach to the trace formula for GL(2) and the precise connection with Hecke operators is described in detail in the book

Traces of Hecke Operators, by Knightly and Li (MR)

Basically, say you want the trace for $T_n$.  You choose a test function $f = \prod f_v$ such that $f_p$ gives you the local Hecke operator for $p \mid N$ and $f_\infty$ gives you the desired weight of the representation.
To modify this for a definite quaternion algebra $B$, you just need to modify the test functions $f_v$ at the places where $B$ ramifies. E.g., if you want weight 2 and squarefree level, just take $f_\infty=1$ and $f_p$ to be the characteristic function of the unit group of a local maximal order at a finite place $p$ where $B$ ramifies (so $p | N$).
Similar calculations have been done several places, e.g. in the context of the relative trace formula in the paper 

Averages of central L-values of Hilbert modular forms with an application to subconvexity, by Feigon and Whitehouse (MR),

which computes sums of $L$-values weighted by Hecke eigenvalues.
