I have several different discounts running on my cart including quantity discounts and group discount

my tax is being calculated on the subtotal BEFORE any of the discounts and I need it to apply the discounts before calculating the tax

does any one have any ideas how I can do this or where the code is that calculates the tax?

thanks

Rachael