if its pinging at 3000-4000rpm, you might be a bit lucky and escape any major damage.. few scorch marks maybe... i wouldn't be pushing your luck tho. I believe 40psi is fine on the fuel pressure, so assuming you have that, most likely culprit is the tune on the ECU... either too much timing or too lean a tune in that rev range... Go aftermarket and get a tuner to do a proper tune or get a stock ecu to replace it.
yes it could be the AFM reporting incorrect (too low) air flow causing the ECU to think their is less air than there is and consequently injecting less fuel, causing detonation. again, borrow one to test.
What sort of fuel are you using ??