Peter, you're completely right.
Carbs & Protein have about 4 kcal/g (~115 kcal/oz), fats about 9 kcal/g (~250 kcal/oz)
Energy density is pushed up only by higher fat content; it's reduced mainly by water content.
Usable energy is also reduced if a lot of the carbs are the form of indigestible fiber, and this is not usually reflected on the nutritional label, which reflects the theoretical energy if everything were completely digested.
A typical energy bar has a little moisture and a little fat, and comes out in the 100-110 kcal/oz range.
Increasing energy density above about 110 kcal/oz means increasing fat content. The problem with this is that fat is more difficult to digest, especially when exercising. That's why most energy bars don't have too much fat. Nuts are high in fat, and the "energy bars" that have much higher energy density, like the "Kind" bars, are basically nuts shaped into a bar. You can get the same energy density by taking a bag of nuts or a jar of peanut butter. The question is, can you digest it?
I take a diet with a much higher fat content when I'm hiking at a moderate pace, taking breaks to stop and eat, and cooking a proper dinner that has time to digest. But moving fast, you just can't digest too much fat.
For me, the ideal bar would be something like:
70% carbs (with minimal fiber)
15% protein
15% fat
I've yet to find anything like this. Most have less fat than this – I think I can digest a little more, and I'd rather have it mixed in with my carbs in the bar than carry a separate high-fat item. Most bars have WAY more fiber than I want. You need some fiber to keep your digestive system healthy, but when you're eating a lot of food on the trail, I don't think most people need the amount of indigestible fiber that's in most energy bars. Power bars are the only low-fiber bar that I've found, they just don't taste so great.