Given a classical Weyl group $W$, that is, a Weyl group of type $A$, $B$ or $D$, one can associate with it a polynomial with integral coefficients $Z_W$ given by the ratio of the Hilbert series of the invariant algebras of the natural action of $W$ and $W^t$ on the ring of polynomials ${\bf C}[x_1, \ldots , x_n]^{\otimes t}$. We introduce and study several statistics on the classical Weyl groups of type $B$ and $D$ and show that they can be used to give an explicit formula for $Z_{D_n}$. More precisely, we define two Mahonian statistics, that is, statistics having the same distribution as the length function, $Dmaj$ and $ned$ on $D_n$. The statistic $Dmaj$, defined in a combinatorial way, has an analogous algebraic meaning to the major index for the symmetric group and the flag-major index of Adin and Roichman for $B_n$; namely, it allows us to find an explicit formula for $Z_{D_n}$. Our proof is based on the theory of $t$-partite partitions introduced by Gordon and further studied by Garsia and Gessel.
Using similar ideas, we define the Mahonian statistic $ned$ also on $B_n$ and we find a new and simpler proof of the Adin–Roichman formula for $Z_{B_n}$.
Finally, we define a new descent number $Ddes$ on $D_n$ so that the pair $(Ddes,Dmaj)$ gives a generalization to $D_n$ of the Carlitz identity on the Eulerian–Mahonian distribution of descent number and major index on the symmetric group.