I'm studying 2d CFTs and partition functions, particularly the modular property. However, I'm confused by the following things:
Partition function of torus ~ Partition functions of Virasoro characters?
I'm puzzled as I've seen in a lot of literature that the 2d CFT on a torus yields the partition function $$ Z(q, \bar{q})=\operatorname{Tr}_{\mathcal{H}_{\text{CFT}}}\left(q^{L_0-\frac{c}{24}} \bar{q}^{\bar{L}_0-\frac{\bar{c}}{24}}\right),$$ where $q=e^{2\pi i \tau}$ where $\tau$ is the modular parameter. And because of the torus this is modular invariant(?). Here I know the -c/24 terms comes from the Neveu-Schwarz (NS) vacuum of the cylinder. However, I also know, that for the highest-weight representations of the Virasoro algebra, the partition function can be written in terms of the Virasoro characters (primaries, descendants) as
$$Z(\tau, \bar{\tau})=\sum_{i, j} M_{i j} \mathcal{X}_i(\tau) \mathcal{X}_j(\bar{\tau}),$$ where the sum is over traces for respective states. Am I correct in this: it seems like requiring modular invariance of this partition function put constraints on the fields(?) — as they need to transform modular invariantly — and the matrix $M_{ij}$, making sure that you eventually end up with an expression like the one above. I have heard that this is called NS partition function based on some vacuum boundary conditions?
What I'm particularly wondering is that, are both approaches equal? Why would I choose the one over the other?