Let's Discuss Octane

I'd like to know how engineers determine octane requirements for a given engine.
I have a basic understanding of octane.
My understanding, in a nut shell, is the higher the octane, the higher the flash point of the fuel.

For instance, my truck is designed to run on regular (91) fuel. Running a higher octane would actually be bad because I wouldn’t get as efficient a burn because it is harder to "flash".....

So how is octane requirements calculated?
Not "if it pings, run higher octane"...

Jeff